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