Chromium Code Reviews| Index: LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js |
| diff --git a/LayoutTests/http/tests/navigatorconnect/connect-cross-origin.html b/LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js |
| similarity index 54% |
| copy from LayoutTests/http/tests/navigatorconnect/connect-cross-origin.html |
| copy to LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js |
| index eaa2b44cb6e2dec054c7d51f3131a0bc6d44421c..328b10ef01b5f6c279d3bc6aaa9db7447324a3fa 100644 |
| --- a/LayoutTests/http/tests/navigatorconnect/connect-cross-origin.html |
| +++ b/LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js |
| @@ -1,18 +1,3 @@ |
| -<!DOCTYPE html> |
| -<title> |
| - Tests accepting and rejecting connections calling navigator.connect from |
| - a cross origin iframe. |
| -</title> |
| -<script src="../../resources/testharness.js"></script> |
| -<script src="../../resources/testharnessreport.js"></script> |
| -<script src="../../resources/testharness-helpers.js"></script> |
| -<script src="../serviceworker/resources/test-helpers.js"></script> |
| -<script src="resources/connect-tests.js"></script> |
| -<body> |
| -<script> |
| -var cross_origin = get_host_info().UNAUTHENTICATED_ORIGIN; |
| -var sw_scope = 'resources/service-worker-scope' + window.location.pathname; |
| - |
| // 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) { |
| @@ -41,6 +26,27 @@ function cross_origin_connect(t, service) { |
| }); |
| } |
| -run_connect_tests(cross_origin_connect); |
| -</script> |
| -</body> |
| +// 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 new Promise(function(resolve, reject) { |
|
Jeffrey Yasskin
2014/12/20 00:31:51
Can you share this Promise creation with cross_ori
|
| + var got_reply = false; |
| + channel.port1.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); |
| + }); |
| + }); |
| +} |