OLD | NEW |
(Empty) | |
| 1 // Tests that the notification available after the given operation is executed |
| 2 // accurately reflects the data attributes of several types with which the |
| 3 // notification was created in the document. |
| 4 function runNotificationDataReflectionTest(test, notificationOperation) { |
| 5 var scope = 'resources/scope/' + location.pathname, |
| 6 script = 'resources/instrumentation-service-worker.js'; |
| 7 |
| 8 // Set notification's data of several types to a structured clone of options
's data. |
| 9 var notificationDataList = new Array( |
| 10 true, // Check Boolean type |
| 11 1024, // Check Number type |
| 12 Number.NaN, // Check Number.NaN type |
| 13 'any data', // Check String type |
| 14 null, // Check null |
| 15 new Array('Saab', 'Volvo', 'BMW'), // Check Array type |
| 16 { first: 'first', second: 'second' } // Check object |
| 17 ); |
| 18 |
| 19 PermissionsHelper.setPermission('notifications', 'granted').then(function()
{ |
| 20 getActiveServiceWorkerWithMessagePort(test, script, scope).then(function
(workerInfo) { |
| 21 // (1) Tell the Service Worker to display a Web Notification. |
| 22 var assertNotificationDataReflects = function(pos) { |
| 23 workerInfo.port.postMessage({ |
| 24 command: 'show', |
| 25 |
| 26 title: scope, |
| 27 options: { |
| 28 title: scope, |
| 29 tag: pos, |
| 30 data: notificationDataList[pos] |
| 31 } |
| 32 }); |
| 33 }; |
| 34 |
| 35 workerInfo.port.addEventListener('message', function(event) { |
| 36 if (typeof event.data != 'object' || !event.data.command) { |
| 37 assert_unreached('Invalid message from the Service Worker.')
; |
| 38 return; |
| 39 } |
| 40 |
| 41 // (2) Listen for confirmation from the Service Worker that the |
| 42 // notification's display promise has been resolved. |
| 43 if (event.data.command == 'show') { |
| 44 assert_true(event.data.success, 'The notification must have
been displayed.'); |
| 45 notificationOperation.run(scope); |
| 46 return; |
| 47 } |
| 48 |
| 49 // (3) Listen for confirmation from the Service Worker that the |
| 50 // notification has been closed. Make sure that all properties |
| 51 // set on the Notification object are as expected. |
| 52 assert_equals(event.data.command, notificationOperation.name, 'N
otification was expected to receive different operation'); |
| 53 |
| 54 var pos = event.data.notification.tag; |
| 55 |
| 56 if (typeof notificationDataList[pos] === 'object' && notificatio
nDataList[pos] !== null) |
| 57 assert_object_equals(event.data.notification.data, notificat
ionDataList[pos], 'The data field must be the same.'); |
| 58 else |
| 59 assert_equals(event.data.notification.data, notificationData
List[pos], 'The data field must be the same.'); |
| 60 |
| 61 if (++pos < notificationDataList.length) |
| 62 assertNotificationDataReflects(pos); |
| 63 else |
| 64 test.done(); |
| 65 }); |
| 66 |
| 67 assertNotificationDataReflects(0); |
| 68 }).catch(unreached_rejection(test)); |
| 69 }); |
| 70 } |
OLD | NEW |