| 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.quickswitch |
| 18 |
|
| 19 |
import android.app.Instrumentation |
| 20 |
import android.platform.test.annotations.Presubmit |
| 21 |
import android.platform.test.annotations.RequiresDevice |
| 22 |
import android.view.Surface |
| 23 |
import android.view.WindowManagerPolicyConstants |
| 24 |
import androidx.test.platform.app.InstrumentationRegistry |
| 25 |
import com.android.launcher3.tapl.LauncherInstrumentation |
| 26 |
import com.android.server.wm.flicker.FlickerBuilderProvider |
| 27 |
import com.android.server.wm.flicker.FlickerParametersRunnerFactory |
| 28 |
import com.android.server.wm.flicker.FlickerTestParameter |
| 29 |
import com.android.server.wm.flicker.FlickerTestParameterFactory |
| 30 |
import com.android.server.wm.flicker.LAUNCHER_COMPONENT |
| 31 |
import com.android.server.wm.flicker.annotation.Group1 |
| 32 |
import com.android.server.wm.flicker.dsl.FlickerBuilder |
| 33 |
import com.android.server.wm.flicker.helpers.NonResizeableAppHelper |
| 34 |
import com.android.server.wm.flicker.helpers.SimpleAppHelper |
| 35 |
import com.android.server.wm.flicker.helpers.WindowUtils |
| 36 |
import com.android.server.wm.flicker.helpers.isShellTransitionsEnabled |
| 37 |
import com.android.server.wm.flicker.navBarLayerIsVisible |
| 38 |
import com.android.server.wm.flicker.navBarLayerRotatesAndScales |
| 39 |
import com.android.server.wm.flicker.navBarWindowIsVisible |
| 40 |
import com.android.server.wm.flicker.statusBarLayerIsVisible |
| 41 |
import com.android.server.wm.flicker.statusBarWindowIsVisible |
| 42 |
import com.android.server.wm.traces.common.FlickerComponentName |
| 43 |
import org.junit.Assume |
| 44 |
import org.junit.Before |
| 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 quick switching back to previous app from last opened app |
| 53 |
* |
| 54 |
* To run this test: `atest FlickerTests:QuickSwitchBetweenTwoAppsBackTest` |
| 55 |
* |
| 56 |
* Actions: |
| 57 |
* Launch an app [testApp1] |
| 58 |
* Launch another app [testApp2] |
| 59 |
* Swipe right from the bottom of the screen to quick switch back to the first app [testApp1] |
| 60 |
* |
| 61 |
*/ |
| 62 |
@RequiresDevice |
| 63 |
@RunWith(Parameterized::class) |
| 64 |
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) |
| 65 |
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 66 |
@Group1 |
| 67 |
open class QuickSwitchBetweenTwoAppsBackTest(private val testSpec: FlickerTestParameter) { |
| 68 |
private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() |
| 69 |
private val taplInstrumentation = LauncherInstrumentation() |
| 70 |
|
| 71 |
private val testApp1 = SimpleAppHelper(instrumentation) |
| 72 |
private val testApp2 = NonResizeableAppHelper(instrumentation) |
| 73 |
|
| 74 |
private val startDisplayBounds = WindowUtils.getDisplayBounds(testSpec.startRotation) |
| 75 |
|
| 76 |
@Before |
| 77 |
open fun before() { |
| 78 |
Assume.assumeFalse(isShellTransitionsEnabled) |
| 79 |
} |
| 80 |
|
| 81 |
@FlickerBuilderProvider |
| 82 |
fun buildFlicker(): FlickerBuilder { |
| 83 |
return FlickerBuilder(instrumentation).apply { |
| 84 |
setup { |
| 85 |
test { |
| 86 |
taplInstrumentation.setExpectedRotation(testSpec.startRotation) |
| 87 |
} |
| 88 |
|
| 89 |
eachRun { |
| 90 |
testApp1.launchViaIntent(wmHelper) |
| 91 |
wmHelper.waitForFullScreenApp(testApp1.component) |
| 92 |
|
| 93 |
testApp2.launchViaIntent(wmHelper) |
| 94 |
wmHelper.waitForFullScreenApp(testApp2.component) |
| 95 |
} |
| 96 |
} |
| 97 |
transitions { |
| 98 |
taplInstrumentation.launchedAppState.quickSwitchToPreviousApp() |
| 99 |
wmHelper.waitForFullScreenApp(testApp1.component) |
| 100 |
wmHelper.waitForAppTransitionIdle() |
| 101 |
wmHelper.waitForNavBarStatusBarVisible() |
| 102 |
} |
| 103 |
|
| 104 |
teardown { |
| 105 |
test { |
| 106 |
testApp1.exit() |
| 107 |
testApp2.exit() |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Checks that the transition starts with [testApp2]'s windows filling/covering exactly the |
| 115 |
* entirety of the display. |
| 116 |
*/ |
| 117 |
@Presubmit |
| 118 |
@Test |
| 119 |
fun startsWithApp2WindowsCoverFullScreen() { |
| 120 |
testSpec.assertWmStart { |
| 121 |
this.frameRegion(testApp2.component).coversExactly(startDisplayBounds) |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Checks that the transition starts with [testApp2]'s layers filling/covering exactly the |
| 127 |
* entirety of the display. |
| 128 |
*/ |
| 129 |
@Presubmit |
| 130 |
@Test |
| 131 |
fun startsWithApp2LayersCoverFullScreen() { |
| 132 |
testSpec.assertLayersStart { |
| 133 |
this.visibleRegion(testApp2.component).coversExactly(startDisplayBounds) |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Checks that the transition starts with [testApp2] being the top window. |
| 139 |
*/ |
| 140 |
@Presubmit |
| 141 |
@Test |
| 142 |
fun startsWithApp2WindowBeingOnTop() { |
| 143 |
testSpec.assertWmStart { |
| 144 |
this.isAppWindowOnTop(testApp2.component) |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Checks that [testApp1] windows fill the entire screen (i.e. is "fullscreen") at the end of the |
| 150 |
* transition once we have fully quick switched from [testApp2] back to the [testApp1]. |
| 151 |
*/ |
| 152 |
@Presubmit |
| 153 |
@Test |
| 154 |
fun endsWithApp1WindowsCoveringFullScreen() { |
| 155 |
testSpec.assertWmEnd { |
| 156 |
this.frameRegion(testApp1.component).coversExactly(startDisplayBounds) |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Checks that [testApp1] layers fill the entire screen (i.e. is "fullscreen") at the end of the |
| 162 |
* transition once we have fully quick switched from [testApp2] back to the [testApp1]. |
| 163 |
*/ |
| 164 |
@Presubmit |
| 165 |
@Test |
| 166 |
fun endsWithApp1LayersCoveringFullScreen() { |
| 167 |
testSpec.assertLayersEnd { |
| 168 |
this.visibleRegion(testApp1.component).coversExactly(startDisplayBounds) |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Checks that [testApp1] is the top window at the end of the transition once we have fully quick |
| 174 |
* switched from [testApp2] back to the [testApp1]. |
| 175 |
*/ |
| 176 |
@Presubmit |
| 177 |
@Test |
| 178 |
fun endsWithApp1BeingOnTop() { |
| 179 |
testSpec.assertWmEnd { |
| 180 |
this.isAppWindowOnTop(testApp1.component) |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Checks that [testApp1]'s window starts off invisible and becomes visible at some point before |
| 186 |
* the end of the transition and then stays visible until the end of the transition. |
| 187 |
*/ |
| 188 |
@Presubmit |
| 189 |
@Test |
| 190 |
fun app1WindowBecomesAndStaysVisible() { |
| 191 |
testSpec.assertWm { |
| 192 |
this.isAppWindowInvisible(testApp1.component) |
| 193 |
.then() |
| 194 |
.isAppWindowVisible(FlickerComponentName.SNAPSHOT, isOptional = true) |
| 195 |
.then() |
| 196 |
.isAppWindowVisible(testApp1.component) |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Checks that [testApp1]'s layer starts off invisible and becomes visible at some point before |
| 202 |
* the end of the transition and then stays visible until the end of the transition. |
| 203 |
*/ |
| 204 |
@Presubmit |
| 205 |
@Test |
| 206 |
fun app1LayerBecomesAndStaysVisible() { |
| 207 |
testSpec.assertLayers { |
| 208 |
this.isInvisible(testApp1.component) |
| 209 |
.then() |
| 210 |
.isVisible(testApp1.component) |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Checks that [testApp2]'s window starts off visible and becomes invisible at some point before |
| 216 |
* the end of the transition and then stays invisible until the end of the transition. |
| 217 |
*/ |
| 218 |
@Presubmit |
| 219 |
@Test |
| 220 |
fun app2WindowBecomesAndStaysInvisible() { |
| 221 |
testSpec.assertWm { |
| 222 |
this.isAppWindowVisible(testApp2.component) |
| 223 |
.then() |
| 224 |
.isAppWindowInvisible(testApp2.component) |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Checks that [testApp2]'s layer starts off visible and becomes invisible at some point before |
| 230 |
* the end of the transition and then stays invisible until the end of the transition. |
| 231 |
*/ |
| 232 |
@Presubmit |
| 233 |
@Test |
| 234 |
fun app2LayerBecomesAndStaysInvisible() { |
| 235 |
testSpec.assertLayers { |
| 236 |
this.isVisible(testApp2.component) |
| 237 |
.then() |
| 238 |
.isInvisible(testApp2.component) |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Checks that [testApp2]'s window is visible at least until [testApp1]'s window is visible. |
| 244 |
* Ensures that at any point, either [testApp1] or [testApp2]'s windows are at least partially |
| 245 |
* visible. |
| 246 |
*/ |
| 247 |
@Presubmit |
| 248 |
@Test |
| 249 |
fun app1WindowIsVisibleOnceApp2WindowIsInvisible() { |
| 250 |
testSpec.assertWm { |
| 251 |
this.isAppWindowVisible(testApp2.component) |
| 252 |
.then() |
| 253 |
// TODO: Do we actually want to test this? Seems too implementation specific... |
| 254 |
.isAppWindowVisible(LAUNCHER_COMPONENT, isOptional = true) |
| 255 |
.then() |
| 256 |
.isAppWindowVisible(FlickerComponentName.SNAPSHOT, isOptional = true) |
| 257 |
.then() |
| 258 |
.isAppWindowVisible(testApp1.component) |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Checks that [testApp2]'s layer is visible at least until [testApp1]'s window is visible. |
| 264 |
* Ensures that at any point, either [testApp1] or [testApp2]'s windows are at least partially |
| 265 |
* visible. |
| 266 |
*/ |
| 267 |
@Presubmit |
| 268 |
@Test |
| 269 |
fun app1LayerIsVisibleOnceApp2LayerIsInvisible() { |
| 270 |
testSpec.assertLayers { |
| 271 |
this.isVisible(testApp2.component) |
| 272 |
.then() |
| 273 |
.isVisible(LAUNCHER_COMPONENT, isOptional = true) |
| 274 |
.then() |
| 275 |
.isVisible(FlickerComponentName.SNAPSHOT, isOptional = true) |
| 276 |
.then() |
| 277 |
.isVisible(testApp1.component) |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* Checks that the navbar window is visible throughout the entire transition. |
| 283 |
*/ |
| 284 |
@Presubmit |
| 285 |
@Test |
| 286 |
fun navBarWindowIsAlwaysVisible() = testSpec.navBarWindowIsVisible() |
| 287 |
|
| 288 |
/** |
| 289 |
* Checks that the navbar layer is visible throughout the entire transition. |
| 290 |
*/ |
| 291 |
@Presubmit |
| 292 |
@Test |
| 293 |
fun navBarLayerAlwaysIsVisible() = testSpec.navBarLayerIsVisible() |
| 294 |
|
| 295 |
/** |
| 296 |
* Checks that the navbar is always in the right position and covers the expected region. |
| 297 |
* |
| 298 |
* NOTE: This doesn't check that the navbar is visible or not. |
| 299 |
*/ |
| 300 |
@Presubmit |
| 301 |
@Test |
| 302 |
fun navbarIsAlwaysInRightPosition() = testSpec.navBarLayerRotatesAndScales() |
| 303 |
|
| 304 |
/** |
| 305 |
* Checks that the status bar window is visible throughout the entire transition. |
| 306 |
*/ |
| 307 |
@Presubmit |
| 308 |
@Test |
| 309 |
fun statusBarWindowIsAlwaysVisible() = testSpec.statusBarWindowIsVisible() |
| 310 |
|
| 311 |
/** |
| 312 |
* Checks that the status bar layer is visible throughout the entire transition. |
| 313 |
*/ |
| 314 |
@Presubmit |
| 315 |
@Test |
| 316 |
fun statusBarLayerIsAlwaysVisible() = testSpec.statusBarLayerIsVisible() |
| 317 |
|
| 318 |
companion object { |
| 319 |
@Parameterized.Parameters(name = "{0}") |
| 320 |
@JvmStatic |
| 321 |
fun getParams(): Collection<FlickerTestParameter> { |
| 322 |
return FlickerTestParameterFactory.getInstance() |
| 323 |
.getConfigNonRotationTests( |
| 324 |
repetitions = 3, |
| 325 |
supportedNavigationModes = listOf( |
| 326 |
WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY |
| 327 |
), |
| 328 |
supportedRotations = listOf(Surface.ROTATION_0, Surface.ROTATION_90) |
| 329 |
) |
| 330 |
} |
| 331 |
} |
| 332 |
} |