Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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.systemui.statusbar.phone; |
| 18 | |
| 19 | import static org.mockito.Matchers.any; |
| 20 | import static org.mockito.Matchers.anyBoolean; |
| 21 | import static org.mockito.Mockito.doAnswer; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
| 25 | import android.support.test.filters.SmallTest; |
| 26 | import android.support.test.runner.AndroidJUnit4; |
| 27 | |
| 28 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 29 | import com.android.systemui.SysuiTestCase; |
| 30 | import com.android.systemui.statusbar.BaseStatusBar; |
| 31 | |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | |
| 36 | @SmallTest |
| 37 | @RunWith(AndroidJUnit4.class) |
| 38 | public class PhoneStatusBarTest extends SysuiTestCase { |
| 39 | |
| 40 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 41 | PhoneStatusBar mPhoneStatusBar; |
| 42 | |
| 43 | @Before |
| 44 | public void setup() { |
| 45 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
| 46 | mPhoneStatusBar = new TestablePhoneStatusBar(mStatusBarKeyguardViewManager); |
| 47 | |
| 48 | doAnswer(invocation -> { |
| 49 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 50 | onDismissAction.onDismiss(); |
| 51 | return null; |
| 52 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 53 | |
| 54 | doAnswer(invocation -> { |
| 55 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 56 | runnable.run(); |
| 57 | return null; |
| 58 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 63 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 64 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 65 | |
| 66 | mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 71 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 72 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 73 | |
| 74 | mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 79 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 80 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 81 | |
| 82 | mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
| 83 | } |
| 84 | |
| 85 | static class TestablePhoneStatusBar extends PhoneStatusBar { |
| 86 | public TestablePhoneStatusBar(StatusBarKeyguardViewManager man) { |
| 87 | mStatusBarKeyguardViewManager = man; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | protected BaseStatusBar.H createHandler() { |
| 92 | return null; |
| 93 | } |
| 94 | } |
| 95 | } |