Bug 1622978 - Dont load distribution engines from filesystem in modern config r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D67498

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dale Harvey 2020-04-08 11:08:07 +00:00
Родитель 76130a7bbf
Коммит 08352f15e3
5 изменённых файлов: 70 добавлений и 52 удалений

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

@ -32,6 +32,7 @@ AddonTestUtils.createAppInfo(
);
add_task(async function setup() {
Services.prefs.setBoolPref("browser.search.modernConfig", false);
await AddonTestUtils.promiseStartupManager();
});

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

@ -1126,47 +1126,7 @@ SearchService.prototype = {
async _loadEngines(cache, isReload) {
SearchUtils.log("_loadEngines: start");
let engines = await this._findEngines();
// Get the non-empty distribution directories into distDirs...
let distDirs = [];
let locations;
try {
locations = Services.dirsvc.get(
NS_APP_DISTRIBUTION_SEARCH_DIR_LIST,
Ci.nsISimpleEnumerator
);
} catch (e) {
// NS_APP_DISTRIBUTION_SEARCH_DIR_LIST is defined by each app
// so this throws during unit tests (but not xpcshell tests).
locations = [];
}
for (let dir of locations) {
let iterator = new OS.File.DirectoryIterator(dir.path, {
winPattern: "*.xml",
});
try {
// Add dir to distDirs if it contains any files.
let { done } = await iterator.next();
if (!done) {
distDirs.push(dir);
}
} catch (ex) {
if (!(ex instanceof OS.File.Error)) {
throw ex;
}
if (ex.becauseAccessDenied) {
Cu.reportError(
"Not loading distribution files because access was denied."
);
} else if (!ex.becauseNoSuchFile) {
throw ex;
}
} finally {
// If there's an issue on close, we can't do anything about it. It could
// be that reading the iterator never fully opened.
iterator.close().catch(Cu.reportError);
}
}
let distDirs = await this._getDistibutionEngineDirectories();
let buildID = Services.appinfo.platformBuildID;
let rebuildCache =
@ -1335,6 +1295,59 @@ SearchService.prototype = {
return engines;
},
/**
* Get the directories that contain distribution engines.
*
* @returns {array}
* Returns an array of directories that contain distribution engines.
*/
async _getDistibutionEngineDirectories() {
if (gModernConfig) {
return [];
}
// Get the non-empty distribution directories into distDirs...
let distDirs = [];
let locations;
try {
locations = Services.dirsvc.get(
NS_APP_DISTRIBUTION_SEARCH_DIR_LIST,
Ci.nsISimpleEnumerator
);
} catch (e) {
// NS_APP_DISTRIBUTION_SEARCH_DIR_LIST is defined by each app
// so this throws during unit tests (but not xpcshell tests).
locations = [];
}
for (let dir of locations) {
let iterator = new OS.File.DirectoryIterator(dir.path, {
winPattern: "*.xml",
});
try {
// Add dir to distDirs if it contains any files.
let { done } = await iterator.next();
if (!done) {
distDirs.push(dir);
}
} catch (ex) {
if (!(ex instanceof OS.File.Error)) {
throw ex;
}
if (ex.becauseAccessDenied) {
Cu.reportError(
"Not loading distribution files because access was denied."
);
} else if (!ex.becauseNoSuchFile) {
throw ex;
}
} finally {
// If there's an issue on close, we can't do anything about it. It could
// be that reading the iterator never fully opened.
iterator.close().catch(Cu.reportError);
}
}
return distDirs;
},
/**
* Ensures a built in search WebExtension is installed, installing
* it if necessary.

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

@ -29,8 +29,9 @@ const SUBMISSION_NO = new Map([
add_task(async function setup() {
await useTestEngines("data1");
installDistributionEngine();
if (!gModernConfig) {
installDistributionEngine();
}
await AddonTestUtils.promiseStartupManager();
});
@ -80,6 +81,9 @@ add_task(async function test_submission_url_built_in() {
});
add_task(async function test_submission_url_distribution() {
if (gModernConfig) {
return;
}
const engine = Services.search.getEngineByName("basic");
await Services.search.setDefault(engine);

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

@ -3,7 +3,6 @@
[test_addEngineWithDetailsObject.js]
[test_addEngineWithExtensionID.js]
[test_async_addon.js]
[test_async_distribution.js]
[test_async_disthidden.js]
[test_async.js]
[test_big_icon.js]
@ -28,13 +27,6 @@ skip-if = os == "win" # Windows doesn't have the same sort of permissions manage
[test_ignorelist.js]
[test_invalid_engine_from_dir.js]
[test_json_cache_broken.js]
[test_json_cache_good_distro.js]
support-files =
data1/engine1/manifest.json
data1/engine2/manifest.json
data1/list.json
data1/engines.json
data1/engine3.xml
[test_json_cache_good.js]
[test_json_cache_ignorelist.js]
support-files = data/search_ignorelist.json
@ -68,7 +60,6 @@ support-files =
[test_purpose.js]
[test_rel_searchform.js]
[test_require_engines_in_cache.js]
[test_remove_distro_engine.js]
[test_remove_profile_engine.js]
[test_resultDomain.js]
[test_save_sorted_engines.js]

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

@ -63,3 +63,12 @@ skip-if = ccov || tsan # Bug 1590254, tsan: bug 1612707
[test_legacy_reload_engines.js]
[test_geodefaults.js]
[test_hidden.js]
[test_async_distribution.js]
[test_remove_distro_engine.js]
[test_json_cache_good_distro.js]
support-files =
data1/engine1/manifest.json
data1/engine2/manifest.json
data1/list.json
data1/engines.json
data1/engine3.xml