Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Lucas Dupin | 71dd484 | 2018-05-29 15:41:03 -0700 | [diff] [blame] | 20 | import static org.mockito.ArgumentMatchers.anyFloat; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.eq; |
| 22 | import static org.mockito.Mockito.never; |
| 23 | import static org.mockito.Mockito.reset; |
| 24 | import static org.mockito.Mockito.verify; |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.when; |
| 26 | |
| 27 | import android.content.Context; |
| 28 | import android.support.test.filters.SmallTest; |
| 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper; |
| 31 | import android.view.ViewGroup; |
| 32 | |
| 33 | import com.android.internal.widget.LockPatternUtils; |
| 34 | import com.android.keyguard.KeyguardHostView; |
| 35 | import com.android.keyguard.ViewMediatorCallback; |
| 36 | import com.android.systemui.SysuiTestCase; |
| 37 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
| 38 | |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
| 41 | import org.junit.runner.RunWith; |
| 42 | import org.mockito.Mock; |
| 43 | import org.mockito.MockitoAnnotations; |
| 44 | |
| 45 | @SmallTest |
| 46 | @RunWith(AndroidTestingRunner.class) |
| 47 | @TestableLooper.RunWithLooper |
| 48 | public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { |
| 49 | |
| 50 | @Mock |
| 51 | private ViewMediatorCallback mViewMediatorCallback; |
| 52 | @Mock |
| 53 | private LockPatternUtils mLockPatternUtils; |
| 54 | @Mock |
| 55 | private KeyguardBouncer mBouncer; |
| 56 | @Mock |
| 57 | private StatusBar mStatusBar; |
| 58 | @Mock |
| 59 | private ViewGroup mContainer; |
| 60 | @Mock |
| 61 | private NotificationPanelView mNotificationPanelView; |
| 62 | @Mock |
| 63 | private FingerprintUnlockController mFingerprintUnlockController; |
| 64 | @Mock |
| 65 | private DismissCallbackRegistry mDismissCallbackRegistry; |
| 66 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
| 67 | |
| 68 | @Before |
| 69 | public void setUp() { |
| 70 | MockitoAnnotations.initMocks(this); |
| 71 | mDependency.injectMockDependency(StatusBarWindowManager.class); |
| 72 | mStatusBarKeyguardViewManager = new TestableStatusBarKeyguardViewManager(getContext(), |
| 73 | mViewMediatorCallback, mLockPatternUtils); |
| 74 | mStatusBarKeyguardViewManager.registerStatusBar(mStatusBar, mContainer, |
| 75 | mNotificationPanelView, mFingerprintUnlockController, mDismissCallbackRegistry); |
| 76 | mStatusBarKeyguardViewManager.show(null); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void dismissWithAction_AfterKeyguardGoneSetToFalse() { |
| 81 | KeyguardHostView.OnDismissAction action = () -> false; |
| 82 | Runnable cancelAction = () -> {}; |
| 83 | mStatusBarKeyguardViewManager.dismissWithAction(action, cancelAction, |
| 84 | false /* afterKeyguardGone */); |
| 85 | verify(mBouncer).showWithDismissAction(eq(action), eq(cancelAction)); |
| 86 | } |
| 87 | |
| 88 | @Test |
| 89 | public void showBouncer_onlyWhenShowing() { |
| 90 | mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); |
| 91 | mStatusBar.showBouncer(true /* scrimmed */); |
| 92 | verify(mBouncer, never()).show(anyBoolean(), anyBoolean()); |
| 93 | verify(mBouncer, never()).show(anyBoolean()); |
| 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void showBouncer_notWhenBouncerAlreadyShowing() { |
| 98 | mStatusBarKeyguardViewManager.hide(0 /* startTime */, 0 /* fadeoutDuration */); |
| 99 | when(mBouncer.isSecure()).thenReturn(true); |
| 100 | mStatusBar.showBouncer(true /* scrimmed */); |
| 101 | verify(mBouncer, never()).show(anyBoolean(), anyBoolean()); |
| 102 | verify(mBouncer, never()).show(anyBoolean()); |
| 103 | } |
| 104 | |
| 105 | @Test |
| 106 | public void showBouncer_showsTheBouncer() { |
| 107 | mStatusBarKeyguardViewManager.showBouncer(true /* scrimmed */); |
| 108 | verify(mBouncer).show(anyBoolean(), eq(true)); |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void onPanelExpansionChanged_neverHidesFullscreenBouncer() { |
| 113 | // TODO: StatusBar should not be here, mBouncer.isFullscreenBouncer() should do the same. |
| 114 | when(mStatusBar.isFullScreenUserSwitcherState()).thenReturn(true); |
| 115 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 116 | true /* tracking */); |
| 117 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE)); |
| 118 | } |
| 119 | |
| 120 | @Test |
| 121 | public void onPanelExpansionChanged_neverHidesScrimmedBouncer() { |
| 122 | when(mBouncer.isShowingScrimmed()).thenReturn(true); |
| 123 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 124 | true /* tracking */); |
| 125 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE)); |
| 126 | } |
| 127 | |
| 128 | @Test |
| 129 | public void onPanelExpansionChanged_neverShowsDuringHintAnimation() { |
| 130 | when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true); |
| 131 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 132 | true /* tracking */); |
| 133 | verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN)); |
| 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void onPanelExpansionChanged_propagatesToBouncer() { |
| 138 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 139 | true /* tracking */); |
| 140 | verify(mBouncer).setExpansion(eq(0.5f)); |
| 141 | } |
| 142 | |
| 143 | @Test |
| 144 | public void onPanelExpansionChanged_showsBouncerWhenSwiping() { |
| 145 | when(mStatusBar.isKeyguardCurrentlySecure()).thenReturn(true); |
| 146 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 147 | true /* tracking */); |
| 148 | verify(mBouncer).show(eq(false), eq(false)); |
| 149 | |
| 150 | // But not when it's already visible |
| 151 | reset(mBouncer); |
| 152 | when(mBouncer.isShowing()).thenReturn(true); |
| 153 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */); |
| 154 | verify(mBouncer, never()).show(eq(false), eq(false)); |
| 155 | |
| 156 | // Or animating away |
| 157 | reset(mBouncer); |
| 158 | when(mBouncer.isAnimatingAway()).thenReturn(true); |
| 159 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */); |
| 160 | verify(mBouncer, never()).show(eq(false), eq(false)); |
| 161 | } |
| 162 | |
Lucas Dupin | aece502 | 2018-05-21 16:44:28 -0700 | [diff] [blame] | 163 | @Test |
| 164 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() { |
| 165 | mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animate */); |
| 166 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, |
| 167 | true /* tracking */); |
| 168 | verify(mBouncer, never()).setExpansion(eq(0.5f)); |
| 169 | } |
| 170 | |
Lucas Dupin | 71dd484 | 2018-05-29 15:41:03 -0700 | [diff] [blame] | 171 | @Test |
| 172 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() { |
| 173 | when(mFingerprintUnlockController.getMode()) |
| 174 | .thenReturn(FingerprintUnlockController.MODE_WAKE_AND_UNLOCK); |
| 175 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE, |
| 176 | false /* tracking */); |
| 177 | verify(mBouncer, never()).setExpansion(anyFloat()); |
| 178 | } |
| 179 | |
Lucas Dupin | f1381bb | 2018-06-08 14:11:41 -0700 | [diff] [blame] | 180 | @Test |
| 181 | public void onPanelExpansionChanged_neverTranslatesBouncerWhenLaunchingApp() { |
| 182 | when(mStatusBar.isInLaunchTransition()).thenReturn(true); |
| 183 | mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE, |
| 184 | false /* tracking */); |
| 185 | verify(mBouncer, never()).setExpansion(anyFloat()); |
| 186 | } |
| 187 | |
Lucas Dupin | f9ca35e | 2018-05-16 20:41:35 -0700 | [diff] [blame] | 188 | private class TestableStatusBarKeyguardViewManager extends StatusBarKeyguardViewManager { |
| 189 | |
| 190 | public TestableStatusBarKeyguardViewManager(Context context, |
| 191 | ViewMediatorCallback callback, |
| 192 | LockPatternUtils lockPatternUtils) { |
| 193 | super(context, callback, lockPatternUtils); |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void registerStatusBar(StatusBar statusBar, ViewGroup container, |
| 198 | NotificationPanelView notificationPanelView, |
| 199 | FingerprintUnlockController fingerprintUnlockController, |
| 200 | DismissCallbackRegistry dismissCallbackRegistry) { |
| 201 | super.registerStatusBar(statusBar, container, notificationPanelView, |
| 202 | fingerprintUnlockController, dismissCallbackRegistry); |
| 203 | mBouncer = StatusBarKeyguardViewManagerTest.this.mBouncer; |
| 204 | } |
| 205 | } |
| 206 | } |