Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm.flicker; |
| 18 | |
| 19 | import static android.view.Surface.rotationToString; |
| 20 | |
| 21 | import static com.android.server.wm.flicker.CommonTransitions.changeAppRotation; |
| 22 | import static com.android.server.wm.flicker.WindowUtils.getAppPosition; |
| 23 | import static com.android.server.wm.flicker.WindowUtils.getNavigationBarPosition; |
| 24 | import static com.android.server.wm.flicker.WindowUtils.getStatusBarPosition; |
| 25 | import static com.android.server.wm.flicker.WmTraceSubject.assertThat; |
| 26 | |
| 27 | import android.graphics.Rect; |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | import android.view.Surface; |
| 30 | |
Brett Chabot | 502ec7a | 2019-03-01 14:43:20 -0800 | [diff] [blame] | 31 | import androidx.test.InstrumentationRegistry; |
| 32 | import androidx.test.filters.LargeTest; |
| 33 | |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 34 | import org.junit.Before; |
| 35 | import org.junit.Test; |
| 36 | import org.junit.runner.RunWith; |
| 37 | import org.junit.runners.Parameterized; |
| 38 | import org.junit.runners.Parameterized.Parameters; |
| 39 | |
| 40 | import java.util.ArrayList; |
| 41 | import 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 |
| 49 | public 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 | } |