test_bug1026397.html (3751B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1026397 5 --> 6 <head> 7 <title>Test for Bug 1026397</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1026397">Mozilla Bug 1026397</a> 14 <p id="display"></p> 15 <div id="content"> 16 <input id="input"> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 1026397 */ 22 SimpleTest.waitForExplicitFinish(); 23 24 function runTests() { 25 var input = document.getElementById("input"); 26 input.focus(); 27 28 function doTest(aMaxLength, aInitialValue, aCaretOffset, 29 aInsertString, aExpectedValueDuringComposition, 30 aExpectedValueAfterCompositionEnd, aAdditionalExplanation) { 31 input.value = aInitialValue; 32 var maxLengthStr = ""; 33 if (aMaxLength >= 0) { 34 input.maxLength = aMaxLength; 35 maxLengthStr = aMaxLength.toString(); 36 } else { 37 input.removeAttribute("maxlength"); 38 maxLengthStr = "not specified"; 39 } 40 input.selectionStart = input.selectionEnd = aCaretOffset; 41 if (aAdditionalExplanation) { 42 aAdditionalExplanation = " " + aAdditionalExplanation; 43 } else { 44 aAdditionalExplanation = ""; 45 } 46 47 synthesizeCompositionChange( 48 { "composition": 49 { "string": aInsertString, 50 "clauses": 51 [ 52 { "length": aInsertString.length, "attr": COMPOSITION_ATTR_RAW_CLAUSE }, 53 ], 54 }, 55 "caret": { "start": aInsertString.length, "length": 0 }, 56 }); 57 is(input.value, aExpectedValueDuringComposition, 58 "The value of input whose maxlength is " + maxLengthStr + " should be " 59 + aExpectedValueDuringComposition + " during composition" + aAdditionalExplanation); 60 synthesizeComposition({ type: "compositioncommitasis" }); 61 is(input.value, aExpectedValueAfterCompositionEnd, 62 "The value of input whose maxlength is " + maxLengthStr + " should be " 63 + aExpectedValueAfterCompositionEnd + " after compositionend" + aAdditionalExplanation); 64 } 65 66 // maxlength hasn't been specified yet. 67 doTest(-1, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6"); 68 69 // maxlength="1" 70 doTest(1, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", ""); 71 72 // maxlength="2" 73 doTest(2, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7"); 74 doTest(2, "X", 1, "\uD842\uDFB7\u91CE\u5BB6", "X\uD842\uDFB7\u91CE\u5BB6", "X"); 75 doTest(2, "Y", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6Y", "Y"); 76 77 // maxlength="3" 78 doTest(3, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE"); 79 doTest(3, "A", 1, "\uD842\uDFB7\u91CE\u5BB6", "A\uD842\uDFB7\u91CE\u5BB6", "A\uD842\uDFB7"); 80 doTest(3, "B", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6B", "\uD842\uDFB7B"); 81 doTest(3, "CD", 1, "\uD842\uDFB7\u91CE\u5BB6", "C\uD842\uDFB7\u91CE\u5BB6D", "CD"); 82 83 // maxlength="4" 84 doTest(4, "EF", 1, "\uD842\uDFB7\u91CE\u5BB6", "E\uD842\uDFB7\u91CE\u5BB6F", "E\uD842\uDFB7F"); 85 doTest(4, "GHI", 1, "\uD842\uDFB7\u91CE\u5BB6", "G\uD842\uDFB7\u91CE\u5BB6HI", "GHI"); 86 87 // maxlength="1", inputting only high surrogate 88 doTest(1, "", 0, "\uD842", "\uD842", "\uD842", "even if input string is only a high surrogate"); 89 90 // maxlength="1", inputting only low surrogate 91 doTest(1, "", 0, "\uDFB7", "\uDFB7", "\uDFB7", "even if input string is only a low surrogate"); 92 93 SimpleTest.finish(); 94 } 95 96 SimpleTest.waitForFocus(runTests); 97 98 </script> 99 </pre> 100 </body> 101 </html>