Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/notifications/serviceworker-notificationclick-event-reply-reflection.html

Issue 2403893002: Add layout test for reply property of notificationclick event (Closed)
Patch Set: Add layout test for reply property of notificationclick event Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // (3) Simulate a reply to the notification text action.
48 for (var i = 0; i < options.actions.length; ++i) 39 testRunner.simulateWebNotificationClickWithReply(scope, 0 /* actio n_index */, 'My reply.');
49 testRunner.simulateWebNotificationClick(scope, i);
50 testRunner.simulateWebNotificationClick(scope, -1 /* action_index */);
51 40
52 port.addEventListener('message', function(event) { 41 port.addEventListener('message', function(event) {
53 // (4) Listen for confirmation from the Service Worker that th e 42 // (4) Listen for confirmation from the Service Worker that th e
54 // notification has been clicked on. Make sure that the action 43 // notification has been clicked on. Make sure that the reply
55 // property set on the NotificationEvent object is as expected . 44 // property set on the NotificationEvent object is as expected .
56 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.'); 45 assert_equals(event.data.command, 'click', 'The notification w as expected to be clicked.');
57 46
58 assert_equals(event.data.action, expectedActions.shift()); 47 assert_equals(event.data.reply, 'My reply.');
Peter Beverloo 2016/10/11 14:28:39 We should probably test the NULL-string and empty-
awdf 2016/10/12 14:59:45 Done the empty string case but not sure how to che
awdf 2016/10/13 13:17:29 Done.
59 48
60 if (expectedActions.length === 0) 49 test.done();
61 test.done();
62 }); 50 });
63 }).catch(unreached_rejection(test)); 51 }).catch(unreached_rejection(test));
64 52
65 }, 'NotificationEvent action property should be reflect which action was c licked.'); 53 }, 'NotificationEvent reply property should reflect the reply that was ent ered');
66 </script> 54 </script>
67 </body> 55 </body>
68 </html> 56 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698