blob: b846fd02840bea5eae816e6d36b1a0bd65649910 [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
19import org.junit.Test;
20import org.junit.runner.RunWith;
21
22import android.platform.test.annotations.Presubmit;
23import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
25
Bryce Lee61fbcbc2017-03-10 14:14:03 -080026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
27import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
28
Andrii Kuliand2765632016-12-12 22:26:34 -080029import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.assertFalse;
31import static org.junit.Assert.assertNotNull;
32import static org.junit.Assert.assertNull;
33import static org.junit.Assert.assertTrue;
34
35/**
36 * Tests for the {@link TaskStack} class.
37 *
38 * Build/Install/Run:
39 * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests
40 */
41@SmallTest
42@Presubmit
43@RunWith(AndroidJUnit4.class)
44public class TaskStackTests extends WindowTestsBase {
45
46 @Test
47 public void testStackPositionChildAt() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070048 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080049 final Task task1 = createTaskInStack(stack, 0 /* userId */);
50 final Task task2 = createTaskInStack(stack, 1 /* userId */);
51
52 // Current user task should be moved to top.
53 stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */);
54 assertEquals(stack.mChildren.get(0), task2);
55 assertEquals(stack.mChildren.get(1), task1);
56
57 // Non-current user won't be moved to top.
58 stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */);
59 assertEquals(stack.mChildren.get(0), task2);
60 assertEquals(stack.mChildren.get(1), task1);
61 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -080062
63 @Test
Bryce Lee61fbcbc2017-03-10 14:14:03 -080064 public void testClosingAppDifferentStackOrientation() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070065 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080066 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070067 WindowTestUtils.TestAppWindowToken appWindowToken1 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070068 new WindowTestUtils.TestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080069 task1.addChild(appWindowToken1, 0);
70 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
71
72 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070073 WindowTestUtils.TestAppWindowToken appWindowToken2 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070074 new WindowTestUtils.TestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080075 task2.addChild(appWindowToken2, 0);
76 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
77
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070078 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080079 sWm.mClosingApps.add(appWindowToken2);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070080 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080081 }
82
83 @Test
84 public void testMoveTaskToBackDifferentStackOrientation() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070085 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080086 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070087 WindowTestUtils.TestAppWindowToken appWindowToken1 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070088 new WindowTestUtils.TestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080089 task1.addChild(appWindowToken1, 0);
90 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
91
92 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070093 WindowTestUtils.TestAppWindowToken appWindowToken2 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070094 new WindowTestUtils.TestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080095 task2.addChild(appWindowToken2, 0);
96 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
97
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070098 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080099 task2.setSendingToBottom(true);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -0700100 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -0800101 }
102
103 @Test
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800104 public void testStackRemoveImmediately() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700105 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800106 final Task task = createTaskInStack(stack, 0 /* userId */);
107 assertEquals(stack, task.mStack);
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700108 assertTrue(mDisplayContent.mDimLayerController.hasDimLayerUser(stack));
109 assertTrue(mDisplayContent.mDimLayerController.hasDimLayerUser(task));
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800110
111 // Remove stack and check if its child is also removed.
112 stack.removeImmediately();
113 assertNull(stack.getDisplayContent());
114 assertNull(task.mStack);
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700115 assertFalse(mDisplayContent.mDimLayerController.hasDimLayerUser(stack));
116 assertFalse(mDisplayContent.mDimLayerController.hasDimLayerUser(task));
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800117 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800118}