blob: ff835871d82228e0bff52c74e11a252be16d6ef2 [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
Gus Prevase2d6f042018-10-17 15:25:30 -040016import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
17
Jason Monke59dc402018-08-16 12:05:01 -040018import static junit.framework.Assert.assertEquals;
19import static junit.framework.Assert.assertNotNull;
Gus Prevas99ba4ba2018-10-01 16:40:23 -040020import static junit.framework.Assert.assertNull;
21
Jason Monk297c04e2018-08-23 17:16:59 -040022import static org.junit.Assert.assertFalse;
23import static org.junit.Assert.assertTrue;
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;
Gus Prevase2d6f042018-10-17 15:25:30 -040040import android.provider.Settings;
Ned Burnsd4a69f72019-06-19 19:49:19 -040041import android.testing.AndroidTestingRunner;
42import android.testing.TestableLooper;
Gus Prevas99ba4ba2018-10-01 16:40:23 -040043import android.view.View;
Selim Cinek8a9308d2017-08-24 09:31:08 -070044
Brett Chabot84151d92019-02-27 15:37:59 -080045import androidx.test.annotation.UiThreadTest;
46import androidx.test.filters.SmallTest;
Brett Chabot84151d92019-02-27 15:37:59 -080047
Will Brockmane718d582019-01-17 16:38:38 -050048import com.android.internal.logging.MetricsLogger;
49import com.android.internal.logging.nano.MetricsProto;
Ned Burns9eb06332019-04-23 16:02:12 -040050import com.android.systemui.ActivityStarterDelegate;
Jason Monk297c04e2018-08-23 17:16:59 -040051import com.android.systemui.Dependency;
Rohan Shah524cf7b2018-03-15 14:40:02 -070052import com.android.systemui.ExpandHelper;
Jason Monk297c04e2018-08-23 17:16:59 -040053import com.android.systemui.InitController;
Julia Reynolds9cf17562018-03-14 09:49:35 -040054import com.android.systemui.R;
Selim Cinek8a9308d2017-08-24 09:31:08 -070055import com.android.systemui.SysuiTestCase;
Will Brockmane718d582019-01-17 16:38:38 -050056import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
Beverly8fdb5332019-02-04 14:29:49 -050057import com.android.systemui.plugins.statusbar.StatusBarStateController;
Selim Cinek34518f62019-02-28 19:41:18 -080058import com.android.systemui.statusbar.AmbientPulseManager;
Julia Reynolds9cf17562018-03-14 09:49:35 -040059import com.android.systemui.statusbar.EmptyShadeView;
Jason Monke59dc402018-08-16 12:05:01 -040060import com.android.systemui.statusbar.NotificationPresenter;
Jason Monk297c04e2018-08-23 17:16:59 -040061import com.android.systemui.statusbar.NotificationRemoteInputManager;
62import com.android.systemui.statusbar.NotificationShelf;
63import com.android.systemui.statusbar.RemoteInputController;
64import com.android.systemui.statusbar.StatusBarState;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070065import com.android.systemui.statusbar.notification.DynamicPrivacyController;
Jason Monke59dc402018-08-16 12:05:01 -040066import com.android.systemui.statusbar.notification.NotificationEntryManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050067import com.android.systemui.statusbar.notification.collection.NotificationData;
68import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Jason Monke59dc402018-08-16 12:05:01 -040069import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070070import com.android.systemui.statusbar.notification.row.FooterView;
71import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
Rohan Shah524cf7b2018-03-15 14:40:02 -070072import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
73import com.android.systemui.statusbar.phone.NotificationGroupManager;
Lucas Dupinfe218782019-06-11 15:20:32 -070074import com.android.systemui.statusbar.phone.NotificationIconAreaController;
Selim Cinek8a9308d2017-08-24 09:31:08 -070075import com.android.systemui.statusbar.phone.ScrimController;
Jason Monk297c04e2018-08-23 17:16:59 -040076import com.android.systemui.statusbar.phone.ShadeController;
Selim Cinek8a9308d2017-08-24 09:31:08 -070077import com.android.systemui.statusbar.phone.StatusBar;
Jason Monke59dc402018-08-16 12:05:01 -040078import com.android.systemui.statusbar.phone.StatusBarTest.TestableNotificationEntryManager;
Ned Burns2c74c2a2019-06-13 19:06:47 -040079import com.android.systemui.statusbar.policy.ConfigurationController;
Jason Monke59dc402018-08-16 12:05:01 -040080
Gus Prevase2d6f042018-10-17 15:25:30 -040081import org.junit.After;
Selim Cinek8a9308d2017-08-24 09:31:08 -070082import org.junit.Assert;
83import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070084import org.junit.Rule;
Selim Cinek8a9308d2017-08-24 09:31:08 -070085import org.junit.Test;
86import org.junit.runner.RunWith;
Jason Monke59dc402018-08-16 12:05:01 -040087import org.mockito.ArgumentCaptor;
Will Brockmane718d582019-01-17 16:38:38 -050088import org.mockito.ArgumentMatcher;
Rohan Shah524cf7b2018-03-15 14:40:02 -070089import org.mockito.Mock;
90import org.mockito.junit.MockitoJUnit;
91import org.mockito.junit.MockitoRule;
Selim Cinek8a9308d2017-08-24 09:31:08 -070092
Jason Monk297c04e2018-08-23 17:16:59 -040093import java.util.ArrayList;
94
Rohan Shah524cf7b2018-03-15 14:40:02 -070095/**
96 * Tests for {@link NotificationStackScrollLayout}.
97 */
Selim Cinek8a9308d2017-08-24 09:31:08 -070098@SmallTest
Ned Burnsd4a69f72019-06-19 19:49:19 -040099@RunWith(AndroidTestingRunner.class)
100@TestableLooper.RunWithLooper
Selim Cinek8a9308d2017-08-24 09:31:08 -0700101public class NotificationStackScrollLayoutTest extends SysuiTestCase {
102
Will Brockmane718d582019-01-17 16:38:38 -0500103 private NotificationStackScrollLayout mStackScroller; // Normally test this
104 private NotificationStackScrollLayout mStackScrollerInternal; // See explanation below
Rohan Shah524cf7b2018-03-15 14:40:02 -0700105
106 @Rule public MockitoRule mockito = MockitoJUnit.rule();
107 @Mock private StatusBar mBar;
Jason Monk1fd3fc32018-08-14 17:20:09 -0400108 @Mock private StatusBarStateController mBarState;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700109 @Mock private HeadsUpManagerPhone mHeadsUpManager;
110 @Mock private NotificationBlockingHelperManager mBlockingHelperManager;
111 @Mock private NotificationGroupManager mGroupManager;
112 @Mock private ExpandHelper mExpandHelper;
113 @Mock private EmptyShadeView mEmptyShadeView;
Jason Monke59dc402018-08-16 12:05:01 -0400114 @Mock private NotificationData mNotificationData;
115 @Mock private NotificationRemoteInputManager mRemoteInputManager;
116 @Mock private RemoteInputController mRemoteInputController;
Lucas Dupinfe218782019-06-11 15:20:32 -0700117 @Mock private NotificationIconAreaController mNotificationIconAreaController;
Will Brockmane718d582019-01-17 16:38:38 -0500118 @Mock private MetricsLogger mMetricsLogger;
Lucas Dupin00be88f2019-01-03 17:50:52 -0800119 @Mock private NotificationRoundnessManager mNotificationRoundnessManager;
Jason Monke59dc402018-08-16 12:05:01 -0400120 private TestableNotificationEntryManager mEntryManager;
Gus Prevase2d6f042018-10-17 15:25:30 -0400121 private int mOriginalInterruptionModelSetting;
Selim Cinek8a9308d2017-08-24 09:31:08 -0700122
Will Brockmane718d582019-01-17 16:38:38 -0500123
Selim Cinek8a9308d2017-08-24 09:31:08 -0700124 @Before
125 @UiThreadTest
126 public void setUp() throws Exception {
Ned Burnsd4a69f72019-06-19 19:49:19 -0400127 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
128
Ned Burns9eb06332019-04-23 16:02:12 -0400129 mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(),
130 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
131 Settings.Secure.putInt(mContext.getContentResolver(),
132 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
133
Rohan Shah524cf7b2018-03-15 14:40:02 -0700134 // Inject dependencies before initializing the layout
135 mDependency.injectTestDependency(
136 NotificationBlockingHelperManager.class,
137 mBlockingHelperManager);
Jason Monk1fd3fc32018-08-14 17:20:09 -0400138 mDependency.injectTestDependency(StatusBarStateController.class, mBarState);
Will Brockmane718d582019-01-17 16:38:38 -0500139 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Jason Monke59dc402018-08-16 12:05:01 -0400140 mDependency.injectTestDependency(NotificationRemoteInputManager.class,
141 mRemoteInputManager);
Jason Monk297c04e2018-08-23 17:16:59 -0400142 mDependency.injectMockDependency(ShadeController.class);
Jason Monke59dc402018-08-16 12:05:01 -0400143 when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
144
Gus Prevas92586462019-01-04 16:06:12 -0500145 mEntryManager = new TestableNotificationEntryManager(mContext);
Jason Monk297c04e2018-08-23 17:16:59 -0400146 mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
147 Dependency.get(InitController.class).executePostInitTasks();
Gus Prevas8621bd22018-12-20 15:04:25 -0500148 mEntryManager.setUpForTest(mock(NotificationPresenter.class), null, mHeadsUpManager,
Kevina5ff1fa2018-08-21 16:35:48 -0700149 mNotificationData);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700150
Jason Monk297c04e2018-08-23 17:16:59 -0400151
152 NotificationShelf notificationShelf = mock(NotificationShelf.class);
Will Brockmane718d582019-01-17 16:38:38 -0500153
154 // The actual class under test. You may need to work with this class directly when
155 // testing anonymous class members of mStackScroller, like mMenuEventListener,
156 // which refer to members of NotificationStackScrollLayout. The spy
157 // holds a copy of the CUT's instances of these classes, so they still refer to the CUT's
158 // member variables, not the spy's member variables.
159 mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null,
Selim Cinek34518f62019-02-28 19:41:18 -0800160 true /* allowLongPress */, mNotificationRoundnessManager,
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700161 new AmbientPulseManager(mContext),
Ned Burns9eb06332019-04-23 16:02:12 -0400162 mock(DynamicPrivacyController.class),
Ned Burns2c74c2a2019-06-13 19:06:47 -0400163 mock(ConfigurationController.class),
Ned Burns7eeccdd2019-05-15 14:50:11 -0400164 mock(ActivityStarterDelegate.class),
165 mock(StatusBarStateController.class));
Will Brockmane718d582019-01-17 16:38:38 -0500166 mStackScroller = spy(mStackScrollerInternal);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700167 mStackScroller.setShelf(notificationShelf);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700168 mStackScroller.setStatusBar(mBar);
169 mStackScroller.setScrimController(mock(ScrimController.class));
Rohan Shah524cf7b2018-03-15 14:40:02 -0700170 mStackScroller.setHeadsUpManager(mHeadsUpManager);
171 mStackScroller.setGroupManager(mGroupManager);
172 mStackScroller.setEmptyShadeView(mEmptyShadeView);
Lucas Dupinfe218782019-06-11 15:20:32 -0700173 mStackScroller.setIconAreaController(mNotificationIconAreaController);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700174
175 // Stub out functionality that isn't necessary to test.
176 doNothing().when(mBar)
177 .executeRunnableDismissingKeyguard(any(Runnable.class),
178 any(Runnable.class),
179 anyBoolean(),
180 anyBoolean(),
181 anyBoolean());
182 doNothing().when(mGroupManager).collapseAllGroups();
183 doNothing().when(mExpandHelper).cancelImmediately();
184 doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean());
Lucas Dupin7fc9dc12019-01-03 09:19:43 -0800185 doNothing().when(notificationShelf).fadeInTranslating();
Gus Prevase2d6f042018-10-17 15:25:30 -0400186 }
187
188 @After
189 public void tearDown() {
190 Settings.Secure.putInt(mContext.getContentResolver(),
191 NOTIFICATION_NEW_INTERRUPTION_MODEL, mOriginalInterruptionModelSetting);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700192 }
193
194 @Test
195 public void testNotDimmedOnKeyguard() {
Jason Monk1fd3fc32018-08-14 17:20:09 -0400196 when(mBarState.getState()).thenReturn(StatusBarState.SHADE);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700197 mStackScroller.setDimmed(true /* dimmed */, false /* animate */);
198 mStackScroller.setDimmed(true /* dimmed */, true /* animate */);
Jason Monk297c04e2018-08-23 17:16:59 -0400199 assertFalse(mStackScroller.isDimmed());
Selim Cinek8a9308d2017-08-24 09:31:08 -0700200 }
201
Lucas Dupin0cd882f2018-01-30 12:19:49 -0800202 @Test
203 public void testAntiBurnInOffset() {
204 final int burnInOffset = 30;
205 mStackScroller.setAntiBurnInOffsetX(burnInOffset);
206 mStackScroller.setDark(false /* dark */, false /* animated */, null /* touch */);
207 Assert.assertEquals(0 /* expected */, mStackScroller.getTranslationX(), 0.01 /* delta */);
208 mStackScroller.setDark(true /* dark */, false /* animated */, null /* touch */);
209 Assert.assertEquals(burnInOffset /* expected */, mStackScroller.getTranslationX(),
210 0.01 /* delta */);
211 }
212
Julia Reynolds9cf17562018-03-14 09:49:35 -0400213 @Test
Julia Reynolds34f14962018-05-03 12:40:20 +0000214 public void updateEmptyView_dndSuppressing() {
215 when(mEmptyShadeView.willBeGone()).thenReturn(true);
216 when(mBar.areNotificationsHidden()).thenReturn(true);
217
218 mStackScroller.updateEmptyShadeView(true);
219
220 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
221 }
222
223 @Test
224 public void updateEmptyView_dndNotSuppressing() {
225 mStackScroller.setEmptyShadeView(mEmptyShadeView);
226 when(mEmptyShadeView.willBeGone()).thenReturn(true);
227 when(mBar.areNotificationsHidden()).thenReturn(false);
228
229 mStackScroller.updateEmptyShadeView(true);
230
231 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
232 }
233
234 @Test
235 public void updateEmptyView_noNotificationsToDndSuppressing() {
236 mStackScroller.setEmptyShadeView(mEmptyShadeView);
237 when(mEmptyShadeView.willBeGone()).thenReturn(true);
238 when(mBar.areNotificationsHidden()).thenReturn(false);
239 mStackScroller.updateEmptyShadeView(true);
240 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
241
242 when(mBar.areNotificationsHidden()).thenReturn(true);
243 mStackScroller.updateEmptyShadeView(true);
244 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
245 }
246
247 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700248 @UiThreadTest
249 public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() {
250 mStackScroller.setExpandedHeight(0f);
251 verify(mBlockingHelperManager).setNotificationShadeExpanded(0f);
252 reset(mBlockingHelperManager);
253
254 mStackScroller.setExpandedHeight(100f);
255 verify(mBlockingHelperManager).setNotificationShadeExpanded(100f);
Julia Reynolds9cf17562018-03-14 09:49:35 -0400256 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400257
258 @Test
259 public void manageNotifications_visible() {
260 FooterView view = mock(FooterView.class);
261 mStackScroller.setFooterView(view);
262 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400263
264 mStackScroller.updateFooterView(true, false);
265
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700266 verify(view).setVisible(eq(true), anyBoolean());
267 verify(view).setSecondaryVisible(eq(false), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400268 }
269
270 @Test
271 public void clearAll_visible() {
272 FooterView view = mock(FooterView.class);
273 mStackScroller.setFooterView(view);
274 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400275
276 mStackScroller.updateFooterView(true, true);
277
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700278 verify(view).setVisible(eq(true), anyBoolean());
279 verify(view).setSecondaryVisible(eq(true), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400280 }
Jason Monke59dc402018-08-16 12:05:01 -0400281
282 @Test
283 public void testInflateFooterView() {
284 mStackScroller.inflateFooterView();
285 ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class);
286 verify(mStackScroller).setFooterView(captor.capture());
287
288 assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners());
289 assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners());
290 }
291
292 @Test
293 public void testUpdateFooter_noNotifications() {
294 setBarStateForTest(StatusBarState.SHADE);
295 assertEquals(0, mNotificationData.getActiveNotifications().size());
296
297 mStackScroller.updateFooter();
Jason Monk297c04e2018-08-23 17:16:59 -0400298 verify(mStackScroller, atLeastOnce()).updateFooterView(false, false);
Jason Monke59dc402018-08-16 12:05:01 -0400299 }
300
301 @Test
302 public void testUpdateFooter_remoteInput() {
303 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500304 ArrayList<NotificationEntry> entries = new ArrayList<>();
305 entries.add(mock(NotificationEntry.class));
Jason Monke59dc402018-08-16 12:05:01 -0400306 when(mNotificationData.getActiveNotifications()).thenReturn(entries);
307
308 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
309 when(row.canViewBeDismissed()).thenReturn(true);
310 when(mStackScroller.getChildCount()).thenReturn(1);
311 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
312 when(mRemoteInputController.isRemoteInputActive()).thenReturn(true);
313
314 mStackScroller.updateFooter();
315 verify(mStackScroller).updateFooterView(false, true);
316 }
317
318 @Test
319 public void testUpdateFooter_oneClearableNotification() {
320 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500321 ArrayList<NotificationEntry> entries = new ArrayList<>();
322 entries.add(mock(NotificationEntry.class));
Jason Monke59dc402018-08-16 12:05:01 -0400323 when(mNotificationData.getActiveNotifications()).thenReturn(entries);
324
325 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
326 when(row.canViewBeDismissed()).thenReturn(true);
327 when(mStackScroller.getChildCount()).thenReturn(1);
328 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
329
330 mStackScroller.updateFooter();
331 verify(mStackScroller).updateFooterView(true, true);
332 }
333
334 @Test
335 public void testUpdateFooter_oneNonClearableNotification() {
336 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500337 ArrayList<NotificationEntry> entries = new ArrayList<>();
338 entries.add(mock(NotificationEntry.class));
Jason Monk297c04e2018-08-23 17:16:59 -0400339 when(mEntryManager.getNotificationData().getActiveNotifications()).thenReturn(entries);
340 assertTrue(mEntryManager.getNotificationData().getActiveNotifications().size() != 0);
Jason Monke59dc402018-08-16 12:05:01 -0400341
342 mStackScroller.updateFooter();
343 verify(mStackScroller).updateFooterView(true, false);
344 }
345
346 @Test
347 public void testUpdateFooter_atEnd() {
348 // add footer
349 mStackScroller.inflateFooterView();
350
351 // add notification
352 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500353 NotificationEntry entry = mock(NotificationEntry.class);
Evan Laird94492852018-10-25 13:43:01 -0400354 when(row.getEntry()).thenReturn(entry);
355 when(entry.isClearable()).thenReturn(true);
Jason Monke59dc402018-08-16 12:05:01 -0400356 mStackScroller.addContainerView(row);
357
358 mStackScroller.onUpdateRowStates();
359
360 // move footer to end
361 verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(-1 /* end */));
362 }
363
364 @Test
365 public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() {
366 clearInvocations(mStackScroller);
367 mStackScroller.onDensityOrFontScaleChanged();
368 verify(mStackScroller).setFooterView(any());
369 verify(mStackScroller).setEmptyShadeView(any());
370 }
371
Gus Prevas99ba4ba2018-10-01 16:40:23 -0400372 @Test
373 @UiThreadTest
374 public void testSetIsBeingDraggedResetsExposedMenu() {
375 NotificationSwipeHelper swipeActionHelper =
376 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
377 swipeActionHelper.setExposedMenuView(new View(mContext));
378 mStackScroller.setIsBeingDragged(true);
379 assertNull(swipeActionHelper.getExposedMenuView());
380 }
381
382 @Test
383 @UiThreadTest
384 public void testPanelTrackingStartResetsExposedMenu() {
385 NotificationSwipeHelper swipeActionHelper =
386 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
387 swipeActionHelper.setExposedMenuView(new View(mContext));
388 mStackScroller.onPanelTrackingStarted();
389 assertNull(swipeActionHelper.getExposedMenuView());
390 }
391
392 @Test
393 @UiThreadTest
394 public void testDarkModeResetsExposedMenu() {
395 NotificationSwipeHelper swipeActionHelper =
396 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
397 swipeActionHelper.setExposedMenuView(new View(mContext));
398 mStackScroller.setDarkAmount(0.1f, 0.1f);
399 assertNull(swipeActionHelper.getExposedMenuView());
400 }
401
Will Brockmane718d582019-01-17 16:38:38 -0500402 class LogMatcher implements ArgumentMatcher<LogMaker> {
403 private int mCategory, mType;
404
405 LogMatcher(int category, int type) {
406 mCategory = category;
407 mType = type;
408 }
409 public boolean matches(LogMaker l) {
410 return (l.getCategory() == mCategory)
411 && (l.getType() == mType);
412 }
413
414 public String toString() {
415 return String.format("LogMaker(%d, %d)", mCategory, mType);
416 }
417 }
418
419 private LogMaker logMatcher(int category, int type) {
420 return argThat(new LogMatcher(category, type));
421 }
422
423 @Test
424 @UiThreadTest
425 public void testOnMenuClickedLogging() {
426 // Set up the object under test to have a valid mLongPressListener. We're testing an
427 // anonymous-class member, mMenuEventListener, so we need to modify the state of the
428 // class itself, not the Mockito spy copied from it. See notes in setup.
429 mStackScrollerInternal.setLongPressListener(
430 mock(ExpandableNotificationRow.LongPressListener.class));
431
432 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
433 when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker(
434 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
435
436 mStackScroller.mMenuEventListener.onMenuClicked(row, 0, 0, mock(
437 NotificationMenuRowPlugin.MenuItem.class));
438 verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data
439 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_TOUCH_GEAR,
440 MetricsProto.MetricsEvent.TYPE_ACTION));
441 }
442
443 @Test
444 @UiThreadTest
445 public void testOnMenuShownLogging() {
446 // Set up the object under test to have a valid mHeadsUpManager. See notes in setup.
447 mStackScrollerInternal.setHeadsUpManager(mHeadsUpManager);
448
449 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
450 when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker(
451 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
452
453 mStackScroller.mMenuEventListener.onMenuShown(row);
454 verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data
455 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_REVEAL_GEAR,
456 MetricsProto.MetricsEvent.TYPE_ACTION));
457 }
458
Jason Monke59dc402018-08-16 12:05:01 -0400459 private void setBarStateForTest(int state) {
Jason Monk297c04e2018-08-23 17:16:59 -0400460 // Can't inject this through the listener or we end up on the actual implementation
461 // rather than the mock because the spy just coppied the anonymous inner /shruggie.
462 mStackScroller.setStatusBarState(state);
Jason Monke59dc402018-08-16 12:05:01 -0400463 }
Selim Cinek8a9308d2017-08-24 09:31:08 -0700464}