tor-browser

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

browser_accessibility_tree_audit_long.js (2641B)


      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, TREE_FILTERS_MENU_ID */
      7 
      8 const header =
      9  '<h1 style="color:rgba(255,0,0,0.1); ' +
     10  'background-color:rgba(255,255,255,1);">header</h1>';
     11 
     12 const TEST_URI = `<html>
     13  <head>
     14    <meta charset="utf-8"/>
     15    <title>Accessibility Panel Test</title>
     16  </head>
     17  <body>
     18    ${header.repeat(20)}
     19  </body>
     20 </html>`;
     21 
     22 const docRow = {
     23  role: "document",
     24  name: `"Accessibility Panel Test"`,
     25 };
     26 const headingRow = {
     27  role: "heading",
     28  name: `"header"`,
     29 };
     30 const textLeafRow = {
     31  role: "text leaf",
     32  name: `"header"contrast`,
     33  badges: ["contrast"],
     34 };
     35 const audit = new Array(20).fill(textLeafRow);
     36 
     37 const auditInitial = audit.map(check => ({ ...check }));
     38 auditInitial[0].selected = true;
     39 
     40 const auditSecondLastSelected = audit.map(check => ({ ...check }));
     41 auditSecondLastSelected[19].selected = true;
     42 
     43 const resetAfterAudit = [docRow];
     44 for (let i = 0; i < 20; i++) {
     45  resetAfterAudit.push(headingRow);
     46  resetAfterAudit.push({ ...textLeafRow, selected: i === 19 });
     47 }
     48 
     49 /**
     50 * Test data has the format of:
     51 * {
     52 *   desc     {String}    description for better logging
     53 *   setup    {Function}  An optional setup that needs to be performed before
     54 *                        the state of the tree and the sidebar can be checked.
     55 *   expected {JSON}      An expected states for the tree and the sidebar.
     56 * }
     57 */
     58 const tests = [
     59  {
     60    desc: "Check initial state.",
     61    expected: {
     62      tree: [{ ...docRow, selected: true }],
     63    },
     64  },
     65  {
     66    desc: "Run an audit from a11y panel toolbar by activating a filter.",
     67    setup: async ({ doc, toolbox }) => {
     68      await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1);
     69    },
     70    expected: {
     71      tree: auditInitial,
     72    },
     73  },
     74  {
     75    desc: "Select a row that is guaranteed to have to be scrolled into view.",
     76    setup: async ({ doc }) => {
     77      selectRow(doc, 0);
     78      EventUtils.synthesizeKey("VK_END", {}, doc.defaultView);
     79    },
     80    expected: {
     81      tree: auditSecondLastSelected,
     82    },
     83  },
     84  {
     85    desc: "Click on the filter again.",
     86    setup: async ({ doc, toolbox }) => {
     87      await toggleMenuItem(doc, toolbox.doc, TREE_FILTERS_MENU_ID, 1);
     88    },
     89    expected: {
     90      tree: resetAfterAudit,
     91    },
     92  },
     93 ];
     94 
     95 /**
     96 * Simple test that checks content of the Accessibility panel tree when the
     97 * audit is activated via the panel's toolbar and the selection persists when
     98 * the filter is toggled off.
     99 */
    100 addA11yPanelTestsTask(
    101  tests,
    102  TEST_URI,
    103  "Test Accessibility panel tree with persistent selected row."
    104 );