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 | |
| 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.junit.Assert.assertFalse; |
| 28 | import static org.junit.Assert.assertNotNull; |
| 29 | import static org.junit.Assert.assertNull; |
| 30 | import static org.junit.Assert.assertTrue; |
| 31 | |
| 32 | /** |
| 33 | * Tests for the {@link TaskStack} class. |
| 34 | * |
| 35 | * Build/Install/Run: |
| 36 | * bit FrameworksServicesTests:com.android.server.wm.TaskStackTests |
| 37 | */ |
| 38 | @SmallTest |
| 39 | @Presubmit |
| 40 | @RunWith(AndroidJUnit4.class) |
| 41 | public class TaskStackTests extends WindowTestsBase { |
| 42 | |
| 43 | @Test |
| 44 | public void testStackPositionChildAt() throws Exception { |
| 45 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 46 | final Task task1 = createTaskInStack(stack, 0 /* userId */); |
| 47 | final Task task2 = createTaskInStack(stack, 1 /* userId */); |
| 48 | |
| 49 | // Current user task should be moved to top. |
| 50 | stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */); |
| 51 | assertEquals(stack.mChildren.get(0), task2); |
| 52 | assertEquals(stack.mChildren.get(1), task1); |
| 53 | |
| 54 | // Non-current user won't be moved to top. |
| 55 | stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */); |
| 56 | assertEquals(stack.mChildren.get(0), task2); |
| 57 | assertEquals(stack.mChildren.get(1), task1); |
| 58 | } |
Andrii Kulian | 45a61fe | 2017-01-05 16:53:19 -0800 | [diff] [blame^] | 59 | |
| 60 | @Test |
| 61 | public void testStackRemoveImmediately() throws Exception { |
| 62 | final TaskStack stack = createTaskStackOnDisplay(sDisplayContent); |
| 63 | final Task task = createTaskInStack(stack, 0 /* userId */); |
| 64 | assertEquals(stack, task.mStack); |
| 65 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 66 | assertTrue(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 67 | |
| 68 | // Remove stack and check if its child is also removed. |
| 69 | stack.removeImmediately(); |
| 70 | assertNull(stack.getDisplayContent()); |
| 71 | assertNull(task.mStack); |
| 72 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(stack)); |
| 73 | assertFalse(sDisplayContent.mDimLayerController.hasDimLayerUser(task)); |
| 74 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 75 | } |