Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.statusbar.notification.row; |
| 18 | |
| 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
| 20 | |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP; |
| 22 | |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 23 | import static junit.framework.Assert.assertNotNull; |
| 24 | |
| 25 | import static org.mockito.ArgumentMatchers.any; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 26 | import static org.mockito.Mockito.mock; |
| 27 | import static org.mockito.Mockito.never; |
| 28 | import static org.mockito.Mockito.verify; |
| 29 | import static org.mockito.Mockito.when; |
| 30 | |
| 31 | import android.app.Notification; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 32 | import android.content.pm.LauncherApps; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 33 | import android.os.Handler; |
| 34 | import android.service.notification.NotificationListenerService; |
| 35 | import android.service.notification.NotificationListenerService.Ranking; |
| 36 | import android.service.notification.StatusBarNotification; |
| 37 | import android.testing.AndroidTestingRunner; |
| 38 | import android.testing.TestableLooper; |
| 39 | |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 40 | import androidx.asynclayoutinflater.view.AsyncLayoutInflater; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 41 | import androidx.test.filters.SmallTest; |
| 42 | |
| 43 | import com.android.internal.util.NotificationMessagingUtil; |
| 44 | import com.android.systemui.R; |
| 45 | import com.android.systemui.SysuiTestCase; |
| 46 | import com.android.systemui.plugins.FalsingManager; |
| 47 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 48 | import com.android.systemui.shared.plugins.PluginManager; |
| 49 | import com.android.systemui.statusbar.FeatureFlags; |
| 50 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 51 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 52 | import com.android.systemui.statusbar.NotificationPresenter; |
| 53 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 54 | import com.android.systemui.statusbar.SbnBuilder; |
| 55 | import com.android.systemui.statusbar.SmartReplyController; |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 56 | import com.android.systemui.statusbar.notification.ConversationNotificationProcessor; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 57 | import com.android.systemui.statusbar.notification.ForegroundServiceDismissalFeatureController; |
| 58 | import com.android.systemui.statusbar.notification.NotificationClicker; |
| 59 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 60 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
| 61 | import com.android.systemui.statusbar.notification.NotificationEntryManagerLogger; |
| 62 | import com.android.systemui.statusbar.notification.NotificationFilter; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager; |
| 64 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 65 | import com.android.systemui.statusbar.notification.collection.NotificationRankingManager; |
Kevin Han | f69b71e | 2020-04-13 15:46:14 -0700 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.collection.inflation.LowPriorityInflationHelper; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl; |
| 68 | import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.icon.IconBuilder; |
| 70 | import com.android.systemui.statusbar.notification.icon.IconManager; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 71 | import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 73 | import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 74 | import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent; |
| 75 | import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent; |
| 76 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
| 77 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
| 78 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
| 79 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 80 | import com.android.systemui.statusbar.policy.SmartReplyConstants; |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 81 | import com.android.systemui.util.concurrency.FakeExecutor; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 82 | import com.android.systemui.util.leak.LeakDetector; |
| 83 | import com.android.systemui.util.time.FakeSystemClock; |
| 84 | |
| 85 | import org.junit.After; |
| 86 | import org.junit.Before; |
| 87 | import org.junit.Test; |
| 88 | import org.junit.runner.RunWith; |
| 89 | import org.mockito.ArgumentCaptor; |
| 90 | import org.mockito.Mock; |
| 91 | import org.mockito.Mockito; |
| 92 | import org.mockito.MockitoAnnotations; |
| 93 | import org.mockito.stubbing.Answer; |
| 94 | |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 95 | import java.util.concurrent.CountDownLatch; |
| 96 | |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 97 | /** |
| 98 | * Functional tests for notification inflation from {@link NotificationEntryManager}. |
| 99 | */ |
| 100 | @SmallTest |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 101 | @RunWith(AndroidTestingRunner.class) |
| 102 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
| 103 | public class NotificationEntryManagerInflationTest extends SysuiTestCase { |
| 104 | |
| 105 | private static final String TEST_TITLE = "Title"; |
| 106 | private static final String TEST_TEXT = "Text"; |
| 107 | private static final long TIMEOUT_TIME = 10000; |
| 108 | private static final Runnable TIMEOUT_RUNNABLE = () -> { |
| 109 | throw new RuntimeException("Timed out waiting to inflate"); |
| 110 | }; |
| 111 | |
| 112 | @Mock private NotificationPresenter mPresenter; |
| 113 | @Mock private NotificationEntryManager.KeyguardEnvironment mEnvironment; |
| 114 | @Mock private NotificationListContainer mListContainer; |
| 115 | @Mock private NotificationEntryListener mEntryListener; |
| 116 | @Mock private NotificationRowBinderImpl.BindRowCallback mBindCallback; |
| 117 | @Mock private HeadsUpManager mHeadsUpManager; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 118 | @Mock private NotificationInterruptStateProvider mNotificationInterruptionStateProvider; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 119 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
| 120 | @Mock private NotificationGutsManager mGutsManager; |
| 121 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
| 122 | @Mock private NotificationMediaManager mNotificationMediaManager; |
| 123 | @Mock private ExpandableNotificationRowComponent.Builder |
| 124 | mExpandableNotificationRowComponentBuilder; |
| 125 | @Mock private ExpandableNotificationRowComponent mExpandableNotificationRowComponent; |
| 126 | @Mock private FalsingManager mFalsingManager; |
| 127 | @Mock private KeyguardBypassController mKeyguardBypassController; |
| 128 | @Mock private StatusBarStateController mStatusBarStateController; |
| 129 | |
| 130 | @Mock private NotificationGroupManager mGroupManager; |
| 131 | @Mock private FeatureFlags mFeatureFlags; |
| 132 | @Mock private LeakDetector mLeakDetector; |
| 133 | |
| 134 | @Mock private ActivatableNotificationViewController mActivatableNotificationViewController; |
| 135 | @Mock private NotificationRowComponent.Builder mNotificationRowComponentBuilder; |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 136 | @Mock private PeopleNotificationIdentifier mPeopleNotificationIdentifier; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 137 | |
| 138 | private StatusBarNotification mSbn; |
| 139 | private NotificationListenerService.RankingMap mRankingMap; |
| 140 | private NotificationEntryManager mEntryManager; |
| 141 | private NotificationRowBinderImpl mRowBinder; |
| 142 | private Handler mHandler; |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 143 | private FakeExecutor mBgExecutor; |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 144 | private RowContentBindStage mRowContentBindStage; |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 145 | |
| 146 | @Before |
| 147 | public void setUp() { |
| 148 | MockitoAnnotations.initMocks(this); |
| 149 | mDependency.injectMockDependency(SmartReplyController.class); |
| 150 | |
| 151 | mHandler = Handler.createAsync(TestableLooper.get(this).getLooper()); |
| 152 | |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 153 | // Add an action so heads up content views are made |
| 154 | Notification.Action action = new Notification.Action.Builder(null, null, null).build(); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 155 | Notification notification = new Notification.Builder(mContext) |
| 156 | .setSmallIcon(R.drawable.ic_person) |
| 157 | .setContentTitle(TEST_TITLE) |
| 158 | .setContentText(TEST_TEXT) |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 159 | .setActions(action) |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 160 | .build(); |
| 161 | mSbn = new SbnBuilder() |
| 162 | .setNotification(notification) |
| 163 | .build(); |
| 164 | |
| 165 | when(mFeatureFlags.isNewNotifPipelineEnabled()).thenReturn(false); |
| 166 | when(mFeatureFlags.isNewNotifPipelineRenderingEnabled()).thenReturn(false); |
| 167 | |
| 168 | mEntryManager = new NotificationEntryManager( |
| 169 | mock(NotificationEntryManagerLogger.class), |
| 170 | mGroupManager, |
| 171 | new NotificationRankingManager( |
| 172 | () -> mock(NotificationMediaManager.class), |
| 173 | mGroupManager, |
| 174 | mHeadsUpManager, |
| 175 | mock(NotificationFilter.class), |
| 176 | mock(NotificationEntryManagerLogger.class), |
| 177 | mock(NotificationSectionsFeatureManager.class), |
| 178 | mock(PeopleNotificationIdentifier.class), |
| 179 | mock(HighPriorityProvider.class)), |
| 180 | mEnvironment, |
| 181 | mFeatureFlags, |
| 182 | () -> mRowBinder, |
| 183 | () -> mRemoteInputManager, |
| 184 | mLeakDetector, |
| 185 | mock(ForegroundServiceDismissalFeatureController.class) |
| 186 | ); |
| 187 | |
| 188 | NotifRemoteViewCache cache = new NotifRemoteViewCacheImpl(mEntryManager); |
| 189 | NotifBindPipeline pipeline = new NotifBindPipeline( |
| 190 | mEntryManager, |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 191 | mock(NotifBindPipelineLogger.class), |
| 192 | TestableLooper.get(this).getLooper()); |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 193 | mBgExecutor = new FakeExecutor(new FakeSystemClock()); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 194 | NotificationContentInflater binder = new NotificationContentInflater( |
| 195 | cache, |
| 196 | mRemoteInputManager, |
| 197 | () -> mock(SmartReplyConstants.class), |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 198 | () -> mock(SmartReplyController.class), |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 199 | mock(ConversationNotificationProcessor.class), |
| 200 | mBgExecutor); |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 201 | mRowContentBindStage = new RowContentBindStage( |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 202 | binder, |
| 203 | mock(NotifInflationErrorManager.class), |
| 204 | mock(RowContentBindStageLogger.class)); |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 205 | pipeline.setStage(mRowContentBindStage); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 206 | |
| 207 | ArgumentCaptor<ExpandableNotificationRow> viewCaptor = |
| 208 | ArgumentCaptor.forClass(ExpandableNotificationRow.class); |
| 209 | when(mExpandableNotificationRowComponentBuilder |
| 210 | .expandableNotificationRow(viewCaptor.capture())) |
| 211 | .thenReturn(mExpandableNotificationRowComponentBuilder); |
| 212 | when(mExpandableNotificationRowComponentBuilder |
| 213 | .notificationEntry(any())) |
| 214 | .thenReturn(mExpandableNotificationRowComponentBuilder); |
| 215 | when(mExpandableNotificationRowComponentBuilder |
| 216 | .onDismissRunnable(any())) |
| 217 | .thenReturn(mExpandableNotificationRowComponentBuilder); |
| 218 | when(mExpandableNotificationRowComponentBuilder |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 219 | .rowContentBindStage(any())) |
| 220 | .thenReturn(mExpandableNotificationRowComponentBuilder); |
| 221 | when(mExpandableNotificationRowComponentBuilder |
| 222 | .onExpandClickListener(any())) |
| 223 | .thenReturn(mExpandableNotificationRowComponentBuilder); |
| 224 | |
| 225 | when(mExpandableNotificationRowComponentBuilder.build()) |
| 226 | .thenReturn(mExpandableNotificationRowComponent); |
| 227 | when(mExpandableNotificationRowComponent.getExpandableNotificationRowController()) |
| 228 | .thenAnswer((Answer<ExpandableNotificationRowController>) invocation -> |
| 229 | new ExpandableNotificationRowController( |
| 230 | viewCaptor.getValue(), |
| 231 | mock(ActivatableNotificationViewController.class), |
| 232 | mNotificationMediaManager, |
| 233 | mock(PluginManager.class), |
| 234 | new FakeSystemClock(), |
| 235 | "FOOBAR", "FOOBAR", |
| 236 | mKeyguardBypassController, |
| 237 | mGroupManager, |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 238 | mRowContentBindStage, |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 239 | mock(NotificationLogger.class), |
| 240 | mHeadsUpManager, |
| 241 | mPresenter, |
| 242 | mStatusBarStateController, |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 243 | mGutsManager, |
| 244 | true, |
| 245 | null, |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 246 | mFalsingManager, |
| 247 | mPeopleNotificationIdentifier |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 248 | )); |
| 249 | |
| 250 | when(mNotificationRowComponentBuilder.activatableNotificationView(any())) |
| 251 | .thenReturn(mNotificationRowComponentBuilder); |
| 252 | when(mNotificationRowComponentBuilder.build()).thenReturn( |
| 253 | () -> mActivatableNotificationViewController); |
| 254 | |
| 255 | mRowBinder = new NotificationRowBinderImpl( |
| 256 | mContext, |
| 257 | new NotificationMessagingUtil(mContext), |
| 258 | mRemoteInputManager, |
| 259 | mLockscreenUserManager, |
| 260 | pipeline, |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 261 | mRowContentBindStage, |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 262 | mNotificationInterruptionStateProvider, |
| 263 | RowInflaterTask::new, |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 264 | mExpandableNotificationRowComponentBuilder, |
| 265 | new IconManager( |
| 266 | mEntryManager, |
| 267 | mock(LauncherApps.class), |
Kevin Han | f69b71e | 2020-04-13 15:46:14 -0700 | [diff] [blame] | 268 | new IconBuilder(mContext)), |
| 269 | mock(LowPriorityInflationHelper.class)); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 270 | |
| 271 | mEntryManager.setUpWithPresenter(mPresenter); |
| 272 | mEntryManager.addNotificationEntryListener(mEntryListener); |
| 273 | |
| 274 | mRowBinder.setUpWithPresenter(mPresenter, mListContainer, mBindCallback); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 275 | mRowBinder.setNotificationClicker(mock(NotificationClicker.class)); |
| 276 | |
| 277 | Ranking ranking = new Ranking(); |
| 278 | ranking.populate( |
| 279 | mSbn.getKey(), |
| 280 | 0, |
| 281 | false, |
| 282 | 0, |
| 283 | 0, |
| 284 | IMPORTANCE_DEFAULT, |
| 285 | null, |
| 286 | null, |
| 287 | null, |
| 288 | null, |
| 289 | null, |
| 290 | true, |
| 291 | Ranking.USER_SENTIMENT_NEUTRAL, |
| 292 | false, |
| 293 | -1, |
| 294 | false, |
| 295 | null, |
| 296 | null, |
| 297 | false, |
| 298 | false, |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 299 | false, |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 300 | null, |
| 301 | false); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 302 | mRankingMap = new NotificationListenerService.RankingMap(new Ranking[] {ranking}); |
| 303 | |
| 304 | TestableLooper.get(this).processAllMessages(); |
| 305 | } |
| 306 | |
| 307 | @After |
| 308 | public void cleanUp() { |
| 309 | // Don't leave anything on main thread |
| 310 | TestableLooper.get(this).processAllMessages(); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testAddNotification() { |
| 315 | // WHEN a notification is added |
| 316 | mEntryManager.addNotification(mSbn, mRankingMap); |
| 317 | ArgumentCaptor<NotificationEntry> entryCaptor = ArgumentCaptor.forClass( |
| 318 | NotificationEntry.class); |
| 319 | verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture()); |
| 320 | NotificationEntry entry = entryCaptor.getValue(); |
| 321 | |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 322 | waitForInflation(); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 323 | |
| 324 | // THEN the notification has its row inflated |
| 325 | assertNotNull(entry.getRow()); |
| 326 | assertNotNull(entry.getRow().getPrivateLayout().getContractedChild()); |
| 327 | |
| 328 | // THEN inflation callbacks are called |
Kevin Han | 3742322 | 2020-03-10 16:05:07 -0700 | [diff] [blame] | 329 | verify(mBindCallback).onBindRow(entry.getRow()); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 330 | verify(mEntryListener, never()).onInflationError(any(), any()); |
| 331 | verify(mEntryListener).onEntryInflated(entry); |
| 332 | verify(mEntryListener).onNotificationAdded(entry); |
| 333 | |
| 334 | // THEN the notification is active |
| 335 | assertNotNull(mEntryManager.getActiveNotificationUnfiltered(mSbn.getKey())); |
| 336 | |
| 337 | // THEN we update the presenter |
| 338 | verify(mPresenter).updateNotificationViews(); |
| 339 | } |
| 340 | |
| 341 | @Test |
| 342 | public void testUpdateNotification() { |
| 343 | // GIVEN a notification already added |
| 344 | mEntryManager.addNotification(mSbn, mRankingMap); |
| 345 | ArgumentCaptor<NotificationEntry> entryCaptor = ArgumentCaptor.forClass( |
| 346 | NotificationEntry.class); |
| 347 | verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture()); |
| 348 | NotificationEntry entry = entryCaptor.getValue(); |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 349 | waitForInflation(); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 350 | |
| 351 | Mockito.reset(mEntryListener); |
| 352 | Mockito.reset(mPresenter); |
| 353 | |
| 354 | // WHEN the notification is updated |
| 355 | mEntryManager.updateNotification(mSbn, mRankingMap); |
| 356 | |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 357 | waitForInflation(); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 358 | |
| 359 | // THEN the notification has its row and inflated |
| 360 | assertNotNull(entry.getRow()); |
| 361 | |
| 362 | // THEN inflation callbacks are called |
| 363 | verify(mEntryListener, never()).onInflationError(any(), any()); |
| 364 | verify(mEntryListener).onEntryReinflated(entry); |
| 365 | |
| 366 | // THEN we update the presenter |
| 367 | verify(mPresenter).updateNotificationViews(); |
| 368 | } |
| 369 | |
Kevin Han | 39ce15f | 2020-04-07 18:13:36 -0700 | [diff] [blame] | 370 | @Test |
| 371 | public void testContentViewInflationDuringRowInflationInflatesCorrectViews() { |
| 372 | // GIVEN a notification is added and the row is inflating |
| 373 | mEntryManager.addNotification(mSbn, mRankingMap); |
| 374 | ArgumentCaptor<NotificationEntry> entryCaptor = ArgumentCaptor.forClass( |
| 375 | NotificationEntry.class); |
| 376 | verify(mEntryListener).onPendingEntryAdded(entryCaptor.capture()); |
| 377 | NotificationEntry entry = entryCaptor.getValue(); |
| 378 | |
| 379 | // WHEN we try to bind a content view |
| 380 | mRowContentBindStage.getStageParams(entry).requireContentViews(FLAG_CONTENT_VIEW_HEADS_UP); |
| 381 | mRowContentBindStage.requestRebind(entry, null); |
| 382 | |
| 383 | waitForInflation(); |
| 384 | |
| 385 | // THEN the notification has its row and all relevant content views inflated |
| 386 | assertNotNull(entry.getRow()); |
| 387 | assertNotNull(entry.getRow().getPrivateLayout().getContractedChild()); |
| 388 | assertNotNull(entry.getRow().getPrivateLayout().getHeadsUpChild()); |
| 389 | } |
| 390 | |
Kevin Han | c571187 | 2020-03-04 22:23:02 +0000 | [diff] [blame] | 391 | /** |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 392 | * Wait for inflation to finish. |
Kevin Han | c571187 | 2020-03-04 22:23:02 +0000 | [diff] [blame] | 393 | * |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 394 | * A few things to note |
| 395 | * 1) Row inflation is done via {@link AsyncLayoutInflater} on its own background thread that |
| 396 | * calls back to main thread which is why we wait on main thread. |
| 397 | * 2) Row *content* inflation is done on the {@link FakeExecutor} we pass in in this test class |
| 398 | * so we control when that work is done. The callback is still always on the main thread. |
Kevin Han | c571187 | 2020-03-04 22:23:02 +0000 | [diff] [blame] | 399 | */ |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 400 | private void waitForInflation() { |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 401 | mHandler.postDelayed(TIMEOUT_RUNNABLE, TIMEOUT_TIME); |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 402 | final CountDownLatch latch = new CountDownLatch(1); |
| 403 | NotificationEntryListener inflationListener = new NotificationEntryListener() { |
| 404 | @Override |
| 405 | public void onEntryInflated(NotificationEntry entry) { |
| 406 | latch.countDown(); |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void onEntryReinflated(NotificationEntry entry) { |
| 411 | latch.countDown(); |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void onInflationError(StatusBarNotification notification, Exception exception) { |
| 416 | latch.countDown(); |
| 417 | } |
| 418 | }; |
| 419 | mEntryManager.addNotificationEntryListener(inflationListener); |
| 420 | while (latch.getCount() != 0) { |
| 421 | mBgExecutor.runAllReady(); |
| 422 | TestableLooper.get(this).processMessages(1); |
| 423 | } |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 424 | mHandler.removeCallbacks(TIMEOUT_RUNNABLE); |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 425 | mEntryManager.removeNotificationEntryListener(inflationListener); |
Kevin Han | 225b712 | 2020-01-31 15:42:42 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | } |