2010-01-18 18:53:59 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=535043
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 535043</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/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=535043">Mozilla Bug 535043</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
<textarea></textarea>
|
|
|
|
<textarea maxlength="-1"></textarea>
|
|
|
|
<textarea maxlength="0"></textarea>
|
|
|
|
<textarea maxlength="2"></textarea>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 535043 **/
|
|
|
|
function checkTextArea(textArea) {
|
|
|
|
textArea.value = '';
|
|
|
|
textArea.focus();
|
2010-08-21 20:32:24 +04:00
|
|
|
for (var j = 0; j < 3; j++) {
|
2018-02-14 22:15:39 +03:00
|
|
|
sendString("x");
|
2010-01-18 18:53:59 +03:00
|
|
|
}
|
|
|
|
var htmlMaxLength = textArea.getAttribute('maxlength');
|
|
|
|
var domMaxLength = textArea.maxLength;
|
|
|
|
if (htmlMaxLength == null) {
|
|
|
|
is(domMaxLength, -1,
|
|
|
|
'maxlength is unset but maxLength DOM attribute is not -1');
|
|
|
|
} else if (htmlMaxLength < 0) {
|
|
|
|
// Per the HTML5 spec, out-of-range values are supposed to translate to -1,
|
|
|
|
// not 0, but they don't?
|
2010-03-05 22:38:26 +03:00
|
|
|
is(domMaxLength, -1,
|
2010-01-18 18:53:59 +03:00
|
|
|
'maxlength is out of range but maxLength DOM attribute is not -1');
|
|
|
|
} else {
|
|
|
|
is(domMaxLength, parseInt(htmlMaxLength),
|
|
|
|
'maxlength in DOM does not match provided value');
|
|
|
|
}
|
|
|
|
if (textArea.maxLength == -1) {
|
2010-08-21 20:32:24 +04:00
|
|
|
is(textArea.value.length, 3,
|
2010-01-18 18:53:59 +03:00
|
|
|
'textarea with maxLength -1 should have no length limit');
|
|
|
|
} else {
|
|
|
|
is(textArea.value.length, textArea.maxLength, 'textarea has maxLength ' +
|
|
|
|
textArea.maxLength + ' but length ' + textArea.value.length );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForFocus(function() {
|
|
|
|
var textAreas = document.getElementsByTagName('textarea');
|
|
|
|
for (var i = 0; i < textAreas.length; i++) {
|
|
|
|
checkTextArea(textAreas[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
textArea = textAreas[0];
|
2010-08-21 20:32:24 +04:00
|
|
|
testNums = [-42, -1, 0, 2];
|
2010-01-18 18:53:59 +03:00
|
|
|
for (var i = 0; i < testNums.length; i++) {
|
|
|
|
textArea.removeAttribute('maxlength');
|
|
|
|
|
|
|
|
var caught = false;
|
|
|
|
try {
|
|
|
|
textArea.maxLength = testNums[i];
|
|
|
|
} catch (e) {
|
|
|
|
caught = true;
|
|
|
|
}
|
|
|
|
if (testNums[i] < 0) {
|
2010-03-05 22:42:46 +03:00
|
|
|
ok(caught, 'Setting negative maxLength should throw exception');
|
2010-01-18 18:53:59 +03:00
|
|
|
} else {
|
|
|
|
ok(!caught, 'Setting nonnegative maxLength should not throw exception');
|
|
|
|
}
|
|
|
|
checkTextArea(textArea);
|
|
|
|
|
|
|
|
textArea.setAttribute('maxlength', testNums[i]);
|
|
|
|
checkTextArea(textArea);
|
|
|
|
}
|
2010-08-21 20:32:24 +04:00
|
|
|
|
|
|
|
SimpleTest.finish();
|
2010-01-18 18:53:59 +03:00
|
|
|
});
|
2010-08-21 20:32:24 +04:00
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-01-18 18:53:59 +03:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|