Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!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#discussion_r3385960016">
<body>
<script>
compression_dictionary_promise_test(async t => {
let sortedEvents = await new Promise(resolve => {
const iframe = document.createElement("iframe");
iframe.src = "resources/dictionary-fetch-timing-001-subframe.https.html";
window.addEventListener("message", message => resolve(message.data.sortedEvents));
document.body.appendChild(iframe);
t.add_cleanup(() => iframe.remove());
});

// First verify observed fetches and load event...
const fetchedNonDictionaryResources = [
"/common/utils.js",
"/html/semantics/document-metadata/interactions-of-styling-and-scripting/stylesheet.py?delay=1",
"/images/wide-gamut-pattern.png",
];
const fetchedLinkElement = "/fetch/compression-dictionary/resources/register-dictionary.py?linkElement";
const fetchedLinkHeader = "/fetch/compression-dictionary/resources/register-dictionary.py?linkHeader";
const loadEvent = "load event";
let expectedEvents = fetchedNonDictionaryResources.concat([fetchedLinkElement, fetchedLinkHeader, loadEvent]);
assert_array_equals(sortedEvents.toSorted(), expectedEvents.toSorted(), "Expected fetches and loaded events observed.");

// Non-dictionary resources are fetched before dictionary resources.
let indexOfLinkElement = sortedEvents.indexOf(fetchedLinkElement);
let indexOfLinkHeader = sortedEvents.indexOf(fetchedLinkHeader);
for (const resource of fetchedNonDictionaryResources) {
let indexOfResource = sortedEvents.indexOf(resource);
assert_less_than(indexOfResource, indexOfLinkElement, `${resource} fetched before link element with rel=compression-dictionary.`);
assert_less_than(indexOfResource, indexOfLinkHeader, `${resource} fetched before Link header with rel=compression-dictionary.`);
};

// Fetching link header is postponed after page load.
let indexOfLoadEvent = sortedEvents.indexOf(loadEvent);
assert_less_than(indexOfLoadEvent, indexOfLinkHeader, `Link header with rel=compression-dictionary is fetched after page load.`);
}, "Timing of compression dictionary fetches for <link> element and Link header.");
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<script>
let timedEntries = [];
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach(entry => {
const url = new URL(entry.name);
timedEntries.push({pathname: url.pathname, search: url.search, time: entry.fetchStart});
});
});
observer.observe({ type: "resource", buffered: true});
</script>
<link rel="compression-dictionary" href="./register-dictionary.py?linkElement">
<link rel="stylesheet" href="/html/semantics/document-metadata/interactions-of-styling-and-scripting/stylesheet.py?delay=1">
<script src="/common/utils.js"></script>
<img src="/images/wide-gamut-pattern.png"/>
<script>
window.addEventListener("load", _ => {
timedEntries.push({name: "load event", time: performance.now()});
function waitForDictionaryLoad() {
if (timedEntries.find(e => e.search === "?linkHeader") &&
timedEntries.find(e => e.search === "?linkElement")) {
let sortedEvents = timedEntries.
sort((entry1, entry2) => entry1.time - entry2.time).
map(entry => entry.name || entry.pathname + entry.search);
window.parent.postMessage({sortedEvents});
return;
}
(window.requestIdleCallback || requestAnimationFrame)(waitForDictionaryLoad);
}
waitForDictionaryLoad();
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Clear-Site-Data: "cache"
Link: <./register-dictionary.py?linkHeader>; rel="compression-dictionary"
Loading