-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathhas-invalidation-first-in-sibling-chain.html
More file actions
77 lines (69 loc) · 2.26 KB
/
has-invalidation-first-in-sibling-chain.html
File metadata and controls
77 lines (69 loc) · 2.26 KB
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selector Invalidation: Invalidate :has() as a result of first DOM element mutation in sibling chain</title>
<link rel="author" title="David Shin" href="mailto:dshin@mozilla.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://un5n798jx6qx6j0rmf2verhh.julianrbryant.com/selectors/#relational">
<link rel="help" href="https://un5h208565ak8emkwgjjkgb49yug.julianrbryant.com/show_bug.cgi?id=1974022">
<style>
div, main { color: grey }
#subject1:has(.item ~ .item + .item) { color: red; }
#subject2:has(.item + .item + .item) { color: orangered; }
#subject3:has(.item .item ~ .item + .item) { color: green; }
#subject4:has(.item .item + .item + .item) { color: lightgreen; }
</style>
<main id=main>
<div id=subject1>
<div class=item></div>
<div class=item></div>
</div>
<div id=subject2>
<div class=item></div>
<div class=item></div>
</div>
<div id=subject3>
<div class=item>
<div class=item></div>
<div class=item></div>
</div>
</div>
<div id=subject4>
<div class=item>
<div class=item></div>
<div class=item></div>
</div>
</div>
</main>
<script>
const grey = 'rgb(128, 128, 128)';
const red = 'rgb(255, 0, 0)';
const orangered = 'rgb(255, 69, 0)';
const green = 'rgb(0, 128, 0)';
const lightgreen = 'rgb(144, 238, 144)';
function newItem() {
const d = document.createElement('div');
d.classList.add('item');
return d;
}
function testColors(test_name, subject, subject_color) {
test(function() {
assert_equals(getComputedStyle(subject).color, subject_color);
}, test_name);
}
const tests = [
{ subject: subject1, prependAt: subject1, color: red },
{ subject: subject2, prependAt: subject2, color: orangered },
{ subject: subject3, prependAt: subject3.firstElementChild, color: green },
{ subject: subject4, prependAt: subject4.firstElementChild, color: lightgreen },
]
for (t of tests) {
const id = t.subject.id;
testColors(`${id} Initial color`, t.subject, grey);
const item = newItem();
t.prependAt.prepend(item);
testColors(`#${id} invalidated after adding first sibling`, t.subject, t.color);
item.remove();
testColors(`#${id} invalidated after removing first sibling`, t.subject, grey);
}
</script>