Bug 1359053 - Reject interaction.flushEventLoop if window is discarded. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 17 Apr 2017 18:42:18 +0100
changeset 394004 cff5c81e36deb161811b4d0b19fddcd467ae5d29
parent 394003 61932206bf73a5c510f97eb3089b823b97b1141e
child 394005 6c7826d0ea5a31d3c0b20cfef53bb10c725d13dd
push id7331
push userryanvm@gmail.com
push dateFri, 19 May 2017 17:36:20 +0000
treeherdermozilla-beta@72da880beaeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1359053
milestone54.0
Bug 1359053 - Reject interaction.flushEventLoop if window is discarded. r=maja_zf, a=test-only 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: LtTHQRudKvk
testing/marionette/interaction.js
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -286,23 +286,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.