From d190976dae94c001cc484bfdb06ce51437d6785e Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Fri, 29 Jul 2016 16:22:11 -0400 Subject: [PATCH] Bug 1287827 - Fix a race-y test_bug260264.html mochitest. r=mrbkap In nsGlobalWindow, we have a static counter for how many popups we've seen recently. We increment it and decrement it when popups open and close - although the decrement only occurs once the DocShell is detached, which happens asynchronously. The test uses a utility that returns Promises for window.open and window.close, but it uses dom-window-destroyed for resolving close, which happens _before_ the counter is decremented. The dom-window-destroyed observer queues a runnable which resolves the Promise. This means that the test is attempting to open windows before the windows from a previous test have finished detaching their DocShells (and decrementing the counter), which means that the attempts to open the window hit the popup limit, which blocks the popups. This test switches us to waiting for outer-window-destroyed instead, which gives us a greater certainty that the decrement has occurred. MozReview-Commit-ID: 3a7QzxelP0a --- dom/tests/mochitest/bugs/utils_bug260264.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dom/tests/mochitest/bugs/utils_bug260264.js b/dom/tests/mochitest/bugs/utils_bug260264.js index de5de657877c..07b98ea7e498 100644 --- a/dom/tests/mochitest/bugs/utils_bug260264.js +++ b/dom/tests/mochitest/bugs/utils_bug260264.js @@ -31,14 +31,22 @@ function send(element, event, handler) { while (n --> 0) { var win = wins.pop(); if (win) { + let openedWindowID = + SpecialPowers.getDOMWindowUtils(win).outerWindowID; promises.push((function(openedWindow) { return new Promise(function(resolve) { - SpecialPowers.addObserver(function observer(subject, topic, data) { - if (subject == openedWindow) { - SpecialPowers.removeObserver(observer, "dom-window-destroyed"); - SimpleTest.executeSoon(resolve); + let observer = { + observe(subject) { + let wrapped = SpecialPowers.wrap(subject); + let winID = wrapped.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data; + if (winID == openedWindowID) { + SpecialPowers.removeObserver(observer, "outer-window-destroyed"); + SimpleTest.executeSoon(resolve); + } } - }, "dom-window-destroyed", false); + }; + + SpecialPowers.addObserver(observer, "outer-window-destroyed", false); }); })(win)); win.close();