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