blob: 50e5a2220ee3a814eb721109bb5f2c9e38b8884c [file] [log] [blame]
Wale Ogunwaleb699ce02016-07-18 12:05:30 -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 Ogunwalea7e3b642016-08-29 10:15:34 -070019import org.junit.Before;
20import org.junit.Test;
21import org.junit.runner.RunWith;
22
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070023import android.content.Context;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import android.os.Binder;
Wale Ogunwale5fc70962016-09-09 22:36:19 -070025import android.platform.test.annotations.Presubmit;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070026import android.support.test.InstrumentationRegistry;
27import android.support.test.filters.SmallTest;
28import android.support.test.runner.AndroidJUnit4;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070029import android.view.IWindow;
30import android.view.WindowManager;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070031
32import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
33import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070034import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
35import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070036import static org.junit.Assert.assertEquals;
37import static org.junit.Assert.assertFalse;
38import static org.junit.Assert.assertNull;
39import static org.junit.Assert.assertTrue;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070040
41/**
42 * Tests for the {@link WindowState} class.
43 *
Jorim Jaggiaf221d12016-11-15 14:59:57 -080044 * runtest frameworks-services -c com.android.server.wm.WindowStateTests
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070045 */
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070046@SmallTest
Wale Ogunwale5fc70962016-09-09 22:36:19 -070047@Presubmit
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070048@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080049public class WindowStateTests extends WindowTestsBase {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070050
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070051 private WindowToken mWindowToken;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070052
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070053 @Before
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070054 public void setUp() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080055 super.setUp();
Wale Ogunwale02319a62016-09-26 15:21:22 -070056 mWindowToken = new WindowToken(sWm, new Binder(), 0, false,
57 sWm.getDefaultDisplayContentLocked());
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070058 }
59
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070060 @Test
Wale Ogunwale9d147902016-07-16 11:58:55 -070061 public void testIsParentWindowHidden() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080062 final WindowState parentWindow =
63 createWindow(null, TYPE_APPLICATION, mWindowToken, "parentWindow");
64 final WindowState child1 =
65 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child1");
66 final WindowState child2 =
67 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child2");
Wale Ogunwale9d147902016-07-16 11:58:55 -070068
69 assertFalse(parentWindow.mHidden);
70 assertFalse(parentWindow.isParentWindowHidden());
71 assertFalse(child1.isParentWindowHidden());
72 assertFalse(child2.isParentWindowHidden());
73
74 parentWindow.mHidden = true;
75 assertFalse(parentWindow.isParentWindowHidden());
76 assertTrue(child1.isParentWindowHidden());
77 assertTrue(child2.isParentWindowHidden());
78 }
79
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070080 @Test
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070081 public void testIsChildWindow() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080082 final WindowState parentWindow =
83 createWindow(null, TYPE_APPLICATION, mWindowToken, "parentWindow");
84 final WindowState child1 =
85 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child1");
86 final WindowState child2 =
87 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child2");
88 final WindowState randomWindow =
89 createWindow(null, TYPE_APPLICATION, mWindowToken, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070090
91 assertFalse(parentWindow.isChildWindow());
92 assertTrue(child1.isChildWindow());
93 assertTrue(child2.isChildWindow());
94 assertFalse(randomWindow.isChildWindow());
95 }
96
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070097 @Test
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070098 public void testHasChild() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080099 final WindowState win1 = createWindow(null, TYPE_APPLICATION, mWindowToken, "win1");
100 final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, mWindowToken, "win11");
101 final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, mWindowToken, "win12");
102 final WindowState win2 = createWindow(null, TYPE_APPLICATION, mWindowToken, "win2");
103 final WindowState win21 = createWindow(win2, FIRST_SUB_WINDOW, mWindowToken, "win21");
104 final WindowState randomWindow =
105 createWindow(null, TYPE_APPLICATION, mWindowToken, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700106
107 assertTrue(win1.hasChild(win11));
108 assertTrue(win1.hasChild(win12));
109 assertTrue(win2.hasChild(win21));
110
111 assertFalse(win1.hasChild(win21));
112 assertFalse(win1.hasChild(randomWindow));
113
114 assertFalse(win2.hasChild(win11));
115 assertFalse(win2.hasChild(win12));
116 assertFalse(win2.hasChild(randomWindow));
117 }
118
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700119 @Test
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700120 public void testGetBottomChild() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800121 final WindowState parentWindow =
122 createWindow(null, TYPE_APPLICATION, mWindowToken, "parentWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700123 assertNull(parentWindow.getBottomChild());
124
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800125 final WindowState child1 =
126 createWindow(parentWindow, TYPE_APPLICATION_PANEL, mWindowToken, "child1");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700127 assertEquals(child1, parentWindow.getBottomChild());
128
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800129 final WindowState child2 =
130 createWindow(parentWindow, TYPE_APPLICATION_PANEL, mWindowToken, "child2");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700131 // Since child1 and child2 are at the same layer, then child2 is expect to be added on top
132 // on child1
133 assertEquals(child1, parentWindow.getBottomChild());
134
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800135 final WindowState child3 =
136 createWindow(parentWindow, TYPE_APPLICATION_MEDIA_OVERLAY, mWindowToken, "child3");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700137 // Since child3 is a negative layer, we would expect it to be added below current children
138 // with positive layers.
139 assertEquals(child3, parentWindow.getBottomChild());
140
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800141 final WindowState child4 =
142 createWindow(parentWindow, TYPE_APPLICATION_MEDIA_OVERLAY, mWindowToken, "child4");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700143 // We would also expect additional negative layers to be added below existing negative
144 // layers.
145 assertEquals(child4, parentWindow.getBottomChild());
146 }
147
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700148 @Test
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700149 public void testGetParentWindow() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800150 final WindowState parentWindow =
151 createWindow(null, TYPE_APPLICATION, mWindowToken, "parentWindow");
152 final WindowState child1 =
153 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child1");
154 final WindowState child2 =
155 createWindow(parentWindow, FIRST_SUB_WINDOW, mWindowToken, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700156
157 assertNull(parentWindow.getParentWindow());
158 assertEquals(parentWindow, child1.getParentWindow());
159 assertEquals(parentWindow, child2.getParentWindow());
160 }
161
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700162 @Test
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700163 public void testGetTopParentWindow() throws Exception {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800164 final WindowState root = createWindow(null, TYPE_APPLICATION, mWindowToken, "root");
165 final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, mWindowToken, "child1");
166 final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, mWindowToken, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700167
168 assertEquals(root, root.getTopParentWindow());
169 assertEquals(root, child1.getTopParentWindow());
170 assertEquals(child1, child2.getParentWindow());
171 assertEquals(root, child2.getTopParentWindow());
172 }
173
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800174 @Test
175 public void testIsOnScreen_hiddenByPolicy() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800176 final WindowState window = createWindow(null, TYPE_APPLICATION, mWindowToken, "window");
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800177 window.setHasSurface(true);
178 assertTrue(window.isOnScreen());
179 window.hideLw(false /* doAnimation */);
180 assertFalse(window.isOnScreen());
181 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700182}