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