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 workerUrl = 'resources/click-forward-service-worker.js'; | 17 workerUrl = 'resources/click-close-service-worker.js'; |
17 | 18 |
18 testRunner.grantWebNotificationPermission(location.origin, true); | 19 testRunner.grantWebNotificationPermission(location.origin, true); |
19 | 20 |
20 var registration = null, | 21 var registration = null, |
21 messagePort = null; | 22 messagePort = null; |
22 service_worker_unregister_and_register(test, workerUrl, scope).then(fu
nction (swRegistration) { | 23 service_worker_unregister_and_register(test, workerUrl, scope).then(fu
nction (swRegistration) { |
23 registration = swRegistration; | 24 registration = swRegistration; |
24 return wait_for_state(test, registration.installing, 'activated'); | 25 return wait_for_state(test, registration.installing, 'activated'); |
25 }).then(function () { | 26 }).then(function () { |
26 assert_not_equals(registration.active, null, 'The Service Worker n
eeds to be activated.'); | 27 assert_not_equals(registration.active, null, 'The Service Worker n
eeds to be activated.'); |
(...skipping 10 matching lines...) Expand all Loading... |
37 messagePort.start(); | 38 messagePort.start(); |
38 }); | 39 }); |
39 }).then(function () { | 40 }).then(function () { |
40 assert_inherits(registration, 'showNotification', 'showNotificatio
n() must be exposed.'); | 41 assert_inherits(registration, 'showNotification', 'showNotificatio
n() must be exposed.'); |
41 return registration.showNotification(scope, { | 42 return registration.showNotification(scope, { |
42 body: 'Hello, world!', | 43 body: 'Hello, world!', |
43 icon: '/icon.png' | 44 icon: '/icon.png' |
44 }); | 45 }); |
45 }).then(function () { | 46 }).then(function () { |
46 messagePort.addEventListener('message', function(event) { | 47 messagePort.addEventListener('message', function(event) { |
47 assert_equals(event.data, 'The notification has been clicked o
n.'); | 48 assert_equals(event.data, 'Clicked on Notification: ' + scope)
; |
48 test.done(); | 49 |
| 50 // FIXME: The notification has now been closed by the Service
Worker. In |
| 51 // order to verify that this works correctly, we need to suppo
rt the |
| 52 // Notification.get() getter, which is not implemented yet. |
| 53 |
| 54 service_worker_unregister_and_done(test, scope); |
49 }); | 55 }); |
50 | 56 |
51 testRunner.simulateWebNotificationClick(scope); | 57 testRunner.simulateWebNotificationClick(scope); |
52 | 58 |
53 }).catch(unreached_rejection(test)); | 59 }).catch(unreached_rejection(test)); |
54 | 60 |
55 }, 'Clicking on a notification displayed through showNotification() fires
a Service Worker event.'); | 61 }, 'Clicking on a notification displayed through showNotification() fires
a Service Worker event, and can be closed there.'); |
56 </script> | 62 </script> |
57 </body> | 63 </body> |
58 </html> | 64 </html> |
OLD | NEW |