Bug 697377 - Use Asynchronous FormHistory.jsm for content/search.xml, p=enndeakin,felix, r=mak

This commit is contained in:
Felix Fung 2011-12-22 06:46:44 -05:00
parent 38683fb3ae
commit 1f23de3ed7
2 changed files with 43 additions and 22 deletions

View File

@ -109,6 +109,9 @@
"anonid", "searchbar-popup");</field>
<field name="_ss">null</field>
<field name="_engines">null</field>
<field name="FormHistory" readonly="true">
(Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory;
</field>
<property name="engines" readonly="true">
<getter><![CDATA[
@ -455,12 +458,13 @@
// Save the current value in the form history
if (textValue && !PrivateBrowsingUtils.isWindowPrivate(window)) {
try {
textBox._formHistSvc.addEntry(textBox.getAttribute("autocompletesearchparam"),
textValue);
} catch (ex) {
Components.utils.reportError("Saving search to form history failed: " + ex);
}
this.FormHistory.update(
{ op : "bump",
fieldname : textBox.getAttribute("autocompletesearchparam"),
value : textValue },
{ onFailure : function(aError) {
Components.utils.reportError("Saving search to form history failed: " + aError.message);
}});
}
this.doSearch(textValue, where);
@ -554,7 +558,6 @@
]]></destructor>
<field name="_stringBundle"/>
<field name="_formHistSvc"/>
<field name="_prefBranch"/>
<field name="_suggestMenuItem"/>
<field name="_suggestEnabled"/>
@ -565,9 +568,6 @@
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
// Initialize fields
this._stringBundle = document.getBindingParent(this)._stringBundle;
this._formHistSvc =
Components.classes["@mozilla.org/satchel/form-history;1"]
.getService(Components.interfaces.nsIFormHistory2);
this._prefBranch =
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
@ -748,10 +748,6 @@
},
isCommandEnabled: function(aCommand) {
if (aCommand == "cmd_clearhistory") {
var param = this._self.getAttribute("autocompletesearchparam");
return this._self._formHistSvc.nameExists(param);
}
return true;
},
@ -759,7 +755,10 @@
switch (aCommand) {
case "cmd_clearhistory":
var param = this._self.getAttribute("autocompletesearchparam");
this._self._formHistSvc.removeEntriesForName(param);
let searchBar = this._self.parentNode;
BrowserSearch.searchBar.FormHistory.update({ op : "remove", fieldname : param }, null);
this._self.value = "";
break;
case "cmd_togglesuggest":

View File

@ -5,6 +5,9 @@ this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", chromeUtils);
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
"resource://gre/modules/FormHistory.jsm");
function test() {
waitForExplicitFinish();
@ -20,6 +23,8 @@ function test() {
var ss = Services.search;
let testIterator;
function observer(aSub, aTopic, aData) {
switch (aData) {
case "engine-added":
@ -182,33 +187,50 @@ function test() {
content.location.href = "about:blank";
simulateClick({ button: 2 }, searchButton);
setTimeout(function() {
is(gBrowser.tabs.length, preTabNo, "RightClick did not open new tab");
is(gBrowser.currentURI.spec, "about:blank", "RightClick did nothing");
testSearchHistory();
testIterator = testSearchHistory();
testIterator.next();
}, 5000);
}
function countEntries(name, value, message) {
FormHistory.count({ fieldname: name, value: value },
{ onSuccess: function(num) { ok(num > 0, message); testIterator.next(); },
onFailure: function(error) { throw error; }
});
}
function testSearchHistory() {
var textbox = searchBar._textbox;
for (var i = 0; i < searchEntries.length; i++) {
let exists = textbox._formHistSvc.entryExists(textbox.getAttribute("autocompletesearchparam"), searchEntries[i]);
ok(exists, "form history entry '" + searchEntries[i] + "' should exist");
yield countEntries(textbox.getAttribute("autocompletesearchparam"), searchEntries[i],
"form history entry '" + searchEntries[i] + "' should exist");
}
testAutocomplete();
}
function testAutocomplete() {
var popup = searchBar.textbox.popup;
popup.addEventListener("popupshowing", function testACPopupShowing() {
popup.removeEventListener("popupshowing", testACPopupShowing);
popup.addEventListener("popupshown", function testACPopupShowing() {
popup.removeEventListener("popupshown", testACPopupShowing);
checkMenuEntries(searchEntries);
SimpleTest.executeSoon(finalize);
testClearHistory();
});
searchBar.textbox.showHistoryPopup();
}
function testClearHistory() {
let controller = searchBar.textbox.controllers.getControllerForCommand("cmd_clearhistory")
ok(controller.isCommandEnabled("cmd_clearhistory"), "Clear history command enabled");
controller.doCommand("cmd_clearhistory");
FormHistory.count({ },
{ onSuccess: function(num) { ok(!num, "History cleared"); finalize(); },
onFailure: function(error) { throw error; }
});
}
function finalize() {
searchBar.value = "";
while (gBrowser.tabs.length != 1) {