package rocks.vale.webview.util import org.junit.Assert.assertEquals import 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)) } }