Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-workers.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-workers.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-workers.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f237b3cac2ab16d989a7a9657a1b73e8f354f992 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-workers.html |
| @@ -0,0 +1,104 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="../resources/get-host-info.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script src="resources/foreign-fetch-helpers.js"></script> |
| +<body> |
| +<script> |
| +var host_info = get_host_info(); |
| +var ff_worker = 'foreign-fetch-worker.js?{}'; |
| + |
| +promise_test(t => { |
| + var ff_scope = 'simple.txt?basic_sw'; |
| + var worker = 'resources/foreign-fetch-helper-worker.js'; |
| + var scope = 'resources/simple.html?foreignfetch'; |
| + return install_cross_origin_worker(t, ff_worker, ff_scope) |
| + .then(() => service_worker_unregister_and_register(t, worker, scope)) |
| + .then(r => { |
| + add_completion_callback(() => r.unregister()); |
| + return wait_for_state(t, r.installing, 'activated'); |
| + }) |
| + .then(() => with_iframe(scope)) |
| + .then(frame => { |
| + assert_equals(frame.contentDocument.body.innerText, 'Foreign Fetch'); |
| + }); |
| + }, 'Foreign fetch can intercept fetches made from a service worker'); |
| + |
| +promise_test(t => { |
| + let scope = 'simple.txt?basic_dedicated'; |
| + let remote_url = |
| + host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope; |
| + return install_cross_origin_worker(t, ff_worker, scope) |
| + .then(() => new Promise(resolve => { |
| + let worker = new Worker('resources/foreign-fetch-helper-script.js'); |
| + let channel = new MessageChannel(); |
| + worker.postMessage({url: remote_url, |
| + port: channel.port1}, |
| + [channel.port1]); |
| + channel.port2.onmessage = reply => resolve(reply.data); |
| + })) |
| + .then(response => assert_equals(response, 'Success: Foreign Fetch')); |
| + }, 'Foreign fetch can intercept fetches made from a dedicated worker'); |
| + |
| +promise_test(t => { |
| + let scope = 'simple.txt?basic_shared'; |
| + let remote_url = |
| + host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + scope; |
| + return install_cross_origin_worker(t, ff_worker, scope) |
| + .then(() => new Promise(resolve => { |
| + let worker = new SharedWorker('resources/foreign-fetch-helper-script.js'); |
|
horo
2016/06/30 10:12:09
nit: Wrap at 80 columns.
https://www.chromium.org
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
|
| + let channel = new MessageChannel(); |
| + worker.port.postMessage({url: remote_url, |
| + port: channel.port1}, |
| + [channel.port1]); |
| + channel.port2.onmessage = reply => resolve(reply.data); |
| + })) |
| + .then(response => assert_equals(response, 'Success: Foreign Fetch')); |
| + }, 'Foreign fetch can intercept fetches made from a shared worker'); |
| + |
| +function fetch_from_cross_origin_worker(worker_type, origin, url) { |
| + return with_iframe(origin + |
| + '/serviceworker/resources/foreign-fetch-helper-iframe.html') |
| + .then(frame => new Promise((resolve) => { |
| + let channel = new MessageChannel(); |
| + frame.contentWindow.postMessage({url: url, |
| + port: channel.port1, |
| + worker: worker_type}, |
| + '*', [channel.port1]); |
| + channel.port2.onmessage = reply => resolve(reply.data); |
| + })); |
| +} |
| + |
| +promise_test(t => { |
| + var scope = 'simple.txt?basic_dedicated_insecure'; |
| + var remote_url = |
| + host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; |
| + return install_cross_origin_worker(t, ff_worker, scope, |
| + host_info.AUTHENTICATED_ORIGIN) |
| + .then(() => fetch_from_cross_origin_worker('dedicated', |
| + host_info.HTTPS_REMOTE_ORIGIN, remote_url)) |
| + .then(response => assert_equals(response, 'Success: Foreign Fetch')) |
| + .then(() => fetch_from_cross_origin_worker('dedicated', |
| + host_info.UNAUTHENTICATED_ORIGIN, remote_url)) |
| + .then(response => assert_equals(response, |
| + 'Error: TypeError: Failed to fetch')); |
| + }, 'Service Worker does not intercept fetches from an insecure dedicated worker.'); |
|
horo
2016/06/30 10:12:09
ditto
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
|
| + |
| +promise_test(t => { |
| + var scope = 'simple.txt?basic_shared_insecure'; |
| + var remote_url = |
| + host_info.AUTHENTICATED_ORIGIN + '/serviceworker/resources/' + scope; |
| + return install_cross_origin_worker(t, ff_worker, scope, |
| + host_info.AUTHENTICATED_ORIGIN) |
| + .then(() => fetch_from_cross_origin_worker('shared', |
| + host_info.HTTPS_REMOTE_ORIGIN, remote_url)) |
| + .then(response => assert_equals(response, 'Success: Foreign Fetch')) |
| + .then(() => fetch_from_cross_origin_worker('shared', |
| + host_info.UNAUTHENTICATED_ORIGIN, remote_url)) |
| + .then(response => assert_equals(response, |
| + 'Error: TypeError: Failed to fetch')); |
| + }, 'Service Worker does not intercept fetches from an insecure shared worker.'); |
|
horo
2016/06/30 10:12:09
ditto
Marijn Kruisselbrink
2016/06/30 22:43:12
Done
|
| + |
| +</script> |
| +</body> |