Bug 1476177 Fix platform matching in AMO metadata requests r=mixedpuppy
authorAndrew Swan <aswan@mozilla.com>
Wed, 01 Aug 2018 09:14:22 -0700
changeset 429860 f6ec69871ae1f0c5899f97241fa960cfee9c5c8d
parent 429859 491a946ba31fa55611e711c0e387e22d53b59f15
child 429861 665be823701439cab8a9960f38544edadd6fa218
push id67290
push useraswan@mozilla.com
push dateThu, 02 Aug 2018 22:29:55 +0000
treeherderautoland@f6ec69871ae1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1476177
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1476177 Fix platform matching in AMO metadata requests r=mixedpuppy MozReview-Commit-ID: EvjeXdCyLxi
toolkit/mozapps/extensions/internal/AddonRepository.jsm
toolkit/mozapps/extensions/test/xpcshell/data/test_AddonRepository_getAddonsByIDs.json
toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository.js
--- 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);