Bug 1162569 - default engine files should be in the omni.ja file, r=markh,glandium.
This commit is contained in:
@@ -383,6 +383,10 @@ pref("browser.helperApps.deleteTempFileOnExit", true);
|
||||
// search engines URL
|
||||
pref("browser.search.searchEnginesURL", "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
|
||||
|
||||
// Tell the search service to load search plugins from the locale JAR
|
||||
pref("browser.search.loadFromJars", true);
|
||||
pref("browser.search.jarURIs", "chrome://browser/locale/searchplugins/");
|
||||
|
||||
// pointer to the default engine name
|
||||
pref("browser.search.defaultenginename", "chrome://browser-region/locale/region.properties");
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
@RESPATH@/dictionaries/*
|
||||
@RESPATH@/hyphenation/*
|
||||
@RESPATH@/browser/@PREF_DIR@/firefox-l10n.js
|
||||
@RESPATH@/browser/searchplugins/*
|
||||
#ifdef HAVE_MAKENSISU
|
||||
@BINPATH@/uninstall/helper.exe
|
||||
#endif
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
vpath %.xml @srcdir@/en-US/searchplugins
|
||||
vpath %.xml $(LOCALE_SRCDIR)/searchplugins
|
||||
|
||||
ifdef LOCALE_MERGEDIR
|
||||
vpath crashreporter%.ini $(LOCALE_MERGEDIR)/browser/crashreporter
|
||||
endif
|
||||
@@ -72,7 +69,7 @@ STUB_HOOK = $(NSINSTALL) -D '$(_ABS_DIST)/$(PKG_INST_PATH)'; \
|
||||
endif
|
||||
|
||||
SEARCHPLUGINS_NAMES = $(shell cat $(call MERGE_FILE,/searchplugins/list.txt)) ddg
|
||||
SEARCHPLUGINS_PATH := $(FINAL_TARGET)/searchplugins
|
||||
SEARCHPLUGINS_PATH := .deps/generated_$(AB_CD)
|
||||
SEARCHPLUGINS_TARGET := libs searchplugins
|
||||
SEARCHPLUGINS := $(foreach plugin,$(addsuffix .xml,$(SEARCHPLUGINS_NAMES)),$(or $(wildcard $(call EN_US_OR_L10N_FILE,searchplugins/$(plugin))),$(info Missing searchplugin: $(plugin))))
|
||||
# Some locale-specific search plugins may have preprocessor directives, but the
|
||||
@@ -80,6 +77,11 @@ SEARCHPLUGINS := $(foreach plugin,$(addsuffix .xml,$(SEARCHPLUGINS_NAMES)),$(or
|
||||
SEARCHPLUGINS_FLAGS := --silence-missing-directive-warnings
|
||||
PP_TARGETS += SEARCHPLUGINS
|
||||
|
||||
list-txt = $(SEARCHPLUGINS_PATH)/list.txt
|
||||
GARBAGE += $(list-txt)
|
||||
|
||||
libs:: searchplugins
|
||||
|
||||
# Required for l10n.mk - defines a list of app sub dirs that should
|
||||
# be included in langpack xpis.
|
||||
DIST_SUBDIRS = $(DIST_SUBDIR)
|
||||
@@ -88,6 +90,11 @@ include $(topsrcdir)/config/rules.mk
|
||||
|
||||
include $(topsrcdir)/toolkit/locales/l10n.mk
|
||||
|
||||
$(list-txt): $(call mkdir_deps,$(SEARCHPLUGINS_PATH)) $(if $(IS_LANGUAGE_REPACK),FORCE)
|
||||
$(RM) $(list-txt)
|
||||
$(foreach plugin,$(SEARCHPLUGINS_NAMES),printf '$(plugin)\n' >> $(list-txt);)
|
||||
searchplugins:: $(list-txt)
|
||||
|
||||
$(STAGEDIST): $(DIST)/branding
|
||||
|
||||
$(DIST)/branding:
|
||||
@@ -126,6 +133,7 @@ ifdef MOZ_WEBAPP_RUNTIME
|
||||
endif
|
||||
@$(MAKE) -C ../../extensions/spellcheck/locales AB_CD=$* XPI_NAME=locale-$*
|
||||
@$(MAKE) -C ../../intl/locales AB_CD=$* XPI_NAME=locale-$*
|
||||
@$(MAKE) -B searchplugins AB_CD=$* XPI_NAME=locale-$*
|
||||
@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=$(PREF_DIR)
|
||||
@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$*
|
||||
|
||||
@@ -158,8 +166,7 @@ clobber-zip:
|
||||
$(STAGEDIST)/webapprt/chrome/$(AB_CD).jar \
|
||||
$(STAGEDIST)/webapprt/chrome/$(AB_CD).manifest \
|
||||
$(STAGEDIST)/$(PREF_DIR)/firefox-l10n.js
|
||||
$(RM) -rf $(STAGEDIST)/searchplugins \
|
||||
$(STAGEDIST)/dictionaries \
|
||||
$(RM) -rf $(STAGEDIST)/dictionaries \
|
||||
$(STAGEDIST)/hyphenation \
|
||||
$(STAGEDIST)/defaults/profile \
|
||||
$(STAGEDIST)/chrome/$(AB_CD) \
|
||||
|
||||
@@ -148,6 +148,8 @@
|
||||
locale/browser/syncQuota.dtd (%chrome/browser/syncQuota.dtd)
|
||||
locale/browser/syncQuota.properties (%chrome/browser/syncQuota.properties)
|
||||
#endif
|
||||
locale/browser/searchplugins/list.txt (.deps/generated_@AB_CD@/list.txt)
|
||||
locale/browser/searchplugins/ (.deps/generated_@AB_CD@/*.xml)
|
||||
% locale browser-region @AB_CD@ %locale/browser-region/
|
||||
locale/browser-region/region.properties (%chrome/browser-region/region.properties)
|
||||
# the following files are browser-specific overrides
|
||||
|
||||
@@ -3405,20 +3405,26 @@ SearchService.prototype = {
|
||||
cache = this._readCacheFile(cacheFile);
|
||||
}
|
||||
|
||||
let loadDirs = [];
|
||||
let loadDirs = [], chromeURIs = [], chromeFiles = [];
|
||||
|
||||
let loadFromJARs = false;
|
||||
try {
|
||||
loadFromJARs = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
|
||||
.getBoolPref("loadFromJars");
|
||||
} catch (ex) {}
|
||||
|
||||
if (loadFromJARs)
|
||||
[chromeFiles, chromeURIs] = this._findJAREngines();
|
||||
|
||||
let locations = getDir(NS_APP_SEARCH_DIR_LIST, Ci.nsISimpleEnumerator);
|
||||
while (locations.hasMoreElements()) {
|
||||
let dir = locations.getNext().QueryInterface(Ci.nsIFile);
|
||||
if (loadFromJARs && dir.equals(getDir(NS_APP_SEARCH_DIR)))
|
||||
continue;
|
||||
if (dir.directoryEntries.hasMoreElements())
|
||||
loadDirs.push(dir);
|
||||
}
|
||||
|
||||
let loadFromJARs = getBoolPref(BROWSER_SEARCH_PREF + "loadFromJars", false);
|
||||
let chromeURIs = [];
|
||||
let chromeFiles = [];
|
||||
if (loadFromJARs)
|
||||
[chromeFiles, chromeURIs] = this._findJAREngines();
|
||||
|
||||
let toLoad = chromeFiles.concat(loadDirs);
|
||||
|
||||
function modifiedDir(aDir) {
|
||||
@@ -3475,12 +3481,29 @@ SearchService.prototype = {
|
||||
cache = yield checkForSyncCompletion(this._asyncReadCacheFile(cacheFilePath));
|
||||
}
|
||||
|
||||
// Add all the non-empty directories of NS_APP_SEARCH_DIR_LIST to
|
||||
// loadDirs.
|
||||
let loadDirs = [];
|
||||
let loadDirs = [], chromeURIs = [], chromeFiles = [];
|
||||
|
||||
let loadFromJARs = false;
|
||||
try {
|
||||
loadFromJARs = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
|
||||
.getBoolPref("loadFromJars");
|
||||
} catch (ex) {}
|
||||
|
||||
if (loadFromJARs) {
|
||||
Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines");
|
||||
[chromeFiles, chromeURIs] =
|
||||
yield checkForSyncCompletion(this._asyncFindJAREngines());
|
||||
}
|
||||
|
||||
// Add the non-empty directories of NS_APP_SEARCH_DIR_LIST to
|
||||
// loadDirs...
|
||||
let locations = getDir(NS_APP_SEARCH_DIR_LIST, Ci.nsISimpleEnumerator);
|
||||
while (locations.hasMoreElements()) {
|
||||
let dir = locations.getNext().QueryInterface(Ci.nsIFile);
|
||||
// ... but skip the application directory if we are loading from JAR.
|
||||
if (loadFromJARs && dir.equals(getDir(NS_APP_SEARCH_DIR)))
|
||||
continue;
|
||||
|
||||
let iterator = new OS.File.DirectoryIterator(dir.path,
|
||||
{ winPattern: "*.xml" });
|
||||
try {
|
||||
@@ -3494,15 +3517,6 @@ SearchService.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
let loadFromJARs = getBoolPref(BROWSER_SEARCH_PREF + "loadFromJars", false);
|
||||
let chromeURIs = [];
|
||||
let chromeFiles = [];
|
||||
if (loadFromJARs) {
|
||||
Services.obs.notifyObservers(null, SEARCH_SERVICE_TOPIC, "find-jar-engines");
|
||||
[chromeFiles, chromeURIs] =
|
||||
yield checkForSyncCompletion(this._asyncFindJAREngines());
|
||||
}
|
||||
|
||||
let toLoad = chromeFiles.concat(loadDirs);
|
||||
function hasModifiedDir(aList) {
|
||||
return Task.spawn(function() {
|
||||
@@ -3867,7 +3881,8 @@ SearchService.prototype = {
|
||||
|
||||
let rootURIPref = ""
|
||||
try {
|
||||
rootURIPref = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "jarURIs");
|
||||
rootURIPref = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
|
||||
.getCharPref("jarURIs");
|
||||
} catch (ex) {}
|
||||
|
||||
if (!rootURIPref) {
|
||||
@@ -3883,27 +3898,25 @@ SearchService.prototype = {
|
||||
rootURIs.forEach(function (root) {
|
||||
// Find the underlying JAR file for this chrome package (_loadEngines uses
|
||||
// it to determine whether it needs to invalidate the cache)
|
||||
let chromeFile;
|
||||
let jarPackaging = false;
|
||||
try {
|
||||
let chromeURI = gChromeReg.convertChromeURL(makeURI(root));
|
||||
let fileURI = chromeURI; // flat packaging
|
||||
while (fileURI instanceof Ci.nsIJARURI)
|
||||
fileURI = fileURI.JARFile; // JAR packaging
|
||||
fileURI.QueryInterface(Ci.nsIFileURL);
|
||||
chromeFile = fileURI.file;
|
||||
if (chromeURI instanceof Ci.nsIJARURI) {
|
||||
let fileURI = chromeURI;
|
||||
while (fileURI instanceof Ci.nsIJARURI)
|
||||
fileURI = fileURI.JARFile;
|
||||
fileURI.QueryInterface(Ci.nsIFileURL);
|
||||
chromeFiles.push(fileURI.file);
|
||||
jarPackaging = true;
|
||||
}
|
||||
} catch (ex) {
|
||||
LOG("_findJAREngines: failed to get chromeFile for " + root + ": " + ex);
|
||||
}
|
||||
|
||||
if (!chromeFile)
|
||||
return;
|
||||
|
||||
chromeFiles.push(chromeFile);
|
||||
}
|
||||
|
||||
// Read list.txt from the chrome package to find the engines we need to
|
||||
// load
|
||||
let listURL = root + "list.txt";
|
||||
let names = [];
|
||||
try {
|
||||
let chan = NetUtil.ioService.newChannelFromURI2(makeURI(listURL),
|
||||
null, // aLoadingNode
|
||||
@@ -3915,14 +3928,22 @@ SearchService.prototype = {
|
||||
createInstance(Ci.nsIScriptableInputStream);
|
||||
sis.init(chan.open());
|
||||
let list = sis.read(sis.available());
|
||||
names = list.split("\n").filter(function (n) !!n);
|
||||
let names = list.split("\n").filter(function (n) !!n);
|
||||
for (let name of names) {
|
||||
let uri = root + name + ".xml";
|
||||
uris.push(uri);
|
||||
if (!jarPackaging) {
|
||||
// Flat packaging requires that _loadEngines checks the modification
|
||||
// time of each engine file.
|
||||
uri = gChromeReg.convertChromeURL(makeURI(uri));
|
||||
chromeFiles.push(uri.QueryInterface(Ci.nsIFileURL).file);
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
LOG("_findJAREngines: failed to retrieve list.txt from " + listURL + ": " + ex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
names.forEach(function (n) uris.push(root + n + ".xml"));
|
||||
});
|
||||
|
||||
return [chromeFiles, uris];
|
||||
@@ -3940,7 +3961,8 @@ SearchService.prototype = {
|
||||
|
||||
let rootURIPref = "";
|
||||
try {
|
||||
rootURIPref = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "jarURIs");
|
||||
rootURIPref = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF)
|
||||
.getCharPref("jarURIs");
|
||||
} catch (ex) {}
|
||||
|
||||
if (!rootURIPref) {
|
||||
@@ -3955,24 +3977,22 @@ SearchService.prototype = {
|
||||
for (let root of rootURIs) {
|
||||
// Find the underlying JAR file for this chrome package (_loadEngines uses
|
||||
// it to determine whether it needs to invalidate the cache)
|
||||
let chromeFile;
|
||||
let jarPackaging = false;
|
||||
try {
|
||||
let chromeURI = gChromeReg.convertChromeURL(makeURI(root));
|
||||
let fileURI = chromeURI; // flat packaging
|
||||
while (fileURI instanceof Ci.nsIJARURI)
|
||||
fileURI = fileURI.JARFile; // JAR packaging
|
||||
fileURI.QueryInterface(Ci.nsIFileURL);
|
||||
chromeFile = fileURI.file;
|
||||
if (chromeURI instanceof Ci.nsIJARURI) {
|
||||
let fileURI = chromeURI;
|
||||
while (fileURI instanceof Ci.nsIJARURI)
|
||||
fileURI = fileURI.JARFile;
|
||||
fileURI.QueryInterface(Ci.nsIFileURL);
|
||||
chromeFiles.push(fileURI.file);
|
||||
jarPackaging = true;
|
||||
}
|
||||
} catch (ex) {
|
||||
LOG("_asyncFindJAREngines: failed to get chromeFile for " + root + ": " + ex);
|
||||
}
|
||||
|
||||
if (!chromeFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
chromeFiles.push(chromeFile);
|
||||
|
||||
// Read list.txt from the chrome package to find the engines we need to
|
||||
// load
|
||||
let listURL = root + "list.txt";
|
||||
@@ -3993,7 +4013,16 @@ SearchService.prototype = {
|
||||
|
||||
let names = [];
|
||||
names = list.split("\n").filter(function (n) !!n);
|
||||
names.forEach(function (n) uris.push(root + n + ".xml"));
|
||||
for (let name of names) {
|
||||
let uri = root + name + ".xml";
|
||||
uris.push(uri);
|
||||
if (!jarPackaging) {
|
||||
// Flat packaging requires that _loadEngines checks the modification
|
||||
// time of each engine file.
|
||||
uri = gChromeReg.convertChromeURL(makeURI(uri));
|
||||
chromeFiles.push(uri.QueryInterface(Ci.nsIFileURL).file);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Task.Result([chromeFiles, uris]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>TestEngineApp</ShortName>
|
||||
<Description>A test search engine installed in the application directory</Description>
|
||||
<InputEncoding>ISO-8859-1</InputEncoding>
|
||||
<Url type="text/html" method="GET" template="http://localhost/" resultdomain="localhost">
|
||||
<Param name="q" value="{searchTerms}"/>
|
||||
</Url>
|
||||
</SearchPlugin>
|
||||
@@ -71,6 +71,31 @@ function dumpn(text)
|
||||
dump("search test: " + text + "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure preferences to load engines from
|
||||
* chrome://testsearchplugin/locale/searchplugins/
|
||||
* unless the loadFromJars parameter is set to false.
|
||||
*/
|
||||
function configureToLoadJarEngines(loadFromJars = true)
|
||||
{
|
||||
let defaultBranch = Services.prefs.getDefaultBranch(null);
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
defaultBranch.setCharPref("browser.search.jarURIs", url);
|
||||
|
||||
defaultBranch.setBoolPref("browser.search.loadFromJars", loadFromJars);
|
||||
|
||||
// Give the pref a user set value that is the opposite of the default,
|
||||
// to ensure user set values are ignored.
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", !loadFromJars)
|
||||
|
||||
// Ensure a test engine exists in the app dir anyway.
|
||||
let dir = Services.dirsvc.get(NS_APP_SEARCH_DIR, Ci.nsIFile);
|
||||
if (!dir.exists())
|
||||
dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
||||
do_get_file("data/engine-app.xml").copyTo(dir, "app.xml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean the profile of any metadata files left from a previous run.
|
||||
*/
|
||||
|
||||
@@ -12,10 +12,7 @@ function run_test() {
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
// The search service needs to be started after the jarURIs pref has been
|
||||
// set in order to initiate it correctly
|
||||
@@ -23,4 +20,3 @@ function run_test() {
|
||||
do_check_neq(engine, null);
|
||||
Services.obs.notifyObservers(null, "quit-application", null);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@ function run_test() {
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
@@ -19,18 +17,14 @@ function run_test() {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
// test jar engine is loaded ok.
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
Services.prefs.clearUserPref("browser.search.jarURIs");
|
||||
Services.prefs.clearUserPref("browser.search.loadFromJars");
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
30
toolkit/components/search/tests/xpcshell/test_async_app.js
Normal file
30
toolkit/components/search/tests/xpcshell/test_async_app.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
removeMetadata();
|
||||
removeCacheFile();
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
configureToLoadJarEngines(false);
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
Services.search.init(function search_initialized(aStatus) {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test engine from dir is loaded.
|
||||
let engine = Services.search.getEngineByName("TestEngineApp");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
// test jar engine is not loaded.
|
||||
engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_eq(engine, null);
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
@@ -14,9 +14,7 @@ function run_test() {
|
||||
removeCacheFile();
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
updateAppInfo();
|
||||
|
||||
@@ -56,4 +54,3 @@ add_test(function test_identifier() {
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@ function getDir(aKey, aIFace) {
|
||||
return _dirSvc.get(aKey, aIFace || Ci.nsIFile);
|
||||
}
|
||||
|
||||
function makeURI(uri) {
|
||||
return Services.io.newURI(uri, null, null);
|
||||
}
|
||||
|
||||
let cacheTemplate, appPluginsPath, profPlugins;
|
||||
|
||||
/**
|
||||
@@ -51,12 +55,59 @@ function run_test() {
|
||||
let engineTemplateFile = do_get_file("data/engine.xml");
|
||||
engineTemplateFile.copyTo(engineFile.parent, "test-search-engine.xml");
|
||||
|
||||
// Add the app's searchplugins directory to the cache so it won't be ignored.
|
||||
let appSearchPlugins = getDir(NS_APP_SEARCH_DIR);
|
||||
appPluginsPath = appSearchPlugins.path;
|
||||
cacheTemplate.directories[appPluginsPath] = {};
|
||||
cacheTemplate.directories[appPluginsPath].lastModifiedTime = appSearchPlugins.lastModifiedTime;
|
||||
cacheTemplate.directories[appPluginsPath].engines = [];
|
||||
// Add the application's built-in plugin locations to the cache so it won't be ignored.
|
||||
let filesToIgnore = []
|
||||
let defaultBranch = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
|
||||
|
||||
let loadFromJARs = false;
|
||||
try {
|
||||
loadFromJARs = defaultBranch.getBoolPref("loadFromJars");
|
||||
} catch (ex) {}
|
||||
|
||||
if (!loadFromJARs) {
|
||||
filesToIgnore.push(getDir(NS_APP_SEARCH_DIR));
|
||||
} else {
|
||||
let rootURIPref = defaultBranch.getCharPref("jarURIs");
|
||||
let rootURIs = rootURIPref.split(",");
|
||||
for (let root of rootURIs) {
|
||||
let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
||||
getService(Ci.nsIChromeRegistry);
|
||||
let chromeURI = chromeReg.convertChromeURL(makeURI(root));
|
||||
if (chromeURI instanceof Ci.nsIJARURI) {
|
||||
// JAR packaging, we only need the parent jar file.
|
||||
let fileURI = chromeURI; // flat packaging
|
||||
while (fileURI instanceof Ci.nsIJARURI)
|
||||
fileURI = fileURI.JARFile;
|
||||
fileURI.QueryInterface(Ci.nsIFileURL);
|
||||
filesToIgnore.push(fileURI.file);
|
||||
} else {
|
||||
// flat packaging, we need to find each .xml file.
|
||||
let listURL = root + "list.txt";
|
||||
let chan = NetUtil.ioService.newChannelFromURI2(makeURI(listURL),
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"].
|
||||
createInstance(Ci.nsIScriptableInputStream);
|
||||
sis.init(chan.open());
|
||||
let list = sis.read(sis.available());
|
||||
let names = list.split("\n").filter(n => !!n);
|
||||
for (let name of names) {
|
||||
let uri = chromeReg.convertChromeURL(makeURI(root + name + ".xml"));
|
||||
filesToIgnore.push(uri.QueryInterface(Ci.nsIFileURL).file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let file of filesToIgnore) {
|
||||
cacheTemplate.directories[file.path] = {
|
||||
lastModifiedTime: file.lastModifiedTime,
|
||||
engines: []
|
||||
};
|
||||
}
|
||||
|
||||
// Replace the profile placeholder with the correct path.
|
||||
profPlugins = engineFile.parent.path;
|
||||
@@ -160,8 +211,12 @@ add_test(function test_cache_write() {
|
||||
// Check that the search.json cache matches the template
|
||||
|
||||
let cacheWritten = readJSONFile(cache);
|
||||
// Delete the app search plugins directory from the template since it's not currently written out.
|
||||
delete cacheTemplate.directories[appPluginsPath];
|
||||
|
||||
// Delete the empty dirs from the template since they are not written out.
|
||||
for (let dir of Object.keys(cacheTemplate.directories)) {
|
||||
if (!cacheTemplate.directories[dir].engines.length)
|
||||
delete cacheTemplate.directories[dir];
|
||||
}
|
||||
|
||||
do_print("Check search.json");
|
||||
isSubObjectOf(cacheTemplate, cacheWritten);
|
||||
|
||||
@@ -7,23 +7,17 @@ function run_test() {
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test jar engine is loaded ok.
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
Services.prefs.clearUserPref("browser.search.jarURIs");
|
||||
Services.prefs.clearUserPref("browser.search.loadFromJars");
|
||||
}
|
||||
|
||||
|
||||
23
toolkit/components/search/tests/xpcshell/test_sync_app.js
Normal file
23
toolkit/components/search/tests/xpcshell/test_sync_app.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function run_test() {
|
||||
removeMetadata();
|
||||
removeCacheFile();
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
configureToLoadJarEngines(false);
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
// test engine from dir is loaded.
|
||||
let engine = Services.search.getEngineByName("TestEngineApp");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test jar engine is not loaded.
|
||||
engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_eq(engine, null);
|
||||
}
|
||||
@@ -9,9 +9,7 @@ function run_test() {
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
let fallback = false;
|
||||
@@ -21,17 +19,14 @@ function run_test() {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
// test jar engine is loaded ok.
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
Services.prefs.clearUserPref("browser.search.jarURIs");
|
||||
Services.prefs.clearUserPref("browser.search.loadFromJars");
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
|
||||
@@ -43,9 +38,9 @@ function run_test() {
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
// test jar engine is loaded ok.
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
|
||||
@@ -9,9 +9,7 @@ function run_test() {
|
||||
|
||||
do_load_manifest("data/chrome.manifest");
|
||||
|
||||
let url = "chrome://testsearchplugin/locale/searchplugins/";
|
||||
Services.prefs.setCharPref("browser.search.jarURIs", url);
|
||||
Services.prefs.setBoolPref("browser.search.loadFromJars", true);
|
||||
configureToLoadJarEngines();
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
@@ -19,25 +17,22 @@ function run_test() {
|
||||
do_check_true(Components.isSuccessCode(aStatus));
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
// test jar engine is loaded ok.
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_neq(engine, null);
|
||||
|
||||
Services.prefs.clearUserPref("browser.search.jarURIs");
|
||||
Services.prefs.clearUserPref("browser.search.loadFromJars");
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
|
||||
do_check_false(Services.search.isInitialized);
|
||||
|
||||
// test engines from dir are loaded.
|
||||
// test engines from dir are not loaded.
|
||||
let engines = Services.search.getEngines();
|
||||
do_check_true(engines.length > 1);
|
||||
do_check_eq(engines.length, 1);
|
||||
|
||||
do_check_true(Services.search.isInitialized);
|
||||
|
||||
@@ -45,4 +40,3 @@ function run_test() {
|
||||
let engine = Services.search.getEngineByName("bug645970");
|
||||
do_check_neq(engine, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ support-files =
|
||||
data/engine.src
|
||||
data/engine.xml
|
||||
data/engine2.xml
|
||||
data/engine-app.xml
|
||||
data/engine-fr.xml
|
||||
data/engineMaker.sjs
|
||||
data/engine-rel-searchform.xml
|
||||
@@ -53,7 +54,9 @@ support-files =
|
||||
[test_serialize_file.js]
|
||||
[test_searchSuggest.js]
|
||||
[test_async.js]
|
||||
[test_async_app.js]
|
||||
[test_sync.js]
|
||||
[test_sync_app.js]
|
||||
[test_sync_fallback.js]
|
||||
[test_sync_delay_fallback.js]
|
||||
[test_rel_searchform.js]
|
||||
|
||||
Reference in New Issue
Block a user