Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162package rocks.vale.webview.util
import org.junit.Assert.assertEqualsimport org.junit.Test
/** Local unit tests for the URL bar's text handling. */class UrlUtilsTest {
private val searchTemplate = "https://www.google.com/search?q=%s"
@Test fun blankInputProducesNothing() { assertEquals("", UrlUtils.normalize("", searchTemplate)) assertEquals("", UrlUtils.normalize(" ", searchTemplate)) }
@Test fun explicitSchemeIsPreserved() { assertEquals("http://example.com", UrlUtils.normalize("http://example.com", searchTemplate)) assertEquals("https://example.com", UrlUtils.normalize("https://example.com", searchTemplate)) assertEquals("about:blank", UrlUtils.normalize("about:blank", searchTemplate)) assertEquals("file:///sdcard/test.html", UrlUtils.normalize("file:///sdcard/test.html", searchTemplate)) }
@Test fun bareHostGetsHttps() { assertEquals("https://example.com", UrlUtils.normalize("example.com", searchTemplate)) assertEquals("https://www.example.com/a/b", UrlUtils.normalize("www.example.com/a/b", searchTemplate)) }
@Test fun hostAndPortGetsHttps() { assertEquals("https://localhost:8080", UrlUtils.normalize("localhost:8080", searchTemplate)) assertEquals("https://192.168.1.10:8443", UrlUtils.normalize("192.168.1.10:8443", searchTemplate)) }
@Test fun wordsBecomeASearch() { assertEquals( "https://www.google.com/search?q=hello", UrlUtils.normalize("hello", searchTemplate), ) assertEquals( "https://www.google.com/search?q=hello+world", UrlUtils.normalize("hello world", searchTemplate), ) }
@Test fun searchQueryIsPercentEncoded() { assertEquals( "https://www.google.com/search?q=a%26b%3Dc", UrlUtils.normalize("a&b=c", searchTemplate), ) }
@Test fun surroundingWhitespaceIsIgnored() { assertEquals("https://example.com", UrlUtils.normalize(" example.com ", searchTemplate)) }}