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