Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -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 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 24 | import android.os.Binder; |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 25 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 26 | import android.support.test.InstrumentationRegistry; |
| 27 | import android.support.test.filters.SmallTest; |
| 28 | import android.support.test.runner.AndroidJUnit4; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 29 | import android.view.IWindow; |
| 30 | import android.view.WindowManager; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 31 | |
| 32 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 36 | import static org.junit.Assert.assertEquals; |
| 37 | import static org.junit.Assert.assertFalse; |
| 38 | import static org.junit.Assert.assertNull; |
| 39 | import static org.junit.Assert.assertTrue; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Tests for the {@link WindowState} class. |
| 43 | * |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 44 | * runtest frameworks-services -c com.android.server.wm.WindowStateTests |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 45 | */ |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 46 | @SmallTest |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 47 | @Presubmit |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 48 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 49 | public class WindowStateTests extends WindowTestsBase { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 50 | |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 51 | private WindowToken mWindowToken; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 52 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 53 | @Before |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 54 | public void setUp() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 55 | super.setUp(); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 56 | mWindowToken = new WindowToken(sWm, new Binder(), 0, false, |
| 57 | sWm.getDefaultDisplayContentLocked()); |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 60 | @Test |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 61 | public void testIsParentWindowHidden() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 62 | 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 Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 68 | |
| 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 Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 80 | @Test |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 81 | public void testIsChildWindow() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 82 | 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 Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 90 | |
| 91 | assertFalse(parentWindow.isChildWindow()); |
| 92 | assertTrue(child1.isChildWindow()); |
| 93 | assertTrue(child2.isChildWindow()); |
| 94 | assertFalse(randomWindow.isChildWindow()); |
| 95 | } |
| 96 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 97 | @Test |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 98 | public void testHasChild() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 99 | 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 Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 106 | |
| 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 Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 119 | @Test |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 120 | public void testGetBottomChild() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 121 | final WindowState parentWindow = |
| 122 | createWindow(null, TYPE_APPLICATION, mWindowToken, "parentWindow"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 123 | assertNull(parentWindow.getBottomChild()); |
| 124 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 125 | final WindowState child1 = |
| 126 | createWindow(parentWindow, TYPE_APPLICATION_PANEL, mWindowToken, "child1"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 127 | assertEquals(child1, parentWindow.getBottomChild()); |
| 128 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 129 | final WindowState child2 = |
| 130 | createWindow(parentWindow, TYPE_APPLICATION_PANEL, mWindowToken, "child2"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 131 | // 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 Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 135 | final WindowState child3 = |
| 136 | createWindow(parentWindow, TYPE_APPLICATION_MEDIA_OVERLAY, mWindowToken, "child3"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 137 | // 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 Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 141 | final WindowState child4 = |
| 142 | createWindow(parentWindow, TYPE_APPLICATION_MEDIA_OVERLAY, mWindowToken, "child4"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 143 | // We would also expect additional negative layers to be added below existing negative |
| 144 | // layers. |
| 145 | assertEquals(child4, parentWindow.getBottomChild()); |
| 146 | } |
| 147 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 148 | @Test |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 149 | public void testGetParentWindow() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 150 | 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 Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 156 | |
| 157 | assertNull(parentWindow.getParentWindow()); |
| 158 | assertEquals(parentWindow, child1.getParentWindow()); |
| 159 | assertEquals(parentWindow, child2.getParentWindow()); |
| 160 | } |
| 161 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 162 | @Test |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 163 | public void testGetTopParentWindow() throws Exception { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 164 | 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 Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 167 | |
| 168 | assertEquals(root, root.getTopParentWindow()); |
| 169 | assertEquals(root, child1.getTopParentWindow()); |
| 170 | assertEquals(child1, child2.getParentWindow()); |
| 171 | assertEquals(root, child2.getTopParentWindow()); |
| 172 | } |
| 173 | |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 174 | @Test |
| 175 | public void testIsOnScreen_hiddenByPolicy() { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 176 | final WindowState window = createWindow(null, TYPE_APPLICATION, mWindowToken, "window"); |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 177 | window.setHasSurface(true); |
| 178 | assertTrue(window.isOnScreen()); |
| 179 | window.hideLw(false /* doAnimation */); |
| 180 | assertFalse(window.isOnScreen()); |
| 181 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 182 | } |