further change to browser_394759_privatebrowsing.js, let's make it wait for new sessionstore.js
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 28 Oct 2009 20:04:32 +0100
changeset 34253 a812503aff1c8941f4f01a220075e9ec30735308
parent 34252 57b3b6d119fd905266b5a8e60892b8900cc34e0e
child 34254 7365dfcea7b8b965fe770b8edd14b5b3def977f0
push idunknown
push userunknown
push dateunknown
milestone1.9.3a1pre
further change to browser_394759_privatebrowsing.js, let's make it wait for new sessionstore.js
browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
--- a/browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
+++ b/browser/components/sessionstore/test/browser/browser_394759_privatebrowsing.js
@@ -37,23 +37,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Private Browsing Test for Bug 394759 **/
 
   waitForExplicitFinish();
 
-  // Setup.
-  let pb = Cc["@mozilla.org/privatebrowsing;1"].
-           getService(Ci.nsIPrivateBrowsingService);
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
 
   // Remove the sessionstore.js file before setting the interval to 0
   let profilePath = Cc["@mozilla.org/file/directory_service;1"].
                     getService(Ci.nsIProperties).
                     get("ProfD", Ci.nsIFile);
   let sessionStoreJS = profilePath.clone();
   sessionStoreJS.append("sessionstore.js");
   if (sessionStoreJS.exists())
@@ -72,19 +67,49 @@ function test() {
     windows: [{
       tabs: [{ entries: [{ url: "about:blank" }] }],
       _closedTabs: []
     }],
     _closedWindows: []
   });
   ss.setBrowserState(blankState);
 
+  waitForSessionStoreJS();
+}
+
+let pass = 0;
+const MAX_PASS = 6;
+function waitForSessionStoreJS() {
+  if (++pass > MAX_PASS) {
+    throw("Timed out waiting for sessionstore.js");
+    finish();
+  }
+
+  let profilePath = Cc["@mozilla.org/file/directory_service;1"].
+                    getService(Ci.nsIProperties).
+                    get("ProfD", Ci.nsIFile);
+  let sessionStoreJS = profilePath.clone();
+  sessionStoreJS.append("sessionstore.js");
+  if (sessionStoreJS.exists())
+    executeSoon(continue_test);
+  else
+    setTimeout(500, waitForSessionStoreJS);
+}
+
+function continue_test() {
+  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
+           getService(Ci.nsIWindowWatcher);
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
+           getService(Ci.nsISessionStore);
+
   let closedWindowCount = ss.getClosedWindowCount();
   is(closedWindowCount, 0, "Correctly set window count");
-  is(sessionStoreJS.exists(), true, "sessionstore.js has been recreated")
+
   gPrefService.clearUserPref("browser.sessionstore.interval");
 
   // Prevent VM timers issues, cache now and increment it manually.
   let now = Date.now();
   const TESTS = [
     { url: "about:config",
       key: "bug 394759 Non-PB",
       value: "uniq" + (++now) },
@@ -164,17 +189,17 @@ function test() {
             }, true);
           }, false);
           // Ensure listener has been added.
           let els = Cc["@mozilla.org/eventlistenerservice;1"].
                     getService(Ci.nsIEventListenerService);
           let infos = els.getListenerInfoFor(win, {});
           is(infos.length, 1, "Window has 1 listener");
           is(infos[0].type, "load", "Window has load listener");
-          is(infos[0].capturing, false, "Window does not have a capture listener");
+          ok(!infos[0].capturing, "Window does not have a capture listener");
         }
         else if (aTopic === "domwindowclosed") {
           info("Window closed");
           ww.unregisterNotification(this);
         }
       }
     };
     ww.registerNotification(windowObserver);