OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Notifications: ServiceWorkerRegistration.showNotification().</title> | 4 <title>Notifications: ServiceWorkerRegistration.showNotification().</title> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
7 <script src="../serviceworker/resources/test-helpers.js"></script> | 7 <script src="../serviceworker/resources/test-helpers.js"></script> |
8 <script src="resources/test-helpers.js"></script> | 8 <script src="resources/test-helpers.js"></script> |
9 </head> | 9 </head> |
10 <body> | 10 <body> |
11 <script> | 11 <script> |
12 // Tests that the showNotification() function when used in a Service Worke
r | 12 // Tests that the showNotification() function when used in a Service Worke
r |
13 // resolves a promise, and that the notificationclick event gets fired whe
n | 13 // resolves a promise, and that the notificationclick event gets fired whe
n |
14 // we simulate a click on it. This test requires the test runner. | 14 // we simulate a click on it. This test requires the test runner. |
15 | 15 |
16 async_test(function(test) { | 16 async_test(function(test) { |
17 var scope = 'resources/scope/serviceworkerregistration-service-worker-
click', | 17 var scope = 'resources/scope/serviceworkerregistration-service-worker-
click', |
18 script = 'resources/instrumentation-service-worker.js'; | 18 script = 'resources/instrumentation-service-worker.js'; |
19 | 19 |
20 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 20 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
21 testRunner.grantWebNotificationPermission(location.origin, true); | |
22 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 21 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
23 // (1) Tell the Service Worker to display a Web Notification. | 22 // (1) Tell the Service Worker to display a Web Notification. |
24 workerInfo.port.postMessage({ | 23 workerInfo.port.postMessage({ |
25 command: 'show', | 24 command: 'show', |
26 | 25 |
27 title: scope, | 26 title: scope, |
28 options: { body: 'Hello, world!' } | 27 options: { body: 'Hello, world!' } |
29 }); | 28 }); |
30 | 29 |
31 workerInfo.port.addEventListener('message', function(event) { | 30 workerInfo.port.addEventListener('message', function(event) { |
(...skipping 20 matching lines...) Expand all Loading... |
52 } | 51 } |
53 | 52 |
54 assert_unreached('Unexpected message from the Service Worker:
' + event.data.command); | 53 assert_unreached('Unexpected message from the Service Worker:
' + event.data.command); |
55 }); | 54 }); |
56 }).catch(unreached_rejection(test)); | 55 }).catch(unreached_rejection(test)); |
57 | 56 |
58 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); | 57 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); |
59 </script> | 58 </script> |
60 </body> | 59 </body> |
61 </html> | 60 </html> |
OLD | NEW |