| 1 |
/* |
| 2 |
* Copyright (C) 2020 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.rotation |
| 18 |
|
| 19 |
import android.platform.test.annotations.Presubmit |
| 20 |
import android.platform.test.annotations.RequiresDevice |
| 21 |
import android.view.WindowManager |
| 22 |
import androidx.test.filters.FlakyTest |
| 23 |
import com.android.server.wm.flicker.FlickerParametersRunnerFactory |
| 24 |
import com.android.server.wm.flicker.FlickerTestParameter |
| 25 |
import com.android.server.wm.flicker.FlickerTestParameterFactory |
| 26 |
import com.android.server.wm.flicker.annotation.Group3 |
| 27 |
import com.android.server.wm.flicker.dsl.FlickerBuilder |
| 28 |
import com.android.server.wm.flicker.helpers.SeamlessRotationAppHelper |
| 29 |
import com.android.server.wm.flicker.testapp.ActivityOptions |
| 30 |
import com.android.server.wm.traces.common.FlickerComponentName |
| 31 |
import org.junit.FixMethodOrder |
| 32 |
import org.junit.Test |
| 33 |
import org.junit.runner.RunWith |
| 34 |
import org.junit.runners.MethodSorters |
| 35 |
import org.junit.runners.Parameterized |
| 36 |
|
| 37 |
/** |
| 38 |
* Test opening an app and cycling through app rotations using seamless rotations |
| 39 |
* |
| 40 |
* Currently runs: |
| 41 |
* 0 -> 90 degrees |
| 42 |
* 0 -> 90 degrees (with starved UI thread) |
| 43 |
* 90 -> 0 degrees |
| 44 |
* 90 -> 0 degrees (with starved UI thread) |
| 45 |
* |
| 46 |
* Actions: |
| 47 |
* Launch an app in fullscreen and supporting seamless rotation (via intent) |
| 48 |
* Set initial device orientation |
| 49 |
* Start tracing |
| 50 |
* Change device orientation |
| 51 |
* Stop tracing |
| 52 |
* |
| 53 |
* To run this test: `atest FlickerTests:SeamlessAppRotationTest` |
| 54 |
* |
| 55 |
* To run only the presubmit assertions add: `-- |
| 56 |
* --module-arg FlickerTests:exclude-annotation:androidx.test.filters.FlakyTest |
| 57 |
* --module-arg FlickerTests:include-annotation:android.platform.test.annotations.Presubmit` |
| 58 |
* |
| 59 |
* To run only the postsubmit assertions add: `-- |
| 60 |
* --module-arg FlickerTests:exclude-annotation:androidx.test.filters.FlakyTest |
| 61 |
* --module-arg FlickerTests:include-annotation:android.platform.test.annotations.Postsubmit` |
| 62 |
* |
| 63 |
* To run only the flaky assertions add: `-- |
| 64 |
* --module-arg FlickerTests:include-annotation:androidx.test.filters.FlakyTest` |
| 65 |
* |
| 66 |
* Notes: |
| 67 |
* 1. Some default assertions (e.g., nav bar, status bar and screen covered) |
| 68 |
* are inherited [RotationTransition] |
| 69 |
* 2. Part of the test setup occurs automatically via |
| 70 |
* [com.android.server.wm.flicker.TransitionRunnerWithRules], |
| 71 |
* including configuring navigation mode, initial orientation and ensuring no |
| 72 |
* apps are running before setup |
| 73 |
*/ |
| 74 |
@RequiresDevice |
| 75 |
@RunWith(Parameterized::class) |
| 76 |
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) |
| 77 |
@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 78 |
@Group3 |
| 79 |
open class SeamlessAppRotationTest( |
| 80 |
testSpec: FlickerTestParameter |
| 81 |
) : RotationTransition(testSpec) { |
| 82 |
override val testApp = SeamlessRotationAppHelper(instrumentation) |
| 83 |
|
| 84 |
override val transition: FlickerBuilder.() -> Unit |
| 85 |
get() = { |
| 86 |
super.transition(this) |
| 87 |
setup { |
| 88 |
test { |
| 89 |
testApp.launchViaIntent(wmHelper, |
| 90 |
stringExtras = mapOf(ActivityOptions.EXTRA_STARVE_UI_THREAD |
| 91 |
to testSpec.starveUiThread.toString()) |
| 92 |
) |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Checks that [testApp] window is always in full screen |
| 99 |
*/ |
| 100 |
@Presubmit |
| 101 |
@Test |
| 102 |
fun appWindowFullScreen() { |
| 103 |
testSpec.assertWm { |
| 104 |
this.invoke("isFullScreen") { |
| 105 |
val appWindow = it.windowState(testApp.`package`) |
| 106 |
val flags = appWindow.windowState?.attributes?.flags ?: 0 |
| 107 |
appWindow.verify("isFullScreen") |
| 108 |
.that(flags.and(WindowManager.LayoutParams.FLAG_FULLSCREEN)) |
| 109 |
.isGreaterThan(0) |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Checks that [testApp] window is always with seamless rotation |
| 116 |
*/ |
| 117 |
@Presubmit |
| 118 |
@Test |
| 119 |
fun appWindowSeamlessRotation() { |
| 120 |
testSpec.assertWm { |
| 121 |
this.invoke("isRotationSeamless") { |
| 122 |
val appWindow = it.windowState(testApp.`package`) |
| 123 |
val rotationAnimation = appWindow.windowState?.attributes?.rotationAnimation ?: 0 |
| 124 |
appWindow.verify("isRotationSeamless") |
| 125 |
.that(rotationAnimation |
| 126 |
.and(WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS)) |
| 127 |
.isGreaterThan(0) |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Checks that [testApp] window is always visible |
| 134 |
*/ |
| 135 |
@Presubmit |
| 136 |
@Test |
| 137 |
fun appLayerAlwaysVisible() { |
| 138 |
testSpec.assertLayers { |
| 139 |
isVisible(testApp.component) |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Checks that [testApp] layer covers the entire screen during the whole transition |
| 145 |
*/ |
| 146 |
@Presubmit |
| 147 |
@Test |
| 148 |
fun appLayerRotates() { |
| 149 |
testSpec.assertLayers { |
| 150 |
this.invoke("entireScreenCovered") { entry -> |
| 151 |
entry.entry.displays.map { display -> |
| 152 |
entry.visibleRegion(testApp.component).coversExactly(display.layerStackSpace) |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Checks that the [FlickerComponentName.STATUS_BAR] window is invisible during the whole |
| 160 |
* transition |
| 161 |
*/ |
| 162 |
@Presubmit |
| 163 |
@Test |
| 164 |
fun statusBarWindowIsAlwaysInvisible() { |
| 165 |
testSpec.assertWm { |
| 166 |
this.isAboveAppWindowInvisible(FlickerComponentName.STATUS_BAR) |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Checks that the [FlickerComponentName.STATUS_BAR] layer is invisible during the whole |
| 172 |
* transition |
| 173 |
*/ |
| 174 |
@Presubmit |
| 175 |
@Test |
| 176 |
fun statusBarLayerIsAlwaysInvisible() { |
| 177 |
testSpec.assertLayers { |
| 178 |
this.isInvisible(FlickerComponentName.STATUS_BAR) |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Checks that the focus doesn't change during animation |
| 184 |
*/ |
| 185 |
@Presubmit |
| 186 |
@Test |
| 187 |
fun focusDoesNotChange() { |
| 188 |
testSpec.assertEventLog { |
| 189 |
this.focusDoesNotChange() |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
/** {@inheritDoc} */ |
| 194 |
@FlakyTest |
| 195 |
@Test |
| 196 |
override fun navBarLayerRotatesAndScales() = super.navBarLayerRotatesAndScales() |
| 197 |
|
| 198 |
companion object { |
| 199 |
private val FlickerTestParameter.starveUiThread |
| 200 |
get() = config.getOrDefault(ActivityOptions.EXTRA_STARVE_UI_THREAD, false) as Boolean |
| 201 |
|
| 202 |
private fun createConfig( |
| 203 |
sourceConfig: FlickerTestParameter, |
| 204 |
starveUiThread: Boolean |
| 205 |
): FlickerTestParameter { |
| 206 |
val newConfig = sourceConfig.config.toMutableMap() |
| 207 |
.also { it[ActivityOptions.EXTRA_STARVE_UI_THREAD] = starveUiThread } |
| 208 |
val nameExt = if (starveUiThread) "_BUSY_UI_THREAD" else "" |
| 209 |
return FlickerTestParameter(newConfig, nameOverride = "$sourceConfig$nameExt") |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Creates the test configurations for seamless rotation based on the default rotation |
| 214 |
* tests from [FlickerTestParameterFactory.getConfigRotationTests], but adding an |
| 215 |
* additional flag ([ActivityOptions.EXTRA_STARVE_UI_THREAD]) to indicate if the app |
| 216 |
* should starve the UI thread of not |
| 217 |
*/ |
| 218 |
@JvmStatic |
| 219 |
private fun getConfigurations(): List<FlickerTestParameter> { |
| 220 |
return FlickerTestParameterFactory.getInstance() |
| 221 |
.getConfigRotationTests(repetitions = 2) |
| 222 |
.flatMap { sourceConfig -> |
| 223 |
val defaultRun = createConfig(sourceConfig, starveUiThread = false) |
| 224 |
val busyUiRun = createConfig(sourceConfig, starveUiThread = true) |
| 225 |
listOf(defaultRun, busyUiRun) |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Creates the test configurations. |
| 231 |
* |
| 232 |
* See [FlickerTestParameterFactory.getConfigRotationTests] for configuring |
| 233 |
* repetitions, screen orientation and navigation modes. |
| 234 |
*/ |
| 235 |
@Parameterized.Parameters(name = "{0}") |
| 236 |
@JvmStatic |
| 237 |
fun getParams(): Collection<FlickerTestParameter> { |
| 238 |
return getConfigurations() |
| 239 |
} |
| 240 |
} |
| 241 |
} |