| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: ServiceWorkerRegistration.getNotifications() within a
Service Worker with a filter.</title> | 4 <title>Notifications: ServiceWorkerRegistration.getNotifications() within a
Service Worker with a filter.</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 Service Worke
r | 12 // Tests that the getNotifications() function when used in a Service Worke
r |
| 13 // return an array of the notifications which were previously displayed us
ing | 13 // return an array of the notifications which were previously displayed us
ing |
| 14 // the same Service Worker registration id. | 14 // the same Service Worker registration id. |
| 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 script = 'instrumentation-service-worker.js'; |
| 18 | 18 |
| 19 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 19 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
| 20 | 20 |
| 21 var info = null; | 21 var info = null; |
| 22 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 22 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 23 info = workerInfo; | 23 info = workerInfo; |
| 24 | 24 |
| 25 // (1) Display two notifications in the Document. | 25 // (1) Display two notifications in the Document. |
| 26 return info.registration.showNotification('Hello, world!', { | 26 return info.registration.showNotification('Hello, world!', { |
| 27 body: 'First notification', | 27 body: 'First notification', |
| 28 tag: 'banana', | 28 tag: 'banana', |
| 29 }); | 29 }); |
| 30 }).then(function() { | 30 }).then(function() { |
| 31 return info.registration.showNotification('Hello again, world!', { | 31 return info.registration.showNotification('Hello again, world!', { |
| 32 body: 'Second notification', | 32 body: 'Second notification', |
| 33 tag: 'strawberry', | 33 tag: 'strawberry', |
| 34 }); | 34 }); |
| 35 }).then(function() { | 35 }).then(function() { |
| 36 // (2) Request the Service Worker to give us all notifications. | 36 // (2) Request the Service Worker to give us a filtered list of no
tifications. |
| 37 info.port.postMessage({ | 37 return sendCommand(info.port, { |
| 38 command: 'get', | 38 command: 'get', |
| 39 filter: { | 39 filter: { |
| 40 tag: 'strawberry', | 40 tag: 'strawberry', |
| 41 } | 41 } |
| 42 }); | 42 }); |
| 43 }).then(function(data) { |
| 44 // (3) Confirm that the Service Worker was able to get the one mat
ching notification. |
| 45 assert_true(data.success); |
| 43 | 46 |
| 44 info.port.addEventListener('message', function(event) { | 47 var notifications = data.notifications; |
| 45 if (typeof event.data != 'object' || !event.data.command) { | |
| 46 assert_unreached('Invalid message from the Service Worker.
'); | |
| 47 return; | |
| 48 } | |
| 49 | 48 |
| 50 // (3) Confirm that the Service Worker was able to read both o
f them. | 49 assert_equals(notifications.length, 1); |
| 51 assert_equals(event.data.command, 'get'); | |
| 52 assert_true(event.data.success); | |
| 53 | 50 |
| 54 var notifications = event.data.notifications; | 51 assert_equals(notifications[0].title, 'Hello again, world!'); |
| 52 assert_equals(notifications[0].body, 'Second notification'); |
| 55 | 53 |
| 56 assert_equals(notifications.length, 1); | 54 test.done(); |
| 57 | |
| 58 assert_equals(notifications[0].title, 'Hello again, world!'); | |
| 59 assert_equals(notifications[0].body, 'Second notification'); | |
| 60 | |
| 61 test.done(); | |
| 62 }); | |
| 63 }).catch(unreached_rejection(test)); | 55 }).catch(unreached_rejection(test)); |
| 64 | 56 |
| 65 }, 'ServiceWorkerRegistration.getNotifications() returns the opened notifi
cations within a Service Worker with a filter.'); | 57 }, 'ServiceWorkerRegistration.getNotifications() returns the opened notifi
cations within a Service Worker with a filter.'); |
| 66 </script> | 58 </script> |
| 67 </body> | 59 </body> |
| 68 </html> | 60 </html> |
| OLD | NEW |