DimLayerControllerTests.java revision 367ff7fd5251790ad8dc086bd386be8cba1dda5c
1/*
2 * Copyright (C) 2017 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.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
20
21import static org.junit.Assert.assertFalse;
22import static org.junit.Assert.assertTrue;
23
24import android.hardware.display.DisplayManagerGlobal;
25import android.platform.test.annotations.Presubmit;
26import android.support.test.filters.SmallTest;
27import android.support.test.runner.AndroidJUnit4;
28import android.view.Display;
29import android.view.DisplayInfo;
30
31import org.junit.Test;
32import org.junit.runner.RunWith;
33
34/**
35 * Tests for the {@link DimLayerController} class.
36 *
37 * Build/Install/Run:
38 *  bit FrameworksServicesTests:com.android.server.wm.DimLayerControllerTests
39 */
40@SmallTest
41@Presubmit
42@org.junit.runner.RunWith(AndroidJUnit4.class)
43public class DimLayerControllerTests extends WindowTestsBase {
44
45    /**
46     * This tests if shared fullscreen dim layer is added when stack is added to display
47     * and is removed when the only stack on the display is removed.
48     */
49    @Test
50    public void testSharedFullScreenDimLayer() throws Exception {
51        // Create a display.
52        final DisplayContent dc = createNewDisplay();
53        assertFalse(dc.mDimLayerController.hasSharedFullScreenDimLayer());
54
55        // Add stack with activity.
56        final TaskStack stack = createTaskStackOnDisplay(dc);
57        assertTrue(dc.mDimLayerController.hasDimLayerUser(stack));
58        assertTrue(dc.mDimLayerController.hasSharedFullScreenDimLayer());
59
60        // Remove the only stack on the display and check if the shared dim layer clears.
61        stack.removeImmediately();
62        assertFalse(dc.mDimLayerController.hasDimLayerUser(stack));
63        assertFalse(dc.mDimLayerController.hasSharedFullScreenDimLayer());
64    }
65}
66