Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 14 | * limitations under the License. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
| 20 | import static android.content.res.Configuration.EMPTY; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 21 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
| 23 | import static org.junit.Assert.assertNull; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
| 27 | import android.platform.test.annotations.Presubmit; |
| 28 | |
| 29 | import androidx.test.filters.FlakyTest; |
| 30 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 31 | |
| 32 | import org.junit.Test; |
| 33 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Test class for {@link WindowContainerController}. |
| 36 | * |
| 37 | * Build/Install/Run: |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 38 | * atest FrameworksServicesTests:WindowContainerControllerTests |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 39 | */ |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 40 | @FlakyTest(bugId = 74078662) |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 41 | @SmallTest |
| 42 | @Presubmit |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 43 | public class WindowContainerControllerTests extends WindowTestsBase { |
| 44 | |
| 45 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 46 | public void testCreation() { |
| 47 | final WindowContainerController controller = new WindowContainerController<>(null, mWm); |
| 48 | final WindowContainer container = new WindowContainer(mWm); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 49 | |
| 50 | container.setController(controller); |
| 51 | assertEquals(controller, container.getController()); |
| 52 | assertEquals(controller.mContainer, container); |
| 53 | } |
| 54 | |
| 55 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 56 | public void testSetContainer() { |
| 57 | final WindowContainerController controller = new WindowContainerController<>(null, mWm); |
| 58 | final WindowContainer container = new WindowContainer(mWm); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 59 | |
| 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 66 | controller.setContainer(new WindowContainer(mWm)); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 67 | } 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 78 | public void testRemoveContainer() { |
| 79 | final WindowContainerController controller = new WindowContainerController<>(null, mWm); |
| 80 | final WindowContainer container = new WindowContainer(mWm); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 81 | |
| 82 | controller.setContainer(container); |
| 83 | assertEquals(controller.mContainer, container); |
| 84 | |
| 85 | controller.removeContainer(); |
| 86 | assertNull(controller.mContainer); |
| 87 | } |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 88 | |
| 89 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame^] | 90 | public void testOnOverrideConfigurationChanged() { |
| 91 | final WindowContainerController controller = new WindowContainerController<>(null, mWm); |
| 92 | final WindowContainer container = new WindowContainer(mWm); |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 93 | |
| 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 Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 111 | } |