Bug 1274274 - Disassociate isDisconnected from element store; r?automatedtester
MozReview-Commit-ID: 4uxbLKlgfsL
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -175,64 +175,26 @@ element.Store = class {
let wrappedShadowRoot;
if (container.shadowRoot) {
wrappedShadowRoot = new XPCNativeWrapper(container.shadowRoot);
}
let wrappedEl = new XPCNativeWrapper(el);
if (!el ||
!(wrappedEl.ownerDocument == wrappedFrame.document) ||
- this.isDisconnected(wrappedEl, wrappedFrame, wrappedShadowRoot)) {
+ element.isDisconnected(wrappedEl, wrappedFrame, wrappedShadowRoot)) {
throw new StaleElementReferenceError(
"The element reference is stale. Either the element " +
"is no longer attached to the DOM or the page has been refreshed.");
}
return el;
}
/**
- * Check if the element is detached from the current frame as well as
- * the optional shadow root (when inside a Shadow DOM context).
- *
- * @param {nsIDOMElement} el
- * Element to be checked.
- * @param nsIDOMWindow frame
- * Window object that contains the element or the current host
- * of the shadow root.
- * @param {ShadowRoot=} shadowRoot
- * An optional shadow root containing an element.
- *
- * @return {boolean}
- * Flag indicating that the element is disconnected.
- */
- isDisconnected(el, frame, shadowRoot = undefined) {
- // shadow dom
- if (shadowRoot && frame.ShadowRoot) {
- if (el.compareDocumentPosition(shadowRoot) &
- DOCUMENT_POSITION_DISCONNECTED) {
- return true;
- }
-
- // looking for next possible ShadowRoot ancestor
- let parent = shadowRoot.host;
- while (parent && !(parent instanceof frame.ShadowRoot)) {
- parent = parent.parentNode;
- }
- return this.isDisconnected(shadowRoot.host, parent, frame);
-
- // outside shadow dom
- } else {
- let docEl = frame.document.documentElement;
- return el.compareDocumentPosition(docEl) &
- DOCUMENT_POSITION_DISCONNECTED;
- }
- }
-
- /**
* Convert values to primitives that can be transported over the
* Marionette protocol.
*
* This function implements the marshaling algorithm defined in the
* WebDriver specification:
*
* https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html#synchronous-javascript-execution
*
@@ -739,16 +701,54 @@ element.makeWebElement = function(uuid)
};
element.generateUUID = function() {
let uuid = uuidGen.generateUUID().toString();
return uuid.substring(1, uuid.length - 1);
};
/**
+ * Check if the element is detached from the current frame as well as
+ * the optional shadow root (when inside a Shadow DOM context).
+ *
+ * @param {nsIDOMElement} el
+ * Element to be checked.
+ * @param nsIDOMWindow frame
+ * Window object that contains the element or the current host
+ * of the shadow root.
+ * @param {ShadowRoot=} shadowRoot
+ * An optional shadow root containing an element.
+ *
+ * @return {boolean}
+ * Flag indicating that the element is disconnected.
+ */
+element.isDisconnected = function(el, frame, shadowRoot = undefined) {
+ // shadow dom
+ if (shadowRoot && frame.ShadowRoot) {
+ if (el.compareDocumentPosition(shadowRoot) &
+ DOCUMENT_POSITION_DISCONNECTED) {
+ return true;
+ }
+
+ // looking for next possible ShadowRoot ancestor
+ let parent = shadowRoot.host;
+ while (parent && !(parent instanceof frame.ShadowRoot)) {
+ parent = parent.parentNode;
+ }
+ return element.isDisconnected(shadowRoot.host, frame, parent);
+
+ // outside shadow dom
+ } else {
+ let docEl = frame.document.documentElement;
+ return el.compareDocumentPosition(docEl) &
+ DOCUMENT_POSITION_DISCONNECTED;
+ }
+};
+
+/**
* This function generates a pair of coordinates relative to the viewport
* given a target element and coordinates relative to that element's
* top-left corner.
*
* @param {Node} node
* Target node.
* @param {number=} xOffset
* Horizontal offset relative to target's top-left corner.