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 | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 20 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 21 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; |
| 22 | import static android.service.notification.NotificationListenerService.REASON_CANCEL; |
| 23 | import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 24 | |
Mady Mellor | 1a4e86f | 2019-05-03 16:07:23 -0700 | [diff] [blame] | 25 | import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; |
| 26 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 27 | import static com.google.common.truth.Truth.assertThat; |
| 28 | |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 29 | import static org.junit.Assert.assertEquals; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 30 | import static org.junit.Assert.assertFalse; |
| 31 | import static org.junit.Assert.assertTrue; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 32 | import static org.mockito.ArgumentMatchers.any; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 33 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.anyInt; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 35 | import static org.mockito.Mockito.atLeastOnce; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 36 | import static org.mockito.Mockito.mock; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 37 | import static org.mockito.Mockito.never; |
| 38 | import static org.mockito.Mockito.times; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 39 | import static org.mockito.Mockito.verify; |
| 40 | import static org.mockito.Mockito.when; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 41 | |
| 42 | import android.app.IActivityManager; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 43 | import android.app.Notification; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 44 | import android.app.PendingIntent; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 45 | import android.content.BroadcastReceiver; |
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; |
| 48 | import android.content.IntentFilter; |
| 49 | import android.graphics.drawable.Icon; |
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 | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 60 | import com.android.systemui.statusbar.NotificationPresenter; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 62 | import com.android.systemui.statusbar.NotificationTestHelper; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 65 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 70 | import com.android.systemui.statusbar.phone.DozeParameters; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 72 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 73 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 74 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.ZenModeController; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 76 | |
| 77 | import org.junit.Before; |
| 78 | import org.junit.Test; |
| 79 | import org.junit.runner.RunWith; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 80 | import org.mockito.ArgumentCaptor; |
| 81 | import org.mockito.Captor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 82 | import org.mockito.Mock; |
| 83 | import org.mockito.MockitoAnnotations; |
| 84 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 85 | import java.util.concurrent.CountDownLatch; |
| 86 | import java.util.concurrent.TimeUnit; |
| 87 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 88 | @SmallTest |
| 89 | @RunWith(AndroidTestingRunner.class) |
| 90 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 91 | public class BubbleControllerTest extends SysuiTestCase { |
| 92 | |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 93 | // Some APIs rely on the app being foreground, check is via pkg name |
| 94 | private static final String FOREGROUND_TEST_PKG_NAME = "com.android.systemui.tests"; |
| 95 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 96 | @Mock |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 97 | private NotificationEntryManager mNotificationEntryManager; |
| 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; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 110 | @Mock |
| 111 | private SysuiStatusBarStateController mStatusBarStateController; |
| 112 | @Mock |
| 113 | private KeyguardBypassController mKeyguardBypassController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 114 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 115 | private FrameLayout mStatusBarView; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 116 | @Captor |
| 117 | private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 118 | @Captor |
| 119 | private ArgumentCaptor<NotificationRemoveInterceptor> mRemoveInterceptorCaptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 120 | |
| 121 | private TestableBubbleController mBubbleController; |
| 122 | private StatusBarWindowController mStatusBarWindowController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 123 | private NotificationEntryListener mEntryListener; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 124 | private NotificationRemoveInterceptor mRemoveInterceptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 125 | |
| 126 | private NotificationTestHelper mNotificationTestHelper; |
| 127 | private ExpandableNotificationRow mRow; |
| 128 | private ExpandableNotificationRow mRow2; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 129 | private ExpandableNotificationRow mAutoExpandRow; |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 130 | private ExpandableNotificationRow mSuppressNotifRow; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 131 | private ExpandableNotificationRow mNonBubbleNotifRow; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 132 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 133 | @Mock |
| 134 | private NotificationData mNotificationData; |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 135 | @Mock |
| 136 | private BubbleController.BubbleStateChangeListener mBubbleStateChangeListener; |
| 137 | @Mock |
| 138 | private BubbleController.BubbleExpandListener mBubbleExpandListener; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 139 | @Mock |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 140 | private PendingIntent mDeleteIntent; |
| 141 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 142 | private BubbleData mBubbleData; |
| 143 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 144 | @Before |
| 145 | public void setUp() throws Exception { |
| 146 | MockitoAnnotations.initMocks(this); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 147 | mStatusBarView = new FrameLayout(mContext); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 148 | mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 149 | |
| 150 | // Bubbles get added to status bar window view |
| 151 | mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 152 | mActivityManager, mDozeParameters, mStatusBarStateController, |
| 153 | mConfigurationController, mKeyguardBypassController); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 154 | mStatusBarWindowController.add(mStatusBarView, 120 /* height */); |
| 155 | |
| 156 | // Need notifications for bubbles |
| 157 | mNotificationTestHelper = new NotificationTestHelper(mContext); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 158 | mRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 159 | mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 160 | mNonBubbleNotifRow = mNotificationTestHelper.createRow(); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 161 | |
| 162 | // Some bubbles want to auto expand |
| 163 | Notification.BubbleMetadata autoExpandMetadata = |
| 164 | getBuilder().setAutoExpandBubble(true).build(); |
| 165 | mAutoExpandRow = mNotificationTestHelper.createBubble(autoExpandMetadata, |
| 166 | FOREGROUND_TEST_PKG_NAME); |
| 167 | |
| 168 | // Some bubbles want to suppress notifs |
| 169 | Notification.BubbleMetadata suppressNotifMetadata = |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 170 | getBuilder().setSuppressNotification(true).build(); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 171 | mSuppressNotifRow = mNotificationTestHelper.createBubble(suppressNotifMetadata, |
| 172 | FOREGROUND_TEST_PKG_NAME); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 173 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 174 | // Return non-null notification data from the NEM |
| 175 | when(mNotificationEntryManager.getNotificationData()).thenReturn(mNotificationData); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 176 | when(mNotificationData.getChannel(mRow.getEntry().key)).thenReturn(mRow.getEntry().channel); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 177 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 178 | mZenModeConfig.suppressedVisualEffects = 0; |
| 179 | when(mZenModeController.getConfig()).thenReturn(mZenModeConfig); |
| 180 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 181 | TestableNotificationInterruptionStateProvider interruptionStateProvider = |
| 182 | new TestableNotificationInterruptionStateProvider(mContext); |
| 183 | interruptionStateProvider.setUpWithPresenter( |
| 184 | mock(NotificationPresenter.class), |
| 185 | mock(HeadsUpManager.class), |
| 186 | mock(NotificationInterruptionStateProvider.HeadsUpSuppressor.class)); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 187 | mBubbleData = new BubbleData(mContext); |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 188 | mBubbleController = new TestableBubbleController(mContext, mStatusBarWindowController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 189 | mBubbleData, mConfigurationController, interruptionStateProvider, |
| 190 | mZenModeController); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 191 | mBubbleController.setBubbleStateChangeListener(mBubbleStateChangeListener); |
| 192 | mBubbleController.setExpandListener(mBubbleExpandListener); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 193 | |
| 194 | // Get a reference to the BubbleController's entry listener |
| 195 | verify(mNotificationEntryManager, atLeastOnce()) |
| 196 | .addNotificationEntryListener(mEntryListenerCaptor.capture()); |
| 197 | mEntryListener = mEntryListenerCaptor.getValue(); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 198 | // And the remove interceptor |
| 199 | verify(mNotificationEntryManager, atLeastOnce()) |
| 200 | .setNotificationRemoveInterceptor(mRemoveInterceptorCaptor.capture()); |
| 201 | mRemoveInterceptor = mRemoveInterceptorCaptor.getValue(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 205 | public void testAddBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 206 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 207 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 208 | |
| 209 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Test |
| 213 | public void testHasBubbles() { |
| 214 | assertFalse(mBubbleController.hasBubbles()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 215 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 216 | assertTrue(mBubbleController.hasBubbles()); |
| 217 | } |
| 218 | |
| 219 | @Test |
| 220 | public void testRemoveBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 221 | mBubbleController.updateBubble(mRow.getEntry()); |
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 | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 227 | assertFalse(mStatusBarWindowController.getBubblesShowing()); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 228 | assertTrue(mRow.getEntry().isBubbleDismissed()); |
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()); |
| 239 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 240 | |
| 241 | // Make it look like dismissed notif |
| 242 | mRow.getEntry().setShowInShadeWhenBubble(false); |
| 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(); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 258 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 259 | verify(mNotificationEntryManager, times(2)).updateNotifications(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 260 | assertTrue(mBubbleController.hasBubbles()); |
| 261 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 262 | mBubbleController.dismissStack(BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 263 | assertFalse(mStatusBarWindowController.getBubblesShowing()); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 264 | verify(mNotificationEntryManager, times(3)).updateNotifications(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 265 | assertTrue(mRow.getEntry().isBubbleDismissed()); |
| 266 | assertTrue(mRow2.getEntry().isBubbleDismissed()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 270 | public void testExpandCollapseStack() { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 271 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 272 | |
| 273 | // Mark it as a bubble and add it explicitly |
| 274 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 275 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 276 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 277 | // We should have bubbles & their notifs should show in the shade |
| 278 | assertTrue(mBubbleController.hasBubbles()); |
| 279 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 280 | assertFalse(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 281 | |
| 282 | // Expand the stack |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 283 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 284 | mBubbleController.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 285 | assertTrue(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 286 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 287 | assertTrue(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 288 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 289 | // Make sure it's no longer in the shade |
| 290 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 291 | |
| 292 | // Collapse |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 293 | mBubbleController.collapseStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 294 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 295 | assertFalse(mBubbleController.isStackExpanded()); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 296 | assertFalse(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 300 | public void testCollapseAfterChangingExpandedBubble() { |
| 301 | // Mark it as a bubble and add it explicitly |
| 302 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 303 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 304 | mBubbleController.updateBubble(mRow.getEntry()); |
| 305 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 306 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 307 | // We should have bubbles & their notifs should show in the shade |
| 308 | assertTrue(mBubbleController.hasBubbles()); |
| 309 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 310 | assertTrue(mRow2.getEntry().showInShadeWhenBubble()); |
| 311 | |
| 312 | // Expand |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 313 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 314 | mBubbleController.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 315 | assertTrue(mBubbleController.isStackExpanded()); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 316 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 317 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 318 | // Last added is the one that is expanded |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 319 | assertEquals(mRow2.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
| 320 | assertFalse(mRow2.getEntry().showInShadeWhenBubble()); |
| 321 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 322 | // Switch which bubble is expanded |
| 323 | mBubbleController.selectBubble(mRow.getEntry().key); |
| 324 | stackView.setExpandedBubble(mRow.getEntry()); |
| 325 | assertEquals(mRow.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
| 326 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 327 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 328 | // collapse for previous bubble |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 329 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 330 | // expand for selected bubble |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 331 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 332 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 333 | // Collapse |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 334 | mBubbleController.collapseStack(); |
| 335 | assertFalse(mBubbleController.isStackExpanded()); |
| 336 | } |
| 337 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 338 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 339 | public void testExpansionRemovesShowInShade() { |
| 340 | // Mark it as a bubble and add it explicitly |
| 341 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 342 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 343 | |
| 344 | // We should have bubbles & their notifs should show in the shade |
| 345 | assertTrue(mBubbleController.hasBubbles()); |
| 346 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 347 | |
| 348 | // Expand |
| 349 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 350 | mBubbleController.expandStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 351 | assertTrue(mBubbleController.isStackExpanded()); |
| 352 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
| 353 | |
| 354 | // No longer show shade in notif after expansion |
| 355 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 356 | } |
| 357 | |
| 358 | @Test |
| 359 | public void testRemoveLastExpandedCollapses() { |
| 360 | // Mark it as a bubble and add it explicitly |
| 361 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 362 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 363 | mBubbleController.updateBubble(mRow.getEntry()); |
| 364 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 365 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
| 366 | |
| 367 | // Expand |
| 368 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 369 | mBubbleController.expandStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 370 | |
| 371 | assertTrue(mBubbleController.isStackExpanded()); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 372 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 373 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 374 | // Last added is the one that is expanded |
| 375 | assertEquals(mRow2.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
| 376 | assertFalse(mRow2.getEntry().showInShadeWhenBubble()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 377 | |
| 378 | // Dismiss currently expanded |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 379 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 380 | BubbleController.DISMISS_USER_GESTURE); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 381 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 382 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 383 | // Make sure first bubble is selected |
| 384 | assertEquals(mRow.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
| 385 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 386 | |
| 387 | // Dismiss that one |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 388 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 389 | BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 390 | |
| 391 | // Make sure state changes and collapse happens |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 392 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 393 | verify(mBubbleStateChangeListener).onHasBubblesChanged(false); |
| 394 | assertFalse(mBubbleController.hasBubbles()); |
| 395 | } |
| 396 | |
| 397 | @Test |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 398 | public void testAutoExpand_FailsNotForeground() { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 399 | assertFalse(mBubbleController.isStackExpanded()); |
| 400 | |
| 401 | // Add the auto expand bubble |
| 402 | mEntryListener.onPendingEntryAdded(mAutoExpandRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 403 | mBubbleController.updateBubble(mAutoExpandRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 404 | |
| 405 | // Expansion shouldn't change |
| 406 | verify(mBubbleExpandListener, never()).onBubbleExpandChanged(false /* expanded */, |
| 407 | mAutoExpandRow.getEntry().key); |
| 408 | assertFalse(mBubbleController.isStackExpanded()); |
| 409 | |
| 410 | // # of bubbles should change |
| 411 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 412 | } |
| 413 | |
| 414 | @Test |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 415 | public void testAutoExpand_SucceedsForeground() { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 416 | final CountDownLatch latch = new CountDownLatch(1); |
| 417 | BroadcastReceiver receiver = new BroadcastReceiver() { |
| 418 | @Override |
| 419 | public void onReceive(Context context, Intent intent) { |
| 420 | latch.countDown(); |
| 421 | } |
| 422 | }; |
| 423 | IntentFilter filter = new IntentFilter(BubblesTestActivity.BUBBLE_ACTIVITY_OPENED); |
| 424 | mContext.registerReceiver(receiver, filter); |
| 425 | |
| 426 | assertFalse(mBubbleController.isStackExpanded()); |
| 427 | |
| 428 | // Make ourselves foreground |
| 429 | Intent i = new Intent(mContext, BubblesTestActivity.class); |
| 430 | i.setFlags(FLAG_ACTIVITY_NEW_TASK); |
| 431 | mContext.startActivity(i); |
| 432 | |
| 433 | try { |
| 434 | latch.await(100, TimeUnit.MILLISECONDS); |
| 435 | } catch (InterruptedException e) { |
| 436 | e.printStackTrace(); |
| 437 | } |
| 438 | |
| 439 | // Add the auto expand bubble |
| 440 | mEntryListener.onPendingEntryAdded(mAutoExpandRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 441 | mBubbleController.updateBubble(mAutoExpandRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 442 | |
| 443 | // Expansion should change |
| 444 | verify(mBubbleExpandListener).onBubbleExpandChanged(true /* expanded */, |
| 445 | mAutoExpandRow.getEntry().key); |
| 446 | assertTrue(mBubbleController.isStackExpanded()); |
| 447 | |
| 448 | // # of bubbles should change |
| 449 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 450 | mContext.unregisterReceiver(receiver); |
| 451 | } |
| 452 | |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 453 | @Test |
| 454 | public void testSuppressNotif_FailsNotForeground() { |
| 455 | // Add the suppress notif bubble |
| 456 | mEntryListener.onPendingEntryAdded(mSuppressNotifRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 457 | mBubbleController.updateBubble(mSuppressNotifRow.getEntry()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 458 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 459 | // Should show in shade because we weren't forground |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 460 | assertTrue(mSuppressNotifRow.getEntry().showInShadeWhenBubble()); |
| 461 | |
| 462 | // # of bubbles should change |
| 463 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 464 | } |
| 465 | |
| 466 | @Test |
| 467 | public void testSuppressNotif_SucceedsForeground() { |
| 468 | final CountDownLatch latch = new CountDownLatch(1); |
| 469 | BroadcastReceiver receiver = new BroadcastReceiver() { |
| 470 | @Override |
| 471 | public void onReceive(Context context, Intent intent) { |
| 472 | latch.countDown(); |
| 473 | } |
| 474 | }; |
| 475 | IntentFilter filter = new IntentFilter(BubblesTestActivity.BUBBLE_ACTIVITY_OPENED); |
| 476 | mContext.registerReceiver(receiver, filter); |
| 477 | |
| 478 | assertFalse(mBubbleController.isStackExpanded()); |
| 479 | |
| 480 | // Make ourselves foreground |
| 481 | Intent i = new Intent(mContext, BubblesTestActivity.class); |
| 482 | i.setFlags(FLAG_ACTIVITY_NEW_TASK); |
| 483 | mContext.startActivity(i); |
| 484 | |
| 485 | try { |
| 486 | latch.await(100, TimeUnit.MILLISECONDS); |
| 487 | } catch (InterruptedException e) { |
| 488 | e.printStackTrace(); |
| 489 | } |
| 490 | |
| 491 | // Add the suppress notif bubble |
| 492 | mEntryListener.onPendingEntryAdded(mSuppressNotifRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 493 | mBubbleController.updateBubble(mSuppressNotifRow.getEntry()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 494 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 495 | // Should NOT show in shade because we were foreground |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 496 | assertFalse(mSuppressNotifRow.getEntry().showInShadeWhenBubble()); |
| 497 | |
| 498 | // # of bubbles should change |
| 499 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */); |
| 500 | mContext.unregisterReceiver(receiver); |
| 501 | } |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 502 | |
| 503 | @Test |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 504 | public void testExpandStackAndSelectBubble_removedFirst() { |
| 505 | final String key = mRow.getEntry().key; |
| 506 | |
| 507 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 508 | mBubbleController.updateBubble(mRow.getEntry()); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 509 | |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 510 | // Simulate notification cancellation. |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 511 | mRemoveInterceptor.onNotificationRemoveRequested(mRow.getEntry().key, REASON_APP_CANCEL); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 512 | |
| 513 | mBubbleController.expandStackAndSelectBubble(key); |
| 514 | } |
| 515 | |
| 516 | @Test |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 517 | public void testMarkNewNotificationAsShowInShade() { |
| 518 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 519 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 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()); |
| 587 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 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 |
| 595 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 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()); |
| 608 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 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 |
| 616 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 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()); |
| 629 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 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, |
| 649 | ZenModeController zenModeController) { |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 650 | super(context, statusBarWindowController, data, Runnable::run, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 651 | configurationController, interruptionStateProvider, zenModeController); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 652 | } |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 653 | |
| 654 | @Override |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 655 | public boolean shouldAutoBubbleForFlags(Context c, NotificationEntry entry) { |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 656 | return entry.notification.getNotification().getBubbleMetadata() != null; |
| 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 | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 660 | public static class TestableNotificationInterruptionStateProvider extends |
| 661 | NotificationInterruptionStateProvider { |
| 662 | |
| 663 | public TestableNotificationInterruptionStateProvider(Context context) { |
| 664 | super(context); |
| 665 | mUseHeadsUp = true; |
| 666 | } |
| 667 | } |
| 668 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 669 | /** |
| 670 | * @return basic {@link android.app.Notification.BubbleMetadata.Builder} |
| 671 | */ |
| 672 | private Notification.BubbleMetadata.Builder getBuilder() { |
| 673 | Intent target = new Intent(mContext, BubblesTestActivity.class); |
| 674 | PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, target, 0); |
| 675 | return new Notification.BubbleMetadata.Builder() |
| 676 | .setIntent(bubbleIntent) |
| 677 | .setIcon(Icon.createWithResource(mContext, R.drawable.android)); |
| 678 | } |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 679 | } |