WindowContainerControllerTests.java revision 26c0dfed7a0cd54abafdd0ccbb5b757506d51c76
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 org.junit.Test;
20import org.junit.runner.RunWith;
21
22import android.platform.test.annotations.Presubmit;
23import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
25
26import static org.junit.Assert.assertEquals;
27import static org.junit.Assert.assertNull;
28import static org.junit.Assert.assertTrue;
29
30/**
31 * Test class for {@link WindowContainerController}.
32 *
33 * Build/Install/Run:
34 *  bit FrameworksServicesTests:com.android.server.wm.WindowContainerControllerTests
35 */
36@SmallTest
37@Presubmit
38@org.junit.runner.RunWith(AndroidJUnit4.class)
39public class WindowContainerControllerTests extends WindowTestsBase {
40
41    @Test
42    public void testCreation() throws Exception {
43        final WindowContainerController controller = new WindowContainerController(null, sWm);
44        final WindowContainer container = new WindowContainer();
45
46        container.setController(controller);
47        assertEquals(controller, container.getController());
48        assertEquals(controller.mContainer, container);
49    }
50
51    @Test
52    public void testSetContainer() throws Exception {
53        final WindowContainerController controller = new WindowContainerController(null, sWm);
54        final WindowContainer container = new WindowContainer();
55
56        controller.setContainer(container);
57        assertEquals(controller.mContainer, container);
58
59        // Assert we can't change the container to another one once set
60        boolean gotException = false;
61        try {
62            controller.setContainer(new WindowContainer());
63        } catch (IllegalArgumentException e) {
64            gotException = true;
65        }
66        assertTrue(gotException);
67
68        // Assert that we can set the container to null.
69        controller.setContainer(null);
70        assertNull(controller.mContainer);
71    }
72
73    @Test
74    public void testRemoveContainer() throws Exception {
75        final WindowContainerController controller = new WindowContainerController(null, sWm);
76        final WindowContainer container = new WindowContainer();
77
78        controller.setContainer(container);
79        assertEquals(controller.mContainer, container);
80
81        controller.removeContainer();
82        assertNull(controller.mContainer);
83    }
84}
85