Skip to content

Commit f995712

Browse files
HuanPo Linchromium-wpt-export-bot
HuanPo Lin
authored andcommitted
prefetch: Allow GET method only
Currently, only GET method is available for Prefetch. https://source.chromium.org/chromium/chromium/src/+/1000eee6f34cd07615837de97c95fd5588c9097d:content/browser/preloading/prefetch/prefetch_container.cc;l=1766;bpv=1;bpt=0 spec: https://wicg.github.io/nav-speculation/prefetch.html#create-navigation-params-from-a-prefetch-record This CL prevents other methods from using the cached prefetch results. Bug: 415942154 Change-Id: I621965073bb502046429e0e0c6fd0ccb50684626 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6512394 Reviewed-by: Taiyo Mizuhashi <[email protected]> Commit-Queue: Huanpo Lin <[email protected]> Reviewed-by: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/main@{#1465744}
1 parent 3ffda23 commit f995712

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<meta name="timeout" content="long">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/dispatcher/dispatcher.js"></script>
6+
<script src="/common/utils.js"></script>
7+
<script src="../resources/utils.js"></script>
8+
<script src="resources/utils.sub.js"></script>
9+
<script>
10+
setup(() => assertSpeculationRulesIsSupported());
11+
12+
promise_test(async t => {
13+
let agent = await spawnWindow(t);
14+
let nextUrl = agent.getExecutorURL({ executor: 'post-navigation-handler.py', protocol: 'https', page: 2 });
15+
await agent.forceSinglePrefetch(nextUrl);
16+
17+
await agent.execute_script(async (nextUrl) => {
18+
window.executor.suspend(() => {
19+
navigate_by_form_generated_post(nextUrl);
20+
});
21+
}, [nextUrl]);
22+
23+
assert_not_prefetched(await agent.getRequestHeaders());
24+
}, "post navigations should not use cached prefetch");
25+
</script>

speculation-rules/prefetch/resources/executor.sub.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
await new test_driver.Actions().addPointer("mouse").pointerMove(0, 0, {origin: target}).pointerDown().pointerMove(0, 0).pointerUp().send();
8383
}
8484

85+
async function navigate_by_form_generated_post(url) {
86+
let form = document.createElement('form');
87+
form.method = 'POST';
88+
form.action = url;
89+
document.body.appendChild(form);
90+
form.submit();
91+
}
8592

8693
// The fetch request's URL sent to the server.
8794
window.requestUrl = reverse_html_escape(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from wptserve.pipes import template
3+
4+
# This is used only to accept POST navigations.
5+
def main(request, response):
6+
response.headers.set(b"Content-Type", b"text/html")
7+
response.headers.set(b"Cache-Control", b"no-store")
8+
response.content = template(
9+
request,
10+
open(os.path.join(os.path.dirname(__file__), "executor.sub.html"), "rb").read())

0 commit comments

Comments
 (0)