blob: efe766771673c52d21ac9e923e5704f31a05e91b [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
19import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
20
Wale Ogunwale687b4272017-07-27 02:56:23 -070021import android.content.res.Configuration;
Andrii Kuliand2765632016-12-12 22:26:34 -080022import org.junit.Test;
23import org.junit.runner.RunWith;
Wale Ogunwale1666e312016-12-16 11:27:18 -080024import org.junit.Before;
25import org.junit.After;
Andrii Kuliand2765632016-12-12 22:26:34 -080026
Wale Ogunwale1666e312016-12-16 11:27:18 -080027import android.graphics.Rect;
Andrii Kuliand2765632016-12-12 22:26:34 -080028import android.platform.test.annotations.Presubmit;
29import android.support.test.filters.SmallTest;
30import android.support.test.runner.AndroidJUnit4;
31
32import static org.junit.Assert.assertEquals;
33import static org.junit.Assert.assertFalse;
34import static org.junit.Assert.assertNotNull;
35import static org.junit.Assert.assertNull;
36import static org.junit.Assert.assertTrue;
37
38/**
39 * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}.
40 *
41 * Build/Install/Run:
42 * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public class TaskStackContainersTests extends WindowTestsBase {
48
Wale Ogunwale1666e312016-12-16 11:27:18 -080049 private TaskStack mPinnedStack;
50
51 @Before
52 public void setUp() throws Exception {
53 super.setUp();
54 mPinnedStack = new StackWindowController(PINNED_STACK_ID, null,
Wale Ogunwale687b4272017-07-27 02:56:23 -070055 mDisplayContent.getDisplayId(), true /* onTop */, new Rect(), new Configuration(),
56 sWm).mContainer;
Wale Ogunwale1666e312016-12-16 11:27:18 -080057
58 // Stack should contain visible app window to be considered visible.
59 final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
60 assertFalse(mPinnedStack.isVisible());
Wale Ogunwale11cc5162017-04-25 20:29:13 -070061 final WindowTestUtils.TestAppWindowToken pinnedApp = new WindowTestUtils.TestAppWindowToken(
62 mDisplayContent);
Wale Ogunwale1666e312016-12-16 11:27:18 -080063 pinnedTask.addChild(pinnedApp, 0 /* addPos */);
64 assertTrue(mPinnedStack.isVisible());
65 }
66
67 @After
68 public void tearDown() throws Exception {
69 mPinnedStack.removeImmediately();
70 }
71
Andrii Kuliand2765632016-12-12 22:26:34 -080072 @Test
73 public void testStackPositionChildAt() throws Exception {
74 // Test that always-on-top stack can't be moved to position other than top.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070075 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
76 final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080077
78 final WindowContainer taskStackContainer = stack1.getParent();
79
80 final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
81 final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080082 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080083 assertGreaterThan(pinnedStackPos, stack2Pos);
84 assertGreaterThan(stack2Pos, stack1Pos);
Andrii Kuliand2765632016-12-12 22:26:34 -080085
Wale Ogunwale1666e312016-12-16 11:27:18 -080086 taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080087 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
88 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080089 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080090
Wale Ogunwale1666e312016-12-16 11:27:18 -080091 taskStackContainer.positionChildAt(1, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080092 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
93 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080094 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080095 }
Wale Ogunwale1666e312016-12-16 11:27:18 -080096
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080097 @Test
98 public void testStackPositionBelowPinnedStack() throws Exception {
99 // Test that no stack can be above pinned stack.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700100 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800101
102 final WindowContainer taskStackContainer = stack1.getParent();
103
104 final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800105 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800106 assertGreaterThan(pinnedStackPos, stackPos);
107
108 taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, 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
112 taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false);
113 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800114 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800115 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800116}