Skip to content

Commit

Permalink
Bug 1593878 [wpt PR 20079] - shadow-dom: Add test cases for focus() a…
Browse files Browse the repository at this point in the history
…nd nested shadow hosts., a=testonly

Automatic update from web-platform-tests
shadow-dom: Add test cases for focus() and nested shadow hosts. (#20079)

Closes whatwg/html#5052
--

wpt-commits: c1e7abe048f9baee56488c23971ee4af08336886
wpt-pr: 20079
  • Loading branch information
tkent-google authored and moz-wptsync-bot committed Nov 29, 2019
1 parent 54a335c commit fc5cd76
Showing 1 changed file with 47 additions and 0 deletions.
Expand Up @@ -236,5 +236,52 @@
assert_equals(shadowRoot.activeElement, belowSlots);
}, "focus() on host with delegatesFocus and already-focused non-first shadow descendant");

function createNestedHosts(innerDelegatesFocus) {
// Structure:
// <div> outerHost
// <input> outerLightChild
// #shadowRoot outerShadow delegatesFocus=true
// <span> innerHost
// #shadowRoot inneShadow delegatesFocus=true/false
// <input> innerShadowChild
// <input> outerShadowChild
const outerHost = document.createElement('div');
const outerLightChild = document.createElement('input');
outerHost.appendChild(outerLightChild);
const innerHost = document.createElement('span');
const outerShadow = outerHost.attachShadow({mode: 'closed', delegatesFocus:true});
outerShadow.appendChild(innerHost);
const outerShadowChild = document.createElement('input');
outerShadow.appendChild(outerShadowChild);

const innerShadow = innerHost.attachShadow({mode: 'closed', delegatesFocus:innerDelegatesFocus});
const innerShadowChild = document.createElement('input');
innerShadow.appendChild(innerShadowChild);

document.body.insertBefore(outerHost, document.body.firstChild);
return {outerHost: outerHost,
outerLightChild: outerLightChild,
outerShadow: outerShadow,
outerShadowChild: outerShadowChild,
innerHost: innerHost,
innerShadow: innerShadow,
innerShadowChild: innerShadowChild};
}

test(() => {
const dom = createNestedHosts(false);
dom.outerHost.focus();
assert_equals(document.activeElement, dom.outerHost);
assert_equals(dom.outerShadow.activeElement, dom.innerHost);
assert_equals(dom.innerShadow.activeElement, dom.innerShadowChild);
}, 'focus() on host with delegatesFocus with another host with no delegatesFocus and a focusable child');

test(() => {
const dom = createNestedHosts(true);
dom.outerHost.focus();
assert_equals(document.activeElement, dom.outerHost);
assert_equals(dom.outerShadow.activeElement, dom.innerHost);
assert_equals(dom.innerShadow.activeElement, dom.innerShadowChild);
}, 'focus() on host with delegatesFocus with another host with delegatesFocus and a focusable child');
</script>

0 comments on commit fc5cd76

Please sign in to comment.