Bug 1387457 - Convert element click functions to async. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 04 Aug 2017 15:45:02 +0100
changeset 621241 a4f6e054b714c13aa0491c806482dfba13a89708
parent 620862 32083f24a1bb2c33050b4c972783f066432194eb
child 640947 3714ed0828e78fc10146302ad880c5159fb13299
push id72308
push userbmo:ato@sny.no
push dateFri, 04 Aug 2017 14:46:05 +0000
reviewersautomatedtester
bugs1387457
milestone57.0a1
Bug 1387457 - Convert element click functions to async. r?automatedtester The element click functions in testing/marionette/interaction.js are generator functions using "yield". This patch converts them to async functions. MozReview-Commit-ID: 4A4cTaY619w
testing/marionette/driver.js
testing/marionette/interaction.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2083,26 +2083,26 @@ GeckoDriver.prototype.getActiveElement =
  * @param {string} id
  *     Reference ID to the element that will be clicked.
  *
  * @throws {NoSuchWindowError}
  *     Top-level browsing context has been discarded.
  * @throws {UnexpectedAlertOpenError}
  *     A modal dialog is open, blocking this operation.
  */
-GeckoDriver.prototype.clickElement = function* (cmd, resp) {
+GeckoDriver.prototype.clickElement = async function (cmd, resp) {
   const win = assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
   let id = cmd.parameters.id;
 
   switch (this.context) {
     case Context.CHROME:
       let el = this.curBrowser.seenEls.get(id, {frame: win});
-      yield interaction.clickElement(el, this.a11yChecks);
+      await interaction.clickElement(el, this.a11yChecks);
       break;
 
     case Context.CONTENT:
       // We need to protect against the click causing an OOP frame
       // to close.  This fires the mozbrowserclose event when it closes
       // so we need to listen for it and then just send an error back.
       // The person making the call should be aware something is not right
       // and handle accordingly.
@@ -2121,17 +2121,17 @@ GeckoDriver.prototype.clickElement = fun
           pageTimeout: this.timeouts.pageLoad,
           startTime: new Date().getTime(),
         };
         this.mm.broadcastAsyncMessage(
             "Marionette:waitForPageLoaded" + this.curBrowser.curFrameId,
             parameters);
       });
 
-      yield click;
+      await click;
       break;
   }
 };
 
 /**
  * Get a given attribute of an element.
  *
  * @param {string} id
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -137,29 +137,29 @@ this.interaction = {};
  * @throws {ElementClickInterceptedError}
  *     If <var>el</var> is obscured by another element and a click would
  *     not hit, in <var>specCompat</var> mode.
  * @throws {ElementNotAccessibleError}
  *     If <var>strict</var> is true and element is not accessible.
  * @throws {InvalidElementStateError}
  *     If <var>el</var> is not enabled.
  */
-interaction.clickElement = function* (
-    el, strict = false, specCompat = false) {
+interaction.clickElement = async function
+    (el, strict = false, specCompat = false) {
   const a11y = accessibility.get(strict);
   if (element.isXULElement(el)) {
-    yield chromeClick(el, a11y);
+    await chromeClick(el, a11y);
   } else if (specCompat) {
-    yield webdriverClickElement(el, a11y);
+    await webdriverClickElement(el, a11y);
   } else {
-    yield seleniumClickElement(el, a11y);
+    await seleniumClickElement(el, a11y);
   }
 };
 
-function* webdriverClickElement(el, a11y) {
+async function webdriverClickElement(el, a11y) {
   const win = getWindow(el);
 
   // step 3
   if (el.localName == "input" && el.type == "file") {
     throw new InvalidArgumentError(
         "Cannot click <input type=file> elements");
   }
 
@@ -184,76 +184,73 @@ function* webdriverClickElement(el, a11y
   // step 7
   let rects = containerEl.getClientRects();
   let clickPoint = element.getInViewCentrePoint(rects[0], win);
 
   if (element.isObscured(containerEl)) {
     throw new ElementClickInterceptedError(containerEl, clickPoint);
   }
 
-  yield a11y.getAccessible(el, true).then(acc => {
-    a11y.assertVisible(acc, el, true);
-    a11y.assertEnabled(acc, el, true);
-    a11y.assertActionable(acc, el);
-  });
+  let acc = await a11y.getAccessible(el, true);
+  a11y.assertVisible(acc, el, true);
+  a11y.assertEnabled(acc, el, true);
+  a11y.assertActionable(acc, el);
 
   // step 8
   if (el.localName == "option") {
     interaction.selectOption(el);
   } else {
     event.synthesizeMouseAtPoint(clickPoint.x, clickPoint.y, {}, win);
   }
 
   // step 9
-  yield interaction.flushEventLoop(win);
+  await interaction.flushEventLoop(win);
 
   // step 10
   // if the click causes navigation, the post-navigation checks are
   // handled by the load listener in listener.js
 }
 
-function* chromeClick(el, a11y) {
+async 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);
-  });
+  let acc = await a11y.getAccessible(el, true);
+  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) {
+async function seleniumClickElement(el, a11y) {
   let win = getWindow(el);
 
   let visibilityCheckEl  = el;
   if (el.localName == "option") {
     visibilityCheckEl = element.getContainer(el);
   }
 
   if (!element.isVisible(visibilityCheckEl)) {
     throw new ElementNotInteractableError();
   }
 
   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);
-  });
+  let acc = await a11y.getAccessible(el, true);
+  a11y.assertVisible(acc, el, true);
+  a11y.assertEnabled(acc, el, true);
+  a11y.assertActionable(acc, el);
 
   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);
@@ -322,17 +319,17 @@ interaction.selectOption = function(el) 
  * @param {Window} win
  *     Associated window.
  *
  * @return {Promise}
  *     Promise is accepted once event queue is flushed, or rejected if
  *     <var>win</var> has closed or been unloaded before the queue can
  *     be flushed.
  */
-interaction.flushEventLoop = function* (win) {
+interaction.flushEventLoop = async function (win) {
   return new Promise(resolve => {
     let handleEvent = event => {
       win.removeEventListener("beforeunload", this);
       resolve();
     };
 
     if (win.closed) {
       resolve();