From 864cf8865cb1abd20e2f1e4be5055db471bd7659 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Tue, 7 Nov 2023 15:04:07 +0000 Subject: [PATCH] Bug 1859791 - Replace in-product abuse report flow with AMO web form. r=willdurand Differential Revision: https://phabricator.services.mozilla.com/D192004 --- modules/libpref/init/all.js | 3 ++ .../extensions/content/abuse-reports.js | 30 ++++++++++- .../extensions/test/browser/browser.toml | 2 + .../test/browser/browser_amo_abuse_report.js | 50 +++++++++++++++++++ .../test/browser/browser_html_abuse_report.js | 7 +++ .../browser_html_abuse_report_dialog.js | 7 +++ .../browser/browser_webapi_abuse_report.js | 5 ++ 7 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 toolkit/mozapps/extensions/test/browser/browser_amo_abuse_report.js diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 5aacef19a39c..57b16a28b91d 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1846,6 +1846,9 @@ pref("extensions.abuseReport.enabled", true); pref("extensions.abuseReport.amWebAPI.enabled", true); pref("extensions.abuseReport.url", "https://services.addons.mozilla.org/api/v4/abuse/report/addon/"); pref("extensions.abuseReport.amoDetailsURL", "https://services.addons.mozilla.org/api/v4/addons/addon/"); +// Whether Firefox integrated abuse reporting feature should be opening the new abuse report form hosted on AMO. +pref("extensions.abuseReport.amoFormEnabled", false); +pref("extensions.abuseReport.amoFormURL", "https://addons.mozilla.org/%LOCALE%/%APP%/feedback/addon/%addonID%/"); // Blocklist preferences pref("extensions.blocklist.enabled", true); diff --git a/toolkit/mozapps/extensions/content/abuse-reports.js b/toolkit/mozapps/extensions/content/abuse-reports.js index 8478203e0b11..54bda5933d23 100644 --- a/toolkit/mozapps/extensions/content/abuse-reports.js +++ b/toolkit/mozapps/extensions/content/abuse-reports.js @@ -5,6 +5,7 @@ /* eslint max-len: ["error", 80] */ /* import-globals-from aboutaddonsCommon.js */ /* exported openAbuseReport */ +/* global windowRoot */ /** * This script is part of the HTML about:addons page and it provides some @@ -15,6 +16,16 @@ const { AbuseReporter } = ChromeUtils.importESModule( "resource://gre/modules/AbuseReporter.sys.mjs" ); +// Whether the abuse report feature should open a form hosted on +// addons.mozilla.org or use the abuse report panel integrated +// in Firefox. +XPCOMUtils.defineLazyPreferenceGetter( + this, + "ABUSE_REPORT_AMO_FORM_ENABLED", + "extensions.abuseReport.amoFormEnabled", + true +); + // Message Bars definitions. const ABUSE_REPORT_MESSAGE_BARS = { // Idle message-bar (used while the submission is still ongoing). @@ -180,7 +191,24 @@ async function openAbuseReport({ addonId, reportEntryPoint }) { } } -window.openAbuseReport = openAbuseReport; +// Unlike the openAbuseReport function, technically this method wouldn't need +// to be async, but it is so that both the implementations will be providing +// the same type signatures (returning a promise) to the callers, independently +// from which abuse reporting feature is enabled. +async function openAbuseReportAMOForm({ addonId, reportEntryPoint }) { + const amoUrl = Services.urlFormatter + .formatURLPref("extensions.abuseReport.amoFormURL") + .replace(/%addonID%/g, addonId); + windowRoot.ownerGlobal.openTrustedLinkIn(amoUrl, "tab", { + // Make sure the newly open tab is going to be focused, independently + // from general user prefs. + forceForeground: true, + }); +} + +window.openAbuseReport = ABUSE_REPORT_AMO_FORM_ENABLED + ? openAbuseReportAMOForm + : openAbuseReport; // Helper function used to create abuse report message bars in the // HTML about:addons page. diff --git a/toolkit/mozapps/extensions/test/browser/browser.toml b/toolkit/mozapps/extensions/test/browser/browser.toml index 54f11270ac09..dad84c78f1fa 100644 --- a/toolkit/mozapps/extensions/test/browser/browser.toml +++ b/toolkit/mozapps/extensions/test/browser/browser.toml @@ -59,6 +59,8 @@ prefs = [ ["browser_addon_list_reordering.js"] fail-if = ["a11y_checks"] # Bug 1854646 clicked h1.header-name may not be focusable +["browser_amo_abuse_report.js"] + ["browser_bug572561.js"] ["browser_checkAddonCompatibility.js"] diff --git a/toolkit/mozapps/extensions/test/browser/browser_amo_abuse_report.js b/toolkit/mozapps/extensions/test/browser/browser_amo_abuse_report.js new file mode 100644 index 000000000000..b29a35c73397 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_amo_abuse_report.js @@ -0,0 +1,50 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* eslint max-len: ["error", 80] */ + +loadTestSubscript("head_abuse_report.js"); + +add_task(async function test_opens_amo_form_in_a_tab() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.abuseReport.amoFormEnabled", true], + [ + "extensions.abuseReport.amoFormURL", + "https://example.org/%LOCALE%/%APP%/feedback/addon/%addonID%/", + ], + ], + }); + + await openAboutAddons(); + + Assert.equal( + gManagerWindow.ABUSE_REPORT_AMO_FORM_ENABLED, + true, + "Expect AMO abuse report form to be enabled by default" + ); + + const ADDON_ID = "test-ext@mochitest"; + const expectedUrl = Services.urlFormatter + .formatURLPref("extensions.abuseReport.amoFormURL") + .replace("%addonID%", ADDON_ID); + + const promiseWaitForAMOFormTab = BrowserTestUtils.waitForNewTab( + gBrowser, + expectedUrl + ); + info("Call about:addons openAbuseReport helper function"); + gManagerWindow.openAbuseReport({ addonId: ADDON_ID }); + info(`Wait for the AMO form url ${expectedUrl} to be opened in a new tab`); + const tab = await promiseWaitForAMOFormTab; + Assert.equal( + tab.linkedBrowser.currentURI.spec, + expectedUrl, + "The newly opened tab has the expected url" + ); + Assert.equal(gBrowser.selectedTab, tab, "The newly opened tab is selected"); + + BrowserTestUtils.removeTab(tab); + await closeAboutAddons(); + await SpecialPowers.popPrefEnv(); +}); diff --git a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js index 22faa78e45f1..57e77f622c00 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js +++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js @@ -6,6 +6,13 @@ loadTestSubscript("head_abuse_report.js"); add_setup(async function () { + // Make sure the integrated abuse report panel is the one enabled + // while this test file runs (instead of the AMO hosted form). + // NOTE: behaviors expected when amoFormEnabled is true are tested + // in the separate browser_amo_abuse_report.js test file. + await SpecialPowers.pushPrefEnv({ + set: [["extensions.abuseReport.amoFormEnabled", false]], + }); await AbuseReportTestUtils.setup(); }); diff --git a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report_dialog.js b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report_dialog.js index 1d62bf265f3f..1efb28add32b 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report_dialog.js +++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report_dialog.js @@ -6,6 +6,13 @@ loadTestSubscript("head_abuse_report.js"); add_setup(async function () { + // Make sure the integrated abuse report panel is the one enabled + // while this test file runs (instead of the AMO hosted form). + // NOTE: behaviors expected when amoFormEnabled is true are tested + // in the separate browser_amo_abuse_report.js test file. + await SpecialPowers.pushPrefEnv({ + set: [["extensions.abuseReport.amoFormEnabled", false]], + }); await AbuseReportTestUtils.setup(); }); diff --git a/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js b/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js index 25f14ce197f3..b9ea0f6a9321 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js +++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_abuse_report.js @@ -67,6 +67,11 @@ add_setup(async function () { set: [ ["extensions.webapi.testing", true], ["extensions.abuseReport.amWebAPI.enabled", true], + // Make sure the integrated abuse report panel is the one enabled + // while this test file runs (instead of the AMO hosted form). + // NOTE: behaviors expected when amoFormEnabled is true are tested + // in the separate browser_amo_abuse_report.js test file. + ["extensions.abuseReport.amoFormEnabled", false], ], }); });