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 379456 7641dfbfb01bb1baef35dceb1cf76340bd78a5ba
parent 379455 71b9bf4fdb00ad93d363774dc7f086fd24dde3e9
child 379457 0a5c564fe17ea146aaf16ead89a1ee0efb29ea36
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1345653
milestone53.0
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`);