Bug 1345653 - Handle document unload when dispatching actions. r=ato, a=test-only
authorMaja Frydrychowicz <mjzffr@gmail.com>
Tue, 04 Apr 2017 00:01:11 -0400
changeset 393373 47c3ec42917e04c125fbf90522d80a93f6ba198c
parent 393372 28ada033908ac8c2879c2cdcab4d98af9aa58b86
child 393374 76b7351b7c2ef1e9528543389ea7778f65959098
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1345653
milestone54.0a2
Bug 1345653 - Handle document unload when dispatching actions. r=ato, a=test-only 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`);