Bug 1556757 - Abuse Report panel should not show the 'broken reason' suggestion when addon support url is missing. r=mstriemer
authorLuca Greco <lgreco@mozilla.com>
Wed, 10 Jul 2019 19:12:19 +0000
changeset 482429 fc6b4b3480aa2bed0e9a18bf2e0574832af3731d
parent 482428 d8ecb078c9a1f61d047856c89223ed34eb86a2ef
child 482430 2d080c3aa7021c77cfb06c8eafd9f17d72dc06f7
push id89768
push userluca.greco@alcacoop.it
push dateThu, 11 Jul 2019 17:38:17 +0000
treeherderautoland@2d080c3aa702 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer
bugs1556757
milestone70.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 1556757 - Abuse Report panel should not show the 'broken reason' suggestion when addon support url is missing. r=mstriemer Differential Revision: https://phabricator.services.mozilla.com/D35674
toolkit/mozapps/extensions/content/abuse-report-panel.js
toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
--- a/toolkit/mozapps/extensions/content/abuse-report-panel.js
+++ b/toolkit/mozapps/extensions/content/abuse-report-panel.js
@@ -37,16 +37,17 @@ const ABUSE_REASONS = (window.ABUSE_REPO
     isReasonHidden: showOnAnyType,
   },
   broken: {
     hasAddonTypeL10nId: true,
     hasAddonTypeSuggestionTemplate: true,
     hasSuggestions: true,
     isExampleHidden: hideOnThemeType,
     isReasonHidden: showOnAnyType,
+    requiresSupportURL: true,
   },
   policy: {
     hasSuggestions: true,
     isExampleHidden: hideOnAnyType,
     isReasonHidden: showOnAnyType,
   },
   unwanted: {
     isExampleHidden: showOnAnyType,
@@ -63,27 +64,34 @@ function getReasonL10nId(reason, addonTy
   // Special case reasons that have a addonType-specific
   // l10n id.
   if (ABUSE_REASONS[reason].hasAddonTypeL10nId) {
     l10nId += `-${addonType}`;
   }
   return l10nId;
 }
 
-function getSuggestionsTemplate(reason, addonType) {
+function getSuggestionsTemplate({ addonType, reason, supportURL }) {
   const reasonInfo = ABUSE_REASONS[reason];
-  if (!reasonInfo.hasSuggestions) {
+
+  if (
+    !addonType ||
+    !reasonInfo.hasSuggestions ||
+    (reasonInfo.requiresSupportURL && !supportURL)
+  ) {
     return null;
   }
+
   let templateId = `tmpl-suggestions-${reason}`;
   // Special case reasons that have a addonType-specific
   // suggestion template.
   if (reasonInfo.hasAddonTypeSuggestionTemplate) {
     templateId += `-${addonType}`;
   }
+
   return document.getElementById(templateId);
 }
 
 // Map of the learnmore links metadata, keyed by link element class.
 const LEARNMORE_LINKS = {
   ".abuse-report-learnmore": {
     path: "reporting-extensions-and-themes-abuse",
   },
@@ -303,23 +311,24 @@ class AbuseReasonSuggestions extends HTM
       extensionSupportURL: "extension-support-url",
       reason: "report-reason",
     });
   }
 
   update() {
     const { addonType, extensionSupportURL, reason } = this;
 
-    if (!addonType) {
-      return;
-    }
-
     this.textContent = "";
 
-    let template = getSuggestionsTemplate(reason, addonType);
+    let template = getSuggestionsTemplate({
+      addonType,
+      reason,
+      supportURL: extensionSupportURL,
+    });
+
     if (template) {
       let content = document.importNode(template.content, true);
 
       formatLearnMoreURLs(content);
 
       let extSupportLink = content.querySelector("a.extension-support-link");
       if (extSupportLink) {
         extSupportLink.href = extensionSupportURL;
--- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
@@ -1280,16 +1280,47 @@ add_task(async function test_trigger_abu
     extension.id,
     "Abuse Report panel rendered for the expected addonId"
   );
 
   await closeAboutAddons();
   await extension.unload();
 });
 
+add_task(async function test_no_broken_suggestion_on_missing_supportURL() {
+  const EXT_ID = "test-no-author@mochi.test";
+  const extension = await installTestExtension(EXT_ID, "extension", {
+    homepage_url: undefined,
+  });
+
+  const abuseReportEl = await openAbuseReport(EXT_ID);
+  await promiseAbuseReportRendered(abuseReportEl);
+
+  info("Select broken as the abuse reason");
+  abuseReportEl.querySelector("#abuse-reason-broken").checked = true;
+
+  info("Clicking the 'next' button");
+  let oncePanelUpdated = promiseAbuseReportUpdated(abuseReportEl, "submit");
+  EventUtils.synthesizeMouseAtCenter(
+    abuseReportEl._btnNext,
+    {},
+    abuseReportEl.ownerGlobal
+  );
+  await oncePanelUpdated;
+
+  const suggestionEl = abuseReportEl.querySelector(
+    "abuse-report-reason-suggestions"
+  );
+  is(suggestionEl.reason, "broken", "Got the expected suggestion element");
+  ok(suggestionEl.hidden, "suggestion element should be empty");
+
+  await closeAboutAddons();
+  await extension.unload();
+});
+
 add_task(async function test_trigger_abusereport_from_browserAction_remove() {
   const EXT_ID = "test-report-from-browseraction-remove@mochi.test";
   const xpiFile = AddonTestUtils.createTempWebExtensionFile({
     manifest: {
       ...BASE_TEST_MANIFEST,
       browser_action: {},
       applications: { gecko: { id: EXT_ID } },
     },