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

Unified Diff: LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js

Issue 812853002: Basic tests for sending messages over a navigator.connect initiated channel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@navigator-connect_connect-tests
Patch Set: fix Created 6 years 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
« no previous file with comments | « LayoutTests/http/tests/navigatorconnect/resources/reply-client-info-worker.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js
diff --git a/LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js b/LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js
new file mode 100644
index 0000000000000000000000000000000000000000..277c9fa565205790e64a57b8646fca151579104f
--- /dev/null
+++ b/LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js
@@ -0,0 +1,47 @@
+// Helper method that waits for a {success: <boolean>, result: any} reply on
+// a port and returns a promise that resolves (if success is true) or rejects
+// the promise with the value of the result attribute.
+function reply_as_promise(t, port) {
+ return new Promise(function(resolve, reject) {
+ var got_reply = false;
+ port.onmessage = t.step_func(function(event) {
+ assert_false(got_reply);
+ assert_true('success' in event.data);
+ assert_true('result' in event.data);
+ got_reply = true;
+ if (event.data.success)
+ resolve(event.data.result);
+ else
+ reject(event.data.result);
+ });
+ });
+}
+
+// Method that behaves similarly to navigator.connect, but the actual connect
+// call is made from a cross origin iframe.
+function cross_origin_connect(t, service) {
+ // |service| is a relative URL, but for this to work from the iframe it needs
+ // an absolute URL.
+ var target_url = location.origin + base_path() + service;
+ return with_iframe(
+ cross_origin + base_path() + 'resources/connect-helper.html')
+ .then(function(iframe) {
+ var channel = new MessageChannel();
+ iframe.contentWindow.postMessage(
+ {connect: target_url, port: channel.port2}, '*', [channel.port2]);
+ return reply_as_promise(t, channel.port1);
+ });
+}
+
+// Method that behaves similarly to navigator.connect, but the actual connect
+// call is made from a worker.
+function connect_from_worker(t, service) {
+ // |service| is a relative URL, but for this to work from the worker it needs
+ // an absolute URL.
+ var target_url = location.origin + base_path() + service;
+ var worker = new Worker('resources/connect-helper.js');
+ var channel = new MessageChannel();
+ worker.postMessage
+ ({connect: target_url, port: channel.port2}, [channel.port2]);
+ return reply_as_promise(t, channel.port1);
+}
« no previous file with comments | « LayoutTests/http/tests/navigatorconnect/resources/reply-client-info-worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698