blob: 92173ccbad2ee30773c2a7e6edfdbf6bbfa0a6cd [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;
Julia Reynolds9cf17562018-03-14 09:49:35 -040058import com.android.systemui.statusbar.EmptyShadeView;
Jason Monke59dc402018-08-16 12:05:01 -040059import com.android.systemui.statusbar.NotificationPresenter;
Jason Monk297c04e2018-08-23 17:16:59 -040060import com.android.systemui.statusbar.NotificationRemoteInputManager;
61import com.android.systemui.statusbar.NotificationShelf;
62import com.android.systemui.statusbar.RemoteInputController;
63import com.android.systemui.statusbar.StatusBarState;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070064import com.android.systemui.statusbar.notification.DynamicPrivacyController;
Jason Monke59dc402018-08-16 12:05:01 -040065import com.android.systemui.statusbar.notification.NotificationEntryManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050066import com.android.systemui.statusbar.notification.collection.NotificationData;
67import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Jason Monke59dc402018-08-16 12:05:01 -040068import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070069import com.android.systemui.statusbar.notification.row.FooterView;
70import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
Rohan Shah524cf7b2018-03-15 14:40:02 -070071import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
Selim Cinekc3fec682019-06-06 18:11:07 -070072import com.android.systemui.statusbar.phone.KeyguardBypassController;
Rohan Shah524cf7b2018-03-15 14:40:02 -070073import 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;
Selim Cinekc3fec682019-06-06 18:11:07 -0700120 @Mock private KeyguardBypassController mKeyguardBypassController;
Jason Monke59dc402018-08-16 12:05:01 -0400121 private TestableNotificationEntryManager mEntryManager;
Gus Prevase2d6f042018-10-17 15:25:30 -0400122 private int mOriginalInterruptionModelSetting;
Selim Cinek8a9308d2017-08-24 09:31:08 -0700123
Will Brockmane718d582019-01-17 16:38:38 -0500124
Selim Cinek8a9308d2017-08-24 09:31:08 -0700125 @Before
126 @UiThreadTest
127 public void setUp() throws Exception {
Ned Burnsd4a69f72019-06-19 19:49:19 -0400128 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
129
Ned Burns9eb06332019-04-23 16:02:12 -0400130 mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(),
131 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
132 Settings.Secure.putInt(mContext.getContentResolver(),
133 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
134
Rohan Shah524cf7b2018-03-15 14:40:02 -0700135 // Inject dependencies before initializing the layout
136 mDependency.injectTestDependency(
137 NotificationBlockingHelperManager.class,
138 mBlockingHelperManager);
Jason Monk1fd3fc32018-08-14 17:20:09 -0400139 mDependency.injectTestDependency(StatusBarStateController.class, mBarState);
Will Brockmane718d582019-01-17 16:38:38 -0500140 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Jason Monke59dc402018-08-16 12:05:01 -0400141 mDependency.injectTestDependency(NotificationRemoteInputManager.class,
142 mRemoteInputManager);
Jason Monk297c04e2018-08-23 17:16:59 -0400143 mDependency.injectMockDependency(ShadeController.class);
Jason Monke59dc402018-08-16 12:05:01 -0400144 when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
145
Gus Prevas92586462019-01-04 16:06:12 -0500146 mEntryManager = new TestableNotificationEntryManager(mContext);
Jason Monk297c04e2018-08-23 17:16:59 -0400147 mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
148 Dependency.get(InitController.class).executePostInitTasks();
Gus Prevas8621bd22018-12-20 15:04:25 -0500149 mEntryManager.setUpForTest(mock(NotificationPresenter.class), null, mHeadsUpManager,
Kevina5ff1fa2018-08-21 16:35:48 -0700150 mNotificationData);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700151
Jason Monk297c04e2018-08-23 17:16:59 -0400152
153 NotificationShelf notificationShelf = mock(NotificationShelf.class);
Will Brockmane718d582019-01-17 16:38:38 -0500154
155 // The actual class under test. You may need to work with this class directly when
156 // testing anonymous class members of mStackScroller, like mMenuEventListener,
157 // which refer to members of NotificationStackScrollLayout. The spy
158 // holds a copy of the CUT's instances of these classes, so they still refer to the CUT's
159 // member variables, not the spy's member variables.
160 mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null,
Selim Cinek34518f62019-02-28 19:41:18 -0800161 true /* allowLongPress */, mNotificationRoundnessManager,
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),
Selim Cinekc3fec682019-06-06 18:11:07 -0700165 mock(StatusBarStateController.class),
166 mHeadsUpManager,
167 mKeyguardBypassController);
Will Brockmane718d582019-01-17 16:38:38 -0500168 mStackScroller = spy(mStackScrollerInternal);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700169 mStackScroller.setShelf(notificationShelf);
Selim Cinek8a9308d2017-08-24 09:31:08 -0700170 mStackScroller.setStatusBar(mBar);
171 mStackScroller.setScrimController(mock(ScrimController.class));
Rohan Shah524cf7b2018-03-15 14:40:02 -0700172 mStackScroller.setGroupManager(mGroupManager);
173 mStackScroller.setEmptyShadeView(mEmptyShadeView);
Lucas Dupinfe218782019-06-11 15:20:32 -0700174 mStackScroller.setIconAreaController(mNotificationIconAreaController);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700175
176 // Stub out functionality that isn't necessary to test.
177 doNothing().when(mBar)
178 .executeRunnableDismissingKeyguard(any(Runnable.class),
179 any(Runnable.class),
180 anyBoolean(),
181 anyBoolean(),
182 anyBoolean());
183 doNothing().when(mGroupManager).collapseAllGroups();
184 doNothing().when(mExpandHelper).cancelImmediately();
185 doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean());
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
Julia Reynolds34f14962018-05-03 12:40:20 +0000203 public void updateEmptyView_dndSuppressing() {
204 when(mEmptyShadeView.willBeGone()).thenReturn(true);
205 when(mBar.areNotificationsHidden()).thenReturn(true);
206
207 mStackScroller.updateEmptyShadeView(true);
208
209 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
210 }
211
212 @Test
213 public void updateEmptyView_dndNotSuppressing() {
214 mStackScroller.setEmptyShadeView(mEmptyShadeView);
215 when(mEmptyShadeView.willBeGone()).thenReturn(true);
216 when(mBar.areNotificationsHidden()).thenReturn(false);
217
218 mStackScroller.updateEmptyShadeView(true);
219
220 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
221 }
222
223 @Test
224 public void updateEmptyView_noNotificationsToDndSuppressing() {
225 mStackScroller.setEmptyShadeView(mEmptyShadeView);
226 when(mEmptyShadeView.willBeGone()).thenReturn(true);
227 when(mBar.areNotificationsHidden()).thenReturn(false);
228 mStackScroller.updateEmptyShadeView(true);
229 verify(mEmptyShadeView).setText(R.string.empty_shade_text);
230
231 when(mBar.areNotificationsHidden()).thenReturn(true);
232 mStackScroller.updateEmptyShadeView(true);
233 verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text);
234 }
235
236 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700237 @UiThreadTest
238 public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() {
239 mStackScroller.setExpandedHeight(0f);
240 verify(mBlockingHelperManager).setNotificationShadeExpanded(0f);
241 reset(mBlockingHelperManager);
242
243 mStackScroller.setExpandedHeight(100f);
244 verify(mBlockingHelperManager).setNotificationShadeExpanded(100f);
Julia Reynolds9cf17562018-03-14 09:49:35 -0400245 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400246
247 @Test
248 public void manageNotifications_visible() {
249 FooterView view = mock(FooterView.class);
250 mStackScroller.setFooterView(view);
251 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400252
253 mStackScroller.updateFooterView(true, false);
254
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700255 verify(view).setVisible(eq(true), anyBoolean());
256 verify(view).setSecondaryVisible(eq(false), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400257 }
258
259 @Test
260 public void clearAll_visible() {
261 FooterView view = mock(FooterView.class);
262 mStackScroller.setFooterView(view);
263 when(view.willBeGone()).thenReturn(true);
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400264
265 mStackScroller.updateFooterView(true, true);
266
Selim Cinekd60ef9e2018-05-16 16:01:05 -0700267 verify(view).setVisible(eq(true), anyBoolean());
268 verify(view).setSecondaryVisible(eq(true), anyBoolean());
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400269 }
Jason Monke59dc402018-08-16 12:05:01 -0400270
271 @Test
272 public void testInflateFooterView() {
273 mStackScroller.inflateFooterView();
274 ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class);
275 verify(mStackScroller).setFooterView(captor.capture());
276
277 assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners());
278 assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners());
279 }
280
281 @Test
282 public void testUpdateFooter_noNotifications() {
283 setBarStateForTest(StatusBarState.SHADE);
284 assertEquals(0, mNotificationData.getActiveNotifications().size());
285
286 mStackScroller.updateFooter();
Jason Monk297c04e2018-08-23 17:16:59 -0400287 verify(mStackScroller, atLeastOnce()).updateFooterView(false, false);
Jason Monke59dc402018-08-16 12:05:01 -0400288 }
289
290 @Test
291 public void testUpdateFooter_remoteInput() {
292 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500293 ArrayList<NotificationEntry> entries = new ArrayList<>();
294 entries.add(mock(NotificationEntry.class));
Jason Monke59dc402018-08-16 12:05:01 -0400295 when(mNotificationData.getActiveNotifications()).thenReturn(entries);
296
297 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
298 when(row.canViewBeDismissed()).thenReturn(true);
299 when(mStackScroller.getChildCount()).thenReturn(1);
300 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
301 when(mRemoteInputController.isRemoteInputActive()).thenReturn(true);
302
303 mStackScroller.updateFooter();
304 verify(mStackScroller).updateFooterView(false, true);
305 }
306
307 @Test
308 public void testUpdateFooter_oneClearableNotification() {
309 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500310 ArrayList<NotificationEntry> entries = new ArrayList<>();
311 entries.add(mock(NotificationEntry.class));
Jason Monke59dc402018-08-16 12:05:01 -0400312 when(mNotificationData.getActiveNotifications()).thenReturn(entries);
313
314 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
315 when(row.canViewBeDismissed()).thenReturn(true);
316 when(mStackScroller.getChildCount()).thenReturn(1);
317 when(mStackScroller.getChildAt(anyInt())).thenReturn(row);
318
319 mStackScroller.updateFooter();
320 verify(mStackScroller).updateFooterView(true, true);
321 }
322
323 @Test
324 public void testUpdateFooter_oneNonClearableNotification() {
325 setBarStateForTest(StatusBarState.SHADE);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500326 ArrayList<NotificationEntry> entries = new ArrayList<>();
327 entries.add(mock(NotificationEntry.class));
Jason Monk297c04e2018-08-23 17:16:59 -0400328 when(mEntryManager.getNotificationData().getActiveNotifications()).thenReturn(entries);
329 assertTrue(mEntryManager.getNotificationData().getActiveNotifications().size() != 0);
Jason Monke59dc402018-08-16 12:05:01 -0400330
331 mStackScroller.updateFooter();
332 verify(mStackScroller).updateFooterView(true, false);
333 }
334
335 @Test
336 public void testUpdateFooter_atEnd() {
337 // add footer
338 mStackScroller.inflateFooterView();
339
340 // add notification
341 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class);
Ned Burnsf81c4c42019-01-07 14:10:43 -0500342 NotificationEntry entry = mock(NotificationEntry.class);
Evan Laird94492852018-10-25 13:43:01 -0400343 when(row.getEntry()).thenReturn(entry);
344 when(entry.isClearable()).thenReturn(true);
Jason Monke59dc402018-08-16 12:05:01 -0400345 mStackScroller.addContainerView(row);
346
347 mStackScroller.onUpdateRowStates();
348
349 // move footer to end
350 verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(-1 /* end */));
351 }
352
353 @Test
354 public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() {
355 clearInvocations(mStackScroller);
356 mStackScroller.onDensityOrFontScaleChanged();
357 verify(mStackScroller).setFooterView(any());
358 verify(mStackScroller).setEmptyShadeView(any());
359 }
360
Gus Prevas99ba4ba2018-10-01 16:40:23 -0400361 @Test
362 @UiThreadTest
363 public void testSetIsBeingDraggedResetsExposedMenu() {
364 NotificationSwipeHelper swipeActionHelper =
365 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
366 swipeActionHelper.setExposedMenuView(new View(mContext));
367 mStackScroller.setIsBeingDragged(true);
368 assertNull(swipeActionHelper.getExposedMenuView());
369 }
370
371 @Test
372 @UiThreadTest
373 public void testPanelTrackingStartResetsExposedMenu() {
374 NotificationSwipeHelper swipeActionHelper =
375 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
376 swipeActionHelper.setExposedMenuView(new View(mContext));
377 mStackScroller.onPanelTrackingStarted();
378 assertNull(swipeActionHelper.getExposedMenuView());
379 }
380
381 @Test
382 @UiThreadTest
383 public void testDarkModeResetsExposedMenu() {
384 NotificationSwipeHelper swipeActionHelper =
385 (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper();
386 swipeActionHelper.setExposedMenuView(new View(mContext));
Selim Cinek195dfc52019-05-30 19:35:05 -0700387 mStackScroller.setHideAmount(0.1f, 0.1f);
Gus Prevas99ba4ba2018-10-01 16:40:23 -0400388 assertNull(swipeActionHelper.getExposedMenuView());
389 }
390
Will Brockmane718d582019-01-17 16:38:38 -0500391 class LogMatcher implements ArgumentMatcher<LogMaker> {
392 private int mCategory, mType;
393
394 LogMatcher(int category, int type) {
395 mCategory = category;
396 mType = type;
397 }
398 public boolean matches(LogMaker l) {
399 return (l.getCategory() == mCategory)
400 && (l.getType() == mType);
401 }
402
403 public String toString() {
404 return String.format("LogMaker(%d, %d)", mCategory, mType);
405 }
406 }
407
408 private LogMaker logMatcher(int category, int type) {
409 return argThat(new LogMatcher(category, type));
410 }
411
412 @Test
413 @UiThreadTest
414 public void testOnMenuClickedLogging() {
415 // Set up the object under test to have a valid mLongPressListener. We're testing an
416 // anonymous-class member, mMenuEventListener, so we need to modify the state of the
417 // class itself, not the Mockito spy copied from it. See notes in setup.
418 mStackScrollerInternal.setLongPressListener(
419 mock(ExpandableNotificationRow.LongPressListener.class));
420
421 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
422 when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker(
423 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
424
425 mStackScroller.mMenuEventListener.onMenuClicked(row, 0, 0, mock(
426 NotificationMenuRowPlugin.MenuItem.class));
427 verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data
428 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_TOUCH_GEAR,
429 MetricsProto.MetricsEvent.TYPE_ACTION));
430 }
431
432 @Test
433 @UiThreadTest
Selim Cinekc3fec682019-06-06 18:11:07 -0700434 public void testOnMenuShownLogging() { ;
Will Brockmane718d582019-01-17 16:38:38 -0500435
436 ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
437 when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker(
438 MetricsProto.MetricsEvent.VIEW_UNKNOWN));
439
440 mStackScroller.mMenuEventListener.onMenuShown(row);
441 verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data
442 verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_REVEAL_GEAR,
443 MetricsProto.MetricsEvent.TYPE_ACTION));
444 }
445
Jason Monke59dc402018-08-16 12:05:01 -0400446 private void setBarStateForTest(int state) {
Jason Monk297c04e2018-08-23 17:16:59 -0400447 // Can't inject this through the listener or we end up on the actual implementation
448 // rather than the mock because the spy just coppied the anonymous inner /shruggie.
449 mStackScroller.setStatusBarState(state);
Jason Monke59dc402018-08-16 12:05:01 -0400450 }
Selim Cinek8a9308d2017-08-24 09:31:08 -0700451}