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 is exposed on the ServiceWor
kerRegistration | 11 // Tests that the showNotification() function rejects the returned promise
with a |
12 // object. As of right now, this is only exposed in documents. | 12 // TypeError when the Service Worker is not activated yet. |
13 async_test(function (test) { | 13 async_test(function (test) { |
14 var scope = 'resources/scope/serviceworkerregistration-show-notificati
on', | 14 var scope = 'resources/scope/service-worker-show-notification-not-acti
vated', |
15 worker_url = 'resources/empty-worker.js'; | 15 worker_url = 'resources/empty-worker.js'; |
16 | 16 |
| 17 if (window.testRunner) |
| 18 testRunner.grantWebNotificationPermission("http://127.0.0.1:8000",
false); |
| 19 |
17 service_worker_unregister_and_register(test, worker_url, scope).then(f
unction (registration) { | 20 service_worker_unregister_and_register(test, worker_url, scope).then(f
unction (registration) { |
18 assert_inherits(registration, 'showNotification', 'showNotificatio
n() must be exposed.'); | 21 assert_inherits(registration, 'showNotification', 'showNotificatio
n() must be exposed.'); |
19 registration.showNotification('Title', { | 22 registration.showNotification('Title', { |
20 body: 'Hello, world!', | 23 body: 'Hello, world!', |
21 icon: '/icon.png' | 24 icon: '/icon.png' |
22 }).then(function() { | 25 }).then(function() { |
23 assert_unreached('showNotification() is expected to reject.'); | 26 assert_unreached('showNotification() is expected to reject.'); |
24 }).catch(test.step_func_done()); | 27 }).catch(function(error) { |
| 28 assert_equals(error.name, 'TypeError'); |
| 29 assert_equals(error.message, 'No active registration available
on the ServiceWorkerRegistration.'); |
| 30 test.done(); |
| 31 }); |
25 | 32 |
26 }).catch(unreached_rejection(test)); | 33 }).catch(unreached_rejection(test)); |
27 | 34 |
28 }, 'showNotification() must be exposed on the Document-based ServiceWorker
Registration.'); | 35 }, 'showNotification() must reject if there is no active registration on t
he ServiceWorkerRegistration.'); |
| 36 |
29 </script> | 37 </script> |
30 </body> | 38 </body> |
31 </html> | 39 </html> |
OLD | NEW |