| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Notifications: ServiceWorkerRegistration.showNotification().</title> | |
| 5 <script src="../resources/testharness.js"></script> | |
| 6 <script src="../resources/testharnessreport.js"></script> | |
| 7 <script src="../serviceworker/resources/test-helpers.js"></script> | |
| 8 </head> | |
| 9 <body> | |
| 10 <script> | |
| 11 // Tests that the showNotification() function resolves a promise, and that
the | |
| 12 // notificationclick event gets fired on the Service Worker when we simula
te a | |
| 13 // click on it. This test requires the test runner. | |
| 14 | |
| 15 async_test(function (test) { | |
| 16 var scope = 'resources/scope/service-worker-show-notification-click', | |
| 17 workerUrl = 'resources/click-forward-service-worker.js'; | |
| 18 | |
| 19 testRunner.grantWebNotificationPermission(location.origin, true); | |
| 20 | |
| 21 var registration = null, | |
| 22 messagePort = null; | |
| 23 service_worker_unregister_and_register(test, workerUrl, scope).then(fu
nction (swRegistration) { | |
| 24 registration = swRegistration; | |
| 25 return wait_for_state(test, registration.installing, 'activated'); | |
| 26 }).then(function () { | |
| 27 assert_not_equals(registration.active, null, 'The Service Worker n
eeds to be activated.'); | |
| 28 return new Promise(function (resolve) { | |
| 29 var messageChannel = new MessageChannel(); | |
| 30 messageChannel.port1.addEventListener('message', function(even
t) { | |
| 31 if (event.data == 'ready') | |
| 32 resolve(); | |
| 33 }); | |
| 34 | |
| 35 registration.active.postMessage(messageChannel.port2, [message
Channel.port2]); | |
| 36 | |
| 37 messagePort = messageChannel.port1; | |
| 38 messagePort.start(); | |
| 39 }); | |
| 40 }).then(function () { | |
| 41 assert_inherits(registration, 'showNotification', 'showNotificatio
n() must be exposed.'); | |
| 42 return registration.showNotification(scope, { | |
| 43 body: 'Hello, world!', | |
| 44 icon: '/icon.png' | |
| 45 }); | |
| 46 }).then(function () { | |
| 47 messagePort.addEventListener('message', function(event) { | |
| 48 assert_equals(event.data, 'Clicked on Notification: ' + scope)
; | |
| 49 service_worker_unregister_and_done(test, scope); | |
| 50 }); | |
| 51 | |
| 52 testRunner.simulateWebNotificationClick(scope); | |
| 53 | |
| 54 }).catch(unreached_rejection(test)); | |
| 55 | |
| 56 }, 'Clicking on a notification displayed through showNotification() fires
a Service Worker event.'); | |
| 57 </script> | |
| 58 </body> | |
| 59 </html> | |
| OLD | NEW |