From ef7a4022680c38394e6b154331bf475b5b9c7733 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 19 Jan 2017 14:48:35 -0800 Subject: [PATCH] PhoneStatusBar: Add test for executeRunnableDismissingKeyguard with null runnable Adds a regression test for NPEs around executeRunnableDismissingKeyguard when a null runnable is passed. The bug was fixed in I89477a8a0067e285e5d0122e918fac45274c57ad. Fixes: 33489225 Test: runtest systemui Change-Id: Ia8981bc4c2a1a0f6d8c48e6d66e2af801d6cddac --- .../statusbar/phone/PhoneStatusBarTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarTest.java diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarTest.java new file mode 100644 index 0000000000000..d82566f0bb460 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import com.android.keyguard.KeyguardHostView.OnDismissAction; +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.BaseStatusBar; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class PhoneStatusBarTest extends SysuiTestCase { + + StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; + PhoneStatusBar mPhoneStatusBar; + + @Before + public void setup() { + mStatusBarKeyguardViewManager = mock(StatusBarKeyguardViewManager.class); + mPhoneStatusBar = new TestablePhoneStatusBar(mStatusBarKeyguardViewManager); + + doAnswer(invocation -> { + OnDismissAction onDismissAction = (OnDismissAction) invocation.getArguments()[0]; + onDismissAction.onDismiss(); + return null; + }).when(mStatusBarKeyguardViewManager).dismissWithAction(any(), any(), anyBoolean()); + + doAnswer(invocation -> { + Runnable runnable = (Runnable) invocation.getArguments()[0]; + runnable.run(); + return null; + }).when(mStatusBarKeyguardViewManager).addAfterKeyguardGoneRunnable(any()); + } + + @Test + public void executeRunnableDismissingKeyguard_nullRunnable_showingAndOccluded() { + when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); + when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(true); + + mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); + } + + @Test + public void executeRunnableDismissingKeyguard_nullRunnable_showing() { + when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(true); + when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); + + mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); + } + + @Test + public void executeRunnableDismissingKeyguard_nullRunnable_notShowing() { + when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); + when(mStatusBarKeyguardViewManager.isOccluded()).thenReturn(false); + + mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, false, false, false); + } + + static class TestablePhoneStatusBar extends PhoneStatusBar { + public TestablePhoneStatusBar(StatusBarKeyguardViewManager man) { + mStatusBarKeyguardViewManager = man; + } + + @Override + protected BaseStatusBar.H createHandler() { + return null; + } + } +} \ No newline at end of file