Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static junit.framework.Assert.assertTrue; |
| 20 | import static org.mockito.Mockito.any; |
| 21 | import static org.mockito.Mockito.doAnswer; |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 22 | |
| 23 | import android.app.ActivityManagerInternal; |
| 24 | import android.content.Context; |
| 25 | import android.platform.test.annotations.Presubmit; |
| 26 | import android.support.test.InstrumentationRegistry; |
| 27 | import android.support.test.filters.SmallTest; |
| 28 | import android.support.test.runner.AndroidJUnit4; |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 29 | |
| 30 | import com.android.server.LocalServices; |
| 31 | |
| 32 | import org.junit.After; |
| 33 | import org.junit.Before; |
| 34 | import org.junit.Test; |
| 35 | import org.junit.runner.RunWith; |
| 36 | import org.mockito.Mock; |
| 37 | import org.mockito.MockitoAnnotations; |
| 38 | import org.mockito.invocation.InvocationOnMock; |
| 39 | |
| 40 | /** |
| 41 | * Test class for {@link AppTransition}. |
| 42 | * |
Jorim Jaggi | 46a26a8 | 2016-12-15 17:45:41 -0800 | [diff] [blame] | 43 | * runtest frameworks-services -c com.android.server.wm.UnknownAppVisibilityControllerTest |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 44 | */ |
| 45 | @SmallTest |
Jorim Jaggi | 46a26a8 | 2016-12-15 17:45:41 -0800 | [diff] [blame] | 46 | @Presubmit |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 47 | @RunWith(AndroidJUnit4.class) |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame^] | 48 | public class UnknownAppVisibilityControllerTest extends WindowTestsBase { |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 49 | |
| 50 | private WindowManagerService mWm; |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 51 | |
| 52 | @Before |
| 53 | public void setUp() throws Exception { |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame^] | 54 | super.setUp(); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | final Context context = InstrumentationRegistry.getTargetContext(); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 56 | doAnswer((InvocationOnMock invocationOnMock) -> { |
| 57 | invocationOnMock.getArgumentAt(0, Runnable.class).run(); |
| 58 | return null; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame^] | 59 | }).when(sMockAm).notifyKeyguardFlagsChanged(any()); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 60 | mWm = TestWindowManagerPolicy.getWindowManagerService(context); |
| 61 | } |
| 62 | |
| 63 | @After |
| 64 | public void tearDown() throws Exception { |
| 65 | LocalServices.removeServiceForTest(ActivityManagerInternal.class); |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void testFlow() throws Exception { |
| 70 | AppWindowToken token = createAppToken(); |
| 71 | mWm.mUnknownAppVisibilityController.notifyLaunched(token); |
| 72 | mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token); |
| 73 | mWm.mUnknownAppVisibilityController.notifyRelayouted(token); |
| 74 | |
| 75 | // Make sure our handler processed the message. |
| 76 | Thread.sleep(100); |
| 77 | assertTrue(mWm.mUnknownAppVisibilityController.allResolved()); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testMultiple() throws Exception { |
| 82 | AppWindowToken token1 = createAppToken(); |
| 83 | AppWindowToken token2 = createAppToken(); |
| 84 | mWm.mUnknownAppVisibilityController.notifyLaunched(token1); |
| 85 | mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token1); |
| 86 | mWm.mUnknownAppVisibilityController.notifyLaunched(token2); |
| 87 | mWm.mUnknownAppVisibilityController.notifyRelayouted(token1); |
| 88 | mWm.mUnknownAppVisibilityController.notifyAppResumedFinished(token2); |
| 89 | mWm.mUnknownAppVisibilityController.notifyRelayouted(token2); |
| 90 | |
| 91 | // Make sure our handler processed the message. |
| 92 | Thread.sleep(100); |
| 93 | assertTrue(mWm.mUnknownAppVisibilityController.allResolved()); |
| 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testClear() throws Exception { |
| 98 | AppWindowToken token = createAppToken(); |
| 99 | mWm.mUnknownAppVisibilityController.notifyLaunched(token); |
| 100 | mWm.mUnknownAppVisibilityController.clear();; |
| 101 | assertTrue(mWm.mUnknownAppVisibilityController.allResolved()); |
| 102 | } |
| 103 | |
| 104 | @Test |
| 105 | public void testAppRemoved() throws Exception { |
| 106 | AppWindowToken token = createAppToken(); |
| 107 | mWm.mUnknownAppVisibilityController.notifyLaunched(token); |
| 108 | mWm.mUnknownAppVisibilityController.appRemoved(token); |
| 109 | assertTrue(mWm.mUnknownAppVisibilityController.allResolved()); |
| 110 | } |
| 111 | |
| 112 | private AppWindowToken createAppToken() { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 113 | return new AppWindowToken(mWm, null, false, mWm.getDefaultDisplayContentLocked()); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 114 | } |
| 115 | } |