File: test_bug1026397.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (101 lines) | stat: -rw-r--r-- 3,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1026397
-->
<head>
  <title>Test for Bug 1026397</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=1026397">Mozilla Bug 1026397</a>
<p id="display"></p>
<div id="content">
<input id="input">
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 1026397 */
SimpleTest.waitForExplicitFinish();

function runTests() {
  var input = document.getElementById("input");
  input.focus();

  function doTest(aMaxLength, aInitialValue, aCaretOffset,
                  aInsertString, aExpectedValueDuringComposition,
                  aExpectedValueAfterCompositionEnd, aAdditionalExplanation) {
    input.value = aInitialValue;
    var maxLengthStr = "";
    if (aMaxLength >= 0) {
      input.maxLength = aMaxLength;
      maxLengthStr = aMaxLength.toString();
    } else {
      input.removeAttribute("maxlength");
      maxLengthStr = "not specified";
    }
    input.selectionStart = input.selectionEnd = aCaretOffset;
    if (aAdditionalExplanation) {
      aAdditionalExplanation = " " + aAdditionalExplanation;
    } else {
      aAdditionalExplanation = "";
    }

    synthesizeCompositionChange(
      { "composition":
        { "string": aInsertString,
          "clauses":
          [
            { "length": aInsertString.length, "attr": COMPOSITION_ATTR_RAW_CLAUSE },
          ],
        },
        "caret": { "start": aInsertString.length, "length": 0 },
      });
    is(input.value, aExpectedValueDuringComposition,
       "The value of input whose maxlength is " + maxLengthStr + " should be "
         + aExpectedValueDuringComposition + " during composition" + aAdditionalExplanation);
    synthesizeComposition({ type: "compositioncommitasis" });
    is(input.value, aExpectedValueAfterCompositionEnd,
       "The value of input whose maxlength is " + maxLengthStr + " should be "
         + aExpectedValueAfterCompositionEnd + " after compositionend" + aAdditionalExplanation);
  }

  // maxlength hasn't been specified yet.
  doTest(-1, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6");

  // maxlength="1"
  doTest(1, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "");

  // maxlength="2"
  doTest(2, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7");
  doTest(2, "X", 1, "\uD842\uDFB7\u91CE\u5BB6", "X\uD842\uDFB7\u91CE\u5BB6", "X");
  doTest(2, "Y", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6Y", "Y");

  // maxlength="3"
  doTest(3, "", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE");
  doTest(3, "A", 1, "\uD842\uDFB7\u91CE\u5BB6", "A\uD842\uDFB7\u91CE\u5BB6", "A\uD842\uDFB7");
  doTest(3, "B", 0, "\uD842\uDFB7\u91CE\u5BB6", "\uD842\uDFB7\u91CE\u5BB6B", "\uD842\uDFB7B");
  doTest(3, "CD", 1, "\uD842\uDFB7\u91CE\u5BB6", "C\uD842\uDFB7\u91CE\u5BB6D", "CD");

  // maxlength="4"
  doTest(4, "EF", 1, "\uD842\uDFB7\u91CE\u5BB6", "E\uD842\uDFB7\u91CE\u5BB6F", "E\uD842\uDFB7F");
  doTest(4, "GHI", 1, "\uD842\uDFB7\u91CE\u5BB6", "G\uD842\uDFB7\u91CE\u5BB6HI", "GHI");

  // maxlength="1", inputting only high surrogate
  doTest(1, "", 0, "\uD842", "\uD842", "\uD842", "even if input string is only a high surrogate");

  // maxlength="1", inputting only low surrogate
  doTest(1, "", 0, "\uDFB7", "\uDFB7", "\uDFB7", "even if input string is only a low surrogate");

  SimpleTest.finish();
}

SimpleTest.waitForFocus(runTests);

</script>
</pre>
</body>
</html>