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
213
214
215
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=557087
-->
<head>
<title>Test for Bug 557087</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557087">Mozilla Bug 557087</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 557087 **/
function checkValueMissing(aElement, aExpected)
{
var msg = aExpected ? aElement.tagName + " should suffer from value missing"
: aElement.tagName + " should not suffer from value missing"
is(aElement.validity.valueMissing, aExpected, msg);
}
function checkCandidateForConstraintValidation(aElement, aExpected)
{
var msg = aExpected ? aElement.tagName + " should be candidate for constraint validation"
: aElement.tagName + " should not be candidate for constraint validation"
is(aElement.willValidate, aExpected, msg);
}
function checkDisabledPseudoClass(aElement, aDisabled)
{
var disabledElements = document.querySelectorAll(":disabled");
var found = false;
for (var e of disabledElements) {
if (aElement == e) {
found = true;
break;
}
}
var msg = aDisabled ? aElement.tagName + " should have :disabled applying"
: aElement.tagName + " should not have :disabled applying";
ok(aDisabled ? found : !found, msg);
}
function checkEnabledPseudoClass(aElement, aEnabled)
{
var enabledElements = document.querySelectorAll(":enabled");
var found = false;
for (var e of enabledElements) {
if (aElement == e) {
found = true;
break;
}
}
var msg = aEnabled ? aElement.tagName + " should have :enabled applying"
: aElement.tagName + " should not have :enabled applying";
ok(aEnabled ? found : !found, msg);
}
function checkFocus(aElement, aExpected)
{
aElement.setAttribute('tabindex', 1);
// We use the focus manager so we can test <label>.
var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"]
.getService(SpecialPowers.Ci.nsIFocusManager);
fm.setFocus(aElement, 0);
if (aExpected) {
is(document.activeElement, aElement, "element should be focused");
} else {
isnot(document.activeElement, aElement, "element should not be focused");
}
aElement.blur();
aElement.removeAttribute('tabindex');
}
var elements = [ "input", "button", "select", "textarea", "fieldset", "option",
"optgroup", "label", "output", "object" ];
var testData = {
/* tag name | affected by disabled | test focus | test pseudo-classes | test willValidate */
"INPUT": [ true, true, true, true, true ],
"BUTTON": [ true, true, true, false, false ],
"SELECT": [ true, true, true, true, false ],
"TEXTAREA": [ true, true, true, true, true ],
"FIELDSET": [ true, true, true, false, false ],
"OPTION": [ false, true, true, false, false ],
"OPTGROUP": [ false, true, true, false, false ],
"OBJECT": [ false, true, false, false, false ],
"LABEL": [ false, true, false, false, false ],
"OUTPUT": [ false, true, false, false, false ],
};
/**
* For not candidate elements without disabled attribute and not submittable,
* we only have to check that focus and click works even inside a disabled
* fieldset.
*/
function checkElement(aElement, aDisabled)
{
var data = testData[aElement.tagName];
var expected = data[0] ? !aDisabled : true;
if (data[1]) {
checkFocus(aElement, expected);
}
if (data[2]) {
checkEnabledPseudoClass(aElement, data[0] ? !aDisabled : true);
checkDisabledPseudoClass(aElement, data[0] ? aDisabled : false);
}
if (data[3]) {
checkCandidateForConstraintValidation(aElement, expected);
}
if (data[4]) {
checkValueMissing(aElement, expected);
}
}
var fieldset1 = document.createElement("fieldset");
var fieldset2 = document.createElement("fieldset");
var legendA = document.createElement("legend");
var legendB = document.createElement("legend");
var content = document.getElementById('content');
content.appendChild(fieldset1);
fieldset1.appendChild(fieldset2);
fieldset2.disabled = true;
for (var data of elements) {
var element = document.createElement(data);
if (data[4]) {
element.required = true;
}
fieldset1.disabled = false;
fieldset2.appendChild(element);
checkElement(element, fieldset2.disabled);
// Make sure changes are correctly managed.
fieldset2.disabled = false;
checkElement(element, fieldset2.disabled);
fieldset2.disabled = true;
checkElement(element, fieldset2.disabled);
// Make sure if a fieldset which is not the first fieldset is disabled, the
// elements inside the second fielset are disabled.
fieldset2.disabled = false;
fieldset1.disabled = true;
checkElement(element, fieldset1.disabled);
// Make sure the state change of the inner fieldset will not confuse.
fieldset2.disabled = true;
fieldset2.disabled = false;
checkElement(element, fieldset1.disabled);
/* legend tests */
// elements in the first legend of a disabled fieldset should not be disabled.
fieldset2.disabled = true;
fieldset1.disabled = false;
legendA.appendChild(element);
fieldset2.appendChild(legendA);
checkElement(element, false);
// elements in the second legend should be disabled
fieldset2.insertBefore(legendB, legendA);
checkElement(element, fieldset2.disabled);
fieldset2.removeChild(legendB);
// Elements in the first legend of a fieldset disabled by another fieldset
// should be disabled.
fieldset1.disabled = true;
checkElement(element, fieldset1.disabled);
// Elements inside a fieldset inside the first legend of a disabled fieldset
// should not be diasbled.
fieldset2.disabled = false;
fieldset1.appendChild(legendA);
legendA.appendChild(fieldset2);
fieldset2.appendChild(element);
checkElement(element, false);
// Elements inside the first legend of a disabled fieldset inside the first
// legend of a disabled fieldset should not be disabled.
fieldset2.disabled = false;
fieldset2.appendChild(legendB);
legendB.appendChild(element);
checkElement(element, false);
fieldset2.removeChild(legendB);
fieldset1.appendChild(fieldset2);
element.parentNode.removeChild(element);
}
</script>
</pre>
</body>
</html>
|