Debian Codegraph @

tests/FlickerTests/src/com/android/server/wm/flicker/rotation/ChangeAppRotationTest.kt

raw
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 androidx.test.filters.FlakyTest
21 import androidx.test.filters.RequiresDevice
22 import com.android.server.wm.flicker.FlickerParametersRunnerFactory
23 import com.android.server.wm.flicker.FlickerTestParameter
24 import com.android.server.wm.flicker.FlickerTestParameterFactory
25 import com.android.server.wm.flicker.annotation.Group3
26 import com.android.server.wm.flicker.dsl.FlickerBuilder
27 import com.android.server.wm.flicker.helpers.SimpleAppHelper
28 import com.android.server.wm.flicker.statusBarLayerIsVisible
29 import com.android.server.wm.flicker.statusBarLayerRotatesScales
30 import com.android.server.wm.flicker.statusBarWindowIsVisible
31 import com.android.server.wm.traces.common.FlickerComponentName
32 import org.junit.FixMethodOrder
33 import org.junit.Test
34 import org.junit.runner.RunWith
35 import org.junit.runners.MethodSorters
36 import org.junit.runners.Parameterized
37
38 /**
39 * Test opening an app and cycling through app rotations
40 *
41 * Currently runs:
42 * 0 -> 90 degrees
43 * 90 -> 0 degrees
44 *
45 * Actions:
46 * Launch an app (via intent)
47 * Set initial device orientation
48 * Start tracing
49 * Change device orientation
50 * Stop tracing
51 *
52 * To run this test: `atest FlickerTests:ChangeAppRotationTest`
53 *
54 * To run only the presubmit assertions add: `--
55 * --module-arg FlickerTests:exclude-annotation:androidx.test.filters.FlakyTest
56 * --module-arg FlickerTests:include-annotation:android.platform.test.annotations.Presubmit`
57 *
58 * To run only the postsubmit assertions add: `--
59 * --module-arg FlickerTests:exclude-annotation:androidx.test.filters.FlakyTest
60 * --module-arg FlickerTests:include-annotation:android.platform.test.annotations.Postsubmit`
61 *
62 * To run only the flaky assertions add: `--
63 * --module-arg FlickerTests:include-annotation:androidx.test.filters.FlakyTest`
64 *
65 * Notes:
66 * 1. Some default assertions (e.g., nav bar, status bar and screen covered)
67 * are inherited [RotationTransition]
68 * 2. Part of the test setup occurs automatically via
69 * [com.android.server.wm.flicker.TransitionRunnerWithRules],
70 * including configuring navigation mode, initial orientation and ensuring no
71 * apps are running before setup
72 */
73 @RequiresDevice
74 @RunWith(Parameterized::class)
75 @Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
76 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
77 @Group3
78 class ChangeAppRotationTest(
79 testSpec: FlickerTestParameter
80 ) : RotationTransition(testSpec) {
81 override val testApp = SimpleAppHelper(instrumentation)
82 override val transition: FlickerBuilder.() -> Unit
83 get() = {
84 super.transition(this)
85 setup {
86 test {
87 testApp.launchViaIntent(wmHelper)
88 }
89 }
90 }
91
92 /**
93 * Windows maybe recreated when rotated. Checks that the focus does not change or if it does,
94 * focus returns to [testApp]
95 */
96 @Presubmit
97 @Test
98 fun focusChanges() {
99 testSpec.assertEventLog {
100 this.focusChanges(testApp.`package`)
101 }
102 }
103
104 /**
105 * Checks that the [FlickerComponentName.ROTATION] layer appears during the transition,
106 * doesn't flicker, and disappears before the transition is complete
107 */
108 fun rotationLayerAppearsAndVanishesAssertion() {
109 testSpec.assertLayers {
110 this.isVisible(testApp.component)
111 .then()
112 .isVisible(FlickerComponentName.ROTATION)
113 .then()
114 .isVisible(testApp.component)
115 .isInvisible(FlickerComponentName.ROTATION)
116 }
117 }
118
119 /**
120 * Checks that the [FlickerComponentName.ROTATION] layer appears during the transition,
121 * doesn't flicker, and disappears before the transition is complete
122 */
123 @Presubmit
124 @Test
125 fun rotationLayerAppearsAndVanishes() {
126 rotationLayerAppearsAndVanishesAssertion()
127 }
128
129 /**
130 * Checks that the status bar window is visible and above the app windows in all WM
131 * trace entries
132 */
133 @Presubmit
134 @Test
135 fun statusBarWindowIsVisible() {
136 testSpec.statusBarWindowIsVisible()
137 }
138
139 /**
140 * Checks that the status bar layer is visible at the start and end of the transition
141 */
142 @Presubmit
143 @Test
144 fun statusBarLayerIsVisible() {
145 testSpec.statusBarLayerIsVisible()
146 }
147
148 /**
149 * Checks the position of the status bar at the start and end of the transition
150 */
151 @FlakyTest(bugId = 206753786)
152 @Test
153 fun statusBarLayerRotatesScales() = testSpec.statusBarLayerRotatesScales()
154
155 /** {@inheritDoc} */
156 @FlakyTest
157 @Test
158 override fun navBarLayerRotatesAndScales() {
159 super.navBarLayerRotatesAndScales()
160 }
161
162 /** {@inheritDoc} */
163 @FlakyTest
164 @Test
165 override fun visibleLayersShownMoreThanOneConsecutiveEntry() =
166 super.visibleLayersShownMoreThanOneConsecutiveEntry()
167
168 companion object {
169 /**
170 * Creates the test configurations.
171 *
172 * See [FlickerTestParameterFactory.getConfigRotationTests] for configuring
173 * repetitions, screen orientation and navigation modes.
174 */
175 @Parameterized.Parameters(name = "{0}")
176 @JvmStatic
177 fun getParams(): Collection<FlickerTestParameter> {
178 return FlickerTestParameterFactory.getInstance()
179 .getConfigRotationTests(repetitions = 3)
180 }
181 }
182 }