From 7ee9c86b250fa3beaadfa24a8c0693cc3f063320 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 24 Oct 2012 00:27:58 -0400 Subject: [PATCH] Bug 723001 - Move privacy state checking from nsFormHistory to its callers. r=dolske * * * Bug 800669 - "Remove recent addition of gPrivateBrowsingUI in PB search bar test" [r=josh] --- browser/components/search/content/search.xml | 2 +- browser/components/search/test/Makefile.in | 1 + .../search/test/browser_contextmenu.js | 1 + .../search/test/browser_private_search.js | 101 ++++++++++++++++++ .../components/satchel/formSubmitListener.js | 3 + toolkit/components/satchel/nsFormHistory.js | 18 +--- .../satchel/test/unit/test_bug_248970.js | 62 ----------- .../components/satchel/test/unit/xpcshell.ini | 3 - 8 files changed, 108 insertions(+), 83 deletions(-) create mode 100644 browser/components/search/test/browser_private_search.js delete mode 100644 toolkit/components/satchel/test/unit/test_bug_248970.js diff --git a/browser/components/search/content/search.xml b/browser/components/search/content/search.xml index a97aba492340..e354572ce0d8 100644 --- a/browser/components/search/content/search.xml +++ b/browser/components/search/content/search.xml @@ -436,7 +436,7 @@ } // Save the current value in the form history - if (textValue) { + if (textValue && !PrivateBrowsingUtils.isWindowPrivate(window)) { try { textBox._formHistSvc.addEntry(textBox.getAttribute("autocompletesearchparam"), textValue); diff --git a/browser/components/search/test/Makefile.in b/browser/components/search/test/Makefile.in index 9d46cbb5a9e5..f2a4b045e1c0 100644 --- a/browser/components/search/test/Makefile.in +++ b/browser/components/search/test/Makefile.in @@ -22,6 +22,7 @@ MOCHITEST_BROWSER_FILES = browser_405664.js \ 483086-1.xml \ 483086-2.xml \ test.html \ + browser_private_search.js \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/browser/components/search/test/browser_contextmenu.js b/browser/components/search/test/browser_contextmenu.js index 1151d68f0966..3e4b74a8d0e8 100644 --- a/browser/components/search/test/browser_contextmenu.js +++ b/browser/components/search/test/browser_contextmenu.js @@ -59,6 +59,7 @@ function test() { is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label"); is(searchItem.disabled, false, "Check that search context menu item is enabled"); searchItem.click(); + contextMenu.hidePopup(); } function checkSearchURL(event){ diff --git a/browser/components/search/test/browser_private_search.js b/browser/components/search/test/browser_private_search.js new file mode 100644 index 000000000000..6ef21950dec3 --- /dev/null +++ b/browser/components/search/test/browser_private_search.js @@ -0,0 +1,101 @@ +// This test performs a search in a public window, then a different +// search in a private window, and then checks in the public window +// whether there is an autocomplete entry for the private search. + +function onLoad(callback) { + gBrowser.addEventListener("DOMContentLoaded", function load() { + gBrowser.removeEventListener("DOMContentLoaded", load, false); + callback(); + }, false); +} + +function doPrivateTest(searchBar) { + gPrivateBrowsingUI.toggleMode(); + Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session"); + + searchBar.value = "p"; + searchBar.focus(); + let popup = searchBar.textbox.popup; + //searchBar.textbox.closePopup(); + + info("adding listener"); + popup.addEventListener("popupshowing", function showing() { + let entries = getMenuEntries(searchBar); + for (var i = 0; i < entries.length; i++) + isnot(entries[0], "private test", "shouldn't see private autocomplete entries"); + popup.removeEventListener("popupshowing", showing, false); + + searchBar.textbox.toggleHistoryPopup(); + executeSoon(function() { + searchBar.value = ""; + gBrowser.addTab(); + gBrowser.removeCurrentTab(); + content.location.href = "about:blank"; + var engine = Services.search.getEngineByName("Bug 426329"); + Services.search.removeEngine(engine); + finish(); + + }); + }, false); + + info("triggering popup"); + searchBar.textbox.showHistoryPopup(); +} + +function doTest() { + let searchBar = BrowserSearch.searchBar; + ok(searchBar, "got search bar"); + + onLoad(function() { + Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); + gPrivateBrowsingUI.toggleMode(); + + onLoad(function() { + doPrivateTest(searchBar); + }); + + searchBar.value = "private test"; + searchBar.focus(); + EventUtils.synthesizeKey("VK_RETURN", {}); + }); + + searchBar.value = "public test"; + searchBar.focus(); + EventUtils.synthesizeKey("VK_RETURN", {}); +} + +function test() { + waitForExplicitFinish(); + //gBrowser.addTab(); + //let testBrowser = gBrowser.selectedBrowser; + + function observer(aSub, aTopic, aData) { + switch (aData) { + case "engine-current": + ok(ss.currentEngine.name == "Bug 426329", "currentEngine set"); + doTest(); + break; + default: + break; + } + } + + var ss = Services.search; + Services.obs.addObserver(observer, "browser-search-engine-modified", false); + ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/426329.xml", + Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00", + false); +} + +function getMenuEntries(searchBar) { + var entries = []; + var autocompleteMenu = searchBar.textbox.popup; + // Could perhaps pull values directly from the controller, but it seems + // more reliable to test the values that are actually in the tree? + var column = autocompleteMenu.tree.columns[0]; + var numRows = autocompleteMenu.tree.view.rowCount; + for (var i = 0; i < numRows; i++) { + entries.push(autocompleteMenu.tree.view.getValueAt(i, column)); + } + return entries; +} diff --git a/toolkit/components/satchel/formSubmitListener.js b/toolkit/components/satchel/formSubmitListener.js index 36ac524576e3..e1dfe61b30a3 100644 --- a/toolkit/components/satchel/formSubmitListener.js +++ b/toolkit/components/satchel/formSubmitListener.js @@ -9,6 +9,7 @@ var Ci = Components.interfaces; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); var satchelFormListener = { QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver, @@ -103,6 +104,8 @@ var satchelFormListener = { if (!this.enabled) return; + if (PrivateBrowsingUtils.isWindowPrivate(domWin)) + return; this.log("Form submit observer notified."); diff --git a/toolkit/components/satchel/nsFormHistory.js b/toolkit/components/satchel/nsFormHistory.js index 400b77142a1a..b97d9d05cab8 100644 --- a/toolkit/components/satchel/nsFormHistory.js +++ b/toolkit/components/satchel/nsFormHistory.js @@ -73,21 +73,6 @@ FormHistory.prototype = { return this._uuidService; }, - // Private Browsing Service - // If the service is not available, null will be returned. - _privBrowsingSvc : undefined, - get privBrowsingSvc() { - if (this._privBrowsingSvc == undefined) { - if ("@mozilla.org/privatebrowsing;1" in Cc) - this._privBrowsingSvc = Cc["@mozilla.org/privatebrowsing;1"]. - getService(Ci.nsIPrivateBrowsingService); - else - this._privBrowsingSvc = null; - } - return this._privBrowsingSvc; - }, - - log : function log(message) { if (!this.debug) return; @@ -143,8 +128,7 @@ FormHistory.prototype = { addEntry : function addEntry(name, value) { - if (!this.enabled || - this.privBrowsingSvc && this.privBrowsingSvc.privateBrowsingEnabled) + if (!this.enabled) return; this.log("addEntry for " + name + "=" + value); diff --git a/toolkit/components/satchel/test/unit/test_bug_248970.js b/toolkit/components/satchel/test/unit/test_bug_248970.js deleted file mode 100644 index 243dfdbfa75d..000000000000 --- a/toolkit/components/satchel/test/unit/test_bug_248970.js +++ /dev/null @@ -1,62 +0,0 @@ -/* 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/. */ - -var _PBSvc = null; -function get_PBSvc() { - if (_PBSvc) - return _PBSvc; - - try { - _PBSvc = Components.classes["@mozilla.org/privatebrowsing;1"]. - getService(Components.interfaces.nsIPrivateBrowsingService); - return _PBSvc; - } catch (e) {} - return null; -} - -var _FHSvc = null; -function get_FormHistory() { - if (_FHSvc) - return _FHSvc; - - return _FHSvc = Components.classes["@mozilla.org/satchel/form-history;1"]. - getService(Components.interfaces.nsIFormHistory2); -} - -function run_test() { - var pb = get_PBSvc(); - if (pb) { // Private Browsing might not be available - var prefBranch = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefBranch); - prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true); - - var fh = get_FormHistory(); - do_check_neq(fh, null); - - // remove possible Pair-A and Pair-B left-overs from previous tests - fh.removeEntriesForName("pair-A"); - fh.removeEntriesForName("pair-B"); - - // save Pair-A - fh.addEntry("pair-A", "value-A"); - // ensure that Pair-A exists - do_check_true(fh.entryExists("pair-A", "value-A")); - // enter private browsing mode - pb.privateBrowsingEnabled = true; - // make sure that Pair-A exists - do_check_true(fh.entryExists("pair-A", "value-A")); - // attempt to save Pair-B - fh.addEntry("pair-B", "value-B"); - // make sure that Pair-B does not exist - do_check_false(fh.entryExists("pair-B", "value-B")); - // exit private browsing mode - pb.privateBrowsingEnabled = false; - // ensure that Pair-A exists - do_check_true(fh.entryExists("pair-A", "value-A")); - // make sure that Pair-B does not exist - do_check_false(fh.entryExists("pair-B", "value-B")); - - prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session"); - } -} diff --git a/toolkit/components/satchel/test/unit/xpcshell.ini b/toolkit/components/satchel/test/unit/xpcshell.ini index ec912956c97e..8e3643f53905 100644 --- a/toolkit/components/satchel/test/unit/xpcshell.ini +++ b/toolkit/components/satchel/test/unit/xpcshell.ini @@ -3,9 +3,6 @@ head = head_satchel.js tail = [test_autocomplete.js] -[test_bug_248970.js] -# Bug 676989: test hangs on Android -skip-if = os == "android" [test_db_corrupt.js] [test_db_update_v1.js] [test_db_update_v1b.js]