diff options
7 files changed, 98 insertions, 87 deletions
diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationColdTest.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationColdTest.kt index 6819a38c9067..620502e521c4 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationColdTest.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationColdTest.kt @@ -25,6 +25,7 @@ import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.LegacyFlickerTest import android.tools.device.flicker.legacy.LegacyFlickerTestFactory +import android.tools.device.helpers.wakeUpAndGoToHomeScreen import androidx.test.filters.RequiresDevice import org.junit.ClassRule import org.junit.FixMethodOrder @@ -49,21 +50,23 @@ import org.junit.runners.Parameterized open class OpenAppFromLockscreenNotificationColdTest(flicker: LegacyFlickerTest) : OpenAppFromNotificationColdTest(flicker) { - override val openingNotificationsFromLockScreen = true - override val transition: FlickerBuilder.() -> Unit get() = { - // Needs to run at start of transition, - // so before the transition defined in super.transition - transitions { device.wakeUp() } - - super.transition(this) + transitions { + device.wakeUp() + openAppFromLockNotification() + } // Needs to run at the end of the setup, so after the setup defined in super.transition setup { + device.wakeUpAndGoToHomeScreen() + launchAppAndPostNotification() + clearOverview() device.sleep() wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify() } + + teardown { testApp.exit(wmHelper) } } /** {@inheritDoc} */ diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWarmTest.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWarmTest.kt index 972221640363..2a458ef82448 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWarmTest.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWarmTest.kt @@ -49,21 +49,22 @@ import org.junit.runners.Parameterized class OpenAppFromLockscreenNotificationWarmTest(flicker: LegacyFlickerTest) : OpenAppFromNotificationWarmTest(flicker) { - override val openingNotificationsFromLockScreen = true - override val transition: FlickerBuilder.() -> Unit get() = { - // Needs to run at start of transition, - // so before the transition defined in super.transition - transitions { device.wakeUp() } - - super.transition(this) + transitions { + device.wakeUp() + openAppFromLockNotification() + } // Needs to run at the end of the setup, so after the setup defined in super.transition setup { + launchAppAndPostNotification() + goHome() device.sleep() wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify() } + + teardown { testApp.exit(wmHelper) } } /** diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWithOverlayAppTest.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWithOverlayAppTest.kt index ffd81716e728..00aad2783d5d 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWithOverlayAppTest.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromLockscreenNotificationWithOverlayAppTest.kt @@ -51,21 +51,21 @@ class OpenAppFromLockscreenNotificationWithOverlayAppTest(flicker: LegacyFlicker OpenAppFromLockscreenNotificationColdTest(flicker) { private val showWhenLockedApp = ShowWhenLockedAppHelper(instrumentation) - // Although we are technically still locked here, the overlay app means we should open the - // notification shade as if we were unlocked. - override val openingNotificationsFromLockScreen = false - override val transition: FlickerBuilder.() -> Unit get() = { - super.transition(this) - transitions { + device.wakeUp() + // Although we are technically still locked here, the overlay app means we should + // open the + // notification shade as if we were unlocked. + openAppFromNotification() wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify() } setup { device.wakeUpAndGoToHomeScreen() - + launchAppAndPostNotification() + clearOverview() // Launch an activity that is shown when the device is locked showWhenLockedApp.launchViaIntent(wmHelper) wmHelper.StateSyncBuilder().withFullScreenApp(showWhenLockedApp).waitForAndVerify() @@ -74,7 +74,10 @@ class OpenAppFromLockscreenNotificationWithOverlayAppTest(flicker: LegacyFlicker wmHelper.StateSyncBuilder().withoutTopVisibleAppWindows().waitForAndVerify() } - teardown { showWhenLockedApp.exit(wmHelper) } + teardown { + testApp.exit(wmHelper) + showWhenLockedApp.exit(wmHelper) + } } @Test diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationColdTest.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationColdTest.kt index fbdba7b71d0f..f8d78b5ddd1e 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationColdTest.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationColdTest.kt @@ -23,6 +23,8 @@ import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.LegacyFlickerTest import android.tools.device.flicker.legacy.LegacyFlickerTestFactory +import android.tools.device.helpers.wakeUpAndGoToHomeScreen +import com.android.server.wm.flicker.helpers.setRotation import com.android.server.wm.flicker.statusBarLayerPositionAtEnd import org.junit.FixMethodOrder import org.junit.Ignore @@ -45,16 +47,16 @@ open class OpenAppFromNotificationColdTest(flicker: LegacyFlickerTest) : /** {@inheritDoc} */ override val transition: FlickerBuilder.() -> Unit get() = { - super.transition(this) - setup { - // Close the app that posted the notification to trigger a cold start next time - // it is open - can't just kill it because that would remove the notification. - tapl.setExpectedRotationCheckEnabled(false) - tapl.goHome() - tapl.workspace.switchToOverview() - tapl.overview.dismissAllTasks() + device.wakeUpAndGoToHomeScreen() + this.setRotation(flicker.scenario.startRotation) + launchAppAndPostNotification() + clearOverview() } + + transitions { openAppFromNotification() } + + teardown { testApp.exit(wmHelper) } } @Presubmit @Test override fun appWindowBecomesVisible() = appWindowBecomesVisible_coldStart() diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationWarmTest.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationWarmTest.kt index 2aa444e45ea2..5c7ec46d6f04 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationWarmTest.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppFromNotificationWarmTest.kt @@ -21,6 +21,7 @@ import android.platform.test.annotations.Presubmit import android.tools.common.traces.component.ComponentNameMatcher import android.tools.device.flicker.junit.FlickerParametersRunnerFactory import android.tools.device.flicker.legacy.FlickerBuilder +import android.tools.device.flicker.legacy.FlickerTestData import android.tools.device.flicker.legacy.LegacyFlickerTest import android.tools.device.flicker.legacy.LegacyFlickerTestFactory import android.tools.device.helpers.wakeUpAndGoToHomeScreen @@ -55,63 +56,68 @@ open class OpenAppFromNotificationWarmTest(flicker: LegacyFlickerTest) : OpenAppTransition(flicker) { override val testApp: NotificationAppHelper = NotificationAppHelper(instrumentation) - open val openingNotificationsFromLockScreen = false - /** {@inheritDoc} */ override val transition: FlickerBuilder.() -> Unit get() = { setup { device.wakeUpAndGoToHomeScreen() this.setRotation(flicker.scenario.startRotation) - testApp.launchViaIntent(wmHelper) - wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify() - testApp.postNotification(wmHelper) - device.pressHome() - wmHelper - .StateSyncBuilder() - .withHomeActivityVisible() - .withWindowSurfaceDisappeared(ComponentNameMatcher.NOTIFICATION_SHADE) - .waitForAndVerify() + launchAppAndPostNotification() + goHome() } - transitions { - var startY = 10 - var endY = 3 * device.displayHeight / 4 - var steps = 25 - if (openingNotificationsFromLockScreen) { - val wm: WindowManager = - instrumentation.context.getSystemService(WindowManager::class.java) - ?: error("Unable to connect to WindowManager service") - val metricInsets = wm.currentWindowMetrics.windowInsets - val insets = - metricInsets.getInsetsIgnoringVisibility( - WindowInsets.Type.statusBars() or WindowInsets.Type.displayCutout() - ) - - startY = insets.top + 100 - endY = device.displayHeight / 2 - steps = 4 - } - - // Swipe down to show the notification shade - val x = device.displayWidth / 2 - device.swipe(x, startY, x, endY, steps) - device.waitForIdle(2000) - instrumentation.uiAutomation.syncInputTransactions() - - // Launch the activity by clicking the notification - val notification = - device.wait(Until.findObject(By.text("Flicker Test Notification")), 2000L) - notification?.click() ?: error("Notification not found") - instrumentation.uiAutomation.syncInputTransactions() - - // Wait for the app to launch - wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify() - } + transitions { openAppFromNotification() } teardown { testApp.exit(wmHelper) } } + protected fun FlickerTestData.launchAppAndPostNotification() { + testApp.launchViaIntent(wmHelper) + wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify() + testApp.postNotification(wmHelper) + } + + protected fun FlickerTestData.goHome() { + device.pressHome() + wmHelper + .StateSyncBuilder() + .withHomeActivityVisible() + .withWindowSurfaceDisappeared(ComponentNameMatcher.NOTIFICATION_SHADE) + .waitForAndVerify() + } + protected fun FlickerTestData.openAppFromNotification() { + doOpenAppAndWait(startY = 10, endY = 3 * device.displayHeight / 4, steps = 25) + } + + protected fun FlickerTestData.openAppFromLockNotification() { + val wm: WindowManager = + instrumentation.context.getSystemService(WindowManager::class.java) + ?: error("Unable to connect to WindowManager service") + val metricInsets = wm.currentWindowMetrics.windowInsets + val insets = + metricInsets.getInsetsIgnoringVisibility( + WindowInsets.Type.statusBars() or WindowInsets.Type.displayCutout() + ) + + doOpenAppAndWait(startY = insets.top + 100, endY = device.displayHeight / 2, steps = 4) + } + + protected fun FlickerTestData.doOpenAppAndWait(startY: Int, endY: Int, steps: Int) { + // Swipe down to show the notification shade + val x = device.displayWidth / 2 + device.swipe(x, startY, x, endY, steps) + device.waitForIdle(2000) + instrumentation.uiAutomation.syncInputTransactions() + + // Launch the activity by clicking the notification + val notification = + device.wait(Until.findObject(By.text("Flicker Test Notification")), 2000L) + notification?.click() ?: error("Notification not found") + instrumentation.uiAutomation.syncInputTransactions() + + // Wait for the app to launch + wmHelper.StateSyncBuilder().withFullScreenApp(testApp).waitForAndVerify() + } @Presubmit @Test override fun appWindowBecomesVisible() = appWindowBecomesVisible_warmStart() @Presubmit @Test override fun appLayerBecomesVisible() = appLayerBecomesVisible_warmStart() diff --git a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppTransition.kt b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppTransition.kt index 684b4b70f950..4e0e3c04ae5a 100644 --- a/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppTransition.kt +++ b/tests/FlickerTests/Notification/src/com/android/server/wm/flicker/notification/OpenAppTransition.kt @@ -19,26 +19,22 @@ package com.android.server.wm.flicker.notification import android.platform.test.annotations.Presubmit import android.tools.common.traces.component.ComponentNameMatcher import android.tools.device.apphelpers.StandardAppHelper -import android.tools.device.flicker.legacy.FlickerBuilder import android.tools.device.flicker.legacy.LegacyFlickerTest -import android.tools.device.helpers.wakeUpAndGoToHomeScreen import com.android.server.wm.flicker.BaseTest import com.android.server.wm.flicker.helpers.SimpleAppHelper -import com.android.server.wm.flicker.helpers.setRotation import org.junit.Test /** Base class for app launch tests */ abstract class OpenAppTransition(flicker: LegacyFlickerTest) : BaseTest(flicker) { protected open val testApp: StandardAppHelper = SimpleAppHelper(instrumentation) - /** {@inheritDoc} */ - override val transition: FlickerBuilder.() -> Unit = { - setup { - tapl.setExpectedRotation(flicker.scenario.startRotation.value) - device.wakeUpAndGoToHomeScreen() - this.setRotation(flicker.scenario.startRotation) - } - teardown { testApp.exit(wmHelper) } + protected fun clearOverview() { + // Close the app that posted the notification to trigger a cold start next time + // it is open - can't just kill it because that would remove the notification. + tapl.expectedRotationCheckEnabled = false + tapl.goHome() + tapl.workspace.switchToOverview() + tapl.overview.dismissAllTasks() } /** diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/ImeShownOnAppStartHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/ImeShownOnAppStartHelper.kt index e106f656ec64..d3cee645cd99 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/ImeShownOnAppStartHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/ImeShownOnAppStartHelper.kt @@ -121,7 +121,7 @@ constructor( else -> null } if (matcher != null && matcher.find()) { - return matcher.group(1).equals("VISIBLE") + return matcher.group(1) == "VISIBLE" } } return false |