blob: ca1994f85ccfa3091a5841131e82004aac365fc9 [file] [log] [blame]
Andrii Kuliand2765632016-12-12 22:26:34 -08001/*
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
17package com.android.server.wm;
18
Wale Ogunwale44f036f2017-09-29 05:09:09 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
Wale Ogunwale68278562017-09-23 17:13:55 -070020import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Andrii Kuliand2765632016-12-12 22:26:34 -080021import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertFalse;
23import static org.junit.Assert.assertNotNull;
24import static org.junit.Assert.assertNull;
25import static org.junit.Assert.assertTrue;
26
Wale Ogunwale44f036f2017-09-29 05:09:09 -070027import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.junit.Before;
30import org.junit.After;
31
32import android.platform.test.annotations.Presubmit;
33import android.support.test.filters.SmallTest;
34import android.support.test.runner.AndroidJUnit4;
35
Andrii Kuliand2765632016-12-12 22:26:34 -080036/**
37 * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}.
38 *
39 * Build/Install/Run:
40 * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
41 */
42@SmallTest
43@Presubmit
44@RunWith(AndroidJUnit4.class)
45public class TaskStackContainersTests extends WindowTestsBase {
46
Wale Ogunwale1666e312016-12-16 11:27:18 -080047 private TaskStack mPinnedStack;
48
49 @Before
50 public void setUp() throws Exception {
51 super.setUp();
Wale Ogunwale44f036f2017-09-29 05:09:09 -070052 mPinnedStack = createStackControllerOnStackOnDisplay(
53 WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
Wale Ogunwale1666e312016-12-16 11:27:18 -080054 // Stack should contain visible app window to be considered visible.
55 final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
56 assertFalse(mPinnedStack.isVisible());
chaviw97d28202018-02-27 16:23:53 -080057 final WindowTestUtils.TestAppWindowToken pinnedApp =
58 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Wale Ogunwale1666e312016-12-16 11:27:18 -080059 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 Kuliand2765632016-12-12 22:26:34 -080068 @Test
69 public void testStackPositionChildAt() throws Exception {
70 // Test that always-on-top stack can't be moved to position other than top.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070071 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
72 final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080073
74 final WindowContainer taskStackContainer = stack1.getParent();
75
76 final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
77 final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080078 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080079 assertGreaterThan(pinnedStackPos, stack2Pos);
80 assertGreaterThan(stack2Pos, stack1Pos);
Andrii Kuliand2765632016-12-12 22:26:34 -080081
Wale Ogunwale1666e312016-12-16 11:27:18 -080082 taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080083 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
84 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080085 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080086
Wale Ogunwale1666e312016-12-16 11:27:18 -080087 taskStackContainer.positionChildAt(1, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080088 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
89 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080090 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080091 }
Wale Ogunwale1666e312016-12-16 11:27:18 -080092
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080093 @Test
94 public void testStackPositionBelowPinnedStack() throws Exception {
95 // Test that no stack can be above pinned stack.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070096 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080097
98 final WindowContainer taskStackContainer = stack1.getParent();
99
100 final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800101 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800102 assertGreaterThan(pinnedStackPos, stackPos);
103
104 taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false);
105 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800106 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800107
108 taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false);
109 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800110 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800111 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800112}