| 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/permissions-helper.js"></script> |
| 5 <script src="../resources/testharness.js"></script> | 6 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharnessreport.js"></script> | 7 <script src="../resources/testharnessreport.js"></script> |
| 7 <script src="../serviceworker/resources/test-helpers.js"></script> | 8 <script src="../serviceworker/resources/test-helpers.js"></script> |
| 9 <script src="resources/notification-data-reflection-test.js"></script> |
| 8 <script src="resources/test-helpers.js"></script> | 10 <script src="resources/test-helpers.js"></script> |
| 9 </head> | 11 </head> |
| 10 <body> | 12 <body> |
| 11 <script> | 13 <script> |
| 12 // Tests that the notification available in the "notificationclick" event
in the | 14 // Tests that the notification available in the "notificationclick" event
in the |
| 13 // Service Worker accurately reflects the data attributes of several type | 15 // Service Worker accurately reflects the data attributes of several type |
| 14 // with which the notification was created (for this test --) in the docum
ent. | 16 // with which the notification was created (for this test --) in the docum
ent. |
| 15 | 17 |
| 16 async_test(function(test) { | 18 async_test(function(test) { |
| 17 var scope = 'resources/scope/' + location.pathname, | 19 runNotificationDataReflectionTest(test, { |
| 18 script = 'resources/instrumentation-service-worker.js'; | 20 run: function (scope) { |
| 19 | 21 testRunner.simulateWebNotificationClick(scope, -1 /* action_in
dex */); |
| 20 // Set notification's data of several type to a structured clone of op
tions's data. | 22 }, |
| 21 var notificationDataList = new Array( | 23 name: 'click' |
| 22 true, // Check Boolean type | 24 }); |
| 23 1024, // Check Number type | |
| 24 Number.NaN, // Check Number.NaN type | |
| 25 'any data', // Check String type | |
| 26 null, // Check null | |
| 27 new Array('Saab', 'Volvo', 'BMW'), // Check Array type | |
| 28 { first: 'first', second: 'second' } // Check object | |
| 29 ); | |
| 30 | |
| 31 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | |
| 32 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | |
| 33 // (1) Tell the Service Worker to display a Web Notification. | |
| 34 var assertNotificationDataReflects = function(pos) { | |
| 35 workerInfo.port.postMessage({ | |
| 36 command: 'show', | |
| 37 | |
| 38 title: scope, | |
| 39 options: { | |
| 40 title: scope, | |
| 41 tag: pos, | |
| 42 data: notificationDataList[pos] | |
| 43 } | |
| 44 }); | |
| 45 }; | |
| 46 | |
| 47 workerInfo.port.addEventListener('message', function(event) { | |
| 48 if (typeof event.data != 'object' || !event.data.command) { | |
| 49 assert_unreached('Invalid message from the Service Worker.
'); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 // (2) Listen for confirmation from the Service Worker that th
e | |
| 54 // notification's display promise has been resolved. | |
| 55 if (event.data.command == 'show') { | |
| 56 assert_true(event.data.success, 'The notification must hav
e been displayed.'); | |
| 57 testRunner.simulateWebNotificationClick(scope, -1 /* actio
n_index */); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 // (3) Listen for confirmation from the Service Worker that th
e | |
| 62 // notification has been clicked on. Make sure that all proper
ties | |
| 63 // set on the Notification object are as expected. | |
| 64 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | |
| 65 | |
| 66 var pos = event.data.notification.tag; | |
| 67 | |
| 68 if (typeof notificationDataList[pos] === 'object' && notificat
ionDataList[pos] !== null) | |
| 69 assert_object_equals(event.data.notification.data, notific
ationDataList[pos], 'The data field must be the same.'); | |
| 70 else | |
| 71 assert_equals(event.data.notification.data, notificationDa
taList[pos], 'The data field must be the same.'); | |
| 72 | |
| 73 if (++pos < notificationDataList.length) | |
| 74 assertNotificationDataReflects(pos); | |
| 75 else | |
| 76 test.done(); | |
| 77 }); | |
| 78 | |
| 79 assertNotificationDataReflects(0); | |
| 80 }).catch(unreached_rejection(test)); | |
| 81 | |
| 82 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); | 25 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); |
| 83 </script> | 26 </script> |
| 84 </body> | 27 </body> |
| 85 </html> | 28 </html> |
| OLD | NEW |