Bug 1549991 - No remove action on report submitted for add-ons without PERM_CAN_UNINSTALL. r=flod,mstriemer
authorLuca Greco <lgreco@mozilla.com>
Thu, 09 May 2019 06:41:13 +0000
changeset 473191 c24c083425d0e543bd59076d675c2efcb3b7c73c
parent 473190 7c9375503ddff95012915a5817ffe049c7302148
child 473192 3a8c6048c5d0874dd3d32c06e7923625b9383e8d
push id35990
push usernerli@mozilla.com
push dateThu, 09 May 2019 15:34:57 +0000
treeherdermozilla-central@34b343ca6c2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, mstriemer
bugs1549991
milestone68.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 1549991 - No remove action on report submitted for add-ons without PERM_CAN_UNINSTALL. r=flod,mstriemer Differential Revision: https://phabricator.services.mozilla.com/D30366
toolkit/locales/en-US/toolkit/about/abuseReports.ftl
toolkit/mozapps/extensions/content/abuse-reports.js
toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
--- a/toolkit/locales/en-US/toolkit/about/abuseReports.ftl
+++ b/toolkit/locales/en-US/toolkit/about/abuseReports.ftl
@@ -30,16 +30,17 @@ abuse-report-submit-button = Submit
 
 ## Message bars descriptions.
 
 ## Variables:
 ##   $addon-name (string) - Name of the add-on
 abuse-report-messagebar-aborted = Report for <span data-l10n-name="addon-name">{ $addon-name }</span> canceled.
 abuse-report-messagebar-submitting = Sending report for <span data-l10n-name="addon-name">{ $addon-name }</span>.
 abuse-report-messagebar-submitted = Thank you for submitting a report. Do you want to remove <span data-l10n-name="addon-name">{ $addon-name }</span>?
+abuse-report-messagebar-submitted-noremove = Thank you for submitting a report.
 abuse-report-messagebar-removed-extension = Thank you for submitting a report. You’ve removed the extension <span data-l10n-name="addon-name">{ $addon-name }</span>.
 abuse-report-messagebar-removed-theme = Thank you for submitting a report. You’ve removed the theme <span data-l10n-name="addon-name">{ $addon-name }</span>.
 abuse-report-messagebar-error = There was an error sending the report for <span data-l10n-name="addon-name">{ $addon-name }</span>.
 abuse-report-messagebar-error-recent-submit = The report for <span data-l10n-name="addon-name">{ $addon-name }</span> wasn’t sent because another report was submitted recently.
 
 ## Message bars actions.
 
 abuse-report-messagebar-action-remove-extension = Yes, Remove It
--- a/toolkit/mozapps/extensions/content/abuse-reports.js
+++ b/toolkit/mozapps/extensions/content/abuse-reports.js
@@ -15,16 +15,20 @@
 const ABUSE_REPORT_MESSAGE_BARS = {
   // Idle message-bar (used while the submission is still ongoing).
   "submitting": {id: "submitting", actions: ["cancel"]},
   // Submitted report message-bar.
   "submitted": {
     id: "submitted", actionAddonTypeSuffix: true,
     actions: ["remove", "keep"], dismissable: true,
   },
+  // Submitted report message-bar (with no remove actions).
+  "submitted-no-remove-action": {
+    id: "submitted-noremove", dismissable: true,
+  },
   // Submitted report and remove addon message-bar.
   "submitted-and-removed": {
     id: "removed", addonTypeSuffix: true, dismissable: true,
   },
   // The "aborted report" message bar is rendered as a generic informative one,
   // because aborting a report is triggered by a user choice.
   "ERROR_ABORTED_SUBMIT": {
     id: "aborted", type: "generic", dismissable: true,
@@ -107,43 +111,51 @@ function createReportMessageBar(
 
   document.dispatchEvent(new CustomEvent("abuse-report:new-message-bar", {
     detail: {definitionId, messagebar},
   }));
   return messagebar;
 }
 
 async function submitReport({report, reason, message}) {
-  const addonId = report.addon.id;
-  const addonName = report.addon && report.addon.name;
-  const addonType = report.addon && report.addon.type;
+  const {addon} = report;
+  const addonId = addon.id;
+  const addonName = addon.name;
+  const addonType = addon.type;
 
   // Create a message bar while we are still submitting the report.
   const mbSubmitting = createReportMessageBar(
     "submitting", {addonId, addonName, addonType}, {
       onaction: (action) => {
         if (action === "cancel") {
           report.abort();
           mbSubmitting.remove();
         }
       },
     });
 
   try {
     await report.submit({reason, message});
     mbSubmitting.remove();
 
-    // Create a submitted message bar is the submission has been
+    // Create a submitted message bar when the submission has been
     // successful.
-    // With reportEntryPoint "uninstall" a specific message bar
-    // is going to be used. All the other reportEntryPoint
-    // values ("menu" and "toolbar_context_menu") uses the same
-    // "submitted" message bar.
-    const barId = report.reportEntryPoint === "uninstall" ?
-      "submitted-and-removed" : "submitted";
+    let barId;
+    if (!(addon.permissions & AddonManager.PERM_CAN_UNINSTALL)) {
+      // Do not offer remove action if the addon can't be uninstalled.
+      barId = "submitted-no-remove-action";
+    } else if (report.reportEntryPoint === "uninstall") {
+      // With reportEntryPoint "uninstall" a specific message bar
+      // is going to be used.
+      barId = "submitted-and-removed";
+    } else {
+      // All the other reportEntryPoint ("menu" and "toolbar_context_menu")
+      // use the same kind of message bar.
+      barId = "submitted";
+    }
 
     const mbInfo = createReportMessageBar(barId, {
       addonId, addonName, addonType,
     }, {
       onaction: (action) => {
         mbInfo.remove();
         // action "keep" doesn't require any further action,
         // just handle "remove".
--- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
@@ -21,17 +21,19 @@ const BASE_TEST_MANIFEST = {
   name: "Fake extension to report",
   author: "Fake author",
   homepage_url: "https://fake.extension.url/",
   applications: {gecko: {id: ADDON_ID}},
   icons: {
     32: "test-icon.png",
   },
 };
+const THEME_NO_UNINSTALL_ID = "theme-without-perm-can-uninstall@mochi.test";
 
+let gProvider;
 let gHtmlAboutAddonsWindow;
 let gManagerWindow;
 let apiRequestHandler;
 
 AddonTestUtils.initMochitest(this);
 
 // Init test report api server.
 const server = AddonTestUtils.createHttpServer({hosts: ["test.addons.org"]});
@@ -209,16 +211,26 @@ add_task(async function setup() {
   // Enable html about:addons and the abuse reporting.
   await SpecialPowers.pushPrefEnv({
     set: [
       ["extensions.htmlaboutaddons.enabled", true],
       ["extensions.abuseReport.enabled", true],
       ["extensions.abuseReport.url", "http://test.addons.org/api/report/"],
     ],
   });
+
+  gProvider = new MockProvider();
+  gProvider.createAddons([{
+    id: THEME_NO_UNINSTALL_ID,
+    name: "This theme cannot be uninstalled",
+    version: "1.1",
+    creator: {name: "Theme creator", url: "http://example.com/creator"},
+    type: "theme",
+    permissions: 0,
+  }]);
 });
 
 // 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
 // - the addon-abuse-report-xulframe contains a transparent browser XUL element
@@ -803,16 +815,27 @@ add_task(async function test_abuse_repor
   await assertMessageBars(["submitting", "ERROR_UNKNOWN"], async () => {
     info("Test message bars on invalid json in the response data");
     setTestRequestHandler(200, "");
     triggerNewAbuseReport(EXT_ID, REPORT_ENTRY_POINT);
     await promiseAbuseReportRendered();
     triggerSubmitAbuseReport("fake-reason", "fake-message");
   });
 
+  // Verify message bar on add-on without perm_can_uninstall.
+  await assertMessageBars([
+    "submitting", "submitted-no-remove-action",
+  ], async () => {
+    info("Test message bars on report submitted on an addon without remove");
+    setTestRequestHandler(200, "{}");
+    triggerNewAbuseReport(THEME_NO_UNINSTALL_ID, "menu");
+    await promiseAbuseReportRendered();
+    triggerSubmitAbuseReport("fake-reason", "fake-message");
+  });
+
   // Verify the 3 expected entry points:
   //   menu, toolbar_context_menu and uninstall
   // (See https://addons-server.readthedocs.io/en/latest/topics/api/abuse.html).
   await assertMessageBars(["submitting", "submitted"], async () => {
     info("Test message bars on report opened from addon options menu");
     setTestRequestHandler(200, "{}");
     triggerNewAbuseReport(EXT_ID, "menu");
     await promiseAbuseReportRendered();