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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/support.js

Issue 238993003: ServiceWorker: "minimal" end-to-end sample as a W3C test (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Sync with github Created 6 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 side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698