tor-browser

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

browser_test_A11yUtils_announce.js (2113B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* import-globals-from ../../mochitest/role.js */
      7 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      8 
      9 // Check that the browser A11yUtils.announce() function works correctly.
     10 // Note that this does not use mozilla::a11y::Accessible::Announce and a11y
     11 // announcement events, as these aren't yet supported on desktop.
     12 async function runTests() {
     13  const alert = document.getElementById("a11y-announcement");
     14  let alerted = waitForEvent(EVENT_ALERT, alert);
     15  A11yUtils.announce({ raw: "first" });
     16  let event = await alerted;
     17  const alertAcc = event.accessible;
     18  is(alertAcc.role, ROLE_ALERT);
     19  ok(!alertAcc.name);
     20  is(alertAcc.childCount, 1);
     21  is(alertAcc.firstChild.name, "first");
     22 
     23  alerted = waitForEvent(EVENT_ALERT, alertAcc);
     24  A11yUtils.announce({ raw: "second" });
     25  event = await alerted;
     26  ok(!alertAcc.name);
     27  is(alertAcc.childCount, 1);
     28  is(alertAcc.firstChild.name, "second");
     29 
     30  info("Testing Fluent message");
     31  // We need a simple Fluent message here without arguments or attributes.
     32  const fluentId = "search-one-offs-with-title";
     33  const fluentMessage = await document.l10n.formatValue(fluentId);
     34  alerted = waitForEvent(EVENT_ALERT, alertAcc);
     35  A11yUtils.announce({ id: fluentId });
     36  event = await alerted;
     37  ok(!alertAcc.name);
     38  is(alertAcc.childCount, 1);
     39  is(alertAcc.firstChild.name, fluentMessage);
     40 
     41  info("Ensuring Fluent message is cancelled if announce is re-entered");
     42  alerted = waitForEvent(EVENT_ALERT, alertAcc);
     43  // This call runs async.
     44  let asyncAnnounce = A11yUtils.announce({ id: fluentId });
     45  // Before the async call finishes, call announce again.
     46  A11yUtils.announce({ raw: "third" });
     47  // Wait for the async call to complete.
     48  await asyncAnnounce;
     49  event = await alerted;
     50  ok(!alertAcc.name);
     51  is(alertAcc.childCount, 1);
     52  // The async call should have been cancelled. If it wasn't, we would get
     53  // fluentMessage here instead of "third".
     54  is(alertAcc.firstChild.name, "third");
     55 }
     56 
     57 addAccessibleTask(``, runTests);