Bug 1115063 - test_localStorageQuotaPrivateBrowsing_perwindowpb.html fails when run as a standalone directory. r=ehsan
authorJoel Maher <jmaher@mozilla.com>
Mon, 26 Jan 2015 14:41:35 -0500
changeset 239192 4244155f633a715e1635c499661020bcb438d139
parent 239191 aa85f08f9f76b2637282d32c52ece39b88e4515d
child 239193 6f06c4beef24a4a67892fd46ed169e3ec878216f
push id489
push usermcmanus@ducksong.com
push dateTue, 27 Jan 2015 01:44:53 +0000
reviewersehsan
bugs1115063
milestone38.0a1
Bug 1115063 - test_localStorageQuotaPrivateBrowsing_perwindowpb.html fails when run as a standalone directory. r=ehsan
dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html
--- a/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaPrivateBrowsing_perwindowpb.html
@@ -19,20 +19,16 @@ var quota;
 try {
   quota = Services.prefs.getIntPref("dom.storage.default_quota");
 } catch (ex) {
   quota = 5 * 1024;
 }
 Services.prefs.setIntPref("browser.startup.page", 0);
 Services.prefs.setIntPref("dom.storage.default_quota", 1);
 
-var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).
-  getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem).
-  rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor).
-  getInterface(Ci.nsIDOMWindow);
 var slaveLoadsPending = 1;
 var slaveOrigin = "";
 var slave = null;
 var failureRegExp = new RegExp("^FAILURE");
 
 function startTest() {
   testOnWindow(true, function(aWindow) {
     info("Private window loaded");
@@ -152,30 +148,41 @@ function onMessageReceived(event, aWindo
       break;
     // Any other message indicates error or succes message of a test
     default:
       SimpleTest.ok(!event.data.match(failureRegExp), event.data);
       break;
   }
 }
 
-function testOnWindow(aIsPrivate, aCallback) {
-  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 != CONTENT_PAGE) {
-        win.gBrowser.loadURI(CONTENT_PAGE);
-        return;
-      }
-      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
-      win.gBrowser.selectedBrowser.focus();
-      SimpleTest.executeSoon(function() { aCallback(win); });
-    }, true);
-    win.gBrowser.loadURI(CONTENT_PAGE);
-  }, true);
+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 != CONTENT_PAGE ) {
+      aWindow.addEventListener("DOMContentLoaded", function onInnerLoad() {
+        aWindow.removeEventListener("DOMContentLoaded", onInnerLoad, true);
+        SimpleTest.executeSoon(function() { aCallback(aWindow); });
+      }, true);
+
+      aWindow.gBrowser.loadURI(CONTENT_PAGE);
+    }
+  }, "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});
+  whenDelayedStartupFinished(win, function() { callback(win); });
+};
 </script>
 </head>
 <body onload="startTest();">
 </body>
 </html>