QaFormAutofillTest.kt

1.9 KB · raw

1package com.peachpasswords.qa23import androidx.test.ext.junit.runners.AndroidJUnit44import androidx.test.platform.app.InstrumentationRegistry5import java.io.BufferedReader6import java.io.InputStreamReader7import org.junit.Assert.assertTrue8import org.junit.Test9import org.junit.runner.RunWith1011/**12 * Emulator-QA probe: does the autofill framework issue fill requests for a13 * native form at all? Launches [QaFormActivity] in the TEST package (a14 * different package from the Peach autofill service, so the framework will15 * fill it), taps the username field, then reads `dumpsys autofill`16 * (shell-priv via UiAutomation) and asserts a session mentions the test17 * package. If this fails, autofill is blocked emulator-wide; if it passes,18 * a Chrome-specific problem is confirmed.19 */20@RunWith(AndroidJUnit4::class)21class QaFormAutofillTest {2223    @Test24    fun frameworkIssuesFillRequestForNativeForm() {25        shell("am start -n com.peachpasswords.debug.test/com.peachpasswords.qa.QaFormActivity")26        Thread.sleep(3000)27        // Username EditText: top of screen, full width (padding 48/96 in the activity).28        shell("input tap 360 150")29        Thread.sleep(4000)30        val dump = shell("dumpsys autofill")31        val mentions = dump.lineSequence()32            .filter { it.contains("com.peachpasswords.debug.test") }33            .take(10)34            .joinToString("\n")35        assertTrue(36            "no autofill session for the QA form — framework never issued a fill request.\n" +37                "dumpsys excerpt:\n$mentions",38            mentions.isNotEmpty(),39        )40    }4142    private fun shell(command: String): String {43        val instrumentation = InstrumentationRegistry.getInstrumentation()44        instrumentation.uiAutomation.executeShellCommand(command).use { pfd ->45            BufferedReader(InputStreamReader(android.os.ParcelFileDescriptor.AutoCloseInputStream(pfd))).use {46                return it.readText()47            }48        }49    }50}