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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-07-10 19:12:19 +00:00
parent 217df84885
commit b56ff15392
2 changed files with 47 additions and 7 deletions

View File

@ -42,6 +42,7 @@ const ABUSE_REASONS = (window.ABUSE_REPORT_REASONS = {
hasSuggestions: true,
isExampleHidden: hideOnThemeType,
isReasonHidden: showOnAnyType,
requiresSupportURL: true,
},
policy: {
hasSuggestions: true,
@ -68,17 +69,24 @@ function getReasonL10nId(reason, 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);
}
@ -308,13 +316,14 @@ class AbuseReasonSuggestions extends HTMLElement {
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);

View File

@ -1285,6 +1285,37 @@ add_task(async function test_trigger_abusereport_from_aboutaddons_remove() {
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({