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