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