1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/test/test_bug345267.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=345267 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 345267</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345267">Mozilla Bug 345267</a> 1.17 +<p id="display"> 1.18 + <input id="d1" maxlength="3" value="abcde"> 1.19 + <input id="d2" maxlength="3"> 1.20 + <input id="d3" maxlength="3"> 1.21 + <input id="d4" value="abcdefghijk"> 1.22 + <input id="target" value="abcdefghijklm" maxlength="3"> 1.23 +</p> 1.24 +<div id="content" style="display: none"> 1.25 + <input id="u1" maxlength="3" value="abcdef"> 1.26 + <input id="u2" maxlength="3"> 1.27 + <input id="u3" maxlength="3"> 1.28 + <input id="u4" value="abcdefghijkl"> 1.29 +</div> 1.30 +<pre id="test"> 1.31 +<script class="testbody" type="text/javascript"> 1.32 + 1.33 +/** Test for Bug 345267 **/ 1.34 + 1.35 +// Turn off Spatial Navigation to stop if from hijacking "left" keypress event. 1.36 +SpecialPowers.setBoolPref('snav.enabled', false); 1.37 + 1.38 +is($("d1").value, "abcde", 1.39 + "Displayed initial value should not be truncated by maxlength"); 1.40 +is($("u1").value, "abcdef", 1.41 + "Undisplayed initial value should not be truncated by maxlength"); 1.42 + 1.43 +$("d2").value = "abcdefg"; 1.44 +is($("d2").value, "abcdefg", 1.45 + "Displayed set value should not be truncated by maxlength"); 1.46 + 1.47 +$("u2").value = "abcdefgh"; 1.48 +is($("u2").value, "abcdefgh", 1.49 + "Undisplayed set value should not be truncated by maxlength"); 1.50 + 1.51 +$("d3").defaultValue = "abcdefghi"; 1.52 +is($("d3").value, "abcdefghi", 1.53 + "Displayed set defaultValue should not be truncated by maxlength"); 1.54 + 1.55 +$("u3").defaultValue = "abcdefghij"; 1.56 +is($("u3").value, "abcdefghij", 1.57 + "Undisplayed set defaultValue should not be truncated by maxlength"); 1.58 + 1.59 +$("d4").maxLength = "3"; 1.60 +is($("d4").value, "abcdefghijk", 1.61 + "Displayed: setting maxLength should not truncate existing value"); 1.62 + 1.63 +$("u4").maxLength = "3"; 1.64 +is($("u4").value, "abcdefghijkl", 1.65 + "Undisplayed: setting maxLength should not truncate existing value"); 1.66 + 1.67 +// Now start the editing tests 1.68 +is($("target").value, "abcdefghijklm", "Test starting state incorrect"); 1.69 +$("target").focus(); 1.70 +$("target").selectionStart = $("target").selectionEnd = 13; 1.71 +sendKey("back_space"); 1.72 +is($("target").value, "abcdefghijkl", "Should only delete one char"); 1.73 +sendKey("back_space"); 1.74 +is($("target").value, "abcdefghijk", "Should only delete one char again"); 1.75 +(function () { 1.76 + SpecialPowers.wrap($("target")).controllers.getControllerForCommand('cmd_undo') 1.77 + .doCommand('cmd_undo'); 1.78 +})(); 1.79 +is($("target").value, "abcdefghijklm", 1.80 + "Should be able to undo deletion in the face of maxlength"); 1.81 +sendString("nopq"); 1.82 +is($("target").value, "abcdefghijklm", 1.83 + "Typing should have no effect when already past maxlength"); 1.84 + 1.85 +$("target").value = ""; 1.86 +sendString("abcde"); 1.87 +is($("target").value, "abc", "Typing should be limited by maxlength"); 1.88 + 1.89 +$("target").value = ""; 1.90 +sendString("ad"); 1.91 +sendKey("left"); 1.92 +sendString("bc"); 1.93 +is($("target").value, "abd", "Typing should be limited by maxlength again"); 1.94 + 1.95 +</script> 1.96 +</pre> 1.97 +</body> 1.98 +</html> 1.99 +