Commit 532cac5e authored by Rachel Sugrono's avatar Rachel Sugrono Committed by Commit Bot

Add a findActiveElement test helper that also examines shadow roots

The browser has one activeElement. Add a test helper that is similar to
getActiveElement but searches shadow roots for the actual activeElement
if needed, and returns details about that element.

Bug: 907380
Change-Id: I0478d125e2b3d1c44f4c5cea03d110b642424955
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002045Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731895}
parent 6447da5e
......@@ -286,6 +286,37 @@ test.util.sync.getActiveElement = (contentWindow, opt_styleNames) => {
contentWindow.document.activeElement, contentWindow, opt_styleNames);
};
/**
* Gets the information of the active element. However, unlike the previous
* helper, the shadow roots are searched as well.
*
* @param {Window} contentWindow Window to be tested.
* @param {Array<string>=} opt_styleNames List of CSS property name to be
* obtained.
* @return {?{attributes:Object<string>, text:string,
* styles:(Object<string>|undefined), hidden:boolean}} Element
* information that contains contentText, attribute names and
* values, hidden attribute, and style names and values. If there is no
* active element, returns null.
*/
test.util.sync.findActiveElement = (contentWindow, opt_styleNames) => {
if (!contentWindow.document || !contentWindow.document.activeElement) {
return null;
}
let activeElement = contentWindow.document.activeElement;
while (true) {
const shadow = activeElement.shadowRoot;
if (shadow && shadow.activeElement) {
activeElement = shadow.activeElement;
} else {
break;
}
}
return extractElementInfo(activeElement, contentWindow, opt_styleNames);
};
/**
* Assigns the text to the input element.
* @param {Window} contentWindow Window to be tested.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment