Bug 1393812 - Fix call to element.isDisconnected. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 25 Aug 2017 16:30:08 +0100
changeset 653119 bffbdc6125ee1700d429f4ac5dfcca45b37add1e
parent 653118 56188620cce00b19700fbb8efaafea65e6ca8c61
child 728263 32c114334c42ae62da5f3127f3ceef292729a0d1
push id76241
push userbmo:ato@sny.no
push dateFri, 25 Aug 2017 15:33:14 +0000
reviewersautomatedtester
bugs1393812, 1392346, 1392854
milestone57.0a1
Bug 1393812 - Fix call to element.isDisconnected. r?automatedtester A fallout from https://bugzil.la/1392346 was that element.isStale called element.isDisconnected incorrectly by using the old container object. This was reported in https://bugzil.la/1392854. Since we in the long term want to get rid of the concept of window/shadow root containers (in preparation for https://bugzil.la/marionette-window-tracking), we might as well fix the fallout by making element.isDisconnected take separate window- and shadowRoot arguments, like element.isStale. Fixes: https://bugzil.la/1392854 MozReview-Commit-ID: ELIu8HsZUfK
testing/marionette/element.js
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -648,63 +648,59 @@ element.isStale = function(el, window, s
   let wrappedElement, wrappedWindow, wrappedShadowRoot;
 
   wrappedElement = new XPCNativeWrapper(el);
   wrappedWindow = new XPCNativeWrapper(window);
   if (shadowRoot) {
     wrappedShadowRoot = new XPCNativeWrapper(shadowRoot);
   }
 
-  const container = {
-    frame: wrappedWindow,
-    shadowRoot: wrappedShadowRoot,
-  };
-
   let sameDoc = wrappedElement.ownerDocument === wrappedWindow.document;
-  let disconn = element.isDisconnected(wrappedElement, container);
+  let disconn = element.isDisconnected(
+      wrappedElement,
+      wrappedWindow,
+      wrappedShadowRoot);
 
   return !el || !sameDoc || disconn;
 };
 
 /**
  * Check if the element is detached from the current frame as well as
  * the optional shadow root (when inside a Shadow DOM context).
  *
  * @param {Element} el
  *     Element to be checked.
- * @param {Container} container
- *     Container with |frame|, which is the window object that contains
- *     the element, and an optional |shadowRoot|.
+ * @param {WindowProxy} window
+ *     Window to find out if <var>el</var> is still connected to.
+ * @param {Element=} shadowRoot
+ *     Current shadow root element, if any.
  *
  * @return {boolean}
  *     Flag indicating that the element is disconnected.
  */
-element.isDisconnected = function(el, container = {}) {
-  const {frame, shadowRoot} = container;
-  assert.defined(frame);
+element.isDisconnected = function(el, window, shadowRoot = undefined) {
+  assert.defined(window);
 
   // shadow DOM
-  if (frame.ShadowRoot && shadowRoot) {
+  if (window.ShadowRoot && 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)) {
+    while (parent && !(parent instanceof window.ShadowRoot)) {
       parent = parent.parentNode;
     }
-    return element.isDisconnected(
-        shadowRoot.host,
-        {frame, shadowRoot: parent});
+    return element.isDisconnected(shadowRoot.host, window, parent);
   }
 
   // outside shadow DOM
-  let docEl = frame.document.documentElement;
+  let docEl = window.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.
@@ -960,17 +956,17 @@ element.getPointerInteractablePaintTree 
 
   // Include shadow DOM host only if the element's root node is not the
   // owner document.
   if (rootNode !== doc) {
     container.shadowRoot = rootNode;
   }
 
   // pointer-interactable elements tree, step 1
-  if (element.isDisconnected(el, container)) {
+  if (element.isDisconnected(el, container.frame, container.shadowRoot)) {
     return [];
   }
 
   // steps 2-3
   let rects = el.getClientRects();
   if (rects.length == 0) {
     return [];
   }