Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 19 | import static android.app.Notification.FLAG_BUBBLE; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 20 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; |
| 21 | import static android.service.notification.NotificationListenerService.REASON_CANCEL; |
| 22 | import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 23 | |
Mady Mellor | 1a4e86f | 2019-05-03 16:07:23 -0700 | [diff] [blame] | 24 | import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; |
| 25 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 26 | import static com.google.common.truth.Truth.assertThat; |
| 27 | |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 28 | import static org.junit.Assert.assertEquals; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 29 | import static org.junit.Assert.assertFalse; |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 30 | import static org.junit.Assert.assertNotNull; |
| 31 | import static org.junit.Assert.assertNull; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 32 | import static org.junit.Assert.assertTrue; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 33 | import static org.mockito.ArgumentMatchers.any; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 35 | import static org.mockito.ArgumentMatchers.anyInt; |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 36 | import static org.mockito.ArgumentMatchers.anyString; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 37 | import static org.mockito.Mockito.atLeastOnce; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 38 | import static org.mockito.Mockito.mock; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 39 | import static org.mockito.Mockito.never; |
| 40 | import static org.mockito.Mockito.times; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 41 | import static org.mockito.Mockito.verify; |
| 42 | import static org.mockito.Mockito.when; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 43 | |
| 44 | import android.app.IActivityManager; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 45 | import android.app.Notification; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 46 | import android.app.PendingIntent; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 47 | import android.content.Context; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 48 | import android.content.res.Resources; |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 49 | import android.hardware.face.FaceManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 50 | import android.service.notification.ZenModeConfig; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 51 | import android.testing.AndroidTestingRunner; |
| 52 | import android.testing.TestableLooper; |
| 53 | import android.view.WindowManager; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 54 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 55 | import androidx.test.filters.SmallTest; |
| 56 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 57 | import com.android.internal.colorextraction.ColorExtractor; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 58 | import com.android.systemui.SystemUIFactory; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 59 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 60 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 61 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.NotificationPresenter; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 64 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 65 | import com.android.systemui.statusbar.NotificationTestHelper; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 66 | import com.android.systemui.statusbar.SuperStatusBarViewFactory; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 69 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.NotificationFilter; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 73 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 74 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 75 | import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 76 | import com.android.systemui.statusbar.phone.DozeParameters; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 79 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 80 | import com.android.systemui.statusbar.phone.ShadeController; |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 81 | import com.android.systemui.statusbar.policy.BatteryController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 82 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 83 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 84 | import com.android.systemui.statusbar.policy.RemoteInputUriController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 85 | import com.android.systemui.statusbar.policy.ZenModeController; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 86 | import com.android.systemui.util.InjectionInflationController; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 87 | |
| 88 | import org.junit.Before; |
| 89 | import org.junit.Test; |
| 90 | import org.junit.runner.RunWith; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 91 | import org.mockito.ArgumentCaptor; |
| 92 | import org.mockito.Captor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 93 | import org.mockito.Mock; |
| 94 | import org.mockito.MockitoAnnotations; |
| 95 | |
| 96 | @SmallTest |
| 97 | @RunWith(AndroidTestingRunner.class) |
| 98 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 99 | public class BubbleControllerTest extends SysuiTestCase { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 100 | @Mock |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 101 | private NotificationEntryManager mNotificationEntryManager; |
| 102 | @Mock |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 103 | private NotificationGroupManager mNotificationGroupManager; |
| 104 | @Mock |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 105 | private WindowManager mWindowManager; |
| 106 | @Mock |
| 107 | private IActivityManager mActivityManager; |
| 108 | @Mock |
| 109 | private DozeParameters mDozeParameters; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 110 | @Mock |
| 111 | private ConfigurationController mConfigurationController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 112 | @Mock |
| 113 | private ZenModeController mZenModeController; |
| 114 | @Mock |
| 115 | private ZenModeConfig mZenModeConfig; |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 116 | @Mock |
| 117 | private FaceManager mFaceManager; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 118 | @Mock |
| 119 | private NotificationLockscreenUserManager mLockscreenUserManager; |
Mady Mellor | f474e0d | 2019-08-01 11:08:40 -0700 | [diff] [blame] | 120 | @Mock |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 121 | private SysuiStatusBarStateController mStatusBarStateController; |
| 122 | @Mock |
| 123 | private KeyguardBypassController mKeyguardBypassController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 124 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 125 | @Captor |
| 126 | private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 127 | @Captor |
| 128 | private ArgumentCaptor<NotificationRemoveInterceptor> mRemoveInterceptorCaptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 129 | |
| 130 | private TestableBubbleController mBubbleController; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 131 | private NotificationShadeWindowController mNotificationShadeWindowController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 132 | private NotificationEntryListener mEntryListener; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 133 | private NotificationRemoveInterceptor mRemoveInterceptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 134 | |
| 135 | private NotificationTestHelper mNotificationTestHelper; |
| 136 | private ExpandableNotificationRow mRow; |
| 137 | private ExpandableNotificationRow mRow2; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 138 | private ExpandableNotificationRow mNonBubbleNotifRow; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 139 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 140 | @Mock |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 141 | private BubbleController.BubbleStateChangeListener mBubbleStateChangeListener; |
| 142 | @Mock |
| 143 | private BubbleController.BubbleExpandListener mBubbleExpandListener; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 144 | @Mock |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 145 | private PendingIntent mDeleteIntent; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 146 | @Mock |
| 147 | private SysuiColorExtractor mColorExtractor; |
| 148 | @Mock |
| 149 | ColorExtractor.GradientColors mGradientColors; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 150 | @Mock |
| 151 | private Resources mResources; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 152 | @Mock |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 153 | private ShadeController mShadeController; |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 154 | @Mock |
| 155 | private RemoteInputUriController mRemoteInputUriController; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 156 | @Mock |
| 157 | private NotificationRowComponent mNotificationRowComponent; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 158 | |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 159 | private SuperStatusBarViewFactory mSuperStatusBarViewFactory; |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 160 | private BubbleData mBubbleData; |
| 161 | |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 162 | private TestableLooper mTestableLooper; |
| 163 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 164 | @Before |
| 165 | public void setUp() throws Exception { |
| 166 | MockitoAnnotations.initMocks(this); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 167 | |
| 168 | mTestableLooper = TestableLooper.get(this); |
| 169 | |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 170 | mContext.addMockSystemService(FaceManager.class, mFaceManager); |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 171 | when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 172 | |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 173 | mSuperStatusBarViewFactory = new SuperStatusBarViewFactory(mContext, |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 174 | new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()), |
| 175 | new NotificationRowComponent.Builder() { |
| 176 | @Override |
| 177 | public NotificationRowComponent.Builder activatableNotificationView( |
| 178 | ActivatableNotificationView view) { |
| 179 | return this; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public NotificationRowComponent build() { |
| 184 | return mNotificationRowComponent; |
| 185 | } |
| 186 | }); |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 187 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 188 | // Bubbles get added to status bar window view |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 189 | mNotificationShadeWindowController = new NotificationShadeWindowController(mContext, |
| 190 | mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 191 | mConfigurationController, mKeyguardBypassController, mColorExtractor, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 192 | mSuperStatusBarViewFactory); |
| 193 | mNotificationShadeWindowController.attach(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 194 | |
| 195 | // Need notifications for bubbles |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 196 | mNotificationTestHelper = new NotificationTestHelper(mContext, mDependency); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 197 | mRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 198 | mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 199 | mNonBubbleNotifRow = mNotificationTestHelper.createRow(); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 200 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 201 | // Return non-null notification data from the NEM |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 202 | when(mNotificationEntryManager |
| 203 | .getActiveNotificationUnfiltered(mRow.getEntry().getKey())).thenReturn( |
| 204 | mRow.getEntry()); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 205 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 206 | mZenModeConfig.suppressedVisualEffects = 0; |
| 207 | when(mZenModeController.getConfig()).thenReturn(mZenModeConfig); |
| 208 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 209 | TestableNotificationInterruptionStateProvider interruptionStateProvider = |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 210 | new TestableNotificationInterruptionStateProvider(mContext, |
| 211 | mock(NotificationFilter.class), |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 212 | mock(StatusBarStateController.class), |
| 213 | mock(BatteryController.class)); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 214 | interruptionStateProvider.setUpWithPresenter( |
| 215 | mock(NotificationPresenter.class), |
| 216 | mock(HeadsUpManager.class), |
| 217 | mock(NotificationInterruptionStateProvider.HeadsUpSuppressor.class)); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 218 | mBubbleData = new BubbleData(mContext); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 219 | mBubbleController = new TestableBubbleController(mContext, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 220 | mNotificationShadeWindowController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 221 | mStatusBarStateController, |
| 222 | mShadeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 223 | mBubbleData, |
| 224 | mConfigurationController, |
| 225 | interruptionStateProvider, |
| 226 | mZenModeController, |
| 227 | mLockscreenUserManager, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 228 | mNotificationGroupManager, |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 229 | mNotificationEntryManager, |
| 230 | mRemoteInputUriController); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 231 | mBubbleController.setBubbleStateChangeListener(mBubbleStateChangeListener); |
| 232 | mBubbleController.setExpandListener(mBubbleExpandListener); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 233 | |
| 234 | // Get a reference to the BubbleController's entry listener |
| 235 | verify(mNotificationEntryManager, atLeastOnce()) |
| 236 | .addNotificationEntryListener(mEntryListenerCaptor.capture()); |
| 237 | mEntryListener = mEntryListenerCaptor.getValue(); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 238 | // And the remove interceptor |
| 239 | verify(mNotificationEntryManager, atLeastOnce()) |
| 240 | .setNotificationRemoveInterceptor(mRemoveInterceptorCaptor.capture()); |
| 241 | mRemoveInterceptor = mRemoveInterceptorCaptor.getValue(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 245 | public void testAddBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 246 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 247 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 248 | |
| 249 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Test |
| 253 | public void testHasBubbles() { |
| 254 | assertFalse(mBubbleController.hasBubbles()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 255 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 256 | assertTrue(mBubbleController.hasBubbles()); |
| 257 | } |
| 258 | |
| 259 | @Test |
| 260 | public void testRemoveBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 261 | mBubbleController.updateBubble(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 262 | assertNotNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 263 | assertTrue(mBubbleController.hasBubbles()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 264 | verify(mNotificationEntryManager).updateNotifications(any()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 265 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
| 266 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 267 | mBubbleController.removeBubble( |
| 268 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 269 | assertFalse(mNotificationShadeWindowController.getBubblesShowing()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 270 | assertNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 271 | verify(mNotificationEntryManager, times(2)).updateNotifications(anyString()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 272 | verify(mBubbleStateChangeListener).onHasBubblesChanged(false); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Test |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 276 | public void testRemoveBubble_withDismissedNotif() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 277 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 278 | mBubbleController.updateBubble(mRow.getEntry()); |
| 279 | |
| 280 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 281 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 282 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 283 | |
| 284 | // Make it look like dismissed notif |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 285 | mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).setSuppressNotification(true); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 286 | |
| 287 | // Now remove the bubble |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 288 | mBubbleController.removeBubble( |
| 289 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 290 | |
| 291 | // Since the notif is dismissed, once the bubble is removed, performRemoveNotification gets |
| 292 | // called to really remove the notif |
| 293 | verify(mNotificationEntryManager, times(1)).performRemoveNotification( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 294 | mRow.getEntry().getSbn(), UNDEFINED_DISMISS_REASON); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 295 | assertFalse(mBubbleController.hasBubbles()); |
| 296 | } |
| 297 | |
| 298 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 299 | public void testDismissStack() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 300 | mBubbleController.updateBubble(mRow.getEntry()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 301 | verify(mNotificationEntryManager, times(1)).updateNotifications(any()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 302 | assertNotNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 303 | mBubbleController.updateBubble(mRow2.getEntry()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 304 | verify(mNotificationEntryManager, times(2)).updateNotifications(any()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 305 | assertNotNull(mBubbleData.getBubbleWithKey(mRow2.getEntry().getKey())); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 306 | assertTrue(mBubbleController.hasBubbles()); |
| 307 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 308 | mBubbleController.dismissStack(BubbleController.DISMISS_USER_GESTURE); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 309 | assertFalse(mNotificationShadeWindowController.getBubblesShowing()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 310 | verify(mNotificationEntryManager, times(3)).updateNotifications(any()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 311 | assertNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
| 312 | assertNull(mBubbleData.getBubbleWithKey(mRow2.getEntry().getKey())); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 316 | public void testExpandCollapseStack() { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 317 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 318 | |
| 319 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 320 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 321 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 322 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 323 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 324 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 325 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 326 | mRow.getEntry())); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 327 | assertFalse(mNotificationShadeWindowController.getBubbleExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 328 | |
| 329 | // Expand the stack |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 330 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 331 | mBubbleController.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 332 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 333 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 334 | assertTrue(mNotificationShadeWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 335 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 336 | // Make sure the notif is suppressed |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 337 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 338 | mRow.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 339 | |
| 340 | // Collapse |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 341 | mBubbleController.collapseStack(); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 342 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 343 | assertFalse(mBubbleController.isStackExpanded()); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 344 | assertFalse(mNotificationShadeWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 348 | public void testCollapseAfterChangingExpandedBubble() { |
| 349 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 350 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
| 351 | mEntryListener.onNotificationAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 352 | mBubbleController.updateBubble(mRow.getEntry()); |
| 353 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 354 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 355 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 356 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 357 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 358 | mRow.getEntry())); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 359 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 360 | mRow2.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 361 | |
| 362 | // Expand |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 363 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 364 | mBubbleController.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 365 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 366 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 367 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 368 | // Last added is the one that is expanded |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 369 | assertEquals(mRow2.getEntry(), mBubbleData.getSelectedBubble().getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 370 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 371 | mRow2.getEntry())); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 372 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 373 | // Switch which bubble is expanded |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 374 | mBubbleController.selectBubble(mRow.getEntry().getKey()); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 375 | mBubbleData.setExpanded(true); |
| 376 | assertEquals(mRow.getEntry(), stackView.getExpandedBubble().getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 377 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 378 | mRow.getEntry())); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 379 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 380 | // collapse for previous bubble |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 381 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 382 | // expand for selected bubble |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 383 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 384 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 385 | // Collapse |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 386 | mBubbleController.collapseStack(); |
| 387 | assertFalse(mBubbleController.isStackExpanded()); |
| 388 | } |
| 389 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 390 | @Test |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 391 | public void testExpansionRemovesShowInShadeAndDot() { |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 392 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 393 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 394 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 395 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 396 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 397 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 398 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 399 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 400 | |
| 401 | mTestableLooper.processAllMessages(); |
| 402 | assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 403 | |
| 404 | // Expand |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 405 | mBubbleController.expandStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 406 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 407 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 408 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 409 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 410 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 411 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 412 | // Notif shouldn't show dot after expansion |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 413 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | @Test |
| 417 | public void testUpdateWhileExpanded_DoesntChangeShowInShadeAndDot() { |
| 418 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 419 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 420 | mBubbleController.updateBubble(mRow.getEntry()); |
| 421 | |
| 422 | // We should have bubbles & their notifs should not be suppressed |
| 423 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 424 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 425 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 426 | |
| 427 | mTestableLooper.processAllMessages(); |
| 428 | assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 429 | |
| 430 | // Expand |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 431 | mBubbleController.expandStack(); |
| 432 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 433 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 434 | |
| 435 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 436 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 437 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 438 | // Notif shouldn't show dot after expansion |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 439 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 440 | |
| 441 | // Send update |
| 442 | mEntryListener.onPreEntryUpdated(mRow.getEntry()); |
| 443 | |
| 444 | // Nothing should have changed |
| 445 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 446 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 447 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 448 | // Notif shouldn't show dot after expansion |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 449 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Test |
| 453 | public void testRemoveLastExpandedCollapses() { |
| 454 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 455 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
| 456 | mEntryListener.onNotificationAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 457 | mBubbleController.updateBubble(mRow.getEntry()); |
| 458 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 459 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
| 460 | |
| 461 | // Expand |
| 462 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 463 | mBubbleController.expandStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 464 | |
| 465 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 466 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 467 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 468 | // Last added is the one that is expanded |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 469 | assertEquals(mRow2.getEntry(), stackView.getExpandedBubble().getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 470 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 471 | mRow2.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 472 | |
| 473 | // Dismiss currently expanded |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 474 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 475 | BubbleController.DISMISS_USER_GESTURE); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 476 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 477 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 478 | // Make sure first bubble is selected |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 479 | assertEquals(mRow.getEntry(), stackView.getExpandedBubble().getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 480 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 481 | |
| 482 | // Dismiss that one |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 483 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 484 | BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 485 | |
| 486 | // Make sure state changes and collapse happens |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 487 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 488 | verify(mBubbleStateChangeListener).onHasBubblesChanged(false); |
| 489 | assertFalse(mBubbleController.hasBubbles()); |
| 490 | } |
| 491 | |
| 492 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 493 | public void testAutoExpand_fails_noFlag() { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 494 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 495 | setMetadataFlags(mRow.getEntry(), |
| 496 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 497 | |
| 498 | // Add the auto expand bubble |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 499 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 500 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 501 | |
| 502 | // Expansion shouldn't change |
| 503 | verify(mBubbleExpandListener, never()).onBubbleExpandChanged(false /* expanded */, |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 504 | mRow.getEntry().getKey()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 505 | assertFalse(mBubbleController.isStackExpanded()); |
| 506 | |
| 507 | // # of bubbles should change |
| 508 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 509 | } |
| 510 | |
| 511 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 512 | public void testAutoExpand_succeeds_withFlag() { |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 513 | setMetadataFlags(mRow.getEntry(), |
| 514 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 515 | |
| 516 | // Add the auto expand bubble |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 517 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 518 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 519 | |
| 520 | // Expansion should change |
| 521 | verify(mBubbleExpandListener).onBubbleExpandChanged(true /* expanded */, |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 522 | mRow.getEntry().getKey()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 523 | assertTrue(mBubbleController.isStackExpanded()); |
| 524 | |
| 525 | // # of bubbles should change |
| 526 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 529 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 530 | public void testSuppressNotif_onInitialNotif() { |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 531 | setMetadataFlags(mRow.getEntry(), |
| 532 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 533 | |
| 534 | // Add the suppress notif bubble |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 535 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 536 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 537 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 538 | // Notif should be suppressed because we were foreground |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 539 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 540 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 541 | // Dot + flyout is hidden because notif is suppressed |
| 542 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
| 543 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 544 | |
| 545 | // # of bubbles should change |
| 546 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 547 | } |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 548 | |
| 549 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 550 | public void testSuppressNotif_onUpdateNotif() { |
| 551 | mBubbleController.updateBubble(mRow.getEntry()); |
| 552 | |
| 553 | // Should not be suppressed |
| 554 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 555 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 556 | // Should show dot |
| 557 | assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
| 558 | |
| 559 | // Update to suppress notif |
| 560 | setMetadataFlags(mRow.getEntry(), |
| 561 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
| 562 | mBubbleController.updateBubble(mRow.getEntry()); |
| 563 | |
| 564 | // Notif should be suppressed |
| 565 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 566 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 567 | // Dot + flyout is hidden because notif is suppressed |
| 568 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
| 569 | assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout()); |
| 570 | |
| 571 | // # of bubbles should change |
| 572 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 573 | } |
| 574 | |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 575 | @Test |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 576 | public void testExpandStackAndSelectBubble_removedFirst() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 577 | final String key = mRow.getEntry().getKey(); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 578 | |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 579 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 580 | mBubbleController.updateBubble(mRow.getEntry()); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 581 | |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 582 | // Simulate notification cancellation. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 583 | mRemoveInterceptor.onNotificationRemoveRequested( |
| 584 | mRow.getEntry().getKey(), REASON_APP_CANCEL); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 585 | |
| 586 | mBubbleController.expandStackAndSelectBubble(key); |
| 587 | } |
| 588 | |
| 589 | @Test |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 590 | public void testMarkNewNotificationAsShowInShade() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 591 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 592 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 593 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 594 | |
| 595 | mTestableLooper.processAllMessages(); |
| 596 | assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 599 | @Test |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 600 | public void testAddNotif_notBubble() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 601 | mEntryListener.onNotificationAdded(mNonBubbleNotifRow.getEntry()); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 602 | mEntryListener.onPreEntryUpdated(mNonBubbleNotifRow.getEntry()); |
| 603 | |
| 604 | verify(mBubbleStateChangeListener, never()).onHasBubblesChanged(anyBoolean()); |
| 605 | assertThat(mBubbleController.hasBubbles()).isFalse(); |
| 606 | } |
| 607 | |
| 608 | @Test |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 609 | public void testDeleteIntent_removeBubble_aged() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 610 | mBubbleController.updateBubble(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 611 | mBubbleController.removeBubble(mRow.getEntry().getKey(), BubbleController.DISMISS_AGED); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 612 | verify(mDeleteIntent, never()).send(); |
| 613 | } |
| 614 | |
| 615 | @Test |
| 616 | public void testDeleteIntent_removeBubble_user() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 617 | mBubbleController.updateBubble(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 618 | mBubbleController.removeBubble( |
| 619 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 620 | verify(mDeleteIntent, times(1)).send(); |
| 621 | } |
| 622 | |
| 623 | @Test |
| 624 | public void testDeleteIntent_dismissStack() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 625 | mBubbleController.updateBubble(mRow.getEntry()); |
| 626 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 627 | mBubbleController.dismissStack(BubbleController.DISMISS_USER_GESTURE); |
| 628 | verify(mDeleteIntent, times(2)).send(); |
| 629 | } |
| 630 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 631 | @Test |
| 632 | public void testRemoveBubble_noLongerBubbleAfterUpdate() |
| 633 | throws PendingIntent.CanceledException { |
| 634 | mBubbleController.updateBubble(mRow.getEntry()); |
| 635 | assertTrue(mBubbleController.hasBubbles()); |
| 636 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 637 | mRow.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 638 | mEntryListener.onPreEntryUpdated(mRow.getEntry()); |
| 639 | |
| 640 | assertFalse(mBubbleController.hasBubbles()); |
| 641 | verify(mDeleteIntent, never()).send(); |
| 642 | } |
| 643 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 644 | @Test |
| 645 | public void testRemoveBubble_succeeds_appCancel() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 646 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 647 | mBubbleController.updateBubble(mRow.getEntry()); |
| 648 | |
| 649 | assertTrue(mBubbleController.hasBubbles()); |
| 650 | |
| 651 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 652 | mRow.getEntry().getKey(), REASON_APP_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 653 | |
| 654 | // Cancels always remove so no need to intercept |
| 655 | assertFalse(intercepted); |
| 656 | assertFalse(mBubbleController.hasBubbles()); |
| 657 | } |
| 658 | |
| 659 | @Test |
| 660 | public void removeBubble_fails_clearAll() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 661 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 662 | mBubbleController.updateBubble(mRow.getEntry()); |
| 663 | |
| 664 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 665 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 666 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 667 | |
| 668 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 669 | mRow.getEntry().getKey(), REASON_CANCEL_ALL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 670 | |
| 671 | // Intercept! |
| 672 | assertTrue(intercepted); |
| 673 | // Should update show in shade state |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 674 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 675 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 676 | |
| 677 | verify(mNotificationEntryManager, never()).performRemoveNotification( |
| 678 | any(), anyInt()); |
| 679 | assertTrue(mBubbleController.hasBubbles()); |
| 680 | } |
| 681 | |
| 682 | @Test |
| 683 | public void removeBubble_fails_userDismissNotif() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 684 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 685 | mBubbleController.updateBubble(mRow.getEntry()); |
| 686 | |
| 687 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 688 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 689 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 690 | |
| 691 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 692 | mRow.getEntry().getKey(), REASON_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 693 | |
| 694 | // Intercept! |
| 695 | assertTrue(intercepted); |
| 696 | // Should update show in shade state |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 697 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 698 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 699 | |
| 700 | verify(mNotificationEntryManager, never()).performRemoveNotification( |
| 701 | any(), anyInt()); |
| 702 | assertTrue(mBubbleController.hasBubbles()); |
| 703 | } |
| 704 | |
| 705 | @Test |
| 706 | public void removeBubble_succeeds_userDismissBubble_userDimissNotif() { |
Mady Mellor | 58dc519 | 2019-12-16 13:49:56 -0800 | [diff] [blame] | 707 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 708 | mBubbleController.updateBubble(mRow.getEntry()); |
| 709 | |
| 710 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 711 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 712 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 713 | |
| 714 | // Dismiss the bubble |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 715 | mBubbleController.removeBubble( |
| 716 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 717 | assertFalse(mBubbleController.hasBubbles()); |
| 718 | |
| 719 | // Dismiss the notification |
| 720 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 721 | mRow.getEntry().getKey(), REASON_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 722 | |
| 723 | // It's no longer a bubble so we shouldn't intercept |
| 724 | assertFalse(intercepted); |
| 725 | } |
| 726 | |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 727 | @Test |
| 728 | public void testNotifyShadeSuppressionChange_notificationDismiss() { |
| 729 | BubbleController.NotificationSuppressionChangedListener listener = |
| 730 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 731 | mBubbleData.setSuppressionChangedListener(listener); |
| 732 | |
| 733 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
| 734 | |
| 735 | assertTrue(mBubbleController.hasBubbles()); |
| 736 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 737 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 738 | |
| 739 | mRemoveInterceptor.onNotificationRemoveRequested(mRow.getEntry().getKey(), REASON_CANCEL); |
| 740 | |
| 741 | // Should update show in shade state |
| 742 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 743 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 744 | |
| 745 | // Should notify delegate that shade state changed |
| 746 | verify(listener).onBubbleNotificationSuppressionChange( |
| 747 | mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
| 748 | } |
| 749 | |
| 750 | @Test |
| 751 | public void testNotifyShadeSuppressionChange_bubbleExpanded() { |
| 752 | BubbleController.NotificationSuppressionChangedListener listener = |
| 753 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 754 | mBubbleData.setSuppressionChangedListener(listener); |
| 755 | |
| 756 | mEntryListener.onNotificationAdded(mRow.getEntry()); |
| 757 | |
| 758 | assertTrue(mBubbleController.hasBubbles()); |
| 759 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 760 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 761 | |
| 762 | mBubbleData.setExpanded(true); |
| 763 | |
| 764 | // Once a bubble is expanded the notif is suppressed |
| 765 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 766 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 767 | |
| 768 | // Should notify delegate that shade state changed |
| 769 | verify(listener).onBubbleNotificationSuppressionChange( |
| 770 | mBubbleData.getBubbleWithKey(mRow.getEntry().getKey())); |
| 771 | } |
| 772 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 773 | static class TestableBubbleController extends BubbleController { |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 774 | // Let's assume surfaces can be synchronized immediately. |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 775 | TestableBubbleController(Context context, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 776 | NotificationShadeWindowController notificationShadeWindowController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 777 | StatusBarStateController statusBarStateController, |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 778 | ShadeController shadeController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 779 | BubbleData data, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 780 | ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 781 | NotificationInterruptionStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 782 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 783 | NotificationLockscreenUserManager lockscreenUserManager, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 784 | NotificationGroupManager groupManager, |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 785 | NotificationEntryManager entryManager, |
| 786 | RemoteInputUriController remoteInputUriController) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 787 | super(context, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 788 | notificationShadeWindowController, statusBarStateController, shadeController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 789 | data, Runnable::run, configurationController, interruptionStateProvider, |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 790 | zenModeController, lockscreenUserManager, groupManager, entryManager, |
| 791 | remoteInputUriController); |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 792 | setInflateSynchronously(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 793 | } |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 794 | } |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 795 | |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 796 | static class TestableNotificationInterruptionStateProvider extends |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 797 | NotificationInterruptionStateProvider { |
| 798 | |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 799 | TestableNotificationInterruptionStateProvider(Context context, |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 800 | NotificationFilter filter, StatusBarStateController controller, |
| 801 | BatteryController batteryController) { |
| 802 | super(context, filter, controller, batteryController); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 803 | mUseHeadsUp = true; |
| 804 | } |
| 805 | } |
| 806 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 807 | /** |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 808 | * Sets the bubble metadata flags for this entry. These flags are normally set by |
| 809 | * NotificationManagerService when the notification is sent, however, these tests do not |
| 810 | * go through that path so we set them explicitly when testing. |
| 811 | */ |
| 812 | private void setMetadataFlags(NotificationEntry entry, int flag, boolean enableFlag) { |
| 813 | Notification.BubbleMetadata bubbleMetadata = |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 814 | entry.getSbn().getNotification().getBubbleMetadata(); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 815 | int flags = bubbleMetadata.getFlags(); |
| 816 | if (enableFlag) { |
| 817 | flags |= flag; |
| 818 | } else { |
| 819 | flags &= ~flag; |
| 820 | } |
| 821 | bubbleMetadata.setFlags(flags); |
| 822 | } |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 823 | } |