-
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.
Bug: 1107415, whatwg/html#5878 Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
- Loading branch information
1 parent
2c83d2e
commit 99e559c
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
html/browsers/browsing-the-web/back-forward-cache/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,86 @@ | ||
<!DOCTYPE HTML> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="resources/helper.sub.js"></script> | ||
<script> | ||
// https://github.com/whatwg/html/issues/5878 | ||
promise_test(async t => { | ||
const pageA = new RemoteContext(token()); | ||
const pageB = new RemoteContext(token()); | ||
|
||
const urlA = executorPath + pageA.context_id + | ||
'&events=pagehide,pageshow,load'; | ||
const urlB = originCrossSite + executorPath + pageB.context_id; | ||
|
||
window.open(urlA, '_blank', 'noopener'); | ||
|
||
await pageA.execute_script(waitForPageShow); | ||
await pageA.execute_script( | ||
(url) => { | ||
// searchParams part of `url` (i.e. `uuid=` param) is passed via <input>, | ||
// while other parts are via <form action>. | ||
url = new URL(url); | ||
const targetId = url.searchParams.get('uuid'); | ||
url.search = ''; | ||
|
||
const form = document.createElement('form'); | ||
form.setAttribute('action', url.href); | ||
|
||
const idInput = document.createElement('input'); | ||
idInput.setAttribute('type', 'text'); | ||
idInput.setAttribute('name', 'uuid'); | ||
idInput.setAttribute('value', targetId); | ||
form.appendChild(idInput); | ||
|
||
const textInput = document.createElement('input'); | ||
textInput.setAttribute('type', 'text'); | ||
textInput.setAttribute('id', 'toBeFocused'); | ||
textInput.onfocus = () => { | ||
recordEvent('input.focus'); | ||
}; | ||
textInput.onblur = () => { | ||
recordEvent('input.blur'); | ||
}; | ||
form.appendChild(textInput); | ||
|
||
document.body.appendChild(form); | ||
|
||
textInput.focus(); | ||
|
||
prepareNavigation(() => { | ||
form.submit(); | ||
}); | ||
}, | ||
[urlB] | ||
); | ||
|
||
await pageB.execute_script(waitForPageShow); | ||
await pageB.execute_script( | ||
() => { | ||
prepareNavigation(() => { history.back(); }); | ||
} | ||
); | ||
|
||
await pageA.execute_script(waitForPageShow); | ||
await assert_bfcached(pageA); | ||
|
||
assert_true( | ||
await pageA.execute_script(() => { | ||
return document.activeElement === | ||
document.querySelector('#toBeFocused'); | ||
}), | ||
'Should be focused'); | ||
|
||
assert_array_equals( | ||
await pageA.execute_script(() => getRecordedEvents()), | ||
[ | ||
'window.load', | ||
'window.pageshow', | ||
'input.focus', | ||
'window.pagehide.persisted', | ||
'window.pageshow.persisted' | ||
]); | ||
}, 'Focus restored on BFCached navigation'); | ||
</script> |