Automatic update from web-platform-tests Add multiple tests for prefetch behavior See https://github.com/whatwg/html/pull/8111#issuecomment-1229907894 Tests that: * preload/prefetch-cache.html No 5 minute rule (cache headers must be respected) * preload/prefetch-document.html No special treatment of as=document Whether Accept is left as its default value. Storage partitioning is applied, including for documents * preload/prefetch-load-event.html Does not block the load event * preload/prefetch-headers.html Whether any additional headers (Sec-Purpose, Purpose, X-moz, X-Purpose) are sent (depending on what we put in the spec) * preload/prefetch-types.html Always uses prefetch destination, and ignores as="" -- Add tests for load/error events -- Add cross-origin event tests -- Test for proprietary headers -- Add test cases for cross-origin error events -- Update preload/prefetch-cache.html Co-authored-by: Domenic Denicola <d@domenic.me> -- Fix CR comments -- Clean up doc test -- Retries in cache test -- Use script instead of fetch to de-flake firefox -- wpt-commits: 56746bfcf1b8eae23f81f69c144d54bb7441b9c6, 9e12c604be29a47a730ecdb3c1382e678eb9eca4, a221f4091d67ca56f9218929ab019b4b9c2f2302, 5fe9b213f64e80cddb5de0aa8debec29f5ab20ad, 67113e16693e30945f2d2b71a8a4b3f556fe4353, c03154bde9e293f82a631b80f841908c25927493, 18faf32573d6d83c1932167e23bb8f6c37df3eb1, 8f2af79a66aeaece84373ce5e24023edb2c55f08, 8ae300754a3dd226cd58b3fd53e270cf141c28fc, 1423a3236683cc4856158c54e9f8f29eef3d2871 wpt-pr: 35707
37 lines
1.3 KiB
HTML
37 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<title>Ensures that prefetch respects HTTP cache semantics</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/utils.js"></script>
|
|
<script src="resources/prefetch-helper.js"></script>
|
|
<body>
|
|
<script>
|
|
|
|
async function prefetch_and_count(cacheControl, t) {
|
|
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 => {
|
|
const result = await prefetch_and_count("max-age=604800", t);
|
|
assert_equals(result, 1);
|
|
}, "Prefetch should populate the HTTP cache");
|
|
|
|
for (const cacheControl of ["no-cache", "no-store", "max-age=0"]) {
|
|
promise_test(async t => {
|
|
const result = await prefetch_and_count(cacheControl, t);
|
|
assert_equals(result, 2);
|
|
}, `Prefetch should respect cache-control: ${cacheControl}`);
|
|
}
|
|
</script>
|
|
</body> |