blob: 29bbe6eca39f601c782f6a16542cf7517e2a049a [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
Wale Ogunwalef75962a2017-08-23 14:58:04 -070032import static android.app.ActivityManager.StackId.getWindowingModeForStackId;
Andrii Kuliand2765632016-12-12 22:26:34 -080033import static org.junit.Assert.assertEquals;
34import static org.junit.Assert.assertFalse;
35import static org.junit.Assert.assertNotNull;
36import static org.junit.Assert.assertNull;
37import static org.junit.Assert.assertTrue;
38
39/**
40 * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}.
41 *
42 * Build/Install/Run:
43 * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
44 */
45@SmallTest
46@Presubmit
47@RunWith(AndroidJUnit4.class)
48public class TaskStackContainersTests extends WindowTestsBase {
49
Wale Ogunwale1666e312016-12-16 11:27:18 -080050 private TaskStack mPinnedStack;
51
52 @Before
53 public void setUp() throws Exception {
54 super.setUp();
Wale Ogunwalef75962a2017-08-23 14:58:04 -070055 final Configuration overrideConfig = new Configuration();
56 overrideConfig.windowConfiguration.setWindowingMode(
Wale Ogunwale926aade2017-08-29 11:24:37 -070057 getWindowingModeForStackId(PINNED_STACK_ID, false /* inSplitScreenMode */));
Wale Ogunwale1666e312016-12-16 11:27:18 -080058 mPinnedStack = new StackWindowController(PINNED_STACK_ID, null,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070059 mDisplayContent.getDisplayId(), true /* onTop */, new Rect(), sWm).mContainer;
60 mPinnedStack.onOverrideConfigurationChanged(overrideConfig);
Wale Ogunwale1666e312016-12-16 11:27:18 -080061
62 // Stack should contain visible app window to be considered visible.
63 final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
64 assertFalse(mPinnedStack.isVisible());
Wale Ogunwale11cc5162017-04-25 20:29:13 -070065 final WindowTestUtils.TestAppWindowToken pinnedApp = new WindowTestUtils.TestAppWindowToken(
66 mDisplayContent);
Wale Ogunwale1666e312016-12-16 11:27:18 -080067 pinnedTask.addChild(pinnedApp, 0 /* addPos */);
68 assertTrue(mPinnedStack.isVisible());
69 }
70
71 @After
72 public void tearDown() throws Exception {
73 mPinnedStack.removeImmediately();
74 }
75
Andrii Kuliand2765632016-12-12 22:26:34 -080076 @Test
77 public void testStackPositionChildAt() throws Exception {
78 // Test that always-on-top stack can't be moved to position other than top.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070079 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
80 final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080081
82 final WindowContainer taskStackContainer = stack1.getParent();
83
84 final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
85 final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080086 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080087 assertGreaterThan(pinnedStackPos, stack2Pos);
88 assertGreaterThan(stack2Pos, stack1Pos);
Andrii Kuliand2765632016-12-12 22:26:34 -080089
Wale Ogunwale1666e312016-12-16 11:27:18 -080090 taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080091 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
92 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080093 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080094
Wale Ogunwale1666e312016-12-16 11:27:18 -080095 taskStackContainer.positionChildAt(1, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080096 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
97 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080098 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080099 }
Wale Ogunwale1666e312016-12-16 11:27:18 -0800100
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800101 @Test
102 public void testStackPositionBelowPinnedStack() throws Exception {
103 // Test that no stack can be above pinned stack.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700104 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800105
106 final WindowContainer taskStackContainer = stack1.getParent();
107
108 final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800109 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800110 assertGreaterThan(pinnedStackPos, stackPos);
111
112 taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, 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
116 taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false);
117 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800118 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800119 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800120}