tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_palette_labels.js (2571B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check that all customizable buttons have labels and icons.
      8 *
      9 * This is primarily designed to ensure we don't end up with items without
     10 * labels in customize mode. In the past, this has happened due to race
     11 * conditions, where labels would be correct if and only if the item had
     12 * already been moved into a toolbar or panel in the main UI before
     13 * (forcing it to be constructed and any fluent identifiers to be localized
     14 * and applied).
     15 * We use a new window to ensure that earlier tests using some of the widgets
     16 * in the palette do not influence our checks to see that such items get
     17 * labels, "even" if the first time they're rendered is in customize mode's
     18 * palette.
     19 */
     20 
     21 add_setup(async function () {
     22  await SpecialPowers.pushPrefEnv({
     23    set: [["browser.search.widget.new", true]],
     24  });
     25 });
     26 
     27 add_task(async function test_all_buttons_have_labels() {
     28  let win = await BrowserTestUtils.openNewBrowserWindow();
     29  registerCleanupFunction(async () => {
     30    await endCustomizing(win);
     31    return BrowserTestUtils.closeWindow(win);
     32  });
     33  await startCustomizing(win);
     34  let { palette } = win.gNavToolbox;
     35  // Wait for things to paint.
     36  await TestUtils.waitForCondition(() => {
     37    return !!Array.from(palette.querySelectorAll(".toolbarbutton-icon")).filter(
     38      n => {
     39        let rect = n.getBoundingClientRect();
     40        return rect.height > 0 && rect.width > 0;
     41      }
     42    ).length;
     43  }, "Must start rendering icons.");
     44 
     45  for (let wrapper of palette.children) {
     46    if (wrapper.hasAttribute("title")) {
     47      ok(true, wrapper.firstElementChild.id + " has a label.");
     48    } else {
     49      info(
     50        `${wrapper.firstElementChild.id} doesn't seem to have a label, waiting.`
     51      );
     52      await BrowserTestUtils.waitForAttribute("title", wrapper);
     53      ok(
     54        wrapper.hasAttribute("title"),
     55        wrapper.firstElementChild.id + " has a label."
     56      );
     57    }
     58    let icons = Array.from(wrapper.querySelectorAll(".toolbarbutton-icon"));
     59    // If there are icons, at least one must be visible
     60    // (not everything necessarily has one, e.g. the search bar has no icon)
     61    if (icons.length) {
     62      let visibleIcons = icons.filter(n => {
     63        let rect = n.getBoundingClientRect();
     64        return rect.height > 0 && rect.width > 0;
     65      });
     66      Assert.greater(
     67        visibleIcons.length,
     68        0,
     69        `${wrapper.firstElementChild.id} should have at least one visible icon.`
     70      );
     71    }
     72  }
     73 });