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