Bug 1345653 - Handle document unload when dispatching actions; r?ato draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 04 Apr 2017 00:01:11 -0400
changeset 555732 462b66592ea1c633107b9d4367cea0fff78e1307
parent 555608 81e37ef1360ba4505726ddf542ebdcc952a57578
child 555733 ea313bd053b15644a71f2d0460193380157d8c18
push id52315
push userbmo:mjzffr@gmail.com
push dateTue, 04 Apr 2017 18:59:07 +0000
reviewersato
bugs1345653
milestone55.0a1
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
testing/marionette/action.js
--- 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`);