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

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

Issue 1907443007: Use promises in notifications tests and enable controlling the page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address peter's comments. Created 4 years, 8 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: Action reflection in the "notificationclick" event.</t itle>
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 action property of the "notificationclick" event in the
13 // Service Worker accurately reflects which action was activated, if any. 13 // Service Worker accurately reflects which action was activated, if any.
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 script = 'resources/instrumentation-service-worker.js'; 17 var script = 'instrumentation-service-worker.js';
18 var port;
18 19
19 var options = { 20 var options = {
20 actions: [] 21 actions: []
21 }; 22 };
22 23
23 var expectedActions = []; 24 var expectedActions = [];
24 for (var i = 0; i < Notification.maxActions; ++i) { 25 for (var i = 0; i < Notification.maxActions; ++i) {
25 var action = { action: "action" + i, title: "Action " + i }; 26 var action = { action: 'action' + i, title: 'Action ' + i };
26 options.actions.push(action); 27 options.actions.push(action);
27 expectedActions.push(action.action); 28 expectedActions.push(action.action);
28 } 29 }
29 // Expect empty string when main body of notification is activated. 30 // Expect empty string when main body of notification is activated.
30 expectedActions.push(""); 31 expectedActions.push('');
31 32
32 testRunner.setPermission('notifications', 'granted', location.origin, location.origin); 33 testRunner.setPermission('notifications', 'granted', location.origin, location.origin);
33 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(workerInfo) { 34 getActiveServiceWorkerWithMessagePort(test, script, scope).then(functi on(info) {
35 port = info.port;
34 // (1) Tell the Service Worker to display a Web Notification. 36 // (1) Tell the Service Worker to display a Web Notification.
35 workerInfo.port.postMessage({ 37 return sendCommand(port, {
36 command: 'show', 38 command: 'show',
37 39
38 title: scope, 40 title: scope,
39 options: options 41 options: options
40 }); 42 });
43 }).then(function(data) {
44 // (2) Confirm that the service worker displayed the notification successfully.
45 assert_true(data.success, 'The notification must have been display ed.');
41 46
42 workerInfo.port.addEventListener('message', function(event) { 47 // (3) Simulate a click on each button and on the notification bod y.
43 if (typeof event.data != 'object' || !event.data.command) { 48 for (var i = 0; i < options.actions.length; ++i)
44 assert_unreached('Invalid message from the Service Worker. '); 49 testRunner.simulateWebNotificationClick(scope, i);
45 return; 50 testRunner.simulateWebNotificationClick(scope, -1 /* action_index */);
46 }
47 51
48 // (2) Listen for confirmation from the Service Worker that th e 52 port.addEventListener('message', function(event) {
49 // notification's display promise has been resolved. 53 // (4) Listen for confirmation from the Service Worker that th e
50 if (event.data.command == 'show') {
51 assert_true(event.data.success, 'The notification must hav e been displayed.');
52 for (var i = 0; i < options.actions.length; ++i)
53 testRunner.simulateWebNotificationClick(scope, i);
54 testRunner.simulateWebNotificationClick(scope, -1 /* actio n_index */);
55 return;
56 }
57
58 // (3) Listen for confirmation from the Service Worker that th e
59 // notification has been clicked on. Make sure that the action 54 // notification has been clicked on. Make sure that the action
60 // property set on the NotificationEvent object is as expected . 55 // property set on the NotificationEvent object is as expected .
61 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.');
62 57
63 assert_equals(event.data.action, expectedActions.shift()); 58 assert_equals(event.data.action, expectedActions.shift());
64 59
65 if (expectedActions.length === 0) 60 if (expectedActions.length === 0)
66 test.done(); 61 test.done();
67 }); 62 });
68 }).catch(unreached_rejection(test)); 63 }).catch(unreached_rejection(test));
69 64
70 }, 'NotificationEvent action property should be reflect which action was c licked.'); 65 }, 'NotificationEvent action property should be reflect which action was c licked.');
71 </script> 66 </script>
72 </body> 67 </body>
73 </html> 68 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698