1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
<!DOCTYPE html>
<html>
<head>
<title>Mozilla bug 1418629</title>
<link rel=stylesheet href="/tests/SimpleTest/test.css">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/editor/spellchecker/tests/spellcheck.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1418629">Mozilla Bug 1418629</a>
<p id="display"></p>
<div id="content" style="display: none;">
</div>
<input id="input1" spellcheck="true">
<textarea id="textarea1"></textarea>
<div id="edit1" contenteditable=true></div>
<script>
const { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.import(
"resource://testing-common/AsyncSpellCheckTestHelper.jsm"
);
SimpleTest.waitForExplicitFinish();
function getEditor(input) {
if (input instanceof HTMLInputElement ||
input instanceof HTMLTextAreaElement) {
return SpecialPowers.wrap(input).editor;
}
return SpecialPowers.wrap(window).docShell.editor;
}
function resetEditableContent(input) {
if (input instanceof HTMLInputElement ||
input instanceof HTMLTextAreaElement) {
input.value = "";
return;
}
input.innerHTML = "";
}
async function test_with_single_quote(input) {
let misspeltWords = [];
input.focus();
resetEditableContent(input);
synthesizeKey("d");
synthesizeKey("o");
synthesizeKey("e");
synthesizeKey("s");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
let editor = getEditor(input);
// isSpellingCheckOk is defined in spellcheck.js
ok(isSpellingCheckOk(editor, misspeltWords), "no misspelt words");
synthesizeKey("n");
synthesizeKey("\'");
is(input.value || input.textContent, "doesn\'", "");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
// XXX This won't work since mozInlineSpellWordUtil::SplitDOM removes
// last single quote unfortunately that is during inputting.
// isSpellingCheckOk is defined in spellcheck.js
todo_is(isSpellingCheckOk(editor, misspeltWords, true), true,
"don't run spellchecker during inputting word");
synthesizeKey(" ");
is(input.value || input.textContent, "doesn\' ", "");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
misspeltWords.push("doesn");
// isSpellingCheckOk is defined in spellcheck.js
ok(isSpellingCheckOk(editor, misspeltWords), "should run spellchecker");
}
async function test_with_twice_characters(input, ch) {
let misspeltWords = [];
input.focus();
resetEditableContent(input);
synthesizeKey("d");
synthesizeKey("o");
synthesizeKey("e");
synthesizeKey("s");
synthesizeKey("n");
synthesizeKey(ch);
synthesizeKey(ch);
is(input.value || input.textContent, "doesn" + ch + ch, "");
// trigger spellchecker
synthesizeKey(" ");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
misspeltWords.push("doesn");
let editor = getEditor(input);
// isSpellingCheckOk is defined in spellcheck.js
ok(isSpellingCheckOk(editor, misspeltWords), "should run spellchecker");
}
async function test_between_single_quote(input) {
let misspeltWords = [];
input.focus();
resetEditableContent(input);
synthesizeKey("\'");
synthesizeKey("t");
synthesizeKey("e");
synthesizeKey("s");
synthesizeKey("t");
synthesizeKey("\'");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
let editor = getEditor(input);
ok(isSpellingCheckOk(editor, misspeltWords),
"don't run spellchecker between single qoute");
}
async function test_with_email(input) {
let misspeltWords = [];
input.focus();
resetEditableContent(input);
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("@");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey(".");
synthesizeKey("c");
synthesizeKey("o");
synthesizeKey("m");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
let editor = getEditor(input);
ok(isSpellingCheckOk(editor, misspeltWords),
"don't run spellchecker for email address");
synthesizeKey(" ");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
ok(isSpellingCheckOk(editor, misspeltWords),
"no misspelt words due to email address");
}
async function test_with_url(input) {
let misspeltWords = [];
input.focus();
resetEditableContent(input);
synthesizeKey("h");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("p");
synthesizeKey(":");
synthesizeKey("/");
synthesizeKey("/");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey("t");
synthesizeKey(".");
synthesizeKey("c");
synthesizeKey("o");
synthesizeKey("m");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
let editor = getEditor(input);
ok(isSpellingCheckOk(editor, misspeltWords),
"don't run spellchecker for URL");
synthesizeKey(" ");
await new Promise((resolve) => { maybeOnSpellCheck(input, resolve); });
ok(isSpellingCheckOk(editor, misspeltWords),
"no misspelt words due to URL");
}
SimpleTest.waitForFocus(() => {
for (let n of ["input1", "textarea1", "edit1"]) {
add_task(test_with_single_quote.bind(null,
document.getElementById(n)));
add_task(test_with_twice_characters.bind(null,
document.getElementById(n),
"\'"));
add_task(test_with_twice_characters.bind(null,
document.getElementById(n),
String.fromCharCode(0x2019)));
add_task(test_between_single_quote.bind(null,
document.getElementById(n)));
add_task(test_with_email.bind(null, document.getElementById(n)));
add_task(test_with_url.bind(null, document.getElementById(n)));
}
});
</script>
</body>
</html>
|