StatusBarTest.java revision ef3199040f0c87f130f8321d9e937604e9f46ca6
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 17package com.android.systemui.statusbar.phone; 18 19import static org.mockito.Matchers.any; 20import static org.mockito.Matchers.anyBoolean; 21import static org.mockito.Mockito.doAnswer; 22import static org.mockito.Mockito.mock; 23import static org.mockito.Mockito.when; 24 25import android.metrics.LogMaker; 26import android.support.test.filters.FlakyTest; 27import android.support.test.filters.SmallTest; 28import android.support.test.metricshelper.MetricsAsserts; 29import android.support.test.runner.AndroidJUnit4; 30import android.util.DisplayMetrics; 31 32import com.android.internal.logging.MetricsLogger; 33import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 34import com.android.internal.logging.testing.FakeMetricsLogger; 35import com.android.keyguard.KeyguardHostView.OnDismissAction; 36import com.android.systemui.SysuiTestCase; 37import com.android.systemui.statusbar.ActivatableNotificationView; 38import com.android.systemui.statusbar.KeyguardIndicationController; 39import com.android.systemui.statusbar.NotificationData; 40import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; 41 42import org.junit.Before; 43import org.junit.Ignore; 44import org.junit.Test; 45import org.junit.runner.RunWith; 46 47@SmallTest 48@RunWith(AndroidJUnit4.class) 49public class StatusBarTest extends SysuiTestCase { 50 51 StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; 52 UnlockMethodCache mUnlockMethodCache; 53 KeyguardIndicationController mKeyguardIndicationController; 54 NotificationStackScrollLayout mStackScroller; 55 StatusBar mStatusBar; 56 FakeMetricsLogger mMetricsLogger; 57 58 private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); 59 60 @Before 61 public void setup() { 62 mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); 63 mUnlockMethodCache = mock(UnlockMethodCache.class); 64 mKeyguardIndicationController = mock(KeyguardIndicationController.class); 65 mStackScroller = mock(NotificationStackScrollLayout.class); 66 mMetricsLogger = new FakeMetricsLogger(); 67 mStatusBar = new TestableStatusBar(mStatusBarKeyguardViewManager, mUnlockMethodCache, 68 mKeyguardIndicationController, mStackScroller, mMetricsLogger); 69 70 doAnswer(invocation -> { 71 OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; 72 onDismissAction.onDismiss(); 73 return null; 74 }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); 75 76 doAnswer(invocation -> { 77 Runnable runnable = (Runnable) invocation.getArguments()[0]; 78 runnable.run(); 79 return null; 80 }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); 81 82 when(mStackScroller.getActivatedChild()).thenReturn(null); 83 } 84 85 @Test 86 public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { 87 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); 88 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); 89 90 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); 91 } 92 93 @Test 94 public void executeRunnableDismissingKeyguard_nullRunnable_showing() { 95 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); 96 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 97 98 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); 99 } 100 101 @Test 102 public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { 103 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); 104 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 105 106 mStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); 107 } 108 109 @Ignore("flaky test") 110 @FlakyTest 111 @Test 112 public void lockscreenStateMetrics_notShowing() { 113 // uninteresting state, except that fingerprint must be non-zero 114 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 115 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); 116 // interesting state 117 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); 118 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); 119 when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); 120 mStatusBar.onKeyguardViewManagerStatesUpdated(); 121 122 MetricsAsserts.assertHasLog("missing hidden insecure lockscreen log", 123 mMetricsLogger.getLogs(), 124 new LogMaker(MetricsEvent.LOCKSCREEN) 125 .setType(MetricsEvent.TYPE_CLOSE) 126 .setSubtype(0)); 127 } 128 129 @Ignore("flaky test") 130 @FlakyTest 131 @Test 132 public void lockscreenStateMetrics_notShowing_secure() { 133 // uninteresting state, except that fingerprint must be non-zero 134 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 135 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); 136 // interesting state 137 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); 138 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); 139 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); 140 141 mStatusBar.onKeyguardViewManagerStatesUpdated(); 142 143 MetricsAsserts.assertHasLog("missing hidden secure lockscreen log", 144 mMetricsLogger.getLogs(), 145 new LogMaker(MetricsEvent.LOCKSCREEN) 146 .setType(MetricsEvent.TYPE_CLOSE) 147 .setSubtype(1)); 148 } 149 150 @Ignore("flaky test") 151 @FlakyTest 152 @Test 153 public void lockscreenStateMetrics_isShowing() { 154 // uninteresting state, except that fingerprint must be non-zero 155 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 156 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); 157 // interesting state 158 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); 159 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); 160 when(mUnlockMethodCache.isMethodSecure()).thenReturn(false); 161 162 mStatusBar.onKeyguardViewManagerStatesUpdated(); 163 164 MetricsAsserts.assertHasLog("missing insecure lockscreen showing", 165 mMetricsLogger.getLogs(), 166 new LogMaker(MetricsEvent.LOCKSCREEN) 167 .setType(MetricsEvent.TYPE_OPEN) 168 .setSubtype(0)); 169 } 170 171 @Ignore("flaky test") 172 @FlakyTest 173 @Test 174 public void lockscreenStateMetrics_isShowing_secure() { 175 // uninteresting state, except that fingerprint must be non-zero 176 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 177 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); 178 // interesting state 179 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); 180 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(false); 181 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); 182 183 mStatusBar.onKeyguardViewManagerStatesUpdated(); 184 185 MetricsAsserts.assertHasLog("missing secure lockscreen showing log", 186 mMetricsLogger.getLogs(), 187 new LogMaker(MetricsEvent.LOCKSCREEN) 188 .setType(MetricsEvent.TYPE_OPEN) 189 .setSubtype(1)); 190 } 191 192 @Ignore("flaky test") 193 @FlakyTest 194 @Test 195 public void lockscreenStateMetrics_isShowingBouncer() { 196 // uninteresting state, except that fingerprint must be non-zero 197 when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); 198 when(mUnlockMethodCache.canSkipBouncer()).thenReturn(true); 199 // interesting state 200 when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); 201 when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); 202 when(mUnlockMethodCache.isMethodSecure()).thenReturn(true); 203 204 mStatusBar.onKeyguardViewManagerStatesUpdated(); 205 206 MetricsAsserts.assertHasLog("missing bouncer log", 207 mMetricsLogger.getLogs(), 208 new LogMaker(MetricsEvent.BOUNCER) 209 .setType(MetricsEvent.TYPE_OPEN) 210 .setSubtype(1)); 211 } 212 213 @Ignore("flaky test") 214 @FlakyTest 215 @Test 216 public void onActivatedMetrics() { 217 ActivatableNotificationView view = mock(ActivatableNotificationView.class); 218 mStatusBar.onActivated(view); 219 220 MetricsAsserts.assertHasLog("missing lockscreen note tap log", 221 mMetricsLogger.getLogs(), 222 new LogMaker(MetricsEvent.ACTION_LS_NOTE) 223 .setType(MetricsEvent.TYPE_ACTION)); 224 } 225 226 static class TestableStatusBar extends StatusBar { 227 public TestableStatusBar(StatusBarKeyguardViewManager man, 228 UnlockMethodCache unlock, KeyguardIndicationController key, 229 NotificationStackScrollLayout stack, MetricsLogger logger) { 230 mStatusBarKeyguardViewManager = man; 231 mUnlockMethodCache = unlock; 232 mKeyguardIndicationController = key; 233 mStackScroller = stack; 234 mMetricsLogger = logger; 235 } 236 237 @Override 238 protected H createHandler() { 239 return null; 240 } 241 } 242}