-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 non-prerendering navigation
In these test cases (except for "<a>" subtest), sourceDocument is different from navigable's active document, and thus the behavior is affected by WICG/nav-speculation#267. Chromium's status: - "<a>" subtest - already passing - "location.href across iframe" subtest - failing, will pass after [1]. - Other tests - failing even after [1] (https://crbug.com/1432886). [1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403 Bug: 1432886, WICG/nav-speculation#267 Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
- Loading branch information
1 parent
ede73e9
commit ce9ded3
Showing
4 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<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> |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<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> |
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
<!DOCTYPE html> | ||
<meta name="variant" content="?cross-site"> | ||
<meta name="variant" content="?same-site"> | ||
<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