Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -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 static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static com.android.server.wm.AppTransition.TRANSIT_UNSET; |
| 21 | import static junit.framework.Assert.assertEquals; |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame^] | 22 | import static junit.framework.Assert.assertFalse; |
| 23 | import static junit.framework.Assert.assertTrue; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 24 | |
| 25 | import android.platform.test.annotations.Presubmit; |
| 26 | import android.support.test.filters.SmallTest; |
| 27 | import android.support.test.runner.AndroidJUnit4; |
| 28 | import android.util.ArraySet; |
| 29 | |
| 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
| 32 | |
| 33 | /** |
| 34 | * Test class for {@link TaskSnapshotController}. |
| 35 | * |
| 36 | * runtest frameworks-services -c com.android.server.wm.TaskSnapshotControllerTest |
| 37 | */ |
| 38 | @SmallTest |
| 39 | @Presubmit |
| 40 | @RunWith(AndroidJUnit4.class) |
| 41 | public class TaskSnapshotControllerTest extends WindowTestsBase { |
| 42 | |
| 43 | @Test |
| 44 | public void testGetClosingApps_closing() throws Exception { |
| 45 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 46 | "closingWindow"); |
| 47 | closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET, |
| 48 | true /* performLayout */, false /* isVoiceInteraction */); |
| 49 | final ArraySet<AppWindowToken> closingApps = new ArraySet<>(); |
| 50 | closingApps.add(closingWindow.mAppToken); |
| 51 | final ArraySet<Task> closingTasks = new ArraySet<>(); |
| 52 | sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); |
| 53 | assertEquals(1, closingTasks.size()); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 54 | assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0)); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testGetClosingApps_notClosing() throws Exception { |
| 59 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 60 | "closingWindow"); |
| 61 | final WindowState openingWindow = createAppWindow(closingWindow.getTask(), |
| 62 | FIRST_APPLICATION_WINDOW, "openingWindow"); |
| 63 | closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET, |
| 64 | true /* performLayout */, false /* isVoiceInteraction */); |
| 65 | openingWindow.mAppToken.setVisibility(null, true /* visible */, TRANSIT_UNSET, |
| 66 | true /* performLayout */, false /* isVoiceInteraction */); |
| 67 | final ArraySet<AppWindowToken> closingApps = new ArraySet<>(); |
| 68 | closingApps.add(closingWindow.mAppToken); |
| 69 | final ArraySet<Task> closingTasks = new ArraySet<>(); |
| 70 | sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); |
| 71 | assertEquals(0, closingTasks.size()); |
| 72 | } |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame^] | 73 | |
| 74 | @Test |
| 75 | public void testSnapshotsDisabled() throws Exception { |
| 76 | final WindowState disabledWindow = createWindow(null, |
| 77 | FIRST_APPLICATION_WINDOW, sDisplayContent, "disabledWindow"); |
| 78 | disabledWindow.mAppToken.setDisablePreviewSnapshots(true); |
| 79 | assertFalse(sWm.mTaskSnapshotController.canSnapshotTask(disabledWindow.getTask())); |
| 80 | final WindowState normalWindow = createWindow(null, |
| 81 | FIRST_APPLICATION_WINDOW, sDisplayContent, "normalWindow"); |
| 82 | assertTrue(sWm.mTaskSnapshotController.canSnapshotTask(normalWindow.getTask())); |
| 83 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 84 | } |