From c2266ad6cb6ac8e5027b11c820296124d1ee5ae4 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Wed, 6 Apr 2022 11:17:03 +0000 Subject: [PATCH] Add Flicker tests for launching app from Notification CUJ Fixes: 227803517 Test: atest FlickerTests:OpenAppFromNotificationWarm FlickerTests:OpenAppFromNotificationCold FlickerTests:OpenAppFromLockNotificationWithLockOverlayApp FlickerTests:OpenAppFromLockNotificationWarm FlickerTests:OpenAppFromLockNotificationCold Change-Id: I88edaa4e5703d3a4667db890b63816523ffa450a --- .../flicker/helpers/NotificationAppHelper.kt | 53 ++++++ .../helpers/ShowWhenLockedAppHelper.kt | 34 ++++ .../launch/OpenAppFromLockNotificationCold.kt | 82 ++++++++ .../launch/OpenAppFromLockNotificationWarm.kt | 114 +++++++++++ ...pFromLockNotificationWithLockOverlayApp.kt | 120 ++++++++++++ .../launch/OpenAppFromNotificationCold.kt | 82 ++++++++ .../launch/OpenAppFromNotificationWarm.kt | 177 ++++++++++++++++++ .../test-apps/flickerapp/AndroidManifest.xml | 22 +++ .../res/drawable/ic_notification.xml | 24 +++ .../res/layout/notification_button.xml | 27 +++ .../wm/flicker/testapp/ActivityOptions.java | 10 + .../flicker/testapp/NotificationActivity.java | 80 ++++++++ .../testapp/ShowWhenLockedActivity.java | 33 ++++ 13 files changed, 858 insertions(+) create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/helpers/NotificationAppHelper.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ShowWhenLockedAppHelper.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationCold.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWarm.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWithLockOverlayApp.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationCold.kt create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationWarm.kt create mode 100644 tests/FlickerTests/test-apps/flickerapp/res/drawable/ic_notification.xml create mode 100644 tests/FlickerTests/test-apps/flickerapp/res/layout/notification_button.xml create mode 100644 tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/NotificationActivity.java create mode 100644 tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/ShowWhenLockedActivity.java diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/NotificationAppHelper.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/NotificationAppHelper.kt new file mode 100644 index 0000000000000..4e360f98723e3 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/NotificationAppHelper.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.helpers + +import android.app.Instrumentation +import android.support.test.launcherhelper.ILauncherStrategy +import android.support.test.launcherhelper.LauncherStrategyFactory +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.Until +import com.android.server.wm.flicker.testapp.ActivityOptions +import com.android.server.wm.traces.common.FlickerComponentName +import com.android.server.wm.traces.parser.toFlickerComponent +import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper + +class NotificationAppHelper @JvmOverloads constructor( + instr: Instrumentation, + launcherName: String = ActivityOptions.NOTIFICATION_ACTIVITY_LAUNCHER_NAME, + component: FlickerComponentName = + ActivityOptions.NOTIFICATION_ACTIVITY_COMPONENT_NAME.toFlickerComponent(), + launcherStrategy: ILauncherStrategy = LauncherStrategyFactory + .getInstance(instr) + .launcherStrategy +) : StandardAppHelper(instr, launcherName, component, launcherStrategy) { + fun postNotification(device: UiDevice, wmHelper: WindowManagerStateHelper) { + val button = device.wait( + Until.findObject(By.res(getPackage(), "post_notification")), + FIND_TIMEOUT) + + require(button != null) { + "Post notification button not found, this usually happens when the device " + + "was left in an unknown state (e.g. in split screen)" + } + button.click() + + device.wait(Until.findObject(By.text("Flicker Test Notification")), FIND_TIMEOUT) + ?: error("Flicker Notification not found") + } +} \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ShowWhenLockedAppHelper.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ShowWhenLockedAppHelper.kt new file mode 100644 index 0000000000000..bd2e5756b4a9b --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ShowWhenLockedAppHelper.kt @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.helpers + +import android.app.Instrumentation +import android.support.test.launcherhelper.ILauncherStrategy +import android.support.test.launcherhelper.LauncherStrategyFactory +import com.android.server.wm.flicker.testapp.ActivityOptions +import com.android.server.wm.traces.common.FlickerComponentName +import com.android.server.wm.traces.parser.toFlickerComponent + +class ShowWhenLockedAppHelper @JvmOverloads constructor( + instr: Instrumentation, + launcherName: String = ActivityOptions.SHOW_WHEN_LOCKED_ACTIVITY_LAUNCHER_NAME, + component: FlickerComponentName = + ActivityOptions.SHOW_WHEN_LOCKED_ACTIVITY_COMPONENT_NAME.toFlickerComponent(), + launcherStrategy: ILauncherStrategy = LauncherStrategyFactory + .getInstance(instr) + .launcherStrategy +) : StandardAppHelper(instr, launcherName, component, launcherStrategy) \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationCold.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationCold.kt new file mode 100644 index 0000000000000..8daf4ca696bf3 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationCold.kt @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.launch + +import android.platform.test.annotations.Postsubmit +import android.platform.test.annotations.RequiresDevice +import com.android.server.wm.flicker.FlickerParametersRunnerFactory +import com.android.server.wm.flicker.FlickerTestParameter +import com.android.server.wm.flicker.FlickerTestParameterFactory +import com.android.server.wm.flicker.annotation.Group1 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import org.junit.FixMethodOrder +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test cold launching an app from a notification from the lock screen. + * + * To run this test: `atest FlickerTests:OpenAppFromLockNotificationCold` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group1 +@Postsubmit +open class OpenAppFromLockNotificationCold(testSpec: FlickerTestParameter) + : OpenAppFromNotificationCold(testSpec) { + + 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) + + // Needs to run at the end of the setup, so after the setup defined in super.transition + setup { + eachRun { + device.sleep() + wmHelper.waitFor("noAppWindowsOnTop") { + it.wmState.topVisibleAppWindow.isEmpty() + } + } + } + } + + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring + * repetitions, screen orientation and navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return com.android.server.wm.flicker.FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests(repetitions = 3) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWarm.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWarm.kt new file mode 100644 index 0000000000000..8eb182a9fa319 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWarm.kt @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.launch + +import android.platform.test.annotations.Postsubmit +import android.platform.test.annotations.RequiresDevice +import com.android.server.wm.flicker.FlickerParametersRunnerFactory +import com.android.server.wm.flicker.FlickerTestParameter +import com.android.server.wm.flicker.FlickerTestParameterFactory +import com.android.server.wm.flicker.annotation.Group1 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import com.android.server.wm.traces.common.FlickerComponentName +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test warm launching an app from a notification from the lock screen. + * + * To run this test: `atest FlickerTests:OpenAppFromLockNotificationWarm` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group1 +@Postsubmit +open class OpenAppFromLockNotificationWarm(testSpec: FlickerTestParameter) + : OpenAppFromNotificationWarm(testSpec) { + + 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) + + // Needs to run at the end of the setup, so after the setup defined in super.transition + setup { + eachRun { + device.sleep() + wmHelper.waitFor("noAppWindowsOnTop") { + it.wmState.topVisibleAppWindow.isEmpty() + } + } + } + } + + /** + * Checks that we start of with no top windows and then [testApp] becomes the first and + * only top window of the transition, with snapshot or splash screen windows optionally showing + * first. + */ + @Test + @Postsubmit + open fun appWindowBecomesFirstAndOnlyTopWindow() { + testSpec.assertWm { + this.hasNoVisibleAppWindow() + .then() + .isAppWindowOnTop(FlickerComponentName.SNAPSHOT, isOptional = true) + .then() + .isAppWindowOnTop(FlickerComponentName.SPLASH_SCREEN, isOptional = true) + .then() + .isAppWindowOnTop(testApp.component) + } + } + + /** + * Checks that the screen is locked. + */ + @Test + @Postsubmit + fun screenLockedStart() { + testSpec.assertLayersStart { + isEmpty() + } + } + + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring + * repetitions, screen orientation and navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return com.android.server.wm.flicker.FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests(repetitions = 3) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWithLockOverlayApp.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWithLockOverlayApp.kt new file mode 100644 index 0000000000000..28a914b96449d --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromLockNotificationWithLockOverlayApp.kt @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.launch + +import android.platform.test.annotations.Postsubmit +import android.platform.test.annotations.RequiresDevice +import com.android.server.wm.flicker.FlickerParametersRunnerFactory +import com.android.server.wm.flicker.FlickerTestParameter +import com.android.server.wm.flicker.FlickerTestParameterFactory +import com.android.server.wm.flicker.annotation.Group1 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import com.android.server.wm.flicker.helpers.ShowWhenLockedAppHelper +import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen +import com.android.server.wm.traces.common.FlickerComponentName +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test cold launching an app from a notification from the lock screen when there is an app + * overlaid on the lock screen. + * + * To run this test: `atest FlickerTests:OpenAppFromLockNotificationWithLockOverlayApp` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group1 +@Postsubmit +class OpenAppFromLockNotificationWithLockOverlayApp(testSpec: FlickerTestParameter) + : OpenAppFromLockNotificationCold(testSpec) { + private val showWhenLockedApp: ShowWhenLockedAppHelper = + 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) + + setup { + eachRun { + device.wakeUpAndGoToHomeScreen() + + // Launch an activity that is shown when the device is locked + showWhenLockedApp.launchViaIntent(wmHelper) + wmHelper.waitForFullScreenApp(showWhenLockedApp.component) + + device.sleep() + wmHelper.waitFor("noAppWindowsOnTop") { + it.wmState.topVisibleAppWindow.isEmpty() + } + } + } + + teardown { + test { + showWhenLockedApp.exit(wmHelper) + } + } + } + + @Test + @Postsubmit + fun showWhenLockedAppWindowBecomesVisible() { + testSpec.assertWm { + this.hasNoVisibleAppWindow() + .then() + .isAppWindowOnTop(FlickerComponentName.SNAPSHOT, isOptional = true) + .then() + .isAppWindowOnTop(showWhenLockedApp.component) + } + } + + @Test + @Postsubmit + fun showWhenLockedAppLayerBecomesVisible() { + testSpec.assertLayers { + this.isInvisible(showWhenLockedApp.component) + .then() + .isVisible(FlickerComponentName.SNAPSHOT, isOptional = true) + .then() + .isVisible(showWhenLockedApp.component) + } + } + + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring + * repetitions, screen orientation and navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return com.android.server.wm.flicker.FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests(repetitions = 3) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationCold.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationCold.kt new file mode 100644 index 0000000000000..ee018ecfd25a6 --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationCold.kt @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.launch + +import android.platform.test.annotations.Postsubmit +import android.platform.test.annotations.RequiresDevice +import com.android.server.wm.flicker.FlickerParametersRunnerFactory +import com.android.server.wm.flicker.FlickerTestParameter +import com.android.server.wm.flicker.FlickerTestParameterFactory +import com.android.server.wm.flicker.annotation.Group1 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test cold launching an app from a notification. + * + * To run this test: `atest FlickerTests:OpenAppFromNotificationCold` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group1 +@Postsubmit +open class OpenAppFromNotificationCold(testSpec: FlickerTestParameter) + : OpenAppFromNotificationWarm(testSpec) { + override val transition: FlickerBuilder.() -> Unit + get() = { + super.transition(this) + + setup { + eachRun { + // 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. + taplInstrumentation.goHome() + taplInstrumentation.workspace.switchToOverview() + taplInstrumentation.overview.dismissAllTasks() + } + } + } + + @Test + @Postsubmit + override fun appWindowBecomesVisible() = appWindowBecomesVisible_coldStart() + + @Test + @Postsubmit + override fun appLayerBecomesVisible() = appLayerBecomesVisible_coldStart() + + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring + * repetitions, screen orientation and navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return com.android.server.wm.flicker.FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests(repetitions = 3) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationWarm.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationWarm.kt new file mode 100644 index 0000000000000..74f1fd781a51c --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppFromNotificationWarm.kt @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm.flicker.launch + +import android.platform.test.annotations.Postsubmit +import android.platform.test.annotations.RequiresDevice +import android.view.WindowInsets +import android.view.WindowManager +import androidx.test.uiautomator.By +import androidx.test.uiautomator.Until +import com.android.launcher3.tapl.LauncherInstrumentation +import com.android.server.wm.flicker.FlickerParametersRunnerFactory +import com.android.server.wm.flicker.FlickerTestParameter +import com.android.server.wm.flicker.FlickerTestParameterFactory +import com.android.server.wm.flicker.annotation.Group1 +import com.android.server.wm.flicker.dsl.FlickerBuilder +import com.android.server.wm.flicker.helpers.NotificationAppHelper +import com.android.server.wm.flicker.helpers.setRotation +import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized + +/** + * Test cold launching an app from a notification. + * + * To run this test: `atest FlickerTests:OpenAppFromNotificationWarm` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Group1 +@Postsubmit +open class OpenAppFromNotificationWarm(testSpec: FlickerTestParameter) + : OpenAppTransition(testSpec) { + protected val taplInstrumentation = LauncherInstrumentation() + + override val testApp: NotificationAppHelper = NotificationAppHelper(instrumentation) + + open val openingNotificationsFromLockScreen = false + + override val transition: FlickerBuilder.() -> Unit + get() = { + setup { + test { + device.wakeUpAndGoToHomeScreen() + this.setRotation(testSpec.startRotation) + } + eachRun { + testApp.launchViaIntent(wmHelper) + wmHelper.waitForFullScreenApp(testApp.component) + testApp.postNotification(device, wmHelper) + device.pressHome() + wmHelper.waitForAppTransitionIdle() + } + } + + transitions { + var startY = 10 + var endY = 3 * device.displayHeight / 4 + var steps = 25 + if (openingNotificationsFromLockScreen) { + val wm = instrumentation.context.getSystemService(WindowManager::class.java) + 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.waitForFullScreenApp(testApp.component) + } + + teardown { + test { + testApp.exit(wmHelper) + } + } + } + + @Test + @Postsubmit + override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales() + + @Test + @Postsubmit + override fun statusBarLayerIsVisible() = super.statusBarLayerIsVisible() + + @Test + @Postsubmit + override fun statusBarLayerRotatesScales() = super.statusBarLayerRotatesScales() + + @Test + @Postsubmit + override fun visibleLayersShownMoreThanOneConsecutiveEntry() = + super.visibleLayersShownMoreThanOneConsecutiveEntry() + + @Test + @Postsubmit + override fun appWindowBecomesVisible() = appWindowBecomesVisible_warmStart() + + @Test + @Postsubmit + override fun appLayerBecomesVisible() = appLayerBecomesVisible_warmStart() + + @Test + @Postsubmit + fun notificationAppWindowVisibleAtEnd() { + testSpec.assertWmEnd { + this.isAppWindowVisible(testApp.component) + } + } + + @Test + @Postsubmit + fun notificationAppWindowOnTopAtEnd() { + testSpec.assertWmEnd { + this.isAppWindowOnTop(testApp.component) + } + } + + @Test + @Postsubmit + fun notificationAppLayerVisibleAtEnd() { + testSpec.assertLayersEnd { + this.isVisible(testApp.component) + } + } + + companion object { + /** + * Creates the test configurations. + * + * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring + * repetitions, screen orientation and navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return FlickerTestParameterFactory.getInstance() + .getConfigNonRotationTests(repetitions = 3) + } + } +} \ No newline at end of file diff --git a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml index 7f513b21957f2..28422321f5b69 100644 --- a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml +++ b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml @@ -130,5 +130,27 @@ + + + + + + + + + + + + diff --git a/tests/FlickerTests/test-apps/flickerapp/res/drawable/ic_notification.xml b/tests/FlickerTests/test-apps/flickerapp/res/drawable/ic_notification.xml new file mode 100644 index 0000000000000..09bd44c108657 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/drawable/ic_notification.xml @@ -0,0 +1,24 @@ + + + + diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/notification_button.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/notification_button.xml new file mode 100644 index 0000000000000..78072006f681b --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/notification_button.xml @@ -0,0 +1,27 @@ + + + +