From a812b84cd1cb7fdd7246b2ab04a399fc27515d6d Mon Sep 17 00:00:00 2001 From: Hiroshige Hayashizaki Date: Mon, 8 May 2023 12:49:24 -0700 Subject: [PATCH] [WPT] Use sourceDocument for prefetch record lookup WPT updates for https://github.com/WICG/nav-speculation/pull/267: - Updated the expected behavior for an existing test: `prerender/prefetch.https.html`. - Added other prefetch test cases. Except for "" subtest, `sourceDocument` is different from `navigable's active document`. Chromium's status: - "" subtest - already passing - Others -- failing. Some of them will pass after [1], and remaining failures after [1] are tracked by https://crbug.com/1432886. [1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403 Bug: 1440607, 1432886, 1422815, https://github.com/WICG/nav-speculation/pull/267 Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475 Reviewed-by: Domenic Denicola Commit-Queue: Hiroshige Hayashizaki Cr-Commit-Position: refs/heads/main@{#1141005} --- .../initiators-a-element.sub.https.html | 79 +++++++++++++++++++ ...iators-iframe-location-href.sub.https.html | 48 +++++++++++ .../initiators-window-open.sub.https.html | 68 ++++++++++++++++ .../prefetch-traverse-reload.sub.html | 30 +++++++ .../prerender/prefetch.https.html | 4 +- 5 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 speculation-rules/prefetch/initiators-a-element.sub.https.html create mode 100644 speculation-rules/prefetch/initiators-iframe-location-href.sub.https.html create mode 100644 speculation-rules/prefetch/initiators-window-open.sub.https.html 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");