uniflix: add emulator launch e2e test
- Commit
f0148860946be2a66eb5ce8b83941a35e8fbfc49- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 04:21 UTC (17 days ago)
- Parents
cb238a1
Add the single LaunchNoCrashTest for uniflix under uniflix/src/androidTest, following the repo-wide launch-no-crash pattern (notes/appstore/email): start from clean app state (pm clear before grants/launch), grant every manifest-requested permission plus the exact-alarm/full-screen appops, launch the launcher intent, assert the permission-gate title never appears, and assert real first-screen content appears with the app still in front. Navigation starts on the Home route with no onboarding gate in this build, and HomeScreen always composes its Movies/Series hub buttons above the network-backed catalog rows, so the content assertion keys on the Movies button and does not depend on catalog rows loading. No production code, config, lint or detekt changes. Verified compile only (emulator run is done centrally): :uniflix:assembleDev and :uniflix:assembleDevAndroidTest pass.
Diff
uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/LaunchNoCrashTest.kt
diff --git a/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/LaunchNoCrashTest.kt b/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..4da58d5ce1--- /dev/null+++ b/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/LaunchNoCrashTest.kt@@ -0,0 +1,127 @@+package com.vayunmathur.uniflix.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on real content rather than sitting on a permission screen.+ *+ * Navigation starts on the Home route with no onboarding gate in this build:+ * HomeScreen always composes its Movies/Series hub buttons above the catalog+ * rows, so the content wait keys on the Movies button and does not depend on+ * the network-backed rows loading.+ *+ * 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+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++ @Test+ fun launch_grantsPermissions_showsCatalogHome() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName++ // Clean-state start: wipe any data a previous run left behind so the+ // first screen below is the fresh-install one, then grant permissions+ // (grants are applied after the clear so they survive it).+ clearAppData(instrumentation.uiAutomation, packageName)+ grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++ val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+ assertNotNull("no launcher intent for $packageName", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ targetContext.startActivity(intent)++ // Past the permission screen: the gate wall never appears (uniflix has+ // no runtime-permission gate; gated apps assert the same absence to+ // prove they cleared it).+ assertNull(+ "permission gate is showing; grants did not clear it",+ device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+ )+ // Main content is actually visible: the home hub Movies button.+ assertNotNull(+ "catalog home never appeared; the app may have crashed on launch",+ device.wait(Until.findObject(By.text(MOVIES_LABEL)), CONTENT_TIMEOUT_MS),+ )+ // 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: leftover state may change the first screen and+ // the content assertions below report it.+ } catch (ignored: IOException) {+ // Shell pipe failed: the content assertions below report it.+ }+ }++ private fun grantAllRequestedPermissions(+ uiAutomation: UiAutomation,+ packageManager: PackageManager,+ packageName: String,+ ) {+ val info = try {+ packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+ } catch (e: PackageManager.NameNotFoundException) {+ throw AssertionError("package $packageName not installed", e)+ }+ for (permission in info.requestedPermissions.orEmpty()) {+ try {+ uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+ } catch (ignored: SecurityException) {+ // Not a headlessly grantable permission: nothing to do.+ } catch (ignored: IOException) {+ // Shell pipe failed: the permission stays ungranted and the+ // content assertions below report it.+ }+ }+ for (command in SPECIAL_ACCESS_COMMANDS) {+ try {+ uiAutomation.executeShellCommand(command.format(packageName)).close()+ } catch (ignored: SecurityException) {+ // Appop missing on this release: the gate assertion reports it.+ } catch (ignored: IOException) {+ // Shell pipe failed: the gate assertion below reports it.+ }+ }+ }++ private companion object {+ private const val CONTENT_TIMEOUT_MS = 15_000L+ private const val GATE_TIMEOUT_MS = 5_000L+ private const val MOVIES_LABEL = "Movies"+ private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++ /**+ * Special access behind some apps' gates: exact alarms + full-screen intent+ * have no pm-grantable permission, but the shell can flip their appops.+ * Ignored where the appop does not exist; the gate assertion reports it.+ */+ private val SPECIAL_ACCESS_COMMANDS = arrayOf(+ "appops set %s SCHEDULE_EXACT_ALARM allow",+ "appops set %s USE_FULL_SCREEN_INTENT allow",+ )+ }+}