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; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 30 | |
| 31 | import org.junit.Before; |
| 32 | import org.junit.Test; |
| 33 | import org.junit.runner.RunWith; |
| 34 | |
| 35 | @SmallTest |
| 36 | @RunWith(AndroidJUnit4.class) |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 37 | public class StatusBarTest extends SysuiTestCase { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 38 | |
| 39 | StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 40 | StatusBar mStatusBar; |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 41 | |
| 42 | @Before |
| 43 | public void setup() { |
| 44 | mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 45 | mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 46 | |
| 47 | doAnswer(invocation -> { |
| 48 | OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; |
| 49 | onDismissAction.onDismiss(); |
| 50 | return null; |
| 51 | }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); |
| 52 | |
| 53 | doAnswer(invocation -> { |
| 54 | Runnable runnable = (Runnable) invocation.getArguments()[0]; |
| 55 | runnable.run(); |
| 56 | return null; |
| 57 | }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { |
| 62 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 63 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); |
| 64 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 65 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void executeRunnableDismissingKeyguard_nullRunnable_showing() { |
| 70 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); |
| 71 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 72 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 73 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { |
| 78 | when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); |
| 79 | when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); |
| 80 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 81 | mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 84 | static class TestableStatusBar extends StatusBar { |
| 85 | public TestableStatusBar(StatusBarKeyguardViewManager man) { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 86 | mStatusBarKeyguardViewManager = man; |
| 87 | } |
| 88 | |
| 89 | @Override |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame^] | 90 | protected H createHandler() { |
Adrian Roos | ef7a402 | 2017-01-19 14:48:35 -0800 | [diff] [blame] | 91 | return null; |
| 92 | } |
| 93 | } |
| 94 | } |