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