Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [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 | |
| 19 | import static org.mockito.ArgumentMatchers.eq; |
| 20 | import static org.mockito.Mockito.inOrder; |
| 21 | import static org.mockito.Mockito.verify; |
| 22 | import static org.mockito.Mockito.when; |
| 23 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 24 | import android.testing.AndroidTestingRunner; |
| 25 | import android.testing.TestableLooper; |
| 26 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 27 | import androidx.test.filters.SmallTest; |
| 28 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 29 | import com.android.keyguard.KeyguardStatusView; |
| 30 | import com.android.systemui.SysuiTestCase; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 31 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.AmbientPulseManager; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 33 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 34 | import com.android.systemui.statusbar.PulseExpansionHandler; |
| 35 | import com.android.systemui.statusbar.StatusBarStateControllerImpl; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 36 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 38 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
| 39 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 40 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 41 | |
| 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
| 44 | import org.junit.runner.RunWith; |
| 45 | import org.mockito.InOrder; |
| 46 | import org.mockito.Mock; |
| 47 | import org.mockito.MockitoAnnotations; |
| 48 | |
| 49 | @SmallTest |
| 50 | @RunWith(AndroidTestingRunner.class) |
| 51 | @TestableLooper.RunWithLooper |
| 52 | public class NotificationPanelViewTest extends SysuiTestCase { |
| 53 | |
| 54 | @Mock |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 55 | private SysuiStatusBarStateController mStatusBarStateController; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 56 | @Mock |
| 57 | private NotificationStackScrollLayout mNotificationStackScrollLayout; |
| 58 | @Mock |
| 59 | private KeyguardStatusView mKeyguardStatusView; |
Lucas Dupin | c97d88f | 2019-01-17 16:34:22 -0800 | [diff] [blame] | 60 | @Mock |
| 61 | private KeyguardStatusBarView mKeyguardStatusBar; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 62 | private NotificationPanelView mNotificationPanelView; |
| 63 | |
| 64 | @Before |
| 65 | public void setup() { |
| 66 | MockitoAnnotations.initMocks(this); |
| 67 | mDependency.injectTestDependency(StatusBarStateController.class, |
| 68 | mStatusBarStateController); |
| 69 | mDependency.injectMockDependency(ShadeController.class); |
| 70 | mDependency.injectMockDependency(NotificationLockscreenUserManager.class); |
| 71 | mDependency.injectMockDependency(ConfigurationController.class); |
| 72 | mDependency.injectMockDependency(ZenModeController.class); |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 73 | NotificationWakeUpCoordinator coordinator = |
| 74 | new NotificationWakeUpCoordinator( |
| 75 | new AmbientPulseManager(mContext), |
| 76 | new StatusBarStateControllerImpl()); |
| 77 | PulseExpansionHandler expansionHandler = new PulseExpansionHandler(mContext, coordinator); |
| 78 | mNotificationPanelView = new TestableNotificationPanelView(coordinator, expansionHandler); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testSetDozing_notifiesNsslAndStateController() { |
| 83 | mNotificationPanelView.setDozing(true /* dozing */, true /* animate */, null /* touch */); |
| 84 | InOrder inOrder = inOrder(mNotificationStackScrollLayout, mStatusBarStateController); |
| 85 | inOrder.verify(mNotificationStackScrollLayout).setDark(eq(true), eq(true), eq(null)); |
| 86 | inOrder.verify(mNotificationStackScrollLayout).setShowDarkShelf(eq(true)); |
| 87 | inOrder.verify(mStatusBarStateController).setDozeAmount(eq(1f), eq(true)); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void testSetDozing_showsDarkShelfWithDefaultClock() { |
| 92 | when(mKeyguardStatusView.hasCustomClock()).thenReturn(false); |
| 93 | mNotificationPanelView.setDozing(true /* dozing */, true /* animate */, null /* touch */); |
| 94 | verify(mNotificationStackScrollLayout).setShowDarkShelf(eq(true)); |
| 95 | } |
| 96 | |
| 97 | @Test |
| 98 | public void testSetDozing_hidesDarkShelfWhenCustomClock() { |
| 99 | when(mKeyguardStatusView.hasCustomClock()).thenReturn(true); |
| 100 | mNotificationPanelView.setDozing(true /* dozing */, true /* animate */, null /* touch */); |
| 101 | verify(mNotificationStackScrollLayout).setShowDarkShelf(eq(false)); |
| 102 | } |
| 103 | |
| 104 | private class TestableNotificationPanelView extends NotificationPanelView { |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 105 | TestableNotificationPanelView(NotificationWakeUpCoordinator coordinator, |
| 106 | PulseExpansionHandler expansionHandler) { |
| 107 | super(NotificationPanelViewTest.this.mContext, null, coordinator, expansionHandler); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 108 | mNotificationStackScroller = mNotificationStackScrollLayout; |
| 109 | mKeyguardStatusView = NotificationPanelViewTest.this.mKeyguardStatusView; |
Lucas Dupin | c97d88f | 2019-01-17 16:34:22 -0800 | [diff] [blame] | 110 | mKeyguardStatusBar = NotificationPanelViewTest.this.mKeyguardStatusBar; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |