Bug 1287827 - Fix a race-y test_bug260264.html mochitest. r=mrbkap
authorMike Conley <mconley@mozilla.com>
Fri, 29 Jul 2016 16:22:11 -0400
changeset 332312 890f2ada97ac7069caa65ea6d472722423868488
parent 332311 e546cb06c2872bf90fa42d00fc311c580bd33a1f
child 332313 b0c4a9c609c8fa6b013e448e15b984ea8c61b122
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1287827, 260264
milestone50.0a1
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
--- a/dom/tests/mochitest/bugs/utils_bug260264.js
+++ b/dom/tests/mochitest/bugs/utils_bug260264.js
@@ -26,24 +26,32 @@ function send(element, event, handler) {
     return win;
   }).close = function(n) {
     var promises = [];
     if (arguments.length < 1)
       n = wins.length;
     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();
       } else {
         promises.push(Promise.resolve());
         break;
       }
     }