Bug 1368275 - Make test_nukeContentWindow.html correctly wait for the window to be destroyed instead of relying on the scheduling of the corresponding event; r=kmag
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 27 May 2017 15:46:27 -0400
changeset 412681 8def89fd63a0b2f819a73e2a4a0fad50a5331715
parent 412680 c7f34448197790499d4709a6e5a36aa7aa876b1b
child 412682 acc8ba5c16d4fdaea4f4838db5ab5f52bfabb293
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1368275
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368275 - Make test_nukeContentWindow.html correctly wait for the window to be destroyed instead of relying on the scheduling of the corresponding event; r=kmag
js/xpconnect/tests/mochitest/test_nukeContentWindow.html
--- a/js/xpconnect/tests/mochitest/test_nukeContentWindow.html
+++ b/js/xpconnect/tests/mochitest/test_nukeContentWindow.html
@@ -13,22 +13,37 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322273">Mozilla Bug 1322273</a>
 
 <iframe id="subframe"></iframe>
 
 <script type="application/javascript">
 "use strict";
 
+function waitForWindowDestroyed(winID, callback) {
+  let observer = {
+    observe: function(subject, topic, data) {
+      let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
+      if (id != winID) {
+        return;
+      }
+      SpecialPowers.removeObserver(observer, "outer-window-destroyed");
+      SpecialPowers.executeSoon(callback);
+    }
+  };
+  SpecialPowers.addObserver(observer, "outer-window-destroyed");
+}
+
 add_task(function* () {
   let frame = $('subframe');
   frame.src = "data:text/html,";
   yield new Promise(resolve => frame.addEventListener("load", resolve, {once: true}));
 
   let win = frame.contentWindow;
+  let winID = SpecialPowers.getDOMWindowUtils(win).outerWindowID;
 
   win.eval("obj = {}");
   win.obj.foo = {bar: "baz"};
 
   let obj = win.obj;
 
   let system = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal()
   let sandbox = SpecialPowers.Cu.Sandbox(system);
@@ -45,17 +60,17 @@ add_task(function* () {
   is(isWrapperDead(), false, "Sandbox wrapper for content window should not be dead");
   is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
 
   // Remove the frame, which should nuke the content window.
   info("Remove the content frame");
   frame.remove();
 
   // Give the nuke wrappers task a chance to run.
-  yield new Promise(SimpleTest.executeSoon);
+  yield new Promise(resolve => waitForWindowDestroyed(winID, resolve));
 
   is(isWrapperDead(), true, "Sandbox wrapper for content window should be dead");
   is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
 });
 </script>
 
 </body>
 </html>