summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_bug1026397.html
blob: 487f3e87f8e9c291c4795192a0b1bdbbfd3e5cd8 (plain)
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
102
103
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1026397
-->
<head>
  <title>Test for Bug 1026397</title>
  <script type="application/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=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>