Bug 806690 - Port browser_privatebrowsing_openlocation.js to the new per-window PB APIs; r=ehsan
authorBellindira Castillo [:bellindira] <bellindira@appcoast.com>
Tue, 13 Nov 2012 19:00:14 -0600
changeset 113194 59106ef8d4e2cfd13525f70437aae7a82c264af4
parent 113193 70859e1ddfe71a17fe92a78623e2fc8e53fb4f84
child 113195 12f5029c12a50a313d2f4d6e5c88f52a052dcdb5
push id23859
push useremorley@mozilla.com
push dateWed, 14 Nov 2012 14:36:31 +0000
treeherdermozilla-central@87928cd21b40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs806690
milestone19.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 806690 - Port browser_privatebrowsing_openlocation.js to the new per-window PB APIs; r=ehsan
browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_openlocation.js
--- a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
@@ -23,13 +23,14 @@ MOCHITEST_BROWSER_FILES =  \
 		browser_privatebrowsing_DownloadLastDirWithCPS.js \
 		browser_privatebrowsing_geoprompt.js \
 		browser_privatebrowsing_geoprompt_page.html \
 		browser_privatebrowsing_lastpbcontextexited.js \
 		browser_privatebrowsing_localStorage.js \
 		browser_privatebrowsing_localStorage_page1.html \
 		browser_privatebrowsing_localStorage_page2.html \
 		browser_privatebrowsing_opendir.js \
+		browser_privatebrowsing_openlocation.js \
 		browser_privatebrowsing_theming.js \
 		browser_privatebrowsing_zoomrestore.js \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_openlocation.js
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_openlocation.js
--- a/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_openlocation.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_openlocation.js
@@ -2,30 +2,27 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This test makes sure that Open Location dialog is usable inside the private browsing
 // mode without leaving any trace of the URLs visited.
 
 function test() {
   // initialization
-  gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-  let pb = Cc["@mozilla.org/privatebrowsing;1"].
-           getService(Ci.nsIPrivateBrowsingService);
   waitForExplicitFinish();
 
-  function openLocation(url, autofilled, callback) {
+  function openLocation(aWindow, url, autofilled, callback) {
     function observer(aSubject, aTopic, aData) {
       switch (aTopic) {
         case "domwindowopened":
           let dialog = aSubject.QueryInterface(Ci.nsIDOMWindow);
           dialog.addEventListener("load", function () {
             dialog.removeEventListener("load", arguments.callee, false);
 
-            let browser = gBrowser.selectedBrowser;
+            let browser = aWindow.gBrowser.selectedBrowser;
             browser.addEventListener("load", function() {
               browser.removeEventListener("load", arguments.callee, true);
 
               is(browser.currentURI.spec, url,
                  "The correct URL should be loaded via the open location dialog");
               executeSoon(callback);
             }, true);
 
@@ -41,38 +38,60 @@ function test() {
           break;
 
         case "domwindowclosed":
           Services.ww.unregisterNotification(arguments.callee);
           break;
       }
     }
 
-    Services.ww.registerNotification(observer);
-    gPrefService.setIntPref("general.open_location.last_window_choice", 0);
-    openDialog("chrome://browser/content/openLocation.xul", "_blank",
-               "chrome,titlebar", window);
+    executeSoon(function() {
+      Services.ww.registerNotification(observer);
+      gPrefService.setIntPref("general.open_location.last_window_choice", 0);
+      aWindow.openDialog("chrome://browser/content/openLocation.xul", "_blank",
+                         "chrome,titlebar", aWindow);
+    });
   }
 
+  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);
+  };
+
+  registerCleanupFunction(function() {
+    windowsToClose.forEach(function(win) {
+      win.close();
+    });
+  });
 
   if (gPrefService.prefHasUserValue("general.open_location.last_url"))
     gPrefService.clearUserPref("general.open_location.last_url");
 
-  openLocation("http://example.com/", "", function() {
-    openLocation("http://example.org/", "http://example.com/", function() {
-      // enter private browsing mode
-      pb.privateBrowsingEnabled = true;
-      openLocation("about:logo", "", function() {
-        openLocation("about:buildconfig", "about:logo", function() {
-          // exit private browsing mode
-          pb.privateBrowsingEnabled = false;
-          openLocation("about:blank", "http://example.org/", function() {
-            gPrefService.clearUserPref("general.open_location.last_url");
-            if (gPrefService.prefHasUserValue("general.open_location.last_window_choice"))
-              gPrefService.clearUserPref("general.open_location.last_window_choice");
-            gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
-            finish();
+  testOnWindow({private: false}, function(win) {
+    openLocation(win, "http://example.com/", "", function() {
+      testOnWindow({private: false}, function(win) {
+        openLocation(win, "http://example.org/", "http://example.com/", function() {
+          testOnWindow({private: true}, function(win) {
+            openLocation(win, "about:logo", "", function() {
+                testOnWindow({private: true}, function(win) {
+                  openLocation(win, "about:buildconfig", "about:logo", function() {
+                    testOnWindow({private: false}, function(win) {
+                      openLocation(win, "about:blank", "http://example.org/", function() {
+                        gPrefService.clearUserPref("general.open_location.last_url");
+                        if (gPrefService.prefHasUserValue("general.open_location.last_window_choice"))
+                          gPrefService.clearUserPref("general.open_location.last_window_choice");
+                        finish();
+                       });
+                     });
+                  });
+               });
+            });
           });
         });
       });
     });
   });
 }