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]
This commit is contained in:
Josh Matthews 2012-10-24 00:27:58 -04:00
Родитель f945fb6ad4
Коммит 7ee9c86b25
8 изменённых файлов: 108 добавлений и 83 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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){

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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.");

Просмотреть файл

@ -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);

Просмотреть файл

@ -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");
}
}

Просмотреть файл

@ -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]