Bug 577685 - Do not allow adding search engines during private browsing mode; r=gavin.sharp ui-r=beltzner approval2.0=beltzner

This commit is contained in:
Ehsan Akhgari 2010-07-27 16:21:29 -04:00
parent c91d03b575
commit 0ad0994cc4
2 changed files with 23 additions and 3 deletions

View File

@ -3091,7 +3091,8 @@ const DOMLinkHandler = {
type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");
if (type == "application/opensearchdescription+xml" && link.title &&
/^(?:https?|ftp):/i.test(link.href)) {
/^(?:https?|ftp):/i.test(link.href) &&
!gPrivateBrowsingUI.privateBrowsingEnabled) {
var engine = { title: link.title, href: link.href };
BrowserSearch.addEngine(engine, link.ownerDocument);
searchAdded = true;

View File

@ -40,6 +40,7 @@
function test() {
// initialization
waitForExplicitFinish();
gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
let pb = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
@ -68,6 +69,24 @@ function test() {
is(searchBar.textbox.editor.transactionManager.numberOfUndoItems, 1,
"leaving the private browsing mode should only leave 1 item in the undo list of the searchbar control");
// enter private browsing mode
pb.privateBrowsingEnabled = true;
const TEST_URL =
"data:text/html,<head><link rel=search type='application/opensearchdescription+xml' href='http://foo.bar' title=dummy></head>";
gBrowser.selectedTab = gBrowser.addTab(TEST_URL);
gBrowser.selectedBrowser.addEventListener("load", function(e) {
e.currentTarget.removeEventListener("load", arguments.callee, true);
var browser = gBrowser.selectedBrowser;
is(typeof browser.engines, "undefined",
"An engine should not be discovered in private browsing mode");
gBrowser.removeTab(gBrowser.selectedTab);
pb.privateBrowsingEnabled = false;
// cleanup
gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
finish();
}, true);
}