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 android.content.pm.ActivityInfo; |
| 20 | import android.view.WindowManager; |
| 21 | import android.view.WindowManager.LayoutParams; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | |
| 25 | import android.platform.test.annotations.Presubmit; |
| 26 | import android.support.test.filters.SmallTest; |
| 27 | import android.support.test.runner.AndroidJUnit4; |
| 28 | |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 29 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 30 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 31 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 32 | import static org.junit.Assert.assertEquals; |
| 33 | import static org.junit.Assert.assertFalse; |
| 34 | import static org.junit.Assert.assertNotNull; |
| 35 | import static org.junit.Assert.assertNull; |
| 36 | import static org.junit.Assert.assertTrue; |
| 37 | |
| 38 | /** |
| 39 | * Tests for the {@link TaskStack} class. |
| 40 | * |
| 41 | * Build/Install/Run: |
| 42 | * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests |
| 43 | */ |
| 44 | @SmallTest |
| 45 | @Presubmit |
| 46 | @RunWith(AndroidJUnit4.class) |
| 47 | public class TaskStackTests extends WindowTestsBase { |
| 48 | |
| 49 | @Test |
| 50 | public void testStackPositionChildAt() throws Exception { |
| 51 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 52 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
| 53 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
| 54 | |
| 55 | // Current user task should be moved to top. |
| 56 | stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */); |
| 57 | assertEquals(stack.mChildren.get(0), task2); |
| 58 | assertEquals(stack.mChildren.get(1), task1); |
| 59 | |
| 60 | // Non-current user won't be moved to top. |
| 61 | stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */); |
| 62 | assertEquals(stack.mChildren.get(0), task2); |
| 63 | assertEquals(stack.mChildren.get(1), task1); |
| 64 | } |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 65 | |
| 66 | @Test |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 67 | public void testClosingAppDifferentStackOrientation() throws Exception { |
| 68 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 69 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
| 70 | TestAppWindowToken appWindowToken1 = new TestAppWindowToken(sDisplayContent); |
| 71 | task1.addChild(appWindowToken1, 0); |
| 72 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 73 | |
| 74 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
| 75 | TestAppWindowToken appWindowToken2 = new TestAppWindowToken(sDisplayContent); |
| 76 | task2.addChild(appWindowToken2, 0); |
| 77 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 78 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame^] | 79 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 80 | sWm.mClosingApps.add(appWindowToken2); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame^] | 81 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void testMoveTaskToBackDifferentStackOrientation() throws Exception { |
| 86 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 87 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
| 88 | TestAppWindowToken appWindowToken1 = new TestAppWindowToken(sDisplayContent); |
| 89 | task1.addChild(appWindowToken1, 0); |
| 90 | appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); |
| 91 | |
| 92 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
| 93 | TestAppWindowToken appWindowToken2 = new TestAppWindowToken(sDisplayContent); |
| 94 | task2.addChild(appWindowToken2, 0); |
| 95 | appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); |
| 96 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame^] | 97 | assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 98 | task2.setSendingToBottom(true); |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame^] | 99 | assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Test |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame] | 103 | public void testStackRemoveImmediately() throws Exception { |
| 104 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 105 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 106 | assertEquals(stack, task.mStack); |
| 107 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 108 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 109 | |
| 110 | // Remove stack and check if its child is also removed. |
| 111 | stack.removeImmediately(); |
| 112 | assertNull(stack.getDisplayContent()); |
| 113 | assertNull(task.mStack); |
| 114 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 115 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 116 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 117 | } |