Commit 0a19cba7 authored by Tooru Fujisawa's avatar Tooru Fujisawa
Browse files

Bug 1706650 - Split localization item for update banner label for each...

Bug 1706650 - Split localization item for update banner label for each notification. r=zbraniecki,fluent-reviewers,Gijs

Instead of copying from label-* attributes, set data-l10n-id for each
notification

Also, stop using attributes for checking if the notification is supported.

Differential Revision: https://phabricator.services.mozilla.com/D129270
parent 12fcf18e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@
    <vbox class="panel-subview-body">
      <vbox id="appMenu-proton-addon-banners"/>
      <toolbarbutton id="appMenu-proton-update-banner" class="panel-banner-item"
                     data-l10n-id="appmenuitem-update-banner3"
                     data-l10n-attrs="label-update-downloading, label-update-available, label-update-manual, label-update-unsupported, label-update-restart"
                     oncommand="PanelUI._onBannerItemSelected(event)"
                     wrap="true"
                     hidden="true"/>
+43 −60
Original line number Diff line number Diff line
@@ -15,6 +15,10 @@ const { CustomizableUITestUtils } = ChromeUtils.import(
  "resource://testing-common/CustomizableUITestUtils.jsm"
);

const { AppMenuNotifications } = ChromeUtils.import(
  "resource://gre/modules/AppMenuNotifications.jsm"
);

// These are brand names, proper names, or other things that we expect to
// not abide exactly to sentence case. NAMES is for single words, and PHRASES
// is for words in a specific order.
@@ -24,52 +28,6 @@ const PHRASES = new Set(["Troubleshoot Mode…"]);
let gCUITestUtils = new CustomizableUITestUtils(window);
let gLocalization = new Localization(["browser/newtab/asrouter.ftl"], true);

/**
 * For certain PanelMultiView subviews, we need to do some special work
 * to pull the strings from the toolbarbuttons. Items in this Object allow
 * us to do that.
 *
 * The schema is like so:
 *
 * const SPECIAL_GETTERS = {
 *   <PanelMultiView subview ID>: {
 *     <toolbarbutton ID>: function
 *   }
 * }
 *
 * The function for each toolbarbutton will receive a single argument
 * (the toolbarbutton), and should return an Array of one or more strings
 * to check for sentence case.
 */
const SPECIAL_GETTERS = {
  "appMenu-protonMainView": {
    "appMenu-proton-update-banner": function(button) {
      // The update banner toolbarbutton has a number of strings set as
      // attributes on it that start with "label-". Those attributes are:
      //
      // label-update-available
      // label-update-manual
      // label-update-unsupported
      // label-update-restart
      // label-update-downloading
      let result = [];
      for (let attr of button.attributes) {
        if (attr.name.startsWith("label-")) {
          result.push(attr.value);
        }
      }

      Assert.ok(
        !!result.length,
        "Should have found at least 1 label- attribute on " +
          "appMenu-update-banner to check for sentence case."
      );

      return result;
    },
  },
};

/**
 * This recursive function will take the current main or subview, find all of
 * the buttons that navigate to subviews inside it, and click each one
@@ -123,20 +81,12 @@ function checkToolbarButtons(view) {
  info("Checking toolbarbuttons in subview with id " + view.id);

  for (let toolbarbutton of toolbarbuttons) {
    let strings;
    if (
      SPECIAL_GETTERS[view.id] &&
      SPECIAL_GETTERS[view.id][toolbarbutton.id]
    ) {
      strings = SPECIAL_GETTERS[view.id][toolbarbutton.id](toolbarbutton);
    } else {
      strings = [
    let strings = [
      toolbarbutton.label,
      toolbarbutton.textContent,
      toolbarbutton.toolTipText,
      GetDynamicShortcutTooltipText(toolbarbutton.id),
    ];
    }
    info("Checking toolbarbutton " + toolbarbutton.id);
    for (let string of strings) {
      checkSentenceCase(string, toolbarbutton.id);
@@ -153,6 +103,37 @@ function checkSubheaders(view) {
  }
}

async function checkUpdateBanner(view) {
  let banner = view.querySelector("#appMenu-proton-update-banner");

  const notifications = [
    "update-downloading",
    "update-available",
    "update-manual",
    "update-unsupported",
    "update-restart",
  ];

  for (const notification of notifications) {
    // Forcibly remove the label in order to wait for the new label.
    banner.removeAttribute("label");

    let labelPromise = BrowserTestUtils.waitForMutationCondition(
      banner,
      { attributes: true, attributeFilter: ["label"] },
      () => !!banner.getAttribute("label")
    );

    AppMenuNotifications.showNotification(notification);

    await labelPromise;

    checkSentenceCase(banner.label, banner.id);

    AppMenuNotifications.removeNotification(/.*/);
  }
}

/**
 * Asserts whether or not a string matches sentence case.
 *
@@ -262,4 +243,6 @@ add_task(async function test_sentence_case_appmenu() {
    checkToolbarButtons(view);
    checkSubheaders(view);
  }

  await checkUpdateBanner(PanelUI.mainView);
});
+15 −6
Original line number Diff line number Diff line
@@ -985,16 +985,25 @@ const PanelUI = {
  // "Banner item" here refers to an item in the hamburger panel menu. They will
  // typically show up as a colored row in the panel.
  _showBannerItem(notification) {
    const supportedIds = [
      "update-downloading",
      "update-available",
      "update-manual",
      "update-unsupported",
      "update-restart",
    ];
    if (!supportedIds.includes(notification.id)) {
      return;
    }

    if (!this._panelBannerItem) {
      this._panelBannerItem = this.mainView.querySelector(".panel-banner-item");
    }
    let label = this._panelBannerItem.getAttribute("label-" + notification.id);
    // Ignore items we don't know about.
    if (!label) {
      return;
    }

    let l10nId = "appmenuitem-banner-" + notification.id;
    document.l10n.setAttributes(this._panelBannerItem, l10nId);

    this._panelBannerItem.setAttribute("notificationid", notification.id);
    this._panelBannerItem.setAttribute("label", label);
    this._panelBannerItem.hidden = false;
    this._panelBannerItem.notification = notification;
  },
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ skip-if = (verify && (os == 'linux' || os == 'mac'))
tags = fullscreen
[browser_panelUINotifications_modals.js]
[browser_panelUINotifications_multiWindow.js]
[browser_panelUINotifications_bannerVisibility.js]
[browser_proton_moreTools_panel.js]
[browser_proton_toolbar_hide_toolbarbuttons.js]
[browser_remove_customized_specials.js]
+10 −10
Original line number Diff line number Diff line
@@ -135,8 +135,8 @@ add_task(async function testSecondaryActionWorkflow() {
    );
    let menuItem = PanelUI.mainView.querySelector(".panel-banner-item");
    is(
      menuItem.label,
      menuItem.getAttribute("label-update-manual"),
      menuItem.getAttribute("data-l10n-id"),
      "appmenuitem-banner-update-manual",
      "Showing correct label"
    );
    is(menuItem.hidden, false, "update-manual menu item is showing.");
@@ -197,8 +197,8 @@ add_task(async function testDownloadingBadge() {
    );
    let menuItem = PanelUI.mainView.querySelector(".panel-banner-item");
    is(
      menuItem.label,
      menuItem.getAttribute("label-update-downloading"),
      menuItem.getAttribute("data-l10n-id"),
      "appmenuitem-banner-update-downloading",
      "Showing correct label (downloading)"
    );
    is(menuItem.hidden, false, "update-downloading menu item is showing.");
@@ -301,8 +301,8 @@ add_task(async function testInteractionWithBadges() {
    );
    let menuItem = PanelUI.mainView.querySelector(".panel-banner-item");
    is(
      menuItem.label,
      menuItem.getAttribute("label-update-manual"),
      menuItem.getAttribute("data-l10n-id"),
      "appmenuitem-banner-update-manual",
      "Showing correct label"
    );
    is(menuItem.hidden, false, "update-manual menu item is showing.");
@@ -552,8 +552,8 @@ add_task(async function testMultipleNonBadges() {
    );
    let menuItem = PanelUI.mainView.querySelector(".panel-banner-item");
    is(
      menuItem.label,
      menuItem.getAttribute("label-update-restart"),
      menuItem.getAttribute("data-l10n-id"),
      "appmenuitem-banner-update-restart",
      "Showing correct label"
    );
    is(menuItem.hidden, false, "update-restart menu item is showing.");
@@ -582,8 +582,8 @@ add_task(async function testMultipleNonBadges() {
      "update-manual badge is displaying on PanelUI button."
    );
    is(
      menuItem.label,
      menuItem.getAttribute("label-update-manual"),
      menuItem.getAttribute("data-l10n-id"),
      "appmenuitem-banner-update-manual",
      "Showing correct label"
    );
    is(menuItem.hidden, false, "update-manual menu item is showing.");
Loading