summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-highlight-api/painting/custom-highlight-painting-overlapping-highlights-002.html
blob: 2dda273abfe8dfc17be2defec60340a85ac5ac4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<meta charset="UTF-8">
<title>CSS Highlight API Test: Overlapping Highlights</title>
<link rel="help" href="https://drafts.csswg.org/css-highlight-api-1/">
<link rel="match" href="custom-highlight-painting-overlapping-highlights-002-ref.html">
<meta name="assert" value="UAs must not define any styles for custom highlight pseudo-elements in the default UA stylesheet.">
<style>
  div {
      font-size: 3em;
      font-weight: bolder;
  }
  #affected1::highlight(highlight1) {
    color: green;
    background-color: rgb(0, 255, 0, 0.5);
  }
  #affected2::highlight(highlight2) {
    color: red;
    background-color: rgba(100, 0, 100, 0.5);
  }
</style>
<body><div><span id="affected1">Green on lime.</span><span id="affected2">Red on maroon.</span></div>
<script>
  /*
    This test is meant to verify that:
      - UAs must not define any styles for custom highlight pseudo-elements in
      the default UA stylesheet.
      - UAs do not paint unstyled custom highlights.

    In this test, highlight1 has higher priority, so it is painted over
    highlight2. This includes painting for span#affected2, where there is no CSS
    rule for highlight1. But since unstyled custom highlights are not painted,
    span#affected2 is still painted with the styles for highlight2.

    See https://drafts.csswg.org/css-highlight-api-1/#default-styles
  */

  const div = document.querySelector("div");

  let r = new Range();
  r.setStart(div, 0);
  r.setEnd(div, 2);
  let r2 = new Range();
  r2.setStart(div, 0);
  r2.setEnd(div, 2);

  let h = new Highlight(r);
  h.priority = 3;
  let h2 = new Highlight(r2);
  h2.priority = 2;

  CSS.highlights.set("highlight1", h);
  CSS.highlights.set("highlight2", h2);
</script>