blob: 117ac5a8fadfc00ecfde925e93fa894b4c6afe98 [file] [log] [blame]
Vishnu Nair8248b7c2018-08-01 10:13:36 -07001/*
2 * Copyright (C) 2018 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
17package com.android.server.wm.flicker;
18
19import static android.view.Surface.rotationToString;
20
21import static com.android.server.wm.flicker.CommonTransitions.changeAppRotation;
22import static com.android.server.wm.flicker.WindowUtils.getAppPosition;
23import static com.android.server.wm.flicker.WindowUtils.getDisplayBounds;
24import static com.android.server.wm.flicker.WindowUtils.getNavigationBarPosition;
25import static com.android.server.wm.flicker.testapp.ActivityOptions.EXTRA_STARVE_UI_THREAD;
26import static com.android.server.wm.flicker.testapp.ActivityOptions.SEAMLESS_ACTIVITY_COMPONENT_NAME;
27
28import android.content.Intent;
29import android.graphics.Rect;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070030import android.view.Surface;
31
Brett Chabot502ec7a2019-03-01 14:43:20 -080032import androidx.test.InstrumentationRegistry;
33import androidx.test.filters.LargeTest;
34
Vishnu Nair8248b7c2018-08-01 10:13:36 -070035import org.junit.Before;
36import org.junit.Test;
37import org.junit.runner.RunWith;
38import org.junit.runners.Parameterized;
39import org.junit.runners.Parameterized.Parameters;
40
41import java.util.ArrayList;
42import java.util.Collection;
43
44/**
45 * Cycle through supported app rotations using seamless rotations.
46 * To run this test: {@code atest FlickerTests:SeamlessAppRotationTest}
47 */
48@LargeTest
49@RunWith(Parameterized.class)
50public class SeamlessAppRotationTest extends FlickerTestBase {
51 private int mBeginRotation;
52 private int mEndRotation;
53 private Intent mIntent;
54
55 public SeamlessAppRotationTest(String testId, Intent intent, int beginRotation,
56 int endRotation) {
57 this.mIntent = intent;
58 this.mBeginRotation = beginRotation;
59 this.mEndRotation = endRotation;
60 }
61
62 @Parameters(name = "{0}")
63 public static Collection<Object[]> getParams() {
64 int[] supportedRotations =
65 {Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_270};
66 Collection<Object[]> params = new ArrayList<>();
67
68 ArrayList<Intent> testIntents = new ArrayList<>();
69
70 // launch test activity that supports seamless rotation
71 Intent intent = new Intent(Intent.ACTION_MAIN);
72 intent.setComponent(SEAMLESS_ACTIVITY_COMPONENT_NAME);
73 testIntents.add(intent);
74
75 // launch test activity that supports seamless rotation with a busy UI thread to miss frames
76 // when the app is asked to redraw
77 intent = new Intent(intent);
78 intent.putExtra(EXTRA_STARVE_UI_THREAD, true);
79 testIntents.add(intent);
80
81 for (Intent testIntent : testIntents) {
82 for (int begin : supportedRotations) {
83 for (int end : supportedRotations) {
84 if (begin != end) {
85 String testId = rotationToString(begin) + "_" + rotationToString(end);
86 if (testIntent.getExtras() != null &&
87 testIntent.getExtras().getBoolean(EXTRA_STARVE_UI_THREAD)) {
88 testId += "_" + "BUSY_UI_THREAD";
89 }
90 params.add(new Object[]{testId, testIntent, begin, end});
91 }
92 }
93 }
94 }
95 return params;
96 }
97
98 @Before
99 public void runTransition() {
100 String intentId = "";
101 if (mIntent.getExtras() != null &&
102 mIntent.getExtras().getBoolean(EXTRA_STARVE_UI_THREAD)) {
103 intentId = "BUSY_UI_THREAD";
104 }
105
106 super.runTransition(
107 changeAppRotation(mIntent, intentId, InstrumentationRegistry.getContext(),
108 uiDevice, mBeginRotation, mEndRotation).repeat(5).build());
109 }
110
111 @Test
112 public void checkVisibility_navBarWindowIsAlwaysVisible() {
113 checkResults(result -> WmTraceSubject.assertThat(result)
114 .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
115 }
116
117 @Test
118 public void checkPosition_navBarLayerRotatesAndScales() {
119 Rect startingPos = getNavigationBarPosition(mBeginRotation);
120 Rect endingPos = getNavigationBarPosition(mEndRotation);
121 if (startingPos.equals(endingPos)) {
122 checkResults(result -> LayersTraceSubject.assertThat(result)
123 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos)
124 .forAllEntries());
125 } else {
126 checkResults(result -> LayersTraceSubject.assertThat(result)
127 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos)
128 .inTheBeginning());
129 checkResults(result -> LayersTraceSubject.assertThat(result)
130 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, endingPos)
131 .atTheEnd());
132 }
133 }
134
135 @Test
136 public void checkPosition_appLayerRotates() {
137 Rect startingPos = getAppPosition(mBeginRotation);
138 Rect endingPos = getAppPosition(mEndRotation);
139 if (startingPos.equals(endingPos)) {
140 checkResults(result -> LayersTraceSubject.assertThat(result)
141 .hasVisibleRegion(mIntent.getComponent().getPackageName(), startingPos)
142 .forAllEntries());
143 } else {
144 checkResults(result -> LayersTraceSubject.assertThat(result)
145 .hasVisibleRegion(mIntent.getComponent().getPackageName(), startingPos)
146 .then()
147 .hasVisibleRegion(mIntent.getComponent().getPackageName(), endingPos)
148 .forAllEntries());
149 }
150 }
151
152 @Test
153 public void checkCoveredRegion_noUncoveredRegions() {
154 Rect startingBounds = getDisplayBounds(mBeginRotation);
155 Rect endingBounds = getDisplayBounds(mEndRotation);
156 if (startingBounds.equals(endingBounds)) {
157 checkResults(result ->
158 LayersTraceSubject.assertThat(result)
159 .coversRegion(startingBounds)
160 .forAllEntries());
161 } else {
162 checkResults(result ->
163 LayersTraceSubject.assertThat(result)
164 .coversRegion(startingBounds)
165 .then()
166 .coversRegion(endingBounds)
167 .forAllEntries());
168 }
169 }
170}