tor-browser

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

highlight-pseudos-computed.html (2021B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle</title>
      4 <link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <style>
      8  #target::selection {
      9    background-color: green;
     10    color: lime;
     11  }
     12  #target::target-text {
     13    background-color: green;
     14    color: lime;
     15  }
     16  #target::spelling-error {
     17    background-color: green;
     18    color: lime;
     19  }
     20  #target::grammar-error {
     21    background-color: green;
     22    color: lime;
     23  }
     24  #target::highlight(foo) {
     25    background-color: green;
     26    color: lime;
     27  }
     28  #target::highlight(bar) {
     29    background-color: blue;
     30    color: yellow;
     31  }
     32 </style>
     33 <div id="target"></div>
     34 <script>
     35  for (const pseudo of ["::selection", "::target-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {
     36    test(() => {
     37      let style = getComputedStyle(target, pseudo);
     38      assert_equals(style.backgroundColor, "rgb(0, 128, 0)", "Background color is green.");
     39      assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");
     40    }, `getComputedStyle() for ${pseudo}`);
     41 
     42    for (illFormedPseudo of [`${pseudo}:`, `${pseudo})`, `${pseudo}(`, `${pseudo}(foo)`, `${pseudo}()`, `:${pseudo}`, `${pseudo}.`]) {
     43      test(() => {
     44        let style = getComputedStyle(target, illFormedPseudo);
     45        let defaultStyle = getComputedStyle(target);
     46        assert_equals(style.backgroundColor, "");
     47        assert_equals(style.color,  "");
     48      }, `getComputedStyle() for ${illFormedPseudo} should return an empty CSSStyleDeclaration`);
     49    }
     50  }
     51 
     52  const pseudo = "::highlight(bar)";
     53  test(() => {
     54    let style = getComputedStyle(target, pseudo);
     55    assert_equals(style.backgroundColor, "rgb(0, 0, 255)", "Background color is blue.");
     56    assert_equals(style.color, "rgb(255, 255, 0)", "Color is yellow.");
     57  }, `Different getComputedStyle() for ${pseudo} and same element`);
     58 </script>