Bug 1274274 - Disassociate isDisconnected from element store; r=automatedtester
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 20 May 2016 15:11:37 +0100
changeset 337933 7d0cf052c1cea39c798d8efdf95da80a882670fc
parent 337932 84c33f8de011c03a27501236ea3def5688f33964
child 337934 aa348e14ae8202828b821328eb48ca24f8454948
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1274274
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1274274 - Disassociate isDisconnected from element store; r=automatedtester MozReview-Commit-ID: 4uxbLKlgfsL
testing/marionette/element.js
--- 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.