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