tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug697842.html (3009B)


      1 <!DOCTYPE>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=697842
      5 -->
      6 <head>
      7  <title>Test for Bug 697842</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css"
     11          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     12 </head>
     13 <body>
     14 <div id="display">
     15  <p id="editor" contenteditable style="min-height: 1.5em;"></p>
     16 </div>
     17 <div id="content" style="display: none">
     18 
     19 </div>
     20 <pre id="test">
     21 </pre>
     22 
     23 <script class="testbody" type="application/javascript">
     24 
     25 /** Test for Bug 697842 */
     26 SimpleTest.waitForExplicitFinish();
     27 SimpleTest.waitForFocus(runTests);
     28 
     29 function runTests() {
     30  var editor = document.getElementById("editor");
     31  editor.focus();
     32 
     33  SimpleTest.executeSoon(function() {
     34    var composingString = "";
     35 
     36    function handler(aEvent) {
     37      switch (aEvent.type) {
     38        case "compositionstart":
     39          // Selected string at starting composition must be empty in this test.
     40          is(aEvent.data, "", "mismatch selected string");
     41          break;
     42        case "compositionupdate":
     43        case "compositionend":
     44          is(aEvent.data, composingString, "mismatch composition string");
     45          break;
     46        default:
     47          break;
     48      }
     49      aEvent.stopPropagation();
     50      aEvent.preventDefault();
     51    }
     52 
     53    editor.addEventListener("compositionstart", handler, true);
     54    editor.addEventListener("compositionend", handler, true);
     55    editor.addEventListener("compositionupdate", handler, true);
     56 
     57    // input first character
     58    composingString = "\u306B";
     59    synthesizeCompositionChange(
     60      { "composition":
     61        { "string": composingString,
     62          "clauses":
     63          [
     64            { "length": 1, "attr": COMPOSITION_ATTR_RAW_CLAUSE },
     65          ],
     66        },
     67        "caret": { "start": 1, "length": 0 },
     68      });
     69 
     70    // input second character
     71    composingString = "\u306B\u3085";
     72    synthesizeCompositionChange(
     73      { "composition":
     74        { "string": composingString,
     75          "clauses":
     76          [
     77            { "length": 2, "attr": COMPOSITION_ATTR_RAW_CLAUSE },
     78          ],
     79        },
     80        "caret": { "start": 2, "length": 0 },
     81      });
     82 
     83    // convert them
     84    synthesizeCompositionChange(
     85      { "composition":
     86        { "string": composingString,
     87          "clauses":
     88          [
     89            { "length": 2,
     90              "attr": COMPOSITION_ATTR_SELECTED_CLAUSE },
     91          ],
     92        },
     93        "caret": { "start": 2, "length": 0 },
     94      });
     95 
     96    synthesizeComposition({ type: "compositioncommitasis" });
     97 
     98    is(editor.innerHTML, composingString,
     99       "editor has unexpected result");
    100 
    101    editor.removeEventListener("compositionstart", handler, true);
    102    editor.removeEventListener("compositionend", handler, true);
    103    editor.removeEventListener("compositionupdate", handler, true);
    104    editor.removeEventListener("text", handler, true);
    105 
    106    SimpleTest.finish();
    107  });
    108 }
    109 
    110 
    111 </script>
    112 </body>
    113 
    114 </html>