TaskStackTests.java revision 61fbcbcc94d1ca949afae47ec0ec7a8da80aadef
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 android.content.pm.ActivityInfo;
20import android.view.WindowManager;
21import android.view.WindowManager.LayoutParams;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24
25import android.platform.test.annotations.Presubmit;
26import android.support.test.filters.SmallTest;
27import android.support.test.runner.AndroidJUnit4;
28
29import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
30import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
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 TaskStack} class.
40 *
41 * Build/Install/Run:
42 *  bit FrameworksServicesTests:com.android.server.wm.TaskStackTests
43 */
44@SmallTest
45@Presubmit
46@RunWith(AndroidJUnit4.class)
47public class TaskStackTests extends WindowTestsBase {
48
49    @Test
50    public void testStackPositionChildAt() throws Exception {
51        final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
52        final Task task1 = createTaskInStack(stack, 0 /* userId */);
53        final Task task2 = createTaskInStack(stack, 1 /* userId */);
54
55        // Current user task should be moved to top.
56        stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */);
57        assertEquals(stack.mChildren.get(0), task2);
58        assertEquals(stack.mChildren.get(1), task1);
59
60        // Non-current user won't be moved to top.
61        stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */);
62        assertEquals(stack.mChildren.get(0), task2);
63        assertEquals(stack.mChildren.get(1), task1);
64    }
65
66    @Test
67    public void testClosingAppDifferentStackOrientation() throws Exception {
68        final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
69        final Task task1 = createTaskInStack(stack, 0 /* userId */);
70        TestAppWindowToken appWindowToken1 = new TestAppWindowToken(sDisplayContent);
71        task1.addChild(appWindowToken1, 0);
72        appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
73
74        final Task task2 = createTaskInStack(stack, 1 /* userId */);
75        TestAppWindowToken appWindowToken2 = new TestAppWindowToken(sDisplayContent);
76        task2.addChild(appWindowToken2, 0);
77        appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
78
79        assertEquals(stack.getOrientation(), SCREEN_ORIENTATION_PORTRAIT);
80        sWm.mClosingApps.add(appWindowToken2);
81        assertEquals(stack.getOrientation(), SCREEN_ORIENTATION_LANDSCAPE);
82    }
83
84    @Test
85    public void testMoveTaskToBackDifferentStackOrientation() throws Exception {
86        final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
87        final Task task1 = createTaskInStack(stack, 0 /* userId */);
88        TestAppWindowToken appWindowToken1 = new TestAppWindowToken(sDisplayContent);
89        task1.addChild(appWindowToken1, 0);
90        appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
91
92        final Task task2 = createTaskInStack(stack, 1 /* userId */);
93        TestAppWindowToken appWindowToken2 = new TestAppWindowToken(sDisplayContent);
94        task2.addChild(appWindowToken2, 0);
95        appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
96
97        assertEquals(stack.getOrientation(), SCREEN_ORIENTATION_PORTRAIT);
98        task2.setSendingToBottom(true);
99        assertEquals(stack.getOrientation(), SCREEN_ORIENTATION_LANDSCAPE);
100    }
101
102    @Test
103    public void testStackRemoveImmediately() throws Exception {
104        final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
105        final Task task = createTaskInStack(stack, 0 /* userId */);
106        assertEquals(stack, task.mStack);
107        assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(stack));
108        assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(task));
109
110        // Remove stack and check if its child is also removed.
111        stack.removeImmediately();
112        assertNull(stack.getDisplayContent());
113        assertNull(task.mStack);
114        assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(stack));
115        assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(task));
116    }
117}
118