File: attribute-or-elemental-selectors-in-has.html

package info (click to toggle)
firefox-esr 140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,539,276 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,918; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (149 lines) | stat: -rw-r--r-- 5,556 bytes parent folder | download | duplicates (16)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selectors Invalidation: :has() invalidation basic</title>
<link rel="author" title="Byungwoo Lee" href="mailto:blee@igalia.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
<style>
div, main { color: grey }
.subject:has(> .child) { color: red }
.subject:has(.descendant) { color: green }
.subject:has([attrname=descendant]) { color: blue }
.subject:has(#div_descendant) { color: yellow }
.subject:has(descendant) { color: yellowgreen }
</style>
<main id=main>
  <div id=div_subject class="subject">
    <div id=div_child>
      <div id=div_grandchild></div>
    </div>
  </div>
</main>
<script>
  let grey = 'rgb(128, 128, 128)';
  let red = 'rgb(255, 0, 0)';
  let green = 'rgb(0, 128, 0)';
  let blue = 'rgb(0, 0, 255)';
  let yellow = 'rgb(255, 255, 0)';
  let yellowgreen = 'rgb(154, 205, 50)';

  function test_div(test_name, el, color) {
    test(function() {
      assert_equals(getComputedStyle(el).color, color);
    }, test_name + ': div#' + el.id + '.color');
  }

  test_div('initial_color', div_subject, grey);
  test_div('initial_color', div_child, grey);
  test_div('initial_color', div_grandchild, grey);

  div_child.classList.add('child');
  test_div('add .child to #div_child', div_subject, red);
  div_child.classList.remove('child');
  test_div('remove .child from #div_child', div_subject, grey);

  div_grandchild.classList.add('child');
  test_div('add .child to #div_grandchild', div_subject, grey);
  div_grandchild.classList.remove('child');
  test_div('remove .child from #div_grandchild', div_subject, grey);

  div_child.classList.add('descendant');
  test_div('add .descendant to #div_child', div_subject, green);
  div_child.classList.remove('descendant');
  test_div('remove .descendant from #div_child', div_subject, grey);

  div_grandchild.classList.add('descendant');
  test_div('add .descendant to #div_grandchild', div_subject, green);
  div_grandchild.classList.remove('descendant');
  test_div('remove .descendant from #div_grandchild', div_subject, grey);

  div_grandchild.setAttribute('attrname', 'descendant');
  test_div('set descendant to #div_grandchild[attrname]', div_subject, blue);
  div_grandchild.setAttribute('attrname', '');
  test_div('clear #div_grandchild[attrname]', div_subject, grey);

  div_grandchild.id = 'div_descendant';
  test_div('change #div_grandchild to #div_descendant', div_subject, yellow);
  div_descendant.id = 'div_grandchild';
  test_div('change #div_descendant to #div_grandchild', div_subject, grey);

  {
    const descendant = document.createElement('descendant');
    div_subject.appendChild(descendant);
    test_div('add descendant to #div_subject', div_subject, yellowgreen);
    div_subject.removeChild(descendant);
    test_div('remove descendant from #div_subject', div_subject, grey);
  }

  {
    const div = document.createElement('div');
    const descendant = document.createElement('descendant');
    div.appendChild(descendant);
    div_subject.appendChild(div);
    test_div('add "div > descendant" to #div_subject', div_subject, yellowgreen);
    div_subject.removeChild(div);
    test_div('remove "div > descendant" from #div_subject', div_subject, grey);
  }

  {
    const child = document.createElement('div');
    child.classList.add('child');
    div_subject.appendChild(child);
    test_div('add div.child to #div_subject', div_subject, red);
    div_subject.removeChild(child);
    test_div('remove div.child from #div_subject', div_subject, grey);
  }

  {
    const descendant = document.createElement('div');
    descendant.classList.add('descendant');
    const div = document.createElement('div');
    div.appendChild(descendant);
    div_subject.appendChild(div);
    test_div('add "div > div.descendant" to #div_subject', div_subject, green);
    div_subject.removeChild(div);
    test_div('remove "div > div.descendant" from #div_subject', div_subject, grey);
  }

  {
    const child = document.createElement('div');
    child.id = 'div_descendant';
    div_subject.appendChild(child);
    test_div('add div#div_descendant to #div_subject', div_subject, yellow);
    div_subject.removeChild(child);
    test_div('remove div#div_descendant from #div_subject', div_subject, grey);
  }

  {
    const descendant = document.createElement('div');
    descendant.id = 'div_descendant';
    const div = document.createElement('div');
    div.appendChild(descendant);
    div_subject.appendChild(div);
    test_div('add "div#div_descendant" to #div_subject', div_subject, yellow);
    div_subject.removeChild(div);
    test_div('remove "div#div_descendant" from #div_subject', div_subject, grey);
  }

  {
    const child = document.createElement('div');
    child.setAttribute('attrname', 'descendant');
    div_subject.appendChild(child);
    test_div('add div[attrname] to #div_subject', div_subject, blue);
    div_subject.removeChild(child);
    test_div('remove div[attrname] from #div_subject', div_subject, grey);
  }

  {
    const descendant = document.createElement('div');
    descendant.setAttribute('attrname', 'descendant');
    const div = document.createElement('div');
    div.appendChild(descendant);
    div_subject.appendChild(div);
    test_div('add "div > div[attrname]" to #div_subject', div_subject, blue);
    div_subject.removeChild(div);
    test_div('remove "div > div[attrname]" from #div_subject', div_subject, grey);
  }

</script>