blob: b6860cbd8d9699e506b47e90fd5532c41c077f5b [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;
32import androidx.test.filters.LargeTest;
33
Vishnu Nair8248b7c2018-08-01 10:13:36 -070034import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.junit.runners.Parameterized;
38import org.junit.runners.Parameterized.Parameters;
39
40import java.util.ArrayList;
41import java.util.Collection;
42
43/**
44 * Cycle through supported app rotations.
45 * To run this test: {@code atest FlickerTest:ChangeAppRotationTest}
46 */
47@RunWith(Parameterized.class)
48@LargeTest
49public class ChangeAppRotationTest extends FlickerTestBase {
50 private int beginRotation;
51 private int endRotation;
52
53 public ChangeAppRotationTest(String beginRotationName, String endRotationName,
54 int beginRotation, int endRotation) {
55 this.testApp = new StandardAppHelper(InstrumentationRegistry.getInstrumentation(),
56 "com.android.server.wm.flicker.testapp", "SimpleApp");
57 this.beginRotation = beginRotation;
58 this.endRotation = endRotation;
59 }
60
61 @Parameters(name = "{0}-{1}")
62 public static Collection<Object[]> getParams() {
63 int[] supportedRotations =
64 {Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_270};
65 Collection<Object[]> params = new ArrayList<>();
66 for (int begin : supportedRotations) {
67 for (int end : supportedRotations) {
68 if (begin != end) {
69 params.add(new Object[]{rotationToString(begin), rotationToString(end), begin,
70 end});
71 }
72 }
73 }
74 return params;
75 }
76
77 @Before
78 public void runTransition() {
79 super.runTransition(
80 changeAppRotation(testApp, uiDevice, beginRotation, endRotation).build());
81 }
82
83 @Test
84 public void checkVisibility_navBarWindowIsAlwaysVisible() {
85 checkResults(result -> assertThat(result)
86 .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
87 }
88
89 @Test
90 public void checkVisibility_statusBarWindowIsAlwaysVisible() {
91 checkResults(result -> assertThat(result)
92 .showsAboveAppWindow(STATUS_BAR_WINDOW_TITLE).forAllEntries());
93 }
94
95 @Test
96 public void checkPosition_navBarLayerRotatesAndScales() {
97 Rect startingPos = getNavigationBarPosition(beginRotation);
98 Rect endingPos = getNavigationBarPosition(endRotation);
99 checkResults(result -> {
100 LayersTraceSubject.assertThat(result)
101 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos)
102 .inTheBeginning();
103 LayersTraceSubject.assertThat(result)
104 .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, endingPos).atTheEnd();
105 }
106 );
107 }
108
109 @Test
110 public void checkPosition_appLayerRotates() {
111 Rect startingPos = getAppPosition(beginRotation);
112 Rect endingPos = getAppPosition(endRotation);
113 Log.e(TAG, "startingPos=" + startingPos + " endingPos=" + endingPos);
114 checkResults(result -> {
115 LayersTraceSubject.assertThat(result)
116 .hasVisibleRegion(testApp.getPackage(), startingPos).inTheBeginning();
117 LayersTraceSubject.assertThat(result)
118 .hasVisibleRegion(testApp.getPackage(), endingPos).atTheEnd();
119 }
120 );
121 }
122
123 @Test
124 public void checkPosition_statusBarLayerScales() {
125 Rect startingPos = getStatusBarPosition(beginRotation);
126 Rect endingPos = getStatusBarPosition(endRotation);
127 checkResults(result -> {
128 LayersTraceSubject.assertThat(result)
129 .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, startingPos)
130 .inTheBeginning();
131 LayersTraceSubject.assertThat(result)
132 .hasVisibleRegion(STATUS_BAR_WINDOW_TITLE, endingPos).atTheEnd();
133 }
134 );
135 }
136
137 @Test
138 public void checkVisibility_navBarLayerIsAlwaysVisible() {
139 checkResults(result -> LayersTraceSubject.assertThat(result)
140 .showsLayer(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries());
141 }
142
143 @Test
144 public void checkVisibility_statusBarLayerIsAlwaysVisible() {
145 checkResults(result -> LayersTraceSubject.assertThat(result)
146 .showsLayer(STATUS_BAR_WINDOW_TITLE).forAllEntries());
147 }
148}