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 com.android.server.wm.flicker.CommonTransitions.resizeSplitScreen; |
| 20 | import static com.android.server.wm.flicker.WindowUtils.getDisplayBounds; |
| 21 | import static com.android.server.wm.flicker.WindowUtils.getDockedStackDividerInset; |
| 22 | import static com.android.server.wm.flicker.WindowUtils.getNavigationBarHeight; |
| 23 | |
| 24 | import static com.google.common.truth.Truth.assertThat; |
| 25 | |
| 26 | import android.graphics.Rect; |
| 27 | import android.platform.helpers.IAppHelper; |
| 28 | import android.support.test.InstrumentationRegistry; |
| 29 | import android.support.test.filters.LargeTest; |
| 30 | import android.support.test.runner.AndroidJUnit4; |
| 31 | import android.util.Rational; |
| 32 | |
| 33 | import org.junit.Before; |
| 34 | import org.junit.Test; |
| 35 | import org.junit.runner.RunWith; |
| 36 | |
| 37 | /** |
| 38 | * Test split screen resizing window transitions. |
| 39 | * To run this test: {@code atest FlickerTests:ResizeSplitScreenTest} |
| 40 | */ |
| 41 | @LargeTest |
| 42 | @RunWith(AndroidJUnit4.class) |
| 43 | public class ResizeSplitScreenTest extends FlickerTestBase { |
| 44 | |
| 45 | public ResizeSplitScreenTest() { |
| 46 | this.testApp = new StandardAppHelper(InstrumentationRegistry.getInstrumentation(), |
| 47 | "com.android.server.wm.flicker.testapp", "SimpleApp"); |
| 48 | } |
| 49 | |
| 50 | @Before |
| 51 | public void runTransition() { |
| 52 | IAppHelper bottomApp = new StandardAppHelper(InstrumentationRegistry |
| 53 | .getInstrumentation(), |
| 54 | "com.android.server.wm.flicker.testapp", "ImeApp"); |
| 55 | super.runTransition(resizeSplitScreen(testApp, bottomApp, uiDevice, new Rational(1, 3), |
| 56 | new Rational(2, 3)).includeJankyRuns().build()); |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void checkVisibility_navBarLayerIsAlwaysVisible() { |
| 61 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 62 | .showsLayer(NAVIGATION_BAR_WINDOW_TITLE) |
| 63 | .forAllEntries()); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void checkVisibility_statusBarLayerIsAlwaysVisible() { |
| 68 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 69 | .showsLayer(STATUS_BAR_WINDOW_TITLE) |
| 70 | .forAllEntries()); |
| 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void checkVisibility_topAppLayerIsAlwaysVisible() { |
| 75 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 76 | .showsLayer("SimpleActivity") |
| 77 | .forAllEntries()); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void checkVisibility_bottomAppLayerIsAlwaysVisible() { |
| 82 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 83 | .showsLayer("ImeActivity") |
| 84 | .forAllEntries()); |
| 85 | } |
| 86 | |
| 87 | @Test |
| 88 | public void checkVisibility_dividerLayerIsAlwaysVisible() { |
| 89 | checkResults(result -> LayersTraceSubject.assertThat(result) |
| 90 | .showsLayer(DOCKED_STACK_DIVIDER) |
| 91 | .forAllEntries()); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void checkPosition_appsStartingBounds() { |
| 96 | Rect displayBounds = getDisplayBounds(); |
| 97 | checkResults(result -> { |
| 98 | LayersTrace entries = LayersTrace.parseFrom(result.getLayersTrace(), |
| 99 | result.getLayersTracePath()); |
| 100 | |
| 101 | assertThat(entries.getEntries()).isNotEmpty(); |
| 102 | Rect startingDividerBounds = entries.getEntries().get(0).getVisibleBounds |
| 103 | (DOCKED_STACK_DIVIDER); |
| 104 | |
| 105 | Rect startingTopAppBounds = new Rect(0, 0, startingDividerBounds.right, |
| 106 | startingDividerBounds.top + getDockedStackDividerInset()); |
| 107 | |
| 108 | Rect startingBottomAppBounds = new Rect(0, |
| 109 | startingDividerBounds.bottom - getDockedStackDividerInset(), |
| 110 | displayBounds.right, |
| 111 | displayBounds.bottom - getNavigationBarHeight()); |
| 112 | |
| 113 | LayersTraceSubject.assertThat(result) |
| 114 | .hasVisibleRegion("SimpleActivity", startingTopAppBounds) |
| 115 | .inTheBeginning(); |
| 116 | |
| 117 | LayersTraceSubject.assertThat(result) |
| 118 | .hasVisibleRegion("ImeActivity", startingBottomAppBounds) |
| 119 | .inTheBeginning(); |
| 120 | }); |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void checkPosition_appsEndingBounds() { |
| 125 | Rect displayBounds = getDisplayBounds(); |
| 126 | checkResults(result -> { |
| 127 | LayersTrace entries = LayersTrace.parseFrom(result.getLayersTrace(), |
| 128 | result.getLayersTracePath()); |
| 129 | |
| 130 | assertThat(entries.getEntries()).isNotEmpty(); |
| 131 | Rect endingDividerBounds = entries.getEntries().get( |
| 132 | entries.getEntries().size() - 1).getVisibleBounds( |
| 133 | DOCKED_STACK_DIVIDER); |
| 134 | |
| 135 | Rect startingTopAppBounds = new Rect(0, 0, endingDividerBounds.right, |
| 136 | endingDividerBounds.top + getDockedStackDividerInset()); |
| 137 | |
| 138 | Rect startingBottomAppBounds = new Rect(0, |
| 139 | endingDividerBounds.bottom - getDockedStackDividerInset(), |
| 140 | displayBounds.right, |
| 141 | displayBounds.bottom - getNavigationBarHeight()); |
| 142 | |
| 143 | LayersTraceSubject.assertThat(result) |
| 144 | .hasVisibleRegion("SimpleActivity", startingTopAppBounds) |
| 145 | .atTheEnd(); |
| 146 | |
| 147 | LayersTraceSubject.assertThat(result) |
| 148 | .hasVisibleRegion("ImeActivity", startingBottomAppBounds) |
| 149 | .atTheEnd(); |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | @Test |
| 154 | public void checkVisibility_navBarWindowIsAlwaysVisible() { |
| 155 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 156 | .showsAboveAppWindow(NAVIGATION_BAR_WINDOW_TITLE) |
| 157 | .forAllEntries()); |
| 158 | } |
| 159 | |
| 160 | @Test |
| 161 | public void checkVisibility_statusBarWindowIsAlwaysVisible() { |
| 162 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 163 | .showsAboveAppWindow(STATUS_BAR_WINDOW_TITLE) |
| 164 | .forAllEntries()); |
| 165 | } |
| 166 | |
| 167 | @Test |
| 168 | public void checkVisibility_topAppWindowIsAlwaysVisible() { |
| 169 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 170 | .showsAppWindow("SimpleActivity") |
| 171 | .forAllEntries()); |
| 172 | } |
| 173 | |
| 174 | @Test |
| 175 | public void checkVisibility_bottomAppWindowIsAlwaysVisible() { |
| 176 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 177 | .showsAppWindow("ImeActivity") |
| 178 | .forAllEntries()); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void checkVisibility_dividerWindowIsAlwaysVisible() { |
| 183 | checkResults(result -> WmTraceSubject.assertThat(result) |
| 184 | .showsAboveAppWindow(DOCKED_STACK_DIVIDER) |
| 185 | .forAllEntries()); |
| 186 | } |
| 187 | } |