tor-browser

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

browser_label_title.js (5117B)


      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 /* import-globals-from ../../mochitest/role.js */
      8 /* import-globals-from ../../mochitest/states.js */
      9 loadScripts(
     10  { name: "role.js", dir: MOCHITESTS_DIR },
     11  { name: "states.js", dir: MOCHITESTS_DIR }
     12 );
     13 
     14 /**
     15 * Test different labeling/titling schemes for text fields
     16 */
     17 addAccessibleTask(
     18  `<label for="n1">Label     </label> <input id="n1">
     19   <label for="n2">Two</label> <label for="n2">Labels</label> <input id="n2">
     20   <input aria-label="ARIA Label" id="n3">`,
     21  (browser, accDoc) => {
     22    let n1 = getNativeInterface(accDoc, "n1");
     23    let n1Label = n1.getAttributeValue("AXTitleUIElement");
     24    // XXX: In Safari the label is an AXText with an AXValue,
     25    // we emulate that so VoiceOver does not speak the label twice.
     26    is(n1Label.getAttributeValue("AXTitle"), "");
     27 
     28    let n2 = getNativeInterface(accDoc, "n2");
     29    is(n2.getAttributeValue("AXTitle"), "Two Labels");
     30 
     31    let n3 = getNativeInterface(accDoc, "n3");
     32    is(n3.getAttributeValue("AXDescription"), "ARIA Label");
     33  }
     34 );
     35 
     36 /**
     37 * Test to see that named groups get labels
     38 */
     39 addAccessibleTask(
     40  `<fieldset id="fieldset"><legend>Fields</legend><input aria-label="hello"></fieldset>`,
     41  (browser, accDoc) => {
     42    let fieldset = getNativeInterface(accDoc, "fieldset");
     43    is(fieldset.getAttributeValue("AXDescription"), "Fields");
     44  }
     45 );
     46 
     47 /**
     48 * Test to see that list items don't get titled groups
     49 */
     50 addAccessibleTask(
     51  `<ul style="list-style: none;"><li id="unstyled-item">Hello</li></ul>
     52   <ul><li id="styled-item">World</li></ul>`,
     53  (browser, accDoc) => {
     54    let unstyledItem = getNativeInterface(accDoc, "unstyled-item");
     55    is(unstyledItem.getAttributeValue("AXTitle"), "");
     56 
     57    let styledItem = getNativeInterface(accDoc, "unstyled-item");
     58    is(styledItem.getAttributeValue("AXTitle"), "");
     59  }
     60 );
     61 
     62 /**
     63 * Test that we fire a title changed notification
     64 */
     65 addAccessibleTask(
     66  `<button id="btn">Hello world</button>`,
     67  async (browser, accDoc) => {
     68    let btn = getNativeInterface(accDoc, "btn");
     69    is(btn.getAttributeValue("AXTitle"), "Hello world");
     70    let evt = waitForMacEvent("AXTitleChanged", "btn");
     71    await SpecialPowers.spawn(browser, [], () => {
     72      content.document.getElementById("btn").textContent = "Hello universe";
     73    });
     74    await evt;
     75    is(btn.getAttributeValue("AXTitle"), "Hello universe");
     76  }
     77 );
     78 
     79 /**
     80 * Test articles supply only labels not titles
     81 */
     82 addAccessibleTask(
     83  `<article id="article" aria-label="Hello world"></article>`,
     84  async (browser, accDoc) => {
     85    let article = getNativeInterface(accDoc, "article");
     86    is(article.getAttributeValue("AXDescription"), "Hello world");
     87    ok(!article.getAttributeValue("AXTitle"));
     88  }
     89 );
     90 
     91 /**
     92 * Test text and number inputs supply only labels not titles
     93 */
     94 addAccessibleTask(
     95  `<label for="input">Your favorite number?</label><input type="text" name="input" value="11" id="input" aria-label="The best number you know of">`,
     96  async (browser, accDoc) => {
     97    let input = getNativeInterface(accDoc, "input");
     98    is(input.getAttributeValue("AXDescription"), "The best number you know of");
     99    ok(!input.getAttributeValue("AXTitle"));
    100    let evt = waitForEvent(EVENT_SHOW, "input");
    101    await SpecialPowers.spawn(browser, [], () => {
    102      content.document.getElementById("input").setAttribute("type", "number");
    103    });
    104    await evt;
    105    input = getNativeInterface(accDoc, "input");
    106    is(input.getAttributeValue("AXDescription"), "The best number you know of");
    107    ok(!input.getAttributeValue("AXTitle"));
    108  }
    109 );
    110 
    111 /**
    112 * Test a label with nested control
    113 */
    114 addAccessibleTask(
    115  `<label>Textarea label <textarea id="textarea"></textarea></label>`,
    116  async (browser, accDoc) => {
    117    let textarea = getNativeInterface(accDoc, "textarea");
    118    ok(!textarea.getAttributeValue("AXDescription"));
    119    is(textarea.getAttributeValue("AXTitle"), "Textarea label");
    120    ok(
    121      !textarea.getAttributeValue("AXTitleUIElement"),
    122      "label with nested control should be stripped"
    123    );
    124  }
    125 );
    126 
    127 /**
    128 * Test a block label with trailing whitespace
    129 */
    130 addAccessibleTask(
    131  `<div id="a">Hello </div><button aria-labelledby="a" id="btn">Click Me</button>`,
    132  async (browser, accDoc) => {
    133    let btn = getNativeInterface(accDoc, "btn");
    134    ok(!btn.getAttributeValue("AXDescription"));
    135    is(btn.getAttributeValue("AXTitle"), "Hello");
    136    ok(
    137      !btn.getAttributeValue("AXTitleUIElement"),
    138      "label with trailing whitespace should be stripped"
    139    );
    140  }
    141 );
    142 
    143 /**
    144 * Test no relation exposed when overridden.
    145 */
    146 addAccessibleTask(
    147  `<label id="lbl" for="btn">a</label><button id="btn" aria-label="c">b</button>`,
    148  async (browser, accDoc) => {
    149    let btn = getNativeInterface(accDoc, "btn");
    150    ok(!btn.getAttributeValue("AXTitle"));
    151    is(btn.getAttributeValue("AXDescription"), "c");
    152    ok(
    153      !btn.getAttributeValue("AXTitleUIElement"),
    154      "No relation exposed when overridden"
    155    );
    156  }
    157 );