Bug 822284 - Intermittent browser_privatebrowsing_cookieacceptdialog.js, browser_privatebrowsing_crh.js; r=ehsan a=test-only
authorAndres Hernandez <andres@appcoast.com>
Mon, 14 Jan 2013 23:37:06 -0600
changeset 127158 f1fb362c0b925ff23084dc21daeaaf49047b88c3
parent 127157 ff27f55151e575cbc68acd73d0a9f3f701831ae2
child 127159 e84c4fb705fdb6d1574e861ff9c2f04ab052f5ea
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, test-only
bugs822284
milestone20.0a2
Bug 822284 - Intermittent browser_privatebrowsing_cookieacceptdialog.js, browser_privatebrowsing_crh.js; r=ehsan a=test-only
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
@@ -55,85 +55,98 @@ function test() {
       isSecure: false,
       expires: time,
       status: 0,
       policy: 0,
       isSession: false,
       expiry: time,
       isHttpOnly: true,
       QueryInterface: function(iid) {
-        const validIIDs = [Ci.nsISupports,
-                           Ci.nsICookie,
-                           Ci.nsICookie2];
+        const validIIDs = [Ci.nsISupports, Ci.nsICookie, Ci.nsICookie2];
         for (var i = 0; i < validIIDs.length; ++i)
           if (iid == validIIDs[i])
             return this;
         throw Cr.NS_ERROR_NO_INTERFACE;
       }
     };
     cp.cookieDialog(aWindow, cookie, "mozilla.org", 10, false, remember);
   }
 
   function checkSettingDialog(aIsPrivateWindow, aWindow, aCallback) {
-    aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab();
     let selectedBrowser = aWindow.gBrowser.selectedBrowser;
 
     function onLoad() {
+      if (aWindow.content.location.href != TEST_URL) {
+        selectedBrowser.loadURI(TEST_URL);
+        return;
+      }
       selectedBrowser.removeEventListener("load", onLoad, true);
       Services.ww.unregisterNotification(observer);
 
-      ok(aIsPrivateWindow, "Confirm setting dialog is not displayed for private window");
+      ok(aIsPrivateWindow,
+         "Confirm setting dialog is not displayed for private window");
 
       executeSoon(aCallback);
     }
     selectedBrowser.addEventListener("load", onLoad, true);
 
     function observer(aSubject, aTopic, aData) {
       if (aTopic != "domwindowopened")
         return;
       selectedBrowser.removeEventListener("load", onLoad, true);
       Services.ww.unregisterNotification(observer);
-
-      ok(!aIsPrivateWindow, "Confirm setting dialog is displayed for normal window");
-
+      ok(!aIsPrivateWindow,
+         "Confirm setting dialog is displayed for normal window");
       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
       executeSoon(function () {
-        win.close();
-        executeSoon(aCallback);
+        info("Wait for window close");
+        waitForWindowClose(win, aCallback);
       });
     }
     Services.ww.registerNotification(observer);
 
     selectedBrowser.loadURI(TEST_URL);
   }
 
-  var windowsToClose = [];
-  function testOnWindow(options, callback) {
-    var win = OpenBrowserWindow(options);
-    win.addEventListener("load", function onLoad() {
-      win.removeEventListener("load", onLoad, false);
-      windowsToClose.push(win);
-      callback(win);
-    }, false);
+  let windowsToClose = [];
+  function testOnWindow(aIsPrivate, aCallback) {
+    whenNewWindowLoaded({private: aIsPrivate}, function(aWin) {
+      windowsToClose.push(aWin);
+      aCallback(aWin);
+    });
   }
 
   registerCleanupFunction(function() {
+    Services.prefs.clearUserPref("network.cookie.lifetimePolicy");
     windowsToClose.forEach(function(win) {
-      Services.prefs.clearUserPref("network.cookie.lifetimePolicy");
       win.close();
     });
   });
 
-  // ask all cookies
+  // Ask all cookies
   Services.prefs.setIntPref("network.cookie.lifetimePolicy", 1);
 
-  testOnWindow({private: true}, function(aPrivWin) {
+  testOnWindow(true, function(aPrivWin) {
+    info("Test on private window");
     checkRememberOption(true, aPrivWin, function() {
       checkSettingDialog(true, aPrivWin, function() {
-        testOnWindow(undefined, function(aWin) {
+        testOnWindow(false, function(aWin) {
+          info("Test on public window");
           checkRememberOption(false, aWin, function() {
             checkSettingDialog(false, aWin, finish);
           });
         });
       });
     });
   });
 }
+
+function waitForWindowClose(aWin, aCallback) {
+  function observer(aSubject, aTopic, aData) {
+    if (aTopic == "domwindowclosed") {
+      info("Window closed");
+      Services.ww.unregisterNotification(observer);
+      executeSoon(aCallback);
+    }
+  }
+  Services.ww.registerNotification(observer);
+  aWin.close();
+}
--- a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_crh.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_crh.js
@@ -18,31 +18,42 @@ function test() {
       is(crhCommand.hasAttribute("disabled"), aPrivateMode,
         "Clear Recent History command should be disabled according to the private browsing mode");
 
       executeSoon(aCallback);
     });
   };
 
   let windowsToClose = [];
-  function testOnWindow(options, callback) {
-    let win = OpenBrowserWindow(options);
-    win.addEventListener("load", function onLoad() {
-      win.removeEventListener("load", onLoad, false);
-      windowsToClose.push(win);
-      callback(win);
-    }, false);
+  let testURI = "about:blank";
+
+  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;
+        }
+        aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
+        executeSoon(function() aCallback(aWin));
+      }, true);
+
+      aWin.gBrowser.loadURI(testURI);
+    });
   };
 
   registerCleanupFunction(function() {
     windowsToClose.forEach(function(win) {
       win.close();
     });
   });
 
-  testOnWindow({private: true}, function(win) {
+  testOnWindow(true, function(win) {
+    info("Test on private window");
     checkDisableOption(true, win, function() {
-      testOnWindow({}, function(win) {
+      testOnWindow(false, function(win) {
+        info("Test on public window");
         checkDisableOption(false, win, finish);
       });
     });
   });
 }