diff --git a/speculation-rules/prefetch/initiators-a-element.sub.https.html b/speculation-rules/prefetch/initiators-a-element.sub.https.html new file mode 100644 index 00000000000000..bac5eb7cb794e0 --- /dev/null +++ b/speculation-rules/prefetch/initiators-a-element.sub.https.html @@ -0,0 +1,79 @@ + + + + + + + + + + diff --git a/speculation-rules/prefetch/initiators-iframe-location-href.sub.https.html b/speculation-rules/prefetch/initiators-iframe-location-href.sub.https.html new file mode 100644 index 00000000000000..9d6702d4b752ad --- /dev/null +++ b/speculation-rules/prefetch/initiators-iframe-location-href.sub.https.html @@ -0,0 +1,48 @@ + + + + + + + + + + diff --git a/speculation-rules/prefetch/initiators-window-open.sub.https.html b/speculation-rules/prefetch/initiators-window-open.sub.https.html new file mode 100644 index 00000000000000..f786df077dbfe1 --- /dev/null +++ b/speculation-rules/prefetch/initiators-window-open.sub.https.html @@ -0,0 +1,68 @@ + + + + + + + + + + diff --git a/speculation-rules/prefetch/prefetch-traverse-reload.sub.html b/speculation-rules/prefetch/prefetch-traverse-reload.sub.html index 3f1312ed1222ad..ec6a7cd9261579 100644 --- a/speculation-rules/prefetch/prefetch-traverse-reload.sub.html +++ b/speculation-rules/prefetch/prefetch-traverse-reload.sub.html @@ -28,6 +28,36 @@ assert_prefetched(await agent.getRequestHeaders(), "traversal should use prefetch"); }, "prefetches can be used for traversal navigations"); +promise_test(async t => { + assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); + + let agent = await spawnWindow(t, { protocol: 'https', pipe: 'header(Cache-Control, no-store)' }); + let previousUrl = await agent.execute_script(() => location.href); + await agent.execute_script(async () => { + window.preventBfcache = new WebSocket('wss://{{ports[wss][0]}}/echo'); + }); + + let nextUrl = agent.getExecutorURL({ protocol: 'https', page: 2 }); + await agent.navigate(nextUrl); + + await agent.forceSinglePrefetch(previousUrl); + // In https://html.spec.whatwg.org/multipage/nav-history-apis.html#delta-traverse, + // `sourceDocument` is `History`'s relevant global object's associated + // Document. In this case, it's `iframe.contentDocument`, and thus the + // prefetch from `win`'s Document (iframe's parent Document) isn't used. + await agent.execute_script(() => { + window.executor.suspend(() => { + const iframe = document.createElement('iframe'); + document.body.appendChild(iframe); + iframe.contentWindow.history.go(-1); + }); + }); + + assert_equals(previousUrl, await agent.execute_script(() => location.href)); + assert_not_prefetched(await agent.getRequestHeaders(), + "prefetch from different Document should not be used"); +}, "History's Document is used for traversal navigations"); + promise_test(async t => { assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); diff --git a/speculation-rules/prerender/prefetch.https.html b/speculation-rules/prerender/prefetch.https.html index 48de5adca13e0a..2a1553b3d94bb7 100644 --- a/speculation-rules/prerender/prefetch.https.html +++ b/speculation-rules/prerender/prefetch.https.html @@ -15,7 +15,7 @@ await create_prerendered_page(t, {}, {prefetch: true}, {}); assert_equals(await tryToActivate(), 'activated'); - assert_equals(await getNetworkRequestCount(), '2', 'Network request count'); -}, "Prerender navigation requests don't use prefetched results (for now)"); + assert_equals(await getNetworkRequestCount(), '1', 'Network request count'); +}, "Prerender navigation requests should use prefetched results");