tor-browser

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

browser_accessibility_tree_iframe_picker.js (2799B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check that the accessibility panel works as expected when using the iframe picker
      7 
      8 const TEST_URI = `data:text/html,<meta charset=utf8>
      9  <head>
     10    <title>TopLevel</title>
     11    <style>h1 { color: lightgrey; }</style>
     12  </head>
     13  <body>
     14    <h1>Top level header</h1>
     15    <p>This is a paragraph.</p>
     16    <iframe src="data:text/html,<meta charset=utf8>
     17      <head>
     18        <title>iframe</title>
     19        <style>h2 { color: aliceblue }</style>
     20      </head>
     21      <body>
     22        <h2>Iframe header</h2>
     23 
     24        <iframe src='data:text/html,<meta charset=utf8>
     25          <head>
     26            <title>nested iframe</title>
     27            <style>h2 { color: lightpink }</style>
     28          </head>
     29          <body>
     30            <h2>Nested Iframe header</h2>
     31          </body>
     32        '></iframe>
     33 
     34      </body>
     35    "></iframe>`;
     36 
     37 add_task(async () => {
     38  const env = await addTestTab(TEST_URI);
     39  const { doc, toolbox, win } = env;
     40 
     41  await checkTree(env, [
     42    {
     43      role: "document",
     44      name: `"TopLevel"`,
     45    },
     46  ]);
     47 
     48  info("Select the iframe in the iframe picker");
     49  // Get the iframe picker items
     50  const menuList = toolbox.doc.getElementById("toolbox-frame-menu");
     51  const frames = Array.from(menuList.querySelectorAll(".command"));
     52 
     53  let onInitialized = win.once(win.EVENTS.INITIALIZED);
     54  frames[1].click();
     55  await onInitialized;
     56 
     57  await checkTree(env, [
     58    {
     59      role: "document",
     60      name: `"iframe"`,
     61    },
     62  ]);
     63 
     64  info(
     65    "Run a constrast audit to check only issues from selected iframe tree are displayed"
     66  );
     67  const CONTRAST_MENU_ITEM_INDEX = 2;
     68  const onUpdated = win.once(win.EVENTS.ACCESSIBILITY_INSPECTOR_UPDATED);
     69  await toggleMenuItem(
     70    doc,
     71    toolbox.doc,
     72    TREE_FILTERS_MENU_ID,
     73    CONTRAST_MENU_ITEM_INDEX
     74  );
     75  await onUpdated;
     76  // wait until the tree is filtered (i.e. the audit is done and only nodes with issues
     77  // should be displayed)
     78  await waitFor(() => doc.querySelector(".treeTable.filtered"));
     79 
     80  await checkTree(env, [
     81    {
     82      role: "text leaf",
     83      name: `"Iframe header"contrast`,
     84      badges: ["contrast"],
     85      level: 1,
     86    },
     87    {
     88      role: "text leaf",
     89      name: `"Nested Iframe header"contrast`,
     90      badges: ["contrast"],
     91      level: 1,
     92    },
     93  ]);
     94 
     95  info("Select the top level document back");
     96  onInitialized = win.once(win.EVENTS.INITIALIZED);
     97  frames[0].click();
     98  await onInitialized;
     99 
    100  await checkTree(env, [
    101    {
    102      role: "document",
    103      name: `"TopLevel"`,
    104    },
    105  ]);
    106 
    107  await closeTabToolboxAccessibility(env.tab);
    108 });
    109 
    110 function checkTree(env, tree) {
    111  return runA11yPanelTests(
    112    [
    113      {
    114        expected: {
    115          tree,
    116        },
    117      },
    118    ],
    119    env
    120  );
    121 }