AppWindowContainerControllerTests.java revision e1fe7fa288a34ecaaab390f49ef540edc4a6c52d
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 org.junit.Test;
20
21import android.os.Binder;
22import android.os.IBinder;
23import android.platform.test.annotations.Presubmit;
24import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
26import android.view.IApplicationToken;
27
28import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
29import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
30import static android.content.res.Configuration.EMPTY;
31import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertNotNull;
33import static org.junit.Assert.assertNull;
34
35/**
36 * Test class for {@link AppWindowContainerController}.
37 *
38 * Build/Install/Run:
39 *  bit FrameworksServicesTests:com.android.server.wm.AppWindowContainerControllerTests
40 */
41@SmallTest
42@Presubmit
43@org.junit.runner.RunWith(AndroidJUnit4.class)
44public class AppWindowContainerControllerTests extends WindowTestsBase {
45
46    @Test
47    public void testRemoveContainer() throws Exception {
48        final TestAppWindowContainerController controller = createAppWindowController();
49
50        // Assert token was added to display.
51        assertNotNull(sDisplayContent.getWindowToken(controller.mToken.asBinder()));
52        // Assert that the container was created and linked.
53        assertNotNull(controller.mContainer);
54
55        controller.removeContainer(sDisplayContent.getDisplayId());
56
57        // Assert token was remove from display.
58        assertNull(sDisplayContent.getWindowToken(controller.mToken.asBinder()));
59        // Assert that the container was removed.
60        assertNull(controller.mContainer);
61    }
62
63    @Test
64    public void testSetOrientation() throws Exception {
65        final TestAppWindowContainerController controller = createAppWindowController();
66
67        // Assert orientation is unspecified to start.
68        assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, controller.getOrientation());
69
70        controller.setOrientation(SCREEN_ORIENTATION_LANDSCAPE, sDisplayContent.getDisplayId(),
71                EMPTY /* displayConfig */, false /* freezeScreenIfNeeded */);
72        assertEquals(SCREEN_ORIENTATION_LANDSCAPE, controller.getOrientation());
73
74        controller.removeContainer(sDisplayContent.getDisplayId());
75        // Assert orientation is unspecified to after container is removed.
76        assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, controller.getOrientation());
77    }
78
79    private TestAppWindowContainerController createAppWindowController() {
80        final TaskStack stack = createTaskStackOnDisplay(sDisplayContent);
81        final TestTaskWindowContainerController taskController =
82                new TestTaskWindowContainerController(stack.mStackId);
83        final IApplicationToken token = new TestIApplicationToken();
84        return new TestAppWindowContainerController(taskController, token);
85    }
86
87    private class TestAppWindowContainerController extends AppWindowContainerController {
88
89        final IApplicationToken mToken;
90
91        TestAppWindowContainerController(TestTaskWindowContainerController taskController,
92                IApplicationToken token) {
93            super(taskController, token, null /* listener */, 0 /* index */,
94                    SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */,
95                    true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */,
96                    false /* launchTaskBehind */, false /* alwaysFocusable */,
97                    0 /* targetSdkVersion */, 0 /* rotationAnimationHint */,
98                    0 /* inputDispatchingTimeoutNanos */, sWm);
99            mToken = token;
100        }
101    }
102
103    private class TestIApplicationToken implements IApplicationToken {
104
105        private final Binder mBinder = new Binder();
106        @Override
107        public IBinder asBinder() {
108            return mBinder;
109        }
110    }
111}
112