Bug 1596133 - AbuseReporter.queryAMOAddonDetails should normalize type 'statictheme' into type 'theme'. r=mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Wed, 13 Nov 2019 18:02:22 +0000
changeset 501770 c3630e8d58372c77b6302ea7571082ce124c31b4
parent 501769 e27a64154a8c64af5238590efd6fb7a536f3fe32
child 501771 f51eb6400003531a012b932a4b19ab5e7d32e85e
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1596133
milestone72.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 1596133 - AbuseReporter.queryAMOAddonDetails should normalize type 'statictheme' into type 'theme'. r=mixedpuppy The addon details returned from the AMO API endpoint for webextensions static themes is type "statictheme", but for an installed WebExtension static theme we expect addon.type to be "theme", and so AbuseReporter.queryAMOAddonDetails should normalize the type received to ensure it matches what Firefox expects. This fix is needed to ensure that reporting a "not installed" theme from AMO works as expected (see https://github.com/mozilla/addons-frontend/issues/8762#issuecomment-553430081). Differential Revision: https://phabricator.services.mozilla.com/D52853
toolkit/mozapps/extensions/AbuseReporter.jsm
toolkit/mozapps/extensions/test/xpcshell/test_AbuseReporter.js
--- a/toolkit/mozapps/extensions/AbuseReporter.jsm
+++ b/toolkit/mozapps/extensions/AbuseReporter.jsm
@@ -248,22 +248,27 @@ const AbuseReporter = {
         return value;
       }
       return value && (value[locale] || value["en-US"]);
     };
 
     const getAuthorField = fieldName =>
       details.authors && details.authors[0] && details.authors[0][fieldName];
 
+    // Normalize type "statictheme" (which is the type used on the AMO API side)
+    // into "theme" (because it is the type we use and expect on the Firefox side
+    // for this addon type).
+    const addonType = details.type === "statictheme" ? "theme" : details.type;
+
     return {
       id: addonId,
       name: getTranslatedValue(details.name),
       version: details.current_version.version,
       description: getTranslatedValue(details.summary),
-      type: details.type,
+      type: addonType,
       iconURL: details.icon_url,
       homepageURL: getTranslatedValue(details.homepage),
       supportURL: getTranslatedValue(details.support_url),
       // Set the addon creator to the first author in the AMO details.
       creator: {
         name: getAuthorField("name"),
         url: getAuthorField("url"),
       },
--- a/toolkit/mozapps/extensions/test/xpcshell/test_AbuseReporter.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_AbuseReporter.js
@@ -858,8 +858,23 @@ add_task(async function test_query_amo_d
     addon_name: FAKE_AMO_DETAILS.name["en-US"],
   };
   await assertReportOnAMODetails({ addonId, expectedReport });
 
   Services.prefs.clearUserPref(PREF_REQUIRED_LOCALE);
 
   amoAddonDetailsMap.clear();
 });
+
+add_task(async function test_statictheme_normalized_into_type_theme() {
+  const themeId = "not-installed-statictheme@mochi.test";
+  amoAddonDetailsMap.set(themeId, {
+    ...FAKE_AMO_DETAILS,
+    type: "statictheme",
+  });
+
+  const report = await AbuseReporter.createAbuseReport(themeId, REPORT_OPTIONS);
+
+  equal(report.addon.id, themeId, "Got a report for the expected theme id");
+  equal(report.addon.type, "theme", "Got the expected addon type");
+
+  amoAddonDetailsMap.clear();
+});