blob: 0801a883177d28b9a050384933c6a745fa06ddd3 [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
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070019import org.junit.Test;
20import org.junit.runner.RunWith;
21
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070022import android.platform.test.annotations.Presubmit;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070023import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070025
26import java.util.ArrayList;
27
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
29import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
30import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
32import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
33import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
34import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
35import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
36import static org.junit.Assert.assertEquals;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070037
38/**
39 * Tests for the {@link DisplayContent} class.
40 *
41 * Build/Install/Run:
42 * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080047public class DisplayContentTests extends WindowTestsBase {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070048
49 @Test
50 public void testForAllWindows() throws Exception {
51 final DisplayContent dc = new DisplayContent(mDisplay, sWm, null, null);
52 final WindowState wallpaperWindow = createWindow(null, TYPE_WALLPAPER, dc, "wallpaper");
53 final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, dc, "ime");
54 final WindowState imeDialogWindow = createWindow(null, TYPE_INPUT_METHOD_DIALOG, dc,
55 "ime dialog");
56 final WindowState statusBarWindow = createWindow(null, TYPE_STATUS_BAR, dc, "status bar");
57 final WindowState navBarWindow = createWindow(null, TYPE_NAVIGATION_BAR,
58 statusBarWindow.mToken, "nav bar");
59 final WindowState appWindow = createWindow(null, TYPE_BASE_APPLICATION, dc, "app");
60 final WindowState negChildAppWindow = createWindow(appWindow, TYPE_APPLICATION_MEDIA,
61 appWindow.mToken, "negative app child");
62 final WindowState posChildAppWindow = createWindow(appWindow,
63 TYPE_APPLICATION_ATTACHED_DIALOG, appWindow.mToken, "positive app child");
64 final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, dc,
65 "exiting app");
66 final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken;
67 exitingAppToken.mIsExiting = true;
68 exitingAppToken.mTask.mStack.mExitingAppTokens.add(exitingAppToken);
69
70 final ArrayList<WindowState> windows = new ArrayList();
71
72 // Test forward traversal.
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080073 dc.forAllWindows(w -> {windows.add(w);}, false /* traverseTopToBottom */);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070074
75 assertEquals(wallpaperWindow, windows.get(0));
76 assertEquals(exitingAppWindow, windows.get(1));
77 assertEquals(negChildAppWindow, windows.get(2));
78 assertEquals(appWindow, windows.get(3));
79 assertEquals(posChildAppWindow, windows.get(4));
80 assertEquals(statusBarWindow, windows.get(5));
81 assertEquals(navBarWindow, windows.get(6));
82 assertEquals(imeWindow, windows.get(7));
83 assertEquals(imeDialogWindow, windows.get(8));
84
85 // Test backward traversal.
86 windows.clear();
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -080087 dc.forAllWindows(w -> {windows.add(w);}, true /* traverseTopToBottom */);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070088
89 assertEquals(wallpaperWindow, windows.get(8));
90 assertEquals(exitingAppWindow, windows.get(7));
91 assertEquals(negChildAppWindow, windows.get(6));
92 assertEquals(appWindow, windows.get(5));
93 assertEquals(posChildAppWindow, windows.get(4));
94 assertEquals(statusBarWindow, windows.get(3));
95 assertEquals(navBarWindow, windows.get(2));
96 assertEquals(imeWindow, windows.get(1));
97 assertEquals(imeDialogWindow, windows.get(0));
98 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070099}