blob: e811e1d955ee11df8a558ae15d3c951f3ab451a4 [file] [log] [blame]
Jason Monk297c04e2018-08-23 17:16:59 -04001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.statusbar.phone;
16
Charles Chenf3d295c2018-11-30 18:15:21 +080017import static android.view.Display.DEFAULT_DISPLAY;
18
Jason Monk297c04e2018-08-23 17:16:59 -040019import static org.junit.Assert.assertFalse;
20import static org.mockito.Mockito.mock;
Lucas Dupin086c6fc2018-10-16 18:06:43 -070021import static org.mockito.Mockito.when;
Jason Monk297c04e2018-08-23 17:16:59 -040022
23import android.app.Notification;
24import android.app.StatusBarManager;
25import android.content.Context;
26import android.metrics.LogMaker;
27import android.os.UserHandle;
28import android.service.notification.StatusBarNotification;
Jason Monk297c04e2018-08-23 17:16:59 -040029import android.support.test.metricshelper.MetricsAsserts;
30import android.testing.AndroidTestingRunner;
31import android.testing.TestableLooper;
32import android.testing.TestableLooper.RunWithLooper;
33import android.view.ViewGroup;
34
Brett Chabot84151d92019-02-27 15:37:59 -080035import androidx.test.filters.SmallTest;
36
Jason Monk297c04e2018-08-23 17:16:59 -040037import com.android.internal.logging.MetricsLogger;
38import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
39import com.android.internal.logging.testing.FakeMetricsLogger;
40import com.android.systemui.SysuiTestCase;
41import com.android.systemui.statusbar.CommandQueue;
42import com.android.systemui.statusbar.notification.ActivityLaunchAnimator;
Gus Prevasb43dc652018-12-20 13:11:45 -050043import com.android.systemui.statusbar.notification.NotificationAlertingManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050044import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Ned Burnsc5864672019-02-20 12:57:29 -050045import com.android.systemui.statusbar.notification.collection.NotificationRowBinderImpl;
Jason Monk297c04e2018-08-23 17:16:59 -040046import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
47import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
48
49import org.junit.Before;
50import org.junit.Test;
51import org.junit.runner.RunWith;
52
53@SmallTest
54@RunWith(AndroidTestingRunner.class)
Aaron Heuckroth96cd93f2018-11-20 11:14:40 -050055@RunWithLooper()
Jason Monk297c04e2018-08-23 17:16:59 -040056public class StatusBarNotificationPresenterTest extends SysuiTestCase {
57
58
59 private StatusBarNotificationPresenter mStatusBar;
60 private CommandQueue mCommandQueue;
61 private FakeMetricsLogger mMetricsLogger;
62 private ShadeController mShadeController = mock(ShadeController.class);
63
64 @Before
65 public void setup() {
66 mMetricsLogger = new FakeMetricsLogger();
67 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Charles Chenf3d295c2018-11-30 18:15:21 +080068 mCommandQueue = new CommandQueue(mContext);
Jason Monk297c04e2018-08-23 17:16:59 -040069 mContext.putComponent(CommandQueue.class, mCommandQueue);
70 mDependency.injectTestDependency(ShadeController.class, mShadeController);
71
Lucas Dupin086c6fc2018-10-16 18:06:43 -070072 StatusBarWindowView statusBarWindowView = mock(StatusBarWindowView.class);
73 when(statusBarWindowView.getResources()).thenReturn(mContext.getResources());
Jason Monk297c04e2018-08-23 17:16:59 -040074 mStatusBar = new StatusBarNotificationPresenter(mContext,
75 mock(NotificationPanelView.class), mock(HeadsUpManagerPhone.class),
Lucas Dupin086c6fc2018-10-16 18:06:43 -070076 statusBarWindowView, mock(NotificationListContainerViewGroup.class),
Jason Monk297c04e2018-08-23 17:16:59 -040077 mock(DozeScrimController.class), mock(ScrimController.class),
Gus Prevasb43dc652018-12-20 13:11:45 -050078 mock(ActivityLaunchAnimator.class), mock(StatusBarKeyguardViewManager.class),
Ned Burnsc5864672019-02-20 12:57:29 -050079 mock(NotificationAlertingManager.class),
80 mock(NotificationRowBinderImpl.class));
Jason Monk297c04e2018-08-23 17:16:59 -040081 }
82
83 @Test
84 public void testHeadsUp_disabledStatusBar() {
85 Notification n = new Notification.Builder(getContext(), "a").build();
86 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
87 UserHandle.of(0), null, 0);
Ned Burnsf81c4c42019-01-07 14:10:43 -050088 NotificationEntry entry = new NotificationEntry(sbn);
Charles Chenf3d295c2018-11-30 18:15:21 +080089 mCommandQueue.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_EXPAND, 0,
90 false /* animate */);
Jason Monk297c04e2018-08-23 17:16:59 -040091 TestableLooper.get(this).processAllMessages();
92
93 assertFalse("The panel shouldn't allow heads up while disabled",
94 mStatusBar.canHeadsUp(entry, sbn));
95 }
96
97 @Test
98 public void testHeadsUp_disabledNotificationShade() {
99 Notification n = new Notification.Builder(getContext(), "a").build();
100 StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
101 UserHandle.of(0), null, 0);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500102 NotificationEntry entry = new NotificationEntry(sbn);
Charles Chenf3d295c2018-11-30 18:15:21 +0800103 mCommandQueue.disable(DEFAULT_DISPLAY, 0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE,
104 false /* animate */);
Jason Monk297c04e2018-08-23 17:16:59 -0400105 TestableLooper.get(this).processAllMessages();
106
107 assertFalse("The panel shouldn't allow heads up while notitifcation shade disabled",
108 mStatusBar.canHeadsUp(entry, sbn));
109 }
110
111 @Test
112 public void onActivatedMetrics() {
113 ActivatableNotificationView view = mock(ActivatableNotificationView.class);
114 mStatusBar.onActivated(view);
115
116 MetricsAsserts.assertHasLog("missing lockscreen note tap log",
117 mMetricsLogger.getLogs(),
118 new LogMaker(MetricsEvent.ACTION_LS_NOTE)
119 .setType(MetricsEvent.TYPE_ACTION));
120 }
121
122 // We need this because mockito doesn't know how to construct a mock that extends ViewGroup
123 // and implements NotificationListContainer without it because of classloader issues.
124 private abstract static class NotificationListContainerViewGroup extends ViewGroup
125 implements NotificationListContainer {
126
127 public NotificationListContainerViewGroup(Context context) {
128 super(context);
129 }
130 }
131}
132