Bug 1075157 - Support action: reset search. r=gfritzsche, r=florian, r=bholley

This commit is contained in:
André Reinald 2015-04-24 17:57:52 +02:00
Родитель 1ce9a95087
Коммит abcbead4d2
6 изменённых файлов: 63 добавлений и 3 удалений

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

@ -22,4 +22,4 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.
Bug 1128037 needed a clobber to properly build on OS X
Bug 1075157 needed a clobber for unknown reasons due to Android debug mochitest crashes.

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

@ -68,6 +68,11 @@ MozSelfSupportInterface.prototype = {
resetPref: function(name) {
Services.prefs.clearUserPref(name);
},
resetSearchEngines: function() {
Services.search.restoreDefaultEngines();
Services.search.resetToOriginalDefaultEngine();
},
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozSelfSupportInterface]);

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

@ -1,6 +1,6 @@
Cu.import("resource://gre/modules/Preferences.jsm");
function test() {
function test_resetPref() {
const prefNewName = "browser.newpref.fake";
Assert.ok(!Preferences.has(prefNewName), "pref should not exist");
@ -45,3 +45,44 @@ function test() {
// clearUserPref can't undo its action
// see discussion in bug 1075160
}
function test_resetSearchEngines()
{
const defaultEngineOriginal = Services.search.defaultEngine;
const visibleEnginesOriginal = Services.search.getVisibleEngines();
// 1. do nothing on unchanged search configuration
MozSelfSupport.resetSearchEngines();
Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
"default visible engines set should be reset");
// 2. change the default search engine
const defaultEngineNew = visibleEnginesOriginal[3];
Assert.notEqual(defaultEngineOriginal, defaultEngineNew, "new default engine should be different from original");
Services.search.defaultEngine = defaultEngineNew;
Assert.equal(Services.search.defaultEngine, defaultEngineNew, "default engine should be set to new");
MozSelfSupport.resetSearchEngines();
Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
"default visible engines set should be reset");
// 3. remove an engine
const engineRemoved = visibleEnginesOriginal[2];
Services.search.removeEngine(engineRemoved);
Assert.ok(Services.search.getVisibleEngines().indexOf(engineRemoved) == -1,
"removed engine should not be visible any more");
MozSelfSupport.resetSearchEngines();
Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
"default visible engines set should be reset");
// 4. add an angine
// we don't remove user-added engines as they are only used if selected
}
function test()
{
test_resetPref();
test_resetSearchEngines();
}

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

@ -50,4 +50,9 @@ interface MozSelfSupport
* The name of the pref to reset.
*/
void resetPref(DOMString name);
/**
* Resets original search engines, and resets the default one.
*/
void resetSearchEngines();
};

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

@ -253,7 +253,7 @@ interface nsIBrowserSearchInitObserver : nsISupports
void onInitComplete(in nsresult aStatus);
};
[scriptable, uuid(4a4ce87d-7cb9-4975-a267-345f6a49bb8f)]
[scriptable, uuid(75731859-c7b1-4edf-8d1c-3d4d79a55d1d)]
interface nsIBrowserSearchService : nsISupports
{
/**
@ -281,6 +281,11 @@ interface nsIBrowserSearchService : nsISupports
*/
readonly attribute bool isInitialized;
/**
* Resets the default engine to its original value.
*/
void resetToOriginalDefaultEngine();
/**
* Adds a new search engine from the file at the supplied URI, optionally
* asking the user for confirmation first. If a confirmation dialog is

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

@ -3304,6 +3304,10 @@ SearchService.prototype = {
return this.getEngineByName(defaultEngine);
},
resetToOriginalDefaultEngine: function SRCH_SVC__resetToOriginalDefaultEngine() {
this.defaultEngine = this._originalDefaultEngine;
},
_buildCache: function SRCH_SVC__buildCache() {
if (!getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true))
return;