Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
 - This WPT test may be referenced by the following Test IDs:
            
- /css/css-pseudo/highlight-cascade/highlight-pseudos-computed-search-text.tentative.html - WPT Dashboard Interop Dashboard
 
 
<!doctype html>
<meta charset="utf-8">
<title>CSS Pseudo-Elements Test: ::search-text getComputedStyle</title>
<link rel="author" name="Delan Azabani" href="mailto:dazabani@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  #target::search-text {
    background-color: blue;
    color: lime;
  }
  #target::search-text:not(:current) {
    background-color: green;
  }
  #target::search-text:current {
    /* FAIL if this matches */
    background-color: red;
  }
</style>
<div id="target"></div>
<script>
  for (const pseudo of ["::search-text"]) {
    test(() => {
      let style = getComputedStyle(target, pseudo);
      assert_equals(style.backgroundColor, "rgb(0, 128, 0)", "Background color is green.");
      assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");
    }, `getComputedStyle() for ${pseudo}`);
    for (illFormedPseudo of [`${pseudo}:`, `${pseudo})`, `${pseudo}(`, `${pseudo}(foo)`, `${pseudo}()`, `:${pseudo}`, `${pseudo}.`]) {
      test(() => {
        let style = getComputedStyle(target, illFormedPseudo);
        let defaultStyle = getComputedStyle(target);
        assert_equals(style.backgroundColor, "");
        assert_equals(style.color,  "");
      }, `getComputedStyle() for ${illFormedPseudo} should return an empty CSSStyleDeclaration`);
    }
  }
</script>