Commit 9b6d6146 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Add a layout test for redirects with referrer-policy via service worker

Redirects with referrer-policy header need to respect a new referrer
policy. This tries to check if it's working when the request is in a service
worker's scope.

Bug: 855948
Change-Id: Icb923fa8b8345c128f02c41e042775ba5bf499ad
Reviewed-on: https://chromium-review.googlesource.com/1113171
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570298}
parent b0c6f3c8
......@@ -5,39 +5,41 @@
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
promise_test(function(t) {
var SCOPE = 'resources/referrer-policy-iframe.html';
var SCRIPT = 'resources/fetch-rewrite-worker-referrer-policy.js';
var host_info = get_host_info();
var body, unregister;
body = service_worker_unregister_and_register(t, SCRIPT, SCOPE)
.then(function(registration) {
unregister = registration.unregister.bind(registration);
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(SCOPE); })
.then(function(frame) {
var channel = new MessageChannel();
t.add_cleanup(function() {
frame.remove();
});
const SCOPE = 'resources/referrer-policy-iframe.html';
const SCRIPT = 'resources/fetch-rewrite-worker-referrer-policy.js';
return new Promise(function(resolve) {
channel.port1.onmessage = resolve;
frame.contentWindow.postMessage({},
host_info['HTTPS_ORIGIN'],
[channel.port2]);
});
})
.then(function(e) {
assert_equals(e.data.results, 'finish');
});
promise_test(async t => {
const registration =
await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
await wait_for_state(t, registration.installing, 'activated');
promise_test(() => registration.unregister(),
'Remove registration as a cleanup');
}, 'Initialize global state (service worker registration)');
// Schedule un-registration to occur after test execution has completed,
// without hiding test failure.
return body
.then(unregister, unregister)
.then(function() { return body; });
}, 'Verify the referer with a Referrer Policy');
promise_test(async t => {
const full_scope_url = new URL(SCOPE, location.href);
const redirect_to = `${full_scope_url.href}?ignore=true`;
const frame = await with_iframe(
`${SCOPE}?pipe=status(302)|header(Location,${redirect_to})|` +
'header(Referrer-Policy,origin)');
assert_equals(frame.contentDocument.referrer,
full_scope_url.origin + '/');
t.add_cleanup(() => frame.remove());
}, 'Referrer for a main resource redirected with referrer-policy (origin) ' +
'should only have origin.');
promise_test(async t => {
const host_info = get_host_info();
const frame = await with_iframe(SCOPE);
const channel = new MessageChannel();
t.add_cleanup(() => frame.remove());
const e = await new Promise(resolve => {
channel.port1.onmessage = resolve;
frame.contentWindow.postMessage(
{}, host_info['HTTPS_ORIGIN'], [channel.port2]);
});
assert_equals(e.data.results, 'finish');
}, 'Referrer for fetch requests initiated from a service worker with ' +
'referrer-policy (origin) should only have origin.');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment