Automatic update from web-platform-tests [compression-dictionary] Make sure link element are processed after changes to crossorigin attribute This is currently not specified but is proposed at https://github.com/whatwg/html/pull/11620 Bug: 522338661, 40255884 Change-Id: Ia6f60eee7f0e5a3af9fb4bda9b0d0a483a3e5950 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8027613 Commit-Queue: Frédéric Wang Nélar <fwang@igalia.com> Reviewed-by: Patrick Meenan <pmeenan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1663692} -- wpt-commits: 9fb9c273ff8ed6dda31c3326cc87d0624404ee3a wpt-pr: 61350
93 lines
5.2 KiB
HTML
93 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="timeout" content="long"/>
|
|
<script src="./resources/compression-dictionary-util.sub.js"></script>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<link rel="help" href="https://github.com/whatwg/html/pull/11620">
|
|
<link id="alreadyBrowsingContextConnected" rel="compression-dictionary" href="./resources/register-dictionary.py?alreadyBrowsingContextConnected"></link>
|
|
<script>
|
|
const dynamicallyConnected = document.createElement('link');
|
|
dynamicallyConnected.rel = 'compression-dictionary';
|
|
dynamicallyConnected.href = `${kRegisterDictionaryPath}?linkDynamicallyBrowsingContextConnected`;
|
|
</script>
|
|
<link id="hrefDynamicallySet" rel="compression-dictionary"></link>
|
|
<link id="hrefDynamicallyChanged" rel="compression-dictionary" href="./resources/register-dictionary.py?hrefDynamicallyChanged"></link>
|
|
<link id="relDynamicallySet" href="./resources/register-dictionary.py?relDynamicallySet">
|
|
<!-- Fetching this resources will be tried immediately, use a 404 response so fetching will be attempted again after mutating crossorigin attribute. -->
|
|
<link id="crossOriginDynamicallySet" rel="compression-dictionary" href="./resources/404NotFound/register-dictionary.py?crossOriginDynamicallySet">
|
|
<link id="crossOriginDynamicallyChanged" rel="compression-dictionary" crossorigin="use-credentials" href="./resources/404NotFound/register-dictionary.py?crossOriginDynamicallyChanged">
|
|
<link id="crossOriginDynamicallyRemoved" rel="compression-dictionary" crossorigin="use-credentials" href="./resources/404NotFound/register-dictionary.py?crossOriginDynamicallyRemoved">
|
|
<body>
|
|
<script>
|
|
let fetchedDictionaries = [];
|
|
const observer = new PerformanceObserver((list) => {
|
|
list.getEntries().forEach(entry => {
|
|
const url = new URL(entry.name);
|
|
if (url.pathname.endsWith("register-dictionary.py")) {
|
|
fetchedDictionaries.push(url.search);
|
|
}
|
|
});
|
|
});
|
|
observer.observe({ type: "resource", buffered: true});
|
|
|
|
compression_dictionary_promise_test(async t => {
|
|
// Initially fetched dictionaries.
|
|
let expectedEntries = [
|
|
"?alreadyBrowsingContextConnected",
|
|
"?crossOriginDynamicallyChanged",
|
|
"?crossOriginDynamicallyRemoved",
|
|
"?crossOriginDynamicallySet",
|
|
"?hrefDynamicallyChanged",
|
|
];
|
|
await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "initially browsing-context connected <link> should trigger fetch", 5000);
|
|
assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionaries fetched for initially browsing-context connected <link>.");
|
|
fetchedDictionaries = [];
|
|
await new Promise(resolve => step_timeout(resolve, 1000));
|
|
assert_equals(fetchedDictionaries.length, 0, "no more dictionary fetched.");
|
|
|
|
// browsing-context connected change.
|
|
expectedEntries = [
|
|
"?linkDynamicallyBrowsingContextConnected",
|
|
];
|
|
document.head.appendChild(dynamicallyConnected);
|
|
await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "browsing-context connecting a link should trigger fetch", 5000);
|
|
assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionary fetched after <link> becomes browsing-context connected.");
|
|
fetchedDictionaries = [];
|
|
|
|
// Dynamic changes to href.
|
|
expectedEntries = [
|
|
"?hrefDynamicallyChangedBis",
|
|
"?hrefDynamicallySet",
|
|
];
|
|
hrefDynamicallySet.setAttribute("href", `${kRegisterDictionaryPath}?hrefDynamicallySet`);
|
|
hrefDynamicallyChanged.setAttribute("href", `${kRegisterDictionaryPath}?hrefDynamicallyChangedBis`);
|
|
await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "modifying href should trigger fetch", 5000);
|
|
assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionaries fetched after dynamic changes to href attribute.");
|
|
fetchedDictionaries = [];
|
|
|
|
// Dynamic change to rel.
|
|
expectedEntries = [
|
|
"?relDynamicallySet",
|
|
];
|
|
relDynamicallySet.setAttribute("rel", "compression-dictionary");
|
|
await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "setting rel should trigger fetch", 5000);
|
|
assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "dictionary fetched after setting the rel attribute.");
|
|
fetchedDictionaries = [];
|
|
|
|
// Dynamic changes to crossorigin.
|
|
expectedEntries = [
|
|
"?crossOriginDynamicallyChanged",
|
|
"?crossOriginDynamicallyRemoved",
|
|
"?crossOriginDynamicallySet",
|
|
];
|
|
crossOriginDynamicallySet.setAttribute("crossorigin", "use-credentials");
|
|
crossOriginDynamicallyChanged.setAttribute("crossorigin", "anonymous");
|
|
crossOriginDynamicallyRemoved.removeAttribute("crossorigin");
|
|
await t.step_wait(_ => fetchedDictionaries.length >= expectedEntries.length, "modifying crossorigin should trigger fetch", 5000);
|
|
assert_array_equals(fetchedDictionaries.toSorted(), expectedEntries, "fetched dictionaries after dynamic changes to crossorigin attribute.");
|
|
}, "<link rel=compression-dictionary> are fetched after DOM operations.");
|
|
</script>
|
|
</body>
|