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 a nd SWR.getNotifications().</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 object in a) the "notificationclick" event in the |
13 // Service Worker accurately reflects the attributes with which the notifi cation | 13 // Service Worker, and b) ServiceWorkerRegistration.getNotifications(), bo th |
14 // was created (for this test --) in the document. | 14 // accurately reflect the attributes with which the notification was creat ed. |
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!', |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 // (2) Listen for confirmation from the Service Worker that th e | 59 // (2) Listen for confirmation from the Service Worker that th e |
60 // notification's display promise has been resolved. | 60 // notification's display promise has been resolved. |
61 if (event.data.command == 'show') { | 61 if (event.data.command == 'show') { |
62 assert_true(event.data.success, 'The notification must hav e been displayed.'); | 62 assert_true(event.data.success, 'The notification must hav e been displayed.'); |
63 testRunner.simulateWebNotificationClick(scope); | 63 testRunner.simulateWebNotificationClick(scope); |
64 return; | 64 return; |
65 } | 65 } |
66 | 66 |
67 // (3) Listen for confirmation from the Service Worker that th e | 67 // (3) Listen for confirmation from the Service Worker that th e |
68 // notification has been clicked on. Make sure that all proper ties | 68 // notification has been clicked on. Make sure that all proper ties |
69 // set on the Notification object are as expected. | 69 // set on the (cloned) Notification object are as expected. |
Peter Beverloo
2015/10/21 13:29:00
no need for parenthesis
johnme
2015/10/21 14:21:18
Done.
| |
70 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); | 70 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); |
71 | 71 |
72 options.actions = options.actions.slice(0, Notification.maxAct ions); | 72 options.actions = options.actions.slice(0, Notification.maxAct ions); |
73 Object.keys(options).forEach(function(key) { | 73 Object.keys(options).forEach(function(key) { |
74 if (typeof options[key] == 'object') | 74 if (typeof options[key] == 'object') |
75 assert_object_equals(event.data.notification[key], opt ions[key], 'The ' + key + ' field must be the same.'); | 75 assert_object_equals(event.data.notification[key], opt ions[key], 'The ' + key + ' field must be the same in notificationclick events.' ); |
76 else | 76 else |
77 assert_equals(event.data.notification[key], options[ke y], 'The ' + key + ' field must be the same.'); | 77 assert_equals(event.data.notification[key], options[ke y], 'The ' + key + ' field must be the same in notificationclick events.'); |
78 }); | 78 }); |
79 | 79 |
80 test.done(); | 80 // (4) Check that the properties are also set correctly on the |
81 // (non-cloned) Notification object from getNotifications. | |
Peter Beverloo
2015/10/21 13:29:00
no need for parenthesis
johnme
2015/10/21 14:21:18
Done.
| |
82 workerInfo.registration.getNotifications().then(function(notif ications) { | |
83 assert_equals(notifications.length, 1); | |
84 | |
85 Object.keys(options).forEach(function(key) { | |
Peter Beverloo
2015/10/21 13:29:00
Can we extract this to a function w/ an argument t
johnme
2015/10/21 14:21:18
Done.
| |
86 if (typeof options[key] == 'object') | |
87 assert_object_equals(notifications[0][key], option s[key], 'The ' + key + ' field must be the same in getNotifications.'); | |
88 else | |
89 assert_equals(notifications[0][key], options[key], 'The ' + key + ' field must be the same in getNotifications.'); | |
90 }); | |
91 | |
92 test.done(); | |
93 }); | |
81 }); | 94 }); |
82 }).catch(unreached_rejection(test)); | 95 }).catch(unreached_rejection(test)); |
83 | 96 |
84 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.'); | 97 }, 'Clicking on a notification displayed by a Service Worker the notificat ionclick event.'); |
85 </script> | 98 </script> |
86 </body> | 99 </body> |
87 </html> | 100 </html> |
OLD | NEW |