Bug 890609 - Make test_privbrowsing_perwindowpb.html wait for browser-delayed-startup-finished
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 16 Mar 2014 10:46:52 -0400
changeset 191027 550a7a811a30339e4c0a8ac31114560ea7ee8d03
parent 191026 c313ebdadc1587f3f09780ed8b038833bbca26db
child 191028 5ea145120fc9ba282ae39832bfa75c9440bf429c
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs890609
milestone30.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 890609 - Make test_privbrowsing_perwindowpb.html wait for browser-delayed-startup-finished
toolkit/components/passwordmgr/test/test_privbrowsing_perwindowpb.html
--- a/toolkit/components/passwordmgr/test/test_privbrowsing_perwindowpb.html
+++ b/toolkit/components/passwordmgr/test/test_privbrowsing_perwindowpb.html
@@ -19,16 +19,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 248970 **/
 // based on test_notifications.html
 
 const Ci = SpecialPowers.Ci;
 const Cc = SpecialPowers.Cc;
 const Cr = SpecialPowers.Cr;
 
+Components.utils.import("resource://gre/modules/Services.jsm");
+
 var testpath = "/tests/toolkit/components/passwordmgr/test/";
 var prefix = "http://test2.example.com" + testpath;
 var subtests = [
                    "subtst_privbrowsing_1.html", // 1
                    "subtst_privbrowsing_1.html", // 2
                    "subtst_privbrowsing_1.html", // 3
                    "subtst_privbrowsing_2.html", // 4
                    "subtst_privbrowsing_2.html", // 5
@@ -186,34 +188,45 @@ var mainWindow = window.QueryInterface(C
                     .getInterface(Ci.nsIWebNavigation)
                     .QueryInterface(Ci.nsIDocShellTreeItem)
                     .rootTreeItem
                     .QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIDOMWindow);
 var contentPage = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/test/privbrowsing_perwindowpb_iframe.html";
 var testWindows = [];
 
+function whenDelayedStartupFinished(aWindow, aCallback) {
+  Services.obs.addObserver(function observer(aSubject, aTopic) {
+    if (aWindow == aSubject) {
+      Services.obs.removeObserver(observer, aTopic);
+      setTimeout(aCallback, 0);
+    }
+  }, "browser-delayed-startup-finished", false);
+}
+
 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 != contentPage) {
-        win.gBrowser.loadURI(contentPage);
-        return;
-      }
-      win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
+    whenDelayedStartupFinished(win, function() {
+      win.addEventListener("DOMContentLoaded", function onInnerLoad() {
+        if (win.content.location.href != contentPage) {
+          win.gBrowser.loadURI(contentPage);
+          return;
+        }
+        win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
 
-      win.content.addEventListener('load', function innerLoad2() {
-        win.content.removeEventListener('load', innerLoad2, false);
-        testWindows.push(win);
-        SimpleTest.executeSoon(function() { aCallback(win); });
-      }, false, true);
-    }, true);
-    SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
+        win.content.addEventListener('load', function innerLoad2() {
+          win.content.removeEventListener('load', innerLoad2, false);
+          testWindows.push(win);
+          SimpleTest.executeSoon(function() { aCallback(win); });
+        }, false, true);
+      }, true);
+      SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
+    });
   }, true);
 }
 
 var ignoreLoad = false;
 function handleLoad(aEvent) {
   // ignore every other load event ... We get one for loading the subtest (which
   // we want to ignore), and another when the subtest's form submits itself
   // (which we want to handle, to start the next test).