editor/libeditor/text/tests/test_bug596333.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial