Bug 1359059 - Skip visibility checks when clicking in XUL; r?whimboo draft
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 24 Apr 2017 15:01:41 +0100
changeset 567165 6706e92f6393b29b4ae168fa4d626c4e37473450
parent 567163 62b649c6b314f756f21cb95f2b0d491e2664e944
child 625551 6b4b1db888bcedfbbd7bf5d9e159450581db3f45
push id55471
push userbmo:ato@mozilla.com
push dateMon, 24 Apr 2017 14:11:55 +0000
reviewerswhimboo
bugs1359059
milestone55.0a1
Bug 1359059 - Skip visibility checks when clicking in XUL; r?whimboo This patch removes the call to element.isVisible when clicking XUL elements because it does not do anything useful. element.isVisible skips the Selenium atom.isElementDisplayed check for XUL elements and runs a few web content/viewport centric tests that always pass in XUL. It also splits the chrome click out to a separate function to avoid a few if-conditions. MozReview-Commit-ID: EkcwT77ku3C
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -111,17 +111,19 @@ this.interaction = {};
  *     in |specCompat| mode.
  * @throws {ElementNotAccessibleError}
  *     If |strict| is true and element is not accessible.
  * @throws {InvalidElementStateError}
  *     If |el| is not enabled.
  */
 interaction.clickElement = function* (el, strict = false, specCompat = false) {
   const a11y = accessibility.get(strict);
-  if (specCompat) {
+  if (element.isXULElement(el)) {
+    yield chromeClick(el, a11y);
+  } else if (specCompat) {
     yield webdriverClickElement(el, a11y);
   } else {
     yield seleniumClickElement(el, a11y);
   }
 };
 
 function* webdriverClickElement (el, a11y) {
   const win = getWindow(el);
@@ -161,42 +163,48 @@ function* webdriverClickElement (el, a11
 
   yield a11y.getAccessible(el, true).then(acc => {
     a11y.assertVisible(acc, el, true);
     a11y.assertEnabled(acc, el, true);
     a11y.assertActionable(acc, el);
   });
 
   // step 8
-
-  // chrome elements
-  if (element.isXULElement(el)) {
-    if (el.localName == "option") {
-      interaction.selectOption(el);
-    } else {
-      el.click();
-    }
-
-  // content elements
+  if (el.localName == "option") {
+    interaction.selectOption(el);
   } else {
-    if (el.localName == "option") {
-      interaction.selectOption(el);
-    } else {
-      event.synthesizeMouseAtPoint(clickPoint.x, clickPoint.y, {}, win);
-    }
+    event.synthesizeMouseAtPoint(clickPoint.x, clickPoint.y, {}, win);
   }
 
   // step 9
   yield interaction.flushEventLoop(win);
 
   // step 10
   // TODO(ato): if the click causes navigation,
   // run post-navigation checks
 }
 
+function* chromeClick (el, a11y) {
+  if (!atom.isElementEnabled(el)) {
+    throw new InvalidElementStateError("Element is not enabled");
+  }
+
+  yield a11y.getAccessible(el, true).then(acc => {
+    a11y.assertVisible(acc, el, true);
+    a11y.assertEnabled(acc, el, true);
+    a11y.assertActionable(acc, el);
+  });
+
+  if (el.localName == "option") {
+    interaction.selectOption(el);
+  } else {
+    el.click();
+  }
+}
+
 function* seleniumClickElement (el, a11y) {
   let win = getWindow(el);
 
   let visibilityCheckEl  = el;
   if (el.localName == "option") {
     visibilityCheckEl = element.getContainer(el);
   }
 
@@ -209,34 +217,23 @@ function* seleniumClickElement (el, a11y
   }
 
   yield a11y.getAccessible(el, true).then(acc => {
     a11y.assertVisible(acc, el, true);
     a11y.assertEnabled(acc, el, true);
     a11y.assertActionable(acc, el);
   });
 
-  // chrome elements
-  if (element.isXULElement(el)) {
-    if (el.localName == "option") {
-      interaction.selectOption(el);
-    } else {
-      el.click();
-    }
-
-  // content elements
+  if (el.localName == "option") {
+    interaction.selectOption(el);
   } else {
-    if (el.localName == "option") {
-      interaction.selectOption(el);
-    } else {
-      let rects = el.getClientRects();
-      let centre = element.getInViewCentrePoint(rects[0], win);
-      let opts = {};
-      event.synthesizeMouseAtPoint(centre.x, centre.y, opts, win);
-    }
+    let rects = el.getClientRects();
+    let centre = element.getInViewCentrePoint(rects[0], win);
+    let opts = {};
+    event.synthesizeMouseAtPoint(centre.x, centre.y, opts, win);
   }
 };
 
 /**
  * Select <option> element in a <select> list.
  *
  * Because the dropdown list of select elements are implemented using
  * native widget technology, our trusted synthesised events are not able