blob: cb5c1cd67092d8a0b12091dbbedc23da529db409 [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 static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
20import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
21
Andrii Kuliand2765632016-12-12 22:26:34 -080022import static org.junit.Assert.assertEquals;
Andrii Kuliand2765632016-12-12 22:26:34 -080023import static org.junit.Assert.assertNull;
Brett Chabota26eda92018-07-23 13:08:30 -070024
25import android.platform.test.annotations.Presubmit;
26
27import androidx.test.filters.SmallTest;
28import androidx.test.runner.AndroidJUnit4;
29
30import org.junit.Test;
31import org.junit.runner.RunWith;
Andrii Kuliand2765632016-12-12 22:26:34 -080032
33/**
34 * Tests for the {@link TaskStack} class.
35 *
36 * Build/Install/Run:
John Reck3d294e72018-09-21 20:26:48 +000037 * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests
Andrii Kuliand2765632016-12-12 22:26:34 -080038 */
39@SmallTest
40@Presubmit
41@RunWith(AndroidJUnit4.class)
42public class TaskStackTests extends WindowTestsBase {
43
44 @Test
45 public void testStackPositionChildAt() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070046 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080047 final Task task1 = createTaskInStack(stack, 0 /* userId */);
48 final Task task2 = createTaskInStack(stack, 1 /* userId */);
49
50 // Current user task should be moved to top.
51 stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */);
52 assertEquals(stack.mChildren.get(0), task2);
53 assertEquals(stack.mChildren.get(1), task1);
54
55 // Non-current user won't be moved to top.
56 stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */);
57 assertEquals(stack.mChildren.get(0), task2);
58 assertEquals(stack.mChildren.get(1), task1);
59 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -080060
61 @Test
Bryce Lee61fbcbc2017-03-10 14:14:03 -080062 public void testClosingAppDifferentStackOrientation() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070063 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080064 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070065 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080066 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080067 task1.addChild(appWindowToken1, 0);
68 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
69
70 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070071 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080072 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080073 task2.addChild(appWindowToken2, 0);
74 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
75
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070076 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
lumark588a3e82018-07-20 18:53:54 +080077 mDisplayContent.mClosingApps.add(appWindowToken2);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070078 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080079 }
80
81 @Test
82 public void testMoveTaskToBackDifferentStackOrientation() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070083 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080084 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070085 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080086 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080087 task1.addChild(appWindowToken1, 0);
88 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
89
90 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070091 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080092 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080093 task2.addChild(appWindowToken2, 0);
94 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
95
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070096 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080097 task2.setSendingToBottom(true);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070098 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080099 }
100
101 @Test
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800102 public void testStackRemoveImmediately() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700103 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800104 final Task task = createTaskInStack(stack, 0 /* userId */);
105 assertEquals(stack, task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800106
107 // Remove stack and check if its child is also removed.
108 stack.removeImmediately();
109 assertNull(stack.getDisplayContent());
110 assertNull(task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800111 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800112}