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_APPLICATION_ATTACHED_DIALOG; |
| 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
| 30 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 36 | import static org.junit.Assert.assertEquals; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Tests for the {@link DisplayContent} class. |
| 40 | * |
| 41 | * Build/Install/Run: |
| 42 | * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests |
| 43 | */ |
| 44 | @SmallTest |
| 45 | @Presubmit |
| 46 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame^] | 47 | public class DisplayContentTests extends WindowTestsBase { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 48 | |
| 49 | @Test |
| 50 | public void testForAllWindows() throws Exception { |
| 51 | final DisplayContent dc = new DisplayContent(mDisplay, sWm, null, null); |
| 52 | final WindowState wallpaperWindow = createWindow(null, TYPE_WALLPAPER, dc, "wallpaper"); |
| 53 | final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, dc, "ime"); |
| 54 | final WindowState imeDialogWindow = createWindow(null, TYPE_INPUT_METHOD_DIALOG, dc, |
| 55 | "ime dialog"); |
| 56 | final WindowState statusBarWindow = createWindow(null, TYPE_STATUS_BAR, dc, "status bar"); |
| 57 | final WindowState navBarWindow = createWindow(null, TYPE_NAVIGATION_BAR, |
| 58 | statusBarWindow.mToken, "nav bar"); |
| 59 | final WindowState appWindow = createWindow(null, TYPE_BASE_APPLICATION, dc, "app"); |
| 60 | final WindowState negChildAppWindow = createWindow(appWindow, TYPE_APPLICATION_MEDIA, |
| 61 | appWindow.mToken, "negative app child"); |
| 62 | final WindowState posChildAppWindow = createWindow(appWindow, |
| 63 | TYPE_APPLICATION_ATTACHED_DIALOG, appWindow.mToken, "positive app child"); |
| 64 | final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION, dc, |
| 65 | "exiting app"); |
| 66 | final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken; |
| 67 | exitingAppToken.mIsExiting = true; |
| 68 | exitingAppToken.mTask.mStack.mExitingAppTokens.add(exitingAppToken); |
| 69 | |
| 70 | final ArrayList<WindowState> windows = new ArrayList(); |
| 71 | |
| 72 | // Test forward traversal. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 73 | dc.forAllWindows(w -> {windows.add(w);}, false /* traverseTopToBottom */); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 74 | |
| 75 | assertEquals(wallpaperWindow, windows.get(0)); |
| 76 | assertEquals(exitingAppWindow, windows.get(1)); |
| 77 | assertEquals(negChildAppWindow, windows.get(2)); |
| 78 | assertEquals(appWindow, windows.get(3)); |
| 79 | assertEquals(posChildAppWindow, windows.get(4)); |
| 80 | assertEquals(statusBarWindow, windows.get(5)); |
| 81 | assertEquals(navBarWindow, windows.get(6)); |
| 82 | assertEquals(imeWindow, windows.get(7)); |
| 83 | assertEquals(imeDialogWindow, windows.get(8)); |
| 84 | |
| 85 | // Test backward traversal. |
| 86 | windows.clear(); |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 87 | dc.forAllWindows(w -> {windows.add(w);}, true /* traverseTopToBottom */); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 88 | |
| 89 | assertEquals(wallpaperWindow, windows.get(8)); |
| 90 | assertEquals(exitingAppWindow, windows.get(7)); |
| 91 | assertEquals(negChildAppWindow, windows.get(6)); |
| 92 | assertEquals(appWindow, windows.get(5)); |
| 93 | assertEquals(posChildAppWindow, windows.get(4)); |
| 94 | assertEquals(statusBarWindow, windows.get(3)); |
| 95 | assertEquals(navBarWindow, windows.get(2)); |
| 96 | assertEquals(imeWindow, windows.get(1)); |
| 97 | assertEquals(imeDialogWindow, windows.get(0)); |
| 98 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 99 | } |