-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WPT] Use sourceDocument for prefetch record lookup
WPT updates for WICG/nav-speculation#267: - Updated the expected behavior for an existing test: `prerender/prefetch.https.html`. - Added other prefetch test cases. Except for "<a>" subtest, `sourceDocument` is different from `navigable's active document`. Chromium's status: - "<a>" 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, WICG/nav-speculation#267 Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475 Reviewed-by: Domenic Denicola <domenic@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#1141005}
- Loading branch information
1 parent
7ac59b9
commit c209438
Showing
5 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
speculation-rules/prefetch/initiators-a-element.sub.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="resources/utils.sub.js"></script> | ||
<script> | ||
// In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, | ||
// `sourceDocument` (instead of `navigable`'s active document) should be | ||
// used as the referring document for prefetch. | ||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
const win = await spawnWindow(t, { protocol: 'https' }); | ||
|
||
const hostname = | ||
location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; | ||
const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); | ||
|
||
await win.forceSinglePrefetch(nextUrl); | ||
|
||
// sourceDocument == `win`'s Document == active document of window being | ||
// navigated. | ||
await win.execute_script((url) => { | ||
window.executor.suspend(() => { | ||
const a = document.createElement('a'); | ||
a.setAttribute('href', url); | ||
document.body.appendChild(a); | ||
a.click(); | ||
}); | ||
}, [nextUrl]); | ||
|
||
assert_equals( | ||
await win.execute_script(() => location.href), | ||
nextUrl.toString(), | ||
"expected navigation to reach destination URL"); | ||
|
||
assert_prefetched(await win.getRequestHeaders()); | ||
}, `<a>`); | ||
|
||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
const win = await spawnWindow(t, { protocol: 'https' }); | ||
|
||
const hostname = | ||
location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; | ||
const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); | ||
|
||
await win.forceSinglePrefetch(nextUrl); | ||
|
||
// sourceDocument == `win`'s Document != active document of window being | ||
// navigated, since the window being navigated is a new window. | ||
await win.execute_script((url) => { | ||
window.executor.suspend(() => { | ||
const a = document.createElement('a'); | ||
a.setAttribute('href', url); | ||
a.setAttribute('target', '_blank'); | ||
document.body.appendChild(a); | ||
a.click(); | ||
}); | ||
}, [nextUrl]); | ||
|
||
// Below, the scripts given to `win.execute_script()` are executed on the | ||
// `nextUrl` page in the new window, because `window.executor.suspend()` | ||
// above made `win`'s original page stop processing `execute_script()`, | ||
// while the new page of `nextUrl` in the new window starts processing | ||
// `execute_script()` for the same ID. | ||
assert_equals( | ||
await win.execute_script(() => location.href), | ||
nextUrl.toString(), | ||
"expected navigation to reach destination URL"); | ||
|
||
assert_prefetched(await win.getRequestHeaders()); | ||
}, `<a target="blank">`); | ||
</script> |
48 changes: 48 additions & 0 deletions
48
speculation-rules/prefetch/initiators-iframe-location-href.sub.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="resources/utils.sub.js"></script> | ||
<script> | ||
// In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, | ||
// `sourceDocument` (instead of `navigable`'s active document) should be | ||
// used as the referring document for prefetch. | ||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
const win = await spawnWindow(t, { protocol: 'https' }); | ||
|
||
const hostname = | ||
location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; | ||
const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); | ||
|
||
await win.forceSinglePrefetch(nextUrl); | ||
|
||
// In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, | ||
// `sourceDocument` is the incumbent Document and thus `win`'s Document. | ||
// `navigable`'s active document is `iframe`'s Document. | ||
await win.execute_script((url) => { | ||
window.executor.suspend(() => { | ||
const iframe = document.createElement('iframe'); | ||
document.body.appendChild(iframe); | ||
iframe.contentWindow.location.href = url; | ||
}); | ||
}, [nextUrl]); | ||
|
||
// Below, the scripts given to `win.execute_script()` are executed on the | ||
// `nextUrl` page in the iframe, because `window.executor.suspend()` above | ||
// made `win`'s original page stop processing `execute_script()`, | ||
// while the new page of `nextUrl` in the iframe starts processing | ||
// `execute_script()` for the same ID. | ||
assert_equals( | ||
await win.execute_script(() => location.href), | ||
nextUrl.toString(), | ||
"expected navigation to reach destination URL"); | ||
|
||
assert_prefetched(await win.getRequestHeaders()); | ||
}, `location.href across iframe`); | ||
</script> |
68 changes: 68 additions & 0 deletions
68
speculation-rules/prefetch/initiators-window-open.sub.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="resources/utils.sub.js"></script> | ||
<script> | ||
// In https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate, | ||
// `sourceDocument` (instead of `navigable`'s active document) should be | ||
// used as the referring document for prefetch. | ||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
const win = await spawnWindow(t, { protocol: 'https' }); | ||
|
||
const hostname = | ||
location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; | ||
const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); | ||
|
||
await win.forceSinglePrefetch(nextUrl); | ||
|
||
await win.execute_script((url) => { | ||
window.executor.suspend(() => { | ||
window.open(url, "_blank"); | ||
}); | ||
}, [nextUrl]); | ||
|
||
// Below, the scripts given to `win.execute_script()` are executed on the | ||
// `nextUrl` page in the new window, because `window.executor.suspend()` | ||
// above made `win`'s original page stop processing `execute_script()`, | ||
// while the new page of `nextUrl` in the new window starts processing | ||
// `execute_script()` for the same ID. Same for below. | ||
assert_equals( | ||
await win.execute_script(() => location.href), | ||
nextUrl.toString(), | ||
"expected navigation to reach destination URL"); | ||
|
||
assert_prefetched(await win.getRequestHeaders()); | ||
}, `window.open()`); | ||
|
||
promise_test(async t => { | ||
assert_implements(HTMLScriptElement.supports('speculationrules'), "Speculation Rules not supported"); | ||
|
||
const win = await spawnWindow(t, { protocol: 'https' }); | ||
|
||
const hostname = | ||
location.search === '?cross-site' ? '{{hosts[alt][www]}}' : undefined; | ||
const nextUrl = win.getExecutorURL({ protocol: 'https', hostname, page: 2 }); | ||
|
||
await win.forceSinglePrefetch(nextUrl); | ||
|
||
await win.execute_script((url) => { | ||
window.executor.suspend(() => { | ||
window.open(url, "_blank", "noopener"); | ||
}); | ||
}, [nextUrl]); | ||
|
||
assert_equals( | ||
await win.execute_script(() => location.href), | ||
nextUrl.toString(), | ||
"expected navigation to reach destination URL"); | ||
|
||
assert_prefetched(await win.getRequestHeaders()); | ||
}, `window.open(noopener)`); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters