Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/launch/ActivitiesTransitionTest.kt

raw
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.server.wm.flicker.launch
18
19 import android.app.Instrumentation
20 import android.platform.test.annotations.Presubmit
21 import android.view.Display
22 import androidx.test.filters.RequiresDevice
23 import androidx.test.platform.app.InstrumentationRegistry
24 import com.android.server.wm.flicker.entireScreenCovered
25 import com.android.server.wm.flicker.FlickerBuilderProvider
26 import com.android.server.wm.flicker.FlickerParametersRunnerFactory
27 import com.android.server.wm.flicker.FlickerTestParameter
28 import com.android.server.wm.flicker.FlickerTestParameterFactory
29 import com.android.server.wm.flicker.LAUNCHER_COMPONENT
30 import com.android.server.wm.flicker.annotation.Group4
31 import com.android.server.wm.flicker.dsl.FlickerBuilder
32 import com.android.server.wm.flicker.helpers.TwoActivitiesAppHelper
33 import com.android.server.wm.flicker.testapp.ActivityOptions
34 import com.android.server.wm.traces.common.WindowManagerConditionsFactory
35 import com.android.server.wm.traces.parser.toFlickerComponent
36 import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
37 import org.junit.FixMethodOrder
38 import org.junit.Test
39 import org.junit.runner.RunWith
40 import org.junit.runners.MethodSorters
41 import org.junit.runners.Parameterized
42
43 /**
44 * Test the back and forward transition between 2 activities.
45 *
46 * To run this test: `atest FlickerTests:ActivitiesTransitionTest`
47 *
48 * Actions:
49 * Launch an app
50 * Launch a secondary activity within the app
51 * Close the secondary activity back to the initial one
52 *
53 * Notes:
54 * 1. Part of the test setup occurs automatically via
55 * [com.android.server.wm.flicker.TransitionRunnerWithRules],
56 * including configuring navigation mode, initial orientation and ensuring no
57 * apps are running before setup
58 */
59 @RequiresDevice
60 @RunWith(Parameterized::class)
61 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
62 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
63 @Group4
64 class ActivitiesTransitionTest(val testSpec: FlickerTestParameter) {
65 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
66 private val testApp: TwoActivitiesAppHelper = TwoActivitiesAppHelper(instrumentation)
67
68 /**
69 * Entry point for the test runner. It will use this method to initialize and cache
70 * flicker executions
71 */
72 @FlickerBuilderProvider
73 fun buildFlicker(): FlickerBuilder {
74 return FlickerBuilder(instrumentation).apply {
75 setup {
76 test {
77 testApp.launchViaIntent(wmHelper)
78 wmHelper.waitForFullScreenApp(testApp.component)
79 }
80 }
81 teardown {
82 test {
83 testApp.exit(wmHelper)
84 }
85 }
86 transitions {
87 testApp.openSecondActivity(device, wmHelper)
88 device.pressBack()
89 val firstActivityVisible = wmHelper.waitFor(
90 WindowManagerConditionsFactory.isAppTransitionIdle(Display.DEFAULT_DISPLAY),
91 WindowManagerStateHelper.isAppFullScreen(testApp.component))
92 require(firstActivityVisible) { "Expected ${testApp.component} to be visible" }
93 }
94 }
95 }
96
97 /**
98 * Checks that the [ActivityOptions.BUTTON_ACTIVITY_COMPONENT_NAME] activity is visible at
99 * the start of the transition, that
100 * [ActivityOptions.SIMPLE_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME] becomes visible during the
101 * transition, and that [ActivityOptions.BUTTON_ACTIVITY_COMPONENT_NAME] is again visible
102 * at the end
103 */
104 @Presubmit
105 @Test
106 fun finishSubActivity() {
107 val buttonActivityComponent = ActivityOptions
108 .BUTTON_ACTIVITY_COMPONENT_NAME.toFlickerComponent()
109 val imeAutoFocusActivityComponent = ActivityOptions
110 .SIMPLE_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME.toFlickerComponent()
111 testSpec.assertWm {
112 this.isAppWindowOnTop(buttonActivityComponent)
113 .then()
114 .isAppWindowOnTop(imeAutoFocusActivityComponent)
115 .then()
116 .isAppWindowOnTop(buttonActivityComponent)
117 }
118 }
119
120 /**
121 * Checks that all parts of the screen are covered during the transition
122 */
123 @Presubmit
124 @Test
125 fun entireScreenCovered() = testSpec.entireScreenCovered()
126
127 /**
128 * Checks that the [LAUNCHER_COMPONENT] window is not on top. The launcher cannot be
129 * asserted with `isAppWindowVisible` because it contains 2 windows with the exact same name,
130 * and both are never simultaneously visible
131 */
132 @Presubmit
133 @Test
134 fun launcherWindowNotOnTop() {
135 testSpec.assertWm {
136 this.isAppWindowNotOnTop(LAUNCHER_COMPONENT)
137 }
138 }
139
140 /**
141 * Checks that the [LAUNCHER_COMPONENT] layer is never visible during the transition
142 */
143 @Presubmit
144 @Test
145 fun launcherLayerNotVisible() {
146 testSpec.assertLayers { this.isInvisible(LAUNCHER_COMPONENT) }
147 }
148
149 companion object {
150 /**
151 * Creates the test configurations.
152 *
153 * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring
154 * repetitions, screen orientation and navigation modes.
155 */
156 @Parameterized.Parameters(name = "{0}")
157 @JvmStatic
158 fun getParams(): Collection<FlickerTestParameter> {
159 return FlickerTestParameterFactory.getInstance()
160 .getConfigNonRotationTests(repetitions = 3)
161 }
162 }
163 }