blob: 3ce3df1557ddd9a28bb0683970f4fb941bbe302a [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
Bryce Lee61fbcbc2017-03-10 14:14:03 -080019import android.content.pm.ActivityInfo;
20import android.view.WindowManager;
21import android.view.WindowManager.LayoutParams;
Andrii Kuliand2765632016-12-12 22:26:34 -080022import 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
Bryce Lee61fbcbc2017-03-10 14:14:03 -080029import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
30import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
31
Andrii Kuliand2765632016-12-12 22:26:34 -080032import 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 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -080065
66 @Test
Bryce Lee61fbcbc2017-03-10 14:14:03 -080067 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
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800103 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 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800117}