Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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">
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
21 /** Test for Bug 596333 **/
22 const Ci = SpecialPowers.Ci;
24 SimpleTest.waitForExplicitFinish();
25 addLoadEvent(runTest);
27 var gMisspeltWords;
29 function getEditor() {
30 return SpecialPowers.wrap(document.getElementById("edit")).editor;
31 }
33 function getSpellCheckSelection() {
34 var editor = getEditor();
35 var selcon = editor.selectionController;
36 return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
37 }
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();
45 for (var i = 0; i < str.length; ++i) {
46 synthesizeKey(str[i], {});
47 }
48 }
50 function getLoadContext() {
51 return SpecialPowers.wrap(window)
52 .QueryInterface(Ci.nsIInterfaceRequestor)
53 .getInterface(Ci.nsIWebNavigation)
54 .QueryInterface(Ci.nsILoadContext);
55 }
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);
66 getEditor().pasteTransferable(trans);
67 }
69 function runOnFocus() {
70 var edit = document.getElementById("edit");
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.");
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.");
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.");
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.");
103 SimpleTest.finish();
104 });
105 });
106 });
107 });
108 }
110 function runTest()
111 {
112 var edit = document.getElementById("edit");
113 edit.focus();
115 SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
116 onSpellCheck(edit, runOnFocus);
117 }
119 function isSpellingCheckOk() {
120 var sel = getSpellCheckSelection();
121 var numWords = sel.rangeCount;
123 is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
125 if (numWords != gMisspeltWords.length)
126 return false;
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 }
137 </script>
138 </pre>
140 <textarea id="edit">I can haz cheezburger</textarea>
142 </body>
143 </html>