tor-browser

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

test_bug596333.html (4864B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=596333
      5 -->
      6 <head>
      7  <title>Test for Bug 596333</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10  <script src="/tests/SimpleTest/EventUtils.js"></script>
     11  <script src="spellcheck.js"></script>
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=596333">Mozilla Bug 596333</a>
     15 <p id="display"></p>
     16 <div id="content" style="display: none">
     17 
     18 </div>
     19 <pre id="test">
     20 <script type="application/javascript">
     21 
     22 /** Test for Bug 596333 */
     23 const Ci = SpecialPowers.Ci;
     24 
     25 SimpleTest.waitForExplicitFinish();
     26 addLoadEvent(runTest);
     27 
     28 var gMisspeltWords;
     29 var onSpellCheck;
     30 
     31 function getEditor() {
     32  return SpecialPowers.wrap(document.getElementById("edit")).editor;
     33 }
     34 
     35 function append(str) {
     36  var edit = document.getElementById("edit");
     37  edit.focus();
     38  edit.selectionStart = edit.selectionEnd = edit.value.length;
     39  sendString(str);
     40 }
     41 
     42 function getLoadContext() {
     43  return SpecialPowers.wrap(window).docShell.QueryInterface(Ci.nsILoadContext);
     44 }
     45 
     46 function paste(str) {
     47  var Cc = SpecialPowers.Cc;
     48  var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
     49  trans.init(getLoadContext());
     50  var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
     51  s.data = str;
     52  trans.setTransferData("text/plain", s);
     53 
     54  let beforeInputEvent = null;
     55  let inputEvent = null;
     56  window.addEventListener("beforeinput", aEvent => { beforeInputEvent = aEvent; }, {once: true});
     57  window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
     58  getEditor().pasteTransferable(trans);
     59  isnot(beforeInputEvent, null, '"beforeinput" event should be fired');
     60  if (beforeInputEvent) {
     61    is(beforeInputEvent.cancelable, true, '"beforeinput" event for "insertFromPaste" should be cancelable');
     62    is(beforeInputEvent.inputType, "insertFromPaste", 'inputType of "beforeinput" event should be "insertFromPaste"');
     63    is(beforeInputEvent.data, str, `data of "beforeinput" event should be "${str}"`);
     64    is(beforeInputEvent.dataTransfer, null, 'dataTransfer of "beforeinput" event should be null on <textarea>');
     65    is(beforeInputEvent.getTargetRanges().length, 0, 'getTargetRanges() of "beforeinput" event should return empty array on <textarea>');
     66  }
     67  is(inputEvent.type, "input", '"input" event should be fired');
     68  is(inputEvent.inputType, "insertFromPaste", '"inputType of "input" event should be "insertFromPaste"');
     69  is(inputEvent.data, str, `data of "input" event should be "${str}"`);
     70  is(inputEvent.dataTransfer, null, 'dataTransfer of "input" event should be null on <textarea>');
     71  is(inputEvent.getTargetRanges().length, 0, 'getTargetRanges() of "input" event should return empty array on <textarea>');
     72 }
     73 
     74 function runOnFocus() {
     75  var edit = document.getElementById("edit");
     76 
     77  gMisspeltWords = ["haz", "cheezburger"];
     78  ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
     79     "All misspellings before editing are accounted for.");
     80  append(" becaz I'm a lulcat!");
     81  onSpellCheck(edit, function() {
     82    gMisspeltWords.push("becaz");
     83    gMisspeltWords.push("lulcat");
     84    ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
     85       "All misspellings after typing are accounted for.");
     86 
     87    // Now, type an invalid word, and instead of hitting "space" at the end, just blur
     88    // the textarea and see if the spell check after the blur event catches it.
     89    append(" workd");
     90    edit.blur();
     91    onSpellCheck(edit, function() {
     92      gMisspeltWords.push("workd");
     93      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
     94         "All misspellings after blur are accounted for.");
     95 
     96      // Also, test the case when we're entering the first word in a textarea
     97      gMisspeltWords = ["workd"];
     98      edit.value = "";
     99      append("workd ");
    100      onSpellCheck(edit, function() {
    101        ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
    102           "Misspelling in the first entered word is accounted for.");
    103 
    104        // Make sure that pasting would also trigger spell checking for the previous word
    105        gMisspeltWords = ["workd"];
    106        edit.value = "";
    107        append("workd");
    108        paste("           x");
    109        onSpellCheck(edit, function() {
    110          ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
    111             "Misspelling is accounted for after pasting.");
    112 
    113          SimpleTest.finish();
    114        });
    115      });
    116    });
    117  });
    118 }
    119 
    120 function runTest() {
    121  var edit = document.getElementById("edit");
    122  edit.focus();
    123 
    124  onSpellCheck = SpecialPowers.ChromeUtils.importESModule(
    125    "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
    126  ).onSpellCheck;
    127  onSpellCheck(edit, runOnFocus);
    128 }
    129 </script>
    130 </pre>
    131 
    132 <textarea id="edit">I can haz cheezburger</textarea>
    133 
    134 </body>
    135 </html>