blob: df35b7eedaf63b83b161b8167cf4ebf7fea0abbb [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.Test;
20import org.junit.runner.RunWith;
21
Wale Ogunwale5fc70962016-09-09 22:36:19 -070022import android.platform.test.annotations.Presubmit;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070023import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070025
26import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080027import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080030import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070031import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertFalse;
33import static org.junit.Assert.assertNull;
34import static org.junit.Assert.assertTrue;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070035
36/**
37 * Tests for the {@link WindowState} class.
38 *
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080039 * Build/Install/Run:
40 * bit FrameworksServicesTests:com.android.server.wm.WindowStateTests
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070041 */
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070042@SmallTest
Wale Ogunwale5fc70962016-09-09 22:36:19 -070043@Presubmit
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070044@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080045public class WindowStateTests extends WindowTestsBase {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070046
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070047 @Test
Wale Ogunwale9d147902016-07-16 11:58:55 -070048 public void testIsParentWindowHidden() throws Exception {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080049 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
50 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
51 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
Wale Ogunwale9d147902016-07-16 11:58:55 -070052
53 assertFalse(parentWindow.mHidden);
54 assertFalse(parentWindow.isParentWindowHidden());
55 assertFalse(child1.isParentWindowHidden());
56 assertFalse(child2.isParentWindowHidden());
57
58 parentWindow.mHidden = true;
59 assertFalse(parentWindow.isParentWindowHidden());
60 assertTrue(child1.isParentWindowHidden());
61 assertTrue(child2.isParentWindowHidden());
62 }
63
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070064 @Test
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070065 public void testIsChildWindow() throws Exception {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080066 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
67 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
68 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
69 final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070070
71 assertFalse(parentWindow.isChildWindow());
72 assertTrue(child1.isChildWindow());
73 assertTrue(child2.isChildWindow());
74 assertFalse(randomWindow.isChildWindow());
75 }
76
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070077 @Test
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070078 public void testHasChild() throws Exception {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080079 final WindowState win1 = createWindow(null, TYPE_APPLICATION, "win1");
80 final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, "win11");
81 final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, "win12");
82 final WindowState win2 = createWindow(null, TYPE_APPLICATION, "win2");
83 final WindowState win21 = createWindow(win2, FIRST_SUB_WINDOW, "win21");
84 final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070085
86 assertTrue(win1.hasChild(win11));
87 assertTrue(win1.hasChild(win12));
88 assertTrue(win2.hasChild(win21));
89
90 assertFalse(win1.hasChild(win21));
91 assertFalse(win1.hasChild(randomWindow));
92
93 assertFalse(win2.hasChild(win11));
94 assertFalse(win2.hasChild(win12));
95 assertFalse(win2.hasChild(randomWindow));
96 }
97
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070098 @Test
Wale Ogunwalecaa53af2016-07-17 14:50:26 -070099 public void testGetParentWindow() throws Exception {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800100 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
101 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
102 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700103
104 assertNull(parentWindow.getParentWindow());
105 assertEquals(parentWindow, child1.getParentWindow());
106 assertEquals(parentWindow, child2.getParentWindow());
107 }
108
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700109 @Test
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700110 public void testGetTopParentWindow() throws Exception {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800111 final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
112 final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1");
113 final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700114
115 assertEquals(root, root.getTopParentWindow());
116 assertEquals(root, child1.getTopParentWindow());
117 assertEquals(child1, child2.getParentWindow());
118 assertEquals(root, child2.getTopParentWindow());
Wale Ogunwaleea92d972016-12-08 07:33:13 -0800119
120 // Test case were child is detached from parent.
121 root.removeChild(child1);
122 assertEquals(child1, child1.getTopParentWindow());
123 assertEquals(child1, child2.getParentWindow());
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700124 }
125
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800126 @Test
127 public void testIsOnScreen_hiddenByPolicy() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800128 final WindowState window = createWindow(null, TYPE_APPLICATION, "window");
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800129 window.setHasSurface(true);
130 assertTrue(window.isOnScreen());
131 window.hideLw(false /* doAnimation */);
132 assertFalse(window.isOnScreen());
133 }
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800134
135 @Test
136 public void testCanBeImeTarget() throws Exception {
137 final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
138 final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, "imeWindow");
139
140 // Setting FLAG_NOT_FOCUSABLE without FLAG_ALT_FOCUSABLE_IM prevents the window from being
141 // an IME target.
142 appWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
143 imeWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
144
145 // Make windows visible
146 appWindow.setHasSurface(true);
147 imeWindow.setHasSurface(true);
148
149 // Windows without flags (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) can't be IME targets
150 assertFalse(appWindow.canBeImeTarget());
151 assertFalse(imeWindow.canBeImeTarget());
152
153 // Add IME target flags
154 appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
155 imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
156
157 // Visible app window with flags can be IME target while an IME window can never be an IME
158 // target regardless of its visibility or flags.
159 assertTrue(appWindow.canBeImeTarget());
160 assertFalse(imeWindow.canBeImeTarget());
161
162 // Make windows invisible
163 appWindow.hideLw(false /* doAnimation */);
164 imeWindow.hideLw(false /* doAnimation */);
165
166 // Invisible window can't be IME targets even if they have the right flags.
167 assertFalse(appWindow.canBeImeTarget());
168 assertFalse(imeWindow.canBeImeTarget());
169 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700170}