Skip to content

Commit babeec8

Browse files
fred-wangchromium-wpt-export-bot
authored andcommitted
[compression-dictionary] Align crossorigin handling with the spec PR.
Per whatwg/html#11620, if crossorigin is "No Cors" we should default to Anonymous. Currently, Chromium departs from the spec and always forces request's mode to "cors" and request's credentials to "omit". This CL aligns Chromium's behavior on the spec PR under a runtime flag and adds corresponding WPT test. Bug: 522338661, 40255884 Change-Id: I30835aebc9df79b59e74747b0729efbc6df69457 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8098207 Reviewed-by: Patrick Meenan <pmeenan@chromium.org> Commit-Queue: Frédéric Wang Nélar <fwang@igalia.com> Cr-Commit-Position: refs/heads/main@{#1663435}
1 parent fe2e38d commit babeec8

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<title>compression-dictionary</title>
3+
<meta name="timeout" content="long"/>
4+
<link rel="help" href="http://github.com/whatwg/html/pull/11620">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
8+
<script src="./resources/compression-dictionary-util.sub.js"></script>
9+
<script>
10+
let frame;
11+
12+
// Set up the service worker and the frame.
13+
promise_test(t => {
14+
const kScope = 'resources/empty.https.html';
15+
const kScript = 'resources/fetch-options-worker.js';
16+
return service_worker_unregister_and_register(t, kScript, kScope)
17+
.then(registration => {
18+
add_completion_callback(() => {
19+
registration.unregister();
20+
});
21+
22+
return wait_for_state(t, registration.installing, 'activated');
23+
})
24+
.then(() => {
25+
return with_iframe(kScope);
26+
})
27+
.then(f => {
28+
frame = f;
29+
add_completion_callback(() => { f.remove(); });
30+
});
31+
}, 'Initialize global state');
32+
33+
compression_dictionary_promise_test(async t => {
34+
await new Promise((resolve, reject) => {
35+
let node = frame.contentWindow.document.createElement("link");
36+
node.rel = "compression-dictionary";
37+
node.onload = resolve;
38+
node.onerror = reject;
39+
node.href = "dummy?mode=cors&credentials=same-origin";
40+
frame.contentWindow.document.body.appendChild(node);
41+
}).catch(() => {
42+
assert_unreached("Fetch errored.");
43+
});
44+
}, 'HTMLLinkElement rel=compression-dictionary');
45+
46+
compression_dictionary_promise_test(async t => {
47+
await new Promise((resolve, reject) => {
48+
let node = frame.contentWindow.document.createElement("link");
49+
node.rel = "compression-dictionary";
50+
node.onload = resolve;
51+
node.onerror = reject;
52+
node.crossOrigin = "anonymous";
53+
node.href = "dummy?mode=cors&credentials=same-origin";
54+
frame.contentWindow.document.body.appendChild(node);
55+
}).catch(() => {
56+
assert_unreached("Fetch errored.");
57+
});
58+
}, 'HTMLLinkElement rel=compression-dictionary crossorigin=anonymous');
59+
60+
compression_dictionary_promise_test(async t => {
61+
await new Promise((resolve, reject) => {
62+
let node = frame.contentWindow.document.createElement("link");
63+
node.rel = "compression-dictionary";
64+
node.onload = resolve;
65+
node.onerror = reject;
66+
node.crossOrigin = "use-credentials";
67+
node.href = "dummy?mode=cors&credentials=include";
68+
frame.contentWindow.document.body.appendChild(node);
69+
}).catch(() => {
70+
assert_unreached("Fetch errored.");
71+
});
72+
}, 'HTMLLinkElement rel=compression-dictionary crossorigin=use-credentials');
73+
74+
</script>

fetch/compression-dictionary/resources/dummy

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!DOCTYPE html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
self.addEventListener('fetch', function(event) {
2+
if (event.request.url.includes('dummy')) {
3+
const params = new URL(event.request.url).searchParams;
4+
const credentials = params.get("credentials");
5+
const mode = params.get("mode");
6+
if ((!mode || mode == event.request.mode) &&
7+
(!credentials || credentials == event.request.credentials)) {
8+
event.respondWith(fetch(event.request));
9+
} else {
10+
event.respondWith(Response.error());
11+
}
12+
}
13+
});

0 commit comments

Comments
 (0)