Bug 1556389 - Show report action only on currently supported addon types. r=mstriemer a=jcristau
authorLuca Greco <lgreco@mozilla.com>
Mon, 10 Jun 2019 18:38:57 +0000
changeset 533853 f2fce0eb3d26339f6f40aae062b66202765c2d68
parent 533852 fa39f1f84dbd753fb836bd12063f744912ef5351
child 533854 c6f045553e3ed87b7aa1e83aeef576da9f52f361
push id11441
push useropoprus@mozilla.com
push dateThu, 13 Jun 2019 13:39:01 +0000
treeherdermozilla-beta@7222059b6940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, jcristau
bugs1556389
milestone68.0
Bug 1556389 - Show report action only on currently supported addon types. r=mstriemer a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D34341
toolkit/mozapps/extensions/content/aboutaddons.js
toolkit/mozapps/extensions/content/abuse-report-frame.js
toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
--- a/toolkit/mozapps/extensions/content/aboutaddons.js
+++ b/toolkit/mozapps/extensions/content/aboutaddons.js
@@ -127,16 +127,22 @@ const AddonCardListenerHandler = {
 
   shutdown() {
     AddonManager.removeAddonListener(this);
     AddonManager.removeInstallListener(this);
     AddonManager.removeManagerListener(this);
   },
 };
 
+function isAbuseReportSupported(addon) {
+  return ABUSE_REPORT_ENABLED &&
+    ["extension", "theme"].includes(addon.type) &&
+    !(addon.isBuiltin || addon.isSystem);
+}
+
 async function isAllowedInPrivateBrowsing(addon) {
   // Use the Promise directly so this function stays sync for the other case.
   let perms = await ExtensionPermissions.get(addon.id);
   return perms.permissions.includes(PRIVATE_BROWSING_PERM_NAME);
 }
 
 function hasPermission(addon, permission) {
   return !!(addon.permissions & PERMISSION_MASKS[permission]);
@@ -628,17 +634,17 @@ class AddonOptions extends HTMLElement {
   }
 
   setElementState(el, card, addon, updateInstall) {
     switch (el.getAttribute("action")) {
       case "remove":
         el.hidden = !hasPermission(addon, "uninstall");
         break;
       case "report":
-        el.hidden = !ABUSE_REPORT_ENABLED || addon.isBuiltin || addon.isSystem;
+        el.hidden = !isAbuseReportSupported(addon);
         break;
       case "toggle-disabled": {
         let toggleDisabledAction = addon.userDisabled ? "enable" : "disable";
         document.l10n.setAttributes(
           el, `${toggleDisabledAction}-addon-button`);
         el.hidden = !hasPermission(addon, toggleDisabledAction);
         break;
       }
--- a/toolkit/mozapps/extensions/content/abuse-report-frame.js
+++ b/toolkit/mozapps/extensions/content/abuse-report-frame.js
@@ -143,21 +143,21 @@
       if (report && report.addon && !report.errorType) {
         const {addon, reportEntryPoint} = this.report;
         this.addonId = addon.id;
         this.reportEntryPoint = reportEntryPoint;
 
         // Set the addon id on the addon-abuse-report webcomponent instance
         // embedded in the XUL browser.
         this.promiseAbuseReport.then(abuseReport => {
+          this.hidden = false;
           abuseReport.addEventListener("abuse-report:updated", this, {once: true});
           abuseReport.addEventListener("abuse-report:submit", this, {once: true});
           abuseReport.addEventListener("abuse-report:cancel", this, {once: true});
           abuseReport.setAbuseReport(report);
-          this.hidden = false;
           // Hide the content of the underlying about:addons page from
           // screen readers.
           this.aboutAddonsContent.setAttribute("aria-hidden", true);
           // Move the focus to the embedded window.
           fm.moveFocus(abuseReport.ownerGlobal, null, fm.MOVEFOCUS_ROOT, fm.FLAG_BYKEY);
           this.dispatchEvent(new CustomEvent("abuse-report:frame-shown"));
         });
       } else {
--- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
@@ -22,18 +22,21 @@ const BASE_TEST_MANIFEST = {
   author: "Fake author",
   homepage_url: "https://fake.extension.url/",
   applications: {gecko: {id: ADDON_ID}},
   icons: {
     32: "test-icon.png",
   },
 };
 const DEFAULT_BUILTIN_THEME_ID = "default-theme@mozilla.org";
+const EXT_DICTIONARY_ADDON_ID = "fake-dictionary@mochi.test";
+const EXT_LANGPACK_ADDON_ID = "fake-langpack@mochi.test";
 const EXT_WITH_PRIVILEGED_URL_ID = "ext-with-privileged-url@mochi.test";
 const EXT_SYSTEM_ADDON_ID = "test-system-addon@mochi.test";
+const EXT_UNSUPPORTED_TYPE_ADDON_ID = "report-unsupported-type@mochi.test";
 const THEME_NO_UNINSTALL_ID = "theme-without-perm-can-uninstall@mochi.test";
 
 let gProvider;
 let gHtmlAboutAddonsWindow;
 let gManagerWindow;
 let apiRequestHandler;
 
 AddonTestUtils.initMochitest(this);
@@ -249,16 +252,31 @@ add_task(async function setup() {
     type: "extension",
   }, {
     id: EXT_SYSTEM_ADDON_ID,
     name: "This is a system addon",
     version: "1.1",
     creator: {name: "creator", url: "http://example.com/creator"},
     type: "extension",
     isSystem: true,
+  }, {
+    id: EXT_UNSUPPORTED_TYPE_ADDON_ID,
+    name: "This is a fake unsupported addon type",
+    version: "1.1",
+    type: "unsupported_addon_type",
+  }, {
+    id: EXT_LANGPACK_ADDON_ID,
+    name: "This is a fake langpack",
+    version: "1.1",
+    type: "locale",
+  }, {
+    id: EXT_DICTIONARY_ADDON_ID,
+    name: "This is a fake dictionary",
+    version: "1.1",
+    type: "dictionary",
   }]);
 });
 
 // This test case verifies that:
 // - the about:addons XUL page contains the addon-abuse-report-xulframe element,
 //   and that
 //   it is part of a XUL stack alongside with the rest of a about:addons
 //   XUL page
@@ -1096,8 +1114,38 @@ add_task(async function test_report_acti
   await closeAboutAddons();
 });
 
 add_task(async function test_report_action_hidden_on_system_addons() {
   await openAboutAddons("extension");
   await assertReportActionHidden(gManagerWindow, EXT_SYSTEM_ADDON_ID);
   await closeAboutAddons();
 });
+
+add_task(async function test_report_action_hidden_on_dictionary_addons() {
+  await openAboutAddons("dictionary");
+  await assertReportActionHidden(gManagerWindow, EXT_DICTIONARY_ADDON_ID);
+  await closeAboutAddons();
+});
+
+add_task(async function test_report_action_hidden_on_langpack_addons() {
+  await openAboutAddons("locale");
+  await assertReportActionHidden(gManagerWindow, EXT_LANGPACK_ADDON_ID);
+  await closeAboutAddons();
+});
+
+// This test verifies that triggering a report that would be immediately
+// cancelled (e.g. because abuse reports for that extension type are not
+// supported) the abuse report frame is being hidden as expected.
+add_task(async function test_frame_hidden_on_report_unsupported_addontype() {
+  await openAboutAddons();
+  const el = getAbuseReportFrame();
+
+  const onceCancelled = BrowserTestUtils.waitForEvent(
+    el, "abuse-report:cancel");
+  triggerNewAbuseReport(EXT_UNSUPPORTED_TYPE_ADDON_ID, "menu");
+
+  await onceCancelled;
+
+  is(el.hidden, true, `report frame hidden on automatically cancelled report`);
+
+  await closeAboutAddons();
+});