-
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.
Prerender: upstream wpt_internal/prerender/restriction-focus.html
The behavior is described in https://jeremyroman.github.io/alternate-loading-modes/prerendering.html#interaction-with-system-focus Bug: 1253158 Change-Id: I292298355d0880160bf78837ed0a8413585f3078 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3229409 Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Commit-Queue: Lingqi Chi <lingqi@chromium.org> Cr-Commit-Position: refs/heads/main@{#932946}
- Loading branch information
1 parent
8777fe5
commit 679cfd4
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
speculation-rules/prerender/resources/prerender-focus.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,25 @@ | ||
<!DOCTYPE html> | ||
<title>Check the focus state of prerendering pages</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<input type="text" id = "prerenderTextField"> | ||
<script> | ||
|
||
// Check this page is being prerendered. | ||
assert_true(document.prerendering); | ||
|
||
const bc = new BroadcastChannel('prerender-channel'); | ||
|
||
// Try to set focus. | ||
const element = document.getElementById('prerenderTextField'); | ||
element.focus(); | ||
|
||
// Post the focus and active states to the initiator page. | ||
bc.postMessage({ | ||
activeElementUpdated: document.activeElement === element, | ||
documentHasFocus: document.hasFocus()}); | ||
bc.close(); | ||
|
||
</script> | ||
</body> |
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,37 @@ | ||
<!DOCTYPE html> | ||
<title>Prerendering documents are not focused</title> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/utils.js"></script> | ||
<body> | ||
<input type="text" id = "prerenderTextField"> | ||
<script> | ||
|
||
setup(() => assertSpeculationRulesIsSupported()); | ||
|
||
promise_test(async t => { | ||
const bc = new BroadcastChannel('prerender-channel'); | ||
|
||
document.getElementById('prerenderTextField').focus(); | ||
assert_true( | ||
document.hasFocus(), | ||
'Initial document should have focus.'); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, {once:true}); | ||
}); | ||
|
||
// Start prerendering a page that accesses the focus state of the page. | ||
startPrerendering(`resources/prerender-focus.html`); | ||
|
||
const result = await gotMessage; | ||
assert_true(result.activeElementUpdated); | ||
assert_false(result.documentHasFocus); | ||
bc.close(); | ||
}, 'Prerendering document should update the active element but not have focus'); | ||
|
||
</script> | ||
</body> |