Bug 1549706 - Use per addonType Fluent id for abuse-report remove and keep actions. r=flod,mstriemer
authorLuca Greco <lgreco@mozilla.com>
Wed, 08 May 2019 16:24:56 +0000
changeset 473190 7c9375503ddff95012915a5817ffe049c7302148
parent 473189 93a295bd607a733eab067b252399fa53c1872608
child 473191 c24c083425d0e543bd59076d675c2efcb3b7c73c
push id35990
push usernerli@mozilla.com
push dateThu, 09 May 2019 15:34:57 +0000
treeherdermozilla-central@34b343ca6c2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, mstriemer
bugs1549706
milestone68.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 1549706 - Use per addonType Fluent id for abuse-report remove and keep actions. r=flod,mstriemer Depends on D30186 Differential Revision: https://phabricator.services.mozilla.com/D30187
toolkit/locales/en-US/toolkit/about/abuseReports.ftl
toolkit/mozapps/extensions/content/abuse-reports.js
toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
--- a/toolkit/locales/en-US/toolkit/about/abuseReports.ftl
+++ b/toolkit/locales/en-US/toolkit/about/abuseReports.ftl
@@ -37,18 +37,20 @@ abuse-report-messagebar-submitting = Sen
 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-removed-extension = Thank you for submitting a report. You’ve removed the extension <span data-l10n-name="addon-name">{ $addon-name }</span>.
 abuse-report-messagebar-removed-theme = Thank you for submitting a report. You’ve 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>.
 abuse-report-messagebar-error-recent-submit = The report for <span data-l10n-name="addon-name">{ $addon-name }</span> wasn’t sent because another report was submitted recently.
 
 ## Message bars actions.
 
-abuse-report-messagebar-action-remove = Yes, Remove It
-abuse-report-messagebar-action-keep = No, I’ll Keep It
+abuse-report-messagebar-action-remove-extension = Yes, Remove It
+abuse-report-messagebar-action-keep-extension = No, I’ll Keep It
+abuse-report-messagebar-action-remove-theme = Yes, Remove It
+abuse-report-messagebar-action-keep-theme = No, I’ll Keep It
 abuse-report-messagebar-action-retry = Retry
 abuse-report-messagebar-action-cancel = Cancel
 
 ## Abuse report reasons (optionally paired with related examples and/or suggestions)
 
 abuse-report-damage-reason = Damages my computer and data
 abuse-report-damage-example = Example: Injected malware or stole data
 
--- a/toolkit/mozapps/extensions/content/abuse-reports.js
+++ b/toolkit/mozapps/extensions/content/abuse-reports.js
@@ -12,17 +12,18 @@
  */
 
 // Message Bars definitions.
 const ABUSE_REPORT_MESSAGE_BARS = {
   // Idle message-bar (used while the submission is still ongoing).
   "submitting": {id: "submitting", actions: ["cancel"]},
   // Submitted report message-bar.
   "submitted": {
-    id: "submitted", actions: ["remove", "keep"], dismissable: true,
+    id: "submitted", actionAddonTypeSuffix: true,
+    actions: ["remove", "keep"], dismissable: true,
   },
   // Submitted report and remove addon message-bar.
   "submitted-and-removed": {
     id: "removed", addonTypeSuffix: true, dismissable: true,
   },
   // The "aborted report" message bar is rendered as a generic informative one,
   // because aborting a report is triggered by a user choice.
   "ERROR_ABORTED_SUBMIT": {
@@ -63,35 +64,39 @@ function createReportMessageBar(
 ) {
   const getMessageL10n = (id) => `abuse-report-messagebar-${id}`;
   const getActionL10n = (action) => getMessageL10n(`action-${action}`);
 
   const barInfo = ABUSE_REPORT_MESSAGE_BARS[definitionId];
   if (!barInfo) {
     throw new Error(`message-bar definition not found: ${definitionId}`);
   }
-  const {id, dismissable, actions, type, addonTypeSuffix} = barInfo;
+  const {id, dismissable, actions, type} = barInfo;
   const messageEl = document.createElement("span");
 
   // The message element includes an addon-name span (also filled by
   // Fluent), which can be used to apply custom styles to the addon name
   // included in the message bar (if needed).
   const addonNameEl = document.createElement("span");
   addonNameEl.setAttribute("data-l10n-name", "addon-name");
   messageEl.append(addonNameEl);
 
   document.l10n.setAttributes(
     messageEl,
-    getMessageL10n(addonTypeSuffix ? `${id}-${addonType}` : id),
+    getMessageL10n(barInfo.addonTypeSuffix ? `${id}-${addonType}` : id),
     {"addon-name": addonName || addonId});
 
   const barActions = actions ? actions.map(action => {
+    // Some of the message bars require a different per addonType
+    // Fluent id for their actions.
+    const actionId = barInfo.actionAddonTypeSuffix ?
+      `${action}-${addonType}` : action;
     const buttonEl = document.createElement("button");
     buttonEl.addEventListener("click", () => onaction && onaction(action));
-    document.l10n.setAttributes(buttonEl, getActionL10n(action));
+    document.l10n.setAttributes(buttonEl, getActionL10n(actionId));
     return buttonEl;
   }) : [];
 
   const messagebar = document.createElement("message-bar");
   messagebar.setAttribute("type", type || "generic");
   if (dismissable) {
     messagebar.setAttribute("dismissable", "");
   }
--- a/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_abuse_report.js
@@ -715,34 +715,38 @@ add_task(async function test_abuse_repor
   const theme = await installTestExtension(THEME_ID, "theme");
   await test_abuse_report_suggestions(THEME_ID);
   await theme.unload();
 });
 
 // This test case verifies the message bars created on other
 // scenarios (e.g. report creation and submissions errors).
 add_task(async function test_abuse_report_message_bars() {
-  const EXT_ID = "test-extension-errors@mochi.test";
-  const EXT_ID2 = "test-extension-errors-2@mochi.test";
+  const EXT_ID = "test-extension-report@mochi.test";
+  const EXT_ID2 = "test-extension-report-2@mochi.test";
+  const THEME_ID = "test-theme-report@mochi.test";
   const extension = await installTestExtension(EXT_ID);
   const extension2 = await installTestExtension(EXT_ID2);
+  const theme = await installTestExtension(THEME_ID, "theme");
 
-  async function assertMessageBars(expectedMessageBarIds, test) {
+  async function assertMessageBars(
+    expectedMessageBarIds, testSetup, testMessageBarDetails
+  ) {
     await openAboutAddons();
     const expectedLength = expectedMessageBarIds.length;
     const onMessageBarsCreated = promiseMessageBars(expectedLength);
     // Reset the timestamp of the last report between tests.
     AbuseReporter._lastReportTimestamp = null;
-    const cleanup = await test();
+    await testSetup();
     info(`Waiting for ${expectedLength} message-bars to be created`);
     const barDetails = await onMessageBarsCreated;
     Assert.deepEqual(barDetails.map(d => d.definitionId), expectedMessageBarIds,
                      "Got the expected message bars");
-    if (cleanup) {
-      await cleanup();
+    if (testMessageBarDetails) {
+      await testMessageBarDetails(barDetails);
     }
     await closeAboutAddons();
   }
 
   function setTestRequestHandler(responseStatus, responseData) {
     apiRequestHandler = ({request, response}) => {
       response.setStatusLine(request.httpVersion, responseStatus, "Error");
       response.write(responseData);
@@ -810,34 +814,51 @@ add_task(async function test_abuse_repor
   await assertMessageBars(["submitting", "submitted"], async () => {
     info("Test message bars on report opened from addon options menu");
     setTestRequestHandler(200, "{}");
     triggerNewAbuseReport(EXT_ID, "menu");
     await promiseAbuseReportRendered();
     triggerSubmitAbuseReport("fake-reason", "fake-message");
   });
 
-  await assertMessageBars(["submitting", "submitted"], async () => {
-    info("Test message bars on report opened from browserAction context menu");
-    setTestRequestHandler(200, "{}");
-    triggerNewAbuseReport(EXT_ID, "toolbar_context_menu");
-    await promiseAbuseReportRendered();
-    triggerSubmitAbuseReport("fake-reason", "fake-message");
-  });
+  for (const extId of [EXT_ID, THEME_ID]) {
+    await assertMessageBars(["submitting", "submitted"], async () => {
+      info(`Test message bars on ${extId} reported from toolbar contextmenu`);
+      setTestRequestHandler(200, "{}");
+      triggerNewAbuseReport(extId, "toolbar_context_menu");
+      await promiseAbuseReportRendered();
+      triggerSubmitAbuseReport("fake-reason", "fake-message");
+    }, ([submittingDetails, submittedDetails]) => {
+      const buttonsL10nId = Array.from(
+        submittedDetails.messagebar.querySelectorAll("button")
+      ).map(el => el.getAttribute("data-l10n-id"));
+      if (extId === THEME_ID) {
+        ok(buttonsL10nId.every(id => id.endsWith("-theme")),
+           "submitted bar actions should use the Fluent id for themes");
+      } else {
+        ok(buttonsL10nId.every(id => id.endsWith("-extension")),
+           "submitted bar actions should use the Fluent id for extensions");
+      }
+    });
+  }
 
-  await assertMessageBars(["submitting", "submitted-and-removed"], async () => {
-    info("Test message bars on report opened from addon removal");
-    setTestRequestHandler(200, "{}");
-    triggerNewAbuseReport(EXT_ID2, "uninstall");
-    await promiseAbuseReportRendered();
-    triggerSubmitAbuseReport("fake-reason", "fake-message");
-  });
+  for (const extId of [EXT_ID2, THEME_ID]) {
+    const testFn = async () => {
+      info(`Test message bars on ${extId} reported opened from addon removal`);
+      setTestRequestHandler(200, "{}");
+      triggerNewAbuseReport(extId, "uninstall");
+      await promiseAbuseReportRendered();
+      triggerSubmitAbuseReport("fake-reason", "fake-message");
+    };
+    await assertMessageBars(["submitting", "submitted-and-removed"], testFn);
+  }
 
   await extension.unload();
   await extension2.unload();
+  await theme.unload();
 });
 
 add_task(async function test_trigger_abusereport_from_aboutaddons_menu() {
   const EXT_ID = "test-report-from-aboutaddons-menu@mochi.test";
   const extension = await installTestExtension(EXT_ID);
 
   await openAboutAddons();
   await gManagerWindow.htmlBrowserLoaded;