Bug 1388082 - Switch to async/await in action module. r?automatedtester
MozReview-Commit-ID: EREW0Hmmtb6
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -3,18 +3,16 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint no-dupe-keys:off */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-Cu.import("resource://gre/modules/Task.jsm");
-
Cu.import("chrome://marionette/content/assert.js");
Cu.import("chrome://marionette/content/element.js");
const {
error,
InvalidArgumentError,
MoveTargetOutOfBoundsError,
UnsupportedOperationError,
} = Cu.import("chrome://marionette/content/error.js", {});
@@ -966,25 +964,25 @@ action.Mouse = class {
* @param {Object.<string, nsIDOMWindow>} container
* Object with <code>frame</code> property of type
* <code>nsIDOMWindow</code>.
*
* @return {Promise}
* Promise for dispatching all actions in |chain|.
*/
action.dispatch = function(chain, seenEls, container) {
- let chainEvents = Task.spawn(function*() {
+ let chainEvents = (async () => {
for (let tickActions of chain) {
- yield action.dispatchTickActions(
+ await action.dispatchTickActions(
tickActions,
action.computeTickDuration(tickActions),
seenEls,
container);
}
- });
+ })();
return chainEvents;
};
/**
* Dispatch sequence of actions for one tick.
*
* This creates a Promise for one tick that resolves once the Promise
* for each tick-action is resolved, which takes at least |tickDuration|
@@ -1321,33 +1319,32 @@ function dispatchPointerMove(
performOnePointerMove(inputState, targetX, targetY, container.frame);
resolve();
return;
}
const distanceX = targetX - startX;
const distanceY = targetY - startY;
const ONE_SHOT = Ci.nsITimer.TYPE_ONE_SHOT;
- let intermediatePointerEvents = Task.spawn(function* () {
+ let intermediatePointerEvents = (async () => {
// wait |fps60| ms before performing first incremental pointer move
- yield new Promise(resolveTimer =>
- timer.initWithCallback(resolveTimer, fps60, ONE_SHOT)
- );
+ await new Promise(resolveTimer =>
+ timer.initWithCallback(resolveTimer, fps60, ONE_SHOT));
let durationRatio = Math.floor(Date.now() - start) / duration;
const epsilon = fps60 / duration / 10;
while ((1 - durationRatio) > epsilon) {
let x = Math.floor(durationRatio * distanceX + startX);
let y = Math.floor(durationRatio * distanceY + startY);
performOnePointerMove(inputState, x, y, container.frame);
// wait |fps60| ms before performing next pointer move
- yield new Promise(resolveTimer =>
+ await new Promise(resolveTimer =>
timer.initWithCallback(resolveTimer, fps60, ONE_SHOT));
durationRatio = Math.floor(Date.now() - start) / duration;
}
- });
+ })();
// perform last pointer move after all incremental moves are resolved and
// durationRatio is close enough to 1
intermediatePointerEvents.then(() => {
performOnePointerMove(inputState, targetX, targetY, container.frame);
resolve();
});
});