blob: c2e5b65d905af9fa97030fd035f700935dd784bb [file] [log] [blame]
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.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?{}';
var resource_path = new URL('resources/', location).pathname;
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 + resource_path + 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 + resource_path + scope;
return install_cross_origin_worker(t, ff_worker, scope)
.then(() => new Promise(resolve => {
let worker = new SharedWorker(
'resources/foreign-fetch-helper-script.js');
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');
promise_test(t => {
var scope = 'simple.txt?basic_dedicated_insecure';
var remote_url = host_info.AUTHENTICATED_ORIGIN + resource_path + scope;
return install_cross_origin_worker(t, ff_worker, scope,
host_info.AUTHENTICATED_ORIGIN)
.then(() => fetch_from_different_origin(
host_info.HTTPS_REMOTE_ORIGIN, remote_url, 'dedicated'))
.then(response => assert_equals(response, 'Success: Foreign Fetch'))
.then(() => fetch_from_different_origin(
host_info.UNAUTHENTICATED_ORIGIN, remote_url, 'dedicated'))
.then(response => assert_equals(response,
'Error: TypeError: Failed to fetch'));
}, 'Fetches from an insecure dedicated worker aren\'t intercepted.');
promise_test(t => {
var scope = 'simple.txt?basic_shared_insecure';
var remote_url = host_info.AUTHENTICATED_ORIGIN + resource_path + scope;
return install_cross_origin_worker(t, ff_worker, scope,
host_info.AUTHENTICATED_ORIGIN)
.then(() => fetch_from_different_origin(
host_info.HTTPS_REMOTE_ORIGIN, remote_url, 'shared'))
.then(response => assert_equals(response, 'Success: Foreign Fetch'))
.then(() => fetch_from_different_origin(
host_info.UNAUTHENTICATED_ORIGIN, remote_url, 'shared'))
.then(response => assert_equals(response,
'Error: TypeError: Failed to fetch'));
}, 'Fetches from an insecure shared worker aren\'t intercepted.');
</script>
</body>