OLD | NEW |
---|---|
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; |
44 import java.util.concurrent.TimeoutException; | 46 import java.util.concurrent.TimeoutException; |
45 | 47 |
46 /** | 48 /** |
47 * Instrumentation tests for the Notification Bridge. | 49 * Instrumentation tests for the Notification Bridge. |
48 * | 50 * |
49 * Web Notifications are only supported on Android JellyBean and beyond. | 51 * Web Notifications are only supported on Android JellyBean and beyond. |
50 */ | 52 */ |
51 public class NotificationPlatformBridgeTest extends NotificationTestBase { | 53 public class NotificationPlatformBridgeTest extends NotificationTestBase { |
52 private static final String NOTIFICATION_TEST_PAGE = | 54 private static final String NOTIFICATION_TEST_PAGE = |
53 "/chrome/test/data/notifications/android_test.html"; | 55 "/chrome/test/data/notifications/android_test.html"; |
54 private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(5 ); | 56 private static final int TITLE_UPDATE_TIMEOUT_SECONDS = (int) scaleTimeout(5 ); |
55 | 57 |
56 @Override | 58 @Override |
57 protected void setUp() throws Exception { | 59 protected void setUp() throws Exception { |
58 super.setUp(); | 60 super.setUp(); |
61 SiteEngagementService.setParamValuesForTesting(); | |
59 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); | 62 loadUrl(getTestServer().getURL(NOTIFICATION_TEST_PAGE)); |
60 } | 63 } |
61 | 64 |
62 private void waitForTitle(String expectedTitle) throws InterruptedException { | 65 private void waitForTitle(String expectedTitle) throws InterruptedException { |
63 Tab tab = getActivity().getActivityTab(); | 66 Tab tab = getActivity().getActivityTab(); |
64 TabTitleObserver titleObserver = new TabTitleObserver(tab, expectedTitle ); | 67 TabTitleObserver titleObserver = new TabTitleObserver(tab, expectedTitle ); |
65 try { | 68 try { |
66 titleObserver.waitForTitleUpdate(TITLE_UPDATE_TIMEOUT_SECONDS); | 69 titleObserver.waitForTitleUpdate(TITLE_UPDATE_TIMEOUT_SECONDS); |
67 } catch (TimeoutException e) { | 70 } catch (TimeoutException e) { |
68 // The title is not as expected, this assertion neatly logs what the difference is. | 71 // The title is not as expected, this assertion neatly logs what the difference is. |
(...skipping 23 matching lines...) Expand all Loading... | |
92 assertEquals(0, getInfoBars().size()); | 95 assertEquals(0, getInfoBars().size()); |
93 } | 96 } |
94 | 97 |
95 private void checkThatShowNotificationIsDenied() throws Exception { | 98 private void checkThatShowNotificationIsDenied() throws Exception { |
96 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {})"); | 99 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {})"); |
97 waitForTitle("TypeError: No notification permission has been granted for this origin."); | 100 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. | 101 // Ideally we'd wait a little here, but it's hard to wait for things tha t shouldn't happen. |
99 assertTrue(getNotificationEntries().isEmpty()); | 102 assertTrue(getNotificationEntries().isEmpty()); |
100 } | 103 } |
101 | 104 |
105 private void checkEngagementScore(final double expectedScore) { | |
106 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
Peter Beverloo
2017/03/16 12:24:14
Optional comment:
There's an overload of runOnUiT
dominickn
2017/03/16 23:25:03
Thanks! This is much nicer. Done.
| |
107 @Override | |
108 public void run() { | |
109 assertEquals(expectedScore, | |
110 SiteEngagementService.getForProfile(Profile.getLastUsedP rofile()) | |
111 .getScore(getOrigin())); | |
112 } | |
113 }); | |
114 } | |
115 | |
102 /** | 116 /** |
103 * Verifies that notifcations cannot be shown without permission, and that d ismissing or denying | 117 * Verifies that notifcations cannot be shown without permission, and that d ismissing or denying |
104 * the infobar works correctly. | 118 * the infobar works correctly. |
105 */ | 119 */ |
106 @LargeTest | 120 @LargeTest |
107 @Feature({"Browser", "Notifications"}) | 121 @Feature({"Browser", "Notifications"}) |
108 public void testPermissionDenied() throws Exception { | 122 public void testPermissionDenied() throws Exception { |
109 // Notifications permission should initially be prompt, and showing shou ld fail. | 123 // Notifications permission should initially be prompt, and showing shou ld fail. |
110 assertEquals("\"default\"", runJavaScriptCodeInCurrentTab("Notification. permission")); | 124 assertEquals("\"default\"", runJavaScriptCodeInCurrentTab("Notification. permission")); |
111 checkThatShowNotificationIsDenied(); | 125 checkThatShowNotificationIsDenied(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 Notification.Action action = notification.actions[0]; | 270 Notification.Action action = notification.actions[0]; |
257 assertEquals("reply", action.title); | 271 assertEquals("reply", action.title); |
258 assertNotNull(notification.actions[0].getRemoteInputs()); | 272 assertNotNull(notification.actions[0].getRemoteInputs()); |
259 assertEquals(1, action.getRemoteInputs().length); | 273 assertEquals(1, action.getRemoteInputs().length); |
260 assertEquals("hi", action.getRemoteInputs()[0].getLabel()); | 274 assertEquals("hi", action.getRemoteInputs()[0].getLabel()); |
261 } | 275 } |
262 | 276 |
263 /** | 277 /** |
264 * Verifies that setting a reply on the remote input of a notification actio n with type 'text' | 278 * 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 | 279 * and triggering the action's intent causes the same reply to be received i n the subsequent |
266 * notificationclick event on the service worker. | 280 * notificationclick event on the service worker. Verifies that site engagem ent is incremented |
281 * appropriately. | |
267 */ | 282 */ |
268 @CommandLineFlags.Add("enable-experimental-web-platform-features") | 283 @CommandLineFlags.Add("enable-experimental-web-platform-features") |
269 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) | 284 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) |
270 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added in KITKAT_WATCH. | 285 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs were only added in KITKAT_WATCH. |
271 @MediumTest | 286 @MediumTest |
272 @Feature({"Browser", "Notifications"}) | 287 @Feature({"Browser", "Notifications"}) |
273 public void testReplyToNotification() throws Exception { | 288 public void testReplyToNotification() throws Exception { |
274 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 289 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
275 Context context = getInstrumentation().getTargetContext(); | 290 Context context = getInstrumentation().getTargetContext(); |
276 | 291 |
292 // We expect +5 engagement from having notification permission and +0.5 from navigating to | |
293 // the test page. | |
294 checkEngagementScore(5.5); | |
277 Notification notification = showAndGetNotification("MyNotification", "{ " | 295 Notification notification = showAndGetNotification("MyNotification", "{ " |
278 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," | 296 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
279 + " data: 'ACTION_REPLY'}"); | 297 + " data: 'ACTION_REPLY'}"); |
280 | 298 |
281 // Check the action is present with a remote input attached. | 299 // Check the action is present with a remote input attached. |
282 Notification.Action action = notification.actions[0]; | 300 Notification.Action action = notification.actions[0]; |
283 assertEquals("reply", action.title); | 301 assertEquals("reply", action.title); |
284 RemoteInput[] remoteInputs = action.getRemoteInputs(); | 302 RemoteInput[] remoteInputs = action.getRemoteInputs(); |
285 assertNotNull(remoteInputs); | 303 assertNotNull(remoteInputs); |
286 | 304 |
287 // Set a reply using the action's remote input key and send it on the in tent. | 305 // Set a reply using the action's remote input key and send it on the in tent. |
288 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, | 306 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, |
289 remoteInputs[0].getResultKey(), "My Reply" /* reply */); | 307 remoteInputs[0].getResultKey(), "My Reply" /* reply */); |
290 | 308 |
291 // Check reply was received by the service worker (see android_test_work er.js). | 309 // Check reply was received by the service worker (see android_test_work er.js). |
310 // Expect +1 engagement from interacting with the notification. | |
292 waitForTitle("reply: My Reply"); | 311 waitForTitle("reply: My Reply"); |
312 checkEngagementScore(6.5); | |
293 } | 313 } |
294 | 314 |
295 /** | 315 /** |
296 * Verifies that setting an empty reply on the remote input of a notificatio n action with type | 316 * 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 | 317 * '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. | 318 * subsequent notificationclick event on the service worker. Verifies that s ite engagement is |
319 * incremented appropriately. | |
299 */ | 320 */ |
300 @CommandLineFlags.Add("enable-experimental-web-platform-features") | 321 @CommandLineFlags.Add("enable-experimental-web-platform-features") |
301 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) | 322 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT_WATCH) |
302 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. | 323 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. |
303 @MediumTest | 324 @MediumTest |
304 @Feature({"Browser", "Notifications"}) | 325 @Feature({"Browser", "Notifications"}) |
305 public void testReplyToNotificationWithEmptyReply() throws Exception { | 326 public void testReplyToNotificationWithEmptyReply() throws Exception { |
306 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 327 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
307 Context context = getInstrumentation().getTargetContext(); | 328 Context context = getInstrumentation().getTargetContext(); |
308 | 329 |
330 // We expect +5 engagement from having notification permission and +0.5 from navigating to | |
331 // the test page. | |
332 checkEngagementScore(5.5); | |
309 Notification notification = showAndGetNotification("MyNotification", "{ " | 333 Notification notification = showAndGetNotification("MyNotification", "{ " |
310 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," | 334 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
311 + " data: 'ACTION_REPLY'}"); | 335 + " data: 'ACTION_REPLY'}"); |
312 | 336 |
313 // Check the action is present with a remote input attached. | 337 // Check the action is present with a remote input attached. |
314 Notification.Action action = notification.actions[0]; | 338 Notification.Action action = notification.actions[0]; |
315 assertEquals("reply", action.title); | 339 assertEquals("reply", action.title); |
316 RemoteInput[] remoteInputs = action.getRemoteInputs(); | 340 RemoteInput[] remoteInputs = action.getRemoteInputs(); |
317 assertNotNull(remoteInputs); | 341 assertNotNull(remoteInputs); |
318 | 342 |
319 // Set a reply using the action's remote input key and send it on the in tent. | 343 // Set a reply using the action's remote input key and send it on the in tent. |
320 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, | 344 sendIntentWithRemoteInput(context, action.actionIntent, remoteInputs, |
321 remoteInputs[0].getResultKey(), "" /* reply */); | 345 remoteInputs[0].getResultKey(), "" /* reply */); |
322 | 346 |
323 // Check empty reply was received by the service worker (see android_tes t_worker.js). | 347 // Check empty reply was received by the service worker (see android_tes t_worker.js). |
348 // Expect +1 engagement from interacting with the notification. | |
324 waitForTitle("reply:"); | 349 waitForTitle("reply:"); |
350 checkEngagementScore(6.5); | |
325 } | 351 } |
326 | 352 |
327 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. | 353 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // RemoteInputs added in KITKAT _WATCH. |
328 private static void sendIntentWithRemoteInput(Context context, PendingIntent pendingIntent, | 354 private static void sendIntentWithRemoteInput(Context context, PendingIntent pendingIntent, |
329 RemoteInput[] remoteInputs, String resultKey, String reply) | 355 RemoteInput[] remoteInputs, String resultKey, String reply) |
330 throws PendingIntent.CanceledException { | 356 throws PendingIntent.CanceledException { |
331 Bundle results = new Bundle(); | 357 Bundle results = new Bundle(); |
332 results.putString(resultKey, reply); | 358 results.putString(resultKey, reply); |
333 Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGRO UND); | 359 Intent fillInIntent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGRO UND); |
334 RemoteInput.addResultsToIntent(remoteInputs, fillInIntent, results); | 360 RemoteInput.addResultsToIntent(remoteInputs, fillInIntent, results); |
335 | 361 |
336 // Send the pending intent filled in with the additional information fro m the new intent. | 362 // Send the pending intent filled in with the additional information fro m the new intent. |
337 pendingIntent.send(context, 0 /* code */, fillInIntent); | 363 pendingIntent.send(context, 0 /* code */, fillInIntent); |
338 } | 364 } |
339 | 365 |
340 /** | 366 /** |
341 * Verifies that *not* setting a reply on the remote input of a notification action with type | 367 * 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 | 368 * '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. | 369 * subsequent notificationclick event on the service worker. Verifies that site engagement is |
370 * incremented appropriately. | |
344 */ | 371 */ |
345 @TargetApi(Build.VERSION_CODES.KITKAT) // Notification.Action.actionIntent a dded in Android K. | 372 @TargetApi(Build.VERSION_CODES.KITKAT) // Notification.Action.actionIntent a dded in Android K. |
346 @CommandLineFlags.Add("enable-experimental-web-platform-features") | 373 @CommandLineFlags.Add("enable-experimental-web-platform-features") |
347 @MediumTest | 374 @MediumTest |
348 @Feature({"Browser", "Notifications"}) | 375 @Feature({"Browser", "Notifications"}) |
349 public void testReplyToNotificationWithNoRemoteInput() throws Exception { | 376 public void testReplyToNotificationWithNoRemoteInput() throws Exception { |
350 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 377 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
351 | 378 |
379 // We expect +5 engagement from having notification permission and +0.5 from navigating to | |
380 // the test page. | |
381 checkEngagementScore(5.5); | |
352 Notification notification = showAndGetNotification("MyNotification", "{ " | 382 Notification notification = showAndGetNotification("MyNotification", "{ " |
353 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," | 383 + " actions: [{action: 'myAction', title: 'reply', type: 'text'}]," |
354 + " data: 'ACTION_REPLY'}"); | 384 + " data: 'ACTION_REPLY'}"); |
355 | 385 |
356 assertEquals("reply", notification.actions[0].title); | 386 assertEquals("reply", notification.actions[0].title); |
357 notification.actions[0].actionIntent.send(); | 387 notification.actions[0].actionIntent.send(); |
358 | 388 |
359 // Check reply was received by the service worker (see android_test_work er.js). | 389 // Check reply was received by the service worker (see android_test_work er.js). |
390 // Expect +1 engagement from interacting with the notification. | |
360 waitForTitle("reply: null"); | 391 waitForTitle("reply: null"); |
392 checkEngagementScore(6.5); | |
361 } | 393 } |
362 | 394 |
363 /** | 395 /** |
364 * Verifies that the ONLY_ALERT_ONCE flag is not set when renotify is true. | 396 * Verifies that the ONLY_ALERT_ONCE flag is not set when renotify is true. |
365 */ | 397 */ |
366 @MediumTest | 398 @MediumTest |
367 @Feature({"Browser", "Notifications"}) | 399 @Feature({"Browser", "Notifications"}) |
368 public void testNotificationRenotifyProperty() throws Exception { | 400 public void testNotificationRenotifyProperty() throws Exception { |
369 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 401 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
370 | 402 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 /* | 604 /* |
573 * Verifies that starting the PendingIntent stored as the notification's con tent intent will | 605 * 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 | 606 * start up the associated Service Worker, where the JavaScript code will cl ose the notification |
575 * by calling event.notification.close(). | 607 * by calling event.notification.close(). |
576 */ | 608 */ |
577 @LargeTest | 609 @LargeTest |
578 @Feature({"Browser", "Notifications"}) | 610 @Feature({"Browser", "Notifications"}) |
579 @RetryOnFailure | 611 @RetryOnFailure |
580 public void testNotificationContentIntentClosesNotification() throws Excepti on { | 612 public void testNotificationContentIntentClosesNotification() throws Excepti on { |
581 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 613 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
614 checkEngagementScore(5.5); | |
582 | 615 |
583 Notification notification = showAndGetNotification("MyNotification", "{} "); | 616 Notification notification = showAndGetNotification("MyNotification", "{} "); |
584 | 617 |
585 // Sending the PendingIntent resembles activating the notification. | 618 // Sending the PendingIntent resembles activating the notification. |
586 assertNotNull(notification.contentIntent); | 619 assertNotNull(notification.contentIntent); |
587 notification.contentIntent.send(); | 620 notification.contentIntent.send(); |
588 | 621 |
589 // The Service Worker will close the notification upon receiving the not ificationclick | 622 // 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. | 623 // event. This will eventually bubble up to a call to cancel() in the No tificationManager. |
591 waitForNotificationManagerMutation(); | 624 waitForNotificationManagerMutation(); |
592 assertTrue(getNotificationEntries().isEmpty()); | 625 assertTrue(getNotificationEntries().isEmpty()); |
626 checkEngagementScore(6.5); | |
593 } | 627 } |
594 | 628 |
595 /** | 629 /** |
596 * Verifies that starting the PendingIntent stored as the notification's con tent intent will | 630 * 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 | 631 * 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. | 632 * displaying the notification's event to the user. |
599 */ | 633 */ |
600 @LargeTest | 634 @LargeTest |
601 @Feature({"Browser", "Notifications"}) | 635 @Feature({"Browser", "Notifications"}) |
602 @RetryOnFailure | 636 @RetryOnFailure |
(...skipping 25 matching lines...) Expand all Loading... | |
628 | 662 |
629 /** | 663 /** |
630 * Verifies that creating a notification with an associated "tag" will cause any previous | 664 * 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. | 665 * notification with the same tag to be dismissed prior to being shown. |
632 */ | 666 */ |
633 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") | 667 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") |
634 @MediumTest | 668 @MediumTest |
635 @Feature({"Browser", "Notifications"}) | 669 @Feature({"Browser", "Notifications"}) |
636 public void testNotificationTagReplacement() throws Exception { | 670 public void testNotificationTagReplacement() throws Exception { |
637 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 671 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
672 checkEngagementScore(5.5); | |
638 | 673 |
639 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});"); | 674 runJavaScriptCodeInCurrentTab("showNotification('MyNotification', {tag: 'myTag'});"); |
640 waitForNotificationManagerMutation(); | 675 waitForNotificationManagerMutation(); |
641 List<NotificationEntry> notifications = getNotificationEntries(); | 676 List<NotificationEntry> notifications = getNotificationEntries(); |
642 String tag = notifications.get(0).tag; | 677 String tag = notifications.get(0).tag; |
643 int id = notifications.get(0).id; | 678 int id = notifications.get(0).id; |
644 | 679 |
645 runJavaScriptCodeInCurrentTab("showNotification('SecondNotification', {t ag: 'myTag'});"); | 680 runJavaScriptCodeInCurrentTab("showNotification('SecondNotification', {t ag: 'myTag'});"); |
646 waitForNotificationManagerMutation(); | 681 waitForNotificationManagerMutation(); |
647 | 682 |
648 // Verify that the notification was successfully replaced. | 683 // Verify that the notification was successfully replaced. |
649 notifications = getNotificationEntries(); | 684 notifications = getNotificationEntries(); |
650 assertEquals(1, notifications.size()); | 685 assertEquals(1, notifications.size()); |
651 assertEquals("SecondNotification", | 686 assertEquals("SecondNotification", |
652 NotificationTestUtil.getExtraTitle(notifications.get(0).notifica tion)); | 687 NotificationTestUtil.getExtraTitle(notifications.get(0).notifica tion)); |
653 | 688 |
654 // Verify that for replaced notifications their tag was the same. | 689 // Verify that for replaced notifications their tag was the same. |
655 assertEquals(tag, notifications.get(0).tag); | 690 assertEquals(tag, notifications.get(0).tag); |
656 | 691 |
657 // Verify that as always, the same integer is used, also for replaced no tifications. | 692 // Verify that as always, the same integer is used, also for replaced no tifications. |
658 assertEquals(id, notifications.get(0).id); | 693 assertEquals(id, notifications.get(0).id); |
659 assertEquals(NotificationPlatformBridge.PLATFORM_ID, notifications.get(0 ).id); | 694 assertEquals(NotificationPlatformBridge.PLATFORM_ID, notifications.get(0 ).id); |
695 | |
696 checkEngagementScore(5.5); | |
660 } | 697 } |
661 | 698 |
662 /** | 699 /** |
663 * Verifies that multiple notifications without a tag can be opened and clos ed without | 700 * Verifies that multiple notifications without a tag can be opened and clos ed without |
664 * affecting eachother. | 701 * affecting eachother. |
665 */ | 702 */ |
666 @LargeTest | 703 @LargeTest |
667 @Feature({"Browser", "Notifications"}) | 704 @Feature({"Browser", "Notifications"}) |
668 public void testShowAndCloseMultipleNotifications() throws Exception { | 705 public void testShowAndCloseMultipleNotifications() throws Exception { |
669 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); | 706 setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); |
707 checkEngagementScore(5.5); | |
670 | 708 |
671 // Open the first notification and verify it is displayed. | 709 // Open the first notification and verify it is displayed. |
672 runJavaScriptCodeInCurrentTab("showNotification('One');"); | 710 runJavaScriptCodeInCurrentTab("showNotification('One');"); |
673 waitForNotificationManagerMutation(); | 711 waitForNotificationManagerMutation(); |
674 List<NotificationEntry> notifications = getNotificationEntries(); | 712 List<NotificationEntry> notifications = getNotificationEntries(); |
675 assertEquals(1, notifications.size()); | 713 assertEquals(1, notifications.size()); |
676 Notification notificationOne = notifications.get(0).notification; | 714 Notification notificationOne = notifications.get(0).notification; |
677 assertEquals("One", NotificationTestUtil.getExtraTitle(notificationOne)) ; | 715 assertEquals("One", NotificationTestUtil.getExtraTitle(notificationOne)) ; |
678 | 716 |
679 // Open the second notification and verify it is displayed. | 717 // Open the second notification and verify it is displayed. |
(...skipping 20 matching lines...) Expand all Loading... | |
700 // Close the first notification and verify that only the second remains. | 738 // 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 | 739 // 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 | 740 // notificationclick event is fired. The test service worker will close the notification |
703 // upon receiving the event. | 741 // upon receiving the event. |
704 notificationOne.contentIntent.send(); | 742 notificationOne.contentIntent.send(); |
705 waitForNotificationManagerMutation(); | 743 waitForNotificationManagerMutation(); |
706 notifications = getNotificationEntries(); | 744 notifications = getNotificationEntries(); |
707 assertEquals(1, notifications.size()); | 745 assertEquals(1, notifications.size()); |
708 assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get (0).notification)); | 746 assertEquals("Two", NotificationTestUtil.getExtraTitle(notifications.get (0).notification)); |
709 | 747 |
748 checkEngagementScore(6.5); | |
749 | |
710 // Close the last notification and verify that none remain. | 750 // Close the last notification and verify that none remain. |
711 notifications.get(0).notification.contentIntent.send(); | 751 notifications.get(0).notification.contentIntent.send(); |
712 waitForNotificationManagerMutation(); | 752 waitForNotificationManagerMutation(); |
713 assertTrue(getNotificationEntries().isEmpty()); | 753 assertTrue(getNotificationEntries().isEmpty()); |
754 | |
755 checkEngagementScore(7.5); | |
714 } | 756 } |
715 } | 757 } |
OLD | NEW |