mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Automatic update from web-platform-tests Ship PrefetchFollowsNormalCacheSemantics This removes the "5-minute rule" for prefetches, where they ignore normal HTTP cache semantics for 5 minutes and instead stay cached in the HTTP cache. This applies to <link rel=prefetch>, NoStatePrefetch (i.e. <link rel=prerender>), and speculation rules prefetch. Note that for speculation rules prefetch, because there is the separate in-memory speculation rules prefetch cache, 2xx responses without caching headers will still be stored in that in-memory cache. They just won't be HTTP cached, in a way that was counter to the website's expressed preferences. Shipping this was approved back in May 2023, with an accompanying Finch study to check for regressions [1]. However, we forgot to actually change the default. This is of new urgency now because of the impact on speculation rules prefetch, which is is causing web developer pain. A web platform test is included for the specific painful scenario, which fails before this change and passes afterward. Most of this CL consists of test updates: many of our tests relied on not needing caching headers to make <link rel=prefetch> or <link rel=prerender> work, and so do things like assume there will never be a second request to those URLs. The general fix is to apply caching headers to the resources in question, as that represents the intended real-world usage of <link rel=prefetch>. (And, to a lesser extent, the nonstandard and hopefully-one-day-removed <link rel=prerender>.) Notably, the WPT prefetch-document.html was failing in all browsers before this, including in Firefox which has a highly spec-conformant implementation. It should now be passing. PrerendererImplBrowserTestPrefetchAhead.PrefetchSuccessPrefetchMatchResolverTimeoutPrerenderFailure was disabled, since it appears to never have been working as expected, with the HTTP caching hiding the real problem. Issue 372851198 tracks fixing that test. Tests specifically for the 5-minute rule were deleted. [1]: https://groups.google.com/a/chromium.org/g/blink-dev/c/Zdo71C0k9C0 Bug: 40232065, 381099745, 356624471, 372851198 Change-Id: I7d42c43efd89486587d8b7fc8ddd4412b31ef0bf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6056830 Reviewed-by: Rakina Zata Amni <[email protected]> Commit-Queue: Domenic Denicola <[email protected]> Reviewed-by: Adam Rice <[email protected]> Reviewed-by: Hiroki Nakagawa <[email protected]> Cr-Commit-Position: refs/heads/main@{#1390213} -- wpt-commits: 6083f4367aead38c31ac0c329bb07abf731219f4 wpt-pr: 49452
64 lines
2.6 KiB
HTML
64 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<title>Ensures that prefetch works with documents</title>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/utils.js"></script>
|
|
<script src="/common/get-host-info.sub.js"></script>
|
|
<script src="/common/dispatcher/dispatcher.js"></script>
|
|
<script src="resources/prefetch-helper.js"></script>
|
|
<body>
|
|
<script>
|
|
|
|
const {ORIGIN, REMOTE_ORIGIN, HTTP_NOTSAMESITE_ORIGIN} = get_host_info();
|
|
|
|
async function prefetch_document_and_count_fetches(options, t) {
|
|
const {href, uid} = await prefetch({
|
|
"cache-control": "public, max-age=3600",
|
|
file: "prefetch-exec.html",
|
|
type: "text/html",
|
|
corssOrigin: "anonymous",
|
|
...options});
|
|
const popup = window.open(href);
|
|
const remoteContext = new RemoteContext(uid);
|
|
t.add_cleanup(() => popup.close());
|
|
const result = await remoteContext.execute_script(() => "OK");
|
|
assert_equals(result, "OK");
|
|
const requests = await get_prefetch_info(href);
|
|
return requests.length;
|
|
}
|
|
|
|
promise_test(async t => {
|
|
assert_equals(await prefetch_document_and_count_fetches({origin: ORIGIN}, t), 1);
|
|
}, "same origin document prefetch without 'as' should be consumed");
|
|
|
|
promise_test(async t => {
|
|
// This (pre-)fetch will be blocked by ORB, which will prevent it from
|
|
// being cached. Thus this prefetch is not consumed.
|
|
assert_equals(await prefetch_document_and_count_fetches({origin: REMOTE_ORIGIN}, t), 2);
|
|
}, "same-site different-origin document prefetch without 'as' should not be consumed");
|
|
|
|
promise_test(async t => {
|
|
assert_equals(await prefetch_document_and_count_fetches({origin: HTTP_NOTSAMESITE_ORIGIN}, t), 2);
|
|
}, "different-site document prefetch without 'as' should not be consumed");
|
|
|
|
promise_test(async t => {
|
|
assert_equals(await prefetch_document_and_count_fetches({origin: HTTP_NOTSAMESITE_ORIGIN, as: "document"}, t), 2);
|
|
}, "different-site document prefetch with 'as=document' should not be consumed");
|
|
|
|
promise_test(async t => {
|
|
const {href, uid} = await prefetch({
|
|
file: "prefetch-exec.html",
|
|
type: "text/html",
|
|
corssOrigin: "anonymous",
|
|
origin: ORIGIN});
|
|
const popup = window.open(href + "&cache_bust=" + token());
|
|
const remoteContext = new RemoteContext(uid);
|
|
t.add_cleanup(() => popup.close());
|
|
await remoteContext.execute_script(() => "OK");
|
|
const results = await get_prefetch_info(href);
|
|
assert_equals(results.length, 2);
|
|
assert_equals(results[0].headers.accept, results[1].headers.accept);
|
|
}, "Document prefetch should send the exact Accept header as navigation")
|
|
</script>
|
|
</body>
|