Bug 1476177 Fix platform matching in AMO metadata requests
MozReview-Commit-ID: EvjeXdCyLxi
--- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm
@@ -13,16 +13,36 @@ XPCOMUtils.defineLazyModuleGetters(this,
DeferredTask: "resource://gre/modules/DeferredTask.jsm",
Services: "resource://gre/modules/Services.jsm",
ServiceRequest: "resource://gre/modules/ServiceRequest.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm",
OS: "resource://gre/modules/osfile.jsm",
Preferences: "resource://gre/modules/Preferences.jsm",
});
+// The current platform as specified in the AMO API:
+// http://addons-server.readthedocs.io/en/latest/topics/api/addons.html#addon-detail-platform
+XPCOMUtils.defineLazyGetter(this, "PLATFORM", () => {
+ let platform = Services.appinfo.OS;
+ switch (platform) {
+ case "Darwin":
+ return "mac";
+
+ case "Linux":
+ return "linux";
+
+ case "Android":
+ return "android";
+
+ case "WINNT":
+ return "windows";
+ }
+ return platform;
+});
+
var EXPORTED_SYMBOLS = [ "AddonRepository" ];
const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
const PREF_GETADDONS_CACHE_TYPES = "extensions.getAddons.cache.types";
const PREF_GETADDONS_CACHE_ID_ENABLED = "extensions.%ID%.getAddons.cache.enabled";
const PREF_GETADDONS_BROWSEADDONS = "extensions.getAddons.browseAddons";
const PREF_GETADDONS_BYIDS = "extensions.getAddons.get.url";
const PREF_COMPAT_OVERRIDES = "extensions.getAddons.compatOverides.url";
@@ -577,17 +597,17 @@ var AddonRepository = {
_parseAddon(aEntry) {
let addon = new AddonSearchResult(aEntry.guid);
addon.name = aEntry.name;
if (typeof aEntry.current_version == "object") {
addon.version = String(aEntry.current_version.version);
if (Array.isArray(aEntry.current_version.files)) {
for (let file of aEntry.current_version.files) {
- if (file.platform == "all" || file.platform == Services.appinfo.OS.toLowerCase()) {
+ if (file.platform == "all" || file.platform == PLATFORM) {
if (file.url) {
addon.sourceURI = NetUtil.newURI(file.url);
}
break;
}
}
}
}
--- a/toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
+++ b/toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
@@ -55,16 +55,31 @@
},
"ratings_url": "http://example.com/review1.html",
"support_url": "http://example.com/support1.html",
"contributions_url": "http://example.com/contribution1.html",
"weekly_downloads": 3333,
"last_updated": "2010-02-01T14:04:05Z"
},
{
+ "name": "PASS",
+ "type": "extension",
+ "guid": "test2@tests.mozilla.org",
+ "current_version": {
+ "version": "2.0",
+ "files": [
+ {
+ "platform": "XPCShell",
+ "url": "http://example.com/addons/bleah.xpi",
+ "size": 1000
+ }
+ ]
+ }
+ },
+ {
"name": "FAIL",
"type": "extension",
"guid": "notRequested@tests.mozilla.org",
"current_version": {
"version": "1.3",
"files": [
{
"platform": "all",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
@@ -119,32 +119,40 @@ var GET_RESULTS = [{
contributionURL: BASE_URL + "/contribution1.html",
averageRating: 4,
reviewCount: 1111,
reviewURL: BASE_URL + "/review1.html",
weeklyDownloads: 3333,
sourceURI: BASE_URL + INSTALL_URL2,
updateDate: new Date(1265033045000),
}, {
+ id: "test2@tests.mozilla.org",
+ type: "extension",
+ version: "2.0",
+ icons: {},
+ sourceURI: "http://example.com/addons/bleah.xpi",
+}, {
id: "test_AddonRepository_1@tests.mozilla.org",
type: "theme",
version: "1.4",
icons: {}
}];
// Values for testing AddonRepository.getAddonsByIDs()
var GET_TEST = {
preference: PREF_GETADDONS_BYIDS,
preferenceValue: BASE_URL + "/%OS%/%VERSION%/%IDS%",
failedIDs: ["test1@tests.mozilla.org"],
failedURL: "/XPCShell/1/test1%40tests.mozilla.org",
successfulIDs: ["test1@tests.mozilla.org",
- "{00000000-1111-2222-3333-444444444444}",
- "test_AddonRepository_1@tests.mozilla.org"],
+ "test2@tests.mozilla.org",
+ "{00000000-1111-2222-3333-444444444444}",
+ "test_AddonRepository_1@tests.mozilla.org"],
successfulURL: "/XPCShell/1/test1%40tests.mozilla.org%2C" +
+ "test2%40tests.mozilla.org%2C" +
"%7B00000000-1111-2222-3333-444444444444%7D%2C" +
"test_AddonRepository_1%40tests.mozilla.org"
};
// Test that actual results and expected results are equal
function check_results(aActualAddons, aExpectedAddons) {
do_check_addons(aActualAddons, aExpectedAddons, ADDON_PROPERTIES);