From 183031c4dd2def8acfcb3f84557edbbe09b5f267 Mon Sep 17 00:00:00 2001 From: "Mario Alvarado [:marioalv]" Date: Thu, 15 Nov 2012 16:21:12 -0600 Subject: [PATCH] Bug 806695 - Port browser_privatebrowsing_protocolhandler.js to the new per-window PB APIs; r=ehsan --HG-- rename : browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler.js => browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js rename : browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_protocolhandler_page.html => browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html --- .../test/browser/perwindow/Makefile.in | 2 + ...browser_privatebrowsing_protocolhandler.js | 65 +++++++++++++++++++ ..._privatebrowsing_protocolhandler_page.html | 13 ++++ 3 files changed, 80 insertions(+) create mode 100644 browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js create mode 100644 browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html diff --git a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in index 01db09777afe..bff0f8852c0b 100644 --- a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in +++ b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in @@ -31,6 +31,8 @@ MOCHITEST_BROWSER_FILES = \ 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 \ diff --git a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js new file mode 100644 index 000000000000..db3e195e7b91 --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler.js @@ -0,0 +1,65 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 + 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"; + + function doTest(aIsPrivateMode, aWindow, aCallback) { + aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { + aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + + setTimeout(function() { + let notificationBox = aWindow.gBrowser.getNotificationBox(); + let notification = notificationBox.getNotificationWithValue(notificationValue); + + 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"); + } + + aCallback(); + }, 100); // remember control is added in a setTimeout(0) call + }, true); + + aWindow.gBrowser.selectedBrowser.loadURI(testURI); + } + + 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)); + }); + }; + + // this function is called after calling finish() on the test. + registerCleanupFunction(function() { + windowsToClose.forEach(function(aWin) { + aWin.close(); + }); + }); + + // 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); + }); + }); + }); +} diff --git a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html new file mode 100644 index 000000000000..74f846d54a7d --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_protocolhandler_page.html @@ -0,0 +1,13 @@ + + + + Protocol registrar page + + + + +