| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: ServiceWorkerRegistration.getNotifications() when crea
ted by the Service Worker.</title> | 4 <title>Notifications: ServiceWorkerRegistration.getNotifications() when crea
ted by the Service Worker.</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 getNotifications() function when used in a document retu
rns | 12 // Tests that the getNotifications() function when used in a document retu
rns |
| 13 // an array of the notifications which were previously displayed by the | 13 // an array of the notifications which were previously displayed by the |
| 14 // Service Worker. | 14 // Service Worker. |
| 15 async_test(function(test) { | 15 async_test(function(test) { |
| 16 var scope = 'resources/scope/' + location.pathname, | 16 var scope = 'resources/scope/' + location.pathname; |
| 17 script = 'resources/instrumentation-service-worker.js'; | 17 var script = 'instrumentation-service-worker.js'; |
| 18 var port; |
| 19 var registration; |
| 18 | 20 |
| 19 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 21 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
| 20 | 22 |
| 21 var info = null; | 23 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(info) { |
| 22 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 24 port = info.port; |
| 23 info = workerInfo; | 25 registration = info.registration; |
| 24 | 26 |
| 25 // (1) Tell the Service Worker to display a new Notification and w
ait for it | 27 // (1) Tell the Service Worker to display a new Notification and w
ait for it |
| 26 // to have been displayed to the user. | 28 // to have been displayed to the user. |
| 27 info.port.postMessage({ | 29 return sendCommand(port, { |
| 28 command: 'show', | 30 command: 'show', |
| 29 | 31 |
| 30 title: scope, | 32 title: scope, |
| 31 options: { body: 'Hello, world!' } | 33 options: { body: 'Hello, world!' } |
| 32 }); | 34 }); |
| 33 | 35 }).then(function(data) { |
| 34 return new Promise(function(resolve) { | 36 assert_true(data.success); |
| 35 info.port.addEventListener('message', function(event) { | |
| 36 if (typeof event.data != 'object' || !event.data.command)
{ | |
| 37 assert_unreached('Invalid message from the Service Wor
ker.'); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 assert_equals(event.data.command, 'show'); | |
| 42 resolve(); | |
| 43 }); | |
| 44 }); | |
| 45 }).then(function() { | |
| 46 // (2) Get a list of all notifications in the document. | 37 // (2) Get a list of all notifications in the document. |
| 47 return info.registration.getNotifications(); | 38 return registration.getNotifications(); |
| 48 }).then(function(notifications) { | 39 }).then(function(notifications) { |
| 49 // (3) Verify that there's only one notification: the one we just
showed. | 40 // (3) Verify that there's only one notification: the one we just
showed. |
| 50 assert_equals(notifications.length, 1); | 41 assert_equals(notifications.length, 1); |
| 51 | 42 |
| 52 assert_equals(notifications[0].title, scope); | 43 assert_equals(notifications[0].title, scope); |
| 53 assert_equals(notifications[0].body, 'Hello, world!'); | 44 assert_equals(notifications[0].body, 'Hello, world!'); |
| 54 | 45 |
| 55 test.done(); | 46 test.done(); |
| 56 | 47 |
| 57 }).catch(unreached_rejection(test)); | 48 }).catch(unreached_rejection(test)); |
| 58 | 49 |
| 59 }, 'ServiceWorkerRegistration.getNotifications() when created by a Service
Worker.'); | 50 }, 'ServiceWorkerRegistration.getNotifications() when created by a Service
Worker.'); |
| 60 </script> | 51 </script> |
| 61 </body> | 52 </body> |
| 62 </html> | 53 </html> |
| OLD | NEW |