TaskWindowContainerControllerTests.java revision 7cd7c2d333c1b4f77a5b1a9f08cbaaebb242700c
1/* 2 * Copyright (C) 2017 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 static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; 20 21import org.junit.Test; 22 23import android.hardware.display.DisplayManagerGlobal; 24import android.platform.test.annotations.Presubmit; 25import android.support.test.filters.SmallTest; 26import android.support.test.runner.AndroidJUnit4; 27import android.view.Display; 28import android.view.DisplayInfo; 29 30import static org.junit.Assert.assertEquals; 31import static org.junit.Assert.assertNotNull; 32import static org.junit.Assert.assertNull; 33import static org.junit.Assert.assertTrue; 34 35/** 36 * Test class for {@link TaskWindowContainerController}. 37 * 38 * Build/Install/Run: 39 * bit FrameworksServicesTests:com.android.server.wm.TaskWindowContainerControllerTests 40 */ 41@SmallTest 42@Presubmit 43@org.junit.runner.RunWith(AndroidJUnit4.class) 44public class TaskWindowContainerControllerTests extends WindowTestsBase { 45 46 @Test 47 public void testRemoveContainer() throws Exception { 48 final TestTaskWindowContainerController taskController = 49 new TestTaskWindowContainerController(); 50 final TestAppWindowContainerController appController = 51 new TestAppWindowContainerController(taskController); 52 53 taskController.removeContainer(); 54 // Assert that the container was removed. 55 assertNull(taskController.mContainer); 56 assertNull(appController.mContainer); 57 } 58 59 @Test 60 public void testRemoveContainer_DeferRemoval() throws Exception { 61 final TestTaskWindowContainerController taskController = 62 new TestTaskWindowContainerController(); 63 final TestAppWindowContainerController appController = 64 new TestAppWindowContainerController(taskController); 65 66 final TestTask task = (TestTask) taskController.mContainer; 67 final AppWindowToken app = appController.mContainer; 68 task.mShouldDeferRemoval = true; 69 70 taskController.removeContainer(); 71 // For the case of deferred removal the task controller will no longer be connected to the 72 // container, but the app controller will still be connected to the its container until 73 // the task window container is removed. 74 assertNull(taskController.mContainer); 75 assertNull(task.getController()); 76 assertNotNull(appController.mContainer); 77 assertNotNull(app.getController()); 78 79 task.removeImmediately(); 80 assertNull(appController.mContainer); 81 assertNull(app.getController()); 82 } 83 84 @Test 85 public void testReparent() throws Exception { 86 final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent); 87 final TestTaskWindowContainerController taskController = 88 new TestTaskWindowContainerController(stack1.mStackId); 89 final TaskStack stack2 = createTaskStackOnDisplay(sDisplayContent); 90 final TestTaskWindowContainerController taskController2 = 91 new TestTaskWindowContainerController(stack2.mStackId); 92 93 boolean gotException = false; 94 try { 95 taskController.reparent(stack1.mStackId, 0); 96 } catch (IllegalArgumentException e) { 97 gotException = true; 98 } 99 assertTrue("Should not be able to reparent to the same parent", gotException); 100 101 gotException = false; 102 try { 103 taskController.reparent(sNextStackId + 1, 0); 104 } catch (IllegalArgumentException e) { 105 gotException = true; 106 } 107 assertTrue("Should not be able to reparent to a stackId that doesn't exist", gotException); 108 109 taskController.reparent(stack2.mStackId, 0); 110 assertEquals(stack2, taskController.mContainer.getParent()); 111 assertEquals(0, ((TestTask) taskController.mContainer).positionInParent()); 112 assertEquals(1, ((TestTask) taskController2.mContainer).positionInParent()); 113 } 114 115 @Test 116 public void testReparentBetweenDisplays() throws Exception { 117 // Create first stack on primary display. 118 final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent); 119 final TestTaskWindowContainerController taskController = 120 new TestTaskWindowContainerController(stack1.mStackId); 121 final TestTask task1 = (TestTask) taskController.mContainer; 122 task1.mOnDisplayChangedCalled = false; 123 124 // Create second display and put second stack on it. 125 final Display display = new Display(DisplayManagerGlobal.getInstance(), 126 sDisplayContent.getDisplayId() + 1, new DisplayInfo(), 127 DEFAULT_DISPLAY_ADJUSTMENTS); 128 final DisplayContent dc = new DisplayContent(display, sWm, sLayersController, 129 new WallpaperController(sWm)); 130 sWm.mRoot.addChild(dc, 1); 131 final TaskStack stack2 = createTaskStackOnDisplay(dc); 132 final TestTaskWindowContainerController taskController2 = 133 new TestTaskWindowContainerController(stack2.mStackId); 134 final TestTask task2 = (TestTask) taskController2.mContainer; 135 136 // Reparent and check state 137 taskController.reparent(stack2.mStackId, 0); 138 assertEquals(stack2, task1.getParent()); 139 assertEquals(0, task1.positionInParent()); 140 assertEquals(1, task2.positionInParent()); 141 assertTrue(task1.mOnDisplayChangedCalled); 142 } 143} 144