TaskStackContainersTests.java revision af691c0be7bbfea63e880dd717c51a38a0bc874a
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
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;
23import org.junit.Before;
24import org.junit.After;
25
26import android.graphics.Rect;
27import 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
48    private TaskStack mPinnedStack;
49
50    @Before
51    public void setUp() throws Exception {
52        super.setUp();
53        mPinnedStack = new StackWindowController(PINNED_STACK_ID, null,
54                sDisplayContent.getDisplayId(), true /* onTop */, new Rect(), sWm).mContainer;
55
56        // Stack should contain visible app window to be considered visible.
57        final Task pinnedTask = createTaskInStack(mPinnedStack, 0 /* userId */);
58        assertFalse(mPinnedStack.isVisible());
59        final WindowTestUtils.TestAppWindowToken pinnedApp = new WindowTestUtils.TestAppWindowToken(sDisplayContent);
60        pinnedTask.addChild(pinnedApp, 0 /* addPos */);
61        assertTrue(mPinnedStack.isVisible());
62    }
63
64    @After
65    public void tearDown() throws Exception {
66        mPinnedStack.removeImmediately();
67    }
68
69    @Test
70    public void testStackPositionChildAt() throws Exception {
71        // Test that always-on-top stack can't be moved to position other than top.
72        final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent);
73        final TaskStack stack2 = createTaskStackOnDisplay(sDisplayContent);
74
75        final WindowContainer taskStackContainer = stack1.getParent();
76
77        final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1);
78        final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2);
79        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
80        assertGreaterThan(pinnedStackPos, stack2Pos);
81        assertGreaterThan(stack2Pos, stack1Pos);
82
83        taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, mPinnedStack, false);
84        assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
85        assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
86        assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
87
88        taskStackContainer.positionChildAt(1, mPinnedStack, false);
89        assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1);
90        assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2);
91        assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
92    }
93
94    @Test
95    public void testStackPositionBelowPinnedStack() throws Exception {
96        // Test that no stack can be above pinned stack.
97        final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent);
98
99        final WindowContainer taskStackContainer = stack1.getParent();
100
101        final int stackPos = taskStackContainer.mChildren.indexOf(stack1);
102        final int pinnedStackPos = taskStackContainer.mChildren.indexOf(mPinnedStack);
103        assertGreaterThan(pinnedStackPos, stackPos);
104
105        taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false);
106        assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
107        assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
108
109        taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false);
110        assertEquals(taskStackContainer.mChildren.get(stackPos), stack1);
111        assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack);
112    }
113}
114