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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js

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 // Supports test-runner control messages being send over |messagePort|, which en able 1 // Supports test-runner control messages being send over |messagePort|, which en able
2 // workers to have limited access to TestRunner methods. 2 // workers to have limited access to TestRunner methods.
3 function supportTestRunnerMessagesOnPort(messagePort) 3 function supportTestRunnerMessagesOnPort(messagePort)
4 { 4 {
5 if (!window.testRunner) 5 if (!window.testRunner)
6 return; 6 return;
7 7
8 messagePort.addEventListener('message', function(message) { 8 messagePort.addEventListener('message', function(message) {
9 if (message.data.type == 'simulateWebNotificationClick') 9 if (message.data.type == 'simulateWebNotificationClick')
10 testRunner.simulateWebNotificationClick(message.data.title, -1 /* ac tion_index */); 10 testRunner.simulateWebNotificationClick(message.data.title, -1 /* ac tion_index */);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 messageChannel.port1.addEventListener('message', function(event) { 59 messageChannel.port1.addEventListener('message', function(event) {
60 if (event.data == 'ready') 60 if (event.data == 'ready')
61 resolve({ registration: registration, port: messageChannel.p ort1 }); 61 resolve({ registration: registration, port: messageChannel.p ort1 });
62 }); 62 });
63 63
64 registration.active.postMessage(messageChannel.port2, [messageChanne l.port2]); 64 registration.active.postMessage(messageChannel.port2, [messageChanne l.port2]);
65 messageChannel.port1.start(); 65 messageChannel.port1.start();
66 }); 66 });
67 }); 67 });
68 } 68 }
69
70 // Sends a message with |data| over |port|. Returns a promise that either reject s when a bad
71 // response message is received, or otherwise resolves with the response data.
72 function sendCommand(port, data)
73 {
74 return new Promise((resolve, reject) => {
75 port.postMessage(data);
76 port.addEventListener('message', function listener(event) {
77 port.removeEventListener('message', listener);
78 if (typeof event.data != 'object' || !event.data.command) {
79 reject(new Error('Invalid message from the Service Worker.'));
80 } else {
81 resolve(event.data);
82 }
83 });
84 });
85 }
86
87 // Simulates a click on the notification whose title equals |title|. The |action Index| specifies
88 // which action button to activate, where -1 means the notification itself is cl icked, not an action
89 // button.
90 function simulateNotificationClick(title, actionIndex, port)
91 {
92 return new Promise((resolve, reject) => {
93 testRunner.simulateWebNotificationClick(title, actionIndex);
94 port.addEventListener('message', function listener(event) {
95 port.removeEventListener('message', listener);
96 if (typeof event.data != 'object' || event.data.command != 'click') {
97 reject(new Error('Invalid message from the Service Worker.'));
98 } else {
99 resolve(event.data);
100 }
101 });
102 });
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698