gecko-dev/dom/html/test/forms/test_maxlength_attribute.html

82 строки
2.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=345624
-->
<head>
<title>Test for Bug 345624</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
input, textarea { background-color: rgb(0,0,0) !important; }
:-moz-any(input,textarea):valid { background-color: rgb(0,255,0) !important; }
:-moz-any(input,textarea):invalid { background-color: rgb(255,0,0) !important; }
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345624">Mozilla Bug 345624</a>
<p id="display"></p>
<div id="content" style="display: none">
<input id='i'>
<textarea id='t'></textarea>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 345624 **/
/**
* This test is checking only tooLong related features
* related to constraint validation.
*/
function checkTooLongValidity(element)
{
element.value = "foo";
ok(!element.validity.tooLong,
"Element should not be too long when maxlength is not set");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(0, 255, 0)", ":valid pseudo-class should apply");
element.maxLength = 3;
ok(!element.validity.tooLong,
"Element should not be to long when maxlength = value length");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(0, 255, 0)", ":valid pseudo-class should apply");
element.maxLength = 5;
ok(!element.validity.tooLong,
"Element should not be too long when maxlength > value length");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(0, 255, 0)", ":valid pseudo-class should apply");
ok(element.validity.valid, "Element should be valid");
element.maxLength = 2;
todo(element.validity.tooLong,
"Element should be too long when maxlength < value length");
todo_is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(255, 0, 0)", ":invalid pseudo-class should apply");
todo(!element.validity.valid,
"Element should not be valid when it is too long");
todo_is(element.validationMessage,
"Please shorten this text to 2 characters or less (you are currently using 3 characters).",
"The validation message text is not correct");
todo(!element.checkValidity(), "The element should not be valid");
element.setCustomValidity("custom message");
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(255, 0, 0)", ":invalid pseudo-class should apply");
is(element.validationMessage, "custom message",
"Custom message should be shown instead of too long one");
}
checkTooLongValidity(document.getElementById('i'));
checkTooLongValidity(document.getElementById('t'));
</script>
</pre>
</body>
</html>