Bug 1287827 - Fix a race-y test_bug260264.html mochitest. r=mrbkap,a=sledru
authorMike Conley <mconley@mozilla.com>
Fri, 29 Jul 2016 16:22:11 -0400
changeset 340158 f3a3809acae60a936d6b09297bbac7c02dac00b0
parent 340157 f0c525d1274c65dde11dd9fd916754f98d95f6b8
child 340159 183d4deab3e587d38075ffb3d81ae71d6f9adcc5
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, sledru
bugs1287827, 260264
milestone49.0a2
Bug 1287827 - Fix a race-y test_bug260264.html mochitest. r=mrbkap,a=sledru
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;
       }
     }