File: has-invalidation-first-in-sibling-chain.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (77 lines) | stat: -rw-r--r-- 2,312 bytes parent folder | download | duplicates (4)
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
<!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://drafts.csswg.org/selectors/#relational">
<link rel="help" href="https://bugzilla.mozilla.org/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>