Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppTransition.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 androidx.test.platform.app.InstrumentationRegistry
22 import com.android.server.wm.flicker.FlickerBuilderProvider
23 import com.android.server.wm.flicker.FlickerTestParameter
24 import com.android.server.wm.flicker.dsl.FlickerBuilder
25 import com.android.server.wm.flicker.helpers.SimpleAppHelper
26 import com.android.server.wm.flicker.helpers.StandardAppHelper
27 import com.android.server.wm.flicker.helpers.setRotation
28 import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
29 import com.android.server.wm.flicker.entireScreenCovered
30 import com.android.server.wm.flicker.navBarLayerIsVisible
31 import com.android.server.wm.flicker.navBarLayerRotatesAndScales
32 import com.android.server.wm.flicker.navBarWindowIsVisible
33 import com.android.server.wm.flicker.statusBarLayerIsVisible
34 import com.android.server.wm.flicker.statusBarLayerRotatesScales
35 import com.android.server.wm.flicker.statusBarWindowIsVisible
36 import com.android.server.wm.traces.common.FlickerComponentName
37 import org.junit.Test
38
39 /**
40 * Base class for app launch tests
41 */
42 abstract class OpenAppTransition(protected val testSpec: FlickerTestParameter) {
43 protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
44 protected open val testApp: StandardAppHelper = SimpleAppHelper(instrumentation)
45
46 /**
47 * Defines the transition used to run the test
48 */
49 protected open val transition: FlickerBuilder.() -> Unit = {
50 setup {
51 test {
52 device.wakeUpAndGoToHomeScreen()
53 this.setRotation(testSpec.startRotation)
54 }
55 }
56 teardown {
57 test {
58 testApp.exit(wmHelper)
59 }
60 }
61 }
62
63 /**
64 * Entry point for the test runner. It will use this method to initialize and cache
65 * flicker executions
66 */
67 @FlickerBuilderProvider
68 fun buildFlicker(): FlickerBuilder {
69 return FlickerBuilder(instrumentation).apply {
70 transition()
71 }
72 }
73
74 /**
75 * Checks that the navigation bar window is visible during the whole transition
76 */
77 open fun navBarWindowIsVisible() {
78 testSpec.navBarWindowIsVisible()
79 }
80
81 /**
82 * Checks that the navigation bar layer is visible at the start and end of the trace
83 */
84 open fun navBarLayerIsVisible() {
85 testSpec.navBarLayerIsVisible()
86 }
87
88 /**
89 * Checks the position of the navigation bar at the start and end of the transition
90 */
91 @Presubmit
92 @Test
93 open fun navBarLayerRotatesAndScales() = testSpec.navBarLayerRotatesAndScales()
94
95 /**
96 * Checks that the status bar window is visible during the whole transition
97 */
98 @Presubmit
99 @Test
100 open fun statusBarWindowIsVisible() {
101 testSpec.statusBarWindowIsVisible()
102 }
103
104 /**
105 * Checks that the status bar layer is visible at the start and end of the trace
106 */
107 @Presubmit
108 @Test
109 open fun statusBarLayerIsVisible() {
110 testSpec.statusBarLayerIsVisible()
111 }
112
113 /**
114 * Checks the position of the status bar at the start and end of the transition
115 */
116 @Presubmit
117 @Test
118 open fun statusBarLayerRotatesScales() = testSpec.statusBarLayerRotatesScales()
119
120 /**
121 * Checks that all windows that are visible on the trace, are visible for at least 2
122 * consecutive entries.
123 */
124 @Presubmit
125 @Test
126 open fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
127 testSpec.assertWm {
128 this.visibleWindowsShownMoreThanOneConsecutiveEntry()
129 }
130 }
131
132 /**
133 * Checks that all layers that are visible on the trace, are visible for at least 2
134 * consecutive entries.
135 */
136 @Presubmit
137 @Test
138 open fun visibleLayersShownMoreThanOneConsecutiveEntry() {
139 testSpec.assertLayers {
140 this.visibleLayersShownMoreThanOneConsecutiveEntry()
141 }
142 }
143
144 /**
145 * Checks that all parts of the screen are covered during the transition
146 */
147 @Presubmit
148 @Test
149 open fun entireScreenCovered() = testSpec.entireScreenCovered()
150
151 /**
152 * Checks that the app layer doesn't exist or is invisible at the start of the transition, but
153 * is created and/or becomes visible during the transition.
154 */
155 @Presubmit
156 @Test
157 open fun appLayerBecomesVisible() = appLayerBecomesVisible_coldStart()
158
159 protected fun appLayerBecomesVisible_coldStart() {
160 testSpec.assertLayers {
161 this.notContains(testApp.component)
162 .then()
163 .isInvisible(testApp.component, isOptional = true)
164 .then()
165 .isVisible(FlickerComponentName.SNAPSHOT, isOptional = true)
166 .then()
167 .isVisible(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
168 .then()
169 .isVisible(testApp.component)
170 }
171 }
172
173 protected fun appLayerBecomesVisible_warmStart() {
174 testSpec.assertLayers {
175 this.isInvisible(testApp.component)
176 .then()
177 .isVisible(FlickerComponentName.SNAPSHOT, isOptional = true)
178 .then()
179 .isVisible(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
180 .then()
181 .isVisible(testApp.component)
182 }
183 }
184
185 /**
186 * Checks that the app window doesn't exist at the start of the transition, that it is
187 * created (invisible - optional) and becomes visible during the transition
188 *
189 * The `isAppWindowInvisible` step is optional because we log once per frame, upon logging,
190 * the window may be visible or not depending on what was processed until that moment.
191 */
192 @Presubmit
193 @Test
194 open fun appWindowBecomesVisible() = appWindowBecomesVisible_coldStart()
195
196 protected fun appWindowBecomesVisible_coldStart() {
197 testSpec.assertWm {
198 this.notContains(testApp.component)
199 .then()
200 .isAppWindowInvisible(testApp.component, isOptional = true)
201 .then()
202 .isAppWindowVisible(testApp.component)
203 }
204 }
205
206 protected fun appWindowBecomesVisible_warmStart() {
207 testSpec.assertWm {
208 this.isAppWindowInvisible(testApp.component)
209 .then()
210 .isAppWindowVisible(FlickerComponentName.SNAPSHOT, isOptional = true)
211 .then()
212 .isAppWindowVisible(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
213 .then()
214 .isAppWindowVisible(testApp.component)
215 }
216 }
217
218 /**
219 * Checks that [testApp] window is not on top at the start of the transition, and then becomes
220 * the top visible window until the end of the transition.
221 */
222 @Presubmit
223 @Test
224 open fun appWindowBecomesTopWindow() {
225 testSpec.assertWm {
226 this.isAppWindowNotOnTop(testApp.component)
227 .then()
228 .isAppWindowOnTop(FlickerComponentName.SNAPSHOT, isOptional = true)
229 .then()
230 .isAppWindowOnTop(FlickerComponentName.SPLASH_SCREEN, isOptional = true)
231 .then()
232 .isAppWindowOnTop(testApp.component)
233 }
234 }
235 }