Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
package org.mozilla.focus.ext
import androidx.core.net.toUri
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class UriTest {
@Test
fun testTruncatedHostWithCommonUrls() {
assertTruncatedHost("yahoo.com", "https://de.search.yahoo.com/search?p=mozilla&fr=yfp-t&fp=1&toggle=1&cop=mss&ei=UTF-8")
assertTruncatedHost("amazon.co.uk", "https://www.amazon.co.uk/Doctor-Who-10-Part-DVD/dp/B06XCMVY1H")
}
@Test
fun testTruncatedHostWithEmptyHost() {
assertTruncatedHost("", "tel://")
}
@Test
fun testTruncatedPathWithEmptySegments() {
}
@Test
fun testTrunactedPathWithOneSegment() {
}
@Test
fun testTruncatedPathWithTwoSegments() {
assertTruncatedPath("/mozilla-mobile/focus-android", "https://github.com/mozilla-mobile/focus-android")
}
@Test
fun testTruncatedPathWithMultipleSegments() {
assertTruncatedPath(
"/2017/…/nasa-hi-seas-mars-analogue-mission-hawaii-mauna-loa",
)
}
@Test
fun testTruncatedPathWithMultipleSegmentsAndFragment() {
assertTruncatedPath(
"/@bfrancis/the-story-of-firefox-os-cb5bf796e8fb",
)
}
private fun assertTruncatedHost(expectedTruncatedPath: String, url: String) {
assertEquals(
"truncatedHost($url)",
expectedTruncatedPath,
url.toUri().truncatedHost(),
)
}
private fun assertTruncatedPath(expectedTruncatedPath: String, url: String) {
assertEquals(
"truncatedPath($url)",
expectedTruncatedPath,
url.toUri().truncatedPath(),
)
}
}