Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/ime/SwitchImeWindowsFromGestureNavTest.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.ime
18
19 import android.app.Instrumentation
20 import android.platform.test.annotations.Presubmit
21 import android.view.Display
22 import android.view.Surface
23 import android.view.WindowManagerPolicyConstants
24 import androidx.test.filters.RequiresDevice
25 import androidx.test.platform.app.InstrumentationRegistry
26 import com.android.server.wm.flicker.dsl.FlickerBuilder
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.helpers.ImeAppAutoFocusHelper
33 import com.android.server.wm.flicker.helpers.SimpleAppHelper
34 import com.android.server.wm.flicker.helpers.WindowUtils
35 import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled
36 import com.android.server.wm.flicker.helpers.setRotation
37 import com.android.server.wm.flicker.navBarWindowIsVisible
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
43 import org.junit.Before
44
45 import org.junit.FixMethodOrder
46 import org.junit.Test
47 import org.junit.runner.RunWith
48 import org.junit.runners.MethodSorters
49 import org.junit.runners.Parameterized
50
51 /**
52 * Test IME windows switching with 2-Buttons or gestural navigation.
53 * To run this test: `atest FlickerTests:SwitchImeWindowsFromGestureNavTest`
54 */
55 @RequiresDevice
56 @RunWith(Parameterized::class)
57 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
58 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
59 @Group4
60 @Presubmit
61 open class SwitchImeWindowsFromGestureNavTest(private val testSpec: FlickerTestParameter) {
62 private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
63 private val testApp = SimpleAppHelper(instrumentation)
64 private val imeTestApp = ImeAppAutoFocusHelper(instrumentation, testSpec.startRotation)
65
66 @Before
67 open fun before() {
68 Assume.assumeFalse(isShellTransitionsEnabled)
69 }
70
71 @FlickerBuilderProvider
72 fun buildFlicker(): FlickerBuilder {
73 return FlickerBuilder(instrumentation).apply {
74 setup {
75 eachRun {
76 this.setRotation(testSpec.startRotation)
77 testApp.launchViaIntent(wmHelper)
78 val testAppVisible = wmHelper.waitFor(
79 WindowManagerStateHelper.isAppFullScreen(testApp.component),
80 WindowManagerConditionsFactory.isAppTransitionIdle(
81 Display.DEFAULT_DISPLAY))
82 require(testAppVisible) {
83 "Expected ${testApp.component.toWindowName()} to be visible"
84 }
85
86 imeTestApp.launchViaIntent(wmHelper)
87 val imeAppVisible = wmHelper.waitFor(
88 WindowManagerStateHelper.isAppFullScreen(imeTestApp.component),
89 WindowManagerConditionsFactory.isAppTransitionIdle(
90 Display.DEFAULT_DISPLAY))
91 require(imeAppVisible) {
92 "Expected ${imeTestApp.component.toWindowName()} to be visible"
93 }
94
95 imeTestApp.openIME(device, wmHelper)
96 }
97 }
98 teardown {
99 eachRun {
100 device.pressHome()
101 wmHelper.waitForHomeActivityVisible()
102 testApp.exit()
103 imeTestApp.exit()
104 }
105 }
106 transitions {
107 // [Step1]: Swipe right from imeTestApp to testApp task
108 createTag(TAG_IME_VISIBLE)
109 val displayBounds = WindowUtils.getDisplayBounds(testSpec.startRotation)
110 device.swipe(0, displayBounds.bounds.height,
111 displayBounds.bounds.width, displayBounds.bounds.height, 50)
112
113 wmHelper.waitForFullScreenApp(testApp.component)
114 wmHelper.waitForAppTransitionIdle()
115 createTag(TAG_IME_INVISIBLE)
116 }
117 transitions {
118 // [Step2]: Swipe left to back to imeTestApp task
119 val displayBounds = WindowUtils.getDisplayBounds(testSpec.startRotation)
120 device.swipe(displayBounds.bounds.width, displayBounds.bounds.height,
121 0, displayBounds.bounds.height, 50)
122 wmHelper.waitForFullScreenApp(imeTestApp.component)
123 }
124 }
125 }
126
127 @Test
128 fun imeAppWindowVisibility() {
129 testSpec.assertWm {
130 isAppWindowVisible(imeTestApp.component)
131 .then()
132 .isAppSnapshotStartingWindowVisibleFor(testApp.component, isOptional = true)
133 .then()
134 .isAppWindowVisible(testApp.component)
135 .then()
136 .isAppSnapshotStartingWindowVisibleFor(imeTestApp.component, isOptional = true)
137 .then()
138 .isAppWindowVisible(imeTestApp.component)
139 }
140 }
141
142 @Test
143 fun navBarLayerIsVisibleAroundSwitching() {
144 testSpec.assertLayersStart {
145 isVisible(FlickerComponentName.NAV_BAR)
146 }
147 testSpec.assertLayersEnd {
148 isVisible(FlickerComponentName.NAV_BAR)
149 }
150 }
151
152 @Test
153 fun statusBarLayerIsVisibleAroundSwitching() {
154 testSpec.assertLayersStart {
155 isVisible(FlickerComponentName.STATUS_BAR)
156 }
157 testSpec.assertLayersEnd {
158 isVisible(FlickerComponentName.STATUS_BAR)
159 }
160 }
161
162 @Test
163 fun imeLayerIsVisibleWhenSwitchingToImeApp() {
164 testSpec.assertLayersStart {
165 isVisible(FlickerComponentName.IME)
166 }
167 testSpec.assertLayersTag(TAG_IME_VISIBLE) {
168 isVisible(FlickerComponentName.IME)
169 }
170 testSpec.assertLayersEnd {
171 isVisible(FlickerComponentName.IME)
172 }
173 }
174
175 @Test
176 fun imeLayerIsInvisibleWhenSwitchingToTestApp() {
177 testSpec.assertLayersTag(TAG_IME_INVISIBLE) {
178 isInvisible(FlickerComponentName.IME)
179 }
180 }
181
182 @Test
183 fun navBarWindowIsVisible() = testSpec.navBarWindowIsVisible()
184
185 @Test
186 fun statusBarWindowIsVisible() = testSpec.statusBarWindowIsVisible()
187
188 companion object {
189 @Parameterized.Parameters(name = "{0}")
190 @JvmStatic
191 fun getParams(): Collection<FlickerTestParameter> {
192 return FlickerTestParameterFactory.getInstance()
193 .getConfigNonRotationTests(
194 repetitions = 3,
195 supportedNavigationModes = listOf(
196 WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY
197 ),
198 supportedRotations = listOf(Surface.ROTATION_0)
199 )
200 }
201
202 private const val TAG_IME_VISIBLE = "imeVisible"
203 private const val TAG_IME_INVISIBLE = "imeInVisible"
204 }
205 }