| Index: LayoutTests/http/tests/serviceworker/resources/support.js
|
| diff --git a/LayoutTests/http/tests/serviceworker/resources/support.js b/LayoutTests/http/tests/serviceworker/resources/support.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fa1591bd90bb5922342f9a8059848d1bcc11ccb8
|
| --- /dev/null
|
| +++ b/LayoutTests/http/tests/serviceworker/resources/support.js
|
| @@ -0,0 +1,27 @@
|
| +// Service Worker helpers for testharness.js-based tests.
|
| +
|
| +// Use with unexpected event handlers or Promise rejection. Will
|
| +// fail the test with a name/message is present on the error.
|
| +// E.g.:
|
| +// onbadevent = fail(t, 'Should only see good events');
|
| +// Promise.then(...).catch(fail(t, 'Rejection is never fun'));
|
| +function fail(test, desc) {
|
| + desc = desc || 'Failure';
|
| + return test.step_func(function(reason) {
|
| + if (reason && 'name' in reason && 'message' in reason) {
|
| + assert_unreached(desc + ': ' + reason.name + ' - ' + reason.message);
|
| + } else if (reason && 'name' in reason) {
|
| + assert_unreached(desc + ': ' + reason.name);
|
| + } else {
|
| + assert_unreached(desc);
|
| + }
|
| + });
|
| +}
|
| +
|
| +// Sends a message of {port, from} to the specified worker, and returns the
|
| +// port at the local end of the channel.
|
| +function sendMessagePort(worker, from) {
|
| + var messageChannel = new MessageChannel();
|
| + worker.postMessage({from:from, port:messageChannel.port2}, [messageChannel.port2]);
|
| + return messageChannel.port1;
|
| +}
|
|
|