AppWindowTokenTests.java revision 3d0bfd9530bc51c52aec027eaf6d0dba918efc99
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.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.FIRST_SUB_WINDOW; 27import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; 28import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; 29import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; 30import static org.junit.Assert.assertEquals; 31import static org.junit.Assert.assertNull; 32import static org.junit.Assert.assertTrue; 33 34/** 35 * Tests for the {@link AppWindowToken} class. 36 * 37 * Build/Install/Run: 38 * bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests 39 */ 40@SmallTest 41@Presubmit 42@RunWith(AndroidJUnit4.class) 43public class AppWindowTokenTests extends WindowTestsBase { 44 45 @Test 46 public void testAddWindow_Order() throws Exception { 47 final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent); 48 49 assertEquals(0, token.getWindowsCount()); 50 51 final WindowState win1 = createWindow(null, TYPE_APPLICATION, token, "win1"); 52 final WindowState startingWin = createWindow(null, TYPE_APPLICATION_STARTING, token, 53 "startingWin"); 54 final WindowState baseWin = createWindow(null, TYPE_BASE_APPLICATION, token, "baseWin"); 55 final WindowState win4 = createWindow(null, TYPE_APPLICATION, token, "win4"); 56 57 // Should not contain the windows that were added above. 58 assertEquals(4, token.getWindowsCount()); 59 assertTrue(token.hasWindow(win1)); 60 assertTrue(token.hasWindow(startingWin)); 61 assertTrue(token.hasWindow(baseWin)); 62 assertTrue(token.hasWindow(win4)); 63 64 // The starting window should be on-top of all other windows. 65 assertEquals(startingWin, token.getLastChild()); 66 67 // The base application window should be below all other windows. 68 assertEquals(baseWin, token.getFirstChild()); 69 } 70 71 @Test 72 public void testFindMainWindow() throws Exception { 73 final TestAppWindowToken token = new TestAppWindowToken(sDisplayContent); 74 75 assertNull(token.findMainWindow()); 76 77 final WindowState window1 = createWindow(null, TYPE_BASE_APPLICATION, token, "window1"); 78 final WindowState window11 = createWindow(window1, FIRST_SUB_WINDOW, token, "window11"); 79 final WindowState window12 = createWindow(window1, FIRST_SUB_WINDOW, token, "window12"); 80 assertEquals(window1, token.findMainWindow()); 81 window1.mAnimatingExit = true; 82 assertEquals(window1, token.findMainWindow()); 83 final WindowState window2 = createWindow(null, TYPE_APPLICATION_STARTING, token, "window2"); 84 assertEquals(window2, token.findMainWindow()); 85 } 86} 87