blob: c8650bf846c57fbc72e39e8401049f63e7dff0bb [file] [log] [blame]
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001/*
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 Ogunwale44fbdf52016-11-16 10:18:45 -080019import org.junit.Test;
20import org.junit.runner.RunWith;
21
22import android.platform.test.annotations.Presubmit;
23import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
25
26import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080028import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080029import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080030
31/**
32 * Tests for the {@link WindowLayersController} class.
33 *
34 * Build/Install/Run:
35 * bit FrameworksServicesTests:com.android.server.wm.WindowLayersControllerTests
36 */
37@SmallTest
38@Presubmit
39@RunWith(AndroidJUnit4.class)
40public class WindowLayersControllerTests extends WindowTestsBase {
41
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080042 @Test
43 public void testAssignWindowLayers_ForImeWithNoTarget() throws Exception {
44 sWm.mInputMethodTarget = null;
45 sLayersController.assignWindowLayers(sDisplayContent);
46
47 // The Ime has an higher base layer than app windows and lower base layer than system
48 // windows, so it should be above app windows and below system windows if there isn't an IME
49 // target.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080050 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindowAbove);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080051 assertWindowLayerGreaterThan(sImeWindow, sAppWindow);
52 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow);
53 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow);
54 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow);
55
56 // And, IME dialogs should always have an higher layer than the IME.
57 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow);
58 }
59
60 @Test
61 public void testAssignWindowLayers_ForImeWithAppTarget() throws Exception {
62 final WindowState imeAppTarget =
63 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget");
64 sWm.mInputMethodTarget = imeAppTarget;
65 sLayersController.assignWindowLayers(sDisplayContent);
66
67 // Ime should be above all app windows and below system windows if it is targeting an app
68 // window.
69 assertWindowLayerGreaterThan(sImeWindow, imeAppTarget);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080070 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindowAbove);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080071 assertWindowLayerGreaterThan(sImeWindow, sAppWindow);
72 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow);
73 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow);
74 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow);
75
76 // And, IME dialogs should always have an higher layer than the IME.
77 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow);
78 }
79
80 @Test
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080081 public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() throws Exception {
82 final WindowState imeAppTarget =
83 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget");
84 final WindowState imeAppTargetChildAboveWindow = createWindow(imeAppTarget,
85 TYPE_APPLICATION_ATTACHED_DIALOG, imeAppTarget.mToken,
86 "imeAppTargetChildAboveWindow");
87 final WindowState imeAppTargetChildBelowWindow = createWindow(imeAppTarget,
88 TYPE_APPLICATION_MEDIA_OVERLAY, imeAppTarget.mToken,
89 "imeAppTargetChildBelowWindow");
90
91 sWm.mInputMethodTarget = imeAppTarget;
92 sLayersController.assignWindowLayers(sDisplayContent);
93
94 // Ime should be above all app windows except for child windows that are z-ordered above it
95 // and below system windows if it is targeting an app window.
96 assertWindowLayerGreaterThan(sImeWindow, imeAppTarget);
97 assertWindowLayerGreaterThan(imeAppTargetChildAboveWindow, sImeWindow);
98 assertWindowLayerGreaterThan(sImeWindow, imeAppTargetChildBelowWindow);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080099 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindowAbove);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800100 assertWindowLayerGreaterThan(sImeWindow, sAppWindow);
101 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow);
102 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow);
103 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow);
104
105 // And, IME dialogs should always have an higher layer than the IME.
106 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow);
107 }
108
109 @Test
110 public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() throws Exception {
111 final WindowState appBelowImeTarget =
112 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "appBelowImeTarget");
113 final WindowState imeAppTarget =
114 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget");
115 final WindowState appAboveImeTarget =
116 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "appAboveImeTarget");
117
118 sWm.mInputMethodTarget = imeAppTarget;
119 sLayersController.assignWindowLayers(sDisplayContent);
120
121 // Ime should be above all app windows except for non-fullscreen app window above it and
122 // below system windows if it is targeting an app window.
123 assertWindowLayerGreaterThan(sImeWindow, imeAppTarget);
124 assertWindowLayerGreaterThan(sImeWindow, appBelowImeTarget);
125 assertWindowLayerGreaterThan(appAboveImeTarget, sImeWindow);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800126 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindowAbove);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800127 assertWindowLayerGreaterThan(sImeWindow, sAppWindow);
128 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow);
129 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow);
130 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow);
131
132 // And, IME dialogs should always have an higher layer than the IME.
133 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow);
134 }
135
136 @Test
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800137 public void testAssignWindowLayers_ForImeNonAppImeTarget() throws Exception {
138 final WindowState imeSystemOverlayTarget =
139 createWindow(null, TYPE_SYSTEM_OVERLAY, sDisplayContent, "imeSystemOverlayTarget");
140
141 sWm.mInputMethodTarget = imeSystemOverlayTarget;
142 sLayersController.assignWindowLayers(sDisplayContent);
143
144 // The IME target base layer is higher than all window except for the nav bar window, so the
145 // IME should be above all windows except for the nav bar.
146 assertWindowLayerGreaterThan(sImeWindow, imeSystemOverlayTarget);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800147 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindowAbove);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800148 assertWindowLayerGreaterThan(sImeWindow, sAppWindow);
149 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow);
150 assertWindowLayerGreaterThan(sImeWindow, sStatusBarWindow);
151 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow);
152
153 // And, IME dialogs should always have an higher layer than the IME.
154 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow);
155 }
156
157 private void assertWindowLayerGreaterThan(WindowState first, WindowState second)
158 throws Exception {
159 assertGreaterThan(first.mWinAnimator.mAnimLayer, second.mWinAnimator.mAnimLayer);
160 }
161
162}