Bug 1321516 - Skip in-view checks for XUL elements draft
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 17 Apr 2017 17:44:00 +0100
changeset 565893 636d68286175aca5852a28bef7d9561c6b0052eb
parent 565892 85e786b9d3096dda786dfd758ff32993053d5d36
child 565894 02d664fd79dc4aea7543eef8357f79cc348b1a7d
push id55051
push userbmo:ato@mozilla.com
push dateThu, 20 Apr 2017 17:08:50 +0000
bugs1321516
milestone55.0a1
Bug 1321516 - Skip in-view checks for XUL elements This skips the in-view checks for chrome XUL elements, and also makes the code more readable by reducing the number of if-conditions by making the XUL element clicking implementation a separate function. MozReview-Commit-ID: 5UAQfoGCzFQ
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -109,27 +109,35 @@ 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) {
   const a11y = accessibility.get(strict);
+
+  if (element.isXULElement(el)) {
+    yield chromeClick(el, a11y);
+  } else {
+    yield contentClick(el, a11y);
+  }
+};
+
+function* contentClick (el, a11y) {
   const win = getWindow(el);
   const doc = win.document;
+  const containerEl = element.getContainer(el);
 
   // step 3
   if (el.localName == "input" && el.type == "file") {
     throw new InvalidArgumentError(
         "Cannot click <input type=file> elements");
   }
 
-  let containerEl = element.getContainer(el);
-
   // step 4
   if (!element.isInView(containerEl)) {
     element.scrollIntoView(containerEl);
   }
 
   // step 5
   // TODO(ato): wait for containerEl to be in view
 
@@ -151,41 +159,43 @@ interaction.clickElement = function* (el
 
   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) {
+  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();
+  }
+}
 
 /**
  * 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
  * to reach them.  Dropdowns are instead handled mimicking DOM events,
  * which for obvious reasons is not ideal, but at the current point in