Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /fetch/compression-dictionary/dictionary-fetch-with-link-referrer-and-referrerpolicy.tentative.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>link rel=compression-dictionary, referrerpolicy attribute</title>
<meta name="timeout" content="long"/>
<link rel="help" href="https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script src="./resources/compression-dictionary-util.sub.js"></script>
<script>
let frame;
// Set up the service worker and the frame.
const kScope = 'resources/empty.https.html';
promise_test(t => {
const kScript = 'resources/fetch-options-worker.js';
return service_worker_unregister_and_register(t, kScript, kScope)
.then(registration => {
add_completion_callback(() => {
registration.unregister();
});
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => {
return with_iframe(kScope);
})
.then(f => {
frame = f;
add_completion_callback(() => { f.remove(); });
});
}, 'Initialize global state');
function expectedReferrer(referrerPolicyAttributeValue) {
switch(referrerPolicyAttributeValue) {
case "no-referrer":
return "";
case "origin":
case "strict-origin":
return `${location.origin}/`;
default:
return (new URL(kScope, `${location.origin}${location.pathname}`)).href;
}
}
function expectedReferrerPolicy(referrerPolicyAttributeValue) {
if (referrerPolicyAttributeValue === null ||
referrerPolicyAttributeValue === "" ||
referrerPolicyAttributeValue === "invalid") {
return "strict-origin-when-cross-origin";
}
return referrerPolicyAttributeValue;
}
[
null,
"",
"no-referrer",
"no-referrer-when-downgrade",
"same-origin",
"origin",
"strict-origin",
"origin-when-cross-origin",
"strict-origin-when-cross-origin",
"unsafe-url",
"invalid",
].forEach(referrerPolicy => {
const test_name = referrerPolicy !== null ? `referrerpolicy='${referrerPolicy}'` : "no referrerpolicy attribute";
compression_dictionary_promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "compression-dictionary";
node.onload = resolve;
node.onerror = reject;
if (referrerPolicy !== null)
node.setAttribute("referrerpolicy", referrerPolicy);
node.href = `dummy?referrerPolicy=${expectedReferrerPolicy(referrerPolicy)}&referrer=${expectedReferrer(referrerPolicy)}`;
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, `HTMLLinkElement rel=compression-dictionary (${test_name})`);
});
</script>