blob: ff30a4d6761df67c157dc6a0f467373f3b55baeb [file] [log] [blame]
Selim Cinek29aab962018-02-27 17:05:45 -08001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.stack;
Selim Cinek29aab962018-02-27 17:05:45 -080018
Selim Cinek29aab962018-02-27 17:05:45 -080019import static org.mockito.Mockito.atLeast;
20import static org.mockito.Mockito.mock;
Gus Prevase2d6f042018-10-17 15:25:30 -040021import static org.mockito.Mockito.never;
22import static org.mockito.Mockito.reset;
Selim Cinek29aab962018-02-27 17:05:45 -080023import static org.mockito.Mockito.verify;
Gus Prevase2d6f042018-10-17 15:25:30 -040024import static org.mockito.Mockito.when;
Selim Cinek29aab962018-02-27 17:05:45 -080025
Selim Cinek29aab962018-02-27 17:05:45 -080026import android.support.test.filters.SmallTest;
Jason Monk6dceace2018-05-15 20:24:07 -040027import android.testing.AndroidTestingRunner;
Jason Monka716bac2018-12-05 15:48:21 -050028import android.testing.TestableLooper;
Jason Monk6dceace2018-05-15 20:24:07 -040029import android.testing.TestableLooper.RunWithLooper;
Selim Cinek29aab962018-02-27 17:05:45 -080030
31import com.android.systemui.SysuiTestCase;
Lucas Dupin00be88f2019-01-03 17:50:52 -080032import com.android.systemui.statusbar.AmbientPulseManager;
Selim Cinek29aab962018-02-27 17:05:45 -080033import com.android.systemui.statusbar.NotificationTestHelper;
Lucas Dupin00be88f2019-01-03 17:50:52 -080034import com.android.systemui.statusbar.notification.collection.NotificationEntry;
35import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
Gus Prevase2d6f042018-10-17 15:25:30 -040036import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Dave Mankoffa4d195d2018-11-16 13:33:27 -050037import com.android.systemui.statusbar.notification.row.ExpandableView;
Selim Cinek29aab962018-02-27 17:05:45 -080038
39import org.junit.Assert;
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
Lucas Dupin00be88f2019-01-03 17:50:52 -080043import org.mockito.Mock;
44import org.mockito.MockitoAnnotations;
Selim Cinek29aab962018-02-27 17:05:45 -080045
46import java.util.HashSet;
47
48@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040049@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050050@RunWithLooper
Selim Cinek29aab962018-02-27 17:05:45 -080051public class NotificationRoundnessManagerTest extends SysuiTestCase {
52
Lucas Dupin00be88f2019-01-03 17:50:52 -080053 private NotificationRoundnessManager mRoundnessManager;
Dave Mankoffa4d195d2018-11-16 13:33:27 -050054 private HashSet<ExpandableView> mAnimatedChildren = new HashSet<>();
Selim Cinek29aab962018-02-27 17:05:45 -080055 private Runnable mRoundnessCallback = mock(Runnable.class);
56 private ExpandableNotificationRow mFirst;
57 private ExpandableNotificationRow mSecond;
Lucas Dupin00be88f2019-01-03 17:50:52 -080058 @Mock
59 private AmbientPulseManager mAmbientPulseManager;
Selim Cinek29aab962018-02-27 17:05:45 -080060
61 @Before
62 public void setUp() throws Exception {
Lucas Dupin00be88f2019-01-03 17:50:52 -080063 MockitoAnnotations.initMocks(this);
64 mRoundnessManager = new NotificationRoundnessManager(mAmbientPulseManager);
Jason Monka716bac2018-12-05 15:48:21 -050065 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinek29aab962018-02-27 17:05:45 -080066 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
67 mFirst = testHelper.createRow();
Selim Cinek8875de12018-03-22 10:14:32 -070068 mFirst.setHeadsUpAnimatingAwayListener(animatingAway
69 -> mRoundnessManager.onHeadsupAnimatingAwayChanged(mFirst, animatingAway));
Selim Cinek29aab962018-02-27 17:05:45 -080070 mSecond = testHelper.createRow();
Selim Cinek8875de12018-03-22 10:14:32 -070071 mSecond.setHeadsUpAnimatingAwayListener(animatingAway
72 -> mRoundnessManager.onHeadsupAnimatingAwayChanged(mSecond, animatingAway));
Selim Cinek29aab962018-02-27 17:05:45 -080073 mRoundnessManager.setOnRoundingChangedCallback(mRoundnessCallback);
74 mRoundnessManager.setAnimatedChildren(mAnimatedChildren);
Gus Prevase2d6f042018-10-17 15:25:30 -040075 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
76 createSection(mFirst, mFirst),
77 createSection(null, null)
78 });
Selim Cinekaa9db1f2018-02-27 17:35:47 -080079 mRoundnessManager.setExpanded(1.0f, 1.0f);
Gus Prevase2d6f042018-10-17 15:25:30 -040080 reset(mRoundnessCallback);
Selim Cinek29aab962018-02-27 17:05:45 -080081 }
82
83 @Test
84 public void testCallbackCalledWhenSecondChanged() {
Gus Prevase2d6f042018-10-17 15:25:30 -040085 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
86 createSection(mFirst, mSecond),
87 createSection(null, null)
88 });
Selim Cinek29aab962018-02-27 17:05:45 -080089 verify(mRoundnessCallback, atLeast(1)).run();
90 }
91
92 @Test
93 public void testCallbackCalledWhenFirstChanged() {
Gus Prevase2d6f042018-10-17 15:25:30 -040094 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
95 createSection(mSecond, mFirst),
96 createSection(null, null)
97 });
Selim Cinek29aab962018-02-27 17:05:45 -080098 verify(mRoundnessCallback, atLeast(1)).run();
99 }
100
101 @Test
Gus Prevase2d6f042018-10-17 15:25:30 -0400102 public void testCallbackCalledWhenSecondSectionFirstChanged() {
103 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
104 createSection(mFirst, mFirst),
105 createSection(mSecond, null)
106 });
107 verify(mRoundnessCallback, atLeast(1)).run();
108 }
109
110 @Test
111 public void testCallbackCalledWhenSecondSectionLastChanged() {
112 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
113 createSection(mFirst, mFirst),
114 createSection(null, mSecond)
115 });
116 verify(mRoundnessCallback, atLeast(1)).run();
117 }
118
119 @Test
120 public void testCallbackNotCalledWhenFirstChangesSections() {
121 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
122 createSection(null, mFirst),
123 createSection(mFirst, null)
124 });
125 verify(mRoundnessCallback, never()).run();
126 }
127
128 @Test
Selim Cinek29aab962018-02-27 17:05:45 -0800129 public void testRoundnessSetOnLast() {
Gus Prevase2d6f042018-10-17 15:25:30 -0400130 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
131 createSection(mFirst, mSecond),
132 createSection(null, null)
133 });
Selim Cinek29aab962018-02-27 17:05:45 -0800134 Assert.assertEquals(1.0f, mSecond.getCurrentBottomRoundness(), 0.0f);
135 Assert.assertEquals(0.0f, mSecond.getCurrentTopRoundness(), 0.0f);
136 }
137
138 @Test
Lucas Dupin00be88f2019-01-03 17:50:52 -0800139 public void testRoundnessPulsing() throws Exception {
140 // Let's create a notification that's neither the first or last item of the stack,
141 // this way we'll ensure that it won't have any rounded corners by default.
142 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
143 createSection(mFirst, mSecond),
144 createSection(null, null)
145 });
146 ExpandableNotificationRow row = new NotificationTestHelper(getContext()).createRow();
147 NotificationEntry entry = mock(NotificationEntry.class);
148 when(entry.getRow()).thenReturn(row);
149
150 mRoundnessManager.onAmbientStateChanged(entry, true);
151 Assert.assertEquals(1f, row.getCurrentBottomRoundness(), 0.0f);
152 Assert.assertEquals(1f, row.getCurrentTopRoundness(), 0.0f);
153
154 mRoundnessManager.onAmbientStateChanged(entry, false);
155 Assert.assertEquals(0f, row.getCurrentBottomRoundness(), 0.0f);
156 Assert.assertEquals(0f, row.getCurrentTopRoundness(), 0.0f);
157 }
158
159 @Test
Gus Prevase2d6f042018-10-17 15:25:30 -0400160 public void testRoundnessSetOnSecondSectionLast() {
161 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
162 createSection(mFirst, mFirst),
163 createSection(null, mSecond)
164 });
165 Assert.assertEquals(1.0f, mSecond.getCurrentBottomRoundness(), 0.0f);
166 Assert.assertEquals(0.0f, mSecond.getCurrentTopRoundness(), 0.0f);
167 }
168
169 @Test
170 public void testRoundnessSetOnSecondSectionFirst() {
171 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
172 createSection(mFirst, mFirst),
173 createSection(mSecond, null)
174 });
175 Assert.assertEquals(0.0f, mSecond.getCurrentBottomRoundness(), 0.0f);
176 Assert.assertEquals(1.0f, mSecond.getCurrentTopRoundness(), 0.0f);
177 }
178
179 @Test
Selim Cinek29aab962018-02-27 17:05:45 -0800180 public void testRoundnessSetOnNew() {
Gus Prevase2d6f042018-10-17 15:25:30 -0400181 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
182 createSection(mFirst, null),
183 createSection(null, null)
184 });
Selim Cinek29aab962018-02-27 17:05:45 -0800185 Assert.assertEquals(0.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
186 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
187 }
188
189 @Test
190 public void testCompleteReplacement() {
Gus Prevase2d6f042018-10-17 15:25:30 -0400191 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
192 createSection(mSecond, mSecond),
193 createSection(null, null)
194 });
Selim Cinek29aab962018-02-27 17:05:45 -0800195 Assert.assertEquals(0.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
196 Assert.assertEquals(0.0f, mFirst.getCurrentTopRoundness(), 0.0f);
197 }
198
199 @Test
200 public void testNotCalledWhenRemoved() {
201 mFirst.setRemoved();
Gus Prevase2d6f042018-10-17 15:25:30 -0400202 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
203 createSection(mSecond, mSecond),
204 createSection(null, null)
205 });
Selim Cinek29aab962018-02-27 17:05:45 -0800206 Assert.assertEquals(1.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
207 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
208 }
209
210 @Test
211 public void testRoundedWhenPinnedAndCollapsed() {
212 mFirst.setPinned(true);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800213 mRoundnessManager.setExpanded(0.0f /* expandedHeight */, 0.0f /* appearFraction */);
Gus Prevase2d6f042018-10-17 15:25:30 -0400214 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
215 createSection(mSecond, mSecond),
216 createSection(null, null)
217 });
Selim Cinek29aab962018-02-27 17:05:45 -0800218 Assert.assertEquals(1.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
219 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
220 }
221
222 @Test
223 public void testRoundedWhenGoingAwayAndCollapsed() {
224 mFirst.setHeadsUpAnimatingAway(true);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800225 mRoundnessManager.setExpanded(0.0f /* expandedHeight */, 0.0f /* appearFraction */);
Gus Prevase2d6f042018-10-17 15:25:30 -0400226 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
227 createSection(mSecond, mSecond),
228 createSection(null, null)
229 });
Selim Cinek29aab962018-02-27 17:05:45 -0800230 Assert.assertEquals(1.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
231 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
232 }
233
234 @Test
235 public void testRoundedNormalRoundingWhenExpanded() {
236 mFirst.setHeadsUpAnimatingAway(true);
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800237 mRoundnessManager.setExpanded(1.0f /* expandedHeight */, 0.0f /* appearFraction */);
Gus Prevase2d6f042018-10-17 15:25:30 -0400238 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
239 createSection(mSecond, mSecond),
240 createSection(null, null)
241 });
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800242 Assert.assertEquals(0.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
243 Assert.assertEquals(0.0f, mFirst.getCurrentTopRoundness(), 0.0f);
244 }
245
246 @Test
247 public void testTrackingHeadsUpRoundedIfPushingUp() {
248 mRoundnessManager.setExpanded(1.0f /* expandedHeight */, -0.5f /* appearFraction */);
249 mRoundnessManager.setTrackingHeadsUp(mFirst);
Gus Prevase2d6f042018-10-17 15:25:30 -0400250 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
251 createSection(mSecond, mSecond),
252 createSection(null, null)
253 });
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800254 Assert.assertEquals(1.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
255 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
256 }
257
258 @Test
259 public void testTrackingHeadsUpNotRoundedIfPushingDown() {
260 mRoundnessManager.setExpanded(1.0f /* expandedHeight */, 0.5f /* appearFraction */);
261 mRoundnessManager.setTrackingHeadsUp(mFirst);
Gus Prevase2d6f042018-10-17 15:25:30 -0400262 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
263 createSection(mSecond, mSecond),
264 createSection(null, null)
265 });
Selim Cinek29aab962018-02-27 17:05:45 -0800266 Assert.assertEquals(0.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
267 Assert.assertEquals(0.0f, mFirst.getCurrentTopRoundness(), 0.0f);
268 }
Selim Cinek8875de12018-03-22 10:14:32 -0700269
270 @Test
271 public void testRoundingUpdatedWhenAnimatingAwayTrue() {
272 mRoundnessManager.setExpanded(0.0f, 0.0f);
Gus Prevase2d6f042018-10-17 15:25:30 -0400273 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
274 createSection(mSecond, mSecond),
275 createSection(null, null)
276 });
Selim Cinek8875de12018-03-22 10:14:32 -0700277 mFirst.setHeadsUpAnimatingAway(true);
278 Assert.assertEquals(1.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
279 Assert.assertEquals(1.0f, mFirst.getCurrentTopRoundness(), 0.0f);
280 }
281
282
283 @Test
284 public void testRoundingUpdatedWhenAnimatingAwayFalse() {
285 mRoundnessManager.setExpanded(0.0f, 0.0f);
Gus Prevase2d6f042018-10-17 15:25:30 -0400286 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
287 createSection(mSecond, mSecond),
288 createSection(null, null)
289 });
Selim Cinek8875de12018-03-22 10:14:32 -0700290 mFirst.setHeadsUpAnimatingAway(true);
291 mFirst.setHeadsUpAnimatingAway(false);
292 Assert.assertEquals(0.0f, mFirst.getCurrentBottomRoundness(), 0.0f);
293 Assert.assertEquals(0.0f, mFirst.getCurrentTopRoundness(), 0.0f);
294 }
Gus Prevase2d6f042018-10-17 15:25:30 -0400295
296 @Test
297 public void testNoViewsFirstOrLastInSectionWhenSecondSectionEmpty() {
298 Assert.assertFalse(mFirst.isFirstInSection());
299 Assert.assertFalse(mFirst.isLastInSection());
300 }
301
302 @Test
303 public void testNoViewsFirstOrLastInSectionWhenFirstSectionEmpty() {
304 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
305 createSection(null, null),
306 createSection(mSecond, mSecond)
307 });
308 Assert.assertFalse(mSecond.isFirstInSection());
309 Assert.assertFalse(mSecond.isLastInSection());
310 }
311
312 @Test
313 public void testFirstAndLastViewsInSectionSetWhenBothSectionsNonEmpty() {
314 mRoundnessManager.updateRoundedChildren(new NotificationSection[]{
315 createSection(mFirst, mFirst),
316 createSection(mSecond, mSecond)
317 });
318 Assert.assertFalse(mFirst.isFirstInSection());
319 Assert.assertTrue(mFirst.isLastInSection());
320 Assert.assertTrue(mSecond.isFirstInSection());
321 Assert.assertFalse(mSecond.isLastInSection());
322 }
323
324 private NotificationSection createSection(ExpandableNotificationRow first,
325 ExpandableNotificationRow last) {
326 NotificationSection section = mock(NotificationSection.class);
327 when(section.getFirstVisibleChild()).thenReturn(first);
328 when(section.getLastVisibleChild()).thenReturn(last);
329 return section;
330 }
Selim Cinek29aab962018-02-27 17:05:45 -0800331}