| 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);
|
| +}
|
|
|