| 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 | |
| 25 'any data', // Check String type | 24 'any data', // Check String type |
| 26 new Array('Saab', 'Volvo', 'BMW'), // Check Array type | 25 new Array('Saab', 'Volvo', 'BMW'), // Check Array type |
| 27 { first: 'first', second: 'second' } // Check object | 26 { first: 'first', second: 'second' } // Check object |
| 28 ); | 27 ); |
| 29 | 28 |
| 30 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 29 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
| 31 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 30 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
| 32 // (1) Tell the Service Worker to display a Web Notification. | 31 // (1) Tell the Service Worker to display a Web Notification. |
| 33 var assertNotificationDataReflects = function(pos) { | 32 var assertNotificationDataReflects = function(pos) { |
| 34 workerInfo.port.postMessage({ | 33 workerInfo.port.postMessage({ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 return; | 56 return; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // (3) Listen for confirmation from the Service Worker that th
e | 59 // (3) Listen for confirmation from the Service Worker that th
e |
| 61 // notification has been clicked on. Make sure that all proper
ties | 60 // notification has been clicked on. Make sure that all proper
ties |
| 62 // set on the Notification object are as expected. | 61 // set on the Notification object are as expected. |
| 63 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | 62 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); |
| 64 | 63 |
| 65 var pos = event.data.notification.tag; | 64 var pos = event.data.notification.tag; |
| 66 | 65 |
| 67 assert_object_equals(event.data.notification.data, notificatio
nDataList[pos], 'The data field must be the same.'); | 66 if (typeof notificationDataList[pos] === 'object') |
| 67 assert_object_equals(event.data.notification.data, notific
ationDataList[pos], 'The data field must be the same.'); |
| 68 else |
| 69 assert_equals(event.data.notification.data, notificationDa
taList[pos], 'The data field must be the same.'); |
| 68 | 70 |
| 69 if (pos < notificationDataList.length) | 71 if (++pos < notificationDataList.length) |
| 70 assertNotificationDataReflects(++pos); | 72 assertNotificationDataReflects(pos); |
| 71 else | 73 else |
| 72 test.done(); | 74 test.done(); |
| 73 }); | 75 }); |
| 74 | 76 |
| 75 assertNotificationDataReflects(0); | 77 assertNotificationDataReflects(0); |
| 76 }).catch(unreached_rejection(test)); | 78 }).catch(unreached_rejection(test)); |
| 77 | 79 |
| 78 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); | 80 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); |
| 79 </script> | 81 </script> |
| 80 </body> | 82 </body> |
| 81 </html> | 83 </html> |
| OLD | NEW |