blob: 7592f1c1fca0a0da838ef00e28bc062bd72571dc [file] [log] [blame]
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080015 */
16
17package com.android.server.wm;
18
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
20import static android.content.res.Configuration.EMPTY;
Brett Chabota26eda92018-07-23 13:08:30 -070021
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080022import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertNull;
24import static org.junit.Assert.assertTrue;
25
Brett Chabota26eda92018-07-23 13:08:30 -070026import android.content.res.Configuration;
27import android.platform.test.annotations.Presubmit;
28
29import androidx.test.filters.FlakyTest;
30import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070031
32import org.junit.Test;
33
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080034/**
35 * Test class for {@link WindowContainerController}.
36 *
37 * Build/Install/Run:
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070038 * atest FrameworksServicesTests:WindowContainerControllerTests
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080039 */
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070040@FlakyTest(bugId = 74078662)
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080041@SmallTest
42@Presubmit
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080043public class WindowContainerControllerTests extends WindowTestsBase {
44
45 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070046 public void testCreation() {
47 final WindowContainerController controller = new WindowContainerController<>(null, mWm);
48 final WindowContainer container = new WindowContainer(mWm);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080049
50 container.setController(controller);
51 assertEquals(controller, container.getController());
52 assertEquals(controller.mContainer, container);
53 }
54
55 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070056 public void testSetContainer() {
57 final WindowContainerController controller = new WindowContainerController<>(null, mWm);
58 final WindowContainer container = new WindowContainer(mWm);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080059
60 controller.setContainer(container);
61 assertEquals(controller.mContainer, container);
62
63 // Assert we can't change the container to another one once set
64 boolean gotException = false;
65 try {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070066 controller.setContainer(new WindowContainer(mWm));
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080067 } catch (IllegalArgumentException e) {
68 gotException = true;
69 }
70 assertTrue(gotException);
71
72 // Assert that we can set the container to null.
73 controller.setContainer(null);
74 assertNull(controller.mContainer);
75 }
76
77 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070078 public void testRemoveContainer() {
79 final WindowContainerController controller = new WindowContainerController<>(null, mWm);
80 final WindowContainer container = new WindowContainer(mWm);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -080081
82 controller.setContainer(container);
83 assertEquals(controller.mContainer, container);
84
85 controller.removeContainer();
86 assertNull(controller.mContainer);
87 }
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070088
89 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070090 public void testOnOverrideConfigurationChanged() {
91 final WindowContainerController controller = new WindowContainerController<>(null, mWm);
92 final WindowContainer container = new WindowContainer(mWm);
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070093
94 controller.setContainer(container);
95 assertEquals(controller.mContainer, container);
96 assertEquals(EMPTY, container.getOverrideConfiguration());
97
98 final Configuration config = new Configuration();
99 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
100 config.windowConfiguration.setAppBounds(10, 10, 10, 10);
101
102 // Assert that the config change through the controller is propagated to the container.
103 controller.onOverrideConfigurationChanged(config);
104 assertEquals(config, container.getOverrideConfiguration());
105
106 // Assert the container configuration isn't changed after removal from the controller.
107 controller.removeContainer();
108 controller.onOverrideConfigurationChanged(EMPTY);
109 assertEquals(config, container.getOverrideConfiguration());
110 }
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800111}