tor-browser

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

browser_accessibility_tree_audit_reset.js (2666B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* global toggleMenuItem, selectAccessibleForNode, TREE_FILTERS_MENU_ID */
      7 
      8 const TEST_URI = `<html>
      9  <head>
     10    <meta charset="utf-8"/>
     11    <title>Accessibility Panel Test</title>
     12  </head>
     13  <body>
     14    <h1 style="color:rgba(255,0,0,0.1); background-color:rgba(255,255,255,1);">
     15      Top level header
     16    </h1>
     17    <h2 style="color:rgba(0,255,0,0.1); background-color:rgba(255,255,255,1);">
     18      Second level header
     19    </h2>
     20  </body>
     21 </html>`;
     22 
     23 /**
     24 * Test data has the format of:
     25 * {
     26 *   desc     {String}    description for better logging
     27 *   setup    {Function}  An optional setup that needs to be performed before
     28 *                        the state of the tree and the sidebar can be checked.
     29 *   expected {JSON}      An expected states for the tree and the sidebar.
     30 * }
     31 */
     32 const tests = [
     33  {
     34    desc: "Check initial state.",
     35    expected: {
     36      tree: [
     37        {
     38          role: "document",
     39          name: `"Accessibility Panel Test"`,
     40          selected: true,
     41        },
     42      ],
     43    },
     44  },
     45  {
     46    desc: "Run an audit from a11y panel toolbar by activating a filter.",
     47    setup: async ({ doc, toolbox }) => {
     48      await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1);
     49    },
     50    expected: {
     51      tree: [
     52        {
     53          role: "text leaf",
     54          name: `"Top level header "contrast`,
     55          badges: ["contrast"],
     56          selected: true,
     57        },
     58        {
     59          role: "text leaf",
     60          name: `"Second level header "contrast`,
     61          badges: ["contrast"],
     62        },
     63      ],
     64    },
     65  },
     66  {
     67    desc: "Select an accessible object.",
     68    setup: async env => {
     69      await selectAccessibleForNode(env, "h1");
     70    },
     71    expected: {
     72      tree: [
     73        {
     74          role: "document",
     75          name: `"Accessibility Panel Test"`,
     76        },
     77        {
     78          role: "heading",
     79          name: `"Top level header"`,
     80          selected: true,
     81        },
     82        {
     83          role: "text leaf",
     84          name: `"Top level header "contrast`,
     85          badges: ["contrast"],
     86        },
     87        {
     88          role: "heading",
     89          name: `"Second level header"`,
     90        },
     91        {
     92          role: "text leaf",
     93          name: `"Second level header "contrast`,
     94          badges: ["contrast"],
     95        },
     96      ],
     97    },
     98  },
     99 ];
    100 
    101 /**
    102 * Simple test that checks content of the Accessibility panel tree when the
    103 * audit is activated via the panel's toolbar.
    104 */
    105 addA11yPanelTestsTask(
    106  tests,
    107  TEST_URI,
    108  "Test Accessibility panel tree with contrast filter audit activation."
    109 );