blob: 7ac331829fb19eb4824327fe79c475c9377953e0 [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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Andrii Kuliand2765632016-12-12 22:26:34 -080015 */
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;
Brett Chabota26eda92018-07-23 13:08:30 -070028
29import org.junit.Test;
Andrii Kuliand2765632016-12-12 22:26:34 -080030
31/**
32 * Tests for the {@link TaskStack} class.
33 *
34 * Build/Install/Run:
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070035 * atest FrameworksServicesTests:TaskStackTests
Andrii Kuliand2765632016-12-12 22:26:34 -080036 */
37@SmallTest
38@Presubmit
Andrii Kuliand2765632016-12-12 22:26:34 -080039public class TaskStackTests extends WindowTestsBase {
40
41 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070042 public void testStackPositionChildAt() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070043 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080044 final Task task1 = createTaskInStack(stack, 0 /* userId */);
45 final Task task2 = createTaskInStack(stack, 1 /* userId */);
46
47 // Current user task should be moved to top.
48 stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */);
49 assertEquals(stack.mChildren.get(0), task2);
50 assertEquals(stack.mChildren.get(1), task1);
51
52 // Non-current user won't be moved to top.
53 stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */);
54 assertEquals(stack.mChildren.get(0), task2);
55 assertEquals(stack.mChildren.get(1), task1);
56 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -080057
58 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070059 public void testClosingAppDifferentStackOrientation() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070060 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080061 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070062 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080063 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080064 task1.addChild(appWindowToken1, 0);
65 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
66
67 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070068 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080069 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080070 task2.addChild(appWindowToken2, 0);
71 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
72
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070073 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
lumark588a3e82018-07-20 18:53:54 +080074 mDisplayContent.mClosingApps.add(appWindowToken2);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070075 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080076 }
77
78 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070079 public void testMoveTaskToBackDifferentStackOrientation() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070080 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080081 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070082 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080083 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080084 task1.addChild(appWindowToken1, 0);
85 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
86
87 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070088 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080089 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080090 task2.addChild(appWindowToken2, 0);
91 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
92
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070093 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080094 task2.setSendingToBottom(true);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070095 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080096 }
97
98 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070099 public void testStackRemoveImmediately() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700100 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800101 final Task task = createTaskInStack(stack, 0 /* userId */);
102 assertEquals(stack, task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800103
104 // Remove stack and check if its child is also removed.
105 stack.removeImmediately();
106 assertNull(stack.getDisplayContent());
107 assertNull(task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800108 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800109}