tor-browser

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

test_changes_stylesheet.js (1578B)


      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 getChangesStylesheet() serializes tracked changes from nested CSS rules
      7 // into the expected stylesheet format.
      8 
      9 const {
     10  getChangesStylesheet,
     11 } = require("resource://devtools/client/inspector/changes/selectors/changes.js");
     12 
     13 const { CHANGES_STATE } = require("resource://test/mocks");
     14 
     15 // Wrap multi-line string in backticks to ensure exact check in test, including new lines.
     16 const STYLESHEET_FOR_ANCESTOR = `
     17 /* Inline | http://localhost:5000/at-rules-nested.html */
     18 
     19 @media (min-width: 50em) {
     20  @supports (display: grid) {
     21    body {
     22      /* background-color: royalblue; */
     23      background-color: red;
     24    }
     25  }
     26 }
     27 `;
     28 
     29 // Wrap multi-line string in backticks to ensure exact check in test, including new lines.
     30 const STYLESHEET_FOR_DESCENDANT = `
     31 /* Inline | http://localhost:5000/at-rules-nested.html */
     32 
     33 body {
     34  /* background-color: royalblue; */
     35  background-color: red;
     36 }
     37 `;
     38 
     39 add_test(() => {
     40  info(
     41    "Check stylesheet generated for the first ancestor in the CSS rule tree."
     42  );
     43  equal(
     44    getChangesStylesheet(CHANGES_STATE),
     45    STYLESHEET_FOR_ANCESTOR,
     46    "Stylesheet includes all ancestors."
     47  );
     48 
     49  info(
     50    "Check stylesheet generated for the last descendant in the CSS rule tree."
     51  );
     52  const filter = { sourceIds: ["source1"], ruleIds: ["rule3"] };
     53  equal(
     54    getChangesStylesheet(CHANGES_STATE, filter),
     55    STYLESHEET_FOR_DESCENDANT,
     56    "Stylesheet includes just descendant."
     57  );
     58 
     59  run_next_test();
     60 });