Bug 806695 - Port browser_privatebrowsing_protocolhandler.js to the new per-window PB APIs; r=ehsan
authorMario Alvarado [:marioalv] <marioalv.mozilla@gmail.com>
Thu, 15 Nov 2012 16:21:12 -0600
changeset 113420 2ed2255f26ada942ac7fd22608f804aacfb98bac
parent 113419 5935517adf4d8a866f8752787b46a9c1684589d5
child 113421 dc61a415f3e907b85a562c47ce1bd985d6b44f23
push id18145
push usereakhgari@mozilla.com
push dateThu, 15 Nov 2012 22:48:38 +0000
treeherdermozilla-inbound@2ed2255f26ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs806695
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 806695 - Port browser_privatebrowsing_protocolhandler.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_protocolhandler.js
browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html
--- a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in
@@ -26,15 +26,17 @@ MOCHITEST_BROWSER_FILES =  \
 		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_openLocationLastURL.js \
 		browser_privatebrowsing_popupblocker.js \
+		browser_privatebrowsing_protocolhandler.js \
+		browser_privatebrowsing_protocolhandler_page.html \
 		browser_privatebrowsing_theming.js \
 		browser_privatebrowsing_urlbarfocus.js \
 		browser_privatebrowsing_zoomrestore.js \
 		popup.html \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler.js
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js
--- a/browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler.js
+++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js
@@ -2,53 +2,64 @@
  * 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 the web pages can't register protocol handlers
 // inside the private browsing mode.
 
 function test() {
   // initialization
-  let pb = Cc["@mozilla.org/privatebrowsing;1"].
-           getService(Ci.nsIPrivateBrowsingService);
+  waitForExplicitFinish();
+  let windowsToClose = [];
+  let notificationValue = "Protocol Registration: testprotocol";
+  let testURI = "http://example.com/browser/" +
+    "browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html";
 
-  const testPageURL = "http://example.com/browser/" +
-    "browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler_page.html";
-  waitForExplicitFinish();
-
-  const notificationValue = "Protocol Registration: testprotocol";
+  function doTest(aIsPrivateMode, aWindow, aCallback) {
+    aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
+      aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
 
-  gBrowser.selectedTab = gBrowser.addTab();
-  gBrowser.selectedBrowser.addEventListener("load", function () {
-    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+      setTimeout(function() {
+        let notificationBox = aWindow.gBrowser.getNotificationBox();
+        let notification = notificationBox.getNotificationWithValue(notificationValue);
 
-    setTimeout(function() {
-      // Make sure the notification is correctly displayed with a remember control
-      let notificationBox = gBrowser.getNotificationBox();
-      let notification = notificationBox.getNotificationWithValue(notificationValue);
-      ok(notification, "Notification box should be displaying outside of private browsing mode");
-      gBrowser.removeCurrentTab();
+        if (aIsPrivateMode) {
+          // Make sure the notification is correctly displayed without a remember control
+          ok(!notification, "Notification box should not be displayed inside of private browsing mode");
+        } else {
+          // Make sure the notification is correctly displayed with a remember control
+          ok(notification, "Notification box should be displaying outside of private browsing mode");
+        }
 
-      // enter the private browsing mode
-      pb.privateBrowsingEnabled = true;
+        aCallback();
+      }, 100); // remember control is added in a setTimeout(0) call
+    }, true);
 
-      gBrowser.selectedTab = gBrowser.addTab();
-      gBrowser.selectedBrowser.addEventListener("load", function () {
-        gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+    aWindow.gBrowser.selectedBrowser.loadURI(testURI);
+  }
 
-        setTimeout(function () {
-          // Make sure the notification is correctly displayed without a remember control
-          let notificationBox = gBrowser.getNotificationBox();
-          let notification = notificationBox.getNotificationWithValue(notificationValue);
-          ok(!notification, "Notification box should not be displayed inside of private browsing mode");
+  function testOnWindow(aOptions, aCallback) {
+    whenNewWindowLoaded(aOptions, function(aWin) {
+      windowsToClose.push(aWin);
+      // execute should only be called when need, like when you are opening
+      // web pages on the test. If calling executeSoon() is not necesary, then
+      // call whenNewWindowLoaded() instead of testOnWindow() on your test.
+      executeSoon(function() aCallback(aWin));
+    });
+  };
 
-          gBrowser.removeCurrentTab();
+   // this function is called after calling finish() on the test.
+  registerCleanupFunction(function() {
+    windowsToClose.forEach(function(aWin) {
+      aWin.close();
+    });
+  });
 
-          // cleanup
-          pb.privateBrowsingEnabled = false;
-          finish();
-        }, 100); // remember control is added in a setTimeout(0) call
-      }, true);
-      content.location = testPageURL;
-    }, 100); // remember control is added in a setTimeout(0) call
-  }, true);
-  content.location = testPageURL;
+  // test first when not on private mode
+  testOnWindow({}, function(aWin) {
+    doTest(false, aWin, function() {
+      // then test when on private mode
+      testOnWindow({private: true}, function(aWin) {
+        doTest(true, aWin, finish);
+      });
+    });
+  });
 }
copy from browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler_page.html
copy to browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html