From eca28634007dd7063610b05a4db12bed7d3353d7 Mon Sep 17 00:00:00 2001 From: Gothwad Tech Date: Mon, 23 Nov 2026 09:24:26 +0000 Subject: [PATCH 1/2] test: fix the failing template test and cover UrlUtils - ExampleRobolectricTest asserted the AI Studio placeholder name "My Application"; it now checks the real app name and the com.bansify.browser package, which is what actually broke the gate - add UrlUtilsTest: omnibox resolution (https-first, bare domain, localhost, javascript: rejection, search fallback), search URL building, file-size formatting and download categorisation --- .../bansify/browser/ExampleRobolectricTest.kt | 23 +++-- .../java/com/bansify/browser/UrlUtilsTest.kt | 94 +++++++++++++++++++ 2 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 app/src/test/java/com/bansify/browser/UrlUtilsTest.kt diff --git a/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt b/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt index b1e3bc4..9f3721f 100644 --- a/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt +++ b/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt @@ -8,14 +8,25 @@ import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config +/** + * Smoke test for the app shell: the resources the launcher and the manifest depend on must + * exist and carry the Bansify identity. The template shipped with the AI Studio export + * asserted the placeholder name "My Application", which failed as soon as the app was + * branded — keep these values in step with strings.xml and build.gradle.kts. + */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [36]) class ExampleRobolectricTest { - @Test - fun `read string from context`() { - val context = ApplicationProvider.getApplicationContext() - val appName = context.getString(R.string.app_name) - assertEquals("My Application", appName) - } + @Test + fun `app name comes from resources`() { + val context = ApplicationProvider.getApplicationContext() + assertEquals("Bansify Browser", context.getString(R.string.app_name)) + } + + @Test + fun `application id is the Bansify package`() { + val context = ApplicationProvider.getApplicationContext() + assertEquals("com.bansify.browser", context.packageName) + } } diff --git a/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt b/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt new file mode 100644 index 0000000..ffb2627 --- /dev/null +++ b/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt @@ -0,0 +1,94 @@ +package com.bansify.browser + +import com.bansify.browser.browser.UrlUtils +import com.bansify.browser.data.BrowserTab +import com.bansify.browser.data.SearchEngine +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +/** + * Omnibox input resolution. Robolectric is required because [UrlUtils] uses + * `android.util.Patterns` and `android.net.Uri`. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [36]) +class UrlUtilsTest { + + private fun resolve(input: String, httpsFirst: Boolean = true) = + UrlUtils.resolveInputToUrl(input, SearchEngine.GOOGLE, httpsFirst) + + @Test + fun `blank input opens the new tab page`() { + assertEquals(BrowserTab.NEW_TAB_URL, resolve("")) + assertEquals(BrowserTab.NEW_TAB_URL, resolve(" ")) + assertEquals(BrowserTab.NEW_TAB_URL, resolve("bansify://newtab")) + } + + @Test + fun `explicit https is kept as typed`() { + assertEquals("https://bansify.com/drive", resolve("https://bansify.com/drive")) + } + + @Test + fun `http is upgraded when https first is on`() { + assertEquals("https://example.com/page", resolve("http://example.com/page", httpsFirst = true)) + } + + @Test + fun `http is kept when https first is off`() { + assertEquals("http://example.com/page", resolve("http://example.com/page", httpsFirst = false)) + } + + @Test + fun `bare domain becomes https`() { + assertEquals("https://bansify.com", resolve("bansify.com")) + } + + @Test + fun `localhost and ip addresses stay http`() { + assertEquals("http://localhost:8080", resolve("localhost:8080")) + assertTrue(resolve("192.168.1.10").startsWith("http://192.168.1.10")) + } + + @Test + fun `plain words become a search`() { + assertEquals( + "https://www.google.com/search?q=bansify+browser", + resolve("bansify browser") + ) + } + + @Test + fun `javascript urls are never executed`() { + val result = resolve("javascript:alert(1)") + assertTrue(result.startsWith("https://www.google.com/search?q=")) + } + + @Test + fun `search url is built from the engine template`() { + assertEquals( + "https://duckduckgo.com/?q=hello+world", + UrlUtils.buildSearchUrl("hello world", SearchEngine.DUCKDUCKGO) + ) + } + + @Test + fun `file sizes are formatted`() { + assertEquals("Unknown size", UrlUtils.formatFileSize(0)) + assertEquals("900 B", UrlUtils.formatFileSize(900)) + assertEquals("2 KB", UrlUtils.formatFileSize(2048)) + assertEquals("1.5 MB", UrlUtils.formatFileSize((1.5 * 1024 * 1024).toLong())) + } + + @Test + fun `downloads are categorised by mime and extension`() { + assertEquals("Images", UrlUtils.inferDownloadCategory("photo.png", "image/png")) + assertEquals("Documents", UrlUtils.inferDownloadCategory("notes.txt", "text/plain")) + assertEquals("Pages", UrlUtils.inferDownloadCategory("page.html", "text/html")) + assertEquals("Other", UrlUtils.inferDownloadCategory("archive.zip", "application/zip")) + } +} From 0d88f0949dda62f709490cdf28d2502916b4db67 Mon Sep 17 00:00:00 2001 From: Gothwad Tech Date: Mon, 23 Nov 2026 09:26:36 +0000 Subject: [PATCH 2/2] test: pin Robolectric to SDK 34 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @Config(sdk = [36]) threw java.lang.UnsupportedOperationException at DefaultSdkProvider.java:170 — Robolectric 4.16.1 has no SDK 36 runtime, so both Robolectric classes failed at class level before any assertion ran. - both test classes now run on SDK 34 - app/src/test/resources/robolectric.properties pins sdk=34 for every future Robolectric test, so a new class cannot hit the same wall --- app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt | 2 +- app/src/test/java/com/bansify/browser/UrlUtilsTest.kt | 2 +- app/src/test/resources/robolectric.properties | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 app/src/test/resources/robolectric.properties diff --git a/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt b/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt index 9f3721f..c8fdfa3 100644 --- a/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt +++ b/app/src/test/java/com/bansify/browser/ExampleRobolectricTest.kt @@ -15,7 +15,7 @@ import org.robolectric.annotation.Config * branded — keep these values in step with strings.xml and build.gradle.kts. */ @RunWith(RobolectricTestRunner::class) -@Config(sdk = [36]) +@Config(sdk = [34]) class ExampleRobolectricTest { @Test diff --git a/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt b/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt index ffb2627..8e8543d 100644 --- a/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt +++ b/app/src/test/java/com/bansify/browser/UrlUtilsTest.kt @@ -15,7 +15,7 @@ import org.robolectric.annotation.Config * `android.util.Patterns` and `android.net.Uri`. */ @RunWith(RobolectricTestRunner::class) -@Config(sdk = [36]) +@Config(sdk = [34]) class UrlUtilsTest { private fun resolve(input: String, httpsFirst: Boolean = true) = diff --git a/app/src/test/resources/robolectric.properties b/app/src/test/resources/robolectric.properties new file mode 100644 index 0000000..979b5ee --- /dev/null +++ b/app/src/test/resources/robolectric.properties @@ -0,0 +1 @@ +sdk=34