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 | |
| 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
| 21 | |
| 22 | import android.platform.test.annotations.Presubmit; |
| 23 | import android.support.test.filters.SmallTest; |
| 24 | import android.support.test.runner.AndroidJUnit4; |
| 25 | |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 28 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertFalse; |
| 31 | import static org.junit.Assert.assertNotNull; |
| 32 | import static org.junit.Assert.assertNull; |
| 33 | import 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) |
| 44 | public class TaskStackTests extends WindowTestsBase { |
| 45 | |
| 46 | @Test |
| 47 | public void testStackPositionChildAt() throws Exception { |
| 48 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 49 | 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 Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 62 | |
| 63 | @Test |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 64 | public void testClosingAppDifferentStackOrientation() throws Exception { |
| 65 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 66 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 67 | WindowTestUtils.TestAppWindowToken appWindowToken1 = |
| 68 | new WindowTestUtils.TestAppWindowToken(sDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 69 | task1.addChild(appWindowToken1, 0); |
| 70 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 71 | |
| 72 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 73 | WindowTestUtils.TestAppWindowToken appWindowToken2 = |
| 74 | new WindowTestUtils.TestAppWindowToken(sDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 75 | task2.addChild(appWindowToken2, 0); |
| 76 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 77 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 78 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 79 | sWm.mClosingApps.add(appWindowToken2); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 80 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testMoveTaskToBackDifferentStackOrientation() throws Exception { |
| 85 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 86 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 87 | WindowTestUtils.TestAppWindowToken appWindowToken1 = |
| 88 | new WindowTestUtils.TestAppWindowToken(sDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 89 | task1.addChild(appWindowToken1, 0); |
| 90 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 91 | |
| 92 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 93 | WindowTestUtils.TestAppWindowToken appWindowToken2 = |
| 94 | new WindowTestUtils.TestAppWindowToken(sDisplayContent); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 95 | task2.addChild(appWindowToken2, 0); |
| 96 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 97 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 98 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 99 | task2.setSendingToBottom(true); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 100 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Test |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 104 | public void testStackRemoveImmediately() throws Exception { |
| 105 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 106 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 107 | assertEquals(stack, task.mStack); |
| 108 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 109 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 110 | |
| 111 | // Remove stack and check if its child is also removed. |
| 112 | stack.removeImmediately(); |
| 113 | assertNull(stack.getDisplayContent()); |
| 114 | assertNull(task.mStack); |
| 115 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 116 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 117 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 118 | } |