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 | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 20 | import static org.junit.Assert.assertFalse; |
| 21 | import static org.junit.Assert.assertTrue; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 22 | import static org.mockito.Mockito.atLeastOnce; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 23 | import static org.mockito.Mockito.never; |
| 24 | import static org.mockito.Mockito.times; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 25 | import static org.mockito.Mockito.verify; |
| 26 | import static org.mockito.Mockito.when; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 27 | |
| 28 | import android.app.IActivityManager; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 30 | import android.content.Context; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 31 | import android.testing.AndroidTestingRunner; |
| 32 | import android.testing.TestableLooper; |
| 33 | import android.view.WindowManager; |
| 34 | import android.widget.FrameLayout; |
| 35 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 36 | import androidx.test.filters.SmallTest; |
| 37 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 38 | import com.android.systemui.SysuiTestCase; |
| 39 | import com.android.systemui.statusbar.NotificationTestHelper; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 41 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 44 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 45 | import com.android.systemui.statusbar.phone.DozeParameters; |
| 46 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
| 47 | |
| 48 | import org.junit.Before; |
| 49 | import org.junit.Test; |
| 50 | import org.junit.runner.RunWith; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 51 | import org.mockito.ArgumentCaptor; |
| 52 | import org.mockito.Captor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 53 | import org.mockito.Mock; |
| 54 | import org.mockito.MockitoAnnotations; |
| 55 | |
| 56 | @SmallTest |
| 57 | @RunWith(AndroidTestingRunner.class) |
| 58 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 59 | public class BubbleControllerTest extends SysuiTestCase { |
| 60 | |
| 61 | @Mock |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 62 | private NotificationEntryManager mNotificationEntryManager; |
| 63 | @Mock |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 64 | private WindowManager mWindowManager; |
| 65 | @Mock |
| 66 | private IActivityManager mActivityManager; |
| 67 | @Mock |
| 68 | private DozeParameters mDozeParameters; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 69 | private FrameLayout mStatusBarView; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 70 | @Captor |
| 71 | private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 72 | |
| 73 | private TestableBubbleController mBubbleController; |
| 74 | private StatusBarWindowController mStatusBarWindowController; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 75 | private NotificationEntryListener mEntryListener; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 76 | |
| 77 | private NotificationTestHelper mNotificationTestHelper; |
| 78 | private ExpandableNotificationRow mRow; |
| 79 | private ExpandableNotificationRow mRow2; |
Mady Mellor | c18ba96 | 2019-01-29 11:11:56 -0800 | [diff] [blame] | 80 | private ExpandableNotificationRow mNoChannelRow; |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 81 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 82 | @Mock |
| 83 | private NotificationData mNotificationData; |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 84 | @Mock |
| 85 | private BubbleController.BubbleStateChangeListener mBubbleStateChangeListener; |
| 86 | @Mock |
| 87 | private BubbleController.BubbleExpandListener mBubbleExpandListener; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 88 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 89 | @Mock |
| 90 | private PendingIntent mDeleteIntent; |
| 91 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 92 | private BubbleData mBubbleData; |
| 93 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 94 | @Before |
| 95 | public void setUp() throws Exception { |
| 96 | MockitoAnnotations.initMocks(this); |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 97 | mStatusBarView = new FrameLayout(mContext); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 98 | mDependency.injectTestDependency(NotificationEntryManager.class, mNotificationEntryManager); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 99 | |
| 100 | // Bubbles get added to status bar window view |
| 101 | mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, |
| 102 | mActivityManager, mDozeParameters); |
| 103 | mStatusBarWindowController.add(mStatusBarView, 120 /* height */); |
| 104 | |
| 105 | // Need notifications for bubbles |
| 106 | mNotificationTestHelper = new NotificationTestHelper(mContext); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 107 | mRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 108 | mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent); |
| 109 | mNoChannelRow = mNotificationTestHelper.createBubble(mDeleteIntent); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 110 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 111 | // Return non-null notification data from the NEM |
| 112 | when(mNotificationEntryManager.getNotificationData()).thenReturn(mNotificationData); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 113 | when(mNotificationData.getChannel(mRow.getEntry().key)).thenReturn(mRow.getEntry().channel); |
Mady Mellor | c18ba96 | 2019-01-29 11:11:56 -0800 | [diff] [blame] | 114 | when(mNotificationData.getChannel(mNoChannelRow.getEntry().key)).thenReturn(null); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 115 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 116 | mBubbleData = new BubbleData(); |
| 117 | mBubbleController = new TestableBubbleController(mContext, mStatusBarWindowController, |
| 118 | mBubbleData); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 119 | mBubbleController.setBubbleStateChangeListener(mBubbleStateChangeListener); |
| 120 | mBubbleController.setExpandListener(mBubbleExpandListener); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 121 | |
| 122 | // Get a reference to the BubbleController's entry listener |
| 123 | verify(mNotificationEntryManager, atLeastOnce()) |
| 124 | .addNotificationEntryListener(mEntryListenerCaptor.capture()); |
| 125 | mEntryListener = mEntryListenerCaptor.getValue(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Test |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 129 | public void testAddBubble() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 130 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 131 | assertTrue(mBubbleController.hasBubbles()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 132 | |
| 133 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Test |
| 137 | public void testHasBubbles() { |
| 138 | assertFalse(mBubbleController.hasBubbles()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 139 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 140 | assertTrue(mBubbleController.hasBubbles()); |
| 141 | } |
| 142 | |
| 143 | @Test |
| 144 | public void testRemoveBubble() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 145 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 146 | assertTrue(mBubbleController.hasBubbles()); |
| 147 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 148 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
| 149 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 150 | mBubbleController.removeBubble(mRow.getEntry().key, BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 151 | assertFalse(mStatusBarWindowController.getBubblesShowing()); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 152 | assertTrue(mRow.getEntry().isBubbleDismissed()); |
| 153 | verify(mNotificationEntryManager).updateNotifications(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 154 | verify(mBubbleStateChangeListener).onHasBubblesChanged(false); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
| 158 | public void testDismissStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 159 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 160 | mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 161 | assertTrue(mBubbleController.hasBubbles()); |
| 162 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 163 | mBubbleController.dismissStack(BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 164 | assertFalse(mStatusBarWindowController.getBubblesShowing()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 165 | verify(mNotificationEntryManager).updateNotifications(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 166 | assertTrue(mRow.getEntry().isBubbleDismissed()); |
| 167 | assertTrue(mRow2.getEntry().isBubbleDismissed()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 171 | public void testExpandCollapseStack() { |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 172 | assertFalse(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 173 | |
| 174 | // Mark it as a bubble and add it explicitly |
| 175 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 176 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 177 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 178 | // We should have bubbles & their notifs should show in the shade |
| 179 | assertTrue(mBubbleController.hasBubbles()); |
| 180 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 181 | assertFalse(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 182 | |
| 183 | // Expand the stack |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 184 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 185 | stackView.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 186 | assertTrue(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 187 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 188 | assertTrue(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 189 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 190 | // Make sure it's no longer in the shade |
| 191 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 192 | |
| 193 | // Collapse |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 194 | stackView.collapseStack(); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 195 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 196 | assertFalse(mBubbleController.isStackExpanded()); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 197 | assertFalse(mStatusBarWindowController.getBubbleExpanded()); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 201 | public void testCollapseAfterChangingExpandedBubble() { |
| 202 | // Mark it as a bubble and add it explicitly |
| 203 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 204 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 205 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 206 | mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 207 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 208 | // We should have bubbles & their notifs should show in the shade |
| 209 | assertTrue(mBubbleController.hasBubbles()); |
| 210 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 211 | assertTrue(mRow2.getEntry().showInShadeWhenBubble()); |
| 212 | |
| 213 | // Expand |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 214 | BubbleStackView stackView = mBubbleController.getStackView(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 215 | stackView.expandStack(); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 216 | assertTrue(mBubbleController.isStackExpanded()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 217 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 218 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 219 | // Last added is the one that is expanded |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 220 | assertEquals(mRow2.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 221 | assertFalse(mRow2.getEntry().showInShadeWhenBubble()); |
| 222 | |
| 223 | // Switch which bubble is expanded |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 224 | stackView.setExpandedBubble(mRow.getEntry()); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 225 | assertEquals(mRow.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 226 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 227 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 228 | // collapse for previous bubble |
| 229 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); |
| 230 | // expand for selected bubble |
| 231 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 232 | |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 233 | // Collapse |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 234 | mBubbleController.collapseStack(); |
| 235 | assertFalse(mBubbleController.isStackExpanded()); |
| 236 | } |
| 237 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 238 | @Test |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 239 | public void testExpansionRemovesShowInShade() { |
| 240 | // Mark it as a bubble and add it explicitly |
| 241 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 242 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 243 | |
| 244 | // We should have bubbles & their notifs should show in the shade |
| 245 | assertTrue(mBubbleController.hasBubbles()); |
| 246 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 247 | |
| 248 | // Expand |
| 249 | BubbleStackView stackView = mBubbleController.getStackView(); |
| 250 | stackView.expandStack(); |
| 251 | assertTrue(mBubbleController.isStackExpanded()); |
| 252 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
| 253 | |
| 254 | // No longer show shade in notif after expansion |
| 255 | assertFalse(mRow.getEntry().showInShadeWhenBubble()); |
| 256 | } |
| 257 | |
| 258 | @Test |
| 259 | public void testRemoveLastExpandedCollapses() { |
| 260 | // Mark it as a bubble and add it explicitly |
| 261 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 262 | mEntryListener.onPendingEntryAdded(mRow2.getEntry()); |
| 263 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 264 | mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); |
| 265 | verify(mBubbleStateChangeListener).onHasBubblesChanged(true); |
| 266 | |
| 267 | // Expand |
| 268 | BubbleStackView stackView = mBubbleController.getStackView(); |
| 269 | stackView.expandStack(); |
| 270 | |
| 271 | assertTrue(mBubbleController.isStackExpanded()); |
| 272 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().key); |
| 273 | |
| 274 | // Last added is the one that is expanded |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 275 | assertEquals(mRow2.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 276 | assertFalse(mRow2.getEntry().showInShadeWhenBubble()); |
| 277 | |
| 278 | // Dismiss currently expanded |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 279 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 280 | BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 281 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().key); |
| 282 | |
| 283 | // Make sure next bubble is selected |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 284 | assertEquals(mRow.getEntry(), stackView.getExpandedBubbleView().getEntry()); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 285 | verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().key); |
| 286 | |
| 287 | // Dismiss that one |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 288 | mBubbleController.removeBubble(stackView.getExpandedBubbleView().getKey(), |
| 289 | BubbleController.DISMISS_USER_GESTURE); |
Mady Mellor | acb1215 | 2019-01-29 15:24:48 -0800 | [diff] [blame] | 290 | |
| 291 | // Make sure state changes and collapse happens |
| 292 | verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().key); |
| 293 | verify(mBubbleStateChangeListener).onHasBubblesChanged(false); |
| 294 | assertFalse(mBubbleController.hasBubbles()); |
| 295 | } |
| 296 | |
| 297 | @Test |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 298 | public void testMarkNewNotificationAsBubble() { |
| 299 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 300 | assertTrue(mRow.getEntry().isBubble()); |
| 301 | } |
| 302 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 303 | @Test |
| 304 | public void testMarkNewNotificationAsShowInShade() { |
| 305 | mEntryListener.onPendingEntryAdded(mRow.getEntry()); |
| 306 | assertTrue(mRow.getEntry().showInShadeWhenBubble()); |
| 307 | } |
| 308 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 309 | @Test |
| 310 | public void testDeleteIntent_removeBubble_aged() throws PendingIntent.CanceledException { |
| 311 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 312 | mBubbleController.removeBubble(mRow.getEntry().key, BubbleController.DISMISS_AGED); |
| 313 | verify(mDeleteIntent, never()).send(); |
| 314 | } |
| 315 | |
| 316 | @Test |
| 317 | public void testDeleteIntent_removeBubble_user() throws PendingIntent.CanceledException { |
| 318 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 319 | mBubbleController.removeBubble(mRow.getEntry().key, BubbleController.DISMISS_USER_GESTURE); |
| 320 | verify(mDeleteIntent, times(1)).send(); |
| 321 | } |
| 322 | |
| 323 | @Test |
| 324 | public void testDeleteIntent_dismissStack() throws PendingIntent.CanceledException { |
| 325 | mBubbleController.updateBubble(mRow.getEntry(), true /* updatePosition */); |
| 326 | mBubbleController.updateBubble(mRow2.getEntry(), true /* updatePosition */); |
| 327 | mBubbleController.dismissStack(BubbleController.DISMISS_USER_GESTURE); |
| 328 | verify(mDeleteIntent, times(2)).send(); |
| 329 | } |
| 330 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 331 | static class TestableBubbleController extends BubbleController { |
| 332 | |
| 333 | TestableBubbleController(Context context, |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 334 | StatusBarWindowController statusBarWindowController, BubbleData data) { |
| 335 | super(context, statusBarWindowController, data); |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 336 | } |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 337 | |
| 338 | @Override |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 339 | public boolean shouldAutoBubbleForFlags(Context c, NotificationEntry entry) { |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 340 | return entry.notification.getNotification().getBubbleMetadata() != null; |
| 341 | } |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 342 | } |
| 343 | } |