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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=514437
https://bugzilla.mozilla.org/show_bug.cgi?id=633913
-->
<head>
<title>Test for progress element content and layout</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=514437">Mozilla Bug 514437</a>
and
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633913">Mozilla Bug 633913</a>
<p id="display"></p>
<iframe name="submit_frame" style="visibility: hidden;"></iframe>
<div id="content" style="visibility: hidden;">
<form id='f' method='get' target='submit_frame' action='foo'>
<progress id='p'></progress>
</form>
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.expectAssertions(0, 1);
/** Test for progress element content and layout **/
function checkFormIDLAttribute(aElement)
{
is("form" in aElement, false, "<progress> shouldn't have a form attribute");
}
function checkAttribute(aElement, aAttribute, aNewValue, aExpectedValueForIDL)
{
var expectedValueForIDL = aNewValue;
var expectedValueForContent = String(aNewValue);
if (aExpectedValueForIDL !== undefined) {
expectedValueForIDL = aExpectedValueForIDL;
}
if (aNewValue != null) {
aElement.setAttribute(aAttribute, aNewValue);
is(aElement.getAttribute(aAttribute), expectedValueForContent,
aAttribute + " content attribute should be " + expectedValueForContent);
is(aElement[aAttribute], expectedValueForIDL,
aAttribute + " IDL attribute should be " + expectedValueForIDL);
if (parseFloat(aNewValue) == aNewValue) {
aElement[aAttribute] = aNewValue;
is(aElement.getAttribute(aAttribute), expectedValueForContent,
aAttribute + " content attribute should be " + expectedValueForContent);
is(aElement[aAttribute], parseFloat(expectedValueForIDL),
aAttribute + " IDL attribute should be " + parseFloat(expectedValueForIDL));
}
} else {
aElement.removeAttribute(aAttribute);
is(aElement.getAttribute(aAttribute), null,
aAttribute + " content attribute should be null");
is(aElement[aAttribute], expectedValueForIDL,
aAttribute + " IDL attribute should be " + expectedValueForIDL);
}
}
function checkValueAttribute()
{
var tests = [
// value has to be a valid float, its default value is 0.0 otherwise.
[ null, 0.0 ],
[ 'fo', 0.0 ],
// If value < 0.0, 0.0 is used instead.
[ -1.0, 0.0 ],
// If value >= max, max is used instead (max default value is 1.0).
[ 2.0, 1.0 ],
[ 1.0, 0.5, 0.5 ],
[ 10.0, 5.0, 5.0 ],
[ 13.37, 13.37, 42.0 ],
// Regular reflection.
[ 0.0 ],
[ 0.5 ],
[ 1.0 ],
// Check double-precision value.
[ 0.234567898765432 ],
];
var element = document.createElement('progress');
for (var test of tests) {
if (test[2]) {
element.setAttribute('max', test[2]);
}
checkAttribute(element, 'value', test[0], test[1]);
element.removeAttribute('max');
}
}
function checkMaxAttribute()
{
var tests = [
// max default value is 1.0.
[ null, 1.0 ],
// If value <= 0.0, 1.0 is used instead.
[ 0.0, 1.0 ],
[ -1.0, 1.0 ],
// Regular reflection.
[ 0.5 ],
[ 1.0 ],
[ 2.0 ],
// Check double-precision value.
[ 0.234567898765432 ],
];
var element = document.createElement('progress');
for (var test of tests) {
checkAttribute(element, 'max', test[0], test[1]);
}
}
function checkPositionAttribute()
{
function checkPositionValue(aElement, aValue, aMax, aExpected) {
if (aValue != null) {
aElement.setAttribute('value', aValue);
} else {
aElement.removeAttribute('value');
}
if (aMax != null) {
aElement.setAttribute('max', aMax);
} else {
aElement.removeAttribute('max');
}
is(aElement.position, aExpected, "position IDL attribute should be " + aExpected);
}
var tests = [
// value has to be defined (indeterminate state).
[ null, null, -1.0 ],
[ null, 1.0, -1.0 ],
// value has to be defined to a valid float (indeterminate state).
[ 'foo', 1.0, -1.0 ],
// If value < 0.0, 0.0 is used instead.
[ -1.0, 1.0, 0.0 ],
// If value >= max, max is used instead.
[ 2.0, 1.0, 1.0 ],
// If max isn't present, max is set to 1.0.
[ 1.0, null, 1.0 ],
// If max isn't a valid float, max is set to 1.0.
[ 1.0, 'foo', 1.0 ],
// If max isn't > 0, max is set to 1.0.
[ 1.0, -1.0, 1.0 ],
// A few simple and valid values.
[ 0.0, 1.0, 0.0 ],
[ 0.1, 1.0, 0.1/1.0 ],
[ 0.1, 2.0, 0.1/2.0 ],
[ 10, 50, 10/50 ],
// Values implying .position is a double.
[ 1.0, 3.0, 1.0/3.0 ],
[ 0.1, 0.7, 0.1/0.7 ],
];
var element = document.createElement('progress');
for (var test of tests) {
checkPositionValue(element, test[0], test[1], test[2], test[3]);
}
}
function checkIndeterminatePseudoClass()
{
function checkIndeterminate(aElement, aValue, aMax, aIndeterminate) {
if (aValue != null) {
aElement.setAttribute('value', aValue);
} else {
aElement.removeAttribute('value');
}
if (aMax != null) {
aElement.setAttribute('max', aMax);
} else {
aElement.removeAttribute('max');
}
is(aElement.matches("progress:indeterminate"), aIndeterminate,
"<progress> indeterminate state should be " + aIndeterminate);
}
var tests = [
// Indeterminate state: (value is undefined, or not a float)
// value has to be defined (indeterminate state).
[ null, null, true ],
[ null, 1.0, true ],
[ 'foo', 1.0, true ],
// Determined state:
[ -1.0, 1.0, false ],
[ 2.0, 1.0, false ],
[ 1.0, null, false ],
[ 1.0, 'foo', false ],
[ 1.0, -1.0, false ],
[ 0.0, 1.0, false ],
];
var element = document.createElement('progress');
for (var test of tests) {
checkIndeterminate(element, test[0], test[1], test[2]);
}
}
function checkFormListedElement(aElement)
{
is(document.forms[0].elements.length, 0, "the form should have no element");
}
function checkLabelable(aElement)
{
var content = document.getElementById('content');
var label = document.createElement('label');
content.appendChild(label);
label.appendChild(aElement);
is(label.control, aElement, "progress should be labelable");
// Cleaning-up.
content.removeChild(label);
content.appendChild(aElement);
}
function checkNotResetableAndFormSubmission(aElement)
{
// Creating an input element to check the submission worked.
var form = document.forms[0];
var input = document.createElement('input');
input.name = 'a';
input.value = 'tulip';
form.appendChild(input);
// Setting values.
aElement.value = 42.0;
aElement.max = 100.0;
document.getElementsByName('submit_frame')[0].addEventListener("load", function() {
document.getElementsByName('submit_frame')[0].removeEventListener("load", arguments.callee, false);
/**
* All elements values have been set just before the submission.
* The input element value should be in the submit url but the progress
* element value should not appear.
*/
is(frames['submit_frame'].location.href,
'http://mochi.test:8888/tests/dom/html/test/forms/foo?a=tulip',
"The progress element value should not be submitted");
checkNotResetable();
}, false);
form.submit();
}
function checkNotResetable()
{
// Try to reset the form.
var form = document.forms[0];
var element = document.getElementById('p');
element.value = 3.0;
element.max = 42.0;
form.reset();
SimpleTest.executeSoon(function() {
is(element.value, 3.0, "progress.value should not have changed");
is(element.max, 42.0, "progress.max should not have changed");
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
var p = document.getElementById('p');
ok(p instanceof HTMLProgressElement,
"The progress element should be instance of HTMLProgressElement");
is(p.constructor, HTMLProgressElement,
"The progress element constructor should be HTMLProgressElement");
checkFormIDLAttribute(p);
checkValueAttribute();
checkMaxAttribute();
checkPositionAttribute();
checkIndeterminatePseudoClass();
checkFormListedElement(p);
checkLabelable(p);
checkNotResetableAndFormSubmission(p);
</script>
</pre>
</body>
</html>
|