tor-browser

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

browser_accessibility.js (2469B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check basics of the accessibility panel
      7 
      8 const ACCESSIBILITY_FORCED_DISABLED_PREF = "accessibility.force_disabled";
      9 
     10 const TEST_URI = `data:text/html,<meta charset=utf8>
     11  <head>
     12    <title>TopLevel</title>
     13    <style>h1 { color: lightgrey; }</style>
     14  </head>
     15  <body>
     16    <h1>Top level header</h1>
     17    <p>This is a paragraph.</p>`;
     18 
     19 add_task(async () => {
     20  const env = await addTestTab(TEST_URI);
     21  const { doc } = env;
     22 
     23  await checkTree(env, [
     24    {
     25      role: "document",
     26      name: `"TopLevel"`,
     27    },
     28  ]);
     29 
     30  ok(
     31    !doc.querySelector(".description"),
     32    "Before disabling the panel via the pref, the panel's description isn't visible"
     33  );
     34 
     35  await pushPref(ACCESSIBILITY_FORCED_DISABLED_PREF, 1);
     36  await waitFor(
     37    () => doc.querySelector(".description"),
     38    "After disabling via the pref, the panel's description is visible"
     39  );
     40 
     41  await pushPref(ACCESSIBILITY_FORCED_DISABLED_PREF, 0);
     42  await waitFor(
     43    () => !doc.querySelector(".description"),
     44    "After enabling via the pref, the panel's description is removed"
     45  );
     46 
     47  await checkTree(env, [
     48    {
     49      role: "document",
     50      name: `"TopLevel"`,
     51    },
     52  ]);
     53 
     54  await closeTabToolboxAccessibility(env.tab);
     55 });
     56 
     57 add_task(async function checkStartingWithDisabledAccessibilityService() {
     58  await pushPref(ACCESSIBILITY_FORCED_DISABLED_PREF, 1);
     59  const env = await addTestTab(TEST_URI, {
     60    // since the accessibility service is disabled, we won't get the document accessible
     61    // in the state
     62    waitUntilDocumentAccessibleInState: false,
     63  });
     64  const { doc, store } = env;
     65 
     66  ok(
     67    doc.querySelector(".description"),
     68    "Starting the panel when the service is disabled, the panel's description is visible"
     69  );
     70 
     71  await pushPref(ACCESSIBILITY_FORCED_DISABLED_PREF, 0);
     72  await waitFor(
     73    () => !doc.querySelector(".description"),
     74    "After enabling via the pref, the panel's description is removed"
     75  );
     76 
     77  await waitUntilState(
     78    store,
     79    state =>
     80      state.accessibles.size === 1 &&
     81      state.details.accessible?.role === "document"
     82  );
     83 
     84  await checkTree(env, [
     85    {
     86      role: "document",
     87      name: `"TopLevel"`,
     88    },
     89  ]);
     90 
     91  await closeTabToolboxAccessibility(env.tab);
     92 });
     93 
     94 function checkTree(env, tree) {
     95  return runA11yPanelTests(
     96    [
     97      {
     98        expected: {
     99          tree,
    100        },
    101      },
    102    ],
    103    env
    104  );
    105 }