Skip to content

Commit f98ce05

Browse files
committed
Bug 1865840 - AbuseReport button should be shown for dictionaries when the AMO port is enabled. r=willdurand
Differential Revision: https://phabricator.services.mozilla.com/D194382
1 parent fbad32a commit f98ce05

File tree

4 files changed

+73
-18
lines changed

4 files changed

+73
-18
lines changed

toolkit/mozapps/extensions/AbuseReporter.sys.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const SUPPORTED_ADDON_TYPES = [
2727
"sitepermission-deprecated",
2828
];
2929

30+
// An expanded set of addon types supported when the abuse report hosted on AMO is enabled
31+
// (based on the "extensions.abuseReport.amoFormEnabled" pref).
32+
const AMO_SUPPORTED_ADDON_TYPES = [...SUPPORTED_ADDON_TYPES, "dictionary"];
33+
3034
const lazy = {};
3135

3236
ChromeUtils.defineESModuleGetters(lazy, {
@@ -47,6 +51,16 @@ XPCOMUtils.defineLazyPreferenceGetter(
4751
PREF_AMO_DETAILS_API_URL
4852
);
4953

54+
// Whether the abuse report feature should open a form hosted by the url
55+
// derived from the one set on the extensions.abuseReport.amoFormURL pref
56+
// or use the abuse report panel integrated in Firefox.
57+
XPCOMUtils.defineLazyPreferenceGetter(
58+
lazy,
59+
"ABUSE_REPORT_AMO_FORM_ENABLED",
60+
"extensions.abuseReport.amoFormEnabled",
61+
true
62+
);
63+
5064
const PRIVATE_REPORT_PROPS = Symbol("privateReportProps");
5165

5266
const ERROR_TYPES = Object.freeze([
@@ -99,6 +113,10 @@ async function responseToErrorInfo(response) {
99113
export const AbuseReporter = {
100114
_lastReportTimestamp: null,
101115

116+
get amoFormEnabled() {
117+
return lazy.ABUSE_REPORT_AMO_FORM_ENABLED;
118+
},
119+
102120
// Error types.
103121
updateLastReportTimestamp() {
104122
this._lastReportTimestamp = Date.now();
@@ -119,6 +137,9 @@ export const AbuseReporter = {
119137
},
120138

121139
isSupportedAddonType(addonType) {
140+
if (this.amoFormEnabled) {
141+
return AMO_SUPPORTED_ADDON_TYPES.includes(addonType);
142+
}
122143
return SUPPORTED_ADDON_TYPES.includes(addonType);
123144
},
124145

toolkit/mozapps/extensions/content/abuse-reports.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ const { AbuseReporter } = ChromeUtils.importESModule(
1616
"resource://gre/modules/AbuseReporter.sys.mjs"
1717
);
1818

19-
// Whether the abuse report feature should open a form hosted on
20-
// addons.mozilla.org or use the abuse report panel integrated
21-
// in Firefox.
22-
XPCOMUtils.defineLazyPreferenceGetter(
23-
this,
24-
"ABUSE_REPORT_AMO_FORM_ENABLED",
25-
"extensions.abuseReport.amoFormEnabled",
26-
true
27-
);
28-
2919
// Message Bars definitions.
3020
const ABUSE_REPORT_MESSAGE_BARS = {
3121
// Idle message-bar (used while the submission is still ongoing).
@@ -206,7 +196,7 @@ async function openAbuseReportAMOForm({ addonId, reportEntryPoint }) {
206196
});
207197
}
208198

209-
window.openAbuseReport = ABUSE_REPORT_AMO_FORM_ENABLED
199+
window.openAbuseReport = AbuseReporter.amoFormEnabled
210200
? openAbuseReportAMOForm
211201
: openAbuseReport;
212202

toolkit/mozapps/extensions/test/browser/browser_amo_abuse_report.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
loadTestSubscript("head_abuse_report.js");
77

8-
add_task(async function test_opens_amo_form_in_a_tab() {
8+
add_setup(async () => {
99
await SpecialPowers.pushPrefEnv({
1010
set: [
1111
["extensions.abuseReport.amoFormEnabled", true],
@@ -16,14 +16,24 @@ add_task(async function test_opens_amo_form_in_a_tab() {
1616
],
1717
});
1818

19-
await openAboutAddons();
19+
const { AbuseReporter } = ChromeUtils.importESModule(
20+
"resource://gre/modules/AbuseReporter.sys.mjs"
21+
);
2022

2123
Assert.equal(
22-
gManagerWindow.ABUSE_REPORT_AMO_FORM_ENABLED,
24+
AbuseReporter.amoFormEnabled,
2325
true,
24-
"Expect AMO abuse report form to be enabled by default"
26+
"Expect AMO abuse report form to be enabled"
2527
);
2628

29+
// Setting up MockProvider to mock various addon types
30+
// as installed.
31+
await AbuseReportTestUtils.setup();
32+
});
33+
34+
add_task(async function test_opens_amo_form_in_a_tab() {
35+
await openAboutAddons();
36+
2737
const ADDON_ID = "test-ext@mochitest";
2838
const expectedUrl = Services.urlFormatter
2939
.formatURLPref("extensions.abuseReport.amoFormURL")
@@ -48,3 +58,21 @@ add_task(async function test_opens_amo_form_in_a_tab() {
4858
await closeAboutAddons();
4959
await SpecialPowers.popPrefEnv();
5060
});
61+
62+
add_task(async function test_report_button_shown_on_dictionary_addons() {
63+
await openAboutAddons("dictionary");
64+
await AbuseReportTestUtils.assertReportActionShown(
65+
gManagerWindow,
66+
EXT_DICTIONARY_ADDON_ID
67+
);
68+
await closeAboutAddons();
69+
});
70+
71+
add_task(async function test_report_action_hidden_on_langpack_addons() {
72+
await openAboutAddons("locale");
73+
await AbuseReportTestUtils.assertReportActionHidden(
74+
gManagerWindow,
75+
EXT_LANGPACK_ADDON_ID
76+
);
77+
await closeAboutAddons();
78+
});

toolkit/mozapps/extensions/test/browser/head_abuse_report.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,33 @@ const AbuseReportTestUtils = {
390390
}
391391
},
392392

393-
// Assert that the report action is hidden on the addon card
393+
// Assert that the report action visibility on the addon card
394394
// for the given about:addons windows and extension id.
395-
async assertReportActionHidden(gManagerWindow, extId) {
395+
async assertReportActionVisibility(gManagerWindow, extId, expectShown) {
396396
let addonCard = gManagerWindow.document.querySelector(
397397
`addon-list addon-card[addon-id="${extId}"]`
398398
);
399399
ok(addonCard, `Got the addon-card for the ${extId} test extension`);
400400

401401
let reportButton = addonCard.querySelector("[action=report]");
402402
ok(reportButton, `Got the report action for ${extId}`);
403-
ok(reportButton.hidden, `${extId} report action should be hidden`);
403+
Assert.equal(
404+
reportButton.hidden,
405+
!expectShown,
406+
`${extId} report action should be ${expectShown ? "shown" : "hidden"}`
407+
);
408+
},
409+
410+
// Assert that the report action is hidden on the addon card
411+
// for the given about:addons windows and extension id.
412+
assertReportActionHidden(gManagerWindow, extId) {
413+
return this.assertReportActionVisibility(gManagerWindow, extId, false);
414+
},
415+
416+
// Assert that the report action is shown on the addon card
417+
// for the given about:addons windows and extension id.
418+
assertReportActionShown(gManagerWindow, extId) {
419+
return this.assertReportActionVisibility(gManagerWindow, extId, true);
404420
},
405421

406422
// Assert that the report panel is hidden (or closed if the report

0 commit comments

Comments
 (0)