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