OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Notifications: Property reflection in the "notificationclick" event.<
/title> | 4 <title>Notifications: Property reflection in the "notificationclick" event.<
/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 attributes with which the notifi
cation | 13 // Service Worker accurately reflects the attributes with which the notifi
cation |
14 // was created (for this test --) in the document. | 14 // was created (for this test --) in the document. |
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 var options = { | 20 var options = { |
21 title: scope, | 21 title: scope, |
22 dir: 'rtl', | 22 dir: 'rtl', |
23 lang: 'nl-NL', | 23 lang: 'nl-NL', |
24 body: 'Hello, world!', | 24 body: 'Hello, world!', |
25 tag: 'tag', | 25 tag: 'tag', |
26 // FIXME: Relative URLs for the icon attribute currently get refle
cted as | 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. | 27 // an absolute URL, which should probably be the given relative UR
L. |
28 icon: 'https://example/icon.png', | 28 icon: 'https://example/icon.png', |
29 silent: true | 29 silent: true, |
| 30 data: [ |
| 31 { property: 'foobar', |
| 32 string: '\uDFFF\u0000\uDBFF', |
| 33 scalar: true }, |
| 34 12.15 |
| 35 ] |
30 }; | 36 }; |
31 | 37 |
32 testRunner.grantWebNotificationPermission(location.origin, true); | 38 testRunner.grantWebNotificationPermission(location.origin, true); |
33 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { | 39 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(workerInfo) { |
34 // (1) Tell the Service Worker to display a Web Notification. | 40 // (1) Tell the Service Worker to display a Web Notification. |
35 workerInfo.port.postMessage({ | 41 workerInfo.port.postMessage({ |
36 command: 'show', | 42 command: 'show', |
37 | 43 |
38 title: scope, | 44 title: scope, |
39 options: options | 45 options: options |
(...skipping 12 matching lines...) Expand all Loading... |
52 testRunner.simulateWebNotificationClick(scope); | 58 testRunner.simulateWebNotificationClick(scope); |
53 return; | 59 return; |
54 } | 60 } |
55 | 61 |
56 // (3) Listen for confirmation from the Service Worker that th
e | 62 // (3) Listen for confirmation from the Service Worker that th
e |
57 // notification has been clicked on. Make sure that all proper
ties | 63 // notification has been clicked on. Make sure that all proper
ties |
58 // set on the Notification object are as expected. | 64 // set on the Notification object are as expected. |
59 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | 65 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); |
60 | 66 |
61 Object.keys(options).forEach(function(key) { | 67 Object.keys(options).forEach(function(key) { |
| 68 if (key == 'data') |
| 69 return; // Check "data" separately to avoid stringify
ing it. |
| 70 |
62 assert_equals(event.data.notification[key], options[key],
'The ' + key + ' field must be the same.'); | 71 assert_equals(event.data.notification[key], options[key],
'The ' + key + ' field must be the same.'); |
63 }); | 72 }); |
64 | 73 |
| 74 assert_object_equals(event.data.notification.data, options.dat
a, 'The data field must be the same.'); |
| 75 |
65 test.done(); | 76 test.done(); |
66 }); | 77 }); |
67 }).catch(unreached_rejection(test)); | 78 }).catch(unreached_rejection(test)); |
68 | 79 |
69 }, '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.'); |
70 </script> | 81 </script> |
71 </body> | 82 </body> |
72 </html> | 83 </html> |
OLD | NEW |