| Index: chrome/test/chromedriver/js/focus.js
|
| diff --git a/chrome/test/chromedriver/js/focus.js b/chrome/test/chromedriver/js/focus.js
|
| index 2945a34c9a74bf93133054d544861467c64432c9..4d6961f9ef2a4eda3ec2ae9f111a648156ae3197 100644
|
| --- a/chrome/test/chromedriver/js/focus.js
|
| +++ b/chrome/test/chromedriver/js/focus.js
|
| @@ -38,6 +38,24 @@ function focus(element) {
|
| throw error;
|
| }
|
| }
|
| - if (element != doc.activeElement)
|
| + var activeElement = doc.activeElement;
|
| + // If the element is in a shadow DOM, then as far as the document is concerned
|
| + // the shadow host is the active element. We need to go through the tree of
|
| + // shadow DOMs to check that the element we gave focus to is now active
|
| + if (element != activeElement) {
|
| + var shadowRoot = activeElement.shadowRoot;
|
| + while (shadowRoot) {
|
| + var activeElement = shadowRoot.activeElement;
|
| + if (element == activeElement) {
|
| + // the shadow DOM's active element is our requested element. We're good.
|
| + break;
|
| + }
|
| + // The shadow DOM's active element isn't our requested element, check to
|
| + // see if there's a nested shadow DOM.
|
| + shadowRoot = activeElement.shadowRoot;
|
| + }
|
| + }
|
| +
|
| + if (element != activeElement)
|
| throw new Error('cannot focus element');
|
| }
|
|
|