Bug 822284 - Intermittent browser_privatebrowsing_cookieacceptdialog.js, browser_privatebrowsing_crh.js; r=ehsan
authorAndres Hernandez <andres@appcoast.com>
Fri, 01 Feb 2013 15:05:29 -0600
changeset 122209 4466d3ff8ada315e689120977012702733af932e
parent 122208 2962a3ff97dad7b1468a3b54c0bb474853f61585
child 122211 b4673ca3faccef843e496fc464f270838aa732c3
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs822284
milestone21.0a1
Bug 822284 - Intermittent browser_privatebrowsing_cookieacceptdialog.js, browser_privatebrowsing_crh.js; r=ehsan
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_cookieacceptdialog.js
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_crh.js
--- a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_cookieacceptdialog.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_cookieacceptdialog.js
@@ -3,18 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This test makes sure that private browsing mode disables the "remember"
 // option in the cookie accept dialog.
 
 function test() {
   // initialization
   const TEST_URL = "http://mochi.test:8888/browser/browser/components/" +
-                   "privatebrowsing/test/browser/perwindow/" + 
+                   "privatebrowsing/test/browser/perwindow/" +
                    "browser_privatebrowsing_cookieacceptdialog.html";
+  const BLANK_URL = "http://mochi.test:8888/";
   let cp = Cc["@mozilla.org/embedcomp/cookieprompt-service;1"].
            getService(Ci.nsICookiePromptService);
 
   waitForExplicitFinish();
 
   function checkRememberOption(expectedDisabled, aWindow, callback) {
     function observer(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
@@ -32,18 +33,17 @@ function test() {
 
           if (expectedDisabled)
             is(remember.getAttribute("disabled"), "true",
                "The checkbox should be disabled");
           else
             ok(!remember.hasAttribute("disabled"),
                "The checkbox should not be disabled");
 
-          win.close();
-          executeSoon(callback);
+          waitForWindowClose(win, callback);
         });
       }, false);
     }
     Services.ww.registerNotification(observer);
 
     let remember = {};
     const time = (new Date("Jan 1, 2030")).getTime() / 1000;
     let cookie = {
@@ -105,17 +105,26 @@ function test() {
 
     selectedBrowser.loadURI(TEST_URL);
   }
 
   let windowsToClose = [];
   function testOnWindow(aIsPrivate, aCallback) {
     whenNewWindowLoaded({private: aIsPrivate}, function(aWin) {
       windowsToClose.push(aWin);
-      aCallback(aWin);
+      let selectedBrowser = aWin.gBrowser.selectedBrowser;
+      selectedBrowser.addEventListener("load", function onLoad() {
+        if (aWin.content.location.href != BLANK_URL) {
+          selectedBrowser.loadURI(BLANK_URL);
+          return;
+        }
+        selectedBrowser.removeEventListener("load", onLoad, true);
+        aCallback(aWin);
+      }, true);
+      selectedBrowser.loadURI(BLANK_URL);
     });
   }
 
   registerCleanupFunction(function() {
     Services.prefs.clearUserPref("network.cookie.lifetimePolicy");
     windowsToClose.forEach(function(win) {
       win.close();
     });
--- a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_crh.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_crh.js
@@ -18,17 +18,17 @@ function test() {
       is(crhCommand.hasAttribute("disabled"), aPrivateMode,
         "Clear Recent History command should be disabled according to the private browsing mode");
 
       executeSoon(aCallback);
     });
   };
 
   let windowsToClose = [];
-  let testURI = "about:blank";
+  let testURI = "http://mochi.test:8888/";
 
   function testOnWindow(aIsPrivate, aCallback) {
     whenNewWindowLoaded({private: aIsPrivate}, function(aWin) {
       windowsToClose.push(aWin);
       aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
         if (aWin.content.location.href != testURI) {
           aWin.gBrowser.loadURI(testURI);
           return;