blob: 45a7999488010b05321b5d0a27022e71ef244c62 [file] [log] [blame]
Jorim Jaggi02886a82016-12-06 09:10:06 -08001/*
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 static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
20import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
21import static junit.framework.Assert.assertEquals;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010022import static junit.framework.Assert.assertFalse;
23import static junit.framework.Assert.assertTrue;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024
25import android.platform.test.annotations.Presubmit;
26import android.support.test.filters.SmallTest;
27import android.support.test.runner.AndroidJUnit4;
28import android.util.ArraySet;
29
30import org.junit.Test;
31import 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)
41public 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 Lee6d410262017-02-28 15:30:17 -080054 assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0));
Jorim Jaggi02886a82016-12-06 09:10:06 -080055 }
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 Jaggi0fe7ce962017-02-22 16:45:48 +010073
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 Jaggi02886a82016-12-06 09:10:06 -080084}