Skip to content

Commit 69eb567

Browse files
fred-wangchromium-wpt-export-bot
authored andcommitted
[compression-dictionary] Align handling of referrer and referrerpolicy with the spec PR.
http://github.com/whatwg/html/pull/11620 follows what is done for rel="prefetch", which does not override referrer and takes into account the referrerpolicy attribute. Align Chromium with that behavior under a runtime flag and add corresponding WPT tests. Bug: 522338661, 40255884 Change-Id: Ia9f845dd8a1bd9c950c5ac302fba0f2d5eaf246c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8118407 Reviewed-by: Patrick Meenan <pmeenan@chromium.org> Commit-Queue: Frédéric Wang Nélar <fwang@igalia.com> Cr-Commit-Position: refs/heads/main@{#1664847}
1 parent 3d088e6 commit 69eb567

2 files changed

Lines changed: 93 additions & 2 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<title>link rel=compression-dictionary, referrerpolicy attribute</title>
3+
<meta name="timeout" content="long"/>
4+
<link rel="help" href="http://github.com/whatwg/html/pull/11620">
5+
<link rel="help" href="https://html.spec.whatwg.org/#create-link-options-from-element">
6+
<link rel="help" href="https://w3c.github.io/webappsec-referrer-policy/#referrer-policy">
7+
<link rel="help" href="https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer">
8+
<script src="/resources/testharness.js"></script>
9+
<script src="/resources/testharnessreport.js"></script>
10+
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
11+
<script src="./resources/compression-dictionary-util.sub.js"></script>
12+
<script>
13+
let frame;
14+
15+
// Set up the service worker and the frame.
16+
const kScope = 'resources/empty.https.html';
17+
promise_test(t => {
18+
const kScript = 'resources/fetch-options-worker.js';
19+
return service_worker_unregister_and_register(t, kScript, kScope)
20+
.then(registration => {
21+
add_completion_callback(() => {
22+
registration.unregister();
23+
});
24+
25+
return wait_for_state(t, registration.installing, 'activated');
26+
})
27+
.then(() => {
28+
return with_iframe(kScope);
29+
})
30+
.then(f => {
31+
frame = f;
32+
add_completion_callback(() => { f.remove(); });
33+
});
34+
}, 'Initialize global state');
35+
36+
function expectedReferrer(referrerPolicyAttributeValue) {
37+
switch(referrerPolicyAttributeValue) {
38+
case "no-referrer":
39+
return "";
40+
case "origin":
41+
case "strict-origin":
42+
return `${location.origin}/`;
43+
default:
44+
return (new URL(kScope, `${location.origin}${location.pathname}`)).href;
45+
}
46+
}
47+
48+
function expectedReferrerPolicy(referrerPolicyAttributeValue) {
49+
if (referrerPolicyAttributeValue === null ||
50+
referrerPolicyAttributeValue === "" ||
51+
referrerPolicyAttributeValue === "invalid") {
52+
return "strict-origin-when-cross-origin";
53+
}
54+
return referrerPolicyAttributeValue;
55+
}
56+
57+
[
58+
null,
59+
"",
60+
"no-referrer",
61+
"no-referrer-when-downgrade",
62+
"same-origin",
63+
"origin",
64+
"strict-origin",
65+
"origin-when-cross-origin",
66+
"strict-origin-when-cross-origin",
67+
"unsafe-url",
68+
"invalid",
69+
].forEach(referrerPolicy => {
70+
const test_name = referrerPolicy !== null ? `referrerpolicy='${referrerPolicy}'` : "no referrerpolicy attribute";
71+
compression_dictionary_promise_test(async t => {
72+
await new Promise((resolve, reject) => {
73+
let node = frame.contentWindow.document.createElement("link");
74+
node.rel = "compression-dictionary";
75+
node.onload = resolve;
76+
node.onerror = reject;
77+
if (referrerPolicy !== null)
78+
node.setAttribute("referrerpolicy", referrerPolicy);
79+
node.href = `dummy?referrerPolicy=${expectedReferrerPolicy(referrerPolicy)}&referrer=${expectedReferrer(referrerPolicy)}`;
80+
frame.contentWindow.document.body.appendChild(node);
81+
}).catch(() => {
82+
assert_unreached("Fetch errored.");
83+
});
84+
}, `HTMLLinkElement rel=compression-dictionary (${test_name})`);
85+
});
86+
</script>

fetch/compression-dictionary/resources/fetch-options-worker.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ self.addEventListener('fetch', function(event) {
33
const params = new URL(event.request.url).searchParams;
44
const credentials = params.get("credentials");
55
const mode = params.get("mode");
6-
if ((!mode || mode == event.request.mode) &&
7-
(!credentials || credentials == event.request.credentials)) {
6+
const referrer = params.get('referrer');
7+
const referrerPolicy = params.get('referrerPolicy');
8+
if ((credentials === null || credentials == event.request.credentials) &&
9+
(mode === null || mode == event.request.mode) &&
10+
(referrer === null || referrer == event.request.referrer) &&
11+
(referrerPolicy === null ||
12+
referrerPolicy == event.request.referrerPolicy)) {
813
event.respondWith(fetch(event.request));
914
} else {
1015
event.respondWith(Response.error());

0 commit comments

Comments
 (0)