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