tor-browser

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

browser_accessibility_node.js (5293B)


      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 // Checks for the AccessibleActor
      8 
      9 add_task(async function () {
     10  const { target, walker, a11yWalker, parentAccessibility } =
     11    await initAccessibilityFrontsForUrl(MAIN_DOMAIN + "doc_accessibility.html");
     12  const modifiers =
     13    Services.appinfo.OS === "Darwin" ? "\u2303\u2325" : "Alt+Shift+";
     14 
     15  const buttonNode = await walker.querySelector(walker.rootNode, "#button");
     16  const accessibleFront = await a11yWalker.getAccessibleFor(buttonNode);
     17 
     18  checkA11yFront(accessibleFront, {
     19    name: "Accessible Button",
     20    role: "button",
     21    childCount: 1,
     22  });
     23 
     24  await accessibleFront.hydrate();
     25 
     26  checkA11yFront(accessibleFront, {
     27    name: "Accessible Button",
     28    role: "button",
     29    value: "",
     30    description: "Accessibility Test",
     31    keyboardShortcut: modifiers + "b",
     32    childCount: 1,
     33    domNodeType: 1,
     34    indexInParent: 1,
     35    states: ["focusable", "opaque", "enabled", "sensitive"],
     36    actions: ["Press"],
     37    attributes: {
     38      "margin-top": "0px",
     39      display: "inline-block",
     40      "text-align": "center",
     41      "text-indent": "0px",
     42      "margin-left": "0px",
     43      tag: "button",
     44      "margin-right": "0px",
     45      id: "button",
     46      formatting: "block",
     47      "margin-bottom": "0px",
     48    },
     49  });
     50 
     51  info("Children");
     52  const children = await accessibleFront.children();
     53  is(children.length, 1, "Accessible Front has correct number of children");
     54  checkA11yFront(children[0], {
     55    name: "Accessible Button",
     56    role: "text leaf",
     57  });
     58 
     59  info("Relations");
     60  const labelNode = await walker.querySelector(walker.rootNode, "#label");
     61  const controlNode = await walker.querySelector(walker.rootNode, "#control");
     62  const labelAccessibleFront = await a11yWalker.getAccessibleFor(labelNode);
     63  const controlAccessibleFront = await a11yWalker.getAccessibleFor(controlNode);
     64  const docAccessibleFront = await a11yWalker.getAccessibleFor(walker.rootNode);
     65  const labelRelations = await labelAccessibleFront.getRelations();
     66  is(labelRelations.length, 2, "Label has correct number of relations");
     67  is(labelRelations[0].type, "label for", "Label has a label for relation");
     68  is(labelRelations[0].targets.length, 1, "Label is a label for one target");
     69  is(
     70    labelRelations[0].targets[0],
     71    controlAccessibleFront,
     72    "Label is a label for control accessible front"
     73  );
     74  is(
     75    labelRelations[1].type,
     76    "containing document",
     77    "Label has a containing document relation"
     78  );
     79  is(
     80    labelRelations[1].targets.length,
     81    1,
     82    "Label is contained by just one document"
     83  );
     84  is(
     85    labelRelations[1].targets[0],
     86    docAccessibleFront,
     87    "Label's containing document is a root document"
     88  );
     89 
     90  const controlRelations = await controlAccessibleFront.getRelations();
     91  is(controlRelations.length, 3, "Control has correct number of relations");
     92  is(controlRelations[2].type, "details", "Control has a details relation");
     93  is(controlRelations[2].targets.length, 1, "Control has one details target");
     94  const detailsNode = await walker.querySelector(walker.rootNode, "#details");
     95  const detailsAccessibleFront = await a11yWalker.getAccessibleFor(detailsNode);
     96  is(
     97    controlRelations[2].targets[0],
     98    detailsAccessibleFront,
     99    "Control has correct details target"
    100  );
    101 
    102  info("Snapshot");
    103  const snapshot = await controlAccessibleFront.snapshot();
    104  Assert.deepEqual(snapshot, {
    105    name: "Label",
    106    role: "textbox",
    107    actions: ["Activate"],
    108    value: "",
    109    nodeCssSelector: "#control",
    110    nodeType: 1,
    111    description: "",
    112    keyboardShortcut: "",
    113    childCount: 0,
    114    indexInParent: 1,
    115    states: [
    116      "focusable",
    117      "autocompletion",
    118      "selectable text",
    119      "editable",
    120      "opaque",
    121      "single line",
    122      "enabled",
    123      "sensitive",
    124    ],
    125    children: [],
    126    attributes: {
    127      "margin-left": "0px",
    128      "text-align": "start",
    129      "text-indent": "0px",
    130      id: "control",
    131      tag: "input",
    132      "margin-top": "0px",
    133      "margin-bottom": "0px",
    134      "margin-right": "0px",
    135      display: "inline-block",
    136      "explicit-name": "true",
    137      "details-from": "aria-details",
    138    },
    139  });
    140 
    141  // Check that we're using ARIA role tokens for landmarks implicit in native
    142  // markup.
    143  const headerNode = await walker.querySelector(walker.rootNode, "#header");
    144  const headerAccessibleFront = await a11yWalker.getAccessibleFor(headerNode);
    145  checkA11yFront(headerAccessibleFront, {
    146    name: null,
    147    role: "banner",
    148    childCount: 1,
    149  });
    150  const navNode = await walker.querySelector(walker.rootNode, "#nav");
    151  const navAccessibleFront = await a11yWalker.getAccessibleFor(navNode);
    152  checkA11yFront(navAccessibleFront, {
    153    name: null,
    154    role: "navigation",
    155    childCount: 1,
    156  });
    157  const footerNode = await walker.querySelector(walker.rootNode, "#footer");
    158  const footerAccessibleFront = await a11yWalker.getAccessibleFor(footerNode);
    159  checkA11yFront(footerAccessibleFront, {
    160    name: null,
    161    role: "contentinfo",
    162    childCount: 1,
    163  });
    164 
    165  await waitForA11yShutdown(parentAccessibility);
    166  await target.destroy();
    167  gBrowser.removeCurrentTab();
    168 });