blob: c4bd1b281b24e6292aa5ebbd9cae9d35308a03a0 [file] [log] [blame]
Selim Cinek8a9308d2017-08-24 09:31:08 -07001/*
2 * Copyright (C) 2017 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.
Jason Monke59dc402018-08-16 12:05:01 -04006 * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 *
Selim Cinek8a9308d2017-08-24 09:31:08 -07007 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License
12 */
13
Rohan Shah20790b82018-07-02 17:21:04 -070014package com.android.systemui.statusbar.notification.stack;
Selim Cinek8a9308d2017-08-24 09:31:08 -070015
Julia Reynoldsda7c2452020-04-16 16:44:58 -040016import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
Gus Prevase2d6f042018-10-17 15:25:30 -040017import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
18
Jason Monke59dc402018-08-16 12:05:01 -040019import static junit.framework.Assert.assertEquals;
20import static junit.framework.Assert.assertNotNull;
Gus Prevas99ba4ba2018-10-01 16:40:23 -040021import static junit.framework.Assert.assertNull;
22
Jason Monk297c04e2018-08-23 17:16:59 -040023import static org.junit.Assert.assertFalse;
Rohan Shah524cf7b2018-03-15 14:40:02 -070024import static org.mockito.ArgumentMatchers.any;
25import static org.mockito.ArgumentMatchers.anyBoolean;
Jason Monke59dc402018-08-16 12:05:01 -040026import static org.mockito.ArgumentMatchers.anyInt;
Will Brockmane718d582019-01-17 16:38:38 -050027import static org.mockito.ArgumentMatchers.argThat;
Selim Cinekd60ef9e2018-05-16 16:01:05 -070028import static org.mockito.ArgumentMatchers.eq;
Gus Prevase2d6f042018-10-17 15:25:30 -040029import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
Evan Lairdfec77662018-09-18 16:56:50 -040030import static org.mockito.Mockito.atLeastOnce;
Jason Monke59dc402018-08-16 12:05:01 -040031import static org.mockito.Mockito.clearInvocations;
Rohan Shah524cf7b2018-03-15 14:40:02 -070032import static org.mockito.Mockito.doNothing;
Selim Cinek8a9308d2017-08-24 09:31:08 -070033import static org.mockito.Mockito.mock;
Rohan Shah524cf7b2018-03-15 14:40:02 -070034import static org.mockito.Mockito.reset;
35import static org.mockito.Mockito.spy;
Julia Reynolds9cf17562018-03-14 09:49:35 -040036import static org.mockito.Mockito.verify;
Selim Cinek8a9308d2017-08-24 09:31:08 -070037import static org.mockito.Mockito.when;
38
Will Brockmane718d582019-01-17 16:38:38 -050039import android.metrics.LogMaker;
Julia Reynolds1f94a9d2020-05-05 12:40:21 -040040import android.os.UserHandle;
Gus Prevase2d6f042018-10-17 15:25:30 -040041import android.provider.Settings;
Ned Burnsd4a69f72019-06-19 19:49:19 -040042import android.testing.AndroidTestingRunner;
43import android.testing.TestableLooper;
Gus Prevas99ba4ba2018-10-01 16:40:23 -040044import android.view.View;
Selim Cinek8a9308d2017-08-24 09:31:08 -070045
Brett Chabot84151d92019-02-27 15:37:59 -080046import androidx.test.annotation.UiThreadTest;
47import androidx.test.filters.SmallTest;
Brett Chabot84151d92019-02-27 15:37:59 -080048
Will Brockmane718d582019-01-17 16:38:38 -050049import com.android.internal.logging.MetricsLogger;
50import com.android.internal.logging.nano.MetricsProto;
Will Brockmanb65faa82020-03-06 10:26:04 -050051import com.android.internal.logging.testing.UiEventLoggerFake;
Rohan Shah524cf7b2018-03-15 14:40:02 -070052import com.android.systemui.ExpandHelper;
Julia Reynolds9cf17562018-03-14 09:49:35 -040053import com.android.systemui.R;
Selim Cinek8a9308d2017-08-24 09:31:08 -070054import com.android.systemui.SysuiTestCase;
Dave Mankoffc195ea82019-06-28 16:33:25 -040055import com.android.systemui.classifier.FalsingManagerFake;
Will Brockmane718d582019-01-17 16:38:38 -050056import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
Julia Reynolds9cf17562018-03-14 09:49:35 -040057import com.android.systemui.statusbar.EmptyShadeView;
Beverly8b493df2019-12-18 14:16:50 -050058import com.android.systemui.statusbar.FeatureFlags;
Lucas Dupind236ee32019-10-08 15:33:59 -070059import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Lucas Dupin28790c02020-01-30 14:18:41 -080060import com.android.systemui.statusbar.NotificationLockscreenUserManager.UserChangedListener;
Evan Laird181de622019-10-24 09:53:02 -040061import com.android.systemui.statusbar.NotificationMediaManager;
Jason Monke59dc402018-08-16 12:05:01 -040062import com.android.systemui.statusbar.NotificationPresenter;
Jason Monk297c04e2018-08-23 17:16:59 -040063import com.android.systemui.statusbar.NotificationRemoteInputManager;
64import com.android.systemui.statusbar.NotificationShelf;
65import com.android.systemui.statusbar.RemoteInputController;
66import com.android.systemui.statusbar.StatusBarState;
Selim Cinek5454a0d2019-07-30 17:14:50 -070067import com.android.systemui.statusbar.SysuiStatusBarStateController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070068import com.android.systemui.statusbar.notification.DynamicPrivacyController;
Evan Laird04373662020-01-24 17:37:39 -050069import com.android.systemui.statusbar.notification.ForegroundServiceDismissalFeatureController;
Jason Monke59dc402018-08-16 12:05:01 -040070import com.android.systemui.statusbar.notification.NotificationEntryManager;
Ned Burnsafe77bc2020-01-30 20:45:07 -050071import com.android.systemui.statusbar.notification.NotificationEntryManagerLogger;
Evan Laird181de622019-10-24 09:53:02 -040072import com.android.systemui.statusbar.notification.NotificationFilter;
Evan Laird367b6142019-08-30 14:40:34 -040073import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager;
Evan Laird181de622019-10-24 09:53:02 -040074import com.android.systemui.statusbar.notification.VisualStabilityManager;
Beverly7e0d6492020-02-07 16:22:14 -050075import com.android.systemui.statusbar.notification.collection.NotifCollection;
76import com.android.systemui.statusbar.notification.collection.NotifPipeline;
Ned Burnsf81c4c42019-01-07 14:10:43 -050077import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverly79c89ec2019-12-13 10:33:01 -050078import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
Evan Laird181de622019-10-24 09:53:02 -040079import com.android.systemui.statusbar.notification.collection.NotificationRankingManager;
Ned Burnsc0cd2832020-01-10 00:37:03 -050080import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder;
Beverlye558f1d2020-01-07 16:28:58 -050081import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
Steve Elliott960f4ce2019-12-04 15:13:52 -050082import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
Jason Monke59dc402018-08-16 12:05:01 -040083import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070084import com.android.systemui.statusbar.notification.row.FooterView;
85import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
Lucas Dupind236ee32019-10-08 15:33:59 -070086import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
Rohan Shah524cf7b2018-03-15 14:40:02 -070087import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
Selim Cinekc3fec682019-06-06 18:11:07 -070088import com.android.systemui.statusbar.phone.KeyguardBypassController;
Rohan Shah524cf7b2018-03-15 14:40:02 -070089import com.android.systemui.statusbar.phone.NotificationGroupManager;
Lucas Dupinfe218782019-06-11 15:20:32 -070090import com.android.systemui.statusbar.phone.NotificationIconAreaController;
Selim Cinek8a9308d2017-08-24 09:31:08 -070091import com.android.systemui.statusbar.phone.ScrimController;
Jason Monk297c04e2018-08-23 17:16:59 -040092import com.android.systemui.statusbar.phone.ShadeController;
Selim Cinek8a9308d2017-08-24 09:31:08 -070093import com.android.systemui.statusbar.phone.StatusBar;
Beverly482ad6a2019-11-06 16:57:05 -050094import com.android.systemui.statusbar.policy.ZenModeController;
Dave Mankoff02dcaf52020-01-08 15:42:06 -050095import com.android.systemui.util.leak.LeakDetector;
Jason Monke59dc402018-08-16 12:05:01 -040096
Gus Prevase2d6f042018-10-17 15:25:30 -040097import org.junit.After;
Selim Cinek8a9308d2017-08-24 09:31:08 -070098import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070099import org.junit.Rule;
Selim Cinek8a9308d2017-08-24 09:31:08 -0700100import org.junit.Test;
101import org.junit.runner.RunWith;
Jason Monke59dc402018-08-16 12:05:01 -0400102import org.mockito.ArgumentCaptor;
Will Brockmane718d582019-01-17 16:38:38 -0500103import org.mockito.ArgumentMatcher;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700104import org.mockito.Mock;
105import org.mockito.junit.MockitoJUnit;
106import org.mockito.junit.MockitoRule;
Selim Cinek8a9308d2017-08-24 09:31:08 -0700107
Jason Monk297c04e2018-08-23 17:16:59 -0400108import java.util.ArrayList;
Evan Laird181de622019-10-24 09:53:02 -0400109import java.util.List;
Jason Monk297c04e2018-08-23 17:16:59 -0400110
Rohan Shah524cf7b2018-03-15 14:40:02 -0700111/**
112 * Tests for {@link NotificationStackScrollLayout}.
113 */
Selim Cinek8a9308d2017-08-24 09:31:08 -0700114@SmallTest
Ned Burnsd4a69f72019-06-19 19:49:19 -0400115@RunWith(AndroidTestingRunner.class)
116@TestableLooper.RunWithLooper
Selim Cinek8a9308d2017-08-24 09:31:08 -0700117public class NotificationStackScrollLayoutTest extends SysuiTestCase {
118
Will Brockmane718d582019-01-17 16:38:38 -0500119 private NotificationStackScrollLayout mStackScroller; // Normally test this
120 private NotificationStackScrollLayout mStackScrollerInternal; // See explanation below
Rohan Shah524cf7b2018-03-15 14:40:02 -0700121
122 @Rule public MockitoRule mockito = MockitoJUnit.rule();
123 @Mock private StatusBar mBar;
Selim Cinek5454a0d2019-07-30 17:14:50 -0700124 @Mock private SysuiStatusBarStateController mBarState;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700125 @Mock private HeadsUpManagerPhone mHeadsUpManager;
126 @Mock private NotificationBlockingHelperManager mBlockingHelperManager;
127 @Mock private NotificationGroupManager mGroupManager;
128 @Mock private ExpandHelper mExpandHelper;
129 @Mock private EmptyShadeView mEmptyShadeView;
Jason Monke59dc402018-08-16 12:05:01 -0400130 @Mock private NotificationRemoteInputManager mRemoteInputManager;
131 @Mock private RemoteInputController mRemoteInputController;
Lucas Dupinfe218782019-06-11 15:20:32 -0700132 @Mock private NotificationIconAreaController mNotificationIconAreaController;
Will Brockmane718d582019-01-17 16:38:38 -0500133 @Mock private MetricsLogger mMetricsLogger;
Lucas Dupin00be88f2019-01-03 17:50:52 -0800134 @Mock private NotificationRoundnessManager mNotificationRoundnessManager;
Selim Cinekc3fec682019-06-06 18:11:07 -0700135 @Mock private KeyguardBypassController mKeyguardBypassController;
Beverly482ad6a2019-11-06 16:57:05 -0500136 @Mock private ZenModeController mZenModeController;
Dave Mankoff56fe9e42020-01-08 15:42:06 -0500137 @Mock private NotificationSectionsManager mNotificationSectionsManager;
138 @Mock private NotificationSection mNotificationSection;
Lucas Dupin28790c02020-01-30 14:18:41 -0800139 @Mock private NotificationLockscreenUserManager mLockscreenUserManager;
Beverly7e0d6492020-02-07 16:22:14 -0500140 @Mock private FeatureFlags mFeatureFlags;
Lucas Dupin28790c02020-01-30 14:18:41 -0800141 private UserChangedListener mUserChangedListener;
Kevin Hanbd142932020-03-10 18:27:50 -0700142 private NotificationEntryManager mEntryManager;
Gus Prevase2d6f042018-10-17 15:25:30 -0400143 private int mOriginalInterruptionModelSetting;
Will Brockmanb65faa82020-03-06 10:26:04 -0500144 private UiEventLoggerFake mUiEventLoggerFake = new UiEventLoggerFake();
Selim Cinek8a9308d2017-08-24 09:31:08 -0700145
Will Brockmane718d582019-01-17 16:38:38 -0500146
Selim Cinek8a9308d2017-08-24 09:31:08 -0700147 @Before
148 @UiThreadTest
149 public void setUp() throws Exception {
Beverly1467c9e2020-02-18 13:31:29 -0500150 allowTestableLooperAsMainThread();
Ned Burnsd4a69f72019-06-19 19:49:19 -0400151
Ned Burns9eb06332019-04-23 16:02:12 -0400152 mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(),
153 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
154 Settings.Secure.putInt(mContext.getContentResolver(),
155 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
Julia Reynolds1f94a9d2020-05-05 12:40:21 -0400156 Settings.Secure.putIntForUser(mContext.getContentResolver(), NOTIFICATION_HISTORY_ENABLED,
157 1, UserHandle.USER_CURRENT);
Ned Burns9eb06332019-04-23 16:02:12 -0400158
Rohan Shah524cf7b2018-03-15 14:40:02 -0700159 // Inject dependencies before initializing the layout
Evan Laird181de622019-10-24 09:53:02 -0400160 mDependency.injectMockDependency(VisualStabilityManager.class);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700161 mDependency.injectTestDependency(
162 NotificationBlockingHelperManager.class,
163 mBlockingHelperManager);
Selim Cinekeec58842019-08-02 09:35:28 -0700164 mDependency.injectTestDependency(SysuiStatusBarStateController.class, mBarState);
Will Brockmane718d582019-01-17 16:38:38 -0500165 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Jason Monke59dc402018-08-16 12:05:01 -0400166 mDependency.injectTestDependency(NotificationRemoteInputManager.class,
167 mRemoteInputManager);
Jason Monk297c04e2018-08-23 17:16:59 -0400168 mDependency.injectMockDependency(ShadeController.class);
Jason Monke59dc402018-08-16 12:05:01 -0400169 when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
170
Lucas Dupin28790c02020-01-30 14:18:41 -0800171 ArgumentCaptor<UserChangedListener> userChangedCaptor = ArgumentCaptor
172 .forClass(UserChangedListener.class);
Kevin Hanbd142932020-03-10 18:27:50 -0700173 mEntryManager = new NotificationEntryManager(
Ned Burnsafe77bc2020-01-30 20:45:07 -0500174 mock(NotificationEntryManagerLogger.class),
Evan Laird181de622019-10-24 09:53:02 -0400175 mock(NotificationGroupManager.class),
176 new NotificationRankingManager(
177 () -> mock(NotificationMediaManager.class),
178 mGroupManager,
179 mHeadsUpManager,
180 mock(NotificationFilter.class),
Ned Burnsafe77bc2020-01-30 20:45:07 -0500181 mock(NotificationEntryManagerLogger.class),
Steve Elliott960f4ce2019-12-04 15:13:52 -0500182 mock(NotificationSectionsFeatureManager.class),
Beverlye558f1d2020-01-07 16:28:58 -0500183 mock(PeopleNotificationIdentifier.class),
184 mock(HighPriorityProvider.class)
Evan Laird181de622019-10-24 09:53:02 -0400185 ),
Beverly8b493df2019-12-18 14:16:50 -0500186 mock(NotificationEntryManager.KeyguardEnvironment.class),
Dave Mankoff02dcaf52020-01-08 15:42:06 -0500187 mock(FeatureFlags.class),
188 () -> mock(NotificationRowBinder.class),
189 () -> mRemoteInputManager,
Evan Laird04373662020-01-24 17:37:39 -0500190 mock(LeakDetector.class),
191 mock(ForegroundServiceDismissalFeatureController.class)
192 );
Kevin Hanbd142932020-03-10 18:27:50 -0700193 mEntryManager.setUpWithPresenter(mock(NotificationPresenter.class));
Beverly7e0d6492020-02-07 16:22:14 -0500194 when(mFeatureFlags.isNewNotifPipelineRenderingEnabled()).thenReturn(false);
Jason Monk297c04e2018-08-23 17:16:59 -0400195
196 NotificationShelf notificationShelf = mock(NotificationShelf.class);
Dave Mankoff56fe9e42020-01-08 15:42:06 -0500197 when(mNotificationSectionsManager.createSectionsForBuckets()).thenReturn(
198 new NotificationSection[]{
199 mNotificationSection
200 });
Will Brockmane718d582019-01-17 16:38:38 -0500201 // The actual class under test. You may need to work with this class directly when
202 // testing anonymous class members of mStackScroller, like mMenuEventListener,
203 // which refer to members of NotificationStackScrollLayout. The spy
Evan Laird181de622019-10-24 09:53:02 -0400204 // holds a copy of the CUT's instances of these KeyguardBypassController, so they still
205 // refer to the CUT's member variables, not the spy's member variables.
Will Brockmane718d582019-01-17 16:38:38 -0500206 mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null,
Selim Cinek34518f62019-02-28 19:41:18 -0800207 true /* allowLongPress */, mNotificationRoundnessManager,
Ned Burns9eb06332019-04-23 16:02:12 -0400208 mock(DynamicPrivacyController.class),
Selim Cinekeec58842019-08-02 09:35:28 -0700209 mock(SysuiStatusBarStateController.class),
Selim Cinekc3fec682019-06-06 18:11:07 -0700210 mHeadsUpManager,
Dave Mankoffc195ea82019-06-28 16:33:25 -0400211 mKeyguardBypassController,
Evan Laird367b6142019-08-30 14:40:34 -0400212 new FalsingManagerFake(),
Lucas Dupin28790c02020-01-30 14:18:41 -0800213 mLockscreenUserManager,
Lucas Dupind236ee32019-10-08 15:33:59 -0700214 mock(NotificationGutsManager.class),
Dave Mankoff56fe9e42020-01-08 15:42:06 -0500215 mZenModeController,
Evan Laird04373662020-01-24 17:37:39 -0500216 mNotificationSectionsManager,
217 mock(ForegroundServiceSectionController.class),
Beverly7e0d6492020-02-07 16:22:14 -0500218 mock(ForegroundServiceDismissalFeatureController.class),
219 mFeatureFlags,
220 mock(NotifPipeline.class),
221 mEntryManager,
Will Brockmanb65faa82020-03-06 10:26:04 -0500222 mock(NotifCollection.class),
223 mUiEventLoggerFake
Evan Laird04373662020-01-24 17:37:39 -0500224 );
Lucas Dupin28790c02020-01-30 14:18:41 -0800225 verify(mLockscreenUserManager).addUserChangedListener(userChangedCaptor.capture());
226 mUserChangedListener = userChangedCaptor.getValue();
Will Brockmane718d582019-01-17 16:38:38 -0500227 mStackScroller = spy(mStackScrollerInternal);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700228 mStackScroller.setShelf(notificationShelf);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700229 mStackScroller.setStatusBar(mBar);
230 mStackScroller.setScrimController(mock(ScrimController.class));
Rohan Shah524cf7b2018-03-15 14:40:02 -0700231 mStackScroller.setGroupManager(mGroupManager);
232 mStackScroller.setEmptyShadeView(mEmptyShadeView);
Lucas Dupinfe218782019-06-11 15:20:32 -0700233 mStackScroller.setIconAreaController(mNotificationIconAreaController);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700234
235 // Stub out functionality that isn't necessary to test.
236 doNothing().when(mBar)
237 .executeRunnableDismissingKeyguard(any(Runnable.class),
238 any(Runnable.class),
239 anyBoolean(),
240 anyBoolean(),
241 anyBoolean());
242 doNothing().when(mGroupManager).collapseAllGroups();
243 doNothing().when(mExpandHelper).cancelImmediately();
244 doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean());
Gus Prevase2d6f042018-10-17 15:25:30 -0400245 }
246
247 @After
248 public void tearDown() {
249 Settings.Secure.putInt(mContext.getContentResolver(),
250 NOTIFICATION_NEW_INTERRUPTION_MODEL, mOriginalInterruptionModelSetting);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700251 }
252
253 @Test
254 public void testNotDimmedOnKeyguard() {
Jason Monk1fd3fc32018-08-14 17:20:09 -0400255 when(mBarState.getState()).thenReturn(StatusBarState.SHADE);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700256 mStackScroller.setDimmed(true /* dimmed */, false /* animate */);
257 mStackScroller.setDimmed(true /* dimmed */, true /* animate */);
Jason Monk297c04e2018-08-23 17:16:59 -0400258 assertFalse(mStackScroller.isDimmed());
Selim Cinek8a9308d2017-08-24 09:31:08 -0700259 }
260
Lucas Dupin0cd882f2018-01-30 12:19:49 -0800261 @Test
Julia Reynolds34f14962018-05-03 12:40:20 +0000262 public void updateEmptyView_dndSuppressing() {
263 when(mEmptyShadeView.willBeGone()).thenReturn(true);
Beverly482ad6a2019-11-06 16:57:05 -0500264 when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(true);
Julia Reynolds34f14962018-05-03 12:40:20 +0000265
266 mStackScroller.updateEmptyShadeView(true);
267
268 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
269 }
270
271 @Test
272 public void updateEmptyView_dndNotSuppressing() {
273 mStackScroller.setEmptyShadeView(mEmptyShadeView);
274 when(mEmptyShadeView.willBeGone()).thenReturn(true);
Beverly482ad6a2019-11-06 16:57:05 -0500275 when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false);
Julia Reynolds34f14962018-05-03 12:40:20 +0000276
277 mStackScroller.updateEmptyShadeView(true);
278
279 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
280 }
281
282 @Test
283 public void updateEmptyView_noNotificationsToDndSuppressing() {
284 mStackScroller.setEmptyShadeView(mEmptyShadeView);
285 when(mEmptyShadeView.willBeGone()).thenReturn(true);
Beverly482ad6a2019-11-06 16:57:05 -0500286 when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false);
Julia Reynolds34f14962018-05-03 12:40:20 +0000287 mStackScroller.updateEmptyShadeView(true);
288 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
289
Beverly482ad6a2019-11-06 16:57:05 -0500290 when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(true);
Julia Reynolds34f14962018-05-03 12:40:20 +0000291 mStackScroller.updateEmptyShadeView(true);
292 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
293 }
294
295 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700296 @UiThreadTest
297 public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() {
298 mStackScroller.setExpandedHeight(0f);
299 verify(mBlockingHelperManager).setNotificationShadeExpanded(0f);
300 reset(mBlockingHelperManager);
301
302 mStackScroller.setExpandedHeight(100f);
303 verify(mBlockingHelperManager).setNotificationShadeExpanded(100f);
Julia Reynolds9cf17562018-03-14 09:49:35 -0400304 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400305
306 @Test
Lucas Dupin28790c02020-01-30 14:18:41 -0800307 public void testOnStatePostChange_verifyIfProfileIsPublic() {
308 mUserChangedListener.onUserChanged(0);
309 verify(mLockscreenUserManager).isAnyProfilePublicMode();
310 }
311
312 @Test
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400313 public void manageNotifications_visible() {
314 FooterView view = mock(FooterView.class);
315 mStackScroller.setFooterView(view);
316 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400317
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400318 mStackScroller.updateFooterView(true, false, true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400319
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700320 verify(view).setVisible(eq(true), anyBoolean());
321 verify(view).setSecondaryVisible(eq(false), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400322 }
323
324 @Test
325 public void clearAll_visible() {
326 FooterView view = mock(FooterView.class);
327 mStackScroller.setFooterView(view);
328 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400329
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400330 mStackScroller.updateFooterView(true, true, true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400331
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700332 verify(view).setVisible(eq(true), anyBoolean());
333 verify(view).setSecondaryVisible(eq(true), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400334 }
Jason Monke59dc402018-08-16 12:05:01 -0400335
336 @Test
337 public void testInflateFooterView() {
338 mStackScroller.inflateFooterView();
339 ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class);
340 verify(mStackScroller).setFooterView(captor.capture());
341
342 assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners());
343 assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners());
344 }
345
346 @Test
347 public void testUpdateFooter_noNotifications() {
348 setBarStateForTest(StatusBarState.SHADE);
Evan Laird181de622019-10-24 09:53:02 -0400349 assertEquals(0, mEntryManager.getActiveNotificationsCount());
Jason Monke59dc402018-08-16 12:05:01 -0400350
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400351 FooterView view = mock(FooterView.class);
352 mStackScroller.setFooterView(view);
Jason Monke59dc402018-08-16 12:05:01 -0400353 mStackScroller.updateFooter();
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400354 verify(mStackScroller, atLeastOnce()).updateFooterView(false, false, true);
Jason Monke59dc402018-08-16 12:05:01 -0400355 }
356
357 @Test
358 public void testUpdateFooter_remoteInput() {
359 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500360 ArrayList<NotificationEntry> entries = new ArrayList<>();
Evan Laird181de622019-10-24 09:53:02 -0400361 entries.add(new NotificationEntryBuilder().build());
362 addEntriesToEntryManager(entries);
Jason Monke59dc402018-08-16 12:05:01 -0400363
364 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
365 when(row.canViewBeDismissed()).thenReturn(true);
366 when(mStackScroller.getChildCount()).thenReturn(1);
367 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
368 when(mRemoteInputController.isRemoteInputActive()).thenReturn(true);
369
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400370 FooterView view = mock(FooterView.class);
371 mStackScroller.setFooterView(view);
Jason Monke59dc402018-08-16 12:05:01 -0400372 mStackScroller.updateFooter();
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400373 verify(mStackScroller).updateFooterView(false, true, true);
Jason Monke59dc402018-08-16 12:05:01 -0400374 }
375
376 @Test
377 public void testUpdateFooter_oneClearableNotification() {
378 setBarStateForTest(StatusBarState.SHADE);
Evan Laird181de622019-10-24 09:53:02 -0400379
Ned Burnsf81c4c42019-01-07 14:10:43 -0500380 ArrayList<NotificationEntry> entries = new ArrayList<>();
Evan Laird181de622019-10-24 09:53:02 -0400381 entries.add(new NotificationEntryBuilder().build());
382 addEntriesToEntryManager(entries);
Jason Monke59dc402018-08-16 12:05:01 -0400383
384 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
385 when(row.canViewBeDismissed()).thenReturn(true);
386 when(mStackScroller.getChildCount()).thenReturn(1);
387 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
388
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400389 FooterView view = mock(FooterView.class);
390 mStackScroller.setFooterView(view);
Jason Monke59dc402018-08-16 12:05:01 -0400391 mStackScroller.updateFooter();
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400392 verify(mStackScroller).updateFooterView(true, true, true);
Jason Monke59dc402018-08-16 12:05:01 -0400393 }
394
395 @Test
396 public void testUpdateFooter_oneNonClearableNotification() {
397 setBarStateForTest(StatusBarState.SHADE);
Evan Laird181de622019-10-24 09:53:02 -0400398
Ned Burnsf81c4c42019-01-07 14:10:43 -0500399 ArrayList<NotificationEntry> entries = new ArrayList<>();
Evan Laird181de622019-10-24 09:53:02 -0400400 entries.add(new NotificationEntryBuilder().build());
401 addEntriesToEntryManager(entries);
Jason Monke59dc402018-08-16 12:05:01 -0400402
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400403 FooterView view = mock(FooterView.class);
404 mStackScroller.setFooterView(view);
Jason Monke59dc402018-08-16 12:05:01 -0400405 mStackScroller.updateFooter();
Julia Reynoldsda7c2452020-04-16 16:44:58 -0400406 verify(mStackScroller).updateFooterView(true, false, true);
Jason Monke59dc402018-08-16 12:05:01 -0400407 }
408
409 @Test
410 public void testUpdateFooter_atEnd() {
411 // add footer
412 mStackScroller.inflateFooterView();
413
414 // add notification
415 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500416 NotificationEntry entry = mock(NotificationEntry.class);
Evan Laird94492852018-10-25 13:43:01 -0400417 when(row.getEntry()).thenReturn(entry);
418 when(entry.isClearable()).thenReturn(true);
Jason Monke59dc402018-08-16 12:05:01 -0400419 mStackScroller.addContainerView(row);
420
421 mStackScroller.onUpdateRowStates();
422
Evan Laird04373662020-01-24 17:37:39 -0500423 // Expecting the footer to be the last child
424 int expected = mStackScroller.getChildCount() - 1;
425
Jason Monke59dc402018-08-16 12:05:01 -0400426 // move footer to end
Evan Laird04373662020-01-24 17:37:39 -0500427 verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(expected));
Jason Monke59dc402018-08-16 12:05:01 -0400428 }
429
430 @Test
431 public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() {
432 clearInvocations(mStackScroller);
433 mStackScroller.onDensityOrFontScaleChanged();
434 verify(mStackScroller).setFooterView(any());
435 verify(mStackScroller).setEmptyShadeView(any());
436 }
437
Gus Prevas99ba4ba2018-10-01 16:40:23 -0400438 @Test
439 @UiThreadTest
440 public void testSetIsBeingDraggedResetsExposedMenu() {
441 NotificationSwipeHelper swipeActionHelper =
442 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
443 swipeActionHelper.setExposedMenuView(new View(mContext));
444 mStackScroller.setIsBeingDragged(true);
445 assertNull(swipeActionHelper.getExposedMenuView());
446 }
447
448 @Test
449 @UiThreadTest
450 public void testPanelTrackingStartResetsExposedMenu() {
451 NotificationSwipeHelper swipeActionHelper =
452 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
453 swipeActionHelper.setExposedMenuView(new View(mContext));
454 mStackScroller.onPanelTrackingStarted();
455 assertNull(swipeActionHelper.getExposedMenuView());
456 }
457
458 @Test
459 @UiThreadTest
460 public void testDarkModeResetsExposedMenu() {
461 NotificationSwipeHelper swipeActionHelper =
462 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
463 swipeActionHelper.setExposedMenuView(new View(mContext));
Selim Cinek195dfc52019-05-30 19:35:05 -0700464 mStackScroller.setHideAmount(0.1f, 0.1f);
Gus Prevas99ba4ba2018-10-01 16:40:23 -0400465 assertNull(swipeActionHelper.getExposedMenuView());
466 }
467
Will Brockmane718d582019-01-17 16:38:38 -0500468 class LogMatcher implements ArgumentMatcher<LogMaker> {
469 private int mCategory, mType;
470
471 LogMatcher(int category, int type) {
472 mCategory = category;
473 mType = type;
474 }
475 public boolean matches(LogMaker l) {
476 return (l.getCategory() == mCategory)
477 && (l.getType() == mType);
478 }
479
480 public String toString() {
481 return String.format("LogMaker(%d, %d)", mCategory, mType);
482 }
483 }
484
485 private LogMaker logMatcher(int category, int type) {
486 return argThat(new LogMatcher(category, type));
487 }
488
489 @Test
490 @UiThreadTest
491 public void testOnMenuClickedLogging() {
492 // Set up the object under test to have a valid mLongPressListener. We're testing an
493 // anonymous-class member, mMenuEventListener, so we need to modify the state of the
494 // class itself, not the Mockito spy copied from it. See notes in setup.
495 mStackScrollerInternal.setLongPressListener(
496 mock(ExpandableNotificationRow.LongPressListener.class));
497
498 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500499 when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker(
Will Brockmane718d582019-01-17 16:38:38 -0500500 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
501
502 mStackScroller.mMenuEventListener.onMenuClicked(row, 0, 0, mock(
503 NotificationMenuRowPlugin.MenuItem.class));
Ned Burns1c2b85a42019-11-14 15:37:03 -0500504 verify(row.getEntry().getSbn()).getLogMaker(); // This writes most of the log data
Will Brockmane718d582019-01-17 16:38:38 -0500505 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_TOUCH_GEAR,
506 MetricsProto.MetricsEvent.TYPE_ACTION));
507 }
508
509 @Test
510 @UiThreadTest
Selim Cinekc3fec682019-06-06 18:11:07 -0700511 public void testOnMenuShownLogging() { ;
Will Brockmane718d582019-01-17 16:38:38 -0500512
513 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500514 when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker(
Will Brockmane718d582019-01-17 16:38:38 -0500515 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
516
517 mStackScroller.mMenuEventListener.onMenuShown(row);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500518 verify(row.getEntry().getSbn()).getLogMaker(); // This writes most of the log data
Will Brockmane718d582019-01-17 16:38:38 -0500519 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_REVEAL_GEAR,
520 MetricsProto.MetricsEvent.TYPE_ACTION));
521 }
522
Will Brockmanb65faa82020-03-06 10:26:04 -0500523 @Test
524 public void testClearNotifications_All() {
525 mStackScroller.clearNotifications(NotificationStackScrollLayout.ROWS_ALL, true);
526 assertEquals(1, mUiEventLoggerFake.numLogs());
527 assertEquals(NotificationStackScrollLayout.NotificationPanelEvent
528 .DISMISS_ALL_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0));
529 }
530
531 @Test
532 public void testClearNotifications_Gentle() {
533 mStackScroller.clearNotifications(NotificationStackScrollLayout.ROWS_GENTLE, false);
534 assertEquals(1, mUiEventLoggerFake.numLogs());
535 assertEquals(NotificationStackScrollLayout.NotificationPanelEvent
536 .DISMISS_SILENT_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0));
537 }
538
Jason Monke59dc402018-08-16 12:05:01 -0400539 private void setBarStateForTest(int state) {
Jason Monk297c04e2018-08-23 17:16:59 -0400540 // Can't inject this through the listener or we end up on the actual implementation
541 // rather than the mock because the spy just coppied the anonymous inner /shruggie.
542 mStackScroller.setStatusBarState(state);
Jason Monke59dc402018-08-16 12:05:01 -0400543 }
Evan Laird181de622019-10-24 09:53:02 -0400544
545 private void addEntriesToEntryManager(List<NotificationEntry> entries) {
546 for (NotificationEntry e : entries) {
547 mEntryManager.addActiveNotificationForTest(e);
548 }
549 }
Selim Cinek8a9308d2017-08-24 09:31:08 -0700550}