Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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; |
| 18 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
| 21 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 24 | import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.junit.Assert.assertTrue; |
| 28 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 29 | import org.junit.Test; |
| 30 | import org.junit.runner.RunWith; |
| 31 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 33 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 34 | import android.support.test.filters.SmallTest; |
| 35 | import android.support.test.runner.AndroidJUnit4; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 36 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 37 | import java.util.Arrays; |
| 38 | import java.util.LinkedList; |
| 39 | import java.util.List; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Tests for the {@link DisplayContent} class. |
| 43 | * |
| 44 | * Build/Install/Run: |
| 45 | * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests |
| 46 | */ |
| 47 | @SmallTest |
| 48 | @Presubmit |
| 49 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 50 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 51 | |
| 52 | @Test |
| 53 | public void testForAllWindows() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 54 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 55 | mDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 56 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 57 | exitingAppToken.mIsExiting = true; |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 58 | exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 59 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 60 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 61 | mWallpaperWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 62 | exitingAppWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 63 | mChildAppWindowBelow, |
| 64 | mAppWindow, |
| 65 | mChildAppWindowAbove, |
| 66 | mDockedDividerWindow, |
| 67 | mStatusBarWindow, |
| 68 | mNavBarWindow, |
| 69 | mImeWindow, |
| 70 | mImeDialogWindow)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 74 | public void testForAllWindows_WithAppImeTarget() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 75 | final WindowState imeAppTarget = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 76 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 77 | |
| 78 | sWm.mInputMethodTarget = imeAppTarget; |
| 79 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 80 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 81 | mWallpaperWindow, |
| 82 | mChildAppWindowBelow, |
| 83 | mAppWindow, |
| 84 | mChildAppWindowAbove, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 85 | imeAppTarget, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 86 | mImeWindow, |
| 87 | mImeDialogWindow, |
| 88 | mDockedDividerWindow, |
| 89 | mStatusBarWindow, |
| 90 | mNavBarWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 91 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 92 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 93 | @Test |
| 94 | public void testForAllWindows_WithChildWindowImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 95 | sWm.mInputMethodTarget = mChildAppWindowAbove; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 96 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 97 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 98 | mWallpaperWindow, |
| 99 | mChildAppWindowBelow, |
| 100 | mAppWindow, |
| 101 | mChildAppWindowAbove, |
| 102 | mImeWindow, |
| 103 | mImeDialogWindow, |
| 104 | mDockedDividerWindow, |
| 105 | mStatusBarWindow, |
| 106 | mNavBarWindow)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 107 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 108 | |
| 109 | @Test |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 110 | public void testForAllWindows_WithStatusBarImeTarget() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 111 | sWm.mInputMethodTarget = mStatusBarWindow; |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 112 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 113 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 114 | mWallpaperWindow, |
| 115 | mChildAppWindowBelow, |
| 116 | mAppWindow, |
| 117 | mChildAppWindowAbove, |
| 118 | mDockedDividerWindow, |
| 119 | mStatusBarWindow, |
| 120 | mImeWindow, |
| 121 | mImeDialogWindow, |
| 122 | mNavBarWindow)); |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Test |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 126 | public void testForAllWindows_WithInBetweenWindowToken() throws Exception { |
| 127 | // This window is set-up to be z-ordered between some windows that go in the same token like |
| 128 | // the nav bar and status bar. |
| 129 | final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 130 | mDisplayContent, "voiceInteractionWindow"); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 131 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 132 | assertForAllWindowsOrder(Arrays.asList( |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 133 | mWallpaperWindow, |
| 134 | mChildAppWindowBelow, |
| 135 | mAppWindow, |
| 136 | mChildAppWindowAbove, |
| 137 | mDockedDividerWindow, |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 138 | voiceInteractionWindow, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 139 | mStatusBarWindow, |
| 140 | mNavBarWindow, |
| 141 | mImeWindow, |
| 142 | mImeDialogWindow)); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 143 | } |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 144 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 145 | @Test |
| 146 | public void testComputeImeTarget() throws Exception { |
| 147 | // Verify that an app window can be an ime target. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 148 | final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin"); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 149 | appWin.setHasSurface(true); |
| 150 | assertTrue(appWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 151 | WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 152 | assertEquals(appWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 153 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 154 | // Verify that an child window can be an ime target. |
| 155 | final WindowState childWin = createWindow(appWin, |
| 156 | TYPE_APPLICATION_ATTACHED_DIALOG, "childWin"); |
| 157 | childWin.setHasSurface(true); |
| 158 | assertTrue(childWin.canBeImeTarget()); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 159 | imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 160 | assertEquals(childWin, imeTarget); |
Wale Ogunwale | 5d7e7f1 | 2016-12-12 14:47:05 -0800 | [diff] [blame] | 161 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 162 | |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 163 | /** |
| 164 | * This tests stack movement between displays and proper stack's, task's and app token's display |
| 165 | * container references updates. |
| 166 | */ |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 167 | @Test |
| 168 | public void testMoveStackBetweenDisplays() throws Exception { |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 169 | // Create a second display. |
| 170 | final DisplayContent dc = createNewDisplay(); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 171 | |
| 172 | // Add stack with activity. |
| 173 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 174 | assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 175 | assertEquals(dc, stack.getParent().getParent()); |
| 176 | assertEquals(dc, stack.getDisplayContent()); |
| 177 | |
| 178 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 179 | final WindowTestUtils.TestAppWindowToken token = new WindowTestUtils.TestAppWindowToken(dc); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 180 | task.addChild(token, 0); |
| 181 | assertEquals(dc, task.getDisplayContent()); |
| 182 | assertEquals(dc, token.getDisplayContent()); |
| 183 | |
| 184 | // Move stack to first display. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 185 | mDisplayContent.moveStackToDisplay(stack, true /* onTop */); |
| 186 | assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId()); |
| 187 | assertEquals(mDisplayContent, stack.getParent().getParent()); |
| 188 | assertEquals(mDisplayContent, stack.getDisplayContent()); |
| 189 | assertEquals(mDisplayContent, task.getDisplayContent()); |
| 190 | assertEquals(mDisplayContent, token.getDisplayContent()); |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 191 | } |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * This tests override configuration updates for display content. |
| 195 | */ |
| 196 | @Test |
| 197 | public void testDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 198 | final int displayId = mDisplayContent.getDisplayId(); |
| 199 | final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 200 | |
| 201 | // Create new, slightly changed override configuration and apply it to the display. |
| 202 | final Configuration newOverrideConfig = new Configuration(currentOverrideConfig); |
| 203 | newOverrideConfig.densityDpi += 120; |
| 204 | newOverrideConfig.fontScale += 0.3; |
| 205 | |
| 206 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId); |
| 207 | |
| 208 | // Check that override config is applied. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 209 | assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration()); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * This tests global configuration updates when default display config is updated. |
| 214 | */ |
| 215 | @Test |
| 216 | public void testDefaultDisplayOverrideConfigUpdate() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 217 | final Configuration currentConfig = mDisplayContent.getConfiguration(); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 218 | |
| 219 | // Create new, slightly changed override configuration and apply it to the display. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 220 | final Configuration newOverrideConfig = new Configuration(currentConfig); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 221 | newOverrideConfig.densityDpi += 120; |
| 222 | newOverrideConfig.fontScale += 0.3; |
| 223 | |
| 224 | sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 225 | |
| 226 | // Check that global configuration is updated, as we've updated default display's config. |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 227 | Configuration globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 228 | assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi); |
| 229 | assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 230 | |
| 231 | // Return back to original values. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 232 | sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 233 | globalConfig = sWm.mRoot.getConfiguration(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 234 | assertEquals(currentConfig.densityDpi, globalConfig.densityDpi); |
| 235 | assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */); |
Andrii Kulian | d68501e | 2017-01-10 22:57:27 -0800 | [diff] [blame] | 236 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 237 | |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 238 | @Test |
| 239 | public void testFocusedWindowMultipleDisplays() throws Exception { |
| 240 | // Create a focusable window and check that focus is calcualted correctly |
| 241 | final WindowState window1 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 242 | createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1"); |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 243 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 244 | |
| 245 | // Check that a new display doesn't affect focus |
| 246 | final DisplayContent dc = createNewDisplay(); |
| 247 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 248 | |
| 249 | // Add a window to the second display, and it should be focused |
| 250 | final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2"); |
| 251 | assertEquals(window2, sWm.mRoot.computeFocusedWindow()); |
| 252 | |
| 253 | // Move the first window to the to including parents, and make sure focus is updated |
| 254 | window1.getParent().positionChildAt(POSITION_TOP, window1, true); |
| 255 | assertEquals(window1, sWm.mRoot.computeFocusedWindow()); |
| 256 | } |
| 257 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 258 | /** |
| 259 | * This tests setting the maximum ui width on a display. |
| 260 | */ |
| 261 | @Test |
| 262 | public void testMaxUiWidth() throws Exception { |
| 263 | final int baseWidth = 1440; |
| 264 | final int baseHeight = 2560; |
| 265 | final int baseDensity = 300; |
| 266 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 267 | mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 268 | |
| 269 | final int maxWidth = 300; |
| 270 | final int resultingHeight = (maxWidth * baseHeight) / baseWidth; |
| 271 | final int resultingDensity = (maxWidth * baseDensity) / baseWidth; |
| 272 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 273 | mDisplayContent.setMaxUiWidth(maxWidth); |
| 274 | verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 275 | |
| 276 | // Assert setting values again does not change; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 277 | mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity); |
| 278 | verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 279 | |
| 280 | final int smallerWidth = 200; |
| 281 | final int smallerHeight = 400; |
| 282 | final int smallerDensity = 100; |
| 283 | |
| 284 | // Specify smaller dimension, verify that it is honored |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 285 | mDisplayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity); |
| 286 | verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 287 | |
| 288 | // Verify that setting the max width to a greater value than the base width has no effect |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 289 | mDisplayContent.setMaxUiWidth(maxWidth); |
| 290 | verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity); |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 293 | /** |
| 294 | * This test enforces that the pinned stack is always kept as the top stack. |
| 295 | */ |
| 296 | @Test |
| 297 | public void testPinnedStackLocation() { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 298 | createStackControllerOnStackOnDisplay(PINNED_STACK_ID, mDisplayContent); |
| 299 | final int initialStackCount = mDisplayContent.getStackCount(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 300 | // Ensure that the pinned stack was placed at the end |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 301 | assertEquals(initialStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 302 | // By default, this should try to create a new stack on top |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 303 | createTaskStackOnDisplay(mDisplayContent); |
| 304 | final int afterStackCount = mDisplayContent.getStackCount(); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 305 | // Make sure the stack count has increased |
| 306 | assertEquals(initialStackCount + 1, afterStackCount); |
| 307 | // Ensure that the pinned stack is still on top |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 308 | assertEquals(afterStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID)); |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 311 | private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth, |
| 312 | int expectedBaseHeight, int expectedBaseDensity) { |
| 313 | assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth); |
| 314 | assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight); |
| 315 | assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity); |
| 316 | } |
| 317 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 318 | private void assertForAllWindowsOrder(List<WindowState> expectedWindows) { |
| 319 | final LinkedList<WindowState> actualWindows = new LinkedList(); |
| 320 | |
| 321 | // Test forward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 322 | mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 323 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 324 | for (WindowState w : expectedWindows) { |
| 325 | assertEquals(w, actualWindows.pollFirst()); |
| 326 | } |
| 327 | assertTrue(actualWindows.isEmpty()); |
| 328 | |
| 329 | // Test backward traversal. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 330 | mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 331 | assertEquals(expectedWindows.size(), actualWindows.size()); |
| 332 | for (WindowState w : expectedWindows) { |
| 333 | assertEquals(w, actualWindows.pollLast()); |
| 334 | } |
| 335 | assertTrue(actualWindows.isEmpty()); |
| 336 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 337 | } |