blob: d9b99eeac6f070f6e1b4dc648eb68360815f651a [file] [log] [blame]
Wale Ogunwale1666e312016-12-16 11:27:18 -08001/*
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
Wale Ogunwale1666e312016-12-16 11:27:18 -080019import android.graphics.Rect;
Wale Ogunwale1666e312016-12-16 11:27:18 -080020import 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 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070045 createStackControllerOnDisplay(mDisplayContent);
Bryce Leeaf691c02017-03-20 14:20:22 -070046 final WindowTestUtils.TestTaskWindowContainerController taskController =
47 new WindowTestUtils.TestTaskWindowContainerController(stackController);
Wale Ogunwale1666e312016-12-16 11:27:18 -080048
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 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070065 createStackControllerOnDisplay(mDisplayContent);
Bryce Leeaf691c02017-03-20 14:20:22 -070066 final WindowTestUtils.TestTaskWindowContainerController taskController =
67 new WindowTestUtils.TestTaskWindowContainerController(stackController);
Wale Ogunwale1666e312016-12-16 11:27:18 -080068
69 final TaskStack stack = stackController.mContainer;
Bryce Leeaf691c02017-03-20 14:20:22 -070070 final WindowTestUtils.TestTask task = (WindowTestUtils.TestTask) taskController.mContainer;
Wale Ogunwale1666e312016-12-16 11:27:18 -080071 // 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 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070092 createStackControllerOnDisplay(mDisplayContent);
Wale Ogunwale1666e312016-12-16 11:27:18 -080093 final TaskStack stack1 = stack1Controller.mContainer;
Bryce Leeaf691c02017-03-20 14:20:22 -070094 final WindowTestUtils.TestTaskWindowContainerController taskController =
95 new WindowTestUtils.TestTaskWindowContainerController(stack1Controller);
96 final WindowTestUtils.TestTask task1 = (WindowTestUtils.TestTask) taskController.mContainer;
Wale Ogunwale1666e312016-12-16 11:27:18 -080097 task1.mOnDisplayChangedCalled = false;
98
99 // Create second display and put second stack on it.
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800100 final DisplayContent dc = createNewDisplay();
Wale Ogunwale1666e312016-12-16 11:27:18 -0800101 final StackWindowController stack2Controller =
102 createStackControllerOnDisplay(dc);
103 final TaskStack stack2 = stack2Controller.mContainer;
104
105 // Reparent
Andrii Kulian51c1b672017-04-07 18:39:32 -0700106 stack1Controller.reparent(dc.getDisplayId(), new Rect(), true /* onTop */);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800107 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}