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 <script src="resources/test-helpers.js"></script> |
| 9 </head> |
| 10 <body> |
| 11 <script> |
| 12 // Tests that the showNotification() function when used in a Service Worke
r |
| 13 // rejects when no permission has been granted. This test requires the tes
t runner. |
| 14 |
| 15 async_test(function(test) { |
| 16 var scope = 'resources/scope/serviceworkerregistration-service-worker-
click', |
| 17 script = 'resources/instrumentation-service-worker.js'; |
| 18 |
| 19 testRunner.grantWebNotificationPermission(location.origin, false); |
| 20 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 21 // (1) Tell the Service Worker to display a Web Notification. |
| 22 workerInfo.port.postMessage({ |
| 23 command: 'show', |
| 24 |
| 25 title: 'My Notification', |
| 26 options: { body: 'Hello, world!' } |
| 27 }); |
| 28 |
| 29 workerInfo.port.addEventListener('message', function(event) { |
| 30 if (typeof event.data != 'object' || !event.data.command) { |
| 31 assert_unreached('Invalid message from the Service Worker.
'); |
| 32 return; |
| 33 } |
| 34 |
| 35 // (2) Listen for confirmation from the Service Worker that th
e |
| 36 // notification could not be displayed because of a permission
error. |
| 37 assert_equals(event.data.command, 'show'); |
| 38 |
| 39 assert_false(event.data.success); |
| 40 assert_equals(event.data.message, 'No notification permission
has been granted for this origin.'); |
| 41 |
| 42 test.done(); |
| 43 }); |
| 44 }).catch(unreached_rejection(test)); |
| 45 |
| 46 }, 'showNotification() must reject if no Web Notification permission has b
een granted.'); |
| 47 </script> |
| 48 </body> |
| 49 </html> |
OLD | NEW |