Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/close/CloseAppTransition.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.close
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.LAUNCHER_COMPONENT
25 import com.android.server.wm.flicker.dsl.FlickerBuilder
26 import com.android.server.wm.flicker.helpers.SimpleAppHelper
27 import com.android.server.wm.flicker.helpers.StandardAppHelper
28 import com.android.server.wm.flicker.helpers.setRotation
29 import com.android.server.wm.flicker.navBarLayerIsVisible
30 import com.android.server.wm.flicker.navBarLayerRotatesAndScales
31 import com.android.server.wm.flicker.navBarWindowIsVisible
32 import com.android.server.wm.flicker.entireScreenCovered
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.flicker.replacesLayer
37 import org.junit.Test
38
39 /**
40 * Base test class for transitions that close an app back to the launcher screen
41 */
42 abstract class CloseAppTransition(protected val testSpec: FlickerTestParameter) {
43 protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
44 protected open val testApp: StandardAppHelper = SimpleAppHelper(instrumentation)
45
46 /**
47 * Specification of the test transition to execute
48 */
49 protected open val transition: FlickerBuilder.() -> Unit = {
50 setup {
51 eachRun {
52 testApp.launchViaIntent(wmHelper)
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 @Presubmit
78 @Test
79 open fun navBarWindowIsVisible() {
80 testSpec.navBarWindowIsVisible()
81 }
82
83 /**
84 * Checks that the status bar window is visible during the whole transition
85 */
86 @Presubmit
87 @Test
88 open fun statusBarWindowIsVisible() {
89 testSpec.statusBarWindowIsVisible()
90 }
91
92 /**
93 * Checks that the navigation bar layer is visible during the whole transition
94 */
95 @Presubmit
96 @Test
97 open fun navBarLayerIsVisible() {
98 testSpec.navBarLayerIsVisible()
99 }
100
101 /**
102 * Checks that the status bar layer is visible during the whole transition
103 */
104 @Presubmit
105 @Test
106 open fun statusBarLayerIsVisible() {
107 testSpec.statusBarLayerIsVisible()
108 }
109
110 /**
111 * Checks the position of the navigation bar at the start and end of the transition
112 */
113 @Presubmit
114 @Test
115 open fun navBarLayerRotatesAndScales() = testSpec.navBarLayerRotatesAndScales()
116
117 /**
118 * Checks the position of the status bar at the start and end of the transition
119 */
120 @Presubmit
121 @Test
122 open fun statusBarLayerRotatesScales() = testSpec.statusBarLayerRotatesScales()
123
124 /**
125 * Checks that all windows that are visible on the trace, are visible for at least 2
126 * consecutive entries.
127 */
128 @Presubmit
129 @Test
130 open fun visibleWindowsShownMoreThanOneConsecutiveEntry() {
131 testSpec.assertWm {
132 this.visibleWindowsShownMoreThanOneConsecutiveEntry()
133 }
134 }
135
136 /**
137 * Checks that all layers that are visible on the trace, are visible for at least 2
138 * consecutive entries.
139 */
140 @Presubmit
141 @Test
142 open fun visibleLayersShownMoreThanOneConsecutiveEntry() {
143 testSpec.assertLayers {
144 this.visibleLayersShownMoreThanOneConsecutiveEntry()
145 }
146 }
147
148 /**
149 * Checks that all parts of the screen are covered during the transition
150 */
151 @Presubmit
152 @Test
153 open fun entireScreenCovered() = testSpec.entireScreenCovered()
154
155 /**
156 * Checks that [testApp] is the top visible app window at the start of the transition and
157 * that it is replaced by [LAUNCHER_COMPONENT] during the transition
158 */
159 @Presubmit
160 @Test
161 open fun launcherReplacesAppWindowAsTopWindow() {
162 testSpec.assertWm {
163 this.isAppWindowOnTop(testApp.component)
164 .then()
165 .isAppWindowOnTop(LAUNCHER_COMPONENT)
166 }
167 }
168
169 /**
170 * Checks that [LAUNCHER_COMPONENT] is invisible at the start of the transition and that
171 * it becomes visible during the transition
172 */
173 @Presubmit
174 @Test
175 open fun launcherWindowBecomesVisible() {
176 testSpec.assertWm {
177 this.isAppWindowNotOnTop(LAUNCHER_COMPONENT)
178 .then()
179 .isAppWindowOnTop(LAUNCHER_COMPONENT)
180 }
181 }
182
183 /**
184 * Checks that [LAUNCHER_COMPONENT] layer becomes visible when [testApp] becomes invisible
185 */
186 @Presubmit
187 @Test
188 open fun launcherLayerReplacesApp() {
189 testSpec.replacesLayer(testApp.component, LAUNCHER_COMPONENT)
190 }
191 }