| 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.launch |
| 18 |
|
| 19 |
import android.app.Instrumentation |
| 20 |
import android.app.WallpaperManager |
| 21 |
import android.platform.test.annotations.Postsubmit |
| 22 |
import androidx.test.filters.RequiresDevice |
| 23 |
import androidx.test.platform.app.InstrumentationRegistry |
| 24 |
import com.android.server.wm.flicker.FlickerBuilderProvider |
| 25 |
import com.android.server.wm.flicker.FlickerParametersRunnerFactory |
| 26 |
import com.android.server.wm.flicker.FlickerTestParameter |
| 27 |
import com.android.server.wm.flicker.FlickerTestParameterFactory |
| 28 |
import com.android.server.wm.flicker.LAUNCHER_COMPONENT |
| 29 |
import com.android.server.wm.flicker.annotation.Group4 |
| 30 |
import com.android.server.wm.flicker.dsl.FlickerBuilder |
| 31 |
import com.android.server.wm.flicker.entireScreenCovered |
| 32 |
import com.android.server.wm.flicker.helpers.NewTasksAppHelper |
| 33 |
import com.android.server.wm.flicker.helpers.WindowUtils |
| 34 |
import com.android.server.wm.flicker.navBarLayerIsVisible |
| 35 |
import com.android.server.wm.flicker.navBarWindowIsVisible |
| 36 |
import com.android.server.wm.flicker.statusBarLayerIsVisible |
| 37 |
import com.android.server.wm.flicker.statusBarWindowIsVisible |
| 38 |
import com.android.server.wm.flicker.testapp.ActivityOptions.LAUNCH_NEW_TASK_ACTIVITY_COMPONENT_NAME |
| 39 |
import com.android.server.wm.flicker.testapp.ActivityOptions.SIMPLE_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME |
| 40 |
import com.android.server.wm.traces.common.FlickerComponentName |
| 41 |
import com.android.server.wm.traces.common.FlickerComponentName.Companion.SPLASH_SCREEN |
| 42 |
import com.android.server.wm.traces.common.FlickerComponentName.Companion.WALLPAPER_BBQ_WRAPPER |
| 43 |
import com.android.server.wm.traces.parser.toFlickerComponent |
| 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 the back and forward transition between 2 activities. |
| 52 |
* |
| 53 |
* To run this test: `atest FlickerTests:ActivitiesTransitionTest` |
| 54 |
* |
| 55 |
* Actions: |
| 56 |
* Launch the NewTaskLauncherApp [mTestApp] |
| 57 |
* Open a new task (SimpleActivity) from the NewTaskLauncherApp [mTestApp] |
| 58 |
* Go back to the NewTaskLauncherApp [mTestApp] |
| 59 |
*/ |
| 60 |
@RequiresDevice |
| 61 |
@RunWith(Parameterized::class) |
| 62 |
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) |
| 63 |
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 64 |
@Group4 |
| 65 |
class TaskTransitionTest(val testSpec: FlickerTestParameter) { |
| 66 |
private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() |
| 67 |
private val mTestApp: NewTasksAppHelper = NewTasksAppHelper(instrumentation) |
| 68 |
private val mWallpaper by lazy { |
| 69 |
getWallpaperPackage(InstrumentationRegistry.getInstrumentation()) |
| 70 |
?: error("Unable to obtain wallpaper") |
| 71 |
} |
| 72 |
|
| 73 |
@FlickerBuilderProvider |
| 74 |
fun buildFlicker(): FlickerBuilder { |
| 75 |
return FlickerBuilder(instrumentation).apply { |
| 76 |
setup { |
| 77 |
eachRun { |
| 78 |
mTestApp.launchViaIntent(wmHelper) |
| 79 |
wmHelper.waitForFullScreenApp(mTestApp.component) |
| 80 |
} |
| 81 |
} |
| 82 |
teardown { |
| 83 |
test { |
| 84 |
mTestApp.exit() |
| 85 |
} |
| 86 |
} |
| 87 |
transitions { |
| 88 |
mTestApp.openNewTask(device, wmHelper) |
| 89 |
device.pressBack() |
| 90 |
wmHelper.waitForAppTransitionIdle() |
| 91 |
wmHelper.waitForFullScreenApp(mTestApp.component) |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Checks that the wallpaper window is never visible when performing task transitions. |
| 98 |
* A solid color background should be shown instead. |
| 99 |
*/ |
| 100 |
@Postsubmit |
| 101 |
@Test |
| 102 |
fun wallpaperWindowIsNeverVisible() { |
| 103 |
testSpec.assertWm { |
| 104 |
this.isNonAppWindowInvisible(mWallpaper) |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Checks that the wallpaper layer is never visible when performing task transitions. |
| 110 |
* A solid color background should be shown instead. |
| 111 |
*/ |
| 112 |
@Postsubmit |
| 113 |
@Test |
| 114 |
fun wallpaperLayerIsNeverVisible() { |
| 115 |
testSpec.assertLayers { |
| 116 |
this.isInvisible(mWallpaper) |
| 117 |
this.isInvisible(WALLPAPER_BBQ_WRAPPER) |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Check that the launcher window is never visible when performing task transitions. |
| 123 |
* A solid color background should be shown above it. |
| 124 |
*/ |
| 125 |
@Postsubmit |
| 126 |
@Test |
| 127 |
fun launcherWindowIsNeverVisible() { |
| 128 |
testSpec.assertWm { |
| 129 |
this.isAppWindowInvisible(LAUNCHER_COMPONENT) |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Checks that the launcher layer is never visible when performing task transitions. |
| 135 |
* A solid color background should be shown above it. |
| 136 |
*/ |
| 137 |
@Postsubmit |
| 138 |
@Test |
| 139 |
fun launcherLayerIsNeverVisible() { |
| 140 |
testSpec.assertLayers { |
| 141 |
this.isInvisible(LAUNCHER_COMPONENT) |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Checks that a color background is visible while the task transition is occurring. |
| 147 |
*/ |
| 148 |
@Postsubmit |
| 149 |
@Test |
| 150 |
fun colorLayerIsVisibleDuringTransition() { |
| 151 |
val bgColorLayer = FlickerComponentName("", "colorBackgroundLayer") |
| 152 |
val displayBounds = WindowUtils.getDisplayBounds(testSpec.startRotation) |
| 153 |
|
| 154 |
testSpec.assertLayers { |
| 155 |
this.invoke("LAUNCH_NEW_TASK_ACTIVITY coversExactly displayBounds") { |
| 156 |
it.visibleRegion(LAUNCH_NEW_TASK_ACTIVITY).coversExactly(displayBounds) |
| 157 |
} |
| 158 |
.isInvisible(bgColorLayer) |
| 159 |
.then() |
| 160 |
// Transitioning |
| 161 |
.isVisible(bgColorLayer) |
| 162 |
.then() |
| 163 |
// Fully transitioned to simple SIMPLE_ACTIVITY |
| 164 |
.invoke("SIMPLE_ACTIVITY coversExactly displayBounds") { |
| 165 |
it.visibleRegion(SIMPLE_ACTIVITY).coversExactly(displayBounds) |
| 166 |
} |
| 167 |
.isInvisible(bgColorLayer) |
| 168 |
.then() |
| 169 |
// Transitioning back |
| 170 |
.isVisible(bgColorLayer) |
| 171 |
.then() |
| 172 |
// Fully transitioned back to LAUNCH_NEW_TASK_ACTIVITY |
| 173 |
.invoke("LAUNCH_NEW_TASK_ACTIVITY coversExactly displayBounds") { |
| 174 |
it.visibleRegion(LAUNCH_NEW_TASK_ACTIVITY).coversExactly(displayBounds) |
| 175 |
} |
| 176 |
.isInvisible(bgColorLayer) |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Checks that we start with the LaunchNewTask activity on top and then open up |
| 182 |
* the SimpleActivity and then go back to the LaunchNewTask activity. |
| 183 |
*/ |
| 184 |
@Postsubmit |
| 185 |
@Test |
| 186 |
fun newTaskOpensOnTopAndThenCloses() { |
| 187 |
testSpec.assertWm { |
| 188 |
this.isAppWindowOnTop(LAUNCH_NEW_TASK_ACTIVITY) |
| 189 |
.then() |
| 190 |
.isAppWindowOnTop(SPLASH_SCREEN, isOptional = true) |
| 191 |
.then() |
| 192 |
.isAppWindowOnTop(SIMPLE_ACTIVITY) |
| 193 |
.then() |
| 194 |
.isAppWindowOnTop(SPLASH_SCREEN, isOptional = true) |
| 195 |
.then() |
| 196 |
.isAppWindowOnTop(LAUNCH_NEW_TASK_ACTIVITY) |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Checks that all parts of the screen are covered at the start and end of the transition |
| 202 |
*/ |
| 203 |
@Postsubmit |
| 204 |
@Test |
| 205 |
fun entireScreenCovered() = testSpec.entireScreenCovered() |
| 206 |
|
| 207 |
/** |
| 208 |
* Checks that the navbar window is visible throughout the transition |
| 209 |
*/ |
| 210 |
@Postsubmit |
| 211 |
@Test |
| 212 |
fun navBarWindowIsVisible() = testSpec.navBarWindowIsVisible() |
| 213 |
|
| 214 |
/** |
| 215 |
* Checks that the navbar layer is visible throughout the transition |
| 216 |
*/ |
| 217 |
@Postsubmit |
| 218 |
@Test |
| 219 |
fun navBarLayerIsVisible() = testSpec.navBarLayerIsVisible() |
| 220 |
|
| 221 |
/** |
| 222 |
* Checks that the status bar window is visible throughout the transition |
| 223 |
*/ |
| 224 |
@Postsubmit |
| 225 |
@Test |
| 226 |
fun statusBarWindowIsVisible() = testSpec.statusBarWindowIsVisible() |
| 227 |
|
| 228 |
/** |
| 229 |
* Checks that the status bar layer is visible throughout the transition |
| 230 |
*/ |
| 231 |
@Postsubmit |
| 232 |
@Test |
| 233 |
fun statusBarLayerIsVisible() = testSpec.statusBarLayerIsVisible() |
| 234 |
|
| 235 |
companion object { |
| 236 |
private val LAUNCH_NEW_TASK_ACTIVITY = |
| 237 |
LAUNCH_NEW_TASK_ACTIVITY_COMPONENT_NAME.toFlickerComponent() |
| 238 |
private val SIMPLE_ACTIVITY = SIMPLE_ACTIVITY_AUTO_FOCUS_COMPONENT_NAME.toFlickerComponent() |
| 239 |
|
| 240 |
private fun getWallpaperPackage(instrumentation: Instrumentation): FlickerComponentName? { |
| 241 |
val wallpaperManager = WallpaperManager.getInstance(instrumentation.targetContext) |
| 242 |
|
| 243 |
return wallpaperManager.wallpaperInfo?.component?.toFlickerComponent() |
| 244 |
} |
| 245 |
|
| 246 |
@Parameterized.Parameters(name = "{0}") |
| 247 |
@JvmStatic |
| 248 |
fun getParams(): Collection<FlickerTestParameter> { |
| 249 |
return FlickerTestParameterFactory.getInstance() |
| 250 |
.getConfigNonRotationTests(repetitions = 3) |
| 251 |
} |
| 252 |
} |
| 253 |
} |