| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Notifications: Property reflection in the "notificationclick" event.<
/title> | |
| 5 <script src="../resources/testharness.js"></script> | |
| 6 <script src="../resources/testharnessreport.js"></script> | |
| 7 <script src="../serviceworker/resources/test-helpers.js"></script> | |
| 8 <script src="resources/test-helpers.js"></script> | |
| 9 </head> | |
| 10 <body> | |
| 11 <script> | |
| 12 // Tests that the notification available in the "notificationclick" event
in the | |
| 13 // Service Worker accurately reflects the attributes with which the notifi
cation | |
| 14 // was created (for this test --) in the document. | |
| 15 | |
| 16 async_test(function(test) { | |
| 17 var scope = 'resources/scope/' + location.pathname, | |
| 18 script = 'resources/instrumentation-service-worker.js'; | |
| 19 | |
| 20 var options = { | |
| 21 title: scope, | |
| 22 dir: 'rtl', | |
| 23 lang: 'nl-NL', | |
| 24 body: 'Hello, world!', | |
| 25 tag: 'tag', | |
| 26 // FIXME: Relative URLs for the icon attribute currently get refle
cted as | |
| 27 // an absolute URL, which should probably be the given relative UR
L. | |
| 28 icon: 'https://example/icon.png', | |
| 29 vibrate: [100, 200, 300], | |
| 30 silent: false, | |
| 31 requireInteraction: true, | |
| 32 data: [ | |
| 33 { property: 'foobar', | |
| 34 string: '\uDFFF\u0000\uDBFF', | |
| 35 scalar: true }, | |
| 36 12.15 | |
| 37 ], | |
| 38 actions: [{ action: 'one', title: 'Action 1' }, | |
| 39 { action: 'two', title: 'Action 2' }, | |
| 40 { action: 'three', title: 'Action 3' }] | |
| 41 }; | |
| 42 | |
| 43 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | |
| 44 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | |
| 45 // (1) Tell the Service Worker to display a Web Notification. | |
| 46 workerInfo.port.postMessage({ | |
| 47 command: 'show', | |
| 48 | |
| 49 title: scope, | |
| 50 options: options | |
| 51 }); | |
| 52 | |
| 53 workerInfo.port.addEventListener('message', function(event) { | |
| 54 if (typeof event.data != 'object' || !event.data.command) { | |
| 55 assert_unreached('Invalid message from the Service Worker.
'); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 // (2) Listen for confirmation from the Service Worker that th
e | |
| 60 // notification's display promise has been resolved. | |
| 61 if (event.data.command == 'show') { | |
| 62 assert_true(event.data.success, 'The notification must hav
e been displayed.'); | |
| 63 testRunner.simulateWebNotificationClick(scope); | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 // (3) Listen for confirmation from the Service Worker that th
e | |
| 68 // notification has been clicked on. Make sure that all proper
ties | |
| 69 // set on the Notification object are as expected. | |
| 70 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | |
| 71 | |
| 72 options.actions = options.actions.slice(0, Notification.maxAct
ions); | |
| 73 Object.keys(options).forEach(function(key) { | |
| 74 if (typeof options[key] == 'object') | |
| 75 assert_object_equals(event.data.notification[key], opt
ions[key], 'The ' + key + ' field must be the same.'); | |
| 76 else | |
| 77 assert_equals(event.data.notification[key], options[ke
y], 'The ' + key + ' field must be the same.'); | |
| 78 }); | |
| 79 | |
| 80 test.done(); | |
| 81 }); | |
| 82 }).catch(unreached_rejection(test)); | |
| 83 | |
| 84 }, 'Clicking on a notification displayed by a Service Worker the notificat
ionclick event.'); | |
| 85 </script> | |
| 86 </body> | |
| 87 </html> | |
| OLD | NEW |