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.getDisplayBounds; |
| 24 | import static com.android.server.wm.flicker.WindowUtils.getNavigationBarPosition; |
| 25 | import static com.android.server.wm.flicker.testapp.ActivityOptions.EXTRA_STARVE_UI_THREAD; |
| 26 | import static com.android.server.wm.flicker.testapp.ActivityOptions.SEAMLESS_ACTIVITY_COMPONENT_NAME; |
| 27 | |
| 28 | import android.content.Intent; |
| 29 | import android.graphics.Rect; |
| 30 | import android.support.test.InstrumentationRegistry; |
| 31 | import android.support.test.filters.LargeTest; |
| 32 | import android.view.Surface; |
| 33 | |
| 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 using seamless rotations. |
| 45 | * To run this test: {@code atest FlickerTests:SeamlessAppRotationTest} |
| 46 | */ |
| 47 | @LargeTest |
| 48 | @RunWith(Parameterized.class) |
| 49 | public class SeamlessAppRotationTest extends FlickerTestBase { |
| 50 | private int mBeginRotation; |
| 51 | private int mEndRotation; |
| 52 | private Intent mIntent; |
| 53 | |
| 54 | public SeamlessAppRotationTest(String testId, Intent intent, int beginRotation, |
| 55 | int endRotation) { |
| 56 | this.mIntent = intent; |
| 57 | this.mBeginRotation = beginRotation; |
| 58 | this.mEndRotation = endRotation; |
| 59 | } |
| 60 | |
| 61 | @Parameters(name = "{0}") |
| 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 | |
| 67 | ArrayList<Intent> testIntents = new ArrayList<>(); |
| 68 | |
| 69 | // launch test activity that supports seamless rotation |
| 70 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 71 | intent.setComponent(SEAMLESS_ACTIVITY_COMPONENT_NAME); |
| 72 | testIntents.add(intent); |
| 73 | |
| 74 | // launch test activity that supports seamless rotation with a busy UI thread to miss frames |
| 75 | // when the app is asked to redraw |
| 76 | intent = new Intent(intent); |
| 77 | intent.putExtra(EXTRA_STARVE_UI_THREAD, true); |
| 78 | testIntents.add(intent); |
| 79 | |
| 80 | for (Intent testIntent : testIntents) { |
| 81 | for (int begin : supportedRotations) { |
| 82 | for (int end : supportedRotations) { |
| 83 | if (begin != end) { |
| 84 | String testId = rotationToString(begin) + "_" + rotationToString(end); |
| 85 | if (testIntent.getExtras() != null && |
| 86 | testIntent.getExtras().getBoolean(EXTRA_STARVE_UI_THREAD)) { |
| 87 | testId += "_" + "BUSY_UI_THREAD"; |
| 88 | } |
| 89 | params.add(new Object[]{testId, testIntent, begin, end}); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return params; |
| 95 | } |
| 96 | |
| 97 | @Before |
| 98 | public void runTransition() { |
| 99 | String intentId = ""; |
| 100 | if (mIntent.getExtras() != null && |
| 101 | mIntent.getExtras().getBoolean(EXTRA_STARVE_UI_THREAD)) { |
| 102 | intentId = "BUSY_UI_THREAD"; |
| 103 | } |
| 104 | |
| 105 | super.runTransition( |
| 106 | changeAppRotation(mIntent, intentId, InstrumentationRegistry.getContext(), |
| 107 | uiDevice, mBeginRotation, mEndRotation).repeat(5).build()); |
| 108 | } |
| 109 | |
| 110 | @Test |
| 111 | public void checkVisibility_navBarWindowIsAlwaysVisible() { |
| 112 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 113 | .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE).forAllEntries()); |
| 114 | } |
| 115 | |
| 116 | @Test |
| 117 | public void checkPosition_navBarLayerRotatesAndScales() { |
| 118 | Rect startingPos = getNavigationBarPosition(mBeginRotation); |
| 119 | Rect endingPos = getNavigationBarPosition(mEndRotation); |
| 120 | if (startingPos.equals(endingPos)) { |
| 121 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 122 | .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos) |
| 123 | .forAllEntries()); |
| 124 | } else { |
| 125 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 126 | .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, startingPos) |
| 127 | .inTheBeginning()); |
| 128 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 129 | .hasVisibleRegion(NAVIGATION_BAR_WINDOW_TITLE, endingPos) |
| 130 | .atTheEnd()); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void checkPosition_appLayerRotates() { |
| 136 | Rect startingPos = getAppPosition(mBeginRotation); |
| 137 | Rect endingPos = getAppPosition(mEndRotation); |
| 138 | if (startingPos.equals(endingPos)) { |
| 139 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 140 | .hasVisibleRegion(mIntent.getComponent().getPackageName(), startingPos) |
| 141 | .forAllEntries()); |
| 142 | } else { |
| 143 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 144 | .hasVisibleRegion(mIntent.getComponent().getPackageName(), startingPos) |
| 145 | .then() |
| 146 | .hasVisibleRegion(mIntent.getComponent().getPackageName(), endingPos) |
| 147 | .forAllEntries()); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | @Test |
| 152 | public void checkCoveredRegion_noUncoveredRegions() { |
| 153 | Rect startingBounds = getDisplayBounds(mBeginRotation); |
| 154 | Rect endingBounds = getDisplayBounds(mEndRotation); |
| 155 | if (startingBounds.equals(endingBounds)) { |
| 156 | checkResults(result -> |
| 157 | LayersTraceSubject.assertThat(result) |
| 158 | .coversRegion(startingBounds) |
| 159 | .forAllEntries()); |
| 160 | } else { |
| 161 | checkResults(result -> |
| 162 | LayersTraceSubject.assertThat(result) |
| 163 | .coversRegion(startingBounds) |
| 164 | .then() |
| 165 | .coversRegion(endingBounds) |
| 166 | .forAllEntries()); |
| 167 | } |
| 168 | } |
| 169 | } |