File: radio-disconnected-group-owner.html

package info (click to toggle)
thunderbird 1%3A140.3.1esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,608,628 kB
  • sloc: cpp: 7,671,698; javascript: 5,901,131; ansic: 3,898,955; python: 1,413,270; xml: 653,997; asm: 462,284; java: 180,948; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (212 lines) | stat: -rw-r--r-- 9,011 bytes parent folder | download | duplicates (7)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>

<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <meta charset="utf-8">
  <title>Test for validity of disconnected radio buttons</title>
</head>

<body>
  <input type="radio" name="group" id="radio1" required />
  <input type="radio" name="group" id="radio2" checked />
  <form>
    <input type="radio" name="group" id="radio3" required />
    <input type="radio" name="group" id="radio4" checked />
  </form>

  <script>
    test(() => {
      const radio1 = document.getElementById("radio1");
      const radio2 = document.getElementById("radio2");
      assert_false(radio1.validity.valueMissing, "Element should not suffer from value missing");

      radio2.remove();
      assert_true(radio1.validity.valueMissing, "Element should suffer from value missing");

      radio1.checked = true;
      radio2.required = true;
      assert_false(radio2.validity.valueMissing, "Element should not suffer from value missing");

      const radio3 = document.getElementById("radio3");
      const radio4 = document.getElementById("radio4");
      assert_false(radio3.validity.valueMissing, "Element should not suffer from value missing");

      radio4.remove();
      assert_true(radio3.validity.valueMissing, "Element should suffer from value missing");

      radio3.checked = true;
      assert_true(radio4.checked, "Element should remain checked");
      assert_false(radio3.validity.valueMissing, "Element should not suffer from value missing");

      document.querySelector("form").appendChild(radio2);
      assert_false(radio3.checked, "Element should be unchecked");
      assert_false(radio1.validity.valueMissing, "Element should not suffer from value missing");
    }, "Removed elements are moved into separate radio groups.");

    test(() => {
      const container = document.createElement("div");
      const radio = document.createElement("input");
      radio.type = "radio";
      radio.name = "group";
      radio.id = "radio5";
      radio.required = true;
      container.appendChild(radio);
      assert_true(radio.validity.valueMissing, "Element should suffer from value missing");

      const outerContainer = document.createElement("div");
      const outerRadio = document.createElement("input");
      outerRadio.type = "radio";
      outerRadio.name = "group";
      outerRadio.id = "radio6";
      outerRadio.checked = true;
      outerContainer.appendChild(outerRadio);
      outerContainer.appendChild(container);
      assert_false(radio.validity.valueMissing, "Element should not suffer from value missing");

      container.remove();
      assert_true(radio.validity.valueMissing, "Element should suffer from value missing");
    }, "Disconnected radio buttons should be contained by their tree root.");

    test(() => {
      const radioParent = document.createElement("input");
      radioParent.type = "radio";
      radioParent.name = "group";
      radioParent.id = "radio-parent";
      radioParent.required = true;
      assert_true(radioParent.validity.valueMissing, "Element should suffer from value missing");

      const radioChild = document.createElement("input");
      radioChild.type = "radio";
      radioChild.name = "group";
      radioChild.id = "radio-child";
      radioChild.checked = true;
      assert_false(radioChild.validity.valueMissing, "Element should not suffer from value missing");

      radioParent.appendChild(radioChild);
      assert_false(radioChild.validity.valueMissing, "Element should not suffer from value missing");
      assert_false(radioParent.validity.valueMissing, "Element should not suffer from value missing");

      radioParent.checked = true;
      assert_false(radioChild.checked, "Element should no longer be checked");
    }, "Disconnected radio buttons can serve as radio group containers.");

    test(() => {
      const shadowHost = document.createElement("div");
      const root = shadowHost.attachShadow({mode: "open"});
      const container = document.createElement("div");
      container.appendChild(shadowHost);

      const radio1 = document.createElement("input");
      radio1.type = "radio";
      radio1.name = "group";
      radio1.required = true;
      const radio2 = document.createElement("input");
      radio2.type = "radio";
      radio2.name = "group";
      radio2.checked = true;
      const radio3 = document.createElement("input");
      radio3.type = "radio";
      radio3.name = "group";
      radio3.required = true;

      root.appendChild(radio1);
      container.appendChild(radio3);
      assert_true(radio1.validity.valueMissing, "Element should suffer from value missing");
      assert_true(radio3.validity.valueMissing, "Element should suffer from value missing");

      root.appendChild(radio2);
      assert_false(radio1.validity.valueMissing, "Element should not suffer from value missing");
      assert_true(radio3.validity.valueMissing, "Element should suffer from value missing");
    }, "Shadow roots in disconnected trees can serve as radio group containers.");

    test(() => {
      const svgRoot = document.createElementNS("http://www.w3.org/2000/svg", "g")
      const htmlContainer = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
      svgRoot.appendChild(htmlContainer);

      const radio1 = document.createElement("input");
      radio1.type = "radio";
      radio1.name = "group";
      radio1.required = true;
      const radio2 = document.createElement("input");
      radio2.type = "radio";
      radio2.name = "group";
      radio2.checked = true;

      htmlContainer.appendChild(radio1);
      assert_true(radio1.validity.valueMissing, "Element should suffer from value missing");
      htmlContainer.appendChild(radio2);
      assert_false(radio1.validity.valueMissing, "Element should not suffer from value missing");
      radio1.checked = true;
      assert_false(radio2.checked, "Element should no longer be checked");
    }, "Non-HTML elements in disconnected trees can serve as radio group containers.");

    test(() => {
      const fragment = document.createDocumentFragment();

      const radio1 = document.createElement("input");
      radio1.type = "radio";
      radio1.name = "group";
      radio1.required = true;
      const radio2 = document.createElement("input");
      radio2.type = "radio";
      radio2.name = "group";
      radio2.checked = true;

      fragment.appendChild(radio1);
      assert_true(radio1.validity.valueMissing, "Element should suffer from value missing");
      fragment.appendChild(radio2);
      assert_false(radio1.validity.valueMissing, "Element should not suffer from value missing");
      radio1.checked = true;
      assert_false(radio2.checked, "Element should no longer be checked");
    }, "Disconnected document fragments can serve as radio group containers.");

    test(() => {
      const container = document.createElement("div");
      const radio1 = document.createElement("input");
      radio1.type = "radio";
      radio1.name = "group";
      radio1.checked = true;
      const radio2 = document.createElement("input");
      radio2.type = "radio";
      radio2.name = "group";
      radio2.checked = true;

      container.appendChild(radio1);
      assert_true(radio1.checked, "radio1 should be checked");
      container.appendChild(radio2);
      assert_true(radio1.checked, "radio1 should still be checked");
      assert_true(radio2.checked, "radio2 should be checked, too");

      container.innerHTML = `<input type="radio" name="group" checked><input type="radio" name="group" checked>`;
      assert_true(container.children[0].checked, "first radio child should be checked");
      assert_true(container.children[1].checked, "second radio child should be checked");
    }, "Appending input radio input into a disconnect tree don't update the other radio inputs in the same radio group.");

    test(() => {
      const form = document.createElement("form");
      const radio1 = document.createElement("input");
      radio1.type = "radio";
      radio1.name = "group";
      radio1.checked = true;
      const radio2 = document.createElement("input");
      radio2.type = "radio";
      radio2.name = "group";
      radio2.checked = true;

      form.appendChild(radio1);
      assert_true(radio1.checked, "radio1 should be checked");
      form.appendChild(radio2);
      assert_false(radio1.checked, "radio1 should no longer be checked");
      assert_true(radio2.checked, "radio2 should be checked");

      form.innerHTML = `<input type="radio" name="group" checked><input type="radio" name="group" checked>`;
      assert_false(form.children[0].checked, "first radio child should no longer be checked");
      assert_true(form.children[1].checked, "second radio child should be checked");
    }, "Appending input radio input into a disconnect form should update the other radio inputs in the same radio group.");
  </script>
</body>

</html>