Bug 1255955 - Document clickElement and calculateCentreCoords; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Sat, 13 Aug 2016 20:54:15 +0200
changeset 400460 ca6e2bde377fa61ff6cc11ec3c7bcffbdfc40d0b
parent 400459 ccb03a53177cc9dfc95ae2a18aafb35d5463610b
child 400461 e07bec92262a5a43aebfde397a3778981b3862ce
push id26147
push userbmo:ato@mozilla.com
push dateSat, 13 Aug 2016 19:00:38 +0000
reviewersautomatedtester
bugs1255955
milestone51.0a1
Bug 1255955 - Document clickElement and calculateCentreCoords; r?automatedtester MozReview-Commit-ID: tSC5xRAVAl
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -74,22 +74,45 @@ const SELECTED_PROPERTY_SUPPORTED_XUL = 
   "TAB",
 ]);
 
 this.interaction = {};
 
 /**
  * Interact with an element by clicking it.
  *
+ * The element is scrolled into view before visibility- or interactability
+ * checks are performed.
+ *
+ * Selenium-style visibility checks will be performed if |specCompat|
+ * is false (default).  Otherwise pointer-interactability checks will be
+ * performed.  If either of these fail an {@code ElementNotVisibleError}
+ * is returned.
+ *
+ * If |strict| is enabled (defaults to disabled), further accessibility
+ * checks will be performed, and these may result in an {@code
+ * ElementNotAccessibleError} being returned.
+ *
+ * When |el| is not enabled, an {@code InvalidElementStateError}
+ * is returned.
+ *
  * @param {DOMElement|XULElement} el
  *     Element to click.
  * @param {boolean=} strict
  *     Enforce strict accessibility tests.
  * @param {boolean=} specCompat
  *     Use WebDriver specification compatible interactability definition.
+ *
+ * @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) {
   let a11y = accessibility.get(strict);
   return a11y.getAccessible(el, true).then(acc => {
     let win = getWindow(el);
 
     let selectEl;
     let visibilityCheckEl = el;
@@ -135,16 +158,26 @@ interaction.clickElement = function(el, 
         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.
+ *
+ * @return {Object.<string, number>}
+ *     X- and Y-position.
+ */
 interaction.calculateCentreCoords = function(el) {
   let rects = el.getClientRects();
   return {
     x: rects[0].left + rects[0].width / 2.0,
     y: rects[0].top + rects[0].height / 2.0,
   };
 };