Bug 1255955 - Simplify element.clickElement complexity; r=automatedtester, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Sat, 13 Aug 2016 20:54:46 +0200
changeset 347776 393b9382b1fcc5b4d373a2698b7c1f257fdb922a
parent 347775 72f83f7e308c690bd26a0d974905d10248208e66
child 347777 f4aa3c3af595bf44fcfbc8ec7b6190ed207090e2
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 - Simplify element.clickElement complexity; r=automatedtester, a=test-only MozReview-Commit-ID: IXqgFlS6R6c
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -104,68 +104,66 @@ this.interaction = {};
  * @throws {ElementNotVisibleError}
  *     If either Selenium-style visibility check or
  *     pointer-interactability check fails.
  * @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) {
+interaction.clickElement = function*(el, strict = false, specCompat = false) {
+  let win = getWindow(el);
   let a11y = accessibility.get(strict);
-  return a11y.getAccessible(el, true).then(acc => {
-    let win = getWindow(el);
 
-    let selectEl;
-    let visibilityCheckEl = el;
-    if (el.localName == "option") {
-      selectEl = interaction.getSelectForOptionElement(el);
-      visibilityCheckEl = selectEl;
+  let visibilityCheckEl  = el;
+  if (el.localName == "option") {
+    visibilityCheckEl = interaction.getSelectForOptionElement(el);
+  }
+
+  let visible = false;
+  if (specCompat) {
+    if (!element.isInteractable(visibilityCheckEl)) {
+      el.scrollIntoView(false);
     }
+    visible = element.isInteractable(visibilityCheckEl);
+  } else {
+    visible = element.isVisible(visibilityCheckEl);
+  }
 
-    let visible = false;
-    if (specCompat) {
-      visible = element.isInteractable(visibilityCheckEl);
-      if (!visible) {
-        el.scrollIntoView(false);
-      }
-      visible = element.isInteractable(visibilityCheckEl);
+  if (!visible) {
+    throw new ElementNotVisibleError("Element not visible");
+  }
+
+  yield a11y.getAccessible(el, true).then(acc => {
+    a11y.assertVisible(acc, el, visible);
+    if (!atom.isElementEnabled(el)) {
+      throw new InvalidElementStateError("Element is not enabled");
+    }
+    a11y.assertEnabled(acc, el, true);
+    a11y.assertActionable(acc, el);
+  });
+
+  // chrome elements
+  if (element.isXULElement(el)) {
+    if (el.localName == "option") {
+      interaction.selectOption(el);
     } else {
-      visible = element.isVisible(visibilityCheckEl);
+      el.click();
     }
 
-    if (!visible) {
-      throw new ElementNotVisibleError("Element is not visible");
-    }
-    a11y.assertVisible(acc, visibilityCheckEl, visible);
-    if (!atom.isElementEnabled(visibilityCheckEl)) {
-      throw new InvalidElementStateError("Element is not enabled");
+  // content elements
+  } else {
+    if (el.localName == "option") {
+      interaction.selectOption(el);
+    } else {
+      let centre = interaction.calculateCentreCoords(el);
+      let opts = {};
+      event.synthesizeMouseAtPoint(centre.x, centre.y, opts, win);
     }
-    a11y.assertEnabled(acc, visibilityCheckEl, true);
-    a11y.assertActionable(acc, visibilityCheckEl);
-
-    // chrome elements
-    if (element.isXULElement(el)) {
-      if (el.localName == "option") {
-        interaction.selectOption(el);
-      } else {
-        el.click();
-      }
-
-    // content elements
-    } else {
-      if (el.localName == "option") {
-        interaction.selectOption(el);
-      } else {
-        let centre = interaction.calculateCentreCoords(el);
-        let opts = {};
-        event.synthesizeMouseAtPoint(centre.x, centre.y, opts, win);
-      }
-    }
-  });
+  }
 };
 
 /**
  * Calculate the in-view centre point, that is the centre point of the
  * area of the first DOM client rectangle that is inside the viewport.
  *
  * @param {DOMElement} el
  *     Element to calculate the visible centre point of.