Bug 1357804: Stop making metadata requests to AMO for system add-ons. r=rhelmer
MozReview-Commit-ID: 2TiAaNqdB3o
--- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm
@@ -116,37 +116,47 @@ function convertHTMLToPlainText(html) {
converter.convert("text/html", input, input.data.length, "text/unicode",
output, {});
if (output.value instanceof Ci.nsISupportsString)
return output.value.data.replace(/\r\n/g, "\n");
return html;
}
-function getAddonsToCache(aIds) {
+async function getAddonsToCache(aIds) {
let types = Preferences.get(PREF_GETADDONS_CACHE_TYPES) || DEFAULT_CACHE_TYPES;
types = types.split(",");
- return AddonManager.getAddonsByIDs(aIds).then(addons => {
- let enabledIds = [];
- for (let [i, addon] of addons.entries()) {
- var preference = PREF_GETADDONS_CACHE_ID_ENABLED.replace("%ID%", aIds[i]);
- // If the preference doesn't exist caching is enabled by default
- if (!Preferences.get(preference, true))
- continue;
+ let addons = await AddonManager.getAddonsByIDs(aIds)
+ let enabledIds = [];
- // The add-ons manager may not know about this ID yet if it is a pending
- // install. In that case we'll just cache it regardless
- if (!addon || types.includes(addon.type))
- enabledIds.push(aIds[i]);
+ for (let [i, addon] of addons.entries()) {
+ var preference = PREF_GETADDONS_CACHE_ID_ENABLED.replace("%ID%", aIds[i]);
+ // If the preference doesn't exist caching is enabled by default
+ if (!Preferences.get(preference, true))
+ continue;
+
+ // The add-ons manager may not know about this ID yet if it is a pending
+ // install. In that case we'll just cache it regardless
+
+ // Don't cache add-ons of the wrong types
+ if (addon && !types.includes(addon.type)) {
+ continue;
}
- return enabledIds;
- });
+ // Don't cache system add-ons
+ if (addon && addon.isSystem) {
+ continue;
+ }
+
+ enabledIds.push(aIds[i]);
+ }
+
+ return enabledIds;
}
function AddonSearchResult(aId) {
this.id = aId;
this.icons = {};
this._unsupportedProperties = {};
}
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_system_repository.js
@@ -0,0 +1,52 @@
+// Tests that AddonRepository doesn't download results for system add-ons
+
+const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
+
+BootstrapMonitor.init();
+
+Components.utils.import("resource://testing-common/httpd.js");
+var gServer = new HttpServer();
+gServer.start(-1);
+
+// Build the test set
+var distroDir = FileUtils.getDir("ProfD", ["sysfeatures"], true);
+do_get_file("data/system_addons/system1_1.xpi").copyTo(distroDir, "system1@tests.mozilla.org.xpi");
+do_get_file("data/system_addons/system2_1.xpi").copyTo(distroDir, "system2@tests.mozilla.org.xpi");
+do_get_file("data/system_addons/system3_1.xpi").copyTo(distroDir, "system3@tests.mozilla.org.xpi");
+registerDirectory("XREAppFeat", distroDir);
+
+createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "0");
+
+function getCachedAddon(id) {
+ return new Promise(resolve => AddonRepository.getCachedAddonByID(id, resolve));
+}
+
+// Test with a missing features directory
+add_task(function* test_app_addons() {
+ Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
+ Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, `http://localhost:${gServer.identity.primaryPort}/get?%IDS%`);
+
+ gServer.registerPathHandler("/get", (request, response) => {
+ do_throw("Unexpected request to server.");
+ });
+
+ startupManager();
+
+ yield new Promise((resolve) => {
+ AddonRepository.cacheAddons(["system1@tests.mozilla.org",
+ "system2@tests.mozilla.org",
+ "system3@tests.mozilla.org"], resolve);
+ });
+
+ let cached = yield getCachedAddon("system1@tests.mozilla.org");
+ do_check_eq(cached, null);
+
+ cached = yield getCachedAddon("system2@tests.mozilla.org");
+ do_check_eq(cached, null);
+
+ cached = yield getCachedAddon("system3@tests.mozilla.org");
+ do_check_eq(cached, null);
+
+ yield promiseShutdownManager();
+ yield new Promise(resolve => gServer.stop(resolve));
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -27,16 +27,17 @@ tags = blocklist
[test_provider_markSafe.js]
[test_provider_shutdown.js]
[test_provider_unsafe_access_shutdown.js]
[test_provider_unsafe_access_startup.js]
[test_ProductAddonChecker.js]
[test_shutdown.js]
[test_system_update.js]
[test_system_update_fail.js]
+[test_system_repository.js]
[test_system_reset.js]
[test_XPIcancel.js]
[test_XPIStates.js]
[test_temporary.js]
tags = webextensions
[test_install_from_sources.js]
[test_proxies.js]
[test_proxy.js]