Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 6 | * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 7 | * 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 Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | package com.android.systemui.statusbar.notification.stack; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 15 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 16 | import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; |
| 17 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 18 | import static junit.framework.Assert.assertEquals; |
| 19 | import static junit.framework.Assert.assertNotNull; |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 20 | import static junit.framework.Assert.assertNull; |
| 21 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 22 | import static org.junit.Assert.assertFalse; |
| 23 | import static org.junit.Assert.assertTrue; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 24 | import static org.mockito.ArgumentMatchers.any; |
| 25 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 26 | import static org.mockito.ArgumentMatchers.anyInt; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 27 | import static org.mockito.ArgumentMatchers.argThat; |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 28 | import static org.mockito.ArgumentMatchers.eq; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 29 | import static org.mockito.Mockito.RETURNS_DEEP_STUBS; |
Evan Laird | fec7766 | 2018-09-18 16:56:50 -0400 | [diff] [blame] | 30 | import static org.mockito.Mockito.atLeastOnce; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 31 | import static org.mockito.Mockito.clearInvocations; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 32 | import static org.mockito.Mockito.doNothing; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 33 | import static org.mockito.Mockito.mock; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.reset; |
| 35 | import static org.mockito.Mockito.spy; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 36 | import static org.mockito.Mockito.verify; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 37 | import static org.mockito.Mockito.when; |
| 38 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 39 | import android.metrics.LogMaker; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 40 | import android.provider.Settings; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 41 | import android.support.test.annotation.UiThreadTest; |
| 42 | import android.support.test.filters.SmallTest; |
| 43 | import android.support.test.runner.AndroidJUnit4; |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 44 | import android.view.View; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 45 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 46 | import com.android.internal.logging.MetricsLogger; |
| 47 | import com.android.internal.logging.nano.MetricsProto; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 48 | import com.android.systemui.Dependency; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 49 | import com.android.systemui.ExpandHelper; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 50 | import com.android.systemui.InitController; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 51 | import com.android.systemui.R; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 52 | import com.android.systemui.SysuiTestCase; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 53 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 54 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 55 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 56 | import com.android.systemui.statusbar.NotificationPresenter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 58 | import com.android.systemui.statusbar.NotificationShelf; |
| 59 | import com.android.systemui.statusbar.RemoteInputController; |
| 60 | import com.android.systemui.statusbar.StatusBarState; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 61 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
| 63 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 66 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
| 68 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 69 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 70 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 72 | import com.android.systemui.statusbar.phone.StatusBarTest.TestableNotificationEntryManager; |
| 73 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 74 | import org.junit.After; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 75 | import org.junit.Assert; |
| 76 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 77 | import org.junit.Rule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 78 | import org.junit.Test; |
| 79 | import org.junit.runner.RunWith; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 80 | import org.mockito.ArgumentCaptor; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 81 | import org.mockito.ArgumentMatcher; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 82 | import org.mockito.Mock; |
| 83 | import org.mockito.junit.MockitoJUnit; |
| 84 | import org.mockito.junit.MockitoRule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 85 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 86 | import java.util.ArrayList; |
| 87 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Tests for {@link NotificationStackScrollLayout}. |
| 90 | */ |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 91 | @SmallTest |
| 92 | @RunWith(AndroidJUnit4.class) |
| 93 | public class NotificationStackScrollLayoutTest extends SysuiTestCase { |
| 94 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 95 | private NotificationStackScrollLayout mStackScroller; // Normally test this |
| 96 | private NotificationStackScrollLayout mStackScrollerInternal; // See explanation below |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 97 | |
| 98 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
| 99 | @Mock private StatusBar mBar; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 100 | @Mock private StatusBarStateController mBarState; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 101 | @Mock private HeadsUpManagerPhone mHeadsUpManager; |
| 102 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 103 | @Mock private NotificationGroupManager mGroupManager; |
| 104 | @Mock private ExpandHelper mExpandHelper; |
| 105 | @Mock private EmptyShadeView mEmptyShadeView; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 106 | @Mock private NotificationData mNotificationData; |
| 107 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 108 | @Mock private RemoteInputController mRemoteInputController; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 109 | @Mock private MetricsLogger mMetricsLogger; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 110 | @Mock private NotificationRoundnessManager mNotificationRoundnessManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 111 | private TestableNotificationEntryManager mEntryManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 112 | private int mOriginalInterruptionModelSetting; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 113 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 114 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 115 | @Before |
| 116 | @UiThreadTest |
| 117 | public void setUp() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 118 | // Inject dependencies before initializing the layout |
| 119 | mDependency.injectTestDependency( |
| 120 | NotificationBlockingHelperManager.class, |
| 121 | mBlockingHelperManager); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 122 | mDependency.injectTestDependency(StatusBarStateController.class, mBarState); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 123 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 124 | mDependency.injectTestDependency(NotificationRemoteInputManager.class, |
| 125 | mRemoteInputManager); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 126 | mDependency.injectMockDependency(ShadeController.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 127 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
| 128 | |
Gus Prevas | 9258646 | 2019-01-04 16:06:12 -0500 | [diff] [blame] | 129 | mEntryManager = new TestableNotificationEntryManager(mContext); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 130 | mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); |
| 131 | Dependency.get(InitController.class).executePostInitTasks(); |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 132 | mEntryManager.setUpForTest(mock(NotificationPresenter.class), null, mHeadsUpManager, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 133 | mNotificationData); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 134 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 135 | |
| 136 | NotificationShelf notificationShelf = mock(NotificationShelf.class); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 137 | |
| 138 | // The actual class under test. You may need to work with this class directly when |
| 139 | // testing anonymous class members of mStackScroller, like mMenuEventListener, |
| 140 | // which refer to members of NotificationStackScrollLayout. The spy |
| 141 | // holds a copy of the CUT's instances of these classes, so they still refer to the CUT's |
| 142 | // member variables, not the spy's member variables. |
| 143 | mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null, |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 144 | true /* allowLongPress */, mNotificationRoundnessManager); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 145 | mStackScroller = spy(mStackScrollerInternal); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 146 | mStackScroller.setShelf(notificationShelf); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 147 | mStackScroller.setStatusBar(mBar); |
| 148 | mStackScroller.setScrimController(mock(ScrimController.class)); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 149 | mStackScroller.setHeadsUpManager(mHeadsUpManager); |
| 150 | mStackScroller.setGroupManager(mGroupManager); |
| 151 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
| 152 | |
| 153 | // Stub out functionality that isn't necessary to test. |
| 154 | doNothing().when(mBar) |
| 155 | .executeRunnableDismissingKeyguard(any(Runnable.class), |
| 156 | any(Runnable.class), |
| 157 | anyBoolean(), |
| 158 | anyBoolean(), |
| 159 | anyBoolean()); |
| 160 | doNothing().when(mGroupManager).collapseAllGroups(); |
| 161 | doNothing().when(mExpandHelper).cancelImmediately(); |
| 162 | doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean()); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 163 | doNothing().when(notificationShelf).fadeInTranslating(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 164 | |
| 165 | mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(), |
| 166 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); |
| 167 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 168 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); |
| 169 | } |
| 170 | |
| 171 | @After |
| 172 | public void tearDown() { |
| 173 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 174 | NOTIFICATION_NEW_INTERRUPTION_MODEL, mOriginalInterruptionModelSetting); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Test |
| 178 | public void testNotDimmedOnKeyguard() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 179 | when(mBarState.getState()).thenReturn(StatusBarState.SHADE); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 180 | mStackScroller.setDimmed(true /* dimmed */, false /* animate */); |
| 181 | mStackScroller.setDimmed(true /* dimmed */, true /* animate */); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 182 | assertFalse(mStackScroller.isDimmed()); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 185 | @Test |
| 186 | public void testAntiBurnInOffset() { |
| 187 | final int burnInOffset = 30; |
| 188 | mStackScroller.setAntiBurnInOffsetX(burnInOffset); |
| 189 | mStackScroller.setDark(false /* dark */, false /* animated */, null /* touch */); |
| 190 | Assert.assertEquals(0 /* expected */, mStackScroller.getTranslationX(), 0.01 /* delta */); |
| 191 | mStackScroller.setDark(true /* dark */, false /* animated */, null /* touch */); |
| 192 | Assert.assertEquals(burnInOffset /* expected */, mStackScroller.getTranslationX(), |
| 193 | 0.01 /* delta */); |
| 194 | } |
| 195 | |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 196 | @Test |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 197 | public void updateEmptyView_dndSuppressing() { |
| 198 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
| 199 | when(mBar.areNotificationsHidden()).thenReturn(true); |
| 200 | |
| 201 | mStackScroller.updateEmptyShadeView(true); |
| 202 | |
| 203 | verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text); |
| 204 | } |
| 205 | |
| 206 | @Test |
| 207 | public void updateEmptyView_dndNotSuppressing() { |
| 208 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
| 209 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
| 210 | when(mBar.areNotificationsHidden()).thenReturn(false); |
| 211 | |
| 212 | mStackScroller.updateEmptyShadeView(true); |
| 213 | |
| 214 | verify(mEmptyShadeView).setText(R.string.empty_shade_text); |
| 215 | } |
| 216 | |
| 217 | @Test |
| 218 | public void updateEmptyView_noNotificationsToDndSuppressing() { |
| 219 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
| 220 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
| 221 | when(mBar.areNotificationsHidden()).thenReturn(false); |
| 222 | mStackScroller.updateEmptyShadeView(true); |
| 223 | verify(mEmptyShadeView).setText(R.string.empty_shade_text); |
| 224 | |
| 225 | when(mBar.areNotificationsHidden()).thenReturn(true); |
| 226 | mStackScroller.updateEmptyShadeView(true); |
| 227 | verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text); |
| 228 | } |
| 229 | |
| 230 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 231 | @UiThreadTest |
| 232 | public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() { |
| 233 | mStackScroller.setExpandedHeight(0f); |
| 234 | verify(mBlockingHelperManager).setNotificationShadeExpanded(0f); |
| 235 | reset(mBlockingHelperManager); |
| 236 | |
| 237 | mStackScroller.setExpandedHeight(100f); |
| 238 | verify(mBlockingHelperManager).setNotificationShadeExpanded(100f); |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 239 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 240 | |
| 241 | @Test |
| 242 | public void manageNotifications_visible() { |
| 243 | FooterView view = mock(FooterView.class); |
| 244 | mStackScroller.setFooterView(view); |
| 245 | when(view.willBeGone()).thenReturn(true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 246 | |
| 247 | mStackScroller.updateFooterView(true, false); |
| 248 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 249 | verify(view).setVisible(eq(true), anyBoolean()); |
| 250 | verify(view).setSecondaryVisible(eq(false), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Test |
| 254 | public void clearAll_visible() { |
| 255 | FooterView view = mock(FooterView.class); |
| 256 | mStackScroller.setFooterView(view); |
| 257 | when(view.willBeGone()).thenReturn(true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 258 | |
| 259 | mStackScroller.updateFooterView(true, true); |
| 260 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 261 | verify(view).setVisible(eq(true), anyBoolean()); |
| 262 | verify(view).setSecondaryVisible(eq(true), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 263 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 264 | |
| 265 | @Test |
| 266 | public void testInflateFooterView() { |
| 267 | mStackScroller.inflateFooterView(); |
| 268 | ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class); |
| 269 | verify(mStackScroller).setFooterView(captor.capture()); |
| 270 | |
| 271 | assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners()); |
| 272 | assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners()); |
| 273 | } |
| 274 | |
| 275 | @Test |
| 276 | public void testUpdateFooter_noNotifications() { |
| 277 | setBarStateForTest(StatusBarState.SHADE); |
| 278 | assertEquals(0, mNotificationData.getActiveNotifications().size()); |
| 279 | |
| 280 | mStackScroller.updateFooter(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 281 | verify(mStackScroller, atLeastOnce()).updateFooterView(false, false); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void testUpdateFooter_remoteInput() { |
| 286 | setBarStateForTest(StatusBarState.SHADE); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 287 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
| 288 | entries.add(mock(NotificationEntry.class)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 289 | when(mNotificationData.getActiveNotifications()).thenReturn(entries); |
| 290 | |
| 291 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 292 | when(row.canViewBeDismissed()).thenReturn(true); |
| 293 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 294 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 295 | when(mRemoteInputController.isRemoteInputActive()).thenReturn(true); |
| 296 | |
| 297 | mStackScroller.updateFooter(); |
| 298 | verify(mStackScroller).updateFooterView(false, true); |
| 299 | } |
| 300 | |
| 301 | @Test |
| 302 | public void testUpdateFooter_oneClearableNotification() { |
| 303 | setBarStateForTest(StatusBarState.SHADE); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 304 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
| 305 | entries.add(mock(NotificationEntry.class)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 306 | 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 | |
| 313 | mStackScroller.updateFooter(); |
| 314 | verify(mStackScroller).updateFooterView(true, true); |
| 315 | } |
| 316 | |
| 317 | @Test |
| 318 | public void testUpdateFooter_oneNonClearableNotification() { |
| 319 | setBarStateForTest(StatusBarState.SHADE); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 320 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
| 321 | entries.add(mock(NotificationEntry.class)); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 322 | when(mEntryManager.getNotificationData().getActiveNotifications()).thenReturn(entries); |
| 323 | assertTrue(mEntryManager.getNotificationData().getActiveNotifications().size() != 0); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 324 | |
| 325 | mStackScroller.updateFooter(); |
| 326 | verify(mStackScroller).updateFooterView(true, false); |
| 327 | } |
| 328 | |
| 329 | @Test |
| 330 | public void testUpdateFooter_atEnd() { |
| 331 | // add footer |
| 332 | mStackScroller.inflateFooterView(); |
| 333 | |
| 334 | // add notification |
| 335 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 336 | NotificationEntry entry = mock(NotificationEntry.class); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 337 | when(row.getEntry()).thenReturn(entry); |
| 338 | when(entry.isClearable()).thenReturn(true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 339 | mStackScroller.addContainerView(row); |
| 340 | |
| 341 | mStackScroller.onUpdateRowStates(); |
| 342 | |
| 343 | // move footer to end |
| 344 | verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(-1 /* end */)); |
| 345 | } |
| 346 | |
| 347 | @Test |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 348 | public void testUpdateGapIndex_allHighPriority() { |
| 349 | when(mStackScroller.getChildCount()).thenReturn(3); |
| 350 | for (int i = 0; i < 3; i++) { |
| 351 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, |
| 352 | RETURNS_DEEP_STUBS); |
| 353 | String key = Integer.toString(i); |
| 354 | when(row.getStatusBarNotification().getKey()).thenReturn(key); |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 355 | when(row.getEntry().isHighPriority()).thenReturn(true); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 356 | when(mStackScroller.getChildAt(i)).thenReturn(row); |
| 357 | } |
| 358 | |
| 359 | mStackScroller.updateSectionBoundaries(); |
| 360 | assertEquals(-1, mStackScroller.getSectionBoundaryIndex(0)); |
| 361 | } |
| 362 | |
| 363 | @Test |
| 364 | public void testUpdateGapIndex_allLowPriority() { |
| 365 | when(mStackScroller.getChildCount()).thenReturn(3); |
| 366 | for (int i = 0; i < 3; i++) { |
| 367 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, |
| 368 | RETURNS_DEEP_STUBS); |
| 369 | String key = Integer.toString(i); |
| 370 | when(row.getStatusBarNotification().getKey()).thenReturn(key); |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 371 | when(row.getEntry().isHighPriority()).thenReturn(false); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 372 | when(mStackScroller.getChildAt(i)).thenReturn(row); |
| 373 | } |
| 374 | |
| 375 | mStackScroller.updateSectionBoundaries(); |
| 376 | assertEquals(-1, mStackScroller.getSectionBoundaryIndex(0)); |
| 377 | } |
| 378 | |
| 379 | @Test |
| 380 | public void testUpdateGapIndex_gapExists() { |
| 381 | when(mStackScroller.getChildCount()).thenReturn(6); |
| 382 | for (int i = 0; i < 6; i++) { |
| 383 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, |
| 384 | RETURNS_DEEP_STUBS); |
| 385 | String key = Integer.toString(i); |
| 386 | when(row.getStatusBarNotification().getKey()).thenReturn(key); |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 387 | when(row.getEntry().isHighPriority()).thenReturn(i < 3); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 388 | when(mStackScroller.getChildAt(i)).thenReturn(row); |
| 389 | } |
| 390 | |
| 391 | mStackScroller.updateSectionBoundaries(); |
| 392 | assertEquals(3, mStackScroller.getSectionBoundaryIndex(0)); |
| 393 | } |
| 394 | |
| 395 | @Test |
| 396 | public void testUpdateGapIndex_empty() { |
| 397 | when(mStackScroller.getChildCount()).thenReturn(0); |
| 398 | |
| 399 | mStackScroller.updateSectionBoundaries(); |
| 400 | assertEquals(-1, mStackScroller.getSectionBoundaryIndex(0)); |
| 401 | } |
| 402 | |
| 403 | @Test |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 404 | public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() { |
| 405 | clearInvocations(mStackScroller); |
| 406 | mStackScroller.onDensityOrFontScaleChanged(); |
| 407 | verify(mStackScroller).setFooterView(any()); |
| 408 | verify(mStackScroller).setEmptyShadeView(any()); |
| 409 | } |
| 410 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 411 | @Test |
| 412 | @UiThreadTest |
| 413 | public void testSetIsBeingDraggedResetsExposedMenu() { |
| 414 | NotificationSwipeHelper swipeActionHelper = |
| 415 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 416 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
| 417 | mStackScroller.setIsBeingDragged(true); |
| 418 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 419 | } |
| 420 | |
| 421 | @Test |
| 422 | @UiThreadTest |
| 423 | public void testPanelTrackingStartResetsExposedMenu() { |
| 424 | NotificationSwipeHelper swipeActionHelper = |
| 425 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 426 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
| 427 | mStackScroller.onPanelTrackingStarted(); |
| 428 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 429 | } |
| 430 | |
| 431 | @Test |
| 432 | @UiThreadTest |
| 433 | public void testDarkModeResetsExposedMenu() { |
| 434 | NotificationSwipeHelper swipeActionHelper = |
| 435 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 436 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
| 437 | mStackScroller.setDarkAmount(0.1f, 0.1f); |
| 438 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 439 | } |
| 440 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 441 | class LogMatcher implements ArgumentMatcher<LogMaker> { |
| 442 | private int mCategory, mType; |
| 443 | |
| 444 | LogMatcher(int category, int type) { |
| 445 | mCategory = category; |
| 446 | mType = type; |
| 447 | } |
| 448 | public boolean matches(LogMaker l) { |
| 449 | return (l.getCategory() == mCategory) |
| 450 | && (l.getType() == mType); |
| 451 | } |
| 452 | |
| 453 | public String toString() { |
| 454 | return String.format("LogMaker(%d, %d)", mCategory, mType); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | private LogMaker logMatcher(int category, int type) { |
| 459 | return argThat(new LogMatcher(category, type)); |
| 460 | } |
| 461 | |
| 462 | @Test |
| 463 | @UiThreadTest |
| 464 | public void testOnMenuClickedLogging() { |
| 465 | // Set up the object under test to have a valid mLongPressListener. We're testing an |
| 466 | // anonymous-class member, mMenuEventListener, so we need to modify the state of the |
| 467 | // class itself, not the Mockito spy copied from it. See notes in setup. |
| 468 | mStackScrollerInternal.setLongPressListener( |
| 469 | mock(ExpandableNotificationRow.LongPressListener.class)); |
| 470 | |
| 471 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS); |
| 472 | when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker( |
| 473 | MetricsProto.MetricsEvent.VIEW_UNKNOWN)); |
| 474 | |
| 475 | mStackScroller.mMenuEventListener.onMenuClicked(row, 0, 0, mock( |
| 476 | NotificationMenuRowPlugin.MenuItem.class)); |
| 477 | verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data |
| 478 | verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_TOUCH_GEAR, |
| 479 | MetricsProto.MetricsEvent.TYPE_ACTION)); |
| 480 | } |
| 481 | |
| 482 | @Test |
| 483 | @UiThreadTest |
| 484 | public void testOnMenuShownLogging() { |
| 485 | // Set up the object under test to have a valid mHeadsUpManager. See notes in setup. |
| 486 | mStackScrollerInternal.setHeadsUpManager(mHeadsUpManager); |
| 487 | |
| 488 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS); |
| 489 | when(row.getStatusBarNotification().getLogMaker()).thenReturn(new LogMaker( |
| 490 | MetricsProto.MetricsEvent.VIEW_UNKNOWN)); |
| 491 | |
| 492 | mStackScroller.mMenuEventListener.onMenuShown(row); |
| 493 | verify(row.getStatusBarNotification()).getLogMaker(); // This writes most of the log data |
| 494 | verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_REVEAL_GEAR, |
| 495 | MetricsProto.MetricsEvent.TYPE_ACTION)); |
| 496 | } |
| 497 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 498 | private void setBarStateForTest(int state) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 499 | // Can't inject this through the listener or we end up on the actual implementation |
| 500 | // rather than the mock because the spy just coppied the anonymous inner /shruggie. |
| 501 | mStackScroller.setStatusBarState(state); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 502 | } |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 503 | } |