Bug 1255955 - Perform click checks as part of promise; r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 05 Aug 2016 11:38:23 +0100
changeset 347767 fc55305fb268a9bc21654175e17df5118bed007d
parent 347766 f1da984b8731e75e13b1b523cee9f275d6276939
child 347768 6b1c452bd581489d196104419e6b90cee1a9c4f4
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester, test-only
bugs1255955
milestone50.0a2
Bug 1255955 - Perform click checks as part of promise; r=automatedtester, a=test-only Some of the element interactability- and visibility checks were previously done when interaction.clickElement was called, and not as part of the resolution of the returned promise. This could have caused a potential race condition. MozReview-Commit-ID: 691V86B4k5w
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -82,54 +82,50 @@ this.interaction = {};
  * @param {DOMElement|XULElement} el
  *     Element to click.
  * @param {boolean=} strict
  *     Enforce strict accessibility tests.
  * @param {boolean=} specCompat
  *     Use WebDriver specification compatible interactability definition.
  */
 interaction.clickElement = function(el, strict = false, specCompat = false) {
-  let win = getWindow(el);
-
-  let visible = false;
-  if (specCompat) {
-    visible = element.isInteractable(el);
-    if (!visible) {
-      el.scrollIntoView(false);
-    }
-    visible = element.isInteractable(el);
-  } else {
-    visible = element.isVisible(el);
-  }
-
-  if (!visible) {
-    throw new ElementNotVisibleError("Element is not visible");
-  }
-
   let a11y = accessibility.get(strict);
   return a11y.getAccessible(el, true).then(acc => {
-    a11y.checkVisible(acc, el, visible);
+    let win = getWindow(el);
 
-    if (atom.isElementEnabled(el)) {
-      a11y.checkEnabled(acc, el, true);
-      a11y.checkActionable(acc, el);
+    let visible = false;
+    if (specCompat) {
+      visible = element.isInteractable(el);
+      if (!visible) {
+        el.scrollIntoView(false);
+      }
+      visible = element.isInteractable(el);
+    } else {
+      visible = element.isVisible(el);
+    }
 
-      if (element.isXULElement(el)) {
-        el.click();
-      } else {
-        let rects = el.getClientRects();
-        event.synthesizeMouseAtPoint(
-            rects[0].left + rects[0].width / 2,
-            rects[0].top + rects[0].height / 2,
-            {} /* opts */,
-            win);
-      }
+    if (!visible) {
+      throw new ElementNotVisibleError("Element is not visible");
+    }
+    a11y.checkVisible(acc, el, visible);
+    if (!atom.isElementEnabled(el)) {
+      throw new InvalidElementStateError("Element is not enabled");
+    }
+    a11y.checkEnabled(acc, el, true);
+    a11y.checkActionable(acc, el);
 
+    if (element.isXULElement(el)) {
+      el.click();
     } else {
-      throw new InvalidElementStateError("Element is not enabled");
+      let rects = el.getClientRects();
+      let coords = {
+        x: rects[0].left + rects[0].width / 2.0,
+        y: rects[0].top + rects[0].height / 2.0,
+      };
+      event.synthesizeMouseAtPoint(coords.x, coords.y, {} /* opts */, win);
     }
   });
 };
 
 /**
  * Send keys to element.
  *
  * @param {DOMElement|XULElement} el