Bug 1354211 - Use element.findClosest in element.getContainer. r?automatedtester
element.findClosest is a more generalised version of findAncestralElement,
which is limited to a list of element tag names. By using
element.findClosest and CSS matching we also avoid a redundant iteration.
MozReview-Commit-ID: 32QwmkwiGf5
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -869,36 +869,25 @@ element.inViewport = function(el, x = un
*
* @param {Element} el
* Element to get the container of.
*
* @return {Element}
* 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> or <optgroup> have a valid context,
// meaning is it a child of <datalist> or <select>?
if (["option", "optgroup"].includes(el.localName)) {
- return findAncestralElement(el, ["datalist", "select"]);
+ return element.findClosest(el, "datalist,select") || el;
}
// Child nodes of button will not be part of the element tree for
// elementsFromPoint until bug 1089326 is fixed.
- return findAncestralElement(el, ["button"]);
+ return element.findClosest(el, "button") || el;
};
/**
* An element is in view if it is a member of its own pointer-interactable
* paint tree.
*
* This means an element is considered to be in view, but not necessarily
* pointer-interactable, if it is found somewhere in the