Bug 1345653 - Handle document unload when dispatching actions; r?ato
This fixes the reported hang that occurs after a pointer click
action resulting in navigation.
MozReview-Commit-ID: A9SBhextVLH
--- a/testing/marionette/action.js
+++ b/testing/marionette/action.js
@@ -7,16 +7,17 @@
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");
Cu.import("chrome://marionette/content/error.js");
Cu.import("chrome://marionette/content/event.js");
+Cu.import("chrome://marionette/content/interaction.js");
this.EXPORTED_SYMBOLS = ["action"];
// TODO? With ES 2016 and Symbol you can make a safer approximation
// to an enum e.g. https://gist.github.com/xmlking/e86e4f15ec32b12c4689
/**
* Implements WebDriver Actions API: a low-level interface for providing
* virtualised device input to the web browser.
@@ -952,17 +953,18 @@ action.dispatch = function(chain, seenEl
* @param {?} container
* Object with |frame| attribute of type |nsIDOMWindow|.
*
* @return {Promise}
* Promise for dispatching all tick-actions and pending DOM events.
*/
action.dispatchTickActions = function(tickActions, tickDuration, seenEls, container) {
let pendingEvents = tickActions.map(toEvents(tickDuration, seenEls, container));
- return Promise.all(pendingEvents).then(() => flushEvents(container));
+ return Promise.all(pendingEvents).then(
+ () => interaction.flushEventLoop(container.frame));
};
/**
* Compute tick duration in milliseconds for a collection of actions.
*
* @param {Array.<action.Action>} tickActions
* List of actions for one tick.
*
@@ -1308,28 +1310,16 @@ function dispatchPause(a, tickDuration)
const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
let duration = typeof a.duration == "undefined" ? tickDuration : a.duration;
return new Promise(resolve =>
timer.initWithCallback(resolve, duration, Ci.nsITimer.TYPE_ONE_SHOT)
);
}
// helpers
-/**
- * Force any pending DOM events to fire.
- *
- * @param {?} container
- * Object with |frame| attribute of type |nsIDOMWindow|.
- *
- * @return {Promise}
- * Promise to flush DOM events.
- */
-function flushEvents(container) {
- return new Promise(resolve => container.frame.requestAnimationFrame(resolve));
-}
function capitalize(str) {
assert.string(str);
return str.charAt(0).toUpperCase() + str.slice(1);
}
function inViewPort(x, y, win) {
assert.number(x, `Expected x to be finite number`);