Bug 1321516 - Reject interaction.flushEventLoop if window is discarded draft
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 17 Apr 2017 18:42:18 +0100
changeset 567221 0d77d54cd18cf9788693525f55bbd985d8451333
parent 567220 3711864cedcec8cd802c3b00f611d9ab3db33013
child 567222 1aec838d84c2917f2e0912f8cfdde3e7b2797274
push id55475
push userbmo:ato@mozilla.com
push dateMon, 24 Apr 2017 14:23:53 +0000
bugs1321516
milestone55.0a1
Bug 1321516 - Reject interaction.flushEventLoop if window is discarded The window reference may have been discarded as a result of interaction. For example, this may happen when clicking a button that deletes the host <iframe> element containing the child window. In this case, the WindowProxy will set its closed property to true, to indicate that the browsing context has been discarded. We only want to flush the event loop of windows that exist, and so we return early from interaction.flushEventLoop if the window has been closed. MozReview-Commit-ID: FcisbRcsbec
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -243,23 +243,30 @@ interaction.selectOption = function (el)
  * If the document is unloaded during this request, the promise is
  * rejected.
  *
  * @param {Window} win
  *     Associated window.
  *
  * @return {Promise}
  *     Promise is accepted once event queue is flushed, or rejected if
- *     |win| is unloaded before the queue can be flushed.
+ *     |win| has closed or been unloaded before the queue can be flushed.
  */
 interaction.flushEventLoop = function* (win) {
   let unloadEv;
+
   return new Promise((resolve, reject) => {
+    if (win.closed) {
+      reject();
+      return;
+    }
+
     unloadEv = reject;
     win.addEventListener("unload", unloadEv, {once: true});
+
     win.requestAnimationFrame(resolve);
   }).then(() => {
     win.removeEventListener("unload", unloadEv);
   });
 };
 
 /**
  * Appends |path| to an <input type=file>'s file list.