Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 21 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.junit.Assert.assertFalse; |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 23 | import static org.junit.Assert.assertNotNull; |
| 24 | import static org.junit.Assert.assertNull; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 25 | import static org.junit.Assert.assertTrue; |
| 26 | |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 27 | import org.junit.Test; |
| 28 | import org.junit.runner.RunWith; |
| 29 | import org.junit.Before; |
| 30 | import org.junit.After; |
| 31 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 32 | import android.platform.test.annotations.Presubmit; |
| 33 | import android.support.test.filters.SmallTest; |
| 34 | import android.support.test.runner.AndroidJUnit4; |
| 35 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}. |
| 38 | * |
| 39 | * Build/Install/Run: |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 40 | * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 41 | */ |
| 42 | @SmallTest |
| 43 | @Presubmit |
| 44 | @RunWith(AndroidJUnit4.class) |
| 45 | public class TaskStackContainersTests extends WindowTestsBase { |
| 46 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 47 | private TaskStack mPinnedStack; |
| 48 | |
| 49 | @Before |
| 50 | public void setUp() throws Exception { |
| 51 | super.setUp(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 52 | mPinnedStack = createStackControllerOnStackOnDisplay( |
| 53 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 54 | // Stack should contain visible app window to be considered visible. |
| 55 | final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */); |
| 56 | assertFalse(mPinnedStack.isVisible()); |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 57 | final WindowTestUtils.TestAppWindowToken pinnedApp = |
| 58 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 59 | pinnedTask.addChild(pinnedApp, 0 /* addPos */); |
| 60 | assertTrue(mPinnedStack.isVisible()); |
| 61 | } |
| 62 | |
| 63 | @After |
| 64 | public void tearDown() throws Exception { |
| 65 | mPinnedStack.removeImmediately(); |
| 66 | } |
| 67 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 68 | @Test |
| 69 | public void testStackPositionChildAt() throws Exception { |
| 70 | // Test that always-on-top stack can't be moved to position other than top. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 71 | final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent); |
| 72 | final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 73 | |
| 74 | final WindowContainer taskStackContainer = stack1.getParent(); |
| 75 | |
| 76 | final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1); |
| 77 | final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 78 | final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 79 | assertGreaterThan(pinnedStackPos, stack2Pos); |
| 80 | assertGreaterThan(stack2Pos, stack1Pos); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 81 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 82 | taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 83 | assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1); |
| 84 | assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 85 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 86 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 87 | taskStackContainer.positionChildAt(1, mPinnedStack, false); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 88 | assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1); |
| 89 | assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 90 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 91 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 92 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 93 | @Test |
| 94 | public void testStackPositionBelowPinnedStack() throws Exception { |
| 95 | // Test that no stack can be above pinned stack. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 96 | final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 97 | |
| 98 | final WindowContainer taskStackContainer = stack1.getParent(); |
| 99 | |
| 100 | final int stackPos = taskStackContainer.mChildren.indexOf(stack1); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 101 | final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 102 | assertGreaterThan(pinnedStackPos, stackPos); |
| 103 | |
| 104 | taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false); |
| 105 | assertEquals(taskStackContainer.mChildren.get(stackPos), stack1); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 106 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 107 | |
| 108 | taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false); |
| 109 | assertEquals(taskStackContainer.mChildren.get(stackPos), stack1); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 110 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 111 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 112 | } |