Skip to content

Commit 3124d2f

Browse files
fred-wangmoz-wptsync-bot
authored andcommitted
Bug 2052067 [wpt PR 61030] - [compression dictionary] Add WPT test to check fetch timing for Link header and <link> element., a=testonly
Automatic update from web-platform-tests [compression dictionary] Add WPT test to check fetch timing for Link header and <link> element. This is currently not specified but there some discussions happening at whatwg/html#11620 and this is important for performance reasons. Bug: 522338661, 40255884 Change-Id: Id1494aa3693b24afaf75dae4e0f5ef5909fce9e1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7922747 Commit-Queue: Frédéric Wang Nélar <fwang@igalia.com> Reviewed-by: Patrick Meenan <pmeenan@chromium.org> Reviewed-by: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/main@{#1655866} -- wpt-commits: b62d7567fd2df9b5a40788a2e9a42f9de756fc21 wpt-pr: 61030
1 parent f757272 commit 3124d2f

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset="utf-8">
4+
<meta name="timeout" content="long"/>
5+
<script src="./resources/compression-dictionary-util.sub.js"></script>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<link rel="help" href="https://github.com/whatwg/html/pull/11620#discussion_r3385960016">
9+
<body>
10+
<script>
11+
compression_dictionary_promise_test(async t => {
12+
let sortedEvents = await new Promise(resolve => {
13+
const iframe = document.createElement("iframe");
14+
iframe.src = "resources/dictionary-fetch-timing-001-subframe.https.html";
15+
window.addEventListener("message", message => resolve(message.data.sortedEvents));
16+
document.body.appendChild(iframe);
17+
t.add_cleanup(() => iframe.remove());
18+
});
19+
20+
// First verify observed fetches and load event...
21+
const fetchedNonDictionaryResources = [
22+
"/common/utils.js",
23+
"/html/semantics/document-metadata/interactions-of-styling-and-scripting/stylesheet.py?delay=1",
24+
"/images/wide-gamut-pattern.png",
25+
];
26+
const fetchedLinkElement = "/fetch/compression-dictionary/resources/register-dictionary.py?linkElement";
27+
const fetchedLinkHeader = "/fetch/compression-dictionary/resources/register-dictionary.py?linkHeader";
28+
const loadEvent = "load event";
29+
let expectedEvents = fetchedNonDictionaryResources.concat([fetchedLinkElement, fetchedLinkHeader, loadEvent]);
30+
assert_array_equals(sortedEvents.toSorted(), expectedEvents.toSorted(), "Expected fetches and loaded events observed.");
31+
32+
// Non-dictionary resources are fetched before dictionary resources.
33+
let indexOfLinkElement = sortedEvents.indexOf(fetchedLinkElement);
34+
let indexOfLinkHeader = sortedEvents.indexOf(fetchedLinkHeader);
35+
for (const resource of fetchedNonDictionaryResources) {
36+
let indexOfResource = sortedEvents.indexOf(resource);
37+
assert_less_than(indexOfResource, indexOfLinkElement, `${resource} fetched before link element with rel=compression-dictionary.`);
38+
assert_less_than(indexOfResource, indexOfLinkHeader, `${resource} fetched before Link header with rel=compression-dictionary.`);
39+
};
40+
41+
// Fetching link header is postponed after page load.
42+
let indexOfLoadEvent = sortedEvents.indexOf(loadEvent);
43+
assert_less_than(indexOfLoadEvent, indexOfLinkHeader, `Link header with rel=compression-dictionary is fetched after page load.`);
44+
}, "Timing of compression dictionary fetches for <link> element and Link header.");
45+
</script>
46+
</body>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<script>
3+
let timedEntries = [];
4+
const observer = new PerformanceObserver((list) => {
5+
list.getEntries().forEach(entry => {
6+
const url = new URL(entry.name);
7+
timedEntries.push({pathname: url.pathname, search: url.search, time: entry.fetchStart});
8+
});
9+
});
10+
observer.observe({ type: "resource", buffered: true});
11+
</script>
12+
<link rel="compression-dictionary" href="./register-dictionary.py?linkElement">
13+
<link rel="stylesheet" href="/html/semantics/document-metadata/interactions-of-styling-and-scripting/stylesheet.py?delay=1">
14+
<script src="/common/utils.js"></script>
15+
<img src="/images/wide-gamut-pattern.png"/>
16+
<script>
17+
window.addEventListener("load", _ => {
18+
timedEntries.push({name: "load event", time: performance.now()});
19+
function waitForDictionaryLoad() {
20+
if (timedEntries.find(e => e.search === "?linkHeader") &&
21+
timedEntries.find(e => e.search === "?linkElement")) {
22+
let sortedEvents = timedEntries.
23+
sort((entry1, entry2) => entry1.time - entry2.time).
24+
map(entry => entry.name || entry.pathname + entry.search);
25+
window.parent.postMessage({sortedEvents});
26+
return;
27+
}
28+
(window.requestIdleCallback || requestAnimationFrame)(waitForDictionaryLoad);
29+
}
30+
waitForDictionaryLoad();
31+
});
32+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Clear-Site-Data: "cache"
2+
Link: <./register-dictionary.py?linkHeader>; rel="compression-dictionary"

0 commit comments

Comments
 (0)