diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/html/test/test_bug535043.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/html/test/test_bug535043.html')
-rw-r--r-- | dom/html/test/test_bug535043.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/dom/html/test/test_bug535043.html b/dom/html/test/test_bug535043.html new file mode 100644 index 0000000000..3eb046b3c5 --- /dev/null +++ b/dom/html/test/test_bug535043.html @@ -0,0 +1,90 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=535043 +--> +<head> + <title>Test for Bug 535043</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script 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(); + for (var j = 0; j < 3; j++) { + sendString("x"); + } + 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? + is(domMaxLength, -1, + '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) { + is(textArea.value.length, 3, + '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]; + testNums = [-42, -1, 0, 2]; + 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) { + ok(caught, 'Setting negative maxLength should throw exception'); + } else { + ok(!caught, 'Setting nonnegative maxLength should not throw exception'); + } + checkTextArea(textArea); + + textArea.setAttribute('maxlength', testNums[i]); + checkTextArea(textArea); + } + + SimpleTest.finish(); +}); + +SimpleTest.waitForExplicitFinish(); + +</script> +</pre> +</body> +</html> |