blob: 36ec2210942d0b49754f21c58737d4bf4dee030e [file] [log] [blame]
Julia Reynolds8a3b4592017-06-26 17:15:14 -04001/*
2 * Copyright (C) 2017 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
17package com.android.server.notification;
18
19import static junit.framework.Assert.assertEquals;
20import static junit.framework.Assert.assertNotNull;
21import static junit.framework.Assert.assertNull;
22
Julia Reynolds7217dc92018-03-07 12:12:09 -050023import static org.junit.Assert.assertFalse;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040024import static org.junit.Assert.assertTrue;
Julia Reynolds7217dc92018-03-07 12:12:09 -050025import static org.mockito.Mockito.mock;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040026import static org.mockito.Mockito.spy;
27import static org.mockito.Mockito.when;
Kristian Monsen30f59b22018-04-09 10:27:16 +020028import static org.mockito.Matchers.any;
29import static org.mockito.Matchers.anyInt;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040030
31import android.app.ActivityManager;
32import android.app.Notification;
Selim Cinek9acd6732018-03-23 16:39:02 -070033import android.app.Person;
Julia Reynolds7217dc92018-03-07 12:12:09 -050034import android.app.PendingIntent;
35import android.app.RemoteInput;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040036import android.content.Context;
37import android.content.pm.ApplicationInfo;
Kristian Monsen30f59b22018-04-09 10:27:16 +020038import android.content.pm.PackageManager;
39import android.content.res.Resources;
Julia Reynolds7217dc92018-03-07 12:12:09 -050040import android.graphics.Bitmap;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040041import android.graphics.Color;
Julia Reynolds7217dc92018-03-07 12:12:09 -050042import android.graphics.drawable.Icon;
43import android.net.Uri;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040044import android.os.Build;
45import android.support.test.filters.SmallTest;
46import android.support.test.runner.AndroidJUnit4;
Julia Reynolds7217dc92018-03-07 12:12:09 -050047import android.widget.RemoteViews;
Julia Reynolds8a3b4592017-06-26 17:15:14 -040048
Jason Monk74f5e362017-12-06 08:56:33 -050049import com.android.server.UiServiceTestCase;
50
Julia Reynolds8a3b4592017-06-26 17:15:14 -040051import org.junit.Before;
52import org.junit.Test;
53import org.junit.runner.RunWith;
54import org.mockito.Mock;
55import org.mockito.MockitoAnnotations;
56
57@RunWith(AndroidJUnit4.class)
58@SmallTest
Jason Monk74f5e362017-12-06 08:56:33 -050059public class NotificationTest extends UiServiceTestCase {
Julia Reynolds8a3b4592017-06-26 17:15:14 -040060
61 @Mock
62 ActivityManager mAm;
63
Kristian Monsen30f59b22018-04-09 10:27:16 +020064 @Mock
65 Resources mResources;
66
Julia Reynolds8a3b4592017-06-26 17:15:14 -040067 @Before
68 public void setUp() {
69 MockitoAnnotations.initMocks(this);
70 }
71
72 @Test
Kristian Monsen30f59b22018-04-09 10:27:16 +020073 public void testStripsExtendersInLowRamModeNoWhitelistNoTv() {
Julia Reynolds8a3b4592017-06-26 17:15:14 -040074 Notification.Builder nb = new Notification.Builder(mContext, "channel");
75 nb.extend(new Notification.CarExtender().setColor(Color.RED));
76 nb.extend(new Notification.TvExtender().setChannelId("different channel"));
77 nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
78 Notification before = nb.build();
79
Kristian Monsen30f59b22018-04-09 10:27:16 +020080 // No whitelist
81 Context context = spy(getContext());
82 when(context.getResources()).thenReturn(mResources);
83 when(mResources.getStringArray(anyInt())).thenReturn(new String[0]);
84
85 Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
86 context);
Julia Reynolds8a3b4592017-06-26 17:15:14 -040087
88 assertEquals("different channel", new Notification.TvExtender(before).getChannelId());
89 assertNull(new Notification.TvExtender(after).getChannelId());
90
91 assertEquals(Color.RED, new Notification.CarExtender(before).getColor());
92 assertEquals(Notification.COLOR_DEFAULT, new Notification.CarExtender(after).getColor());
93
94 assertEquals("dismiss", new Notification.WearableExtender(before).getDismissalId());
95 assertNull(new Notification.WearableExtender(after).getDismissalId());
96 }
97
98 @Test
Kristian Monsen30f59b22018-04-09 10:27:16 +020099 public void testStripsExtendersInLowRamModeHasWhitelist() {
100 Notification.Builder nb = new Notification.Builder(mContext, "channel");
101 nb.extend(new Notification.CarExtender().setColor(Color.RED));
102 nb.extend(new Notification.TvExtender().setChannelId("different channel"));
103 nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
104 Notification before = nb.build();
105
106 // Has whitelist
107 Context context = spy(mContext);
108 when(context.getResources()).thenReturn(mResources);
109 when(mResources.getStringArray(anyInt())).thenReturn(new String[1]);
110
111 Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
112 context);
113
114 assertEquals("different channel", new Notification.TvExtender(before).getChannelId());
115 assertEquals("different channel", new Notification.TvExtender(after).getChannelId());
116
117 assertEquals(Color.RED, new Notification.CarExtender(before).getColor());
118 assertEquals(Color.RED, new Notification.CarExtender(after).getColor());
119
120 assertEquals("dismiss", new Notification.WearableExtender(before).getDismissalId());
121 assertEquals("dismiss", new Notification.WearableExtender(after).getDismissalId());
122 }
123
124 @Test
Julia Reynolds8a3b4592017-06-26 17:15:14 -0400125 public void testStripsRemoteViewsInLowRamMode() {
Kristian Monsen30f59b22018-04-09 10:27:16 +0200126 Context context = spy(mContext);
Julia Reynolds8a3b4592017-06-26 17:15:14 -0400127 ApplicationInfo ai = new ApplicationInfo();
128 ai.targetSdkVersion = Build.VERSION_CODES.M;
129 when(context.getApplicationInfo()).thenReturn(ai);
130
131 final Notification.BigTextStyle style = new Notification.BigTextStyle()
132 .bigText("hello")
133 .setSummaryText("And the summary");
134 Notification before = new Notification.Builder(context, "channel")
135 .setContentText("hi")
136 .setStyle(style)
137 .build();
138
Kristian Monsen30f59b22018-04-09 10:27:16 +0200139 Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
140 mContext);
Julia Reynolds8a3b4592017-06-26 17:15:14 -0400141 assertNotNull(before.contentView);
142 assertNotNull(before.bigContentView);
143 assertNotNull(before.headsUpContentView);
144 assertNull(after.contentView);
145 assertNull(after.bigContentView);
146 assertNull(after.headsUpContentView);
147 }
148
149 @Test
150 public void testDoesNotStripsExtendersInNormalRamMode() {
151 Notification.Builder nb = new Notification.Builder(mContext, "channel");
152 nb.extend(new Notification.CarExtender().setColor(Color.RED));
153 nb.extend(new Notification.TvExtender().setChannelId("different channel"));
154 nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
155 Notification before = nb.build();
Kristian Monsen30f59b22018-04-09 10:27:16 +0200156 Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, false,
157 mContext);
Julia Reynolds8a3b4592017-06-26 17:15:14 -0400158
159 assertTrue(before == after);
160
161 assertEquals("different channel", new Notification.TvExtender(before).getChannelId());
162 assertEquals(Color.RED, new Notification.CarExtender(before).getColor());
163 assertEquals("dismiss", new Notification.WearableExtender(before).getDismissalId());
164 }
Julia Reynolds7217dc92018-03-07 12:12:09 -0500165
166 @Test
167 public void testStyleChangeVisiblyDifferent_noStyles() {
168 Notification.Builder n1 = new Notification.Builder(mContext, "test");
169 Notification.Builder n2 = new Notification.Builder(mContext, "test");
170
171 assertFalse(Notification.areStyledNotificationsVisiblyDifferent(n1, n2));
172 }
173
174 @Test
175 public void testStyleChangeVisiblyDifferent_noStyleToStyle() {
176 Notification.Builder n1 = new Notification.Builder(mContext, "test");
177 Notification.Builder n2 = new Notification.Builder(mContext, "test")
178 .setStyle(new Notification.BigTextStyle());
179
180 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(n1, n2));
181 }
182
183 @Test
184 public void testStyleChangeVisiblyDifferent_styleToNoStyle() {
185 Notification.Builder n2 = new Notification.Builder(mContext, "test");
186 Notification.Builder n1 = new Notification.Builder(mContext, "test")
187 .setStyle(new Notification.BigTextStyle());
188
189 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(n1, n2));
190 }
191
192 @Test
193 public void testStyleChangeVisiblyDifferent_changeStyle() {
194 Notification.Builder n1 = new Notification.Builder(mContext, "test")
195 .setStyle(new Notification.InboxStyle());
196 Notification.Builder n2 = new Notification.Builder(mContext, "test")
197 .setStyle(new Notification.BigTextStyle());
198
199 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(n1, n2));
200 }
201
202 @Test
203 public void testInboxTextChange() {
204 Notification.Builder nInbox1 = new Notification.Builder(mContext, "test")
205 .setStyle(new Notification.InboxStyle().addLine("a").addLine("b"));
206 Notification.Builder nInbox2 = new Notification.Builder(mContext, "test")
207 .setStyle(new Notification.InboxStyle().addLine("b").addLine("c"));
208
209 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nInbox1, nInbox2));
210 }
211
212 @Test
213 public void testBigTextTextChange() {
214 Notification.Builder nBigText1 = new Notification.Builder(mContext, "test")
215 .setStyle(new Notification.BigTextStyle().bigText("something"));
216 Notification.Builder nBigText2 = new Notification.Builder(mContext, "test")
217 .setStyle(new Notification.BigTextStyle().bigText("else"));
218
219 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nBigText1, nBigText2));
220 }
221
222 @Test
223 public void testBigPictureChange() {
224 Notification.Builder nBigPic1 = new Notification.Builder(mContext, "test")
225 .setStyle(new Notification.BigPictureStyle().bigPicture(mock(Bitmap.class)));
226 Notification.Builder nBigPic2 = new Notification.Builder(mContext, "test")
227 .setStyle(new Notification.BigPictureStyle().bigPicture(mock(Bitmap.class)));
228
229 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nBigPic1, nBigPic2));
230 }
231
232 @Test
233 public void testMessagingChange_text() {
234 Notification.Builder nM1 = new Notification.Builder(mContext, "test")
235 .setStyle(new Notification.MessagingStyle("")
236 .addMessage(new Notification.MessagingStyle.Message(
Selim Cinek9acd6732018-03-23 16:39:02 -0700237 "a", 100, mock(Person.class))));
Julia Reynolds7217dc92018-03-07 12:12:09 -0500238 Notification.Builder nM2 = new Notification.Builder(mContext, "test")
239 .setStyle(new Notification.MessagingStyle("")
240 .addMessage(new Notification.MessagingStyle.Message(
Selim Cinek9acd6732018-03-23 16:39:02 -0700241 "a", 100, mock(Person.class)))
Julia Reynolds7217dc92018-03-07 12:12:09 -0500242 .addMessage(new Notification.MessagingStyle.Message(
Selim Cinek9acd6732018-03-23 16:39:02 -0700243 "b", 100, mock(Person.class)))
Julia Reynolds7217dc92018-03-07 12:12:09 -0500244 );
245
246 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
247 }
248
249 @Test
250 public void testMessagingChange_data() {
251 Notification.Builder nM1 = new Notification.Builder(mContext, "test")
252 .setStyle(new Notification.MessagingStyle("")
253 .addMessage(new Notification.MessagingStyle.Message(
254 "a", 100, mock(Person.class))
255 .setData("text", mock(Uri.class))));
256 Notification.Builder nM2 = new Notification.Builder(mContext, "test")
257 .setStyle(new Notification.MessagingStyle("")
258 .addMessage(new Notification.MessagingStyle.Message(
259 "a", 100, mock(Person.class))));
260
261 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
262 }
263
264 @Test
265 public void testMessagingChange_sender() {
266 Person a = mock(Person.class);
267 when(a.getName()).thenReturn("A");
268 Person b = mock(Person.class);
269 when(b.getName()).thenReturn("b");
270 Notification.Builder nM1 = new Notification.Builder(mContext, "test")
271 .setStyle(new Notification.MessagingStyle("")
272 .addMessage(new Notification.MessagingStyle.Message("a", 100, b)));
273 Notification.Builder nM2 = new Notification.Builder(mContext, "test")
274 .setStyle(new Notification.MessagingStyle("")
275 .addMessage(new Notification.MessagingStyle.Message("a", 100, a)));
276
277 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
278 }
279
280 @Test
281 public void testMessagingChange_key() {
282 Person a = mock(Person.class);
283 when(a.getKey()).thenReturn("A");
284 Person b = mock(Person.class);
285 when(b.getKey()).thenReturn("b");
286 Notification.Builder nM1 = new Notification.Builder(mContext, "test")
287 .setStyle(new Notification.MessagingStyle("")
288 .addMessage(new Notification.MessagingStyle.Message("a", 100, a)));
289 Notification.Builder nM2 = new Notification.Builder(mContext, "test")
290 .setStyle(new Notification.MessagingStyle("")
291 .addMessage(new Notification.MessagingStyle.Message("a", 100, b)));
292
293 assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
294 }
295
296 @Test
297 public void testMessagingChange_ignoreTimeChange() {
298 Notification.Builder nM1 = new Notification.Builder(mContext, "test")
299 .setStyle(new Notification.MessagingStyle("")
300 .addMessage(new Notification.MessagingStyle.Message(
Selim Cinek9acd6732018-03-23 16:39:02 -0700301 "a", 100, mock(Person.class))));
Julia Reynolds7217dc92018-03-07 12:12:09 -0500302 Notification.Builder nM2 = new Notification.Builder(mContext, "test")
303 .setStyle(new Notification.MessagingStyle("")
304 .addMessage(new Notification.MessagingStyle.Message(
Selim Cinek9acd6732018-03-23 16:39:02 -0700305 "a", 1000, mock(Person.class)))
Julia Reynolds7217dc92018-03-07 12:12:09 -0500306 );
307
308 assertFalse(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
309 }
310
311 @Test
312 public void testRemoteViews_nullChange() {
313 Notification.Builder n1 = new Notification.Builder(mContext, "test")
314 .setContent(mock(RemoteViews.class));
315 Notification.Builder n2 = new Notification.Builder(mContext, "test");
316 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
317
318 n1 = new Notification.Builder(mContext, "test");
319 n2 = new Notification.Builder(mContext, "test")
320 .setContent(mock(RemoteViews.class));
321 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
322
323 n1 = new Notification.Builder(mContext, "test")
324 .setCustomBigContentView(mock(RemoteViews.class));
325 n2 = new Notification.Builder(mContext, "test");
326 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
327
328 n1 = new Notification.Builder(mContext, "test");
329 n2 = new Notification.Builder(mContext, "test")
330 .setCustomBigContentView(mock(RemoteViews.class));
331 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
332
333 n1 = new Notification.Builder(mContext, "test");
334 n2 = new Notification.Builder(mContext, "test");
335 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
336 }
337
338 @Test
Julia Reynoldse5c60452018-04-30 14:41:36 -0400339 public void testRemoteViews_layoutChange() {
340 RemoteViews a = mock(RemoteViews.class);
341 when(a.getLayoutId()).thenReturn(234);
342 RemoteViews b = mock(RemoteViews.class);
343 when(b.getLayoutId()).thenReturn(189);
344
345 Notification.Builder n1 = new Notification.Builder(mContext, "test").setContent(a);
346 Notification.Builder n2 = new Notification.Builder(mContext, "test").setContent(b);
347 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
348
349 n1 = new Notification.Builder(mContext, "test").setCustomBigContentView(a);
350 n2 = new Notification.Builder(mContext, "test").setCustomBigContentView(b);
351 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
352
353 n1 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(a);
354 n2 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(b);
355 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
356 }
357
358 @Test
359 public void testRemoteViews_layoutSame() {
360 RemoteViews a = mock(RemoteViews.class);
361 when(a.getLayoutId()).thenReturn(234);
362 RemoteViews b = mock(RemoteViews.class);
363 when(b.getLayoutId()).thenReturn(234);
364
365 Notification.Builder n1 = new Notification.Builder(mContext, "test").setContent(a);
366 Notification.Builder n2 = new Notification.Builder(mContext, "test").setContent(b);
367 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
368
369 n1 = new Notification.Builder(mContext, "test").setCustomBigContentView(a);
370 n2 = new Notification.Builder(mContext, "test").setCustomBigContentView(b);
371 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
372
373 n1 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(a);
374 n2 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(b);
375 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
376 }
377
378 @Test
379 public void testRemoteViews_sequenceChange() {
380 RemoteViews a = mock(RemoteViews.class);
381 when(a.getLayoutId()).thenReturn(234);
382 when(a.getSequenceNumber()).thenReturn(1);
383 RemoteViews b = mock(RemoteViews.class);
384 when(b.getLayoutId()).thenReturn(234);
385 when(b.getSequenceNumber()).thenReturn(2);
386
387 Notification.Builder n1 = new Notification.Builder(mContext, "test").setContent(a);
388 Notification.Builder n2 = new Notification.Builder(mContext, "test").setContent(b);
389 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
390
391 n1 = new Notification.Builder(mContext, "test").setCustomBigContentView(a);
392 n2 = new Notification.Builder(mContext, "test").setCustomBigContentView(b);
393 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
394
395 n1 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(a);
396 n2 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(b);
397 assertTrue(Notification.areRemoteViewsChanged(n1, n2));
398 }
399
400 @Test
401 public void testRemoteViews_sequenceSame() {
402 RemoteViews a = mock(RemoteViews.class);
403 when(a.getLayoutId()).thenReturn(234);
404 when(a.getSequenceNumber()).thenReturn(1);
405 RemoteViews b = mock(RemoteViews.class);
406 when(b.getLayoutId()).thenReturn(234);
407 when(b.getSequenceNumber()).thenReturn(1);
408
409 Notification.Builder n1 = new Notification.Builder(mContext, "test").setContent(a);
410 Notification.Builder n2 = new Notification.Builder(mContext, "test").setContent(b);
411 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
412
413 n1 = new Notification.Builder(mContext, "test").setCustomBigContentView(a);
414 n2 = new Notification.Builder(mContext, "test").setCustomBigContentView(b);
415 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
416
417 n1 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(a);
418 n2 = new Notification.Builder(mContext, "test").setCustomHeadsUpContentView(b);
419 assertFalse(Notification.areRemoteViewsChanged(n1, n2));
420 }
421
422 @Test
Julia Reynolds7217dc92018-03-07 12:12:09 -0500423 public void testActionsDifferent_null() {
424 Notification n1 = new Notification.Builder(mContext, "test")
425 .build();
426 Notification n2 = new Notification.Builder(mContext, "test")
427 .build();
428
429 assertFalse(Notification.areActionsVisiblyDifferent(n1, n2));
430 }
431
432 @Test
433 public void testActionsDifferentSame() {
434 PendingIntent intent = mock(PendingIntent.class);
435 Icon icon = mock(Icon.class);
436
437 Notification n1 = new Notification.Builder(mContext, "test")
438 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent).build())
439 .build();
440 Notification n2 = new Notification.Builder(mContext, "test")
441 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent).build())
442 .build();
443
444 assertFalse(Notification.areActionsVisiblyDifferent(n1, n2));
445 }
446
447 @Test
448 public void testActionsDifferentText() {
449 PendingIntent intent = mock(PendingIntent.class);
450 Icon icon = mock(Icon.class);
451
452 Notification n1 = new Notification.Builder(mContext, "test")
453 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent).build())
454 .build();
455 Notification n2 = new Notification.Builder(mContext, "test")
456 .addAction(new Notification.Action.Builder(icon, "TEXT 2", intent).build())
457 .build();
458
459 assertTrue(Notification.areActionsVisiblyDifferent(n1, n2));
460 }
461
462 @Test
463 public void testActionsDifferentNumber() {
464 PendingIntent intent = mock(PendingIntent.class);
465 Icon icon = mock(Icon.class);
466
467 Notification n1 = new Notification.Builder(mContext, "test")
468 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent).build())
469 .build();
470 Notification n2 = new Notification.Builder(mContext, "test")
471 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent).build())
472 .addAction(new Notification.Action.Builder(icon, "TEXT 2", intent).build())
473 .build();
474
475 assertTrue(Notification.areActionsVisiblyDifferent(n1, n2));
476 }
477
478 @Test
479 public void testActionsDifferentIntent() {
480 PendingIntent intent1 = mock(PendingIntent.class);
481 PendingIntent intent2 = mock(PendingIntent.class);
482 Icon icon = mock(Icon.class);
483
484 Notification n1 = new Notification.Builder(mContext, "test")
485 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent1).build())
486 .build();
487 Notification n2 = new Notification.Builder(mContext, "test")
488 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent2).build())
489 .build();
490
491 assertFalse(Notification.areActionsVisiblyDifferent(n1, n2));
492 }
493
494 @Test
Julia Reynolds5a366fb2018-03-21 15:40:53 -0400495 public void testActionsMoreOptionsThanChoices() {
496 PendingIntent intent1 = mock(PendingIntent.class);
497 PendingIntent intent2 = mock(PendingIntent.class);
498 Icon icon = mock(Icon.class);
499
500 Notification n1 = new Notification.Builder(mContext, "test")
501 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent1).build())
502 .addAction(new Notification.Action.Builder(icon, "TEXT 2", intent1)
503 .addRemoteInput(new RemoteInput.Builder("a")
504 .setChoices(new CharSequence[] {"i", "m"})
505 .build())
506 .build())
507 .build();
508 Notification n2 = new Notification.Builder(mContext, "test")
509 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent2).build())
510 .addAction(new Notification.Action.Builder(icon, "TEXT 2", intent1).build())
511 .build();
512
513 assertTrue(Notification.areActionsVisiblyDifferent(n1, n2));
514 }
515
516 @Test
Julia Reynolds7217dc92018-03-07 12:12:09 -0500517 public void testActionsDifferentRemoteInputs() {
518 PendingIntent intent = mock(PendingIntent.class);
519 Icon icon = mock(Icon.class);
520
521 Notification n1 = new Notification.Builder(mContext, "test")
522 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent)
523 .addRemoteInput(new RemoteInput.Builder("a")
524 .setChoices(new CharSequence[] {"i", "m"})
525 .build())
526 .build())
527 .build();
528 Notification n2 = new Notification.Builder(mContext, "test")
529 .addAction(new Notification.Action.Builder(icon, "TEXT 1", intent)
530 .addRemoteInput(new RemoteInput.Builder("a")
531 .setChoices(new CharSequence[] {"t", "m"})
532 .build())
533 .build())
534 .build();
535
536 assertTrue(Notification.areActionsVisiblyDifferent(n1, n2));
537 }
Julia Reynolds8a3b4592017-06-26 17:15:14 -0400538}
539