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; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 41 | import android.testing.AndroidTestingRunner; |
| 42 | import android.testing.TestableLooper; |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 43 | import android.view.View; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 44 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 45 | import androidx.test.annotation.UiThreadTest; |
| 46 | import androidx.test.filters.SmallTest; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 47 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 48 | import com.android.internal.logging.MetricsLogger; |
| 49 | import com.android.internal.logging.nano.MetricsProto; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 50 | import com.android.systemui.ActivityStarterDelegate; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 51 | import com.android.systemui.Dependency; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 52 | import com.android.systemui.ExpandHelper; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 53 | import com.android.systemui.InitController; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 54 | import com.android.systemui.R; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 55 | import com.android.systemui.SysuiTestCase; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 56 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 57 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 58 | import com.android.systemui.statusbar.AmbientPulseManager; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 59 | import com.android.systemui.statusbar.EmptyShadeView; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 60 | import com.android.systemui.statusbar.NotificationPresenter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 61 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 62 | import com.android.systemui.statusbar.NotificationShelf; |
| 63 | import com.android.systemui.statusbar.RemoteInputController; |
| 64 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
| 68 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 71 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 72 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
| 73 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 74 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 75 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.StatusBarTest.TestableNotificationEntryManager; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 80 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 81 | import org.junit.After; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 82 | import org.junit.Assert; |
| 83 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 84 | import org.junit.Rule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 85 | import org.junit.Test; |
| 86 | import org.junit.runner.RunWith; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 87 | import org.mockito.ArgumentCaptor; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 88 | import org.mockito.ArgumentMatcher; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 89 | import org.mockito.Mock; |
| 90 | import org.mockito.junit.MockitoJUnit; |
| 91 | import org.mockito.junit.MockitoRule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 92 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 93 | import java.util.ArrayList; |
| 94 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Tests for {@link NotificationStackScrollLayout}. |
| 97 | */ |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 98 | @SmallTest |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 99 | @RunWith(AndroidTestingRunner.class) |
| 100 | @TestableLooper.RunWithLooper |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 101 | public class NotificationStackScrollLayoutTest extends SysuiTestCase { |
| 102 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 103 | private NotificationStackScrollLayout mStackScroller; // Normally test this |
| 104 | private NotificationStackScrollLayout mStackScrollerInternal; // See explanation below |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 105 | |
| 106 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
| 107 | @Mock private StatusBar mBar; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 108 | @Mock private StatusBarStateController mBarState; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 109 | @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 Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 114 | @Mock private NotificationData mNotificationData; |
| 115 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 116 | @Mock private RemoteInputController mRemoteInputController; |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 117 | @Mock private NotificationIconAreaController mNotificationIconAreaController; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 118 | @Mock private MetricsLogger mMetricsLogger; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 119 | @Mock private NotificationRoundnessManager mNotificationRoundnessManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 120 | private TestableNotificationEntryManager mEntryManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 121 | private int mOriginalInterruptionModelSetting; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 122 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 123 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 124 | @Before |
| 125 | @UiThreadTest |
| 126 | public void setUp() throws Exception { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 127 | com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
| 128 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 129 | 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 Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 134 | // Inject dependencies before initializing the layout |
| 135 | mDependency.injectTestDependency( |
| 136 | NotificationBlockingHelperManager.class, |
| 137 | mBlockingHelperManager); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 138 | mDependency.injectTestDependency(StatusBarStateController.class, mBarState); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 139 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 140 | mDependency.injectTestDependency(NotificationRemoteInputManager.class, |
| 141 | mRemoteInputManager); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 142 | mDependency.injectMockDependency(ShadeController.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 143 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
| 144 | |
Gus Prevas | 9258646 | 2019-01-04 16:06:12 -0500 | [diff] [blame] | 145 | mEntryManager = new TestableNotificationEntryManager(mContext); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 146 | mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); |
| 147 | Dependency.get(InitController.class).executePostInitTasks(); |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 148 | mEntryManager.setUpForTest(mock(NotificationPresenter.class), null, mHeadsUpManager, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 149 | mNotificationData); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 150 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 151 | |
| 152 | NotificationShelf notificationShelf = mock(NotificationShelf.class); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 153 | |
| 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 Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 160 | true /* allowLongPress */, mNotificationRoundnessManager, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 161 | new AmbientPulseManager(mContext), |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 162 | mock(DynamicPrivacyController.class), |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 163 | mock(ConfigurationController.class), |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 164 | mock(ActivityStarterDelegate.class), |
| 165 | mock(StatusBarStateController.class)); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 166 | mStackScroller = spy(mStackScrollerInternal); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 167 | mStackScroller.setShelf(notificationShelf); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 168 | mStackScroller.setStatusBar(mBar); |
| 169 | mStackScroller.setScrimController(mock(ScrimController.class)); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 170 | mStackScroller.setHeadsUpManager(mHeadsUpManager); |
| 171 | mStackScroller.setGroupManager(mGroupManager); |
| 172 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 173 | mStackScroller.setIconAreaController(mNotificationIconAreaController); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 174 | |
| 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 Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 185 | doNothing().when(notificationShelf).fadeInTranslating(); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | @After |
| 189 | public void tearDown() { |
| 190 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 191 | NOTIFICATION_NEW_INTERRUPTION_MODEL, mOriginalInterruptionModelSetting); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Test |
| 195 | public void testNotDimmedOnKeyguard() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 196 | when(mBarState.getState()).thenReturn(StatusBarState.SHADE); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 197 | mStackScroller.setDimmed(true /* dimmed */, false /* animate */); |
| 198 | mStackScroller.setDimmed(true /* dimmed */, true /* animate */); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 199 | assertFalse(mStackScroller.isDimmed()); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 202 | @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 Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 213 | @Test |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 214 | 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 Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 248 | @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 Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 256 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 257 | |
| 258 | @Test |
| 259 | public void manageNotifications_visible() { |
| 260 | FooterView view = mock(FooterView.class); |
| 261 | mStackScroller.setFooterView(view); |
| 262 | when(view.willBeGone()).thenReturn(true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 263 | |
| 264 | mStackScroller.updateFooterView(true, false); |
| 265 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 266 | verify(view).setVisible(eq(true), anyBoolean()); |
| 267 | verify(view).setSecondaryVisible(eq(false), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 268 | } |
| 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 Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 275 | |
| 276 | mStackScroller.updateFooterView(true, true); |
| 277 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 278 | verify(view).setVisible(eq(true), anyBoolean()); |
| 279 | verify(view).setSecondaryVisible(eq(true), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 280 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 281 | |
| 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 Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 298 | verify(mStackScroller, atLeastOnce()).updateFooterView(false, false); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | @Test |
| 302 | public void testUpdateFooter_remoteInput() { |
| 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 | 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 Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 321 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
| 322 | entries.add(mock(NotificationEntry.class)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 323 | 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 Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 337 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
| 338 | entries.add(mock(NotificationEntry.class)); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 339 | when(mEntryManager.getNotificationData().getActiveNotifications()).thenReturn(entries); |
| 340 | assertTrue(mEntryManager.getNotificationData().getActiveNotifications().size() != 0); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 341 | |
| 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 Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 353 | NotificationEntry entry = mock(NotificationEntry.class); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 354 | when(row.getEntry()).thenReturn(entry); |
| 355 | when(entry.isClearable()).thenReturn(true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 356 | 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 Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 372 | @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 Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 402 | 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 Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 459 | private void setBarStateForTest(int state) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 460 | // 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 Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 463 | } |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 464 | } |