tor-browser

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

browser_computed_shadow_host.js (1900B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const {
      7  PropertyView,
      8 } = require("resource://devtools/client/inspector/computed/computed.js");
      9 
     10 // Test matched selectors for a :host selector in the computed view.
     11 
     12 const SHADOW_DOM = `<style>
     13  :host {
     14    color: red;
     15  }
     16 
     17  .test-span {
     18    color: blue;
     19  }
     20 </style>
     21 <span class="test-span">test</span>`;
     22 
     23 const TEST_PAGE = `
     24  <div id="host"></div>
     25  <script>
     26    const div = document.querySelector("div");
     27    div.attachShadow({ mode: "open" }).innerHTML = \`${SHADOW_DOM}\`;
     28  </script>`;
     29 
     30 const TEST_URI = `https://example.com/document-builder.sjs?html=${encodeURIComponent(
     31  TEST_PAGE
     32 )}`;
     33 
     34 add_task(async function () {
     35  await addTab(TEST_URI);
     36  const { inspector, view } = await openComputedView();
     37 
     38  {
     39    await selectNode("#host", inspector);
     40    const propertyView = await getPropertyViewWithSelectors(view, "color");
     41    const selectors = propertyView.matchedSelectors.map(s => s.selector);
     42    Assert.deepEqual(
     43      selectors,
     44      [":host", ":root"],
     45      "host has the expected selectors for color"
     46    );
     47  }
     48 
     49  {
     50    const nodeFront = await getNodeFrontInShadowDom(
     51      ".test-span",
     52      "#host",
     53      inspector
     54    );
     55    await selectNode(nodeFront, inspector);
     56    const propertyView = await getPropertyViewWithSelectors(view, "color");
     57    const selectors = propertyView.matchedSelectors.map(s => s.selector);
     58    Assert.deepEqual(
     59      selectors,
     60      [".test-span", ":host", ":root"],
     61      "shadow host child has the expected selectors for color"
     62    );
     63  }
     64 });
     65 
     66 async function getPropertyViewWithSelectors(view, property) {
     67  const propertyView = new PropertyView(view, property);
     68  propertyView.createListItemElement();
     69  propertyView.matchedExpanded = true;
     70 
     71  await propertyView.refreshMatchedSelectors();
     72 
     73  return propertyView;
     74 }