Bug 1549991 - No remove action on report submitted for add-ons without PERM_CAN_UNINSTALL. r=flod,mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D30366

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-05-09 06:41:13 +00:00
parent f513023141
commit 97a6924489
3 changed files with 46 additions and 10 deletions

View File

@ -35,6 +35,7 @@ abuse-report-submit-button = Submit
abuse-report-messagebar-aborted = Report for <span data-l10n-name="addon-name">{ $addon-name }</span> canceled.
abuse-report-messagebar-submitting = Sending report for <span data-l10n-name="addon-name">{ $addon-name }</span>.
abuse-report-messagebar-submitted = Thank you for submitting a report. Do you want to remove <span data-l10n-name="addon-name">{ $addon-name }</span>?
abuse-report-messagebar-submitted-noremove = Thank you for submitting a report.
abuse-report-messagebar-removed-extension = Thank you for submitting a report. Youve removed the extension <span data-l10n-name="addon-name">{ $addon-name }</span>.
abuse-report-messagebar-removed-theme = Thank you for submitting a report. Youve removed the theme <span data-l10n-name="addon-name">{ $addon-name }</span>.
abuse-report-messagebar-error = There was an error sending the report for <span data-l10n-name="addon-name">{ $addon-name }</span>.

View File

@ -20,6 +20,10 @@ const ABUSE_REPORT_MESSAGE_BARS = {
id: "submitted", actionAddonTypeSuffix: true,
actions: ["remove", "keep"], dismissable: true,
},
// Submitted report message-bar (with no remove actions).
"submitted-no-remove-action": {
id: "submitted-noremove", dismissable: true,
},
// Submitted report and remove addon message-bar.
"submitted-and-removed": {
id: "removed", addonTypeSuffix: true, dismissable: true,
@ -112,9 +116,10 @@ function createReportMessageBar(
}
async function submitReport({report, reason, message}) {
const addonId = report.addon.id;
const addonName = report.addon && report.addon.name;
const addonType = report.addon && report.addon.type;
const {addon} = report;
const addonId = addon.id;
const addonName = addon.name;
const addonType = addon.type;
// Create a message bar while we are still submitting the report.
const mbSubmitting = createReportMessageBar(
@ -131,14 +136,21 @@ async function submitReport({report, reason, message}) {
await report.submit({reason, message});
mbSubmitting.remove();
// Create a submitted message bar is the submission has been
// Create a submitted message bar when the submission has been
// successful.
// With reportEntryPoint "uninstall" a specific message bar
// is going to be used. All the other reportEntryPoint
// values ("menu" and "toolbar_context_menu") uses the same
// "submitted" message bar.
const barId = report.reportEntryPoint === "uninstall" ?
"submitted-and-removed" : "submitted";
let barId;
if (!(addon.permissions & AddonManager.PERM_CAN_UNINSTALL)) {
// Do not offer remove action if the addon can't be uninstalled.
barId = "submitted-no-remove-action";
} else if (report.reportEntryPoint === "uninstall") {
// With reportEntryPoint "uninstall" a specific message bar
// is going to be used.
barId = "submitted-and-removed";
} else {
// All the other reportEntryPoint ("menu" and "toolbar_context_menu")
// use the same kind of message bar.
barId = "submitted";
}
const mbInfo = createReportMessageBar(barId, {
addonId, addonName, addonType,

View File

@ -26,7 +26,9 @@ const BASE_TEST_MANIFEST = {
32: "test-icon.png",
},
};
const THEME_NO_UNINSTALL_ID = "theme-without-perm-can-uninstall@mochi.test";
let gProvider;
let gHtmlAboutAddonsWindow;
let gManagerWindow;
let apiRequestHandler;
@ -214,6 +216,16 @@ add_task(async function setup() {
["extensions.abuseReport.url", "http://test.addons.org/api/report/"],
],
});
gProvider = new MockProvider();
gProvider.createAddons([{
id: THEME_NO_UNINSTALL_ID,
name: "This theme cannot be uninstalled",
version: "1.1",
creator: {name: "Theme creator", url: "http://example.com/creator"},
type: "theme",
permissions: 0,
}]);
});
// This test case verifies that:
@ -808,6 +820,17 @@ add_task(async function test_abuse_report_message_bars() {
triggerSubmitAbuseReport("fake-reason", "fake-message");
});
// Verify message bar on add-on without perm_can_uninstall.
await assertMessageBars([
"submitting", "submitted-no-remove-action",
], async () => {
info("Test message bars on report submitted on an addon without remove");
setTestRequestHandler(200, "{}");
triggerNewAbuseReport(THEME_NO_UNINSTALL_ID, "menu");
await promiseAbuseReportRendered();
triggerSubmitAbuseReport("fake-reason", "fake-message");
});
// Verify the 3 expected entry points:
// menu, toolbar_context_menu and uninstall
// (See https://addons-server.readthedocs.io/en/latest/topics/api/abuse.html).