| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: data property reflection in the "notificationclick" ev
ent.</title> | 4 <title>Notifications: data property reflection in the "notificationclick" ev
ent.</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 notification available in the "notificationclick" event
in the | 12 // Tests that the notification available in the "notificationclick" event
in the |
| 13 // Service Worker accurately reflects the data attributes of several type | 13 // Service Worker accurately reflects the data attributes of several type |
| 14 // with which the notification was created (for this test --) in the docum
ent. | 14 // with which the notification was created (for this test --) in the docum
ent. |
| 15 | 15 |
| 16 async_test(function(test) { | 16 async_test(function(test) { |
| 17 var scope = 'resources/scope/' + location.pathname, | 17 var scope = 'resources/scope/' + location.pathname, |
| 18 script = 'resources/instrumentation-service-worker.js'; | 18 script = 'resources/instrumentation-service-worker.js'; |
| 19 | 19 |
| 20 // Set notification's data of several type to a structured clone of op
tions's data. | 20 // Set notification's data of several type to a structured clone of op
tions's data. |
| 21 var notificationDataList = new Array( | 21 var notificationDataList = new Array( |
| 22 true, // Check Boolean type | 22 true, // Check Boolean type |
| 23 1024, // Check Number type | 23 1024, // Check Number type |
| 24 Number.NaN, // Check Number.NaN type |
| 24 'any data', // Check String type | 25 'any data', // Check String type |
| 26 null, // Check null |
| 25 new Array('Saab', 'Volvo', 'BMW'), // Check Array type | 27 new Array('Saab', 'Volvo', 'BMW'), // Check Array type |
| 26 { first: 'first', second: 'second' } // Check object | 28 { first: 'first', second: 'second' } // Check object |
| 27 ); | 29 ); |
| 28 | 30 |
| 29 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 31 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
| 30 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 32 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 31 // (1) Tell the Service Worker to display a Web Notification. | 33 // (1) Tell the Service Worker to display a Web Notification. |
| 32 var assertNotificationDataReflects = function(pos) { | 34 var assertNotificationDataReflects = function(pos) { |
| 33 workerInfo.port.postMessage({ | 35 workerInfo.port.postMessage({ |
| 34 command: 'show', | 36 command: 'show', |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 return; | 58 return; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // (3) Listen for confirmation from the Service Worker that th
e | 61 // (3) Listen for confirmation from the Service Worker that th
e |
| 60 // notification has been clicked on. Make sure that all proper
ties | 62 // notification has been clicked on. Make sure that all proper
ties |
| 61 // set on the Notification object are as expected. | 63 // set on the Notification object are as expected. |
| 62 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | 64 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); |
| 63 | 65 |
| 64 var pos = event.data.notification.tag; | 66 var pos = event.data.notification.tag; |
| 65 | 67 |
| 66 if (typeof notificationDataList[pos] === 'object') | 68 if (typeof notificationDataList[pos] === 'object' && notificat
ionDataList[pos] !== null) |
| 67 assert_object_equals(event.data.notification.data, notific
ationDataList[pos], 'The data field must be the same.'); | 69 assert_object_equals(event.data.notification.data, notific
ationDataList[pos], 'The data field must be the same.'); |
| 68 else | 70 else |
| 69 assert_equals(event.data.notification.data, notificationDa
taList[pos], 'The data field must be the same.'); | 71 assert_equals(event.data.notification.data, notificationDa
taList[pos], 'The data field must be the same.'); |
| 70 | 72 |
| 71 if (++pos < notificationDataList.length) | 73 if (++pos < notificationDataList.length) |
| 72 assertNotificationDataReflects(pos); | 74 assertNotificationDataReflects(pos); |
| 73 else | 75 else |
| 74 test.done(); | 76 test.done(); |
| 75 }); | 77 }); |
| 76 | 78 |
| 77 assertNotificationDataReflects(0); | 79 assertNotificationDataReflects(0); |
| 78 }).catch(unreached_rejection(test)); | 80 }).catch(unreached_rejection(test)); |
| 79 | 81 |
| 80 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); | 82 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); |
| 81 </script> | 83 </script> |
| 82 </body> | 84 </body> |
| 83 </html> | 85 </html> |
| OLD | NEW |