mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 1444491 - Update existing autofocus related WPTs to make them more robust r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D162035
This commit is contained in:
parent
6b5798cb94
commit
8e0155cf74
@ -10,9 +10,12 @@
|
||||
|
||||
promise_test(async () => {
|
||||
await waitForLoad(window);
|
||||
const iframe = document.querySelector('iframe');
|
||||
await waitUntilStableAutofocusState();
|
||||
assert_equals(document.activeElement, document.querySelector('iframe'),
|
||||
assert_equals(document.activeElement, iframe,
|
||||
'Autofocus elements in iframes should be focused.');
|
||||
const doc = iframe.contentDocument;
|
||||
assert_true(!doc.querySelector(':target'));
|
||||
|
||||
let input = document.createElement('input');
|
||||
input.autofocus = true;
|
||||
|
@ -21,7 +21,23 @@ promise_test(async () => {
|
||||
doc.body.appendChild(input);
|
||||
await waitUntilStableAutofocusState();
|
||||
assert_not_equals(doc.activeElement, input);
|
||||
}, 'Autofocus elements in iframed documents with URL fragments should be skipped.');
|
||||
iframe.remove();
|
||||
}, 'Autofocus elements in iframed documents with URL fragments should be skipped. (id matches)');
|
||||
|
||||
promise_test(async () => {
|
||||
let iframe = await waitForIframeLoad("resources/frame-with-a.html");
|
||||
iframe.contentWindow.location.hash = 'anchor1';
|
||||
await waitForEvent(iframe.contentWindow, 'hashchange');
|
||||
const doc = iframe.contentDocument;
|
||||
assert_true(!!doc.querySelector(':target'));
|
||||
|
||||
let input = doc.createElement('input');
|
||||
input.autofocus = true;
|
||||
doc.body.appendChild(input);
|
||||
await waitUntilStableAutofocusState();
|
||||
assert_not_equals(doc.activeElement, input);
|
||||
iframe.remove();
|
||||
}, 'Autofocus elements in iframed documents with URL fragments should be skipped.(a element)');
|
||||
|
||||
promise_test(async () => {
|
||||
let w = window.open('resources/frame-with-anchor.html');
|
||||
|
@ -0,0 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
<a name="anchor1"></a>
|
||||
</body>
|
@ -39,3 +39,13 @@ async function waitUntilStableAutofocusState(w) {
|
||||
// Awaiting one animation frame is an easy way to determine autofocus state.
|
||||
await waitForAnimationFrame(targetWindow);
|
||||
}
|
||||
|
||||
async function waitForIframeLoad(src, w = window) {
|
||||
const iframe = w.document.createElement("iframe");
|
||||
let loadPromise = new Promise(resolve => {
|
||||
iframe.addEventListener("load", () => resolve(iframe));
|
||||
});
|
||||
iframe.src = src;
|
||||
w.document.body.appendChild(iframe);
|
||||
return loadPromise;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
'use strict';
|
||||
|
||||
promise_test(async () => {
|
||||
await waitForEvent(document.body, 'focus', {capture:true});
|
||||
await waitForLoad(window);
|
||||
await waitForAnimationFrame();
|
||||
assert_equals(document.activeElement.id, 'second');
|
||||
}, 'Script-blocking style sheet should pause flushing autofocus candidates.');
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user