Skip to content

Commit

Permalink
Bug 1593925 [wpt PR 20083] - autofocus: Add tests for delegatesFocus …
Browse files Browse the repository at this point in the history
…and <area>., a=testonly

Automatic update from web-platform-tests
autofocus: Add tests for delegatesFocus and <area>

Follows whatwg/html#5059.
--

wpt-commits: 4cfddceea40940f2d8290bb92d081824fe781942
wpt-pr: 20083

UltraBlame original commit: c2b6f23092d76bffaa131715c54ec5dfd9009d18
  • Loading branch information
marco-c committed Nov 30, 2019
1 parent 1119531 commit 9d5949c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<body>
<img src="/media/poster.png" usemap="#map">
<map name="map"></map>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,50 @@
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement.tagName, 'BODY');
}, 'Non-HTMLElement should not support autofocus');

promise_test(async t => {
let w = window.open('/common/blank.html');
await waitForLoad(w);
t.add_cleanup(() => { w.close(); });
const host = w.document.createElement('div');
host.autofocus = true;
const shadow = host.attachShadow({mode:'closed', delegatesFocus:true});
shadow.appendChild(w.document.createElement('input'));
w.document.body.appendChild(host);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, host);
assert_equals(shadow.activeElement.tagName, 'INPUT');
}, 'Host element with delegatesFocus should support autofocus');

promise_test(async t => {
let w = window.open('/common/blank.html');
await waitForLoad(w);
t.add_cleanup(() => { w.close(); });
const host = w.document.createElement('div');
host.autofocus = true;
host.attachShadow({mode:'closed', delegatesFocus:true});
w.document.body.appendChild(host);
const next = w.document.createElement('input');
next.autofocus = true;
w.document.body.appendChild(next);
await waitUntilStableAutofocusState(w);
assert_equals(w.document.activeElement, next);
}, 'Host element with delegatesFocus including no focusable descendants should be skipped');

promise_test(async t => {
let w = window.open('./resources/imagemap.html');
await waitForLoad(w);
t.add_cleanup(() => { w.close(); });
const area = w.document.createElement('area');
area.autofocus = true;
area.shape = 'rect';
area.coords = '1,1,99,99';
area.href = '/common/blank.html';
w.document.querySelector('map').appendChild(area);
await waitUntilStableAutofocusState(w);
// According to the specification, DOM anchor for an AREA shape is an IMG
// element, but major browsers don't follow it.
// See https://github.com/whatwg/html/issues/5054
assert_equals(w.document.activeElement, area);
}, 'Area element should support autofocus');
</script>

0 comments on commit 9d5949c

Please sign in to comment.