editor/libeditor/html/tests/test_bug697842.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug697842.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +<!DOCTYPE>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=697842
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 697842</title>
    1.11 +  <script type="application/javascript" src="/MochiKit/packed.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css"
    1.15 +          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.16 +</head>
    1.17 +<body>
    1.18 +<div id="display">
    1.19 +  <p id="editor" contenteditable style="min-height: 1.5em;"></p>
    1.20 +</div>
    1.21 +<div id="content" style="display: none">
    1.22 +  
    1.23 +</div>
    1.24 +<pre id="test">
    1.25 +</pre>
    1.26 +
    1.27 +<script class="testbody" type="application/javascript">
    1.28 +
    1.29 +/** Test for Bug 697842 **/
    1.30 +SimpleTest.waitForExplicitFinish();
    1.31 +SimpleTest.waitForFocus(runTests);
    1.32 +
    1.33 +function runTests()
    1.34 +{
    1.35 +  var editor = document.getElementById("editor");
    1.36 +  editor.focus();
    1.37 +
    1.38 +  SimpleTest.executeSoon(function() {
    1.39 +    var composingString = "";
    1.40 +
    1.41 +    function handler(aEvent) {
    1.42 +      if (aEvent.type != "text") {
    1.43 +        is(aEvent.data, composingString, "mismatch composition string");
    1.44 +      }
    1.45 +      aEvent.stopPropagation();
    1.46 +      aEvent.preventDefault();
    1.47 +    }
    1.48 +
    1.49 +    editor.addEventListener("compositionstart", handler, true);
    1.50 +    editor.addEventListener("compositionend", handler, true);
    1.51 +    editor.addEventListener("compositionupdate", handler, true);
    1.52 +    editor.addEventListener("text", handler, true);
    1.53 +
    1.54 +    // start composition
    1.55 +    synthesizeComposition({ type: "compositionstart" });
    1.56 +
    1.57 +    // input first character
    1.58 +    composingString = "\u306B";
    1.59 +    synthesizeComposition({ type: "compositionupdate", data: composingString });
    1.60 +    synthesizeText(
    1.61 +      { "composition":
    1.62 +        { "string": composingString,
    1.63 +          "clauses":
    1.64 +          [
    1.65 +            { "length": 1, "attr": COMPOSITION_ATTR_RAWINPUT }
    1.66 +          ]
    1.67 +        },
    1.68 +        "caret": { "start": 1, "length": 0 }
    1.69 +      });
    1.70 +
    1.71 +    // input second character
    1.72 +    composingString = "\u306B\u3085";
    1.73 +    synthesizeComposition({ type: "compositionupdate", data: composingString });
    1.74 +    synthesizeText(
    1.75 +      { "composition":
    1.76 +        { "string": composingString,
    1.77 +          "clauses":
    1.78 +          [
    1.79 +            { "length": 2, "attr": COMPOSITION_ATTR_RAWINPUT }
    1.80 +          ]
    1.81 +        },
    1.82 +        "caret": { "start": 2, "length": 0 }
    1.83 +      });
    1.84 +
    1.85 +    // convert them
    1.86 +    synthesizeText(
    1.87 +      { "composition":
    1.88 +        { "string": composingString,
    1.89 +          "clauses":
    1.90 +          [
    1.91 +            { "length": 2,
    1.92 +              "attr": COMPOSITION_ATTR_SELECTEDCONVERTEDTEXT }
    1.93 +          ]
    1.94 +        },
    1.95 +        "caret": { "start": 2, "length": 0 }
    1.96 +      });
    1.97 +
    1.98 +    // commit
    1.99 +    synthesizeText(
   1.100 +      { "composition":
   1.101 +        { "string": composingString,
   1.102 +          "clauses":
   1.103 +          [
   1.104 +            { "length": 0, "attr": 0 }
   1.105 +          ]
   1.106 +        },
   1.107 +        "caret": { "start": 2, "length": 0 }
   1.108 +      });
   1.109 +
   1.110 +    synthesizeComposition({ type: "compositionend", data: composingString });
   1.111 +
   1.112 +    is(editor.innerHTML, composingString,
   1.113 +       "editor has unexpected result");
   1.114 +
   1.115 +    editor.removeEventListener("compositionstart", handler, true);
   1.116 +    editor.removeEventListener("compositionend", handler, true);
   1.117 +    editor.removeEventListener("compositionupdate", handler, true);
   1.118 +    editor.removeEventListener("text", handler, true);
   1.119 +
   1.120 +    SimpleTest.finish();
   1.121 +  });
   1.122 +}
   1.123 +
   1.124 +
   1.125 +</script>
   1.126 +</body>
   1.127 +
   1.128 +</html>

mercurial