WindowLayersControllerTests.java revision 44fbdf5b1e13398e35d4bafb7236d194a51ee7af
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 17package com.android.server.wm; 18 19import org.junit.Before; 20import org.junit.Test; 21import org.junit.runner.RunWith; 22 23import android.platform.test.annotations.Presubmit; 24import android.support.test.filters.SmallTest; 25import android.support.test.runner.AndroidJUnit4; 26 27import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; 28import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; 29import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; 30import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; 31import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; 32import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; 33import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; 34import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; 35import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; 36 37/** 38 * Tests for the {@link WindowLayersController} class. 39 * 40 * Build/Install/Run: 41 * bit FrameworksServicesTests:com.android.server.wm.WindowLayersControllerTests 42 */ 43@SmallTest 44@Presubmit 45@RunWith(AndroidJUnit4.class) 46public class WindowLayersControllerTests extends WindowTestsBase { 47 48 private static boolean sOneTimeSetupDone = false; 49 private static WindowLayersController sLayersController; 50 private static DisplayContent sDisplayContent; 51 private static WindowState sImeWindow; 52 private static WindowState sImeDialogWindow; 53 private static WindowState sStatusBarWindow; 54 private static WindowState sDockedDividerWindow; 55 private static WindowState sNavBarWindow; 56 private static WindowState sAppWindow; 57 private static WindowState sChildAppWindow; 58 59 @Before 60 public void setUp() throws Exception { 61 super.setUp(); 62 63 if (sOneTimeSetupDone) { 64 return; 65 } 66 sOneTimeSetupDone = true; 67 sLayersController = new WindowLayersController(sWm); 68 sDisplayContent = 69 new DisplayContent(mDisplay, sWm, sLayersController, new WallpaperController(sWm)); 70 final WindowState wallpaperWindow = 71 createWindow(null, TYPE_WALLPAPER, sDisplayContent, "wallpaperWindow"); 72 sImeWindow = createWindow(null, TYPE_INPUT_METHOD, sDisplayContent, "sImeWindow"); 73 sImeDialogWindow = 74 createWindow(null, TYPE_INPUT_METHOD_DIALOG, sDisplayContent, "sImeDialogWindow"); 75 sStatusBarWindow = createWindow(null, TYPE_STATUS_BAR, sDisplayContent, "sStatusBarWindow"); 76 sNavBarWindow = 77 createWindow(null, TYPE_NAVIGATION_BAR, sStatusBarWindow.mToken, "sNavBarWindow"); 78 sDockedDividerWindow = 79 createWindow(null, TYPE_DOCK_DIVIDER, sDisplayContent, "sDockedDividerWindow"); 80 sAppWindow = createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "sAppWindow"); 81 sChildAppWindow = createWindow(sAppWindow, 82 TYPE_APPLICATION_ATTACHED_DIALOG, sAppWindow.mToken, "sChildAppWindow"); 83 } 84 85 @Test 86 public void testAssignWindowLayers_ForImeWithNoTarget() throws Exception { 87 sWm.mInputMethodTarget = null; 88 sLayersController.assignWindowLayers(sDisplayContent); 89 90 // The Ime has an higher base layer than app windows and lower base layer than system 91 // windows, so it should be above app windows and below system windows if there isn't an IME 92 // target. 93 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindow); 94 assertWindowLayerGreaterThan(sImeWindow, sAppWindow); 95 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow); 96 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow); 97 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow); 98 99 // And, IME dialogs should always have an higher layer than the IME. 100 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow); 101 } 102 103 @Test 104 public void testAssignWindowLayers_ForImeWithAppTarget() throws Exception { 105 final WindowState imeAppTarget = 106 createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget"); 107 sWm.mInputMethodTarget = imeAppTarget; 108 sLayersController.assignWindowLayers(sDisplayContent); 109 110 // Ime should be above all app windows and below system windows if it is targeting an app 111 // window. 112 assertWindowLayerGreaterThan(sImeWindow, imeAppTarget); 113 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindow); 114 assertWindowLayerGreaterThan(sImeWindow, sAppWindow); 115 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow); 116 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow); 117 assertWindowLayerGreaterThan(sStatusBarWindow, sImeWindow); 118 119 // And, IME dialogs should always have an higher layer than the IME. 120 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow); 121 } 122 123 @Test 124 public void testAssignWindowLayers_ForImeNonAppImeTarget() throws Exception { 125 final WindowState imeSystemOverlayTarget = 126 createWindow(null, TYPE_SYSTEM_OVERLAY, sDisplayContent, "imeSystemOverlayTarget"); 127 128 sWm.mInputMethodTarget = imeSystemOverlayTarget; 129 sLayersController.assignWindowLayers(sDisplayContent); 130 131 // The IME target base layer is higher than all window except for the nav bar window, so the 132 // IME should be above all windows except for the nav bar. 133 assertWindowLayerGreaterThan(sImeWindow, imeSystemOverlayTarget); 134 assertWindowLayerGreaterThan(sImeWindow, sChildAppWindow); 135 assertWindowLayerGreaterThan(sImeWindow, sAppWindow); 136 assertWindowLayerGreaterThan(sImeWindow, sDockedDividerWindow); 137 assertWindowLayerGreaterThan(sImeWindow, sStatusBarWindow); 138 assertWindowLayerGreaterThan(sNavBarWindow, sImeWindow); 139 140 // And, IME dialogs should always have an higher layer than the IME. 141 assertWindowLayerGreaterThan(sImeDialogWindow, sImeWindow); 142 } 143 144 private void assertWindowLayerGreaterThan(WindowState first, WindowState second) 145 throws Exception { 146 assertGreaterThan(first.mWinAnimator.mAnimLayer, second.mWinAnimator.mAnimLayer); 147 } 148 149} 150