tor-browser

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

browser_aria_controls_flowto.js (2685B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Test aria-controls
      9 */
     10 addAccessibleTask(
     11  `<button aria-controls="info" id="info-button">Show info</button>
     12   <div id="info">Information.</div>
     13   <div id="more-info">More information.</div>`,
     14  async (browser, accDoc) => {
     15    const getAriaControls = id =>
     16      JSON.stringify(
     17        getNativeInterface(accDoc, id)
     18          .getAttributeValue("AXARIAControls")
     19          .map(e => e.getAttributeValue("AXDOMIdentifier"))
     20      );
     21 
     22    await untilCacheIs(
     23      () => getAriaControls("info-button"),
     24      JSON.stringify(["info"]),
     25      "Info-button has correct initial controls"
     26    );
     27 
     28    await SpecialPowers.spawn(browser, [], () => {
     29      content.document
     30        .getElementById("info-button")
     31        .setAttribute("aria-controls", "info more-info");
     32    });
     33 
     34    await untilCacheIs(
     35      () => getAriaControls("info-button"),
     36      JSON.stringify(["info", "more-info"]),
     37      "Info-button has correct controls after mutation"
     38    );
     39  }
     40 );
     41 
     42 function getLinkedUIElements(accDoc, id) {
     43  return JSON.stringify(
     44    getNativeInterface(accDoc, id)
     45      .getAttributeValue("AXLinkedUIElements")
     46      .map(e => e.getAttributeValue("AXDOMIdentifier"))
     47  );
     48 }
     49 
     50 /**
     51 * Test aria-flowto
     52 */
     53 addAccessibleTask(
     54  `<button aria-flowto="info" id="info-button">Show info</button>
     55   <div id="info">Information.</div>
     56   <div id="more-info">More information.</div>`,
     57  async (browser, accDoc) => {
     58    await untilCacheIs(
     59      () => getLinkedUIElements(accDoc, "info-button"),
     60      JSON.stringify(["info"]),
     61      "Info-button has correct initial linked elements"
     62    );
     63 
     64    await SpecialPowers.spawn(browser, [], () => {
     65      content.document
     66        .getElementById("info-button")
     67        .setAttribute("aria-flowto", "info more-info");
     68    });
     69 
     70    await untilCacheIs(
     71      () => getLinkedUIElements(accDoc, "info-button"),
     72      JSON.stringify(["info", "more-info"]),
     73      "Info-button has correct linked elements after mutation"
     74    );
     75  }
     76 );
     77 
     78 /**
     79 * Test aria-controls
     80 */
     81 addAccessibleTask(
     82  `<input type="radio" id="cat-radio" name="animal"><label for="cat">Cat</label>
     83   <input type="radio" id="dog-radio" name="animal" aria-flowto="info"><label for="dog">Dog</label>
     84   <div id="info">Information.</div>`,
     85  async (browser, accDoc) => {
     86    await untilCacheIs(
     87      () => getLinkedUIElements(accDoc, "dog-radio"),
     88      JSON.stringify(["cat-radio", "dog-radio", "info"]),
     89      "dog-radio has correct linked elements"
     90    );
     91  }
     92 );