2010-08-21 22:51:38 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=561634
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 561634</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=561634">Mozilla Bug 561634</a>
|
|
|
|
<p id="display"></p>
|
2011-06-21 20:50:12 +04:00
|
|
|
<div id="content" style="display: none;">
|
2010-08-21 22:51:38 +04:00
|
|
|
<form>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 561634 **/
|
|
|
|
|
|
|
|
function checkEmptyForm()
|
|
|
|
{
|
|
|
|
ok(document.forms[0].checkValidity(), "An empty form is valid");
|
|
|
|
}
|
|
|
|
|
2010-11-23 14:19:49 +03:00
|
|
|
function checkBarredFromConstraintValidation()
|
2010-08-21 22:51:38 +04:00
|
|
|
{
|
|
|
|
var f = document.forms[0];
|
|
|
|
var fs = document.createElement('fieldset');
|
2010-11-23 14:19:49 +03:00
|
|
|
var i = document.createElement('input');
|
2010-08-21 22:51:38 +04:00
|
|
|
|
|
|
|
f.appendChild(fs);
|
|
|
|
i.type = 'hidden';
|
|
|
|
f.appendChild(i);
|
|
|
|
|
2010-11-23 14:19:49 +03:00
|
|
|
fs.setCustomValidity("foo");
|
2010-08-21 22:51:38 +04:00
|
|
|
i.setCustomValidity("foo");
|
2010-11-23 14:19:49 +03:00
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
ok(f.checkValidity(),
|
2010-11-23 14:19:49 +03:00
|
|
|
"A form with invalid element barred from constraint validation should be valid");
|
2010-08-21 22:51:38 +04:00
|
|
|
|
|
|
|
f.removeChild(i);
|
2010-11-23 14:19:49 +03:00
|
|
|
f.removeChild(fs);
|
2010-08-21 22:51:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkValid()
|
|
|
|
{
|
|
|
|
var f = document.forms[0];
|
|
|
|
var i = document.createElement('input');
|
|
|
|
f.appendChild(i);
|
|
|
|
|
|
|
|
ok(f.checkValidity(), "A form with valid elements is valid");
|
|
|
|
|
|
|
|
f.removeChild(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkInvalid()
|
|
|
|
{
|
|
|
|
var f = document.forms[0];
|
|
|
|
var i = document.createElement('input');
|
|
|
|
f.appendChild(i);
|
|
|
|
|
|
|
|
i.setCustomValidity("foo");
|
|
|
|
ok(!f.checkValidity(), "A form with invalid elements is invalid");
|
|
|
|
|
|
|
|
var i2 = document.createElement('input');
|
|
|
|
f.appendChild(i2);
|
|
|
|
ok(!f.checkValidity(),
|
|
|
|
"A form with at least one invalid element is invalid");
|
|
|
|
|
|
|
|
f.removeChild(i2);
|
|
|
|
f.removeChild(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkInvalidEvent()
|
|
|
|
{
|
|
|
|
var f = document.forms[0];
|
|
|
|
var i = document.createElement('input');
|
|
|
|
f.appendChild(i);
|
|
|
|
var i2 = document.createElement('input');
|
|
|
|
f.appendChild(i2);
|
|
|
|
|
|
|
|
i.setCustomValidity("foo");
|
|
|
|
|
|
|
|
var invalidEventForInvalidElement = false;
|
|
|
|
var invalidEventForValidElement = false;
|
|
|
|
|
|
|
|
i.addEventListener("invalid", function (e) {
|
|
|
|
invalidEventForInvalidElement = true;
|
|
|
|
ok(e.cancelable, "invalid event should be cancelable");
|
|
|
|
ok(!e.bubbles, "invalid event should not bubble");
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2010-08-21 22:51:38 +04:00
|
|
|
|
|
|
|
i2.addEventListener("invalid", function (e) {
|
|
|
|
invalidEventForValidElement = true;
|
2017-01-17 13:50:25 +03:00
|
|
|
});
|
2010-08-21 22:51:38 +04:00
|
|
|
|
|
|
|
f.checkValidity();
|
|
|
|
|
2011-06-21 20:50:12 +04:00
|
|
|
setTimeout(function() {
|
2010-08-21 22:51:38 +04:00
|
|
|
ok(invalidEventForInvalidElement,
|
|
|
|
"invalid event should be fired on invalid elements");
|
|
|
|
ok(!invalidEventForValidElement,
|
|
|
|
"invalid event should not be fired on valid elements");
|
|
|
|
|
2011-06-21 20:50:12 +04:00
|
|
|
f.removeChild(i2);
|
|
|
|
f.removeChild(i);
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}, 0);
|
2010-08-21 22:51:38 +04:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:50:12 +04:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-08-21 22:51:38 +04:00
|
|
|
checkEmptyForm();
|
|
|
|
checkBarredFromConstraintValidation();
|
|
|
|
checkValid();
|
|
|
|
checkInvalid();
|
2011-06-21 20:50:12 +04:00
|
|
|
checkInvalidEvent(); // will call finish().
|
2010-08-21 22:51:38 +04:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|