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