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
This commit is contained in:
Mike Conley 2016-07-29 16:22:11 -04:00 committed by Mark Banner
parent 6114a6fff7
commit d190976dae

View File

@ -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();