Bug 1125958 - test_bug_461710_perwindowpb.html fails when run as a standalone directory. r=ehsan
authorJoel Maher <jmaher@mozilla.com>
Mon, 26 Jan 2015 16:12:24 -0500
changeset 239202 1afe3f5bc9c78b0ba452246cc310734f8b988d4c
parent 239201 32048e974c4b8e087c917623186c94a1f5b4ebb7
child 239203 901b357d733450444d316ec1e0f8530384aee7cc
push id489
push usermcmanus@ducksong.com
push dateTue, 27 Jan 2015 01:44:53 +0000
reviewersehsan
bugs1125958
milestone38.0a1
Bug 1125958 - test_bug_461710_perwindowpb.html fails when run as a standalone directory. r=ehsan
toolkit/components/places/tests/test_bug_461710_perwindowpb.html
--- a/toolkit/components/places/tests/test_bug_461710_perwindowpb.html
+++ b/toolkit/components/places/tests/test_bug_461710_perwindowpb.html
@@ -152,40 +152,45 @@ function handleLoad() {
   } else {
     normalWindow.close();
     privateWindow.close();
 
     SimpleTest.finish();
   }
 }
 
-var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIWebNavigation)
-                    .QueryInterface(Ci.nsIDocShellTreeItem)
-                    .rootTreeItem
-                    .QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIDOMWindow);
 var contentPage = "http://mochi.test:8888/tests/toolkit/components/places/tests/mochitest/bug_461710/iframe.html";
 
-function testOnWindow(aIsPrivate, aCallback) {
+function whenDelayedStartupFinished(aWindow, aCallback) {
+  Services.obs.addObserver(function observer(aSubject, aTopic) {
+    if (aWindow == aSubject) {
+      Services.obs.removeObserver(observer, aTopic);
+    }
+
+    if (aWindow.content == null || aWindow.content.location.href != contentPage) {
+      aWindow.addEventListener("DOMContentLoaded", function onInnerLoad() {
+        aWindow.removeEventListener("DOMContentLoaded", onInnerLoad, true);
+        SimpleTest.executeSoon(function() { aCallback(aWindow); });
+      }, true);
+
+      aWindow.gBrowser.loadURI(contentPage);
+    }
+  }, "browser-delayed-startup-finished", false);
+}
+
+function testOnWindow(aIsPrivate, callback) {
+  var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsIWebNavigation)
+                         .QueryInterface(Ci.nsIDocShellTreeItem)
+                         .rootTreeItem
+                         .QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsIDOMWindow);
   var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
-  win.addEventListener("load", function onLoad() {
-    win.removeEventListener("load", onLoad, false);
-    win.addEventListener("DOMContentLoaded", function onInnerLoad() {
-      if (win.content.location.href != contentPage) {
-        win.gBrowser.loadURI(contentPage);
-        return;
-      }
-      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
-      win.gBrowser.selectedBrowser.focus();
-      SimpleTest.executeSoon(function() { aCallback(win); });
-    }, true);
-    SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
-  }, true);
-}
+  whenDelayedStartupFinished(win, function() { callback(win); });
+};
 
 const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
 var observer = {
   uri: null,
   resolved: true,
   observe: function (aSubject, aTopic, aData) {
 
     if (this.uri.equals(SpecialPowers.wrap(aSubject).QueryInterface(Ci.nsIURI))) {