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; |
Nataniel Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 32 | import androidx.test.filters.FlakyTest; |
Brett Chabot | 502ec7a | 2019-03-01 14:43:20 -0800 | [diff] [blame] | 33 | import androidx.test.filters.LargeTest; |
| 34 | |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 35 | import org.junit.Before; |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 36 | import org.junit.FixMethodOrder; |
Nataniel Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 37 | import org.junit.Ignore; |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 38 | import org.junit.Test; |
| 39 | import org.junit.runner.RunWith; |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 40 | import org.junit.runners.MethodSorters; |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 41 | import org.junit.runners.Parameterized; |
| 42 | import org.junit.runners.Parameterized.Parameters; |
| 43 | |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.Collection; |
| 46 | |
| 47 | /** |
| 48 | * Cycle through supported app rotations. |
| 49 | * To run this test: {@code atest FlickerTest:ChangeAppRotationTest} |
| 50 | */ |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 51 | @LargeTest |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 52 | @RunWith(Parameterized.class) |
| 53 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 54 | public class ChangeAppRotationTest extends FlickerTestBase { |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 55 | private int mBeginRotation; |
| 56 | private int mEndRotation; |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 57 | |
| 58 | public ChangeAppRotationTest(String beginRotationName, String endRotationName, |
| 59 | int beginRotation, int endRotation) { |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 60 | this.mTestApp = new StandardAppHelper(InstrumentationRegistry.getInstrumentation(), |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 61 | "com.android.server.wm.flicker.testapp", "SimpleApp"); |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 62 | this.mBeginRotation = beginRotation; |
| 63 | this.mEndRotation = endRotation; |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 64 | } |
| 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 Borges | 8e65a89 | 2019-11-26 11:46:42 +0100 | [diff] [blame] | 85 | changeAppRotation(mTestApp, mUiDevice, mBeginRotation, mEndRotation) |
| 86 | .includeJankyRuns().build()); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Nataniel Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 89 | @FlakyTest(bugId = 140855415) |
| 90 | @Ignore("Waiting bug feedback") |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 91 | @Test |
| 92 | public void checkVisibility_navBarWindowIsAlwaysVisible() { |
| 93 | checkResults(result -> assertThat(result) |
| 94 | .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries()); |
| 95 | } |
| 96 | |
Nataniel Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 97 | @FlakyTest(bugId = 140855415) |
| 98 | @Ignore("Waiting bug feedback") |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 99 | @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 Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 107 | Rect startingPos = getNavigationBarPosition(mBeginRotation); |
| 108 | Rect endingPos = getNavigationBarPosition(mEndRotation); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 109 | 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 Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 121 | Rect startingPos = getAppPosition(mBeginRotation); |
| 122 | Rect endingPos = getAppPosition(mEndRotation); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 123 | Log.e(TAG, "startingPos=" + startingPos + " endingPos=" + endingPos); |
| 124 | checkResults(result -> { |
| 125 | LayersTraceSubject.assertThat(result) |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 126 | .hasVisibleRegion(mTestApp.getPackage(), startingPos).inTheBeginning(); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 127 | LayersTraceSubject.assertThat(result) |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 128 | .hasVisibleRegion(mTestApp.getPackage(), endingPos).atTheEnd(); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 129 | } |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | @Test |
| 134 | public void checkPosition_statusBarLayerScales() { |
Nataniel Borges | f5c828c | 2019-09-09 17:29:23 +0200 | [diff] [blame] | 135 | Rect startingPos = getStatusBarPosition(mBeginRotation); |
| 136 | Rect endingPos = getStatusBarPosition(mEndRotation); |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 137 | 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 Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 147 | @FlakyTest(bugId = 140855415) |
| 148 | @Ignore("Waiting bug feedback") |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 149 | @Test |
| 150 | public void checkVisibility_navBarLayerIsAlwaysVisible() { |
| 151 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 152 | .showsLayer(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries()); |
| 153 | } |
| 154 | |
Nataniel Borges | 0e476aa | 2019-09-18 16:10:03 +0200 | [diff] [blame] | 155 | @FlakyTest(bugId = 140855415) |
| 156 | @Ignore("Waiting bug feedback") |
Vishnu Nair | 8248b7c | 2018-08-01 10:13:36 -0700 | [diff] [blame] | 157 | @Test |
| 158 | public void checkVisibility_statusBarLayerIsAlwaysVisible() { |
| 159 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 160 | .showsLayer(STATUS_BAR_WINDOW_TITLE).forAllEntries()); |
| 161 | } |
| 162 | } |