blob: 91eb55ba3fcf22ae78553a414a1cb80c265e295b [file] [log] [blame]
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001/*
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
17package com.android.server.wm;
18
Bryce Lee48f4b572017-04-10 10:54:15 -070019import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale34247952017-02-19 11:57:53 -080020import static android.view.Display.DEFAULT_DISPLAY;
21import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
22import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
23import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
24import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
David Stevens46939562017-03-24 13:04:00 -070025import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale34247952017-02-19 11:57:53 -080026import static org.junit.Assert.assertEquals;
27import static org.junit.Assert.assertTrue;
28
Wale Ogunwale42bab782017-05-02 13:16:39 -070029import org.junit.Ignore;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070030import org.junit.Test;
31import org.junit.runner.RunWith;
32
Andrii Kuliand68501e2017-01-10 22:57:27 -080033import android.content.res.Configuration;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070034import android.os.SystemClock;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070035import android.platform.test.annotations.Presubmit;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070036import android.support.test.filters.SmallTest;
37import android.support.test.runner.AndroidJUnit4;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070038import android.util.DisplayMetrics;
Andrii Kulian0214ed92017-05-16 13:44:05 -070039import android.util.SparseIntArray;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070040import android.view.MotionEvent;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070041
Wale Ogunwale34247952017-02-19 11:57:53 -080042import java.util.Arrays;
43import java.util.LinkedList;
44import java.util.List;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070045
46/**
47 * Tests for the {@link DisplayContent} class.
48 *
49 * Build/Install/Run:
50 * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests
51 */
52@SmallTest
53@Presubmit
54@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080055public class DisplayContentTests extends WindowTestsBase {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070056
57 @Test
58 public void testForAllWindows() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080059 final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070060 mDisplayContent, "exiting app");
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070061 final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken;
62 exitingAppToken.mIsExiting = true;
Bryce Lee6d410262017-02-28 15:30:17 -080063 exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070064
Wale Ogunwale34247952017-02-19 11:57:53 -080065 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -070066 mWallpaperWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -080067 exitingAppWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070068 mChildAppWindowBelow,
69 mAppWindow,
70 mChildAppWindowAbove,
71 mDockedDividerWindow,
72 mStatusBarWindow,
73 mNavBarWindow,
74 mImeWindow,
75 mImeDialogWindow));
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080076 }
77
78 @Test
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080079 public void testForAllWindows_WithAppImeTarget() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080080 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070081 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080082
83 sWm.mInputMethodTarget = imeAppTarget;
84
Wale Ogunwale34247952017-02-19 11:57:53 -080085 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -070086 mWallpaperWindow,
87 mChildAppWindowBelow,
88 mAppWindow,
89 mChildAppWindowAbove,
Wale Ogunwale34247952017-02-19 11:57:53 -080090 imeAppTarget,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070091 mImeWindow,
92 mImeDialogWindow,
93 mDockedDividerWindow,
94 mStatusBarWindow,
95 mNavBarWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -080096 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080097
Wale Ogunwale34247952017-02-19 11:57:53 -080098 @Test
99 public void testForAllWindows_WithChildWindowImeTarget() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700100 sWm.mInputMethodTarget = mChildAppWindowAbove;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800101
Wale Ogunwale34247952017-02-19 11:57:53 -0800102 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700103 mWallpaperWindow,
104 mChildAppWindowBelow,
105 mAppWindow,
106 mChildAppWindowAbove,
107 mImeWindow,
108 mImeDialogWindow,
109 mDockedDividerWindow,
110 mStatusBarWindow,
111 mNavBarWindow));
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700112 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800113
114 @Test
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800115 public void testForAllWindows_WithStatusBarImeTarget() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700116 sWm.mInputMethodTarget = mStatusBarWindow;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800117
Wale Ogunwale34247952017-02-19 11:57:53 -0800118 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700119 mWallpaperWindow,
120 mChildAppWindowBelow,
121 mAppWindow,
122 mChildAppWindowAbove,
123 mDockedDividerWindow,
124 mStatusBarWindow,
125 mImeWindow,
126 mImeDialogWindow,
127 mNavBarWindow));
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800128 }
129
130 @Test
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800131 public void testForAllWindows_WithInBetweenWindowToken() throws Exception {
132 // This window is set-up to be z-ordered between some windows that go in the same token like
133 // the nav bar and status bar.
134 final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700135 mDisplayContent, "voiceInteractionWindow");
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800136
Wale Ogunwale34247952017-02-19 11:57:53 -0800137 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700138 mWallpaperWindow,
139 mChildAppWindowBelow,
140 mAppWindow,
141 mChildAppWindowAbove,
142 mDockedDividerWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -0800143 voiceInteractionWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700144 mStatusBarWindow,
145 mNavBarWindow,
146 mImeWindow,
147 mImeDialogWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -0800148 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800149
Wale Ogunwale34247952017-02-19 11:57:53 -0800150 @Test
151 public void testComputeImeTarget() throws Exception {
152 // Verify that an app window can be an ime target.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700153 final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin");
Wale Ogunwale34247952017-02-19 11:57:53 -0800154 appWin.setHasSurface(true);
155 assertTrue(appWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700156 WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800157 assertEquals(appWin, imeTarget);
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800158
Wale Ogunwale34247952017-02-19 11:57:53 -0800159 // Verify that an child window can be an ime target.
160 final WindowState childWin = createWindow(appWin,
161 TYPE_APPLICATION_ATTACHED_DIALOG, "childWin");
162 childWin.setHasSurface(true);
163 assertTrue(childWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700164 imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800165 assertEquals(childWin, imeTarget);
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800166 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800167
Andrii Kuliand68501e2017-01-10 22:57:27 -0800168 /**
169 * This tests stack movement between displays and proper stack's, task's and app token's display
170 * container references updates.
171 */
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800172 @Test
173 public void testMoveStackBetweenDisplays() throws Exception {
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800174 // Create a second display.
175 final DisplayContent dc = createNewDisplay();
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800176
177 // Add stack with activity.
178 final TaskStack stack = createTaskStackOnDisplay(dc);
179 assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId());
180 assertEquals(dc, stack.getParent().getParent());
181 assertEquals(dc, stack.getDisplayContent());
182
183 final Task task = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -0700184 final WindowTestUtils.TestAppWindowToken token = new WindowTestUtils.TestAppWindowToken(dc);
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800185 task.addChild(token, 0);
186 assertEquals(dc, task.getDisplayContent());
187 assertEquals(dc, token.getDisplayContent());
188
189 // Move stack to first display.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700190 mDisplayContent.moveStackToDisplay(stack, true /* onTop */);
191 assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId());
192 assertEquals(mDisplayContent, stack.getParent().getParent());
193 assertEquals(mDisplayContent, stack.getDisplayContent());
194 assertEquals(mDisplayContent, task.getDisplayContent());
195 assertEquals(mDisplayContent, token.getDisplayContent());
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800196 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800197
198 /**
199 * This tests override configuration updates for display content.
200 */
201 @Test
202 public void testDisplayOverrideConfigUpdate() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700203 final int displayId = mDisplayContent.getDisplayId();
204 final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800205
206 // Create new, slightly changed override configuration and apply it to the display.
207 final Configuration newOverrideConfig = new Configuration(currentOverrideConfig);
208 newOverrideConfig.densityDpi += 120;
209 newOverrideConfig.fontScale += 0.3;
210
211 sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId);
212
213 // Check that override config is applied.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700214 assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration());
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800215 }
216
217 /**
218 * This tests global configuration updates when default display config is updated.
219 */
220 @Test
221 public void testDefaultDisplayOverrideConfigUpdate() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700222 final Configuration currentConfig = mDisplayContent.getConfiguration();
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800223
224 // Create new, slightly changed override configuration and apply it to the display.
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700225 final Configuration newOverrideConfig = new Configuration(currentConfig);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800226 newOverrideConfig.densityDpi += 120;
227 newOverrideConfig.fontScale += 0.3;
228
229 sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800230
231 // Check that global configuration is updated, as we've updated default display's config.
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800232 Configuration globalConfig = sWm.mRoot.getConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800233 assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi);
234 assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800235
236 // Return back to original values.
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700237 sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800238 globalConfig = sWm.mRoot.getConfiguration();
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700239 assertEquals(currentConfig.densityDpi, globalConfig.densityDpi);
240 assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800241 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800242
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700243 /**
244 * Tests tapping on a stack in different display results in window gaining focus.
245 */
246 @Test
247 public void testInputEventBringsCorrectDisplayInFocus() throws Exception {
248 DisplayContent dc0 = sWm.getDefaultDisplayContentLocked();
249 // Create a second display
250 final DisplayContent dc1 = createNewDisplay();
251
252 // Add stack with activity.
253 final TaskStack stack0 = createTaskStackOnDisplay(dc0);
254 final Task task0 = createTaskInStack(stack0, 0 /* userId */);
255 final WindowTestUtils.TestAppWindowToken token =
256 new WindowTestUtils.TestAppWindowToken(dc0);
257 task0.addChild(token, 0);
258 dc0.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
259 sWm.registerPointerEventListener(dc0.mTapDetector);
260 final TaskStack stack1 = createTaskStackOnDisplay(dc1);
261 final Task task1 = createTaskInStack(stack1, 0 /* userId */);
262 final WindowTestUtils.TestAppWindowToken token1 =
263 new WindowTestUtils.TestAppWindowToken(dc0);
264 task1.addChild(token1, 0);
265 dc1.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
266 sWm.registerPointerEventListener(dc1.mTapDetector);
267
268 // tap on primary display (by sending ACTION_DOWN followed by ACTION_UP)
269 DisplayMetrics dm0 = dc0.getDisplayMetrics();
270 dc0.mTapDetector.onPointerEvent(
271 createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, true));
272 dc0.mTapDetector.onPointerEvent(
273 createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, false));
274
275 // Check focus is on primary display.
276 assertEquals(sWm.mCurrentFocus, dc0.findFocusedWindow());
277
278 // Tap on secondary display
279 DisplayMetrics dm1 = dc1.getDisplayMetrics();
280 dc1.mTapDetector.onPointerEvent(
281 createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, true));
282 dc1.mTapDetector.onPointerEvent(
283 createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, false));
284
285 // Check focus is on secondary.
286 assertEquals(sWm.mCurrentFocus, dc1.findFocusedWindow());
287 }
288
David Stevens46939562017-03-24 13:04:00 -0700289 @Test
Wale Ogunwale42bab782017-05-02 13:16:39 -0700290 @Ignore
David Stevens46939562017-03-24 13:04:00 -0700291 public void testFocusedWindowMultipleDisplays() throws Exception {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700292 // Create a focusable window and check that focus is calculated correctly
David Stevens46939562017-03-24 13:04:00 -0700293 final WindowState window1 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700294 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1");
David Stevens46939562017-03-24 13:04:00 -0700295 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
296
297 // Check that a new display doesn't affect focus
298 final DisplayContent dc = createNewDisplay();
299 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
300
301 // Add a window to the second display, and it should be focused
302 final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2");
303 assertEquals(window2, sWm.mRoot.computeFocusedWindow());
304
305 // Move the first window to the to including parents, and make sure focus is updated
306 window1.getParent().positionChildAt(POSITION_TOP, window1, true);
307 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
308 }
309
Bryce Lee27cec322017-03-21 09:41:37 -0700310 /**
311 * This tests setting the maximum ui width on a display.
312 */
313 @Test
314 public void testMaxUiWidth() throws Exception {
315 final int baseWidth = 1440;
316 final int baseHeight = 2560;
317 final int baseDensity = 300;
318
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700319 mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700320
321 final int maxWidth = 300;
322 final int resultingHeight = (maxWidth * baseHeight) / baseWidth;
323 final int resultingDensity = (maxWidth * baseDensity) / baseWidth;
324
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700325 mDisplayContent.setMaxUiWidth(maxWidth);
326 verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700327
328 // Assert setting values again does not change;
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700329 mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
330 verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700331
332 final int smallerWidth = 200;
333 final int smallerHeight = 400;
334 final int smallerDensity = 100;
335
336 // Specify smaller dimension, verify that it is honored
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700337 mDisplayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity);
338 verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700339
340 // Verify that setting the max width to a greater value than the base width has no effect
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700341 mDisplayContent.setMaxUiWidth(maxWidth);
342 verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700343 }
344
Bryce Lee48f4b572017-04-10 10:54:15 -0700345 /**
346 * This test enforces that the pinned stack is always kept as the top stack.
347 */
348 @Test
349 public void testPinnedStackLocation() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700350 createStackControllerOnStackOnDisplay(PINNED_STACK_ID, mDisplayContent);
351 final int initialStackCount = mDisplayContent.getStackCount();
Bryce Lee48f4b572017-04-10 10:54:15 -0700352 // Ensure that the pinned stack was placed at the end
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700353 assertEquals(initialStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID));
Bryce Lee48f4b572017-04-10 10:54:15 -0700354 // By default, this should try to create a new stack on top
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700355 createTaskStackOnDisplay(mDisplayContent);
356 final int afterStackCount = mDisplayContent.getStackCount();
Bryce Lee48f4b572017-04-10 10:54:15 -0700357 // Make sure the stack count has increased
358 assertEquals(initialStackCount + 1, afterStackCount);
359 // Ensure that the pinned stack is still on top
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700360 assertEquals(afterStackCount - 1, mDisplayContent.getStaskPosById(PINNED_STACK_ID));
Bryce Lee48f4b572017-04-10 10:54:15 -0700361 }
362
Andrii Kulian0214ed92017-05-16 13:44:05 -0700363 /**
364 * Test that WM does not report displays to AM that are pending to be removed.
365 */
366 @Test
367 public void testDontReportDeferredRemoval() {
368 // Create a display and add an animating window to it.
369 final DisplayContent dc = createNewDisplay();
370 final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
371 window.mAnimatingExit = true;
372 // Request display removal, it should be deferred.
373 dc.removeIfPossible();
374 // Request ordered display ids from WM.
375 final SparseIntArray orderedDisplayIds = new SparseIntArray();
376 sWm.getDisplaysInFocusOrder(orderedDisplayIds);
377 // Make sure that display that is marked for removal is not reported.
378 assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId()));
379 }
380
Bryce Lee27cec322017-03-21 09:41:37 -0700381 private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
382 int expectedBaseHeight, int expectedBaseDensity) {
383 assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);
384 assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight);
385 assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity);
386 }
387
Wale Ogunwale34247952017-02-19 11:57:53 -0800388 private void assertForAllWindowsOrder(List<WindowState> expectedWindows) {
389 final LinkedList<WindowState> actualWindows = new LinkedList();
390
391 // Test forward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700392 mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800393 assertEquals(expectedWindows.size(), actualWindows.size());
394 for (WindowState w : expectedWindows) {
395 assertEquals(w, actualWindows.pollFirst());
396 }
397 assertTrue(actualWindows.isEmpty());
398
399 // Test backward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700400 mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800401 assertEquals(expectedWindows.size(), actualWindows.size());
402 for (WindowState w : expectedWindows) {
403 assertEquals(w, actualWindows.pollLast());
404 }
405 assertTrue(actualWindows.isEmpty());
406 }
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700407
408 private MotionEvent createTapEvent(float x, float y, boolean isDownEvent) {
409 final long downTime = SystemClock.uptimeMillis();
410 final long eventTime = SystemClock.uptimeMillis() + 100;
411 final int metaState = 0;
412
413 return MotionEvent.obtain(
414 downTime,
415 eventTime,
416 isDownEvent ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP,
417 x,
418 y,
419 metaState);
420 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700421}