Commit 2777c1c3 authored by Andreas Tolfsen's avatar Andreas Tolfsen
Browse files

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

--HG--
extra : rebase_source : 1b6f1b545f438ae253fd4024500bf41536d976aa
parent 250a8036
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2088,7 +2088,7 @@ GeckoDriver.prototype.getActiveElement = function* (cmd, resp) {
 * @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);

@@ -2097,7 +2097,7 @@ GeckoDriver.prototype.clickElement = function* (cmd, resp) {
  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:
@@ -2126,7 +2126,7 @@ GeckoDriver.prototype.clickElement = function* (cmd, resp) {
            parameters);
      });

      yield click;
      await click;
      break;
  }
};
+22 −25
Original line number Diff line number Diff line
@@ -142,19 +142,19 @@ this.interaction = {};
 * @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
@@ -189,11 +189,10 @@ function* webdriverClickElement(el, a11y) {
    throw new ElementClickInterceptedError(containerEl, clickPoint);
  }

  yield a11y.getAccessible(el, true).then(acc => {
  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") {
@@ -203,23 +202,22 @@ function* webdriverClickElement(el, a11y) {
  }

  // 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 => {
  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);
@@ -228,7 +226,7 @@ function* chromeClick(el, a11y) {
  }
}

function* seleniumClickElement(el, a11y) {
async function seleniumClickElement(el, a11y) {
  let win = getWindow(el);

  let visibilityCheckEl  = el;
@@ -244,11 +242,10 @@ function* seleniumClickElement(el, a11y) {
    throw new InvalidElementStateError("Element is not enabled");
  }

  yield a11y.getAccessible(el, true).then(acc => {
  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);
@@ -327,7 +324,7 @@ interaction.selectOption = function(el) {
 *     <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);