Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -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 | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
| 21 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 22 | import android.platform.test.annotations.Presubmit; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 23 | import android.support.test.filters.SmallTest; |
| 24 | import android.support.test.runner.AndroidJUnit4; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.ArrayList; |
| 27 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 29 | import static org.junit.Assert.assertEquals; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Tests for the {@link DisplayContent} class. |
| 33 | * |
| 34 | * Build/Install/Run: |
| 35 | * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests |
| 36 | */ |
| 37 | @SmallTest |
| 38 | @Presubmit |
| 39 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 40 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 41 | |
| 42 | @Test |
| 43 | public void testForAllWindows() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 44 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, |
| 45 | sDisplayContent, "exiting app"); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 46 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 47 | exitingAppToken.mIsExiting = true; |
| 48 | exitingAppToken.mTask.mStack.mExitingAppTokens.add(exitingAppToken); |
| 49 | |
| 50 | final ArrayList<WindowState> windows = new ArrayList(); |
| 51 | |
| 52 | // Test forward traversal. |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 53 | sDisplayContent.forAllWindows(w -> {windows.add(w);}, false /* traverseTopToBottom */); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 54 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 55 | assertEquals(sWallpaperWindow, windows.get(0)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 56 | assertEquals(exitingAppWindow, windows.get(1)); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 57 | assertEquals(sChildAppWindowBelow, windows.get(2)); |
| 58 | assertEquals(sAppWindow, windows.get(3)); |
| 59 | assertEquals(sChildAppWindowAbove, windows.get(4)); |
| 60 | assertEquals(sDockedDividerWindow, windows.get(5)); |
| 61 | assertEquals(sStatusBarWindow, windows.get(6)); |
| 62 | assertEquals(sNavBarWindow, windows.get(7)); |
| 63 | assertEquals(sImeWindow, windows.get(8)); |
| 64 | assertEquals(sImeDialogWindow, windows.get(9)); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 65 | |
| 66 | // Test backward traversal. |
| 67 | windows.clear(); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 68 | sDisplayContent.forAllWindows(w -> {windows.add(w);}, true /* traverseTopToBottom */); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 69 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame^] | 70 | assertEquals(sWallpaperWindow, windows.get(9)); |
| 71 | assertEquals(exitingAppWindow, windows.get(8)); |
| 72 | assertEquals(sChildAppWindowBelow, windows.get(7)); |
| 73 | assertEquals(sAppWindow, windows.get(6)); |
| 74 | assertEquals(sChildAppWindowAbove, windows.get(5)); |
| 75 | assertEquals(sDockedDividerWindow, windows.get(4)); |
| 76 | assertEquals(sStatusBarWindow, windows.get(3)); |
| 77 | assertEquals(sNavBarWindow, windows.get(2)); |
| 78 | assertEquals(sImeWindow, windows.get(1)); |
| 79 | assertEquals(sImeDialogWindow, windows.get(0)); |
| 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testForAllWindows_WithImeTarget() throws Exception { |
| 84 | final WindowState imeAppTarget = |
| 85 | createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "imeAppTarget"); |
| 86 | |
| 87 | sWm.mInputMethodTarget = imeAppTarget; |
| 88 | |
| 89 | final ArrayList<WindowState> windows = new ArrayList(); |
| 90 | |
| 91 | // Test forward traversal. |
| 92 | sDisplayContent.forAllWindows(w -> {windows.add(w);}, false /* traverseTopToBottom */); |
| 93 | |
| 94 | assertEquals(sWallpaperWindow, windows.get(0)); |
| 95 | assertEquals(sChildAppWindowBelow, windows.get(1)); |
| 96 | assertEquals(sAppWindow, windows.get(2)); |
| 97 | assertEquals(sChildAppWindowAbove, windows.get(3)); |
| 98 | assertEquals(imeAppTarget, windows.get(4)); |
| 99 | assertEquals(sImeWindow, windows.get(5)); |
| 100 | assertEquals(sImeDialogWindow, windows.get(6)); |
| 101 | assertEquals(sDockedDividerWindow, windows.get(7)); |
| 102 | assertEquals(sStatusBarWindow, windows.get(8)); |
| 103 | assertEquals(sNavBarWindow, windows.get(9)); |
| 104 | |
| 105 | // Test backward traversal. |
| 106 | windows.clear(); |
| 107 | sDisplayContent.forAllWindows(w -> {windows.add(w);}, true /* traverseTopToBottom */); |
| 108 | |
| 109 | assertEquals(sWallpaperWindow, windows.get(9)); |
| 110 | assertEquals(sChildAppWindowBelow, windows.get(8)); |
| 111 | assertEquals(sAppWindow, windows.get(7)); |
| 112 | assertEquals(sChildAppWindowAbove, windows.get(6)); |
| 113 | assertEquals(imeAppTarget, windows.get(5)); |
| 114 | assertEquals(sImeWindow, windows.get(4)); |
| 115 | assertEquals(sImeDialogWindow, windows.get(3)); |
| 116 | assertEquals(sDockedDividerWindow, windows.get(2)); |
| 117 | assertEquals(sStatusBarWindow, windows.get(1)); |
| 118 | assertEquals(sNavBarWindow, windows.get(0)); |
| 119 | |
| 120 | // Clean-up |
| 121 | sWm.mInputMethodTarget = null; |
| 122 | imeAppTarget.removeImmediately(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 123 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 124 | } |