Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 19 | import android.graphics.Rect; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | |
| 23 | import android.platform.test.annotations.Presubmit; |
| 24 | import android.support.test.filters.SmallTest; |
| 25 | import android.support.test.runner.AndroidJUnit4; |
| 26 | |
| 27 | import static org.junit.Assert.assertEquals; |
| 28 | import static org.junit.Assert.assertNotNull; |
| 29 | import static org.junit.Assert.assertNull; |
| 30 | import 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) |
| 41 | public class StackWindowControllerTests extends WindowTestsBase { |
| 42 | @Test |
| 43 | public void testRemoveContainer() throws Exception { |
| 44 | final StackWindowController stackController = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 45 | createStackControllerOnDisplay(mDisplayContent); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 46 | final WindowTestUtils.TestTaskWindowContainerController taskController = |
| 47 | new WindowTestUtils.TestTaskWindowContainerController(stackController); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 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 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 65 | createStackControllerOnDisplay(mDisplayContent); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 66 | final WindowTestUtils.TestTaskWindowContainerController taskController = |
| 67 | new WindowTestUtils.TestTaskWindowContainerController(stackController); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 68 | |
| 69 | final TaskStack stack = stackController.mContainer; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 70 | final WindowTestUtils.TestTask task = (WindowTestUtils.TestTask) taskController.mContainer; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 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 = |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame^] | 92 | createStackControllerOnDisplay(mDisplayContent); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 93 | final TaskStack stack1 = stack1Controller.mContainer; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 94 | final WindowTestUtils.TestTaskWindowContainerController taskController = |
| 95 | new WindowTestUtils.TestTaskWindowContainerController(stack1Controller); |
| 96 | final WindowTestUtils.TestTask task1 = (WindowTestUtils.TestTask) taskController.mContainer; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 97 | task1.mOnDisplayChangedCalled = false; |
| 98 | |
| 99 | // Create second display and put second stack on it. |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 100 | final DisplayContent dc = createNewDisplay(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 101 | final StackWindowController stack2Controller = |
| 102 | createStackControllerOnDisplay(dc); |
| 103 | final TaskStack stack2 = stack2Controller.mContainer; |
| 104 | |
| 105 | // Reparent |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 106 | stack1Controller.reparent(dc.getDisplayId(), new Rect(), true /* onTop */); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 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 | } |