TaskStackTests.java revision 11cc516a925ac7fc814dbb0a79a7f0abfbfe1ce1
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 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 26import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; 27import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 28 29import 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 { 48 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); 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 } 62 63 @Test 64 public void testClosingAppDifferentStackOrientation() throws Exception { 65 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); 66 final Task task1 = createTaskInStack(stack, 0 /* userId */); 67 WindowTestUtils.TestAppWindowToken appWindowToken1 = 68 new WindowTestUtils.TestAppWindowToken(mDisplayContent); 69 task1.addChild(appWindowToken1, 0); 70 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); 71 72 final Task task2 = createTaskInStack(stack, 1 /* userId */); 73 WindowTestUtils.TestAppWindowToken appWindowToken2 = 74 new WindowTestUtils.TestAppWindowToken(mDisplayContent); 75 task2.addChild(appWindowToken2, 0); 76 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); 77 78 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); 79 sWm.mClosingApps.add(appWindowToken2); 80 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); 81 } 82 83 @Test 84 public void testMoveTaskToBackDifferentStackOrientation() throws Exception { 85 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); 86 final Task task1 = createTaskInStack(stack, 0 /* userId */); 87 WindowTestUtils.TestAppWindowToken appWindowToken1 = 88 new WindowTestUtils.TestAppWindowToken(mDisplayContent); 89 task1.addChild(appWindowToken1, 0); 90 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); 91 92 final Task task2 = createTaskInStack(stack, 1 /* userId */); 93 WindowTestUtils.TestAppWindowToken appWindowToken2 = 94 new WindowTestUtils.TestAppWindowToken(mDisplayContent); 95 task2.addChild(appWindowToken2, 0); 96 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT); 97 98 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation()); 99 task2.setSendingToBottom(true); 100 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation()); 101 } 102 103 @Test 104 public void testStackRemoveImmediately() throws Exception { 105 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); 106 final Task task = createTaskInStack(stack, 0 /* userId */); 107 assertEquals(stack, task.mStack); 108 assertTrue(mDisplayContent.mDimLayerController.hasDimLayerUser(stack)); 109 assertTrue(mDisplayContent.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(mDisplayContent.mDimLayerController.hasDimLayerUser(stack)); 116 assertFalse(mDisplayContent.mDimLayerController.hasDimLayerUser(task)); 117 } 118} 119