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