StackWindowControllerTests.java revision 11cc516a925ac7fc814dbb0a79a7f0abfbfe1ce1
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 android.graphics.Rect; 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 org.junit.Assert.assertEquals; 28import static org.junit.Assert.assertNotNull; 29import static org.junit.Assert.assertNull; 30import static org.junit.Assert.assertTrue; 31 32/** 33 * Test class for {@link StackWindowController}. 34 * 35 * Build/Install/Run: 36 * bit FrameworksServicesTests:com.android.server.wm.StackWindowControllerTests 37 */ 38@SmallTest 39@Presubmit 40@RunWith(AndroidJUnit4.class) 41public class StackWindowControllerTests extends WindowTestsBase { 42 @Test 43 public void testRemoveContainer() throws Exception { 44 final StackWindowController stackController = 45 createStackControllerOnDisplay(mDisplayContent); 46 final WindowTestUtils.TestTaskWindowContainerController taskController = 47 new WindowTestUtils.TestTaskWindowContainerController(stackController); 48 49 final TaskStack stack = stackController.mContainer; 50 final Task task = taskController.mContainer; 51 assertNotNull(stack); 52 assertNotNull(task); 53 stackController.removeContainer(); 54 // Assert that the container was removed. 55 assertNull(stackController.mContainer); 56 assertNull(taskController.mContainer); 57 assertNull(stack.getDisplayContent()); 58 assertNull(task.getDisplayContent()); 59 assertNull(task.mStack); 60 } 61 62 @Test 63 public void testRemoveContainer_deferRemoval() throws Exception { 64 final StackWindowController stackController = 65 createStackControllerOnDisplay(mDisplayContent); 66 final WindowTestUtils.TestTaskWindowContainerController taskController = 67 new WindowTestUtils.TestTaskWindowContainerController(stackController); 68 69 final TaskStack stack = stackController.mContainer; 70 final WindowTestUtils.TestTask task = (WindowTestUtils.TestTask) taskController.mContainer; 71 // Stack removal is deferred if one of its child is animating. 72 task.setLocalIsAnimating(true); 73 74 stackController.removeContainer(); 75 // For the case of deferred removal the stack controller will no longer be connected to the 76 // container, but the task controller will still be connected to the its container until 77 // the stack window container is removed. 78 assertNull(stackController.mContainer); 79 assertNull(stack.getController()); 80 assertNotNull(taskController.mContainer); 81 assertNotNull(task.getController()); 82 83 stack.removeImmediately(); 84 assertNull(taskController.mContainer); 85 assertNull(task.getController()); 86 } 87 88 @Test 89 public void testReparent() throws Exception { 90 // Create first stack on primary display. 91 final StackWindowController stack1Controller = 92 createStackControllerOnDisplay(mDisplayContent); 93 final TaskStack stack1 = stack1Controller.mContainer; 94 final WindowTestUtils.TestTaskWindowContainerController taskController = 95 new WindowTestUtils.TestTaskWindowContainerController(stack1Controller); 96 final WindowTestUtils.TestTask task1 = (WindowTestUtils.TestTask) taskController.mContainer; 97 task1.mOnDisplayChangedCalled = false; 98 99 // Create second display and put second stack on it. 100 final DisplayContent dc = createNewDisplay(); 101 final StackWindowController stack2Controller = 102 createStackControllerOnDisplay(dc); 103 final TaskStack stack2 = stack2Controller.mContainer; 104 105 // Reparent 106 stack1Controller.reparent(dc.getDisplayId(), new Rect(), true /* onTop */); 107 assertEquals(dc, stack1.getDisplayContent()); 108 final int stack1PositionInParent = stack1.getParent().mChildren.indexOf(stack1); 109 final int stack2PositionInParent = stack1.getParent().mChildren.indexOf(stack2); 110 assertEquals(stack1PositionInParent, stack2PositionInParent + 1); 111 assertTrue(task1.mOnDisplayChangedCalled); 112 } 113} 114