Skip to content

Commit

Permalink
Use script instead of fetch to de-flake firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
noamr authored and sideshowbarker committed Jan 18, 2023
1 parent 8ae3007 commit 1423a32
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions preload/prefetch-cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
<script>

async function prefetch_and_count(cacheControl, t) {
const {href} = await prefetch({"cache-control": cacheControl, "type": "text/plain", content: "123"}, t);
await fetch(href);
const {href} = await prefetch({
"cache-control": cacheControl,
"type": "application/javascript",
content: "/**/"}, t);
const script = document.createElement("script");
script.src = href;
t.add_cleanup(() => script.remove());
const loaded = new Promise(resolve => script.addEventListener("load", resolve));
document.body.appendChild(script);
await loaded;
const info = await get_prefetch_info(href);
return info.length;
}

promise_test(async t => {
let result = 0;
// Sometimes the HTTP cache is not reliable. We want to see that the prefetch is reused in at
// least 1 out of 10 tries.
for (let i = 0; i < 10 && result !== 1; ++i) {
result = await prefetch_and_count("max-age=604800", t);
}
const result = await prefetch_and_count("max-age=604800", t);
assert_equals(result, 1);
}, "Prefetch should populate the HTTP cache");

Expand Down

0 comments on commit 1423a32

Please sign in to comment.