summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/invalidation/input-pseudo-classes-in-has.html
blob: a9a1d9f5ee7e0b10ee6ccd01242de8e000918dbb (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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<meta charset="utf-8" />
<title>CSS Selectors Invalidation: input pseudo classes in :has() argument</title>
<link rel="author" title="Byungwoo Lee" href="blee@igalia.com">
<link rel="help" href="https://drafts.csswg.org/selectors/#relational">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  .ancestor:has(#checkme:checked) { color: green }
  .ancestor:has(#checkme:indeterminate) { color: yellowgreen }
  .ancestor:has(#checkme:disabled) { color: blue }
  .ancestor:has(#textinput:read-only) { color: skyblue }
  .ancestor:has(#textinput:placeholder-shown) { color: navy }
  .ancestor:has(#radioinput:default) { color: lightblue }
  .ancestor:has(#textinput:valid) { color: lightgreen }
  .ancestor:has(#numberinput:out-of-range) { color: darkgreen }
  .ancestor:has(#numberinput:required) { color: pink }
  .ancestor:has(#progress:indeterminate) { color: orange }
  .ancestor:has(#checkboxinput:default) { color: purple; }
</style>
<div id=subject class=ancestor>
  <input type="checkbox" name="my-checkbox" id="checkme">
  <label for="checkme">Check me!</label>
  <input type="text" id="textinput" required>
  <input id="radioinput" checked>
  <input id="numberinput" type="number" min="1" max="10" value="5">
  <progress id="progress" value="50" max="100"></progress>
  <input id="checkboxinput" type="checkbox">
</div>
<script>
  test(function() {
    let input = null;
    this.add_cleanup(() => {
      if (input) {
        // Need to put the input back for the rest of the tests.
        subject.prepend(input);
      }
      checkme.checked = false;
    });
    checkme.checked = false;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    checkme.checked = true;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 128, 0)",
                  "ancestor should be green");
    checkme.indeterminate = true;
    assert_equals(getComputedStyle(subject).color, "rgb(154, 205, 50)",
                  "ancestor should be yellowgreen");
    input = checkme;
    checkme.remove();
    input.indeterminate = false;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");

    subject.prepend(input);
    input = null;
    checkme.checked = true;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 128, 0)",
                  "ancestor should be green");
  }, ":checked & :indeterminate invalidation on <input>");

  test(function() {
    this.add_cleanup(() => {
      progress.setAttribute("value", "50");
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    progress.removeAttribute("value");
    assert_equals(getComputedStyle(subject).color, "rgb(255, 165, 0)",
                  "ancestor should be orange");
  }, ":indeterminate invalidation on <progress>");

  test(function() {
    this.add_cleanup(() => {
      checkme.disabled = false;
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    checkme.disabled = true;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 255)",
                  "ancestor should be blue");
  }, ":disabled invalidation");

  test(function() {
    this.add_cleanup(() => {
      textinput.readOnly = false;
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    textinput.readOnly = true;
    assert_equals(getComputedStyle(subject).color, "rgb(135, 206, 235)",
                  "ancestor should be skyblue");
  }, ":read-only invalidation");

  test(function() {
    this.add_cleanup(() => {
      textinput.value = "";
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    textinput.value = "text input";
    assert_equals(getComputedStyle(subject).color, "rgb(144, 238, 144)",
                  "ancestor should be lightgreen");
  }, ":valid invalidation");

  test(function() {
    this.add_cleanup(() => {
      radioinput.removeAttribute("type");
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    radioinput.type = 'radio';
    assert_equals(getComputedStyle(subject).color, "rgb(173, 216, 230)",
                  "ancestor should be lightblue");
  }, ":default invalidation with input[type=radio]");

  test(function() {
    this.add_cleanup(() => {
      numberinput.required = false;
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    numberinput.required = true;
    assert_equals(getComputedStyle(subject).color, "rgb(255, 192, 203)",
                  "ancestor should be pink");
  }, ":required invalidation");

  test(function() {
    this.add_cleanup(() => {
      numberinput.value = 5;
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    numberinput.value = 12;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 100, 0)",
                  "ancestor should be darkgreen");
  }, ":out-of-range invalidation");

  test(function() {
    this.add_cleanup(() => {
      textinput.removeAttribute("placeholder");
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    textinput.placeholder = 'placeholder text';
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 128)",
                  "ancestor should be navy");
  }, ":placeholder-shown invalidation");

  test(function() {
    this.add_cleanup(() => {
      checkboxinput.checked = false;
      checkboxinput.removeAttribute("checked");
    });
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
    checkboxinput.checked = true;
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should still be black");
    checkboxinput.setAttribute("checked", "");
    assert_equals(getComputedStyle(subject).color, "rgb(128, 0, 128)",
                  "ancestor should be purple");
    checkboxinput.checked = false;
    assert_equals(getComputedStyle(subject).color, "rgb(128, 0, 128)",
                  "ancestor should still be purple");
    checkboxinput.removeAttribute("checked");
    assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)",
                  "ancestor should be black");
  }, ":default invalidation with input[type=checkbox] and assignment to .checked");
</script>