| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Notifications: Action reflection in the "notificationclick" event.</t
itle> | 4 <title>Notifications: Reply reflection in the "notificationclick" event.</ti
tle> |
| 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 action property of the "notificationclick" event in the | 12 // Tests that the reply property of the "notificationclick" event in the |
| 13 // Service Worker accurately reflects which action was activated, if any. | 13 // Service Worker accurately reflects the reply entered. |
| 14 | 14 |
| 15 async_test(function(test) { | 15 async_test(function(test) { |
| 16 var scope = 'resources/scope/' + location.pathname; | 16 var scope = 'resources/scope/' + location.pathname; |
| 17 var script = 'instrumentation-service-worker.js'; | 17 var script = 'instrumentation-service-worker.js'; |
| 18 var port; | 18 var port; |
| 19 | 19 |
| 20 var options = { | 20 var options = { |
| 21 actions: [] | 21 actions: [{ action: 'actionName', title: 'ActionTitle', type: 'text'
}] |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 var expectedActions = []; | |
| 25 for (var i = 0; i < Notification.maxActions; ++i) { | |
| 26 var action = { action: 'action' + i, title: 'Action ' + i }; | |
| 27 options.actions.push(action); | |
| 28 expectedActions.push(action.action); | |
| 29 } | |
| 30 // Expect empty string when main body of notification is activated. | |
| 31 expectedActions.push(''); | |
| 32 | |
| 33 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); | 24 testRunner.setPermission('notifications', 'granted', location.origin,
location.origin); |
| 34 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(info) { | 25 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi
on(info) { |
| 35 port = info.port; | 26 port = info.port; |
| 36 // (1) Tell the Service Worker to display a Web Notification. | 27 // (1) Tell the Service Worker to display a Web Notification. |
| 37 return sendCommand(port, { | 28 return sendCommand(port, { |
| 38 command: 'show', | 29 command: 'show', |
| 39 | 30 |
| 40 title: scope, | 31 title: scope, |
| 41 options: options | 32 options: options |
| 42 }); | 33 }); |
| 43 }).then(function(data) { | 34 }).then(function(data) { |
| 44 // (2) Confirm that the service worker displayed the notification
successfully. | 35 // (2) Confirm that the service worker displayed the notification
successfully. |
| 45 assert_true(data.success, 'The notification must have been display
ed.'); | 36 assert_true(data.success, 'The notification must have been display
ed.'); |
| 46 | 37 |
| 47 // (3) Simulate a click on each button and on the notification bod
y. | 38 var expectedReplies = []; |
| 48 for (var i = 0; i < options.actions.length; ++i) | 39 // (3) Simulate some clicks on the notification, with and without
replies. |
| 49 testRunner.simulateWebNotificationClick(scope, i); | 40 // (3.1) Simulate a reply to the notification text action. |
| 41 testRunner.simulateWebNotificationClickWithReply(scope, 0 /* actio
n_index */, 'My reply.'); |
| 42 expectedReplies.push('My reply.'); |
| 43 |
| 44 // (3.2) Simulate an empty reply to the notification text action. |
| 45 testRunner.simulateWebNotificationClickWithReply(scope, 0 /* actio
n_index */, ''); |
| 46 expectedReplies.push(''); |
| 47 |
| 48 // (3.3) Simulate a click on the notification body (reply should b
e null). |
| 50 testRunner.simulateWebNotificationClick(scope, -1 /* action_index
*/); | 49 testRunner.simulateWebNotificationClick(scope, -1 /* action_index
*/); |
| 50 expectedReplies.push(null); |
| 51 | 51 |
| 52 port.addEventListener('message', function(event) { | 52 port.addEventListener('message', function(event) { |
| 53 // (4) Listen for confirmation from the Service Worker that th
e | 53 // (4) Listen for confirmation from the Service Worker that th
e |
| 54 // notification has been clicked on. Make sure that the action | 54 // notification has been clicked on. Make sure that the reply |
| 55 // property set on the NotificationEvent object is as expected
. | 55 // property set on the NotificationEvent object is as expected
. |
| 56 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); | 56 assert_equals(event.data.command, 'click', 'The notification w
as expected to be clicked.'); |
| 57 | 57 |
| 58 assert_equals(event.data.action, expectedActions.shift()); | 58 assert_equals(event.data.reply, expectedReplies.shift()); |
| 59 | 59 |
| 60 if (expectedActions.length === 0) | 60 if (expectedReplies.length === 0) |
| 61 test.done(); | 61 test.done(); |
| 62 }); | 62 }); |
| 63 }).catch(unreached_rejection(test)); | 63 }).catch(unreached_rejection(test)); |
| 64 | 64 |
| 65 }, 'NotificationEvent action property should be reflect which action was c
licked.'); | 65 }, 'NotificationEvent reply property should reflect the reply that was ent
ered'); |
| 66 </script> | 66 </script> |
| 67 </body> | 67 </body> |
| 68 </html> | 68 </html> |
| OLD | NEW |