Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.bubbles; |
| 18 | |
| 19 | import static android.app.Notification.FLAG_BUBBLE; |
| 20 | import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED; |
| 21 | |
| 22 | import static com.google.common.truth.Truth.assertThat; |
| 23 | |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | import static org.junit.Assert.assertFalse; |
| 26 | import static org.junit.Assert.assertNotNull; |
| 27 | import static org.junit.Assert.assertNull; |
| 28 | import static org.junit.Assert.assertTrue; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 29 | import static org.mockito.ArgumentMatchers.anyInt; |
| 30 | import static org.mockito.ArgumentMatchers.anyString; |
| 31 | import static org.mockito.ArgumentMatchers.eq; |
| 32 | import static org.mockito.Mockito.atLeastOnce; |
| 33 | import static org.mockito.Mockito.mock; |
| 34 | import static org.mockito.Mockito.never; |
| 35 | import static org.mockito.Mockito.times; |
| 36 | import static org.mockito.Mockito.verify; |
| 37 | import static org.mockito.Mockito.when; |
| 38 | |
| 39 | import android.app.IActivityManager; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame] | 40 | import android.app.INotificationManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 41 | import android.app.Notification; |
| 42 | import android.app.PendingIntent; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 43 | import android.content.res.Resources; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 44 | import android.hardware.display.AmbientDisplayConfiguration; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 45 | import android.hardware.face.FaceManager; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 46 | import android.os.Handler; |
| 47 | import android.os.PowerManager; |
| 48 | import android.service.dreams.IDreamManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 49 | import android.service.notification.ZenModeConfig; |
| 50 | import android.testing.AndroidTestingRunner; |
| 51 | import android.testing.TestableLooper; |
| 52 | import android.view.WindowManager; |
| 53 | |
| 54 | import androidx.test.filters.SmallTest; |
| 55 | |
| 56 | import com.android.internal.colorextraction.ColorExtractor; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 57 | import com.android.systemui.SystemUIFactory; |
| 58 | import com.android.systemui.SysuiTestCase; |
| 59 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 60 | import com.android.systemui.dump.DumpManager; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 61 | import com.android.systemui.model.SysUiState; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 62 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 63 | import com.android.systemui.statusbar.FeatureFlags; |
| 64 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.SuperStatusBarViewFactory; |
| 66 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
| 67 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 68 | import com.android.systemui.statusbar.notification.NotificationFilter; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.collection.NotifPipeline; |
| 70 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 71 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; |
| 72 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
| 73 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 74 | import com.android.systemui.statusbar.notification.row.NotificationTestHelper; |
| 75 | import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent; |
| 76 | import com.android.systemui.statusbar.phone.DozeParameters; |
| 77 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.LockscreenLockIconController; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 79 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
| 80 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 81 | import com.android.systemui.statusbar.phone.NotificationShadeWindowView; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 82 | import com.android.systemui.statusbar.phone.ShadeController; |
| 83 | import com.android.systemui.statusbar.policy.BatteryController; |
| 84 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 85 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 86 | import com.android.systemui.statusbar.policy.ZenModeController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 87 | import com.android.systemui.util.FloatingContentCoordinator; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 88 | import com.android.systemui.util.InjectionInflationController; |
| 89 | |
| 90 | import org.junit.Before; |
| 91 | import org.junit.Test; |
| 92 | import org.junit.runner.RunWith; |
| 93 | import org.mockito.ArgumentCaptor; |
| 94 | import org.mockito.Captor; |
| 95 | import org.mockito.Mock; |
| 96 | import org.mockito.MockitoAnnotations; |
| 97 | |
| 98 | import java.util.List; |
| 99 | |
| 100 | /** |
| 101 | * Tests the NotifPipeline setup with BubbleController. |
| 102 | * The NotificationEntryManager setup with BubbleController is tested in |
| 103 | * {@link BubbleControllerTest}. |
| 104 | */ |
| 105 | @SmallTest |
| 106 | @RunWith(AndroidTestingRunner.class) |
| 107 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 108 | public class NewNotifPipelineBubbleControllerTest extends SysuiTestCase { |
| 109 | @Mock |
| 110 | private NotificationEntryManager mNotificationEntryManager; |
| 111 | @Mock |
| 112 | private NotificationGroupManager mNotificationGroupManager; |
| 113 | @Mock |
| 114 | private BubbleController.NotifCallback mNotifCallback; |
| 115 | @Mock |
| 116 | private WindowManager mWindowManager; |
| 117 | @Mock |
| 118 | private IActivityManager mActivityManager; |
| 119 | @Mock |
| 120 | private DozeParameters mDozeParameters; |
| 121 | @Mock |
| 122 | private ConfigurationController mConfigurationController; |
| 123 | @Mock |
| 124 | private ZenModeController mZenModeController; |
| 125 | @Mock |
| 126 | private ZenModeConfig mZenModeConfig; |
| 127 | @Mock |
| 128 | private FaceManager mFaceManager; |
| 129 | @Mock |
| 130 | private NotificationLockscreenUserManager mLockscreenUserManager; |
| 131 | @Mock |
| 132 | private SysuiStatusBarStateController mStatusBarStateController; |
| 133 | @Mock |
| 134 | private KeyguardBypassController mKeyguardBypassController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 135 | @Mock |
| 136 | private FloatingContentCoordinator mFloatingContentCoordinator; |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 137 | @Mock |
Pinyao Ting | ee191b1 | 2020-04-29 18:35:39 -0700 | [diff] [blame] | 138 | private BubbleDataRepository mDataRepository; |
| 139 | @Mock |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 140 | private NotificationShadeWindowView mNotificationShadeWindowView; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 141 | |
| 142 | private SysUiState mSysUiState = new SysUiState(); |
| 143 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 144 | @Captor |
| 145 | private ArgumentCaptor<NotifCollectionListener> mNotifListenerCaptor; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 146 | private TestableBubbleController mBubbleController; |
| 147 | private NotificationShadeWindowController mNotificationShadeWindowController; |
| 148 | private NotifCollectionListener mEntryListener; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 149 | private NotificationTestHelper mNotificationTestHelper; |
| 150 | private ExpandableNotificationRow mRow; |
| 151 | private ExpandableNotificationRow mRow2; |
| 152 | private ExpandableNotificationRow mNonBubbleNotifRow; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 153 | @Mock |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 154 | private BubbleController.BubbleExpandListener mBubbleExpandListener; |
| 155 | @Mock |
| 156 | private PendingIntent mDeleteIntent; |
| 157 | @Mock |
| 158 | private SysuiColorExtractor mColorExtractor; |
| 159 | @Mock |
| 160 | ColorExtractor.GradientColors mGradientColors; |
| 161 | @Mock |
| 162 | private Resources mResources; |
| 163 | @Mock |
| 164 | private ShadeController mShadeController; |
| 165 | @Mock |
| 166 | private NotificationRowComponent mNotificationRowComponent; |
| 167 | @Mock |
| 168 | private NotifPipeline mNotifPipeline; |
| 169 | @Mock |
| 170 | private FeatureFlags mFeatureFlagsNewPipeline; |
| 171 | @Mock |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 172 | private DumpManager mDumpManager; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 173 | @Mock |
| 174 | private LockscreenLockIconController mLockIconController; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 175 | |
| 176 | private SuperStatusBarViewFactory mSuperStatusBarViewFactory; |
| 177 | private BubbleData mBubbleData; |
| 178 | |
| 179 | private TestableLooper mTestableLooper; |
| 180 | |
| 181 | @Before |
| 182 | public void setUp() throws Exception { |
| 183 | MockitoAnnotations.initMocks(this); |
| 184 | |
| 185 | mTestableLooper = TestableLooper.get(this); |
| 186 | |
| 187 | mContext.addMockSystemService(FaceManager.class, mFaceManager); |
| 188 | when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); |
| 189 | |
| 190 | mSuperStatusBarViewFactory = new SuperStatusBarViewFactory(mContext, |
| 191 | new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()), |
| 192 | new NotificationRowComponent.Builder() { |
| 193 | @Override |
| 194 | public NotificationRowComponent.Builder activatableNotificationView( |
| 195 | ActivatableNotificationView view) { |
| 196 | return this; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public NotificationRowComponent build() { |
| 201 | return mNotificationRowComponent; |
| 202 | } |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 203 | }, |
| 204 | mLockIconController); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 205 | |
| 206 | // Bubbles get added to status bar window view |
| 207 | mNotificationShadeWindowController = new NotificationShadeWindowController(mContext, |
| 208 | mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, |
Lucas Dupin | d73410a | 2020-02-18 12:54:41 -0800 | [diff] [blame] | 209 | mConfigurationController, mKeyguardBypassController, mColorExtractor, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 210 | mDumpManager); |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 211 | mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 212 | mNotificationShadeWindowController.attach(); |
| 213 | |
| 214 | // Need notifications for bubbles |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 215 | mNotificationTestHelper = new NotificationTestHelper( |
| 216 | mContext, |
| 217 | mDependency, |
| 218 | TestableLooper.get(this)); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 219 | mRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 220 | mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 221 | mNonBubbleNotifRow = mNotificationTestHelper.createRow(); |
| 222 | |
| 223 | mZenModeConfig.suppressedVisualEffects = 0; |
| 224 | when(mZenModeController.getConfig()).thenReturn(mZenModeConfig); |
| 225 | |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 226 | TestableNotificationInterruptStateProviderImpl interruptionStateProvider = |
| 227 | new TestableNotificationInterruptStateProviderImpl(mContext.getContentResolver(), |
| 228 | mock(PowerManager.class), |
| 229 | mock(IDreamManager.class), |
| 230 | mock(AmbientDisplayConfiguration.class), |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 231 | mock(NotificationFilter.class), |
| 232 | mock(StatusBarStateController.class), |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 233 | mock(BatteryController.class), |
| 234 | mock(HeadsUpManager.class), |
| 235 | mock(Handler.class) |
| 236 | ); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 237 | mBubbleData = new BubbleData(mContext); |
| 238 | when(mFeatureFlagsNewPipeline.isNewNotifPipelineRenderingEnabled()).thenReturn(true); |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 239 | mBubbleController = new TestableBubbleController( |
| 240 | mContext, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 241 | mNotificationShadeWindowController, |
| 242 | mStatusBarStateController, |
| 243 | mShadeController, |
| 244 | mBubbleData, |
| 245 | mConfigurationController, |
| 246 | interruptionStateProvider, |
| 247 | mZenModeController, |
| 248 | mLockscreenUserManager, |
| 249 | mNotificationGroupManager, |
| 250 | mNotificationEntryManager, |
| 251 | mNotifPipeline, |
| 252 | mFeatureFlagsNewPipeline, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 253 | mDumpManager, |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 254 | mFloatingContentCoordinator, |
Pinyao Ting | ee191b1 | 2020-04-29 18:35:39 -0700 | [diff] [blame] | 255 | mDataRepository, |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame] | 256 | mSysUiState, |
Mady Mellor | 59a7b98 | 2020-05-11 15:19:59 -0700 | [diff] [blame] | 257 | mock(INotificationManager.class), |
| 258 | mWindowManager); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 259 | mBubbleController.addNotifCallback(mNotifCallback); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 260 | mBubbleController.setExpandListener(mBubbleExpandListener); |
| 261 | |
| 262 | // Get a reference to the BubbleController's entry listener |
| 263 | verify(mNotifPipeline, atLeastOnce()) |
| 264 | .addCollectionListener(mNotifListenerCaptor.capture()); |
| 265 | mEntryListener = mNotifListenerCaptor.getValue(); |
| 266 | } |
| 267 | |
| 268 | @Test |
| 269 | public void testAddBubble() { |
| 270 | mBubbleController.updateBubble(mRow.getEntry()); |
| 271 | assertTrue(mBubbleController.hasBubbles()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Test |
| 275 | public void testHasBubbles() { |
| 276 | assertFalse(mBubbleController.hasBubbles()); |
| 277 | mBubbleController.updateBubble(mRow.getEntry()); |
| 278 | assertTrue(mBubbleController.hasBubbles()); |
| 279 | } |
| 280 | |
| 281 | @Test |
| 282 | public void testRemoveBubble() { |
| 283 | mBubbleController.updateBubble(mRow.getEntry()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 284 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 285 | assertTrue(mBubbleController.hasBubbles()); |
| 286 | verify(mNotifCallback, times(1)).invalidateNotifications(anyString()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 287 | |
| 288 | mBubbleController.removeBubble(mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 289 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 290 | verify(mNotifCallback, times(2)).invalidateNotifications(anyString()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Test |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 294 | public void testRemoveBubble_withDismissedNotif_inOverflow() { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 295 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 296 | mBubbleController.updateBubble(mRow.getEntry()); |
| 297 | |
| 298 | assertTrue(mBubbleController.hasBubbles()); |
| 299 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow.getEntry())); |
| 300 | |
| 301 | // Make it look like dismissed notif |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 302 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).setSuppressNotification(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 303 | |
| 304 | // Now remove the bubble |
| 305 | mBubbleController.removeBubble(mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 306 | assertTrue(mBubbleData.hasOverflowBubbleWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 307 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 308 | // We don't remove the notification since the bubble is still in overflow. |
| 309 | verify(mNotifCallback, never()).removeNotification(eq(mRow.getEntry()), anyInt()); |
| 310 | assertFalse(mBubbleController.hasBubbles()); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testRemoveBubble_withDismissedNotif_notInOverflow() { |
| 315 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 316 | mBubbleController.updateBubble(mRow.getEntry()); |
| 317 | |
| 318 | assertTrue(mBubbleController.hasBubbles()); |
| 319 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow.getEntry())); |
| 320 | |
| 321 | // Make it look like dismissed notif |
| 322 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).setSuppressNotification(true); |
| 323 | |
| 324 | // Now remove the bubble |
| 325 | mBubbleController.removeBubble(mRow.getEntry(), BubbleController.DISMISS_NOTIF_CANCEL); |
| 326 | assertFalse(mBubbleData.hasOverflowBubbleWithKey(mRow.getEntry().getKey())); |
| 327 | |
| 328 | // Since the notif is dismissed and not in overflow, once the bubble is removed, |
| 329 | // removeNotification gets called to really remove the notif |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 330 | verify(mNotifCallback, times(1)).removeNotification(eq(mRow.getEntry()), anyInt()); |
| 331 | assertFalse(mBubbleController.hasBubbles()); |
| 332 | } |
| 333 | |
| 334 | @Test |
| 335 | public void testDismissStack() { |
| 336 | mBubbleController.updateBubble(mRow.getEntry()); |
| 337 | verify(mNotifCallback, times(1)).invalidateNotifications(anyString()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 338 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 339 | mBubbleController.updateBubble(mRow2.getEntry()); |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 340 | verify(mNotifCallback, times(2)).invalidateNotifications(anyString()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 341 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow2.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 342 | assertTrue(mBubbleController.hasBubbles()); |
| 343 | |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 344 | mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 345 | verify(mNotifCallback, times(3)).invalidateNotifications(anyString()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 346 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
| 347 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow2.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | @Test |
| 351 | public void testExpandCollapseStack() { |
| 352 | assertFalse(mBubbleController.isStackExpanded()); |
| 353 | |
| 354 | // Mark it as a bubble and add it explicitly |
| 355 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 356 | mBubbleController.updateBubble(mRow.getEntry()); |
| 357 | |
| 358 | // We should have bubbles & their notifs should not be suppressed |
| 359 | assertTrue(mBubbleController.hasBubbles()); |
| 360 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 361 | mRow.getEntry())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 362 | |
| 363 | // Expand the stack |
| 364 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 365 | mBubbleData.setExpanded(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 366 | assertTrue(mBubbleController.isStackExpanded()); |
| 367 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 368 | |
| 369 | // Make sure the notif is suppressed |
| 370 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow.getEntry())); |
| 371 | |
| 372 | // Collapse |
| 373 | mBubbleController.collapseStack(); |
| 374 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
| 375 | assertFalse(mBubbleController.isStackExpanded()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | @Test |
| 379 | public void testCollapseAfterChangingExpandedBubble() { |
| 380 | // Mark it as a bubble and add it explicitly |
| 381 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 382 | mEntryListener.onEntryAdded(mRow2.getEntry()); |
| 383 | mBubbleController.updateBubble(mRow.getEntry()); |
| 384 | mBubbleController.updateBubble(mRow2.getEntry()); |
| 385 | |
| 386 | // We should have bubbles & their notifs should not be suppressed |
| 387 | assertTrue(mBubbleController.hasBubbles()); |
| 388 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 389 | mRow.getEntry())); |
| 390 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 391 | mRow2.getEntry())); |
| 392 | |
| 393 | // Expand |
| 394 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 395 | mBubbleData.setExpanded(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 396 | assertTrue(mBubbleController.isStackExpanded()); |
| 397 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey()); |
| 398 | |
| 399 | // Last added is the one that is expanded |
| 400 | assertEquals(mRow2.getEntry(), mBubbleData.getSelectedBubble().getEntry()); |
| 401 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow2.getEntry())); |
| 402 | |
| 403 | // Switch which bubble is expanded |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 404 | mBubbleData.setSelectedBubble(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 405 | mBubbleData.setExpanded(true); |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 406 | assertEquals(mRow.getEntry(), |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 407 | mBubbleData.getBubbleInStackWithKey(stackView.getExpandedBubble().getKey()).getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 408 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 409 | mRow.getEntry())); |
| 410 | |
| 411 | // collapse for previous bubble |
| 412 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey()); |
| 413 | // expand for selected bubble |
| 414 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
| 415 | |
| 416 | // Collapse |
| 417 | mBubbleController.collapseStack(); |
| 418 | assertFalse(mBubbleController.isStackExpanded()); |
| 419 | } |
| 420 | |
| 421 | @Test |
| 422 | public void testExpansionRemovesShowInShadeAndDot() { |
| 423 | // Mark it as a bubble and add it explicitly |
| 424 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 425 | mBubbleController.updateBubble(mRow.getEntry()); |
| 426 | |
| 427 | // We should have bubbles & their notifs should not be suppressed |
| 428 | assertTrue(mBubbleController.hasBubbles()); |
| 429 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow.getEntry())); |
| 430 | |
| 431 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 432 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 433 | |
| 434 | // Expand |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 435 | mBubbleData.setExpanded(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 436 | assertTrue(mBubbleController.isStackExpanded()); |
| 437 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
| 438 | |
| 439 | // Notif is suppressed after expansion |
| 440 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 441 | mRow.getEntry())); |
| 442 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 443 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | @Test |
| 447 | public void testUpdateWhileExpanded_DoesntChangeShowInShadeAndDot() { |
| 448 | // Mark it as a bubble and add it explicitly |
| 449 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 450 | mBubbleController.updateBubble(mRow.getEntry()); |
| 451 | |
| 452 | // We should have bubbles & their notifs should not be suppressed |
| 453 | assertTrue(mBubbleController.hasBubbles()); |
| 454 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 455 | mRow.getEntry())); |
| 456 | |
| 457 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 458 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 459 | |
| 460 | // Expand |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 461 | mBubbleData.setExpanded(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 462 | assertTrue(mBubbleController.isStackExpanded()); |
| 463 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
| 464 | |
| 465 | // Notif is suppressed after expansion |
| 466 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 467 | mRow.getEntry())); |
| 468 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 469 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 470 | |
| 471 | // Send update |
| 472 | mEntryListener.onEntryUpdated(mRow.getEntry()); |
| 473 | |
| 474 | // Nothing should have changed |
| 475 | // Notif is suppressed after expansion |
| 476 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 477 | mRow.getEntry())); |
| 478 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 479 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Test |
| 483 | public void testRemoveLastExpandedCollapses() { |
| 484 | // Mark it as a bubble and add it explicitly |
| 485 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 486 | mEntryListener.onEntryAdded(mRow2.getEntry()); |
| 487 | mBubbleController.updateBubble(mRow.getEntry()); |
| 488 | mBubbleController.updateBubble(mRow2.getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 489 | |
| 490 | // Expand |
| 491 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 492 | mBubbleData.setExpanded(true); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 493 | |
| 494 | assertTrue(mBubbleController.isStackExpanded()); |
| 495 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey()); |
| 496 | |
| 497 | // Last added is the one that is expanded |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 498 | assertEquals(mRow2.getEntry(), |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 499 | mBubbleData.getBubbleInStackWithKey(stackView.getExpandedBubble().getKey()).getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 500 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 501 | mRow2.getEntry())); |
| 502 | |
| 503 | // Dismiss currently expanded |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 504 | mBubbleController.removeBubble( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 505 | mBubbleData.getBubbleInStackWithKey(stackView.getExpandedBubble().getKey()).getEntry(), |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 506 | BubbleController.DISMISS_USER_GESTURE); |
| 507 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey()); |
| 508 | |
| 509 | // Make sure first bubble is selected |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 510 | assertEquals(mRow.getEntry(), |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 511 | mBubbleData.getBubbleInStackWithKey(stackView.getExpandedBubble().getKey()).getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 512 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
| 513 | |
| 514 | // Dismiss that one |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 515 | mBubbleController.removeBubble( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 516 | mBubbleData.getBubbleInStackWithKey(stackView.getExpandedBubble().getKey()).getEntry(), |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 517 | BubbleController.DISMISS_USER_GESTURE); |
| 518 | |
| 519 | // Make sure state changes and collapse happens |
| 520 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 521 | assertFalse(mBubbleController.hasBubbles()); |
| 522 | } |
| 523 | |
| 524 | @Test |
| 525 | public void testAutoExpand_fails_noFlag() { |
| 526 | assertFalse(mBubbleController.isStackExpanded()); |
| 527 | setMetadataFlags(mRow.getEntry(), |
| 528 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */); |
| 529 | |
| 530 | // Add the auto expand bubble |
| 531 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 532 | mBubbleController.updateBubble(mRow.getEntry()); |
| 533 | |
| 534 | // Expansion shouldn't change |
| 535 | verify(mBubbleExpandListener, never()).onBubbleExpandChanged(false /* expanded */, |
| 536 | mRow.getEntry().getKey()); |
| 537 | assertFalse(mBubbleController.isStackExpanded()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | @Test |
| 541 | public void testAutoExpand_succeeds_withFlag() { |
| 542 | setMetadataFlags(mRow.getEntry(), |
| 543 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */); |
| 544 | |
| 545 | // Add the auto expand bubble |
| 546 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 547 | mBubbleController.updateBubble(mRow.getEntry()); |
| 548 | |
| 549 | // Expansion should change |
| 550 | verify(mBubbleExpandListener).onBubbleExpandChanged(true /* expanded */, |
| 551 | mRow.getEntry().getKey()); |
| 552 | assertTrue(mBubbleController.isStackExpanded()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | @Test |
| 556 | public void testSuppressNotif_onInitialNotif() { |
| 557 | setMetadataFlags(mRow.getEntry(), |
| 558 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
| 559 | |
| 560 | // Add the suppress notif bubble |
| 561 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 562 | mBubbleController.updateBubble(mRow.getEntry()); |
| 563 | |
| 564 | // Notif should be suppressed because we were foreground |
| 565 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 566 | mRow.getEntry())); |
| 567 | // Dot + flyout is hidden because notif is suppressed |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 568 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
| 569 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showFlyout()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | @Test |
| 573 | public void testSuppressNotif_onUpdateNotif() { |
| 574 | mBubbleController.updateBubble(mRow.getEntry()); |
| 575 | |
| 576 | // Should not be suppressed |
| 577 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 578 | mRow.getEntry())); |
| 579 | // Should show dot |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 580 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 581 | |
| 582 | // Update to suppress notif |
| 583 | setMetadataFlags(mRow.getEntry(), |
| 584 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
| 585 | mBubbleController.updateBubble(mRow.getEntry()); |
| 586 | |
| 587 | // Notif should be suppressed |
| 588 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 589 | mRow.getEntry())); |
| 590 | // Dot + flyout is hidden because notif is suppressed |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 591 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
| 592 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showFlyout()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | @Test |
| 596 | public void testMarkNewNotificationAsShowInShade() { |
| 597 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 598 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 599 | mRow.getEntry())); |
| 600 | |
| 601 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 602 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | @Test |
| 606 | public void testAddNotif_notBubble() { |
| 607 | mEntryListener.onEntryAdded(mNonBubbleNotifRow.getEntry()); |
| 608 | mEntryListener.onEntryUpdated(mNonBubbleNotifRow.getEntry()); |
| 609 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 610 | assertThat(mBubbleController.hasBubbles()).isFalse(); |
| 611 | } |
| 612 | |
| 613 | @Test |
| 614 | public void testDeleteIntent_removeBubble_aged() throws PendingIntent.CanceledException { |
| 615 | mBubbleController.updateBubble(mRow.getEntry()); |
| 616 | mBubbleController.removeBubble(mRow.getEntry(), BubbleController.DISMISS_AGED); |
| 617 | verify(mDeleteIntent, never()).send(); |
| 618 | } |
| 619 | |
| 620 | @Test |
| 621 | public void testDeleteIntent_removeBubble_user() throws PendingIntent.CanceledException { |
| 622 | mBubbleController.updateBubble(mRow.getEntry()); |
| 623 | mBubbleController.removeBubble( |
| 624 | mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE); |
| 625 | verify(mDeleteIntent, times(1)).send(); |
| 626 | } |
| 627 | |
| 628 | @Test |
| 629 | public void testDeleteIntent_dismissStack() throws PendingIntent.CanceledException { |
| 630 | mBubbleController.updateBubble(mRow.getEntry()); |
| 631 | mBubbleController.updateBubble(mRow2.getEntry()); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 632 | mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 633 | verify(mDeleteIntent, times(2)).send(); |
| 634 | } |
| 635 | |
| 636 | @Test |
| 637 | public void testRemoveBubble_noLongerBubbleAfterUpdate() |
| 638 | throws PendingIntent.CanceledException { |
| 639 | mBubbleController.updateBubble(mRow.getEntry()); |
| 640 | assertTrue(mBubbleController.hasBubbles()); |
| 641 | |
| 642 | mRow.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
| 643 | mEntryListener.onEntryUpdated(mRow.getEntry()); |
| 644 | |
| 645 | assertFalse(mBubbleController.hasBubbles()); |
| 646 | verify(mDeleteIntent, never()).send(); |
| 647 | } |
| 648 | |
| 649 | @Test |
| 650 | public void testRemoveBubble_entryListenerRemove() { |
| 651 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 652 | mBubbleController.updateBubble(mRow.getEntry()); |
| 653 | |
| 654 | assertTrue(mBubbleController.hasBubbles()); |
| 655 | |
| 656 | // Removes the notification |
| 657 | mEntryListener.onEntryRemoved(mRow.getEntry(), 0); |
| 658 | assertFalse(mBubbleController.hasBubbles()); |
| 659 | } |
| 660 | |
| 661 | @Test |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 662 | public void removeBubble_intercepted() { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 663 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 664 | mBubbleController.updateBubble(mRow.getEntry()); |
| 665 | |
| 666 | assertTrue(mBubbleController.hasBubbles()); |
| 667 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 668 | mRow.getEntry())); |
| 669 | |
| 670 | boolean intercepted = mBubbleController.handleDismissalInterception(mRow.getEntry()); |
| 671 | |
| 672 | // Intercept! |
| 673 | assertTrue(intercepted); |
| 674 | // Should update show in shade state |
| 675 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(mRow.getEntry())); |
| 676 | } |
| 677 | |
| 678 | @Test |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 679 | public void removeBubble_dismissIntoOverflow_intercepted() { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 680 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 681 | mBubbleController.updateBubble(mRow.getEntry()); |
| 682 | |
| 683 | assertTrue(mBubbleController.hasBubbles()); |
| 684 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 685 | mRow.getEntry())); |
| 686 | |
| 687 | // Dismiss the bubble |
| 688 | mBubbleController.removeBubble( |
| 689 | mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE); |
| 690 | assertFalse(mBubbleController.hasBubbles()); |
| 691 | |
| 692 | // Dismiss the notification |
| 693 | boolean intercepted = mBubbleController.handleDismissalInterception(mRow.getEntry()); |
| 694 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 695 | // Intercept dismissal since bubble is going into overflow |
| 696 | assertTrue(intercepted); |
| 697 | } |
| 698 | |
| 699 | @Test |
| 700 | public void removeBubble_notIntercepted() { |
| 701 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 702 | mBubbleController.updateBubble(mRow.getEntry()); |
| 703 | |
| 704 | assertTrue(mBubbleController.hasBubbles()); |
| 705 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 706 | mRow.getEntry())); |
| 707 | |
| 708 | // Dismiss the bubble |
| 709 | mBubbleController.removeBubble( |
| 710 | mRow.getEntry(), BubbleController.DISMISS_NOTIF_CANCEL); |
| 711 | assertFalse(mBubbleController.hasBubbles()); |
| 712 | |
| 713 | // Dismiss the notification |
| 714 | boolean intercepted = mBubbleController.handleDismissalInterception(mRow.getEntry()); |
| 715 | |
| 716 | // Not a bubble anymore so we don't intercept dismissal. |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 717 | assertFalse(intercepted); |
| 718 | } |
| 719 | |
| 720 | @Test |
| 721 | public void testNotifyShadeSuppressionChange_notificationDismiss() { |
| 722 | BubbleController.NotificationSuppressionChangedListener listener = |
| 723 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 724 | mBubbleData.setSuppressionChangedListener(listener); |
| 725 | |
| 726 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 727 | |
| 728 | assertTrue(mBubbleController.hasBubbles()); |
| 729 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 730 | mRow.getEntry())); |
| 731 | |
| 732 | mBubbleController.handleDismissalInterception(mRow.getEntry()); |
| 733 | |
| 734 | // Should update show in shade state |
| 735 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 736 | mRow.getEntry())); |
| 737 | |
| 738 | // Should notify delegate that shade state changed |
| 739 | verify(listener).onBubbleNotificationSuppressionChange( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 740 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | @Test |
| 744 | public void testNotifyShadeSuppressionChange_bubbleExpanded() { |
| 745 | BubbleController.NotificationSuppressionChangedListener listener = |
| 746 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 747 | mBubbleData.setSuppressionChangedListener(listener); |
| 748 | |
| 749 | mEntryListener.onEntryAdded(mRow.getEntry()); |
| 750 | |
| 751 | assertTrue(mBubbleController.hasBubbles()); |
| 752 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 753 | mRow.getEntry())); |
| 754 | |
| 755 | mBubbleData.setExpanded(true); |
| 756 | |
| 757 | // Once a bubble is expanded the notif is suppressed |
| 758 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 759 | mRow.getEntry())); |
| 760 | |
| 761 | // Should notify delegate that shade state changed |
| 762 | verify(listener).onBubbleNotificationSuppressionChange( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 763 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | @Test |
| 767 | public void testBubbleSummaryDismissal_suppressesSummaryAndBubbleFromShade() throws Exception { |
| 768 | // GIVEN a group summary with a bubble child |
| 769 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0); |
| 770 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
| 771 | mEntryListener.onEntryAdded(groupedBubble.getEntry()); |
| 772 | groupSummary.addChildNotification(groupedBubble); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 773 | assertTrue(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 774 | |
| 775 | // WHEN the summary is dismissed |
| 776 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 777 | |
| 778 | // THEN the summary and bubbled child are suppressed from the shade |
| 779 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 780 | groupedBubble.getEntry())); |
| 781 | assertTrue(mBubbleData.isSummarySuppressed(groupSummary.getEntry().getSbn().getGroupKey())); |
| 782 | } |
| 783 | |
| 784 | @Test |
| 785 | public void testAppRemovesSummary_removesAllBubbleChildren() throws Exception { |
| 786 | // GIVEN a group summary with a bubble child |
| 787 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0); |
| 788 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
| 789 | mEntryListener.onEntryAdded(groupedBubble.getEntry()); |
| 790 | groupSummary.addChildNotification(groupedBubble); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 791 | assertTrue(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 792 | |
| 793 | // GIVEN the summary is dismissed |
| 794 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 795 | |
| 796 | // WHEN the summary is cancelled by the app |
| 797 | mEntryListener.onEntryRemoved(groupSummary.getEntry(), 0); |
| 798 | |
| 799 | // THEN the summary and its children are removed from bubble data |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 800 | assertFalse(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 801 | assertFalse(mBubbleData.isSummarySuppressed( |
| 802 | groupSummary.getEntry().getSbn().getGroupKey())); |
| 803 | } |
| 804 | |
| 805 | @Test |
| 806 | public void testSummaryDismissalMarksBubblesHiddenFromShadeAndDismissesNonBubbledChildren() |
| 807 | throws Exception { |
| 808 | // GIVEN a group summary with two (non-bubble) children and one bubble child |
| 809 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(2); |
| 810 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
| 811 | mEntryListener.onEntryAdded(groupedBubble.getEntry()); |
| 812 | groupSummary.addChildNotification(groupedBubble); |
| 813 | |
| 814 | // WHEN the summary is dismissed |
| 815 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 816 | |
| 817 | // THEN only the NON-bubble children are dismissed |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 818 | List<ExpandableNotificationRow> childrenRows = groupSummary.getAttachedChildren(); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 819 | verify(mNotifCallback, times(1)).removeNotification( |
| 820 | childrenRows.get(0).getEntry(), REASON_GROUP_SUMMARY_CANCELED); |
| 821 | verify(mNotifCallback, times(1)).removeNotification( |
| 822 | childrenRows.get(1).getEntry(), REASON_GROUP_SUMMARY_CANCELED); |
| 823 | verify(mNotifCallback, never()).removeNotification(eq(groupedBubble.getEntry()), anyInt()); |
| 824 | |
| 825 | // THEN the bubble child still exists as a bubble and is suppressed from the shade |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 826 | assertTrue(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 827 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 828 | groupedBubble.getEntry())); |
| 829 | |
| 830 | // THEN the summary is also suppressed from the shade |
| 831 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 832 | groupSummary.getEntry())); |
| 833 | } |
| 834 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 835 | /** |
| 836 | * Sets the bubble metadata flags for this entry. These flags are normally set by |
| 837 | * NotificationManagerService when the notification is sent, however, these tests do not |
| 838 | * go through that path so we set them explicitly when testing. |
| 839 | */ |
| 840 | private void setMetadataFlags(NotificationEntry entry, int flag, boolean enableFlag) { |
| 841 | Notification.BubbleMetadata bubbleMetadata = |
| 842 | entry.getSbn().getNotification().getBubbleMetadata(); |
| 843 | int flags = bubbleMetadata.getFlags(); |
| 844 | if (enableFlag) { |
| 845 | flags |= flag; |
| 846 | } else { |
| 847 | flags &= ~flag; |
| 848 | } |
| 849 | bubbleMetadata.setFlags(flags); |
| 850 | } |
| 851 | } |