Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.stack; |
| 18 | |
| 19 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 20 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 22 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP; |
| 23 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 24 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT; |
| 25 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 26 | import static org.mockito.ArgumentMatchers.any; |
| 27 | import static org.mockito.ArgumentMatchers.anyInt; |
| 28 | import static org.mockito.ArgumentMatchers.eq; |
| 29 | import static org.mockito.Mockito.RETURNS_DEEP_STUBS; |
| 30 | import static org.mockito.Mockito.clearInvocations; |
| 31 | import static org.mockito.Mockito.mock; |
| 32 | import static org.mockito.Mockito.never; |
| 33 | import static org.mockito.Mockito.verify; |
| 34 | import static org.mockito.Mockito.when; |
| 35 | |
| 36 | import android.testing.AndroidTestingRunner; |
| 37 | import android.testing.TestableLooper; |
| 38 | import android.util.AttributeSet; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 39 | import android.view.LayoutInflater; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 40 | import android.view.View; |
| 41 | import android.view.ViewGroup; |
| 42 | |
| 43 | import androidx.test.filters.SmallTest; |
| 44 | |
| 45 | import com.android.systemui.ActivityStarterDelegate; |
| 46 | import com.android.systemui.SysuiTestCase; |
Selim Cinek | b52642b | 2020-04-17 14:30:29 -0700 | [diff] [blame] | 47 | import com.android.systemui.media.KeyguardMediaController; |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 48 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 49 | import com.android.systemui.statusbar.StatusBarState; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 51 | import com.android.systemui.statusbar.notification.people.PeopleHubViewAdapter; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 52 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationViewController; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 53 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 54 | import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 56 | |
| 57 | import org.junit.Before; |
| 58 | import org.junit.Rule; |
| 59 | import org.junit.Test; |
| 60 | import org.junit.runner.RunWith; |
| 61 | import org.mockito.Mock; |
| 62 | import org.mockito.junit.MockitoJUnit; |
| 63 | import org.mockito.junit.MockitoRule; |
| 64 | |
| 65 | @SmallTest |
| 66 | @RunWith(AndroidTestingRunner.class) |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 67 | @TestableLooper.RunWithLooper(setAsMainLooper = true) |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 68 | public class NotificationSectionsManagerTest extends SysuiTestCase { |
| 69 | |
| 70 | @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); |
| 71 | |
| 72 | @Mock private NotificationStackScrollLayout mNssl; |
| 73 | @Mock private ActivityStarterDelegate mActivityStarterDelegate; |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 74 | @Mock private StatusBarStateController mStatusBarStateController; |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 75 | @Mock private ConfigurationController mConfigurationController; |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 76 | @Mock private PeopleHubViewAdapter mPeopleHubAdapter; |
Selim Cinek | b52642b | 2020-04-17 14:30:29 -0700 | [diff] [blame] | 77 | @Mock private KeyguardMediaController mKeyguardMediaController; |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 78 | @Mock private NotificationSectionsFeatureManager mSectionsFeatureManager; |
| 79 | @Mock private NotificationRowComponent mNotificationRowComponent; |
| 80 | @Mock private ActivatableNotificationViewController mActivatableNotificationViewController; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 81 | |
| 82 | private NotificationSectionsManager mSectionsManager; |
| 83 | |
| 84 | @Before |
| 85 | public void setUp() { |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 86 | when(mSectionsFeatureManager.getNumberOfBuckets()).thenReturn(2); |
| 87 | when(mNotificationRowComponent.getActivatableNotificationViewController()).thenReturn( |
| 88 | mActivatableNotificationViewController |
| 89 | ); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 90 | mSectionsManager = |
| 91 | new NotificationSectionsManager( |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 92 | mActivityStarterDelegate, |
| 93 | mStatusBarStateController, |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 94 | mConfigurationController, |
Steve Elliott | 58adc21 | 2019-10-15 11:07:54 -0400 | [diff] [blame] | 95 | mPeopleHubAdapter, |
Selim Cinek | b52642b | 2020-04-17 14:30:29 -0700 | [diff] [blame] | 96 | mKeyguardMediaController, |
Steve Elliott | b094038 | 2020-02-20 14:24:02 -0500 | [diff] [blame] | 97 | mSectionsFeatureManager |
| 98 | ); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 99 | // Required in order for the header inflation to work properly |
| 100 | when(mNssl.generateLayoutParams(any(AttributeSet.class))) |
| 101 | .thenReturn(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 102 | mSectionsManager.initialize(mNssl, LayoutInflater.from(mContext)); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 103 | when(mNssl.indexOfChild(any(View.class))).thenReturn(-1); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 104 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 107 | @Test(expected = IllegalStateException.class) |
| 108 | public void testDuplicateInitializeThrows() { |
Dave Mankoff | 56fe9e4 | 2020-01-08 15:42:06 -0500 | [diff] [blame] | 109 | mSectionsManager.initialize(mNssl, LayoutInflater.from(mContext)); |
Ned Burns | 2c74c2a | 2019-06-13 19:06:47 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 112 | @Test |
| 113 | public void testInsertHeader() { |
| 114 | // GIVEN a stack with HI and LO rows but no section headers |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 115 | setStackState(ChildType.ALERTING, ChildType.ALERTING, ChildType.ALERTING, ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 116 | |
| 117 | // WHEN we update the section headers |
| 118 | mSectionsManager.updateSectionBoundaries(); |
| 119 | |
| 120 | // THEN a LO section header is added |
| 121 | verify(mNssl).addView(mSectionsManager.getGentleHeaderView(), 3); |
| 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void testRemoveHeader() { |
| 126 | // GIVEN a stack that originally had a header between the HI and LO sections |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 127 | setStackState(ChildType.ALERTING, ChildType.ALERTING, ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 128 | mSectionsManager.updateSectionBoundaries(); |
| 129 | |
| 130 | // WHEN the last LO row is replaced with a HI row |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 131 | setStackState( |
| 132 | ChildType.ALERTING, |
| 133 | ChildType.ALERTING, |
| 134 | ChildType.GENTLE_HEADER, |
| 135 | ChildType.ALERTING); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 136 | clearInvocations(mNssl); |
| 137 | mSectionsManager.updateSectionBoundaries(); |
| 138 | |
| 139 | // THEN the LO section header is removed |
| 140 | verify(mNssl).removeView(mSectionsManager.getGentleHeaderView()); |
| 141 | } |
| 142 | |
| 143 | @Test |
| 144 | public void testDoNothingIfHeaderAlreadyRemoved() { |
| 145 | // GIVEN a stack with only HI rows |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 146 | setStackState(ChildType.ALERTING, ChildType.ALERTING, ChildType.ALERTING); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 147 | |
| 148 | // WHEN we update the sections headers |
| 149 | mSectionsManager.updateSectionBoundaries(); |
| 150 | |
| 151 | // THEN we don't add any section headers |
| 152 | verify(mNssl, never()).addView(eq(mSectionsManager.getGentleHeaderView()), anyInt()); |
| 153 | } |
| 154 | |
| 155 | @Test |
| 156 | public void testMoveHeaderForward() { |
| 157 | // GIVEN a stack that originally had a header between the HI and LO sections |
| 158 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 159 | ChildType.ALERTING, |
| 160 | ChildType.ALERTING, |
| 161 | ChildType.ALERTING, |
| 162 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 163 | mSectionsManager.updateSectionBoundaries(); |
| 164 | |
| 165 | // WHEN the LO section moves forward |
| 166 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 167 | ChildType.ALERTING, |
| 168 | ChildType.ALERTING, |
| 169 | ChildType.GENTLE, |
| 170 | ChildType.GENTLE_HEADER, |
| 171 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 172 | mSectionsManager.updateSectionBoundaries(); |
| 173 | |
| 174 | // THEN the LO section header is also moved forward |
| 175 | verify(mNssl).changeViewPosition(mSectionsManager.getGentleHeaderView(), 2); |
| 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void testMoveHeaderBackward() { |
| 180 | // GIVEN a stack that originally had a header between the HI and LO sections |
| 181 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 182 | ChildType.ALERTING, |
| 183 | ChildType.GENTLE, |
| 184 | ChildType.GENTLE, |
| 185 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 186 | mSectionsManager.updateSectionBoundaries(); |
| 187 | |
| 188 | // WHEN the LO section moves backward |
| 189 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 190 | ChildType.ALERTING, |
| 191 | ChildType.GENTLE_HEADER, |
| 192 | ChildType.ALERTING, |
| 193 | ChildType.ALERTING, |
| 194 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 195 | mSectionsManager.updateSectionBoundaries(); |
| 196 | |
| 197 | // THEN the LO section header is also moved backward (with appropriate index shifting) |
| 198 | verify(mNssl).changeViewPosition(mSectionsManager.getGentleHeaderView(), 3); |
| 199 | } |
| 200 | |
| 201 | @Test |
| 202 | public void testHeaderRemovedFromTransientParent() { |
| 203 | // GIVEN a stack where the header is animating away |
| 204 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 205 | ChildType.ALERTING, |
| 206 | ChildType.GENTLE, |
| 207 | ChildType.GENTLE, |
| 208 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 209 | mSectionsManager.updateSectionBoundaries(); |
| 210 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 211 | ChildType.ALERTING, |
| 212 | ChildType.GENTLE_HEADER); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 213 | mSectionsManager.updateSectionBoundaries(); |
| 214 | clearInvocations(mNssl); |
| 215 | |
| 216 | ViewGroup transientParent = mock(ViewGroup.class); |
| 217 | mSectionsManager.getGentleHeaderView().setTransientContainer(transientParent); |
| 218 | |
| 219 | // WHEN the LO section reappears |
| 220 | setStackState( |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 221 | ChildType.ALERTING, |
| 222 | ChildType.GENTLE); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 223 | mSectionsManager.updateSectionBoundaries(); |
| 224 | |
| 225 | // THEN the header is first removed from the transient parent before being added to the |
| 226 | // NSSL. |
| 227 | verify(transientParent).removeTransientView(mSectionsManager.getGentleHeaderView()); |
| 228 | verify(mNssl).addView(mSectionsManager.getGentleHeaderView(), 1); |
| 229 | } |
| 230 | |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 231 | @Test |
| 232 | public void testHeaderNotShownOnLockscreen() { |
| 233 | // GIVEN a stack of HI and LO notifs on the lockscreen |
| 234 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 235 | setStackState(ChildType.ALERTING, ChildType.ALERTING, ChildType.ALERTING, ChildType.GENTLE); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 236 | |
| 237 | // WHEN we update the section headers |
| 238 | mSectionsManager.updateSectionBoundaries(); |
| 239 | |
| 240 | // Then the section header is not added |
| 241 | verify(mNssl, never()).addView(eq(mSectionsManager.getGentleHeaderView()), anyInt()); |
| 242 | } |
| 243 | |
| 244 | @Test |
| 245 | public void testHeaderShownWhenEnterLockscreen() { |
| 246 | // GIVEN a stack of HI and LO notifs on the lockscreen |
| 247 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 248 | setStackState(ChildType.ALERTING, ChildType.ALERTING, ChildType.ALERTING, ChildType.GENTLE); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 249 | mSectionsManager.updateSectionBoundaries(); |
| 250 | |
| 251 | // WHEN we unlock |
| 252 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE); |
| 253 | mSectionsManager.updateSectionBoundaries(); |
| 254 | |
| 255 | // Then the section header is added |
| 256 | verify(mNssl).addView(mSectionsManager.getGentleHeaderView(), 3); |
| 257 | } |
| 258 | |
| 259 | @Test |
| 260 | public void testHeaderHiddenWhenEnterLockscreen() { |
| 261 | // GIVEN a stack of HI and LO notifs on the shade |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 262 | setStackState(ChildType.ALERTING, ChildType.GENTLE_HEADER, ChildType.GENTLE); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 263 | |
| 264 | // WHEN we go back to the keyguard |
| 265 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
| 266 | mSectionsManager.updateSectionBoundaries(); |
| 267 | |
| 268 | // Then the section header is removed |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 269 | verify(mNssl).removeView(mSectionsManager.getGentleHeaderView()); |
Ned Burns | 7eeccdd | 2019-05-15 14:50:11 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 272 | @Test |
| 273 | public void testPeopleFiltering_addHeadersFromShowingOnlyGentle() { |
| 274 | enablePeopleFiltering(); |
| 275 | |
| 276 | setStackState( |
| 277 | ChildType.GENTLE_HEADER, |
| 278 | ChildType.PERSON, |
| 279 | ChildType.ALERTING, |
| 280 | ChildType.GENTLE); |
| 281 | mSectionsManager.updateSectionBoundaries(); |
| 282 | |
| 283 | verify(mNssl).changeViewPosition(mSectionsManager.getGentleHeaderView(), 2); |
| 284 | verify(mNssl).addView(mSectionsManager.getAlertingHeaderView(), 1); |
| 285 | verify(mNssl).addView(mSectionsManager.getPeopleHeaderView(), 0); |
| 286 | } |
| 287 | |
| 288 | @Test |
| 289 | public void testPeopleFiltering_addAllHeaders() { |
| 290 | enablePeopleFiltering(); |
| 291 | |
| 292 | setStackState( |
| 293 | ChildType.PERSON, |
| 294 | ChildType.ALERTING, |
| 295 | ChildType.GENTLE); |
| 296 | mSectionsManager.updateSectionBoundaries(); |
| 297 | |
| 298 | verify(mNssl).addView(mSectionsManager.getGentleHeaderView(), 2); |
| 299 | verify(mNssl).addView(mSectionsManager.getAlertingHeaderView(), 1); |
| 300 | verify(mNssl).addView(mSectionsManager.getPeopleHeaderView(), 0); |
| 301 | } |
| 302 | |
| 303 | @Test |
| 304 | public void testPeopleFiltering_moveAllHeaders() { |
| 305 | enablePeopleFiltering(); |
| 306 | |
| 307 | setStackState( |
| 308 | ChildType.PEOPLE_HEADER, |
| 309 | ChildType.ALERTING_HEADER, |
| 310 | ChildType.GENTLE_HEADER, |
| 311 | ChildType.PERSON, |
| 312 | ChildType.ALERTING, |
| 313 | ChildType.GENTLE); |
| 314 | mSectionsManager.updateSectionBoundaries(); |
| 315 | |
| 316 | verify(mNssl).changeViewPosition(mSectionsManager.getGentleHeaderView(), 4); |
| 317 | verify(mNssl).changeViewPosition(mSectionsManager.getAlertingHeaderView(), 2); |
| 318 | verify(mNssl).changeViewPosition(mSectionsManager.getPeopleHeaderView(), 0); |
| 319 | } |
| 320 | |
Steve Elliott | 6de51a7 | 2020-03-05 11:00:47 -0500 | [diff] [blame] | 321 | @Test |
| 322 | public void testPeopleFiltering_keepPeopleHeaderWhenSectionEmpty() { |
| 323 | mSectionsManager.setPeopleHubVisible(true); |
| 324 | enablePeopleFiltering(); |
| 325 | |
| 326 | setStackState( |
| 327 | ChildType.PEOPLE_HEADER, |
| 328 | ChildType.ALERTING_HEADER, |
| 329 | ChildType.ALERTING, |
| 330 | ChildType.GENTLE_HEADER, |
| 331 | ChildType.GENTLE |
| 332 | ); |
| 333 | mSectionsManager.updateSectionBoundaries(); |
| 334 | |
| 335 | verify(mNssl, never()).removeView(mSectionsManager.getPeopleHeaderView()); |
| 336 | verify(mNssl).changeViewPosition(mSectionsManager.getPeopleHeaderView(), 0); |
| 337 | } |
| 338 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 339 | @Test |
| 340 | public void testMediaControls_AddWhenEnterKeyguard() { |
| 341 | enableMediaControls(); |
| 342 | |
| 343 | // GIVEN a stack that doesn't include media controls |
| 344 | setStackState(ChildType.ALERTING, ChildType.GENTLE_HEADER, ChildType.GENTLE); |
| 345 | |
| 346 | // WHEN we go back to the keyguard |
| 347 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
| 348 | mSectionsManager.updateSectionBoundaries(); |
| 349 | |
| 350 | // Then the media controls are added |
| 351 | verify(mNssl).addView(mSectionsManager.getMediaControlsView(), 0); |
| 352 | } |
| 353 | |
| 354 | @Test |
| 355 | public void testMediaControls_AddWhenEnterKeyguardWithHeadsUp() { |
| 356 | enableMediaControls(); |
| 357 | |
| 358 | // GIVEN a stack that doesn't include media controls but includes HEADS_UP |
| 359 | setStackState(ChildType.HEADS_UP, ChildType.ALERTING, ChildType.GENTLE_HEADER, |
| 360 | ChildType.GENTLE); |
| 361 | |
| 362 | // WHEN we go back to the keyguard |
| 363 | when(mStatusBarStateController.getState()).thenReturn(StatusBarState.KEYGUARD); |
| 364 | mSectionsManager.updateSectionBoundaries(); |
| 365 | |
| 366 | // Then the media controls are added after HEADS_UP |
| 367 | verify(mNssl).addView(mSectionsManager.getMediaControlsView(), 1); |
| 368 | } |
| 369 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 370 | private void enablePeopleFiltering() { |
| 371 | when(mSectionsFeatureManager.isFilteringEnabled()).thenReturn(true); |
| 372 | when(mSectionsFeatureManager.getNumberOfBuckets()).thenReturn(4); |
| 373 | } |
| 374 | |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 375 | private void enableMediaControls() { |
| 376 | when(mSectionsFeatureManager.isMediaControlsEnabled()).thenReturn(true); |
| 377 | when(mSectionsFeatureManager.getNumberOfBuckets()).thenReturn(4); |
| 378 | } |
| 379 | |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 380 | private enum ChildType { |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 381 | MEDIA_CONTROLS, PEOPLE_HEADER, ALERTING_HEADER, GENTLE_HEADER, HEADS_UP, PERSON, ALERTING, |
| 382 | GENTLE, OTHER |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 383 | } |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 384 | |
| 385 | private void setStackState(ChildType... children) { |
| 386 | when(mNssl.getChildCount()).thenReturn(children.length); |
| 387 | for (int i = 0; i < children.length; i++) { |
| 388 | View child; |
| 389 | switch (children[i]) { |
Robert Snoeberger | b6464ea | 2020-03-20 11:56:22 -0400 | [diff] [blame] | 390 | case MEDIA_CONTROLS: |
| 391 | child = mSectionsManager.getMediaControlsView(); |
| 392 | break; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 393 | case PEOPLE_HEADER: |
| 394 | child = mSectionsManager.getPeopleHeaderView(); |
| 395 | break; |
| 396 | case ALERTING_HEADER: |
| 397 | child = mSectionsManager.getAlertingHeaderView(); |
| 398 | break; |
| 399 | case GENTLE_HEADER: |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 400 | child = mSectionsManager.getGentleHeaderView(); |
| 401 | break; |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 402 | case HEADS_UP: |
| 403 | child = mockNotification(BUCKET_HEADS_UP); |
| 404 | break; |
| 405 | case PERSON: |
| 406 | child = mockNotification(BUCKET_PEOPLE); |
| 407 | break; |
| 408 | case ALERTING: |
| 409 | child = mockNotification(BUCKET_ALERTING); |
| 410 | break; |
| 411 | case GENTLE: |
| 412 | child = mockNotification(BUCKET_SILENT); |
| 413 | break; |
| 414 | case OTHER: |
| 415 | child = mock(View.class); |
| 416 | when(child.getVisibility()).thenReturn(View.VISIBLE); |
| 417 | when(child.getParent()).thenReturn(mNssl); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 418 | break; |
| 419 | default: |
| 420 | throw new RuntimeException("Unknown ChildType: " + children[i]); |
| 421 | } |
| 422 | when(mNssl.getChildAt(i)).thenReturn(child); |
| 423 | when(mNssl.indexOfChild(child)).thenReturn(i); |
| 424 | } |
| 425 | } |
Steve Elliott | 35956b4 | 2020-02-25 17:12:09 -0500 | [diff] [blame] | 426 | |
| 427 | private View mockNotification(int bucket) { |
| 428 | ExpandableNotificationRow notifRow = mock(ExpandableNotificationRow.class, |
| 429 | RETURNS_DEEP_STUBS); |
| 430 | when(notifRow.getVisibility()).thenReturn(View.VISIBLE); |
| 431 | when(notifRow.getEntry().getBucket()).thenReturn(bucket); |
| 432 | when(notifRow.getParent()).thenReturn(mNssl); |
| 433 | return notifRow; |
| 434 | } |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 435 | } |