Bug 1354211 - Consider <optgroup> when finding container element. r?automatedtester
It is a bug in element.getContainer that <optgroup> is not considered
when locating the containing context element, <select>. <optgroup>
is also a child element of <select> on the same level as <option>.
MozReview-Commit-ID: 2GJJrRuY5Th
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -842,35 +842,33 @@ element.inViewport = function(el, x = un
*
* If the element does not have a valid context, its container element
* is itself.
*
* @param {Element} el
* Element to get the container of.
*
* @return {Element}
- * Container element of |el|.
+ * Container element of <var>el</var>.
*/
element.getContainer = function(el) {
-
function findAncestralElement(startNode, validAncestors) {
let node = startNode;
while (node.parentNode) {
node = node.parentNode;
if (validAncestors.includes(node.localName)) {
return node;
}
}
-
return startNode;
}
- // Does <option> have a valid context,
+ // Does <option> or <optgroup> have a valid context,
// meaning is it a child of <datalist> or <select>?
- if (el.localName === "option") {
+ if (["option", "optgroup"].includes(el.localName)) {
return findAncestralElement(el, ["datalist", "select"]);
}
// Child nodes of button will not be part of the element tree for
// elementsFromPoint until bug 1089326 is fixed.
return findAncestralElement(el, ["button"]);
};