editor/libeditor/html/tests/test_bug484181.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=484181
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 484181</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=484181">Mozilla Bug 484181</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 484181 **/
michael@0 22
michael@0 23 SimpleTest.waitForExplicitFinish();
michael@0 24 addLoadEvent(runTest);
michael@0 25
michael@0 26 var gMisspeltWords;
michael@0 27
michael@0 28 function getEditor() {
michael@0 29 var Ci = SpecialPowers.Ci;
michael@0 30 var win = window;
michael@0 31 var editingSession = SpecialPowers.wrap(win).QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 32 .getInterface(Ci.nsIWebNavigation)
michael@0 33 .QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 34 .getInterface(Ci.nsIEditingSession);
michael@0 35 return editingSession.getEditorForWindow(win);
michael@0 36 }
michael@0 37
michael@0 38 function getSpellCheckSelection() {
michael@0 39 var editor = getEditor();
michael@0 40 var selcon = editor.selectionController;
michael@0 41 return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
michael@0 42 }
michael@0 43
michael@0 44 function append(str) {
michael@0 45
michael@0 46 var edit = document.getElementById("edit");
michael@0 47 var editor = getEditor();
michael@0 48 var sel = editor.selection;
michael@0 49 sel.selectAllChildren(edit);
michael@0 50 sel.collapseToEnd();
michael@0 51
michael@0 52 for (var i = 0; i < str.length; ++i) {
michael@0 53 synthesizeKey(str[i], {});
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 function runTest() {
michael@0 58 gMisspeltWords = ["haz", "cheezburger"];
michael@0 59 var edit = document.getElementById("edit");
michael@0 60 edit.focus();
michael@0 61
michael@0 62 SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
michael@0 63 onSpellCheck(edit, function () {
michael@0 64 is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
michael@0 65
michael@0 66 append(" becaz I'm a lolcat!");
michael@0 67 onSpellCheck(edit, function () {
michael@0 68 gMisspeltWords.push("becaz");
michael@0 69 gMisspeltWords.push("lolcat");
michael@0 70 is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
michael@0 71
michael@0 72 SimpleTest.finish();
michael@0 73 });
michael@0 74 });
michael@0 75 }
michael@0 76
michael@0 77 function isSpellingCheckOk() {
michael@0 78
michael@0 79 var sel = getSpellCheckSelection();
michael@0 80 var numWords = sel.rangeCount;
michael@0 81
michael@0 82 is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
michael@0 83
michael@0 84 if (numWords != gMisspeltWords.length)
michael@0 85 return false;
michael@0 86
michael@0 87 for (var i=0; i<numWords; i++) {
michael@0 88 var word = sel.getRangeAt(i);
michael@0 89 is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
michael@0 90 if (word != gMisspeltWords[i])
michael@0 91 return false;
michael@0 92 }
michael@0 93 return true;
michael@0 94 }
michael@0 95
michael@0 96 </script>
michael@0 97 </pre>
michael@0 98
michael@0 99 <div><div></div><div id="edit" contenteditable="true">I can haz cheezburger</div></div>
michael@0 100
michael@0 101 </body>
michael@0 102 </html>

mercurial