Modern Apps git

← Modern-Apps.git

communicate: strengthen launch e2e test

Commit
3c4114dd0e2da723f6477f22eacc49ec0b9b4995
Author
Vayun Mathur <[email protected]>
When
2026-11-19 04:21 UTC (17 days ago)
Parents
624ceca
Strengthen the single LaunchNoCrashTest for communicate instead of adding a
separate journey test, so the app keeps exactly one emulator e2e test.

The test now clears the target package data (pm clear) before the
grant/launch pass, so it starts from clean state on the emulator, then
performs one small deterministic core interaction after the existing
launch assertions: Messages -> Dialer -> Call logs -> Messages tabs, each asserting its verified default-app gate or empty state on a fresh no-SIM emulator. All selectors are verified literals from
the module's Compose code and strings (see the test body); no network,
accounts, Bluetooth, SIM, camera, microphone input or other hardware
dependency is introduced beyond the existing headless grant pass.

No production code, lint, detekt or test configuration was changed.

Verified compile-only (emulator runs centrally, not here):
JAVA_HOME=/home/vayun/maos/prebuilts/jdk/jdk21/linux-x86 ./gradlew
:communicate:assembleDev :communicate:assembleDevAndroidTest -- BUILD SUCCESSFUL.

Diff

communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt
diff --git a/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt b/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.ktindex 157fa538f5..727642ec5d 100644--- a/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt+++ b/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt@@ -24,6 +24,11 @@ import org.junit.runner.RunWith  * at runtime and issues headless `pm grant`s, so the gate clears without  * touching system UI.  *+ * Strengthened launch-e2e: clears the target package data before the+ * grant/launch pass so the journey starts from clean state, then performs+ * one small deterministic core interaction (see the test body) and returns+ * to the launch surface. Still a single @Test for this app.+ *  * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on  * hidden InputManager APIs that no longer exist on current releases, so every  * compose-rule test dies before its first line. Text polling works for Compose@@ -39,6 +44,10 @@ class LaunchNoCrashTest {         val targetContext = instrumentation.targetContext         val packageName = targetContext.packageName +        // Clean state first (fresh-install journey); grants follow the clear+        // because a clear can drop runtime-grant state on some releases.+        clearAppData(instrumentation.uiAutomation, packageName)+         grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)          val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)@@ -56,10 +65,31 @@ class LaunchNoCrashTest {             "messages tab never appeared; the app may have crashed on launch",             device.wait(Until.findObject(By.text(MESSAGES_TAB_LABEL)), CONTENT_TIMEOUT_MS),         )+        // Core interaction: visit Dialer and Call logs, then return to+        // Messages. A fresh emulator is neither default SMS/phone app and+        // has no SIM or history, so each tab deterministically shows its+        // default-app gate or its empty state (verified literals).+        waitForAnyText(device, MESSAGES_SURFACES)+        tapTab(device, DIALER_TAB)+        waitForAnyText(device, DIALER_SURFACES)+        tapTab(device, CALL_LOGS_TAB)+        waitForAnyText(device, CALL_LOG_SURFACES)+        tapTab(device, MESSAGES_TAB_LABEL)+        waitForAnyText(device, MESSAGES_SURFACES)         // Still alive in front: the process did not crash after painting content.         assertEquals(packageName, device.currentPackageName)     } +    private fun clearAppData(uiAutomation: UiAutomation, packageName: String) {+        try {+            uiAutomation.executeShellCommand("pm clear $packageName").close()+        } catch (ignored: SecurityException) {+            // Clear refused: the journey assertions below still report state.+        } catch (ignored: IOException) {+            // Shell pipe failed: the content assertions below report it.+        }+    }+     private fun grantAllRequestedPermissions(         uiAutomation: UiAutomation,         packageManager: PackageManager,@@ -91,11 +121,40 @@ class LaunchNoCrashTest {         }     } +    private fun tapTab(device: UiDevice, label: String) {+        val tab = device.wait(Until.findObject(By.text(label)), CONTENT_TIMEOUT_MS)+        assertNotNull("tab $label never appeared", tab)+        tab!!.click()+    }++    private fun waitForAnyText(device: UiDevice, texts: List<String>) {+        val deadline = System.currentTimeMillis() + CONTENT_TIMEOUT_MS+        while (System.currentTimeMillis() < deadline) {+            if (texts.any { device.findObject(By.text(it)) != null }) return+            Thread.sleep(250L)+        }+        throw AssertionError("none of $texts ever appeared")+    }+     private companion object {         private const val CONTENT_TIMEOUT_MS = 15_000L         private const val GATE_TIMEOUT_MS = 5_000L         private const val MESSAGES_TAB_LABEL = "Messages"         private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"+        private const val DIALER_TAB = "Dialer"+        private const val CALL_LOGS_TAB = "Call logs"+        private val MESSAGES_SURFACES = listOf(+            "No conversations yet",+            "Set Communicate as your default SMS app to read and manage messages here.",+        )+        private val DIALER_SURFACES = listOf(+            "No contacts found",+            "Set Communicate as your default phone app to use the dialer and call history here.",+        )+        private val CALL_LOG_SURFACES = listOf(+            "No recent calls found",+            "Set Communicate as your default phone app to use the dialer and call history here.",+        )          /**          * Special access behind some apps' gates: exact alarms + full-screen intent