blob: 5feda41f959969a94a1ac1b64fd5289f83075900 [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
21import org.junit.Test;
22import org.junit.runner.RunWith;
Wale Ogunwale1666e312016-12-16 11:27:18 -080023import org.junit.Before;
24import org.junit.After;
Andrii Kuliand2765632016-12-12 22:26:34 -080025
Wale Ogunwale1666e312016-12-16 11:27:18 -080026import android.graphics.Rect;
Andrii Kuliand2765632016-12-12 22:26:34 -080027import android.platform.test.annotations.Presubmit;
28import android.support.test.filters.SmallTest;
29import android.support.test.runner.AndroidJUnit4;
30
31import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertFalse;
33import static org.junit.Assert.assertNotNull;
34import static org.junit.Assert.assertNull;
35import static org.junit.Assert.assertTrue;
36
37/**
38 * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}.
39 *
40 * Build/Install/Run:
41 * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
42 */
43@SmallTest
44@Presubmit
45@RunWith(AndroidJUnit4.class)
46public class TaskStackContainersTests extends WindowTestsBase {
47
Wale Ogunwale1666e312016-12-16 11:27:18 -080048 private TaskStack mPinnedStack;
49
50 @Before
51 public void setUp() throws Exception {
52 super.setUp();
53 mPinnedStack = new StackWindowController(PINNED_STACK_ID, null,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070054 mDisplayContent.getDisplayId(), true /* onTop */, new Rect(), sWm).mContainer;
Wale Ogunwale1666e312016-12-16 11:27:18 -080055
56 // Stack should contain visible app window to be considered visible.
57 final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
58 assertFalse(mPinnedStack.isVisible());
Wale Ogunwale11cc5162017-04-25 20:29:13 -070059 final WindowTestUtils.TestAppWindowToken pinnedApp = new WindowTestUtils.TestAppWindowToken(
60 mDisplayContent);
Wale Ogunwale1666e312016-12-16 11:27:18 -080061 pinnedTask.addChild(pinnedApp, 0 /* addPos */);
62 assertTrue(mPinnedStack.isVisible());
63 }
64
65 @After
66 public void tearDown() throws Exception {
67 mPinnedStack.removeImmediately();
68 }
69
Andrii Kuliand2765632016-12-12 22:26:34 -080070 @Test
71 public void testStackPositionChildAt() throws Exception {
72 // Test that always-on-top stack can't be moved to position other than top.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070073 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
74 final TaskStack stack2 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080075
76 final WindowContainer taskStackContainer = stack1.getParent();
77
78 final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
79 final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080080 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080081 assertGreaterThan(pinnedStackPos, stack2Pos);
82 assertGreaterThan(stack2Pos, stack1Pos);
Andrii Kuliand2765632016-12-12 22:26:34 -080083
Wale Ogunwale1666e312016-12-16 11:27:18 -080084 taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080085 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
86 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080087 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080088
Wale Ogunwale1666e312016-12-16 11:27:18 -080089 taskStackContainer.positionChildAt(1, mPinnedStack, false);
Andrii Kuliand2765632016-12-12 22:26:34 -080090 assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
91 assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
Wale Ogunwale1666e312016-12-16 11:27:18 -080092 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliand2765632016-12-12 22:26:34 -080093 }
Wale Ogunwale1666e312016-12-16 11:27:18 -080094
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080095 @Test
96 public void testStackPositionBelowPinnedStack() throws Exception {
97 // Test that no stack can be above pinned stack.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070098 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -080099
100 final WindowContainer taskStackContainer = stack1.getParent();
101
102 final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800103 final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800104 assertGreaterThan(pinnedStackPos, stackPos);
105
106 taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false);
107 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800108 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800109
110 taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false);
111 assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800112 assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -0800113 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800114}