blob: 42cafd43f8bdffd2246489dc17f07a4f1fb8aec8 [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.getNavigationBarPosition;
24import static com.android.server.wm.flicker.WindowUtils.getStatusBarPosition;
25import static com.android.server.wm.flicker.WmTraceSubject.assertThat;
26
27import android.graphics.Rect;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070028import android.util.Log;
29import android.view.Surface;
30
Brett Chabot502ec7a2019-03-01 14:43:20 -080031import androidx.test.InstrumentationRegistry;
Nataniel Borges0e476aa2019-09-18 16:10:03 +020032import androidx.test.filters.FlakyTest;
Brett Chabot502ec7a2019-03-01 14:43:20 -080033import androidx.test.filters.LargeTest;
34
Vishnu Nair8248b7c2018-08-01 10:13:36 -070035import org.junit.Before;
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020036import org.junit.FixMethodOrder;
Nataniel Borges0e476aa2019-09-18 16:10:03 +020037import org.junit.Ignore;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070038import org.junit.Test;
39import org.junit.runner.RunWith;
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020040import org.junit.runners.MethodSorters;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070041import org.junit.runners.Parameterized;
42import org.junit.runners.Parameterized.Parameters;
43
44import java.util.ArrayList;
45import java.util.Collection;
46
47/**
48 * Cycle through supported app rotations.
49 * To run this test: {@code atest FlickerTest:ChangeAppRotationTest}
50 */
Vishnu Nair8248b7c2018-08-01 10:13:36 -070051@LargeTest
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020052@RunWith(Parameterized.class)
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
Vishnu Nair8248b7c2018-08-01 10:13:36 -070054public class ChangeAppRotationTest extends FlickerTestBase {
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020055 private int mBeginRotation;
56 private int mEndRotation;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070057
58 public ChangeAppRotationTest(String beginRotationName, String endRotationName,
59 int beginRotation, int endRotation) {
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020060 this.mTestApp = new StandardAppHelper(InstrumentationRegistry.getInstrumentation(),
Vishnu Nair8248b7c2018-08-01 10:13:36 -070061 "com.android.server.wm.flicker.testapp", "SimpleApp");
Nataniel Borgesf5c828c2019-09-09 17:29:23 +020062 this.mBeginRotation = beginRotation;
63 this.mEndRotation = endRotation;
Vishnu Nair8248b7c2018-08-01 10:13:36 -070064 }
65
66 @Parameters(name = "{0}-{1}")
67 public static Collection<Object[]> getParams() {
68 int[] supportedRotations =
69 {Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_270};
70 Collection<Object[]> params = new ArrayList<>();
71 for (int begin : supportedRotations) {
72 for (int end : supportedRotations) {
73 if (begin != end) {
74 params.add(new Object[]{rotationToString(begin), rotationToString(end), begin,
75 end});
76 }
77 }
78 }
79 return params;
80 }
81
82 @Before
83 public void runTransition() {
84 super.runTransition(
Nataniel Borges8e65a892019-11-26 11:46:42 +010085 changeAppRotation(mTestApp, mUiDevice, mBeginRotation, mEndRotation)
86 .includeJankyRuns().build());
Vishnu Nair8248b7c2018-08-01 10:13:36 -070087 }
88
Nataniel Borges0e476aa2019-09-18 16:10:03 +020089 @FlakyTest(bugId = 140855415)
90 @Ignore("Waiting bug feedback")
Vishnu Nair8248b7c2018-08-01 10:13:36 -070091 @Test
92 public void checkVisibility_navBarWindowIsAlwaysVisible() {
93 checkResults(result -> assertThat(result)
94 .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
95 }
96
Nataniel Borges0e476aa2019-09-18 16:10:03 +020097 @FlakyTest(bugId = 140855415)
98 @Ignore("Waiting bug feedback")
Vishnu Nair8248b7c2018-08-01 10:13:36 -070099 @Test
100 public void checkVisibility_statusBarWindowIsAlwaysVisible() {
101 checkResults(result -> assertThat(result)
102 .showsAboveAppWindow(STATUS_BAR_WINDOW_TITLE).forAllEntries());
103 }
104
105 @Test
106 public void checkPosition_navBarLayerRotatesAndScales() {
Nataniel Borgesf5c828c2019-09-09 17:29:23 +0200107 Rect startingPos = getNavigationBarPosition(mBeginRotation);
108 Rect endingPos = getNavigationBarPosition(mEndRotation);
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700109 checkResults(result -> {
110 LayersTraceSubject.assertThat(result)
111 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos)
112 .inTheBeginning();
113 LayersTraceSubject.assertThat(result)
114 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, endingPos).atTheEnd();
115 }
116 );
117 }
118
119 @Test
120 public void checkPosition_appLayerRotates() {
Nataniel Borgesf5c828c2019-09-09 17:29:23 +0200121 Rect startingPos = getAppPosition(mBeginRotation);
122 Rect endingPos = getAppPosition(mEndRotation);
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700123 Log.e(TAG, "startingPos=" + startingPos + " endingPos=" + endingPos);
124 checkResults(result -> {
125 LayersTraceSubject.assertThat(result)
Nataniel Borgesf5c828c2019-09-09 17:29:23 +0200126 .hasVisibleRegion(mTestApp.getPackage(), startingPos).inTheBeginning();
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700127 LayersTraceSubject.assertThat(result)
Nataniel Borgesf5c828c2019-09-09 17:29:23 +0200128 .hasVisibleRegion(mTestApp.getPackage(), endingPos).atTheEnd();
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700129 }
130 );
131 }
132
133 @Test
134 public void checkPosition_statusBarLayerScales() {
Nataniel Borgesf5c828c2019-09-09 17:29:23 +0200135 Rect startingPos = getStatusBarPosition(mBeginRotation);
136 Rect endingPos = getStatusBarPosition(mEndRotation);
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700137 checkResults(result -> {
138 LayersTraceSubject.assertThat(result)
139 .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, startingPos)
140 .inTheBeginning();
141 LayersTraceSubject.assertThat(result)
142 .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, endingPos).atTheEnd();
143 }
144 );
145 }
146
Nataniel Borges0e476aa2019-09-18 16:10:03 +0200147 @FlakyTest(bugId = 140855415)
148 @Ignore("Waiting bug feedback")
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700149 @Test
150 public void checkVisibility_navBarLayerIsAlwaysVisible() {
151 checkResults(result -> LayersTraceSubject.assertThat(result)
152 .showsLayer(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
153 }
154
Nataniel Borges0e476aa2019-09-18 16:10:03 +0200155 @FlakyTest(bugId = 140855415)
156 @Ignore("Waiting bug feedback")
Vishnu Nair8248b7c2018-08-01 10:13:36 -0700157 @Test
158 public void checkVisibility_statusBarLayerIsAlwaysVisible() {
159 checkResults(result -> LayersTraceSubject.assertThat(result)
160 .showsLayer(STATUS_BAR_WINDOW_TITLE).forAllEntries());
161 }
162}