Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/ime/OpenImeWindowToOverViewTest.kt

raw
1 /*
2 * Copyright (C) 2022 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.ime
18
19 import android.app.Instrumentation
20 import android.platform.test.annotations.Postsubmit
21 import android.platform.test.annotations.Presubmit
22 import android.platform.test.annotations.RequiresDevice
23 import android.view.Surface
24 import android.view.WindowManagerPolicyConstants
25 import androidx.test.filters.FlakyTest
26 import androidx.test.platform.app.InstrumentationRegistry
27 import com.android.server.wm.flicker.FlickerBuilderProvider
28 import com.android.server.wm.flicker.FlickerParametersRunnerFactory
29 import com.android.server.wm.flicker.FlickerTestParameter
30 import com.android.server.wm.flicker.FlickerTestParameterFactory
31 import com.android.server.wm.flicker.annotation.Group4
32 import com.android.server.wm.flicker.dsl.FlickerBuilder
33 import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled
34 import com.android.server.wm.flicker.helpers.ImeAppAutoFocusHelper
35 import com.android.server.wm.flicker.navBarLayerIsVisible
36 import com.android.server.wm.flicker.navBarWindowIsVisible
37 import com.android.server.wm.flicker.statusBarLayerIsVisible
38 import com.android.server.wm.flicker.statusBarWindowIsVisible
39 import com.android.server.wm.traces.common.FlickerComponentName
40 import com.android.server.wm.traces.common.WindowManagerConditionsFactory
41 import com.android.server.wm.traces.parser.windowmanager.WindowManagerStateHelper
42 import org.junit.Assume.assumeTrue
43 import org.junit.Assume.assumeFalse
44 import org.junit.FixMethodOrder
45 import org.junit.Test
46 import org.junit.runner.RunWith
47 import org.junit.runners.MethodSorters
48 import org.junit.runners.Parameterized
49
50 /**
51 * Test IME window layer will be associated with the app task when going to the overview screen.
52 * To run this test: `atest FlickerTests:OpenImeWindowToOverViewTest`
53 */
54 @RequiresDevice
55 @RunWith(Parameterized::class)
56 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
57 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 @Group4
59 class OpenImeWindowToOverViewTest(private val testSpec: FlickerTestParameter) {
60 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
61 private val imeTestApp = ImeAppAutoFocusHelper(instrumentation, testSpec.startRotation)
62 private val statusBarInvisible = WindowManagerConditionsFactory.isStatusBarVisible().negate()
63 private val navBarInvisible = WindowManagerConditionsFactory.isNavBarVisible().negate()
64
65 @FlickerBuilderProvider
66 fun buildFlicker(): FlickerBuilder {
67 return FlickerBuilder(instrumentation).apply {
68 setup {
69 eachRun {
70 imeTestApp.launchViaIntent(wmHelper)
71 }
72 }
73 transitions {
74 device.pressRecentApps()
75 waitForRecentsActivityVisible(wmHelper)
76 waitNavStatusBarVisibility(wmHelper)
77 }
78 teardown {
79 test {
80 device.pressHome()
81 imeTestApp.exit(wmHelper)
82 }
83 }
84 }
85 }
86
87 /**
88 * The bars (including status bar and navigation bar) are expected to be hidden while
89 * entering overview in landscape if launcher is set to portrait only. Because
90 * "showing portrait overview (launcher) in landscape display" is an intermediate state
91 * depending on the touch-up to decide the intention of gesture, the display may keep in
92 * landscape if return to app, or change to portrait if the gesture is to swipe-to-home.
93 *
94 * So instead of showing landscape bars with portrait launcher at the same time
95 * (especially return-to-home that launcher workspace becomes visible), hide the bars until
96 * leave overview to have cleaner appearance.
97 *
98 * b/227189877
99 */
100 private fun waitNavStatusBarVisibility(wmHelper: WindowManagerStateHelper) {
101 when {
102 testSpec.isLandscapeOrSeascapeAtStart && !testSpec.isGesturalNavigation ->
103 wmHelper.waitFor(statusBarInvisible)
104 testSpec.isLandscapeOrSeascapeAtStart ->
105 wmHelper.waitFor(statusBarInvisible, navBarInvisible)
106 }
107 }
108
109 @Presubmit
110 @Test
111 fun navBarWindowIsVisible() = testSpec.navBarWindowIsVisible()
112
113 @Presubmit
114 @Test
115 fun statusBarWindowIsVisible() = testSpec.statusBarWindowIsVisible()
116
117 @Presubmit
118 @Test
119 fun imeWindowIsAlwaysVisible() {
120 testSpec.imeWindowIsAlwaysVisible()
121 }
122
123 @Presubmit
124 @Test
125 fun navBarLayerIsVisible3Button() {
126 assumeFalse(testSpec.isGesturalNavigation)
127 testSpec.navBarLayerIsVisible()
128 }
129
130 /**
131 * Bars are expected to be hidden while entering overview in landscape (b/227189877)
132 */
133 @Presubmit
134 @Test
135 fun navBarLayerIsVisibleInPortraitGestural() {
136 assumeFalse(testSpec.isLandscapeOrSeascapeAtStart)
137 assumeTrue(testSpec.isGesturalNavigation)
138 testSpec.navBarLayerIsVisible()
139 }
140
141 /**
142 * In the legacy transitions, the nav bar is not marked as invisible.
143 * In the new transitions this is fixed and the nav bar shows as invisible
144 */
145 @Postsubmit
146 @Test
147 fun navBarLayerIsInvisibleInLandscapeGestural() {
148 assumeTrue(testSpec.isLandscapeOrSeascapeAtStart)
149 assumeTrue(testSpec.isGesturalNavigation)
150 assumeTrue(isShellTransitionsEnabled)
151 testSpec.assertLayersStart {
152 this.isVisible(FlickerComponentName.NAV_BAR)
153 }
154 testSpec.assertLayersEnd {
155 this.isInvisible(FlickerComponentName.NAV_BAR)
156 }
157 }
158
159 @Postsubmit
160 @Test
161 fun statusBarLayerIsVisibleInPortrait() {
162 assumeFalse(testSpec.isLandscapeOrSeascapeAtStart)
163 testSpec.statusBarLayerIsVisible()
164 }
165
166 @Presubmit
167 @Test
168 fun statusBarLayerIsInvisibleInLandscape() {
169 assumeTrue(testSpec.isLandscapeOrSeascapeAtStart)
170 testSpec.assertLayersStart {
171 this.isVisible(FlickerComponentName.STATUS_BAR)
172 }
173 testSpec.assertLayersEnd {
174 this.isInvisible(FlickerComponentName.STATUS_BAR)
175 }
176 }
177
178 @FlakyTest(bugId = 228011606)
179 @Test
180 fun imeLayerIsVisibleAndAssociatedWithAppWidow() {
181 testSpec.assertLayersStart {
182 isVisible(FlickerComponentName.IME).visibleRegion(FlickerComponentName.IME)
183 .coversAtMost(isVisible(imeTestApp.component)
184 .visibleRegion(imeTestApp.component).region)
185 }
186 testSpec.assertLayers {
187 this.invoke("imeLayerIsVisibleAndAlignAppWidow") {
188 val imeVisibleRegion = it.visibleRegion(FlickerComponentName.IME)
189 val appVisibleRegion = it.visibleRegion(imeTestApp.component)
190 if (imeVisibleRegion.region.isNotEmpty) {
191 it.isVisible(FlickerComponentName.IME)
192 imeVisibleRegion.coversAtMost(appVisibleRegion.region)
193 }
194 }
195 }
196 }
197
198 private fun waitForRecentsActivityVisible(
199 wmHelper: WindowManagerStateHelper
200 ) {
201 val waitMsg = "state of Recents activity to be visible"
202 require(
203 wmHelper.waitFor(waitMsg) {
204 it.wmState.homeActivity?.let { act ->
205 it.wmState.isActivityVisible(act.name)
206 } == true ||
207 it.wmState.recentsActivity?.let { act ->
208 it.wmState.isActivityVisible(act.name)
209 } == true
210 }
211 ) { "Recents activity should be visible" }
212 wmHelper.waitForAppTransitionIdle()
213 // Ensure WindowManagerService wait until all animations have completed
214 instrumentation.uiAutomation.syncInputTransactions()
215 }
216
217 companion object {
218 /**
219 * Creates the test configurations.
220 *
221 * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring
222 * repetitions, screen orientation and navigation modes.
223 */
224 @Parameterized.Parameters(name = "{0}")
225 @JvmStatic
226 fun getParams(): Collection<FlickerTestParameter> {
227 return FlickerTestParameterFactory.getInstance()
228 .getConfigNonRotationTests(
229 repetitions = 1,
230 supportedRotations = listOf(Surface.ROTATION_0, Surface.ROTATION_90),
231 supportedNavigationModes = listOf(
232 WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY,
233 WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY
234 )
235 )
236 }
237 }
238 }