tor-browser

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

browser_treeupdate_csscontentvisibility.js (2418B)


      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 /* import-globals-from ../../mochitest/role.js */
      8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
      9 
     10 const snippet = `
     11  <style>
     12    #target {
     13      width: 150px;
     14      height: 150px;
     15      background-color: lightblue;
     16    }
     17    #child {
     18      width: 100px;
     19      height: 100px;
     20      background-color: lightgreen;
     21    }
     22    #content-child {
     23      width: 100px;
     24      height: 100px;
     25      background-color: green;
     26      display: contents;
     27    }
     28    .hidden {
     29      content-visibility: hidden;
     30    }
     31    .auto {
     32      content-visibility: auto;
     33    }
     34    #hidden-subtree-2 {
     35      visibility: hidden;
     36    }
     37  </style>
     38  <div class="hidden" id="target">
     39    <div id="child">A</div>
     40    <div id="content-child">B</div>
     41    <div id="hidden-subtree-1" class="hidden">C</div>
     42    <div id="hidden-subtree-2">D</div>
     43    <div id="shadow-host"></div>
     44  </div>
     45  `;
     46 
     47 async function setContentVisibility(browser, value) {
     48  let mutationPromise = waitForEvent(EVENT_REORDER, "target");
     49 
     50  // Change the value of `content-visibility` property for the target
     51  info(`Setting content-visibility: ${value}`);
     52  await invokeSetAttribute(browser, "target", "class", value);
     53  await mutationPromise;
     54 }
     55 
     56 addAccessibleTask(
     57  snippet,
     58  async function (browser, accDoc) {
     59    const target = findAccessibleChildByID(accDoc, "target");
     60 
     61    info("Initial Accessibility Structure Test");
     62    testAccessibleTree(target, { SECTION: [] });
     63 
     64    await setContentVisibility(browser, "auto");
     65    testAccessibleTree(target, {
     66      SECTION: [
     67        { SECTION: [{ TEXT_LEAF: [] }] } /* child */,
     68        { SECTION: [{ TEXT_LEAF: [] }] } /* content-child */,
     69        { SECTION: [] } /* hidden-subtree-1 */,
     70        { SECTION: [{ SECTION: [{ TEXT_LEAF: [] }] }] } /* shadow-host */,
     71      ],
     72    });
     73 
     74    await setContentVisibility(browser, "hidden");
     75    testAccessibleTree(target, { SECTION: [] });
     76  },
     77  {
     78    iframe: true,
     79    remoteIframe: true,
     80    chrome: true,
     81 
     82    contentSetup: async function contentSetup() {
     83      const host = content.document.querySelector("#shadow-host");
     84      const shadowRoot = host.attachShadow({ mode: "open" });
     85      shadowRoot.innerHTML = "<div id='shadowDiv'>E</div>";
     86    },
     87  }
     88 );