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