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 </head> | 8 </head> |
9 <body> | 9 <body> |
10 <script> | 10 <script> |
11 // Tests that the showNotification() function resolves a promise, and that the | 11 // Tests that the showNotification() function resolves a promise, that the |
12 // notificationclick event gets fired on the Service Worker when we simula te a | 12 // notificationclick event gets fired on the Service Worker when we simula te a |
13 // click on it. This test requires the test runner. | 13 // click on it, and the notification can then be closed. This test require s |
14 // the test runner. | |
14 async_test(function (test) { | 15 async_test(function (test) { |
15 var scope = 'resources/scope/service-worker-show-notification-click', | 16 var scope = 'resources/scope/service-worker-show-notification-close', |
16 worker_url = 'resources/click-forward-service-worker.js'; | 17 worker_url = 'resources/click-close-service-worker.js'; |
17 | 18 |
18 testRunner.grantWebNotificationPermission("http://127.0.0.1:8000", tru e); | 19 testRunner.grantWebNotificationPermission("http://127.0.0.1:8000", tru e); |
19 | 20 |
20 var registration = null, | 21 var registration = null, |
21 messagePort = null; | 22 messagePort = null; |
22 service_worker_unregister_and_register(test, worker_url, scope).then(f unction (swRegistration) { | 23 service_worker_unregister_and_register(test, worker_url, scope).then(f unction (swRegistration) { |
23 registration = swRegistration; | 24 registration = swRegistration; |
24 return wait_for_update(test, registration); | 25 return wait_for_update(test, registration); |
25 }).then(function (serviceWorker) { | 26 }).then(function (serviceWorker) { |
26 return wait_for_state(test, serviceWorker, 'activating'); | 27 return wait_for_state(test, serviceWorker, 'activating'); |
(...skipping 13 matching lines...) Expand all Loading... | |
40 }); | 41 }); |
41 }).then(function () { | 42 }).then(function () { |
42 assert_inherits(registration, 'showNotification', 'showNotificatio n() must be exposed.'); | 43 assert_inherits(registration, 'showNotification', 'showNotificatio n() must be exposed.'); |
43 | 44 |
44 return registration.showNotification(scope, { | 45 return registration.showNotification(scope, { |
45 body: 'Hello, world!', | 46 body: 'Hello, world!', |
46 icon: '/icon.png' | 47 icon: '/icon.png' |
47 }); | 48 }); |
48 }).then(function () { | 49 }).then(function () { |
49 messagePort.addEventListener('message', function(event) { | 50 messagePort.addEventListener('message', function(event) { |
50 assert_equals(event.data, 'The notification has been clicked o n.'); | 51 assert_equals(event.data, 'Clicked on Notificationx: ' + scope ); |
Michael van Ouwerkerk
2014/12/09 19:49:20
This is not the data sent, with "Notificationx".
Peter Beverloo
2014/12/10 14:11:09
Done.
| |
52 | |
53 // FIXME: The notification has now been closed by the Service Worker. In | |
54 // order to verify that this works correctly, we need to suppo rt the | |
55 // Notification.get() getter, which is not implemented yet. | |
56 | |
51 test.done(); | 57 test.done(); |
52 }); | 58 }); |
53 | 59 |
54 testRunner.simulateWebNotificationClick(scope); | 60 testRunner.simulateWebNotificationClick(scope); |
55 | 61 |
56 }).catch(unreached_rejection(test)); | 62 }).catch(unreached_rejection(test)); |
57 | 63 |
58 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event.'); | 64 }, 'Clicking on a notification displayed through showNotification() fires a Service Worker event, and can be closed there.'); |
59 </script> | 65 </script> |
60 </body> | 66 </body> |
61 </html> | 67 </html> |
OLD | NEW |