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