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 @@ ...@@ -5,39 +5,41 @@
<script src="/common/get-host-info.sub.js"></script> <script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script> <script src="resources/test-helpers.sub.js"></script>
<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) const SCOPE = 'resources/referrer-policy-iframe.html';
.then(function(registration) { const SCRIPT = 'resources/fetch-rewrite-worker-referrer-policy.js';
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();
});
return new Promise(function(resolve) { promise_test(async t => {
channel.port1.onmessage = resolve; const registration =
frame.contentWindow.postMessage({}, await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
host_info['HTTPS_ORIGIN'], await wait_for_state(t, registration.installing, 'activated');
[channel.port2]); promise_test(() => registration.unregister(),
}); 'Remove registration as a cleanup');
}) }, 'Initialize global state (service worker registration)');
.then(function(e) {
assert_equals(e.data.results, 'finish');
});
// Schedule un-registration to occur after test execution has completed, promise_test(async t => {
// without hiding test failure. const full_scope_url = new URL(SCOPE, location.href);
return body const redirect_to = `${full_scope_url.href}?ignore=true`;
.then(unregister, unregister) const frame = await with_iframe(
.then(function() { return body; }); `${SCOPE}?pipe=status(302)|header(Location,${redirect_to})|` +
}, 'Verify the referer with a Referrer Policy'); '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> </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