Bug 1596137 - mozAddonManager.reportAbuse should reject on unsupported addon types. r=mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Thu, 14 Nov 2019 16:42:30 +0000
changeset 502013 7405a856572c00f82145b8e5bf397998f6349ac1
parent 502012 dd473ab6821ecc27e748a756dca9ea8ebceaf0c5
child 502014 fb4b9875d44d472f27ea1df1066e1f359b28a053
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
bugs1596137
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 1596137 - mozAddonManager.reportAbuse should reject on unsupported addon types. r=mixedpuppy mozAddonManager.reportAbuse should reject explicitly when called for an unsupported addon type, to make AMO able to detect when if triggering the integrated report failed instead of being cancelled by the user, and fallback on the report form integrated on the AMO website. Differential Revision: https://phabricator.services.mozilla.com/D52882
toolkit/mozapps/extensions/AbuseReporter.jsm
toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js
toolkit/mozapps/extensions/test/browser/head_abuse_report.js
--- a/toolkit/mozapps/extensions/AbuseReporter.jsm
+++ b/toolkit/mozapps/extensions/AbuseReporter.jsm
@@ -18,16 +18,19 @@ const PREF_AMO_DETAILS_API_URL = "extens
 const DIALOG_WINDOW_NAME = "addons-abuse-report-dialog";
 
 // Maximum length of the string properties sent to the API endpoint.
 const MAX_STRING_LENGTH = 255;
 
 // Minimum time between report submissions (in ms).
 const MIN_MS_BETWEEN_SUBMITS = 30000;
 
+// The addon types currently supported by the integrated abuse report panel.
+const SUPPORTED_ADDON_TYPES = ["extension", "theme"];
+
 XPCOMUtils.defineLazyModuleGetters(this, {
   AddonManager: "resource://gre/modules/AddonManager.jsm",
   AMTelemetry: "resource://gre/modules/AddonManager.jsm",
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   ClientID: "resource://gre/modules/ClientID.jsm",
   Services: "resource://gre/modules/Services.jsm",
 });
 
@@ -417,16 +420,25 @@ const AbuseReporter = {
       } = dialogWin.arguments[0].wrappedJSObject;
       deferredReport.resolve({ userCancelled: true });
       await promiseReport;
     }
 
     const report = await AbuseReporter.createAbuseReport(addonId, {
       reportEntryPoint,
     });
+
+    if (!SUPPORTED_ADDON_TYPES.includes(report.addon.type)) {
+      throw new Error(
+        `Addon type "${
+          report.addon.type
+        }" is not currently supported by the integrated abuse reporting feature`
+      );
+    }
+
     const params = Cc["@mozilla.org/array;1"].createInstance(
       Ci.nsIMutableArray
     );
 
     const dialogInit = {
       report,
       openWebLink(url) {
         chromeWin.openWebLinkIn(url, "tab", {
--- a/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js
@@ -285,16 +285,48 @@ add_task(async function test_amo_report_
 
   let promiseWinClosed = waitClosedWindow();
   AbuseReportTestUtils.clickPanelButton(panelEl._btnCancel);
   await promiseWinClosed;
 
   await extension.unload();
 });
 
+add_task(async function test_reject_on_unsupported_addon_types() {
+  const addonId = "not-supported-addon-type@mochi.test";
+
+  await BrowserTestUtils.withNewTab(TESTPAGE, async browser => {
+    const fakeAMODetails = {
+      name: "fake name",
+      current_version: { version: "1.0" },
+      type: "fake-unsupported-addon-type",
+    };
+
+    AbuseReportTestUtils.amoAddonDetailsMap.set(addonId, fakeAMODetails);
+    registerCleanupFunction(() =>
+      AbuseReportTestUtils.amoAddonDetailsMap.clear()
+    );
+
+    let webAPIResult = await SpecialPowers.spawn(browser, [addonId], id =>
+      content.navigator.mozAddonManager
+        .reportAbuse(id)
+        .then(
+          res => ({ gotRejection: false, result: res }),
+          err => ({ gotRejection: true, message: err.message })
+        )
+    );
+
+    Assert.deepEqual(
+      webAPIResult,
+      { gotRejection: true, message: "Error creating abuse report" },
+      "Got the expected rejection from mozAddonManager.reportAbuse"
+    );
+  });
+});
+
 add_task(async function test_report_on_disabled_webapi() {
   await SpecialPowers.pushPrefEnv({
     set: [["extensions.abuseReport.amWebAPI.enabled", false]],
   });
 
   await BrowserTestUtils.withNewTab(TESTPAGE, async browser => {
     let reportEnabled = await SpecialPowers.spawn(browser, [], () => {
       return content.navigator.mozAddonManager.abuseReportPanelEnabled;
--- a/toolkit/mozapps/extensions/test/browser/head_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/head_abuse_report.js
@@ -1461,45 +1461,43 @@ async function test_report_action_hidden
 }
 
 // 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.
 async function test_report_hidden_on_report_unsupported_addontype() {
   await openAboutAddons();
 
+  // The error message bar is only being shown in the new implementation
+  // which opens the report in a dialog window, on the contrary when the
+  // report is shown in a about:addons subframe the report is cancelled
+  // but no error messagebar is going to be shown.
+  let onceCreateReportFailed;
+  let reportFrameEl;
   if (AbuseReporter.openDialogDisabled) {
-    const el = AbuseReportTestUtils.getReportFrame();
-
-    const onceCancelled = BrowserTestUtils.waitForEvent(
-      el,
+    reportFrameEl = AbuseReportTestUtils.getReportFrame();
+    onceCreateReportFailed = BrowserTestUtils.waitForEvent(
+      reportFrameEl,
       "abuse-report:cancel"
     );
-    AbuseReportTestUtils.triggerNewReport(
-      EXT_UNSUPPORTED_TYPE_ADDON_ID,
-      "menu"
-    );
-
-    await onceCancelled;
-
-    is(el.hidden, true, `report frame hidden on cancelled report`);
   } else {
-    const promiseNewWin = waitForNewWindow();
-    AbuseReportTestUtils.triggerNewReport(
-      EXT_UNSUPPORTED_TYPE_ADDON_ID,
-      "menu"
-    );
-    const win = await promiseNewWin;
-    const report = await AbuseReportTestUtils.getReportDialogParams()
-      .promiseReport;
+    onceCreateReportFailed = AbuseReportTestUtils.promiseMessageBars(1);
+  }
+
+  AbuseReportTestUtils.triggerNewReport(EXT_UNSUPPORTED_TYPE_ADDON_ID, "menu");
+
+  await onceCreateReportFailed;
 
-    ok(!report, "Abuse Report dialog cancelled as expected");
-    await BrowserTestUtils.waitForCondition(
-      () => win.closed,
-      "Wait the report dialog to be closed"
+  if (AbuseReporter.openDialogDisabled) {
+    is(reportFrameEl.hidden, true, "report frame should not be visible");
+  } else {
+    is(
+      AbuseReporter.getOpenDialog(),
+      undefined,
+      "report dialog should not be open"
     );
   }
 
   await closeAboutAddons();
 }
 
 async function test_no_report_checkbox_for_unsupported_addon_types() {
   async function test_report_checkbox_hidden(addon) {