Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js b/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| index fca5463c72841efe40fc2ad556868a9b1995d9ac..d9fb5a297c918da802fdda4a481b347cbe25e9b5 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| +++ b/third_party/WebKit/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| @@ -66,3 +66,38 @@ function getActiveServiceWorkerWithMessagePort(test, script, scope) |
| }); |
| }); |
| } |
| + |
| +// Sends a message with |data| over |port|. Returns a promise that either rejects when a bad |
| +// response message is received, or otherwise resolves with the response data. |
| +function sendCommand(port, data) |
| +{ |
| + return new Promise((resolve, reject) => { |
| + port.postMessage(data); |
| + port.addEventListener('message', function listener(event) { |
| + port.removeEventListener('message', listener); |
| + if (typeof event.data != 'object' || !event.data.command) { |
| + reject('Invalid message from the Service Worker.'); |
|
Peter Beverloo
2016/04/21 17:20:56
nit: Promises should be rejected with errors.
new
Michael van Ouwerkerk
2016/04/22 09:44:22
Done.
|
| + } else { |
| + resolve(event.data); |
| + } |
| + }); |
| + }); |
| +} |
| + |
| +// Simulates a click on the notification whose title equals |title|. The |actionIndex| specifies |
| +// which action button to activate, where -1 means the notification itself is clicked, not an action |
| +// button. |
| +function simulateNotificationClick(title, actionIndex, port) |
| +{ |
| + return new Promise((resolve, reject) => { |
| + testRunner.simulateWebNotificationClick(title, actionIndex); |
| + port.addEventListener('message', function listener(event) { |
| + port.removeEventListener('message', listener); |
| + if (typeof event.data != 'object' || event.data.command != 'click') { |
| + reject('Invalid message from the Service Worker.'); |
| + } else { |
| + resolve(event.data); |
| + } |
| + }); |
| + }); |
| +} |