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; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 23 | import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED; |
Mady Mellor | 1a4e86f | 2019-05-03 16:07:23 -0700 | [diff] [blame] | 24 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 25 | import static com.google.common.truth.Truth.assertThat; |
| 26 | |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 27 | import static org.junit.Assert.assertEquals; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 28 | import static org.junit.Assert.assertFalse; |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 29 | import static org.junit.Assert.assertNotNull; |
| 30 | import static org.junit.Assert.assertNull; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 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 | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 33 | import static org.mockito.ArgumentMatchers.anyInt; |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.anyString; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 35 | import static org.mockito.ArgumentMatchers.eq; |
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 | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame] | 44 | import android.app.INotificationManager; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 45 | import android.app.Notification; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 46 | import android.app.PendingIntent; |
Joshua Tsuji | 3347739 | 2020-06-19 18:35:35 -0400 | [diff] [blame] | 47 | import android.content.pm.LauncherApps; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 48 | import android.hardware.display.AmbientDisplayConfiguration; |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 49 | import android.hardware.face.FaceManager; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 50 | import android.os.Handler; |
| 51 | import android.os.PowerManager; |
| 52 | import android.service.dreams.IDreamManager; |
Mady Mellor | 7634301 | 2020-05-13 11:02:50 -0700 | [diff] [blame] | 53 | import android.service.notification.NotificationListenerService; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 54 | import android.service.notification.ZenModeConfig; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 55 | import android.testing.AndroidTestingRunner; |
| 56 | import android.testing.TestableLooper; |
| 57 | import android.view.WindowManager; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 58 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 59 | import androidx.test.filters.SmallTest; |
| 60 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 61 | import com.android.internal.colorextraction.ColorExtractor; |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 62 | import com.android.internal.statusbar.IStatusBarService; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 63 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 64 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 65 | import com.android.systemui.dump.DumpManager; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 66 | import com.android.systemui.model.SysUiState; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 67 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 68 | import com.android.systemui.shared.system.QuickStepContract; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.FeatureFlags; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 70 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Mady Mellor | 7634301 | 2020-05-13 11:02:50 -0700 | [diff] [blame] | 72 | import com.android.systemui.statusbar.RankingBuilder; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 73 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 74 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 75 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 76 | import com.android.systemui.statusbar.notification.NotificationFilter; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 77 | import com.android.systemui.statusbar.notification.collection.NotifPipeline; |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 78 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 79 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 80 | import com.android.systemui.statusbar.notification.row.NotificationTestHelper; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 81 | import com.android.systemui.statusbar.phone.DozeParameters; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 82 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 83 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 84 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 85 | import com.android.systemui.statusbar.phone.NotificationShadeWindowView; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 86 | import com.android.systemui.statusbar.phone.ShadeController; |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 87 | import com.android.systemui.statusbar.policy.BatteryController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 89 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 90 | import com.android.systemui.statusbar.policy.ZenModeController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 91 | import com.android.systemui.util.FloatingContentCoordinator; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 92 | |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 93 | import com.google.common.collect.ImmutableList; |
| 94 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 95 | import org.junit.Before; |
Josh Tsuji | 72e12cb | 2020-06-12 16:49:33 -0400 | [diff] [blame] | 96 | import org.junit.Ignore; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 97 | import org.junit.Test; |
| 98 | import org.junit.runner.RunWith; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 99 | import org.mockito.ArgumentCaptor; |
| 100 | import org.mockito.Captor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 101 | import org.mockito.Mock; |
| 102 | import org.mockito.MockitoAnnotations; |
| 103 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 104 | import java.util.List; |
| 105 | |
| 106 | /** |
| 107 | * Tests the NotificationEntryManager setup with BubbleController. |
| 108 | * The {@link NotifPipeline} setup with BubbleController is tested in |
| 109 | * {@link NewNotifPipelineBubbleControllerTest}. |
| 110 | */ |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 111 | @SmallTest |
| 112 | @RunWith(AndroidTestingRunner.class) |
| 113 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 114 | public class BubbleControllerTest extends SysuiTestCase { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 115 | @Mock |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 116 | private NotificationEntryManager mNotificationEntryManager; |
| 117 | @Mock |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 118 | private NotificationGroupManager mNotificationGroupManager; |
| 119 | @Mock |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 120 | private WindowManager mWindowManager; |
| 121 | @Mock |
| 122 | private IActivityManager mActivityManager; |
| 123 | @Mock |
| 124 | private DozeParameters mDozeParameters; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 125 | @Mock |
| 126 | private ConfigurationController mConfigurationController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 127 | @Mock |
| 128 | private ZenModeController mZenModeController; |
| 129 | @Mock |
| 130 | private ZenModeConfig mZenModeConfig; |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 131 | @Mock |
| 132 | private FaceManager mFaceManager; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 133 | @Mock |
| 134 | private NotificationLockscreenUserManager mLockscreenUserManager; |
Mady Mellor | f474e0d | 2019-08-01 11:08:40 -0700 | [diff] [blame] | 135 | @Mock |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 136 | private SysuiStatusBarStateController mStatusBarStateController; |
| 137 | @Mock |
| 138 | private KeyguardBypassController mKeyguardBypassController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 139 | @Mock |
| 140 | private FloatingContentCoordinator mFloatingContentCoordinator; |
Pinyao Ting | ee191b1 | 2020-04-29 18:35:39 -0700 | [diff] [blame] | 141 | @Mock |
| 142 | private BubbleDataRepository mDataRepository; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 143 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 144 | private SysUiState mSysUiState; |
| 145 | private boolean mSysUiStateBubblesExpanded; |
| 146 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 147 | @Captor |
| 148 | private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 149 | @Captor |
| 150 | private ArgumentCaptor<NotificationRemoveInterceptor> mRemoveInterceptorCaptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 151 | |
| 152 | private TestableBubbleController mBubbleController; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 153 | private NotificationShadeWindowController mNotificationShadeWindowController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 154 | private NotificationEntryListener mEntryListener; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 155 | private NotificationRemoveInterceptor mRemoveInterceptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 156 | |
| 157 | private NotificationTestHelper mNotificationTestHelper; |
| 158 | private ExpandableNotificationRow mRow; |
| 159 | private ExpandableNotificationRow mRow2; |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 160 | private ExpandableNotificationRow mRow3; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 161 | private ExpandableNotificationRow mNonBubbleNotifRow; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 162 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 163 | @Mock |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 164 | private BubbleController.BubbleExpandListener mBubbleExpandListener; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 165 | @Mock |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 166 | private PendingIntent mDeleteIntent; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 167 | @Mock |
| 168 | private SysuiColorExtractor mColorExtractor; |
| 169 | @Mock |
| 170 | ColorExtractor.GradientColors mGradientColors; |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 171 | @Mock |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 172 | private ShadeController mShadeController; |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 173 | @Mock |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 174 | private NotifPipeline mNotifPipeline; |
| 175 | @Mock |
| 176 | private FeatureFlags mFeatureFlagsOldPipeline; |
| 177 | @Mock |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 178 | private DumpManager mDumpManager; |
Dave Mankoff | c0d9a7d | 2020-02-27 17:15:52 -0500 | [diff] [blame] | 179 | @Mock |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 180 | private NotificationShadeWindowView mNotificationShadeWindowView; |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 181 | @Mock |
| 182 | private IStatusBarService mStatusBarService; |
Joshua Tsuji | 3347739 | 2020-06-19 18:35:35 -0400 | [diff] [blame] | 183 | @Mock |
| 184 | private LauncherApps mLauncherApps; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 185 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 186 | private BubbleData mBubbleData; |
| 187 | |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 188 | private TestableLooper mTestableLooper; |
| 189 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 190 | @Before |
| 191 | public void setUp() throws Exception { |
| 192 | MockitoAnnotations.initMocks(this); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 193 | |
| 194 | mTestableLooper = TestableLooper.get(this); |
| 195 | |
Mady Mellor | 80c25b2 | 2019-06-17 14:40:37 -0700 | [diff] [blame] | 196 | mContext.addMockSystemService(FaceManager.class, mFaceManager); |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 197 | when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 198 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 199 | mNotificationShadeWindowController = new NotificationShadeWindowController(mContext, |
| 200 | mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, |
Lucas Dupin | d73410a | 2020-02-18 12:54:41 -0800 | [diff] [blame] | 201 | mConfigurationController, mKeyguardBypassController, mColorExtractor, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 202 | mDumpManager); |
Fabian Kozynski | b00c70b | 2020-04-03 12:41:31 -0400 | [diff] [blame] | 203 | mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 204 | mNotificationShadeWindowController.attach(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 205 | |
| 206 | // Need notifications for bubbles |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 207 | mNotificationTestHelper = new NotificationTestHelper( |
| 208 | mContext, |
| 209 | mDependency, |
| 210 | TestableLooper.get(this)); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 211 | mRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 212 | mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 213 | mRow3 = mNotificationTestHelper.createBubble(mDeleteIntent); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 214 | mNonBubbleNotifRow = mNotificationTestHelper.createRow(); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 215 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 216 | // Return non-null notification data from the NEM |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 217 | when(mNotificationEntryManager |
| 218 | .getActiveNotificationUnfiltered(mRow.getEntry().getKey())).thenReturn( |
| 219 | mRow.getEntry()); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 220 | |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 221 | mZenModeConfig.suppressedVisualEffects = 0; |
| 222 | when(mZenModeController.getConfig()).thenReturn(mZenModeConfig); |
| 223 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 224 | mSysUiState = new SysUiState(); |
| 225 | mSysUiState.addCallback(sysUiFlags -> |
| 226 | mSysUiStateBubblesExpanded = |
| 227 | (sysUiFlags & QuickStepContract.SYSUI_STATE_BUBBLES_EXPANDED) != 0); |
| 228 | |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 229 | TestableNotificationInterruptStateProviderImpl interruptionStateProvider = |
| 230 | new TestableNotificationInterruptStateProviderImpl(mContext.getContentResolver(), |
| 231 | mock(PowerManager.class), |
| 232 | mock(IDreamManager.class), |
| 233 | mock(AmbientDisplayConfiguration.class), |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 234 | mock(NotificationFilter.class), |
Lucas Dupin | bd7366d | 2019-09-25 13:39:21 -0700 | [diff] [blame] | 235 | mock(StatusBarStateController.class), |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 236 | mock(BatteryController.class), |
| 237 | mock(HeadsUpManager.class), |
| 238 | mock(Handler.class) |
| 239 | ); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 240 | mBubbleData = new BubbleData(mContext); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 241 | when(mFeatureFlagsOldPipeline.isNewNotifPipelineRenderingEnabled()).thenReturn(false); |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 242 | mBubbleController = new TestableBubbleController( |
| 243 | mContext, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 244 | mNotificationShadeWindowController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 245 | mStatusBarStateController, |
| 246 | mShadeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 247 | mBubbleData, |
| 248 | mConfigurationController, |
| 249 | interruptionStateProvider, |
| 250 | mZenModeController, |
| 251 | mLockscreenUserManager, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 252 | mNotificationGroupManager, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 253 | mNotificationEntryManager, |
| 254 | mNotifPipeline, |
| 255 | mFeatureFlagsOldPipeline, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 256 | mDumpManager, |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 257 | mFloatingContentCoordinator, |
Pinyao Ting | ee191b1 | 2020-04-29 18:35:39 -0700 | [diff] [blame] | 258 | mDataRepository, |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame] | 259 | mSysUiState, |
Mady Mellor | 59a7b98 | 2020-05-11 15:19:59 -0700 | [diff] [blame] | 260 | mock(INotificationManager.class), |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 261 | mStatusBarService, |
Joshua Tsuji | 3347739 | 2020-06-19 18:35:35 -0400 | [diff] [blame] | 262 | mWindowManager, |
| 263 | mLauncherApps); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 264 | mBubbleController.setExpandListener(mBubbleExpandListener); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 265 | |
| 266 | // Get a reference to the BubbleController's entry listener |
| 267 | verify(mNotificationEntryManager, atLeastOnce()) |
| 268 | .addNotificationEntryListener(mEntryListenerCaptor.capture()); |
| 269 | mEntryListener = mEntryListenerCaptor.getValue(); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 270 | // And the remove interceptor |
| 271 | verify(mNotificationEntryManager, atLeastOnce()) |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 272 | .addNotificationRemoveInterceptor(mRemoveInterceptorCaptor.capture()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 273 | mRemoveInterceptor = mRemoveInterceptorCaptor.getValue(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 277 | public void testAddBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 278 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 279 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 280 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 281 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void testHasBubbles() { |
| 286 | assertFalse(mBubbleController.hasBubbles()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 287 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 288 | assertTrue(mBubbleController.hasBubbles()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 289 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @Test |
| 293 | public void testRemoveBubble() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 294 | mBubbleController.updateBubble(mRow.getEntry()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 295 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 296 | assertTrue(mBubbleController.hasBubbles()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 297 | verify(mNotificationEntryManager).updateNotifications(any()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 298 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 299 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 300 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 301 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 302 | verify(mNotificationEntryManager, times(2)).updateNotifications(anyString()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 303 | |
| 304 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Test |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 308 | public void testPromoteBubble_autoExpand() throws Exception { |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 309 | mBubbleController.updateBubble(mRow2.getEntry()); |
| 310 | mBubbleController.updateBubble(mRow.getEntry()); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 311 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow.getEntry().getKey())) |
| 312 | .thenReturn(mRow.getEntry()); |
| 313 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow2.getEntry().getKey())) |
| 314 | .thenReturn(mRow2.getEntry()); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 315 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 316 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 317 | |
| 318 | Bubble b = mBubbleData.getOverflowBubbleWithKey(mRow.getEntry().getKey()); |
| 319 | assertThat(mBubbleData.getOverflowBubbles()).isEqualTo(ImmutableList.of(b)); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 320 | verify(mNotificationEntryManager, never()).performRemoveNotification( |
| 321 | eq(mRow.getEntry().getSbn()), anyInt()); |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 322 | assertThat(mRow.getEntry().isBubble()).isFalse(); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 323 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 324 | Bubble b2 = mBubbleData.getBubbleInStackWithKey(mRow2.getEntry().getKey()); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 325 | assertThat(mBubbleData.getSelectedBubble()).isEqualTo(b2); |
| 326 | |
| 327 | mBubbleController.promoteBubbleFromOverflow(b); |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 328 | |
| 329 | assertThat(b.isBubble()).isTrue(); |
| 330 | assertThat(b.shouldAutoExpand()).isTrue(); |
| 331 | int flags = Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE |
| 332 | | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 333 | verify(mStatusBarService, times(1)).onNotificationBubbleChanged( |
| 334 | eq(b.getKey()), eq(true), eq(flags)); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | @Test |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 338 | public void testCancelOverflowBubble() { |
| 339 | mBubbleController.updateBubble(mRow2.getEntry()); |
| 340 | mBubbleController.updateBubble(mRow.getEntry(), /* suppressFlyout */ |
| 341 | false, /* showInShade */ true); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 342 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow.getEntry().getKey())) |
| 343 | .thenReturn(mRow.getEntry()); |
| 344 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow2.getEntry().getKey())) |
| 345 | .thenReturn(mRow2.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 346 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 347 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 348 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 349 | mBubbleController.removeBubble( |
| 350 | mRow.getEntry().getKey(), BubbleController.DISMISS_NOTIF_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 351 | verify(mNotificationEntryManager, times(1)).performRemoveNotification( |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 352 | eq(mRow.getEntry().getSbn()), anyInt()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 353 | assertThat(mBubbleData.getOverflowBubbles()).isEmpty(); |
| 354 | assertFalse(mRow.getEntry().isBubble()); |
| 355 | } |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 356 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 357 | @Test |
| 358 | public void testUserChange_doesNotRemoveNotif() { |
| 359 | mBubbleController.updateBubble(mRow.getEntry()); |
| 360 | assertTrue(mBubbleController.hasBubbles()); |
| 361 | |
| 362 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 363 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_CHANGED); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 364 | verify(mNotificationEntryManager, never()).performRemoveNotification( |
| 365 | eq(mRow.getEntry().getSbn()), anyInt()); |
| 366 | assertFalse(mBubbleController.hasBubbles()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 367 | assertFalse(mSysUiStateBubblesExpanded); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 368 | assertTrue(mRow.getEntry().isBubble()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 372 | public void testDismissStack() { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 373 | mBubbleController.updateBubble(mRow.getEntry()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 374 | verify(mNotificationEntryManager, times(1)).updateNotifications(any()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 375 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 376 | mBubbleController.updateBubble(mRow2.getEntry()); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 377 | verify(mNotificationEntryManager, times(2)).updateNotifications(any()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 378 | assertNotNull(mBubbleData.getBubbleInStackWithKey(mRow2.getEntry().getKey())); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 379 | assertTrue(mBubbleController.hasBubbles()); |
| 380 | |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 381 | mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE); |
Beverly | 85d4c19 | 2019-09-30 11:40:39 -0400 | [diff] [blame] | 382 | verify(mNotificationEntryManager, times(3)).updateNotifications(any()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 383 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
| 384 | assertNull(mBubbleData.getBubbleInStackWithKey(mRow2.getEntry().getKey())); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 385 | |
| 386 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 390 | public void testExpandCollapseStack() { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 391 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 392 | |
| 393 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 394 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 395 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 396 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 397 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 398 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 399 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 400 | mRow.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 401 | |
| 402 | // Expand the stack |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 403 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 404 | mBubbleData.setExpanded(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 405 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 406 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 407 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 408 | assertTrue(mSysUiStateBubblesExpanded); |
| 409 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 410 | // Make sure the notif is suppressed |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 411 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 412 | mRow.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 413 | |
| 414 | // Collapse |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 415 | mBubbleController.collapseStack(); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 416 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 417 | assertFalse(mBubbleController.isStackExpanded()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 418 | |
| 419 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | @Test |
Josh Tsuji | 72e12cb | 2020-06-12 16:49:33 -0400 | [diff] [blame] | 423 | @Ignore("Currently broken.") |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 424 | public void testCollapseAfterChangingExpandedBubble() { |
| 425 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 426 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 427 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 428 | mBubbleController.updateBubble(mRow.getEntry()); |
| 429 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 430 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 431 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 432 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 433 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 434 | mRow.getEntry())); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 435 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 436 | mRow2.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 437 | |
| 438 | // Expand |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 439 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 440 | mBubbleData.setExpanded(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 441 | assertTrue(mBubbleController.isStackExpanded()); |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 442 | verify(mBubbleExpandListener, atLeastOnce()).onBubbleExpandChanged( |
| 443 | true, mRow2.getEntry().getKey()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 444 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 445 | assertTrue(mSysUiStateBubblesExpanded); |
| 446 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 447 | // Last added is the one that is expanded |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 448 | assertEquals(mRow2.getEntry().getKey(), mBubbleData.getSelectedBubble().getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 449 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 450 | mRow2.getEntry())); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 451 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 452 | // Switch which bubble is expanded |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 453 | mBubbleData.setSelectedBubble(mBubbleData.getBubbleInStackWithKey( |
| 454 | mRow.getEntry().getKey())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 455 | mBubbleData.setExpanded(true); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 456 | assertEquals(mRow.getEntry().getKey(), mBubbleData.getBubbleInStackWithKey( |
| 457 | stackView.getExpandedBubble().getKey()).getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 458 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 459 | mRow.getEntry())); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 460 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 461 | // collapse for previous bubble |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 462 | verify(mBubbleExpandListener, atLeastOnce()).onBubbleExpandChanged( |
| 463 | false, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 464 | // expand for selected bubble |
Joshua Tsuji | 06785ab | 2020-06-08 11:18:40 -0400 | [diff] [blame] | 465 | verify(mBubbleExpandListener, atLeastOnce()).onBubbleExpandChanged( |
| 466 | true, mRow.getEntry().getKey()); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 467 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 468 | // Collapse |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 469 | mBubbleController.collapseStack(); |
| 470 | assertFalse(mBubbleController.isStackExpanded()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 471 | |
| 472 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 475 | @Test |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 476 | public void testExpansionRemovesShowInShadeAndDot() { |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 477 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 478 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 479 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 480 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 481 | // We should have bubbles & their notifs should not be suppressed |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 482 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 483 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 484 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 485 | |
| 486 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 487 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 488 | |
| 489 | // Expand |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 490 | mBubbleData.setExpanded(true); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 491 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 492 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 493 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 494 | assertTrue(mSysUiStateBubblesExpanded); |
| 495 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 496 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 497 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 498 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 499 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 500 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | @Test |
| 504 | public void testUpdateWhileExpanded_DoesntChangeShowInShadeAndDot() { |
| 505 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 506 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 507 | mBubbleController.updateBubble(mRow.getEntry()); |
| 508 | |
| 509 | // We should have bubbles & their notifs should not be suppressed |
| 510 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 511 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 512 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 513 | |
| 514 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 515 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 516 | |
| 517 | // Expand |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 518 | mBubbleData.setExpanded(true); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 519 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 520 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 521 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 522 | assertTrue(mSysUiStateBubblesExpanded); |
| 523 | |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 524 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 525 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 526 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 527 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 528 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 529 | |
| 530 | // Send update |
| 531 | mEntryListener.onPreEntryUpdated(mRow.getEntry()); |
| 532 | |
| 533 | // Nothing should have changed |
| 534 | // Notif is suppressed after expansion |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 535 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 536 | mRow.getEntry())); |
Mady Mellor | aea895f0 | 2019-07-10 14:37:48 -0700 | [diff] [blame] | 537 | // Notif shouldn't show dot after expansion |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 538 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | @Test |
| 542 | public void testRemoveLastExpandedCollapses() { |
| 543 | // Mark it as a bubble and add it explicitly |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 544 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 545 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 546 | mBubbleController.updateBubble(mRow.getEntry()); |
| 547 | mBubbleController.updateBubble(mRow2.getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 548 | |
| 549 | // Expand |
| 550 | BubbleStackView stackView = mBubbleController.getStackView(); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 551 | mBubbleData.setExpanded(true); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 552 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 553 | assertTrue(mSysUiStateBubblesExpanded); |
| 554 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 555 | assertTrue(mBubbleController.isStackExpanded()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 556 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 557 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 558 | // Last added is the one that is expanded |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 559 | assertEquals(mRow2.getEntry().getKey(), mBubbleData.getBubbleInStackWithKey( |
| 560 | stackView.getExpandedBubble().getKey()).getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 561 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 562 | mRow2.getEntry())); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 563 | |
| 564 | // Dismiss currently expanded |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 565 | mBubbleController.removeBubble( |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 566 | mBubbleData.getBubbleInStackWithKey( |
| 567 | stackView.getExpandedBubble().getKey()).getKey(), |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 568 | BubbleController.DISMISS_USER_GESTURE); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 569 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 570 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 571 | // Make sure first bubble is selected |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 572 | assertEquals(mRow.getEntry().getKey(), mBubbleData.getBubbleInStackWithKey( |
| 573 | stackView.getExpandedBubble().getKey()).getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 574 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 575 | |
| 576 | // Dismiss that one |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 577 | mBubbleController.removeBubble( |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 578 | mBubbleData.getBubbleInStackWithKey( |
| 579 | stackView.getExpandedBubble().getKey()).getKey(), |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 580 | BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 581 | |
| 582 | // Make sure state changes and collapse happens |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 583 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 584 | assertFalse(mBubbleController.hasBubbles()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 585 | |
| 586 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 590 | public void testAutoExpand_fails_noFlag() { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 591 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 592 | setMetadataFlags(mRow.getEntry(), |
| 593 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 594 | |
| 595 | // Add the auto expand bubble |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 596 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 597 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 598 | |
| 599 | // Expansion shouldn't change |
| 600 | verify(mBubbleExpandListener, never()).onBubbleExpandChanged(false /* expanded */, |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 601 | mRow.getEntry().getKey()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 602 | assertFalse(mBubbleController.isStackExpanded()); |
| 603 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 604 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 608 | public void testAutoExpand_succeeds_withFlag() { |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 609 | setMetadataFlags(mRow.getEntry(), |
| 610 | Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 611 | |
| 612 | // Add the auto expand bubble |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 613 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 614 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 615 | |
| 616 | // Expansion should change |
| 617 | verify(mBubbleExpandListener).onBubbleExpandChanged(true /* expanded */, |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 618 | mRow.getEntry().getKey()); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 619 | assertTrue(mBubbleController.isStackExpanded()); |
| 620 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 621 | assertTrue(mSysUiStateBubblesExpanded); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 624 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 625 | public void testSuppressNotif_onInitialNotif() { |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 626 | setMetadataFlags(mRow.getEntry(), |
| 627 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 628 | |
| 629 | // Add the suppress notif bubble |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 630 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 631 | mBubbleController.updateBubble(mRow.getEntry()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 632 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 633 | // Notif should be suppressed because we were foreground |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 634 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 635 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 636 | // Dot + flyout is hidden because notif is suppressed |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 637 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
| 638 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showFlyout()); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 639 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 640 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | 3ed4620 | 2019-03-26 20:22:35 -0700 | [diff] [blame] | 641 | } |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 642 | |
| 643 | @Test |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 644 | public void testSuppressNotif_onUpdateNotif() { |
| 645 | mBubbleController.updateBubble(mRow.getEntry()); |
| 646 | |
| 647 | // Should not be suppressed |
| 648 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 649 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 650 | // Should show dot |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 651 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 652 | |
| 653 | // Update to suppress notif |
| 654 | setMetadataFlags(mRow.getEntry(), |
| 655 | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */); |
| 656 | mBubbleController.updateBubble(mRow.getEntry()); |
| 657 | |
| 658 | // Notif should be suppressed |
| 659 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 660 | mRow.getEntry())); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 661 | // Dot + flyout is hidden because notif is suppressed |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 662 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
| 663 | assertFalse(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showFlyout()); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 664 | |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 665 | assertFalse(mSysUiStateBubblesExpanded); |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 668 | @Test |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 669 | public void testExpandStackAndSelectBubble_removedFirst() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 670 | final String key = mRow.getEntry().getKey(); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 671 | |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 672 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 673 | mBubbleController.updateBubble(mRow.getEntry()); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 674 | |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 675 | // Simulate notification cancellation. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 676 | mRemoveInterceptor.onNotificationRemoveRequested( |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 677 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_APP_CANCEL); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 678 | |
Mady Mellor | 7634301 | 2020-05-13 11:02:50 -0700 | [diff] [blame] | 679 | mBubbleController.expandStackAndSelectBubble(mRow.getEntry()); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 680 | |
| 681 | assertTrue(mSysUiStateBubblesExpanded); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | @Test |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 685 | public void testMarkNewNotificationAsShowInShade() { |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 686 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 687 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 688 | mRow.getEntry())); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 689 | |
| 690 | mTestableLooper.processAllMessages(); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 691 | assertTrue(mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey()).showDot()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 694 | @Test |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 695 | public void testAddNotif_notBubble() { |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 696 | mEntryListener.onPendingEntryAdded(mNonBubbleNotifRow.getEntry()); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 697 | mEntryListener.onPreEntryUpdated(mNonBubbleNotifRow.getEntry()); |
| 698 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 699 | assertThat(mBubbleController.hasBubbles()).isFalse(); |
| 700 | } |
| 701 | |
| 702 | @Test |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 703 | public void testDeleteIntent_removeBubble_aged() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 704 | mBubbleController.updateBubble(mRow.getEntry()); |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 705 | mBubbleController.removeBubble(mRow.getEntry().getKey(), BubbleController.DISMISS_AGED); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 706 | verify(mDeleteIntent, never()).send(); |
| 707 | } |
| 708 | |
| 709 | @Test |
| 710 | public void testDeleteIntent_removeBubble_user() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 711 | mBubbleController.updateBubble(mRow.getEntry()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 712 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 713 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 714 | verify(mDeleteIntent, times(1)).send(); |
| 715 | } |
| 716 | |
| 717 | @Test |
| 718 | public void testDeleteIntent_dismissStack() throws PendingIntent.CanceledException { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 719 | mBubbleController.updateBubble(mRow.getEntry()); |
| 720 | mBubbleController.updateBubble(mRow2.getEntry()); |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 721 | mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 722 | verify(mDeleteIntent, times(2)).send(); |
| 723 | } |
| 724 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 725 | @Test |
| 726 | public void testRemoveBubble_noLongerBubbleAfterUpdate() |
| 727 | throws PendingIntent.CanceledException { |
| 728 | mBubbleController.updateBubble(mRow.getEntry()); |
| 729 | assertTrue(mBubbleController.hasBubbles()); |
| 730 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 731 | mRow.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 7634301 | 2020-05-13 11:02:50 -0700 | [diff] [blame] | 732 | NotificationListenerService.Ranking ranking = new RankingBuilder( |
| 733 | mRow.getEntry().getRanking()).setCanBubble(false).build(); |
| 734 | mRow.getEntry().setRanking(ranking); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 735 | mEntryListener.onPreEntryUpdated(mRow.getEntry()); |
| 736 | |
| 737 | assertFalse(mBubbleController.hasBubbles()); |
| 738 | verify(mDeleteIntent, never()).send(); |
| 739 | } |
| 740 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 741 | @Test |
| 742 | public void testRemoveBubble_succeeds_appCancel() { |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 743 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 744 | mBubbleController.updateBubble(mRow.getEntry()); |
| 745 | |
| 746 | assertTrue(mBubbleController.hasBubbles()); |
| 747 | |
| 748 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 749 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_APP_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 750 | |
| 751 | // Cancels always remove so no need to intercept |
| 752 | assertFalse(intercepted); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | @Test |
| 756 | public void testRemoveBubble_entryListenerRemove() { |
| 757 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 758 | mBubbleController.updateBubble(mRow.getEntry()); |
| 759 | |
| 760 | assertTrue(mBubbleController.hasBubbles()); |
| 761 | |
| 762 | // Removes the notification |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 763 | mEntryListener.onEntryRemoved(mRow.getEntry(), null, false, REASON_APP_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 764 | assertFalse(mBubbleController.hasBubbles()); |
| 765 | } |
| 766 | |
| 767 | @Test |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 768 | public void removeBubble_clearAllIntercepted() { |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 769 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 770 | mBubbleController.updateBubble(mRow.getEntry()); |
| 771 | |
| 772 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 773 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 774 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 775 | |
| 776 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 777 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL_ALL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 778 | |
| 779 | // Intercept! |
| 780 | assertTrue(intercepted); |
| 781 | // Should update show in shade state |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 782 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 783 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | @Test |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 787 | public void removeBubble_userDismissNotifIntercepted() { |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 788 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 789 | mBubbleController.updateBubble(mRow.getEntry()); |
| 790 | |
| 791 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 792 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 793 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 794 | |
| 795 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 796 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 797 | |
| 798 | // Intercept! |
| 799 | assertTrue(intercepted); |
| 800 | // Should update show in shade state |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 801 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 802 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | @Test |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 806 | public void removeNotif_inOverflow_intercepted() { |
| 807 | // Get bubble with notif in shade. |
| 808 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 809 | mBubbleController.updateBubble(mRow.getEntry()); |
| 810 | assertTrue(mBubbleController.hasBubbles()); |
| 811 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 812 | mRow.getEntry())); |
| 813 | |
| 814 | // Dismiss the bubble into overflow. |
| 815 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 816 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 817 | assertFalse(mBubbleController.hasBubbles()); |
| 818 | |
| 819 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
| 820 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL); |
| 821 | |
| 822 | // Notif is no longer a bubble, but still in overflow, so we intercept removal. |
| 823 | assertTrue(intercepted); |
| 824 | } |
| 825 | |
| 826 | @Test |
| 827 | public void removeNotif_notInOverflow_notIntercepted() { |
| 828 | // Get bubble with notif in shade. |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 829 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 830 | mBubbleController.updateBubble(mRow.getEntry()); |
| 831 | |
| 832 | assertTrue(mBubbleController.hasBubbles()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 833 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 834 | mRow.getEntry())); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 835 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 836 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 837 | mRow.getEntry().getKey(), BubbleController.DISMISS_NO_LONGER_BUBBLE); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 838 | assertFalse(mBubbleController.hasBubbles()); |
| 839 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 840 | boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested( |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 841 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 842 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 843 | // Notif is no longer a bubble, so we should not intercept removal. |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 844 | assertFalse(intercepted); |
| 845 | } |
| 846 | |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 847 | @Test |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 848 | public void testOverflowBubble_maxReached_notInShade_bubbleRemoved() { |
| 849 | mBubbleController.updateBubble( |
| 850 | mRow.getEntry(), /* suppressFlyout */ false, /* showInShade */ false); |
| 851 | mBubbleController.updateBubble( |
| 852 | mRow2.getEntry(), /* suppressFlyout */ false, /* showInShade */ false); |
| 853 | mBubbleController.updateBubble( |
| 854 | mRow3.getEntry(), /* suppressFlyout */ false, /* showInShade */ false); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 855 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow.getEntry().getKey())) |
| 856 | .thenReturn(mRow.getEntry()); |
| 857 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow2.getEntry().getKey())) |
| 858 | .thenReturn(mRow2.getEntry()); |
| 859 | when(mNotificationEntryManager.getPendingOrActiveNotif(mRow3.getEntry().getKey())) |
| 860 | .thenReturn(mRow3.getEntry()); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 861 | assertEquals(mBubbleData.getBubbles().size(), 3); |
| 862 | |
| 863 | mBubbleData.setMaxOverflowBubbles(1); |
| 864 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 865 | mRow.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 866 | assertEquals(mBubbleData.getBubbles().size(), 2); |
| 867 | assertEquals(mBubbleData.getOverflowBubbles().size(), 1); |
| 868 | |
| 869 | mBubbleController.removeBubble( |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 870 | mRow2.getEntry().getKey(), BubbleController.DISMISS_USER_GESTURE); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 871 | // Overflow max of 1 is reached; mRow is oldest, so it gets removed |
| 872 | verify(mNotificationEntryManager, times(1)).performRemoveNotification( |
| 873 | mRow.getEntry().getSbn(), REASON_CANCEL); |
| 874 | assertEquals(mBubbleData.getBubbles().size(), 1); |
| 875 | assertEquals(mBubbleData.getOverflowBubbles().size(), 1); |
| 876 | } |
| 877 | |
| 878 | @Test |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 879 | public void testNotifyShadeSuppressionChange_notificationDismiss() { |
| 880 | BubbleController.NotificationSuppressionChangedListener listener = |
| 881 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 882 | mBubbleData.setSuppressionChangedListener(listener); |
| 883 | |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 884 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 885 | |
| 886 | assertTrue(mBubbleController.hasBubbles()); |
| 887 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 888 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 889 | |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 890 | mRemoveInterceptor.onNotificationRemoveRequested( |
| 891 | mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 892 | |
| 893 | // Should update show in shade state |
| 894 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 895 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 896 | |
| 897 | // Should notify delegate that shade state changed |
| 898 | verify(listener).onBubbleNotificationSuppressionChange( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 899 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | @Test |
| 903 | public void testNotifyShadeSuppressionChange_bubbleExpanded() { |
| 904 | BubbleController.NotificationSuppressionChangedListener listener = |
| 905 | mock(BubbleController.NotificationSuppressionChangedListener.class); |
| 906 | mBubbleData.setSuppressionChangedListener(listener); |
| 907 | |
Mady Mellor | 7813351 | 2020-01-31 08:45:52 -0800 | [diff] [blame] | 908 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 909 | |
| 910 | assertTrue(mBubbleController.hasBubbles()); |
| 911 | assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 912 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 913 | |
| 914 | mBubbleData.setExpanded(true); |
| 915 | |
| 916 | // Once a bubble is expanded the notif is suppressed |
| 917 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 918 | mRow.getEntry())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 919 | |
| 920 | // Should notify delegate that shade state changed |
| 921 | verify(listener).onBubbleNotificationSuppressionChange( |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 922 | mBubbleData.getBubbleInStackWithKey(mRow.getEntry().getKey())); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 923 | } |
| 924 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 925 | @Test |
| 926 | public void testBubbleSummaryDismissal_suppressesSummaryAndBubbleFromShade() throws Exception { |
| 927 | // GIVEN a group summary with a bubble child |
| 928 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0); |
| 929 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 930 | when(mNotificationEntryManager.getPendingOrActiveNotif(groupedBubble.getEntry().getKey())) |
| 931 | .thenReturn(groupedBubble.getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 932 | mEntryListener.onPendingEntryAdded(groupedBubble.getEntry()); |
| 933 | groupSummary.addChildNotification(groupedBubble); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 934 | assertTrue(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 935 | |
| 936 | // WHEN the summary is dismissed |
| 937 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 938 | |
| 939 | // THEN the summary and bubbled child are suppressed from the shade |
| 940 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 941 | groupedBubble.getEntry())); |
| 942 | assertTrue(mBubbleData.isSummarySuppressed(groupSummary.getEntry().getSbn().getGroupKey())); |
| 943 | } |
| 944 | |
| 945 | @Test |
| 946 | public void testAppRemovesSummary_removesAllBubbleChildren() throws Exception { |
| 947 | // GIVEN a group summary with a bubble child |
| 948 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0); |
| 949 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
| 950 | mEntryListener.onPendingEntryAdded(groupedBubble.getEntry()); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 951 | when(mNotificationEntryManager.getPendingOrActiveNotif(groupedBubble.getEntry().getKey())) |
| 952 | .thenReturn(groupedBubble.getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 953 | groupSummary.addChildNotification(groupedBubble); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 954 | assertTrue(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 955 | |
| 956 | // GIVEN the summary is dismissed |
| 957 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 958 | |
| 959 | // WHEN the summary is cancelled by the app |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 960 | mEntryListener.onEntryRemoved(groupSummary.getEntry(), null, false, REASON_APP_CANCEL); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 961 | |
| 962 | // THEN the summary and its children are removed from bubble data |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 963 | assertFalse(mBubbleData.hasBubbleInStackWithKey(groupedBubble.getEntry().getKey())); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 964 | assertFalse(mBubbleData.isSummarySuppressed( |
| 965 | groupSummary.getEntry().getSbn().getGroupKey())); |
| 966 | } |
| 967 | |
| 968 | @Test |
| 969 | public void testSummaryDismissal_marksBubblesHiddenFromShadeAndDismissesNonBubbledChildren() |
| 970 | throws Exception { |
| 971 | // GIVEN a group summary with two (non-bubble) children and one bubble child |
| 972 | ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(2); |
| 973 | ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 974 | when(mNotificationEntryManager.getPendingOrActiveNotif(groupedBubble.getEntry().getKey())) |
| 975 | .thenReturn(groupedBubble.getEntry()); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 976 | mEntryListener.onPendingEntryAdded(groupedBubble.getEntry()); |
| 977 | groupSummary.addChildNotification(groupedBubble); |
| 978 | |
| 979 | // WHEN the summary is dismissed |
| 980 | mBubbleController.handleDismissalInterception(groupSummary.getEntry()); |
| 981 | |
| 982 | // THEN only the NON-bubble children are dismissed |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 983 | List<ExpandableNotificationRow> childrenRows = groupSummary.getAttachedChildren(); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 984 | verify(mNotificationEntryManager, times(1)).performRemoveNotification( |
| 985 | childrenRows.get(0).getEntry().getSbn(), REASON_GROUP_SUMMARY_CANCELED); |
| 986 | verify(mNotificationEntryManager, times(1)).performRemoveNotification( |
| 987 | childrenRows.get(1).getEntry().getSbn(), REASON_GROUP_SUMMARY_CANCELED); |
| 988 | verify(mNotificationEntryManager, never()).performRemoveNotification( |
| 989 | eq(groupedBubble.getEntry().getSbn()), anyInt()); |
| 990 | |
| 991 | // THEN the bubble child is suppressed from the shade |
| 992 | assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade( |
| 993 | groupedBubble.getEntry())); |
| 994 | |
| 995 | // THEN the summary is removed from GroupManager |
| 996 | verify(mNotificationGroupManager, times(1)).onEntryRemoved(groupSummary.getEntry()); |
| 997 | } |
| 998 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 999 | /** |
Aran Ink | c4381c4 | 2020-02-06 13:11:53 -0500 | [diff] [blame] | 1000 | * Sets the bubble metadata flags for this entry. These ]flags are normally set by |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 1001 | * NotificationManagerService when the notification is sent, however, these tests do not |
| 1002 | * go through that path so we set them explicitly when testing. |
| 1003 | */ |
| 1004 | private void setMetadataFlags(NotificationEntry entry, int flag, boolean enableFlag) { |
| 1005 | Notification.BubbleMetadata bubbleMetadata = |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 1006 | entry.getSbn().getNotification().getBubbleMetadata(); |
Mady Mellor | 8d25b20 | 2019-06-25 13:59:28 -0700 | [diff] [blame] | 1007 | int flags = bubbleMetadata.getFlags(); |
| 1008 | if (enableFlag) { |
| 1009 | flags |= flag; |
| 1010 | } else { |
| 1011 | flags &= ~flag; |
| 1012 | } |
| 1013 | bubbleMetadata.setFlags(flags); |
| 1014 | } |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 1015 | } |