summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/invalidation/is-where-pseudo-containing-hard-pseudo.html
blob: 416aacca8c0d0085f0e574852ed6f0cc4cdc9ca0 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<title>CSS Selectors Invalidation: :is and :where selectors containing "hard" selectors</title>
<link rel="author" title="David Shin" href="dshin@mozilla.com">
<link rel="help" href="https://drafts.csswg.org/selectors/#logical-combination">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1874042">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.container {
  color: grey;
}

#subject1:is(.other-match, :has(.descendant)) {
  color: red;
}

#subject1:is(.parent > .other-match, .parent > :has(.descendant)) {
  color: orangered;
}

#subject2:where(.other-match, :has(.descendant)) {
  color: darkred;
}

#subject2:where(.parent > .other-match, .parent > :has(.descendant)) {
  color: pink;
}

#subject3:is(.other-match, :nth-child(1000 of .another-match)) {
  color: green;
}

#subject3:is(.parent > .other-match, .parent > :nth-child(1000 of .another-match)) {
  color: lightgreen;
}

#subject4:where(.other-match, :nth-child(1000 of .another-match)) {
  color: darkgreen;
}

#subject4:where(.parent > .other-match, .parent > :nth-child(1000 of .another-match)) {
  color: yellowgreen;
}
</style>
<div id="par">
  <div id="subject1" class="container"></div>
  <div id="subject2" class="container"></div>
  <div id="subject3" class="container another-match"></div>
  <div id="subject4" class="container another-match"></div>
</div>
<script>
const colors = {
  grey: "rgb(128, 128, 128)",
  red: "rgb(255, 0, 0)",
  orangered: "rgb(255, 69, 0)",
  darkred: "rgb(139, 0, 0)",
  pink: "rgb(255, 192, 203)",
  green: "rgb(0, 128, 0)",
  lightgreen: "rgb(144, 238, 144)",
  darkgreen: "rgb(0, 100, 0)",
  yellowgreen: "rgb(154, 205, 50)"
};

function testClassChange(subject, before, after, afterParent) {
  const cls = "other-match";
  const parentCls = "parent";
  const beforeColor = colors[before];

  test(() => {
    assert_equals(getComputedStyle(subject).color, beforeColor);
  }, subject.id + " initial color is " + before);

  subject.classList.add(cls);
  const afterColor = colors[after];
  test(() => {
    assert_equals(getComputedStyle(subject).color, afterColor);
  }, subject.id + " is " + after + " when ." + cls + " added");

  par.classList.add(parentCls);
  const afterParentColor = colors[afterParent];
  test(() => {
    assert_equals(getComputedStyle(subject).color, afterParentColor);
  }, subject.id + " is " + afterParent + " when ." + parentCls + " added to parent");

  par.classList.remove(parentCls);
  test(() => {
    assert_equals(getComputedStyle(subject).color, afterColor);
  }, subject.id + " is " + afterParent + " when ." + parentCls + " removed from parent");

  subject.classList.remove(cls);
  test(() => {
    assert_equals(getComputedStyle(subject).color, beforeColor);
  }, subject.id + " is " + after + " when ." + cls + " removed");
}

testClassChange(subject1, "grey", "red", "orangered");
testClassChange(subject2, "grey", "darkred", "pink");
testClassChange(subject3, "grey", "green", "lightgreen");
testClassChange(subject4, "grey", "darkgreen", "yellowgreen");
</script>