Bug 565458 - Attempt to fix intermittent browser_privatebrowsing_beforeunload.js test failure. r=ehsan, a=NPOTB
authorNochum Sossonko <highmind63@gmail.com>
Thu, 29 Jul 2010 20:33:01 -0400
changeset 48390 4214929901439e71c0a23b2b518d70dbb49f8270
parent 48389 1e89617828246e7240d47c0a943dfa94b1b3acea
child 48391 1d0d268c33aa372747e3aeb764a3298a1d7e25fc
push id14708
push userhighmind63@gmail.com
push dateFri, 30 Jul 2010 00:33:35 +0000
treeherdermozilla-central@421492990143 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, NPOTB
bugs565458
milestone2.0b3pre
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 565458 - Attempt to fix intermittent browser_privatebrowsing_beforeunload.js test failure. r=ehsan, a=NPOTB
browser/components/privatebrowsing/test/browser/Makefile.in
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload_enter.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload_exit.js
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -41,17 +41,18 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/privatebrowsing/test/browser
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES =  \
 		browser_console_clear.js \
-		browser_privatebrowsing_beforeunload.js \
+		browser_privatebrowsing_beforeunload_enter.js \
+		browser_privatebrowsing_beforeunload_exit.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_commandline_toggle.js \
 		browser_privatebrowsing_cookieacceptdialog.js \
 		browser_privatebrowsing_crh.js \
 		browser_privatebrowsing_downloadmonitor.js \
 		browser_privatebrowsing_fastswitch.js \
 		browser_privatebrowsing_findbar.js \
 		browser_privatebrowsing_forgetthissite.js \
rename from browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
rename to browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload_enter.js
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload_enter.js
@@ -93,73 +93,21 @@ function test() {
          "Incorrect number of tabs after transition into private browsing");
       gBrowser.selectedBrowser.addEventListener("load", function() {
         gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
 
         is(gBrowser.currentURI.spec, "about:privatebrowsing",
            "Incorrect page displayed after private browsing transition");
         is(acceptDialog, 0, "Two confirm dialogs should have been accepted");
 
-        gBrowser.selectedBrowser.addEventListener("load", function() {
-          gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
-
-          gBrowser.selectedTab = gBrowser.addTab();
-          gBrowser.selectedBrowser.addEventListener("load", function() {
-            gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
-
-            confirmCalls = 0;
-            rejectDialog = 1;
-            pb.privateBrowsingEnabled = false;
-
-            ok(pb.privateBrowsingEnabled, "Private browsing mode should not have been deactivated");
-            is(confirmCalls, 1, "Only one confirm box should be shown");
-            is(gBrowser.tabs.length, 2,
-               "No tabs should be closed because private browsing mode transition was canceled");
-            is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec, TEST_PAGE_1,
-               "The first tab should be the same one we opened");
-            is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, TEST_PAGE_2,
-               "The last tab should be the same one we opened");
-            is(rejectDialog, 0, "Only one confirm dialog should have been rejected");
-
-            confirmCalls = 0;
-            acceptDialog = 2;
-            pb.privateBrowsingEnabled = false;
-
-            ok(!pb.privateBrowsingEnabled, "Private browsing mode should have been deactivated");
-            is(confirmCalls, 2, "Only two confirm boxes should be shown");
-            is(gBrowser.tabs.length, 3,
-               "Incorrect number of tabs after transition into private browsing");
-
-            let loads = 0;
-            function waitForLoad(event) {
-              gBrowser.removeEventListener("load", arguments.callee, true);
-
-              if (++loads != 3)
-                return;
-
-              is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec, "about:blank",
-                 "The first tab should be a blank tab");
-              is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild.nextSibling).currentURI.spec, TEST_PAGE_1,
-                 "The middle tab should be the same one we opened");
-              is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, TEST_PAGE_2,
-                 "The last tab should be the same one we opened");
-              is(acceptDialog, 0, "Two confirm dialogs should have been accepted");
-              is(acceptDialog, 0, "Two prompts should have been raised");
-
-              acceptDialog = 2;
-              gBrowser.removeTab(gBrowser.tabContainer.lastChild);
-              gBrowser.removeTab(gBrowser.tabContainer.lastChild);
-
-              Services.obs.removeObserver(promptObserver, "common-dialog-loaded", false);
-              finish();
-            }
-            for (let i = 0; i < gBrowser.browsers.length; ++i)
-              gBrowser.browsers[i].addEventListener("load", waitForLoad, true);
-          }, true);
-          gBrowser.selectedBrowser.loadURI(TEST_PAGE_2);
-        }, true);
-        gBrowser.selectedBrowser.loadURI(TEST_PAGE_1);
+        gBrowser.addTab();
+        gBrowser.removeTab(gBrowser.selectedTab);
+        Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+        pb.privateBrowsingEnabled = false;
+        Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+        Services.obs.removeObserver(promptObserver, "common-dialog-loaded", false);
+        finish();
       }, true);
     }, true);
     browser2.loadURI(TEST_PAGE_2);
   }, true);
   browser1.loadURI(TEST_PAGE_1);
 }
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_beforeunload_exit.js
@@ -0,0 +1,124 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Private Browsing Tests.
+ *
+ * The Initial Developer of the Original Code is
+ * Nochum Sossonko.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Nochum Sossonko <highmind63@gmail.com> (Original Author)
+ *   Ehsan Akhgari <ehsan@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+// This test makes sure that cancelling the unloading of a page with a beforeunload
+// handler prevents the private browsing mode transition.
+
+function test() {
+  const TEST_PAGE_1 = "data:text/html,<body%20onbeforeunload='return%20false;'>first</body>";
+  const TEST_PAGE_2 = "data:text/html,<body%20onbeforeunload='return%20false;'>second</body>";
+  let pb = Cc["@mozilla.org/privatebrowsing;1"]
+             .getService(Ci.nsIPrivateBrowsingService);
+
+  let rejectDialog = 0;
+  let acceptDialog = 0;
+  let confirmCalls = 0;
+  function promptObserver(aSubject, aTopic, aData) {
+    let dialogWin = aSubject.QueryInterface(Ci.nsIDOMWindow);
+    confirmCalls++;
+    if (acceptDialog-- > 0)
+      dialogWin.document.documentElement.getButton("accept").click();
+    else if (rejectDialog-- > 0)
+      dialogWin.document.documentElement.getButton("cancel").click();
+  }
+
+  Services.obs.addObserver(promptObserver, "common-dialog-loaded", false);
+  pb.privateBrowsingEnabled = true;
+
+  waitForExplicitFinish();
+  let browser1 = gBrowser.getBrowserForTab(gBrowser.addTab());
+  browser1.addEventListener("load", function() {
+    browser1.removeEventListener("load", arguments.callee, true);
+
+    let browser2 = gBrowser.getBrowserForTab(gBrowser.addTab());
+    browser2.addEventListener("load", function() {
+      browser2.removeEventListener("load", arguments.callee, true);
+
+      confirmCalls = 0;
+      rejectDialog = 1;
+      pb.privateBrowsingEnabled = false;
+
+      ok(pb.privateBrowsingEnabled, "Private browsing mode should not have been deactivated");
+      is(confirmCalls, 1, "Only one confirm box should be shown");
+      is(gBrowser.tabs.length, 3,
+         "No tabs should be closed because private browsing mode transition was canceled");
+      is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec, "about:privatebrowsing",
+         "The first tab should be the same one we opened");
+      is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, TEST_PAGE_2,
+         "The last tab should be the same one we opened");
+      is(rejectDialog, 0, "Only one confirm dialog should have been rejected");
+
+      confirmCalls = 0;
+      acceptDialog = 2;
+      pb.privateBrowsingEnabled = false;
+
+      ok(!pb.privateBrowsingEnabled, "Private browsing mode should have been deactivated");
+      is(confirmCalls, 2, "Only two confirm boxes should be shown");
+      is(gBrowser.tabs.length, 3,
+         "Incorrect number of tabs after transition into private browsing");
+
+      let loads = 0;
+      function waitForLoad(event) {
+        gBrowser.removeEventListener("load", arguments.callee, true);
+
+        if (++loads != 3)
+          return;
+
+        is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec, "about:blank",
+           "The first tab should be a blank tab");
+        is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild.nextSibling).currentURI.spec, TEST_PAGE_1,
+           "The middle tab should be the same one we opened");
+        is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, TEST_PAGE_2,
+           "The last tab should be the same one we opened");
+        is(acceptDialog, 0, "Two confirm dialogs should have been accepted");
+        is(acceptDialog, 0, "Two prompts should have been raised");
+
+        acceptDialog = 2;
+        gBrowser.removeTab(gBrowser.tabContainer.lastChild);
+        gBrowser.removeTab(gBrowser.tabContainer.lastChild);
+
+        Services.obs.removeObserver(promptObserver, "common-dialog-loaded", false);
+        finish();
+      }
+      for (let i = 0; i < gBrowser.browsers.length; ++i)
+        gBrowser.browsers[i].addEventListener("load", waitForLoad, true);
+    }, true);
+    browser2.loadURI(TEST_PAGE_2);
+  }, true);
+  browser1.loadURI(TEST_PAGE_1);
+}