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