Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 20 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 21 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 23 | import static org.junit.Assert.assertNull; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | |
| 25 | import android.platform.test.annotations.Presubmit; |
| 26 | |
| 27 | import androidx.test.filters.SmallTest; |
| 28 | import androidx.test.runner.AndroidJUnit4; |
| 29 | |
| 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Tests for the {@link TaskStack} class. |
| 35 | * |
| 36 | * Build/Install/Run: |
John Reck | 3d294e7 | 2018-09-21 20:26:48 +0000 | [diff] [blame] | 37 | * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 38 | */ |
| 39 | @SmallTest |
| 40 | @Presubmit |
| 41 | @RunWith(AndroidJUnit4.class) |
| 42 | public class TaskStackTests extends WindowTestsBase { |
| 43 | |
| 44 | @Test |
| 45 | public void testStackPositionChildAt() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 46 | final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 47 | 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 Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 60 | |
| 61 | @Test |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 62 | public void testClosingAppDifferentStackOrientation() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 63 | final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 64 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 65 | WindowTestUtils.TestAppWindowToken appWindowToken1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 66 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 67 | task1.addChild(appWindowToken1, 0); |
| 68 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 69 | |
| 70 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 71 | WindowTestUtils.TestAppWindowToken appWindowToken2 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 72 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 73 | task2.addChild(appWindowToken2, 0); |
| 74 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 75 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 76 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame^] | 77 | mDisplayContent.mClosingApps.add(appWindowToken2); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 78 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testMoveTaskToBackDifferentStackOrientation() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 83 | final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 84 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 85 | WindowTestUtils.TestAppWindowToken appWindowToken1 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 86 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 87 | task1.addChild(appWindowToken1, 0); |
| 88 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 89 | |
| 90 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 91 | WindowTestUtils.TestAppWindowToken appWindowToken2 = |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 92 | WindowTestUtils.createTestAppWindowToken(mDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 93 | task2.addChild(appWindowToken2, 0); |
| 94 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 95 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 96 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 97 | task2.setSendingToBottom(true); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 98 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Test |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 102 | public void testStackRemoveImmediately() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 103 | final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 104 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 105 | assertEquals(stack, task.mStack); |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 106 | |
| 107 | // Remove stack and check if its child is also removed. |
| 108 | stack.removeImmediately(); |
| 109 | assertNull(stack.getDisplayContent()); |
| 110 | assertNull(task.mStack); |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 111 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 112 | } |