Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeTest.java

Issue 2748103011: Grant origins engagement for having interactions on their notifications. (Closed)
Patch Set: Unfriend Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.notifications; 5 package org.chromium.chrome.browser.notifications;
6 6
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8 8
9 import android.annotation.TargetApi; 9 import android.annotation.TargetApi;
10 import android.app.Notification; 10 import android.app.Notification;
11 import android.app.PendingIntent; 11 import android.app.PendingIntent;
12 import android.app.RemoteInput; 12 import android.app.RemoteInput;
13 import android.content.Context; 13 import android.content.Context;
14 import android.content.Intent; 14 import android.content.Intent;
15 import android.graphics.Bitmap; 15 import android.graphics.Bitmap;
16 import android.graphics.BitmapFactory; 16 import android.graphics.BitmapFactory;
17 import android.graphics.Color; 17 import android.graphics.Color;
18 import android.os.Build; 18 import android.os.Build;
19 import android.os.Bundle; 19 import android.os.Bundle;
20 import android.support.test.filters.LargeTest; 20 import android.support.test.filters.LargeTest;
21 import android.support.test.filters.MediumTest; 21 import android.support.test.filters.MediumTest;
22 22
23 import org.chromium.base.ThreadUtils; 23 import org.chromium.base.ThreadUtils;
24 import org.chromium.base.annotations.SuppressFBWarnings; 24 import org.chromium.base.annotations.SuppressFBWarnings;
25 import org.chromium.base.test.util.CommandLineFlags; 25 import org.chromium.base.test.util.CommandLineFlags;
26 import org.chromium.base.test.util.Feature; 26 import org.chromium.base.test.util.Feature;
27 import org.chromium.base.test.util.MinAndroidSdkLevel; 27 import org.chromium.base.test.util.MinAndroidSdkLevel;
28 import org.chromium.base.test.util.RetryOnFailure; 28 import org.chromium.base.test.util.RetryOnFailure;
29 import org.chromium.chrome.R; 29 import org.chromium.chrome.R;
30 import org.chromium.chrome.browser.engagement.SiteEngagementService;
30 import org.chromium.chrome.browser.infobar.InfoBar; 31 import org.chromium.chrome.browser.infobar.InfoBar;
31 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 32 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
32 import org.chromium.chrome.browser.preferences.website.ContentSetting; 33 import org.chromium.chrome.browser.preferences.website.ContentSetting;
34 import org.chromium.chrome.browser.profiles.Profile;
33 import org.chromium.chrome.browser.tab.Tab; 35 import org.chromium.chrome.browser.tab.Tab;
34 import org.chromium.chrome.browser.widget.RoundedIconGenerator; 36 import org.chromium.chrome.browser.widget.RoundedIconGenerator;
35 import org.chromium.chrome.test.util.InfoBarUtil; 37 import org.chromium.chrome.test.util.InfoBarUtil;
36 import org.chromium.chrome.test.util.browser.TabTitleObserver; 38 import org.chromium.chrome.test.util.browser.TabTitleObserver;
37 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy.NotificationEntry; 39 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy.NotificationEntry;
38 import org.chromium.components.url_formatter.UrlFormatter; 40 import org.chromium.components.url_formatter.UrlFormatter;
39 import org.chromium.content.browser.test.util.Criteria; 41 import org.chromium.content.browser.test.util.Criteria;
40 import org.chromium.content.browser.test.util.CriteriaHelper; 42 import org.chromium.content.browser.test.util.CriteriaHelper;
41 43
42 import java.net.URL; 44 import java.net.URL;
43 import java.util.List; 45 import java.util.List;
46 import java.util.concurrent.Callable;
47 import java.util.concurrent.ExecutionException;
44 import java.util.concurrent.TimeoutException; 48 import java.util.concurrent.TimeoutException;
45 49
46 /** 50 /**
47 * Instrumentation tests for the Notification Bridge. 51 * Instrumentation tests for the Notification Bridge.
48 * 52 *
49 * Web Notifications are only supported on Android JellyBean and beyond. 53 * Web Notifications are only supported on Android JellyBean and beyond.
50 */ 54 */
51 public class NotificationPlatformBridgeTest extends NotificationTestBase { 55 public class NotificationPlatformBridgeTest extends NotificationTestBase {
52 private static final String NOTIFICATION_TEST_PAGE = 56 private static final String NOTIFICATION_TEST_PAGE =
53 "/chrome/test/data/notifications/android_test.html"; 57 "/chrome/test/data/notifications/android_test.html";
54 private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(5 ); 58 private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(5 );
55 59
56 @Override 60 @Override
57 protected void setUp() throws Exception { 61 protected void setUp() throws Exception {
58 super.setUp(); 62 super.setUp();
63 SiteEngagementService.setParamValuesForTesting();
59 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); 64 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE));
60 } 65 }
61 66
62 private void waitForTitle(String expectedTitle) throws InterruptedException { 67 private void waitForTitle(String expectedTitle) throws InterruptedException {
63 Tab tab = getActivity().getActivityTab(); 68 Tab tab = getActivity().getActivityTab();
64 TabTitleObserver titleObserver = new TabTitleObserver(tab, expectedTitle ); 69 TabTitleObserver titleObserver = new TabTitleObserver(tab, expectedTitle );
65 try { 70 try {
66 titleObserver.waitForTitleUpdate(TITLE_UPDATE_TIMEOUT_SECONDS); 71 titleObserver.waitForTitleUpdate(TITLE_UPDATE_TIMEOUT_SECONDS);
67 } catch (TimeoutException e) { 72 } catch (TimeoutException e) {
68 // The title is not as expected, this assertion neatly logs what the difference is. 73 // The title is not as expected, this assertion neatly logs what the difference is.
(...skipping 23 matching lines...) Expand all
92 assertEquals(0, getInfoBars().size()); 97 assertEquals(0, getInfoBars().size());
93 } 98 }
94 99
95 private void checkThatShowNotificationIsDenied() throws Exception { 100 private void checkThatShowNotificationIsDenied() throws Exception {
96 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {})"); 101 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {})");
97 waitForTitle("TypeError: No notification permission has been granted for this origin."); 102 waitForTitle("TypeError: No notification permission has been granted for this origin.");
98 // Ideally we'd wait a little here, but it's hard to wait for things tha t shouldn't happen. 103 // Ideally we'd wait a little here, but it's hard to wait for things tha t shouldn't happen.
99 assertTrue(getNotificationEntries().isEmpty()); 104 assertTrue(getNotificationEntries().isEmpty());
100 } 105 }
101 106
107 private double getEngagementScoreBlocking() {
108 try {
109 return ThreadUtils.runOnUiThreadBlocking(new Callable<Double>() {
110 @Override
111 public Double call() throws Exception {
112 return SiteEngagementService.getForProfile(Profile.getLastUs edProfile())
113 .getScore(getOrigin());
114 }
115 });
116 } catch (ExecutionException ex) {
117 assert false : "Unexpected ExecutionException";
118 }
119 return 0.0;
120 }
121
102 /** 122 /**
103 * Verifies that notifcations cannot be shown without permission, and that d ismissing or denying 123 * Verifies that notifcations cannot be shown without permission, and that d ismissing or denying
104 * the infobar works correctly. 124 * the infobar works correctly.
105 */ 125 */
106 @LargeTest 126 @LargeTest
107 @Feature({"Browser", "Notifications"}) 127 @Feature({"Browser", "Notifications"})
108 public void testPermissionDenied() throws Exception { 128 public void testPermissionDenied() throws Exception {
109 // Notifications permission should initially be prompt, and showing shou ld fail. 129 // Notifications permission should initially be prompt, and showing shou ld fail.
110 assertEquals("\"default\"", runJavaScriptCodeInCurrentTab("Notification. permission")); 130 assertEquals("\"default\"", runJavaScriptCodeInCurrentTab("Notification. permission"));
111 checkThatShowNotificationIsDenied(); 131 checkThatShowNotificationIsDenied();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 Notification.Action action = notification.actions[0]; 276 Notification.Action action = notification.actions[0];
257 assertEquals("reply", action.title); 277 assertEquals("reply", action.title);
258 assertNotNull(notification.actions[0].getRemoteInputs()); 278 assertNotNull(notification.actions[0].getRemoteInputs());
259 assertEquals(1, action.getRemoteInputs().length); 279 assertEquals(1, action.getRemoteInputs().length);
260 assertEquals("hi", action.getRemoteInputs()[0].getLabel()); 280 assertEquals("hi", action.getRemoteInputs()[0].getLabel());
261 } 281 }
262 282
263 /** 283 /**
264 * Verifies that setting a reply on the remote input of a notification actio n with type 'text' 284 * Verifies that setting a reply on the remote input of a notification actio n with type 'text'
265 * and triggering the action's intent causes the same reply to be received i n the subsequent 285 * and triggering the action's intent causes the same reply to be received i n the subsequent
266 * notificationclick event on the service worker. 286 * notificationclick event on the service worker. Verifies that site engagem ent is incremented
287 * appropriately.
267 */ 288 */
268 @CommandLineFlags.Add("enable-experimental-web-platform-features") 289 @CommandLineFlags.Add("enable-experimental-web-platform-features")
269 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) 290 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH)
270 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added in KITKAT_WATCH. 291 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added in KITKAT_WATCH.
271 @MediumTest 292 @MediumTest
272 @Feature({"Browser", "Notifications"}) 293 @Feature({"Browser", "Notifications"})
273 public void testReplyToNotification() throws Exception { 294 public void testReplyToNotification() throws Exception {
274 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 295 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
275 Context context = getInstrumentation().getTargetContext(); 296 Context context = getInstrumentation().getTargetContext();
276 297
298 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
299 assertEquals(5.5, getEngagementScoreBlocking());
277 Notification notification = showAndGetNotification("MyNotification", "{ " 300 Notification notification = showAndGetNotification("MyNotification", "{ "
278 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," 301 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
279 + " data: 'ACTION_REPLY'}"); 302 + " data: 'ACTION_REPLY'}");
280 303
281 // Check the action is present with a remote input attached. 304 // Check the action is present with a remote input attached.
282 Notification.Action action = notification.actions[0]; 305 Notification.Action action = notification.actions[0];
283 assertEquals("reply", action.title); 306 assertEquals("reply", action.title);
284 RemoteInput[] remoteInputs = action.getRemoteInputs(); 307 RemoteInput[] remoteInputs = action.getRemoteInputs();
285 assertNotNull(remoteInputs); 308 assertNotNull(remoteInputs);
286 309
287 // Set a reply using the action's remote input key and send it on the in tent. 310 // Set a reply using the action's remote input key and send it on the in tent.
288 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, 311 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs,
289 remoteInputs[0].getResultKey(), "My Reply" /* reply */); 312 remoteInputs[0].getResultKey(), "My Reply" /* reply */);
290 313
291 // Check reply was received by the service worker (see android_test_work er.js). 314 // Check reply was received by the service worker (see android_test_work er.js).
315 // Expect +1 engagement from interacting with the notification.
292 waitForTitle("reply: My Reply"); 316 waitForTitle("reply: My Reply");
317 assertEquals(6.5, getEngagementScoreBlocking());
293 } 318 }
294 319
295 /** 320 /**
296 * Verifies that setting an empty reply on the remote input of a notificatio n action with type 321 * Verifies that setting an empty reply on the remote input of a notificatio n action with type
297 * 'text' and triggering the action's intent causes an empty reply string to be received in the 322 * 'text' and triggering the action's intent causes an empty reply string to be received in the
298 * subsequent notificationclick event on the service worker. 323 * subsequent notificationclick event on the service worker. Verifies that s ite engagement is
324 * incremented appropriately.
299 */ 325 */
300 @CommandLineFlags.Add("enable-experimental-web-platform-features") 326 @CommandLineFlags.Add("enable-experimental-web-platform-features")
301 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) 327 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH)
302 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. 328 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH.
303 @MediumTest 329 @MediumTest
304 @Feature({"Browser", "Notifications"}) 330 @Feature({"Browser", "Notifications"})
305 public void testReplyToNotificationWithEmptyReply() throws Exception { 331 public void testReplyToNotificationWithEmptyReply() throws Exception {
306 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 332 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
307 Context context = getInstrumentation().getTargetContext(); 333 Context context = getInstrumentation().getTargetContext();
308 334
335 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
336 assertEquals(5.5, getEngagementScoreBlocking());
309 Notification notification = showAndGetNotification("MyNotification", "{ " 337 Notification notification = showAndGetNotification("MyNotification", "{ "
310 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," 338 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
311 + " data: 'ACTION_REPLY'}"); 339 + " data: 'ACTION_REPLY'}");
312 340
313 // Check the action is present with a remote input attached. 341 // Check the action is present with a remote input attached.
314 Notification.Action action = notification.actions[0]; 342 Notification.Action action = notification.actions[0];
315 assertEquals("reply", action.title); 343 assertEquals("reply", action.title);
316 RemoteInput[] remoteInputs = action.getRemoteInputs(); 344 RemoteInput[] remoteInputs = action.getRemoteInputs();
317 assertNotNull(remoteInputs); 345 assertNotNull(remoteInputs);
318 346
319 // Set a reply using the action's remote input key and send it on the in tent. 347 // Set a reply using the action's remote input key and send it on the in tent.
320 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, 348 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs,
321 remoteInputs[0].getResultKey(), "" /* reply */); 349 remoteInputs[0].getResultKey(), "" /* reply */);
322 350
323 // Check empty reply was received by the service worker (see android_tes t_worker.js). 351 // Check empty reply was received by the service worker (see android_tes t_worker.js).
352 // Expect +1 engagement from interacting with the notification.
324 waitForTitle("reply:"); 353 waitForTitle("reply:");
354 assertEquals(6.5, getEngagementScoreBlocking());
325 } 355 }
326 356
327 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. 357 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH.
328 private static void sendIntentWithRemoteInput(Context context, PendingIntent pendingIntent, 358 private static void sendIntentWithRemoteInput(Context context, PendingIntent pendingIntent,
329 RemoteInput[] remoteInputs, String resultKey, String reply) 359 RemoteInput[] remoteInputs, String resultKey, String reply)
330 throws PendingIntent.CanceledException { 360 throws PendingIntent.CanceledException {
331 Bundle results = new Bundle(); 361 Bundle results = new Bundle();
332 results.putString(resultKey, reply); 362 results.putString(resultKey, reply);
333 Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGRO UND); 363 Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGRO UND);
334 RemoteInput.addResultsToIntent(remoteInputs, fillInIntent, results); 364 RemoteInput.addResultsToIntent(remoteInputs, fillInIntent, results);
335 365
336 // Send the pending intent filled in with the additional information fro m the new intent. 366 // Send the pending intent filled in with the additional information fro m the new intent.
337 pendingIntent.send(context, 0 /* code */, fillInIntent); 367 pendingIntent.send(context, 0 /* code */, fillInIntent);
338 } 368 }
339 369
340 /** 370 /**
341 * Verifies that *not* setting a reply on the remote input of a notification action with type 371 * Verifies that *not* setting a reply on the remote input of a notification action with type
342 * 'text' and triggering the action's intent causes a null reply to be recei ved in the 372 * 'text' and triggering the action's intent causes a null reply to be recei ved in the
343 * subsequent notificationclick event on the service worker. 373 * subsequent notificationclick event on the service worker. Verifies that site engagement is
374 * incremented appropriately.
344 */ 375 */
345 @TargetApi(Build.VERSION_CODES.KITKAT) // Notification.Action.actionIntent a dded in Android K. 376 @TargetApi(Build.VERSION_CODES.KITKAT) // Notification.Action.actionIntent a dded in Android K.
346 @CommandLineFlags.Add("enable-experimental-web-platform-features") 377 @CommandLineFlags.Add("enable-experimental-web-platform-features")
347 @MediumTest 378 @MediumTest
348 @Feature({"Browser", "Notifications"}) 379 @Feature({"Browser", "Notifications"})
349 public void testReplyToNotificationWithNoRemoteInput() throws Exception { 380 public void testReplyToNotificationWithNoRemoteInput() throws Exception {
350 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 381 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
351 382
383 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
384 assertEquals(5.5, getEngagementScoreBlocking());
352 Notification notification = showAndGetNotification("MyNotification", "{ " 385 Notification notification = showAndGetNotification("MyNotification", "{ "
353 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," 386 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}],"
354 + " data: 'ACTION_REPLY'}"); 387 + " data: 'ACTION_REPLY'}");
355 388
356 assertEquals("reply", notification.actions[0].title); 389 assertEquals("reply", notification.actions[0].title);
357 notification.actions[0].actionIntent.send(); 390 notification.actions[0].actionIntent.send();
358 391
359 // Check reply was received by the service worker (see android_test_work er.js). 392 // Check reply was received by the service worker (see android_test_work er.js).
393 // Expect +1 engagement from interacting with the notification.
360 waitForTitle("reply: null"); 394 waitForTitle("reply: null");
395 assertEquals(6.5, getEngagementScoreBlocking());
361 } 396 }
362 397
363 /** 398 /**
364 * Verifies that the ONLY_ALERT_ONCE flag is not set when renotify is true. 399 * Verifies that the ONLY_ALERT_ONCE flag is not set when renotify is true.
365 */ 400 */
366 @MediumTest 401 @MediumTest
367 @Feature({"Browser", "Notifications"}) 402 @Feature({"Browser", "Notifications"})
368 public void testNotificationRenotifyProperty() throws Exception { 403 public void testNotificationRenotifyProperty() throws Exception {
369 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 404 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
370 405
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 /* 607 /*
573 * Verifies that starting the PendingIntent stored as the notification's con tent intent will 608 * Verifies that starting the PendingIntent stored as the notification's con tent intent will
574 * start up the associated Service Worker, where the JavaScript code will cl ose the notification 609 * start up the associated Service Worker, where the JavaScript code will cl ose the notification
575 * by calling event.notification.close(). 610 * by calling event.notification.close().
576 */ 611 */
577 @LargeTest 612 @LargeTest
578 @Feature({"Browser", "Notifications"}) 613 @Feature({"Browser", "Notifications"})
579 @RetryOnFailure 614 @RetryOnFailure
580 public void testNotificationContentIntentClosesNotification() throws Excepti on { 615 public void testNotificationContentIntentClosesNotification() throws Excepti on {
581 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 616 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
617 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
618 assertEquals(5.5, getEngagementScoreBlocking());
582 619
583 Notification notification = showAndGetNotification("MyNotification", "{} "); 620 Notification notification = showAndGetNotification("MyNotification", "{} ");
584 621
585 // Sending the PendingIntent resembles activating the notification. 622 // Sending the PendingIntent resembles activating the notification.
586 assertNotNull(notification.contentIntent); 623 assertNotNull(notification.contentIntent);
587 notification.contentIntent.send(); 624 notification.contentIntent.send();
588 625
589 // The Service Worker will close the notification upon receiving the not ificationclick 626 // The Service Worker will close the notification upon receiving the not ificationclick
590 // event. This will eventually bubble up to a call to cancel() in the No tificationManager. 627 // event. This will eventually bubble up to a call to cancel() in the No tificationManager.
628 // Expect +1 engagement from interacting with the notification.
591 waitForNotificationManagerMutation(); 629 waitForNotificationManagerMutation();
592 assertTrue(getNotificationEntries().isEmpty()); 630 assertTrue(getNotificationEntries().isEmpty());
631 assertEquals(6.5, getEngagementScoreBlocking());
593 } 632 }
594 633
595 /** 634 /**
596 * Verifies that starting the PendingIntent stored as the notification's con tent intent will 635 * Verifies that starting the PendingIntent stored as the notification's con tent intent will
597 * start up the associated Service Worker, where the JavaScript code will cr eate a new tab for 636 * start up the associated Service Worker, where the JavaScript code will cr eate a new tab for
598 * displaying the notification's event to the user. 637 * displaying the notification's event to the user.
599 */ 638 */
600 @LargeTest 639 @LargeTest
601 @Feature({"Browser", "Notifications"}) 640 @Feature({"Browser", "Notifications"})
602 @RetryOnFailure 641 @RetryOnFailure
(...skipping 25 matching lines...) Expand all
628 667
629 /** 668 /**
630 * Verifies that creating a notification with an associated "tag" will cause any previous 669 * Verifies that creating a notification with an associated "tag" will cause any previous
631 * notification with the same tag to be dismissed prior to being shown. 670 * notification with the same tag to be dismissed prior to being shown.
632 */ 671 */
633 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") 672 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
634 @MediumTest 673 @MediumTest
635 @Feature({"Browser", "Notifications"}) 674 @Feature({"Browser", "Notifications"})
636 public void testNotificationTagReplacement() throws Exception { 675 public void testNotificationTagReplacement() throws Exception {
637 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 676 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
677 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
678 assertEquals(5.5, getEngagementScoreBlocking());
638 679
639 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});"); 680 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});");
640 waitForNotificationManagerMutation(); 681 waitForNotificationManagerMutation();
641 List<NotificationEntry> notifications = getNotificationEntries(); 682 List<NotificationEntry> notifications = getNotificationEntries();
642 String tag = notifications.get(0).tag; 683 String tag = notifications.get(0).tag;
643 int id = notifications.get(0).id; 684 int id = notifications.get(0).id;
644 685
645 runJavaScriptCodeInCurrentTab("showNotification('SecondNotification', {t ag: 'myTag'});"); 686 runJavaScriptCodeInCurrentTab("showNotification('SecondNotification', {t ag: 'myTag'});");
646 waitForNotificationManagerMutation(); 687 waitForNotificationManagerMutation();
647 688
648 // Verify that the notification was successfully replaced. 689 // Verify that the notification was successfully replaced.
649 notifications = getNotificationEntries(); 690 notifications = getNotificationEntries();
650 assertEquals(1, notifications.size()); 691 assertEquals(1, notifications.size());
651 assertEquals("SecondNotification", 692 assertEquals("SecondNotification",
652 NotificationTestUtil.getExtraTitle(notifications.get(0).notifica tion)); 693 NotificationTestUtil.getExtraTitle(notifications.get(0).notifica tion));
653 694
654 // Verify that for replaced notifications their tag was the same. 695 // Verify that for replaced notifications their tag was the same.
655 assertEquals(tag, notifications.get(0).tag); 696 assertEquals(tag, notifications.get(0).tag);
656 697
657 // Verify that as always, the same integer is used, also for replaced no tifications. 698 // Verify that as always, the same integer is used, also for replaced no tifications.
658 assertEquals(id, notifications.get(0).id); 699 assertEquals(id, notifications.get(0).id);
659 assertEquals(NotificationPlatformBridge.PLATFORM_ID, notifications.get(0 ).id); 700 assertEquals(NotificationPlatformBridge.PLATFORM_ID, notifications.get(0 ).id);
701
702 // Engagement should not have changed since we didn't interact.
703 assertEquals(5.5, getEngagementScoreBlocking());
660 } 704 }
661 705
662 /** 706 /**
663 * Verifies that multiple notifications without a tag can be opened and clos ed without 707 * Verifies that multiple notifications without a tag can be opened and clos ed without
664 * affecting eachother. 708 * affecting eachother.
665 */ 709 */
666 @LargeTest 710 @LargeTest
667 @Feature({"Browser", "Notifications"}) 711 @Feature({"Browser", "Notifications"})
668 public void testShowAndCloseMultipleNotifications() throws Exception { 712 public void testShowAndCloseMultipleNotifications() throws Exception {
669 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); 713 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
714 // +5 engagement from notification permission and +0.5 from navigating t o the test page.
715 assertEquals(5.5, getEngagementScoreBlocking());
670 716
671 // Open the first notification and verify it is displayed. 717 // Open the first notification and verify it is displayed.
672 runJavaScriptCodeInCurrentTab("showNotification('One');"); 718 runJavaScriptCodeInCurrentTab("showNotification('One');");
673 waitForNotificationManagerMutation(); 719 waitForNotificationManagerMutation();
674 List<NotificationEntry> notifications = getNotificationEntries(); 720 List<NotificationEntry> notifications = getNotificationEntries();
675 assertEquals(1, notifications.size()); 721 assertEquals(1, notifications.size());
676 Notification notificationOne = notifications.get(0).notification; 722 Notification notificationOne = notifications.get(0).notification;
677 assertEquals("One", NotificationTestUtil.getExtraTitle(notificationOne)) ; 723 assertEquals("One", NotificationTestUtil.getExtraTitle(notificationOne)) ;
678 724
679 // Open the second notification and verify it is displayed. 725 // Open the second notification and verify it is displayed.
(...skipping 20 matching lines...) Expand all
700 // Close the first notification and verify that only the second remains. 746 // Close the first notification and verify that only the second remains.
701 // Sending the content intent resembles touching the notification. In re sponse tho this the 747 // Sending the content intent resembles touching the notification. In re sponse tho this the
702 // notificationclick event is fired. The test service worker will close the notification 748 // notificationclick event is fired. The test service worker will close the notification
703 // upon receiving the event. 749 // upon receiving the event.
704 notificationOne.contentIntent.send(); 750 notificationOne.contentIntent.send();
705 waitForNotificationManagerMutation(); 751 waitForNotificationManagerMutation();
706 notifications = getNotificationEntries(); 752 notifications = getNotificationEntries();
707 assertEquals(1, notifications.size()); 753 assertEquals(1, notifications.size());
708 assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get (0).notification)); 754 assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get (0).notification));
709 755
756 // Expect +1 engagement from interacting with the notification.
757 assertEquals(6.5, getEngagementScoreBlocking());
758
710 // Close the last notification and verify that none remain. 759 // Close the last notification and verify that none remain.
711 notifications.get(0).notification.contentIntent.send(); 760 notifications.get(0).notification.contentIntent.send();
712 waitForNotificationManagerMutation(); 761 waitForNotificationManagerMutation();
713 assertTrue(getNotificationEntries().isEmpty()); 762 assertTrue(getNotificationEntries().isEmpty());
763
764 // Expect +1 engagement from interacting with the notification.
765 assertEquals(7.5, getEngagementScoreBlocking());
714 } 766 }
715 } 767 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698