/** Test for progress element content and layout **/
function checkFormIDLAttribute(aElement)
{
is("form" in aElement, false, ");
}
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]);
}
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');
}
function checkNotResetableAndFormSubmission(aElement)
{
// Creating an input element to check the submission worked. varform = document.forms[0]; varinput = document.createElement('input');
document.getElementsByName('submit_frame')[0].addEventListener("load", function() {
is(frames.submit_frame.location.href,
`${location.origin}/tests/dom/html/test/forms/foo?a=tulip`, "The progress element value should not be submitted");
checkNotResetable();
}, {once: true});
form.submit();
}
function checkNotResetable()
{
// Try to reset the form. varform = 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>
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.