blob: a97fa1ff162964477ac8e3ac39ec8751c5e2f92e [file] [log] [blame]
Lucas Dupin7fc9dc12019-01-03 09:19:43 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
19import static org.mockito.ArgumentMatchers.eq;
20import static org.mockito.Mockito.inOrder;
21import static org.mockito.Mockito.verify;
22import static org.mockito.Mockito.when;
23
24import android.support.test.filters.SmallTest;
25import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper;
27
28import com.android.keyguard.KeyguardStatusView;
29import com.android.systemui.SysuiTestCase;
Beverly8fdb5332019-02-04 14:29:49 -050030import com.android.systemui.plugins.statusbar.StatusBarStateController;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080031import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Beverly8fdb5332019-02-04 14:29:49 -050032import com.android.systemui.statusbar.SysuiStatusBarStateController;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080033import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
34import com.android.systemui.statusbar.policy.ConfigurationController;
35import com.android.systemui.statusbar.policy.ZenModeController;
36
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.InOrder;
41import org.mockito.Mock;
42import org.mockito.MockitoAnnotations;
43
44@SmallTest
45@RunWith(AndroidTestingRunner.class)
46@TestableLooper.RunWithLooper
47public class NotificationPanelViewTest extends SysuiTestCase {
48
49 @Mock
Beverly8fdb5332019-02-04 14:29:49 -050050 private SysuiStatusBarStateController mStatusBarStateController;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080051 @Mock
52 private NotificationStackScrollLayout mNotificationStackScrollLayout;
53 @Mock
54 private KeyguardStatusView mKeyguardStatusView;
Lucas Dupinc97d88f2019-01-17 16:34:22 -080055 @Mock
56 private KeyguardStatusBarView mKeyguardStatusBar;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -080057 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 Dupinc97d88f2019-01-17 16:34:22 -080099 mKeyguardStatusBar = NotificationPanelViewTest.this.mKeyguardStatusBar;
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800100 }
101 }
102}