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 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 16 | import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 17 | import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; |
| 18 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 19 | import static junit.framework.Assert.assertEquals; |
| 20 | import static junit.framework.Assert.assertNotNull; |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 21 | import static junit.framework.Assert.assertNull; |
| 22 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 23 | import static org.junit.Assert.assertFalse; |
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; |
Julia Reynolds | 1f94a9d | 2020-05-05 12:40:21 -0400 | [diff] [blame] | 40 | import android.os.UserHandle; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 41 | import android.provider.Settings; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 42 | import android.testing.AndroidTestingRunner; |
| 43 | import android.testing.TestableLooper; |
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 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 46 | import androidx.test.annotation.UiThreadTest; |
| 47 | import androidx.test.filters.SmallTest; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 48 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 49 | import com.android.internal.logging.MetricsLogger; |
| 50 | import com.android.internal.logging.nano.MetricsProto; |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 51 | import com.android.internal.logging.testing.UiEventLoggerFake; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 52 | import com.android.systemui.ExpandHelper; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 53 | import com.android.systemui.R; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 54 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 55 | import com.android.systemui.classifier.FalsingManagerFake; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 56 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.EmptyShadeView; |
Beverly | 8b493df | 2019-12-18 14:16:50 -0500 | [diff] [blame] | 58 | import com.android.systemui.statusbar.FeatureFlags; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 60 | import com.android.systemui.statusbar.NotificationLockscreenUserManager.UserChangedListener; |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 61 | import com.android.systemui.statusbar.NotificationMediaManager; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.NotificationPresenter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 63 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 64 | import com.android.systemui.statusbar.NotificationShelf; |
| 65 | import com.android.systemui.statusbar.RemoteInputController; |
| 66 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.ForegroundServiceDismissalFeatureController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | afe77bc | 2020-01-30 20:45:07 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.notification.NotificationEntryManagerLogger; |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.NotificationFilter; |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager; |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 75 | import com.android.systemui.statusbar.notification.collection.NotifCollection; |
| 76 | import com.android.systemui.statusbar.notification.collection.NotifPipeline; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 77 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | 79c89ec | 2019-12-13 10:33:01 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 79 | import com.android.systemui.statusbar.notification.collection.NotificationRankingManager; |
Ned Burns | c0cd283 | 2020-01-10 00:37:03 -0500 | [diff] [blame] | 80 | import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinder; |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 81 | import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; |
Steve Elliott | 960f4ce | 2019-12-04 15:13:52 -0500 | [diff] [blame] | 82 | import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 83 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 84 | import com.android.systemui.statusbar.notification.row.FooterView; |
| 85 | import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 86 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 87 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 89 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 90 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 91 | import com.android.systemui.statusbar.phone.ScrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 92 | import com.android.systemui.statusbar.phone.ShadeController; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 93 | import com.android.systemui.statusbar.phone.StatusBar; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 94 | import com.android.systemui.statusbar.policy.ZenModeController; |
Dave Mankoff | 02dcaf5 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 95 | import com.android.systemui.util.leak.LeakDetector; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 96 | |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 97 | import org.junit.After; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 98 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 99 | import org.junit.Rule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 100 | import org.junit.Test; |
| 101 | import org.junit.runner.RunWith; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 102 | import org.mockito.ArgumentCaptor; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 103 | import org.mockito.ArgumentMatcher; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 104 | import org.mockito.Mock; |
| 105 | import org.mockito.junit.MockitoJUnit; |
| 106 | import org.mockito.junit.MockitoRule; |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 107 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 108 | import java.util.ArrayList; |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 109 | import java.util.List; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 110 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Tests for {@link NotificationStackScrollLayout}. |
| 113 | */ |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 114 | @SmallTest |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 115 | @RunWith(AndroidTestingRunner.class) |
| 116 | @TestableLooper.RunWithLooper |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 117 | public class NotificationStackScrollLayoutTest extends SysuiTestCase { |
| 118 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 119 | private NotificationStackScrollLayout mStackScroller; // Normally test this |
| 120 | private NotificationStackScrollLayout mStackScrollerInternal; // See explanation below |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 121 | |
| 122 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
| 123 | @Mock private StatusBar mBar; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 124 | @Mock private SysuiStatusBarStateController mBarState; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 125 | @Mock private HeadsUpManagerPhone mHeadsUpManager; |
| 126 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 127 | @Mock private NotificationGroupManager mGroupManager; |
| 128 | @Mock private ExpandHelper mExpandHelper; |
| 129 | @Mock private EmptyShadeView mEmptyShadeView; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 130 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 131 | @Mock private RemoteInputController mRemoteInputController; |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 132 | @Mock private NotificationIconAreaController mNotificationIconAreaController; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 133 | @Mock private MetricsLogger mMetricsLogger; |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 134 | @Mock private NotificationRoundnessManager mNotificationRoundnessManager; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 135 | @Mock private KeyguardBypassController mKeyguardBypassController; |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 136 | @Mock private ZenModeController mZenModeController; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 137 | @Mock private NotificationSectionsManager mNotificationSectionsManager; |
| 138 | @Mock private NotificationSection mNotificationSection; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 139 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 140 | @Mock private FeatureFlags mFeatureFlags; |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 141 | private UserChangedListener mUserChangedListener; |
Kevin Han | bd14293 | 2020-03-10 18:27:50 -0700 | [diff] [blame] | 142 | private NotificationEntryManager mEntryManager; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 143 | private int mOriginalInterruptionModelSetting; |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 144 | private UiEventLoggerFake mUiEventLoggerFake = new UiEventLoggerFake(); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 145 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 146 | |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 147 | @Before |
| 148 | @UiThreadTest |
| 149 | public void setUp() throws Exception { |
Beverly | 1467c9e | 2020-02-18 13:31:29 -0500 | [diff] [blame] | 150 | allowTestableLooperAsMainThread(); |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 151 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 152 | mOriginalInterruptionModelSetting = Settings.Secure.getInt(mContext.getContentResolver(), |
| 153 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); |
| 154 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 155 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); |
Julia Reynolds | 1f94a9d | 2020-05-05 12:40:21 -0400 | [diff] [blame] | 156 | Settings.Secure.putIntForUser(mContext.getContentResolver(), NOTIFICATION_HISTORY_ENABLED, |
| 157 | 1, UserHandle.USER_CURRENT); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 158 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 159 | // Inject dependencies before initializing the layout |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 160 | mDependency.injectMockDependency(VisualStabilityManager.class); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 161 | mDependency.injectTestDependency( |
| 162 | NotificationBlockingHelperManager.class, |
| 163 | mBlockingHelperManager); |
Selim Cinek | eec5884 | 2019-08-02 09:35:28 -0700 | [diff] [blame] | 164 | mDependency.injectTestDependency(SysuiStatusBarStateController.class, mBarState); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 165 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 166 | mDependency.injectTestDependency(NotificationRemoteInputManager.class, |
| 167 | mRemoteInputManager); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 168 | mDependency.injectMockDependency(ShadeController.class); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 169 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
| 170 | |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 171 | ArgumentCaptor<UserChangedListener> userChangedCaptor = ArgumentCaptor |
| 172 | .forClass(UserChangedListener.class); |
Kevin Han | bd14293 | 2020-03-10 18:27:50 -0700 | [diff] [blame] | 173 | mEntryManager = new NotificationEntryManager( |
Ned Burns | afe77bc | 2020-01-30 20:45:07 -0500 | [diff] [blame] | 174 | mock(NotificationEntryManagerLogger.class), |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 175 | mock(NotificationGroupManager.class), |
| 176 | new NotificationRankingManager( |
| 177 | () -> mock(NotificationMediaManager.class), |
| 178 | mGroupManager, |
| 179 | mHeadsUpManager, |
| 180 | mock(NotificationFilter.class), |
Ned Burns | afe77bc | 2020-01-30 20:45:07 -0500 | [diff] [blame] | 181 | mock(NotificationEntryManagerLogger.class), |
Steve Elliott | 960f4ce | 2019-12-04 15:13:52 -0500 | [diff] [blame] | 182 | mock(NotificationSectionsFeatureManager.class), |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 183 | mock(PeopleNotificationIdentifier.class), |
| 184 | mock(HighPriorityProvider.class) |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 185 | ), |
Beverly | 8b493df | 2019-12-18 14:16:50 -0500 | [diff] [blame] | 186 | mock(NotificationEntryManager.KeyguardEnvironment.class), |
Dave Mankoff | 02dcaf5 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 187 | mock(FeatureFlags.class), |
| 188 | () -> mock(NotificationRowBinder.class), |
| 189 | () -> mRemoteInputManager, |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 190 | mock(LeakDetector.class), |
| 191 | mock(ForegroundServiceDismissalFeatureController.class) |
| 192 | ); |
Kevin Han | bd14293 | 2020-03-10 18:27:50 -0700 | [diff] [blame] | 193 | mEntryManager.setUpWithPresenter(mock(NotificationPresenter.class)); |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 194 | when(mFeatureFlags.isNewNotifPipelineRenderingEnabled()).thenReturn(false); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 195 | |
| 196 | NotificationShelf notificationShelf = mock(NotificationShelf.class); |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 197 | when(mNotificationSectionsManager.createSectionsForBuckets()).thenReturn( |
| 198 | new NotificationSection[]{ |
| 199 | mNotificationSection |
| 200 | }); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 201 | // The actual class under test. You may need to work with this class directly when |
| 202 | // testing anonymous class members of mStackScroller, like mMenuEventListener, |
| 203 | // which refer to members of NotificationStackScrollLayout. The spy |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 204 | // holds a copy of the CUT's instances of these KeyguardBypassController, so they still |
| 205 | // refer to the CUT's member variables, not the spy's member variables. |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 206 | mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null, |
Selim Cinek | 34518f6 | 2019-02-28 19:41:18 -0800 | [diff] [blame] | 207 | true /* allowLongPress */, mNotificationRoundnessManager, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 208 | mock(DynamicPrivacyController.class), |
Selim Cinek | eec5884 | 2019-08-02 09:35:28 -0700 | [diff] [blame] | 209 | mock(SysuiStatusBarStateController.class), |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 210 | mHeadsUpManager, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 211 | mKeyguardBypassController, |
Evan Laird | 367b614 | 2019-08-30 14:40:34 -0400 | [diff] [blame] | 212 | new FalsingManagerFake(), |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 213 | mLockscreenUserManager, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 214 | mock(NotificationGutsManager.class), |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 215 | mZenModeController, |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 216 | mNotificationSectionsManager, |
| 217 | mock(ForegroundServiceSectionController.class), |
Beverly | 7e0d649 | 2020-02-07 16:22:14 -0500 | [diff] [blame] | 218 | mock(ForegroundServiceDismissalFeatureController.class), |
| 219 | mFeatureFlags, |
| 220 | mock(NotifPipeline.class), |
| 221 | mEntryManager, |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 222 | mock(NotifCollection.class), |
| 223 | mUiEventLoggerFake |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 224 | ); |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 225 | verify(mLockscreenUserManager).addUserChangedListener(userChangedCaptor.capture()); |
| 226 | mUserChangedListener = userChangedCaptor.getValue(); |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 227 | mStackScroller = spy(mStackScrollerInternal); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 228 | mStackScroller.setShelf(notificationShelf); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 229 | mStackScroller.setStatusBar(mBar); |
| 230 | mStackScroller.setScrimController(mock(ScrimController.class)); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 231 | mStackScroller.setGroupManager(mGroupManager); |
| 232 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
Lucas Dupin | fe21878 | 2019-06-11 15:20:32 -0700 | [diff] [blame] | 233 | mStackScroller.setIconAreaController(mNotificationIconAreaController); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 234 | |
| 235 | // Stub out functionality that isn't necessary to test. |
| 236 | doNothing().when(mBar) |
| 237 | .executeRunnableDismissingKeyguard(any(Runnable.class), |
| 238 | any(Runnable.class), |
| 239 | anyBoolean(), |
| 240 | anyBoolean(), |
| 241 | anyBoolean()); |
| 242 | doNothing().when(mGroupManager).collapseAllGroups(); |
| 243 | doNothing().when(mExpandHelper).cancelImmediately(); |
| 244 | doNothing().when(notificationShelf).setAnimationsEnabled(anyBoolean()); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @After |
| 248 | public void tearDown() { |
| 249 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 250 | NOTIFICATION_NEW_INTERRUPTION_MODEL, mOriginalInterruptionModelSetting); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Test |
| 254 | public void testNotDimmedOnKeyguard() { |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 255 | when(mBarState.getState()).thenReturn(StatusBarState.SHADE); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 256 | mStackScroller.setDimmed(true /* dimmed */, false /* animate */); |
| 257 | mStackScroller.setDimmed(true /* dimmed */, true /* animate */); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 258 | assertFalse(mStackScroller.isDimmed()); |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Lucas Dupin | 0cd882f | 2018-01-30 12:19:49 -0800 | [diff] [blame] | 261 | @Test |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 262 | public void updateEmptyView_dndSuppressing() { |
| 263 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 264 | when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(true); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 265 | |
| 266 | mStackScroller.updateEmptyShadeView(true); |
| 267 | |
| 268 | verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text); |
| 269 | } |
| 270 | |
| 271 | @Test |
| 272 | public void updateEmptyView_dndNotSuppressing() { |
| 273 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
| 274 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 275 | when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 276 | |
| 277 | mStackScroller.updateEmptyShadeView(true); |
| 278 | |
| 279 | verify(mEmptyShadeView).setText(R.string.empty_shade_text); |
| 280 | } |
| 281 | |
| 282 | @Test |
| 283 | public void updateEmptyView_noNotificationsToDndSuppressing() { |
| 284 | mStackScroller.setEmptyShadeView(mEmptyShadeView); |
| 285 | when(mEmptyShadeView.willBeGone()).thenReturn(true); |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 286 | when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 287 | mStackScroller.updateEmptyShadeView(true); |
| 288 | verify(mEmptyShadeView).setText(R.string.empty_shade_text); |
| 289 | |
Beverly | 482ad6a | 2019-11-06 16:57:05 -0500 | [diff] [blame] | 290 | when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(true); |
Julia Reynolds | 34f1496 | 2018-05-03 12:40:20 +0000 | [diff] [blame] | 291 | mStackScroller.updateEmptyShadeView(true); |
| 292 | verify(mEmptyShadeView).setText(R.string.dnd_suppressing_shade_text); |
| 293 | } |
| 294 | |
| 295 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 296 | @UiThreadTest |
| 297 | public void testSetExpandedHeight_blockingHelperManagerReceivedCallbacks() { |
| 298 | mStackScroller.setExpandedHeight(0f); |
| 299 | verify(mBlockingHelperManager).setNotificationShadeExpanded(0f); |
| 300 | reset(mBlockingHelperManager); |
| 301 | |
| 302 | mStackScroller.setExpandedHeight(100f); |
| 303 | verify(mBlockingHelperManager).setNotificationShadeExpanded(100f); |
Julia Reynolds | 9cf1756 | 2018-03-14 09:49:35 -0400 | [diff] [blame] | 304 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 305 | |
| 306 | @Test |
Lucas Dupin | 28790c0 | 2020-01-30 14:18:41 -0800 | [diff] [blame] | 307 | public void testOnStatePostChange_verifyIfProfileIsPublic() { |
| 308 | mUserChangedListener.onUserChanged(0); |
| 309 | verify(mLockscreenUserManager).isAnyProfilePublicMode(); |
| 310 | } |
| 311 | |
| 312 | @Test |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 313 | public void manageNotifications_visible() { |
| 314 | FooterView view = mock(FooterView.class); |
| 315 | mStackScroller.setFooterView(view); |
| 316 | when(view.willBeGone()).thenReturn(true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 317 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 318 | mStackScroller.updateFooterView(true, false, true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 319 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 320 | verify(view).setVisible(eq(true), anyBoolean()); |
| 321 | verify(view).setSecondaryVisible(eq(false), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Test |
| 325 | public void clearAll_visible() { |
| 326 | FooterView view = mock(FooterView.class); |
| 327 | mStackScroller.setFooterView(view); |
| 328 | when(view.willBeGone()).thenReturn(true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 329 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 330 | mStackScroller.updateFooterView(true, true, true); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 331 | |
Selim Cinek | d60ef9e | 2018-05-16 16:01:05 -0700 | [diff] [blame] | 332 | verify(view).setVisible(eq(true), anyBoolean()); |
| 333 | verify(view).setSecondaryVisible(eq(true), anyBoolean()); |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 334 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 335 | |
| 336 | @Test |
| 337 | public void testInflateFooterView() { |
| 338 | mStackScroller.inflateFooterView(); |
| 339 | ArgumentCaptor<FooterView> captor = ArgumentCaptor.forClass(FooterView.class); |
| 340 | verify(mStackScroller).setFooterView(captor.capture()); |
| 341 | |
| 342 | assertNotNull(captor.getValue().findViewById(R.id.manage_text).hasOnClickListeners()); |
| 343 | assertNotNull(captor.getValue().findViewById(R.id.dismiss_text).hasOnClickListeners()); |
| 344 | } |
| 345 | |
| 346 | @Test |
| 347 | public void testUpdateFooter_noNotifications() { |
| 348 | setBarStateForTest(StatusBarState.SHADE); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 349 | assertEquals(0, mEntryManager.getActiveNotificationsCount()); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 350 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 351 | FooterView view = mock(FooterView.class); |
| 352 | mStackScroller.setFooterView(view); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 353 | mStackScroller.updateFooter(); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 354 | verify(mStackScroller, atLeastOnce()).updateFooterView(false, false, true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Test |
| 358 | public void testUpdateFooter_remoteInput() { |
| 359 | setBarStateForTest(StatusBarState.SHADE); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 360 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 361 | entries.add(new NotificationEntryBuilder().build()); |
| 362 | addEntriesToEntryManager(entries); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 363 | |
| 364 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 365 | when(row.canViewBeDismissed()).thenReturn(true); |
| 366 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 367 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 368 | when(mRemoteInputController.isRemoteInputActive()).thenReturn(true); |
| 369 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 370 | FooterView view = mock(FooterView.class); |
| 371 | mStackScroller.setFooterView(view); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 372 | mStackScroller.updateFooter(); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 373 | verify(mStackScroller).updateFooterView(false, true, true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Test |
| 377 | public void testUpdateFooter_oneClearableNotification() { |
| 378 | setBarStateForTest(StatusBarState.SHADE); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 379 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 380 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 381 | entries.add(new NotificationEntryBuilder().build()); |
| 382 | addEntriesToEntryManager(entries); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 383 | |
| 384 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
| 385 | when(row.canViewBeDismissed()).thenReturn(true); |
| 386 | when(mStackScroller.getChildCount()).thenReturn(1); |
| 387 | when(mStackScroller.getChildAt(anyInt())).thenReturn(row); |
| 388 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 389 | FooterView view = mock(FooterView.class); |
| 390 | mStackScroller.setFooterView(view); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 391 | mStackScroller.updateFooter(); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 392 | verify(mStackScroller).updateFooterView(true, true, true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | @Test |
| 396 | public void testUpdateFooter_oneNonClearableNotification() { |
| 397 | setBarStateForTest(StatusBarState.SHADE); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 398 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 399 | ArrayList<NotificationEntry> entries = new ArrayList<>(); |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 400 | entries.add(new NotificationEntryBuilder().build()); |
| 401 | addEntriesToEntryManager(entries); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 402 | |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 403 | FooterView view = mock(FooterView.class); |
| 404 | mStackScroller.setFooterView(view); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 405 | mStackScroller.updateFooter(); |
Julia Reynolds | da7c245 | 2020-04-16 16:44:58 -0400 | [diff] [blame] | 406 | verify(mStackScroller).updateFooterView(true, false, true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | @Test |
| 410 | public void testUpdateFooter_atEnd() { |
| 411 | // add footer |
| 412 | mStackScroller.inflateFooterView(); |
| 413 | |
| 414 | // add notification |
| 415 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 416 | NotificationEntry entry = mock(NotificationEntry.class); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 417 | when(row.getEntry()).thenReturn(entry); |
| 418 | when(entry.isClearable()).thenReturn(true); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 419 | mStackScroller.addContainerView(row); |
| 420 | |
| 421 | mStackScroller.onUpdateRowStates(); |
| 422 | |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 423 | // Expecting the footer to be the last child |
| 424 | int expected = mStackScroller.getChildCount() - 1; |
| 425 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 426 | // move footer to end |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 427 | verify(mStackScroller).changeViewPosition(any(FooterView.class), eq(expected)); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | @Test |
| 431 | public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() { |
| 432 | clearInvocations(mStackScroller); |
| 433 | mStackScroller.onDensityOrFontScaleChanged(); |
| 434 | verify(mStackScroller).setFooterView(any()); |
| 435 | verify(mStackScroller).setEmptyShadeView(any()); |
| 436 | } |
| 437 | |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 438 | @Test |
| 439 | @UiThreadTest |
| 440 | public void testSetIsBeingDraggedResetsExposedMenu() { |
| 441 | NotificationSwipeHelper swipeActionHelper = |
| 442 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 443 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
| 444 | mStackScroller.setIsBeingDragged(true); |
| 445 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 446 | } |
| 447 | |
| 448 | @Test |
| 449 | @UiThreadTest |
| 450 | public void testPanelTrackingStartResetsExposedMenu() { |
| 451 | NotificationSwipeHelper swipeActionHelper = |
| 452 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 453 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
| 454 | mStackScroller.onPanelTrackingStarted(); |
| 455 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 456 | } |
| 457 | |
| 458 | @Test |
| 459 | @UiThreadTest |
| 460 | public void testDarkModeResetsExposedMenu() { |
| 461 | NotificationSwipeHelper swipeActionHelper = |
| 462 | (NotificationSwipeHelper) mStackScroller.getSwipeActionHelper(); |
| 463 | swipeActionHelper.setExposedMenuView(new View(mContext)); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 464 | mStackScroller.setHideAmount(0.1f, 0.1f); |
Gus Prevas | 99ba4ba | 2018-10-01 16:40:23 -0400 | [diff] [blame] | 465 | assertNull(swipeActionHelper.getExposedMenuView()); |
| 466 | } |
| 467 | |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 468 | class LogMatcher implements ArgumentMatcher<LogMaker> { |
| 469 | private int mCategory, mType; |
| 470 | |
| 471 | LogMatcher(int category, int type) { |
| 472 | mCategory = category; |
| 473 | mType = type; |
| 474 | } |
| 475 | public boolean matches(LogMaker l) { |
| 476 | return (l.getCategory() == mCategory) |
| 477 | && (l.getType() == mType); |
| 478 | } |
| 479 | |
| 480 | public String toString() { |
| 481 | return String.format("LogMaker(%d, %d)", mCategory, mType); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | private LogMaker logMatcher(int category, int type) { |
| 486 | return argThat(new LogMatcher(category, type)); |
| 487 | } |
| 488 | |
| 489 | @Test |
| 490 | @UiThreadTest |
| 491 | public void testOnMenuClickedLogging() { |
| 492 | // Set up the object under test to have a valid mLongPressListener. We're testing an |
| 493 | // anonymous-class member, mMenuEventListener, so we need to modify the state of the |
| 494 | // class itself, not the Mockito spy copied from it. See notes in setup. |
| 495 | mStackScrollerInternal.setLongPressListener( |
| 496 | mock(ExpandableNotificationRow.LongPressListener.class)); |
| 497 | |
| 498 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 499 | when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker( |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 500 | MetricsProto.MetricsEvent.VIEW_UNKNOWN)); |
| 501 | |
| 502 | mStackScroller.mMenuEventListener.onMenuClicked(row, 0, 0, mock( |
| 503 | NotificationMenuRowPlugin.MenuItem.class)); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 504 | verify(row.getEntry().getSbn()).getLogMaker(); // This writes most of the log data |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 505 | verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_TOUCH_GEAR, |
| 506 | MetricsProto.MetricsEvent.TYPE_ACTION)); |
| 507 | } |
| 508 | |
| 509 | @Test |
| 510 | @UiThreadTest |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 511 | public void testOnMenuShownLogging() { ; |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 512 | |
| 513 | ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 514 | when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker( |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 515 | MetricsProto.MetricsEvent.VIEW_UNKNOWN)); |
| 516 | |
| 517 | mStackScroller.mMenuEventListener.onMenuShown(row); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 518 | verify(row.getEntry().getSbn()).getLogMaker(); // This writes most of the log data |
Will Brockman | e718d58 | 2019-01-17 16:38:38 -0500 | [diff] [blame] | 519 | verify(mMetricsLogger).write(logMatcher(MetricsProto.MetricsEvent.ACTION_REVEAL_GEAR, |
| 520 | MetricsProto.MetricsEvent.TYPE_ACTION)); |
| 521 | } |
| 522 | |
Will Brockman | b65faa8 | 2020-03-06 10:26:04 -0500 | [diff] [blame] | 523 | @Test |
| 524 | public void testClearNotifications_All() { |
| 525 | mStackScroller.clearNotifications(NotificationStackScrollLayout.ROWS_ALL, true); |
| 526 | assertEquals(1, mUiEventLoggerFake.numLogs()); |
| 527 | assertEquals(NotificationStackScrollLayout.NotificationPanelEvent |
| 528 | .DISMISS_ALL_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0)); |
| 529 | } |
| 530 | |
| 531 | @Test |
| 532 | public void testClearNotifications_Gentle() { |
| 533 | mStackScroller.clearNotifications(NotificationStackScrollLayout.ROWS_GENTLE, false); |
| 534 | assertEquals(1, mUiEventLoggerFake.numLogs()); |
| 535 | assertEquals(NotificationStackScrollLayout.NotificationPanelEvent |
| 536 | .DISMISS_SILENT_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0)); |
| 537 | } |
| 538 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 539 | private void setBarStateForTest(int state) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 540 | // Can't inject this through the listener or we end up on the actual implementation |
| 541 | // rather than the mock because the spy just coppied the anonymous inner /shruggie. |
| 542 | mStackScroller.setStatusBarState(state); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 543 | } |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 544 | |
| 545 | private void addEntriesToEntryManager(List<NotificationEntry> entries) { |
| 546 | for (NotificationEntry e : entries) { |
| 547 | mEntryManager.addActiveNotificationForTest(e); |
| 548 | } |
| 549 | } |
Selim Cinek | 8a9308d | 2017-08-24 09:31:08 -0700 | [diff] [blame] | 550 | } |