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 static junit.framework.Assert.assertTrue;
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 org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 /**
30  * Test class for {@link AppTransition}.
31  *
32  * runtest frameworks-services -c com.android.server.wm.UnknownAppVisibilityControllerTest
33  */
34 @SmallTest
35 @Presubmit
36 @RunWith(AndroidJUnit4.class)
37 public class UnknownAppVisibilityControllerTest extends WindowTestsBase {
38 
39     @Before
setUp()40     public void setUp() throws Exception {
41         super.setUp();
42         sWm.mUnknownAppVisibilityController.clear();
43     }
44 
45     @Test
testFlow()46     public void testFlow() throws Exception {
47         final AppWindowToken token = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
48         sWm.mUnknownAppVisibilityController.notifyLaunched(token);
49         sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token);
50         sWm.mUnknownAppVisibilityController.notifyRelayouted(token);
51 
52         // Make sure our handler processed the message.
53         Thread.sleep(100);
54         assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
55     }
56 
57     @Test
testMultiple()58     public void testMultiple() throws Exception {
59         final AppWindowToken token1 = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
60         final AppWindowToken token2 = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
61         sWm.mUnknownAppVisibilityController.notifyLaunched(token1);
62         sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token1);
63         sWm.mUnknownAppVisibilityController.notifyLaunched(token2);
64         sWm.mUnknownAppVisibilityController.notifyRelayouted(token1);
65         sWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token2);
66         sWm.mUnknownAppVisibilityController.notifyRelayouted(token2);
67 
68         // Make sure our handler processed the message.
69         Thread.sleep(100);
70         assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
71     }
72 
73     @Test
testClear()74     public void testClear() throws Exception {
75         final AppWindowToken token = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
76         sWm.mUnknownAppVisibilityController.notifyLaunched(token);
77         sWm.mUnknownAppVisibilityController.clear();;
78         assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
79     }
80 
81     @Test
testAppRemoved()82     public void testAppRemoved() throws Exception {
83         final AppWindowToken token = new WindowTestUtils.TestAppWindowToken(mDisplayContent);
84         sWm.mUnknownAppVisibilityController.notifyLaunched(token);
85         sWm.mUnknownAppVisibilityController.appRemovedOrHidden(token);
86         assertTrue(sWm.mUnknownAppVisibilityController.allResolved());
87     }
88 }
89