OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/spellchecker/spellcheck.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <memory> | |
10 #include <utility> | |
11 | |
12 #include "base/files/file_path.h" | |
13 #include "base/files/file_util.h" | |
14 #include "base/macros.h" | |
15 #include "base/message_loop/message_loop.h" | |
16 #include "base/path_service.h" | |
17 #include "base/run_loop.h" | |
18 #include "base/strings/string_number_conversions.h" | |
19 #include "base/strings/utf_string_conversions.h" | |
20 #include "build/build_config.h" | |
21 #include "chrome/renderer/spellchecker/hunspell_engine.h" | |
22 #include "chrome/renderer/spellchecker/spellcheck_language.h" | |
23 #include "components/spellcheck/common/spellcheck_common.h" | |
24 #include "components/spellcheck/common/spellcheck_result.h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | |
26 #include "third_party/WebKit/public/platform/WebVector.h" | |
27 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | |
28 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | |
29 | |
30 #define TYPOGRAPHICAL_APOSTROPHE L"\x2019" | |
31 | |
32 namespace { | |
33 const int kNoOffset = 0; | |
34 const int kNoTag = 0; | |
35 | |
36 base::FilePath GetHunspellDirectory() { | |
37 base::FilePath hunspell_directory; | |
38 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) | |
39 return base::FilePath(); | |
40 | |
41 hunspell_directory = hunspell_directory.AppendASCII("third_party"); | |
42 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); | |
43 return hunspell_directory; | |
44 } | |
45 | |
46 } // namespace | |
47 | |
48 // TODO(groby): This needs to be a BrowserTest for OSX. | |
49 class SpellCheckTest : public testing::Test { | |
50 public: | |
51 SpellCheckTest() { | |
52 ReinitializeSpellCheck("en-US"); | |
53 } | |
54 | |
55 void ReinitializeSpellCheck(const std::string& language) { | |
56 spell_check_.reset(new SpellCheck()); | |
57 InitializeSpellCheck(language); | |
58 } | |
59 | |
60 void UninitializeSpellCheck() { | |
61 spell_check_.reset(new SpellCheck()); | |
62 } | |
63 | |
64 bool InitializeIfNeeded() { | |
65 return spell_check()->InitializeIfNeeded(); | |
66 } | |
67 | |
68 void InitializeSpellCheck(const std::string& language) { | |
69 base::FilePath hunspell_directory = GetHunspellDirectory(); | |
70 EXPECT_FALSE(hunspell_directory.empty()); | |
71 base::File file( | |
72 spellcheck::GetVersionedFileName(language, hunspell_directory), | |
73 base::File::FLAG_OPEN | base::File::FLAG_READ); | |
74 #if defined(OS_MACOSX) | |
75 // TODO(groby): Forcing spellcheck to use hunspell, even on OSX. | |
76 // Instead, tests should exercise individual spelling engines. | |
77 spell_check_->languages_.push_back(new SpellcheckLanguage()); | |
78 spell_check_->languages_.front()->platform_spelling_engine_.reset( | |
79 new HunspellEngine); | |
80 spell_check_->languages_.front()->Init(std::move(file), language); | |
81 #else | |
82 spell_check_->AddSpellcheckLanguage(std::move(file), language); | |
83 #endif | |
84 } | |
85 | |
86 ~SpellCheckTest() override {} | |
87 | |
88 SpellCheck* spell_check() { return spell_check_.get(); } | |
89 | |
90 bool CheckSpelling(const std::string& word, int tag) { | |
91 return spell_check_->languages_.front() | |
92 ->platform_spelling_engine_->CheckSpelling(base::ASCIIToUTF16(word), | |
93 tag); | |
94 } | |
95 | |
96 bool IsValidContraction(const base::string16& word, int tag) { | |
97 return spell_check_->languages_.front()->IsValidContraction(word, tag); | |
98 } | |
99 | |
100 static void FillSuggestions( | |
101 const std::vector<std::vector<base::string16>>& suggestions_list, | |
102 std::vector<base::string16>* optional_suggestions) { | |
103 SpellCheck::FillSuggestions(suggestions_list, optional_suggestions); | |
104 } | |
105 | |
106 #if !defined(OS_MACOSX) | |
107 protected: | |
108 void TestSpellCheckParagraph( | |
109 const base::string16& input, | |
110 const std::vector<SpellCheckResult>& expected) { | |
111 blink::WebVector<blink::WebTextCheckingResult> results; | |
112 spell_check()->SpellCheckParagraph(input, | |
113 &results); | |
114 | |
115 EXPECT_EQ(results.size(), expected.size()); | |
116 size_t size = std::min(results.size(), expected.size()); | |
117 for (size_t j = 0; j < size; ++j) { | |
118 EXPECT_EQ(results[j].decoration, blink::WebTextDecorationTypeSpelling); | |
119 EXPECT_EQ(results[j].location, expected[j].location); | |
120 EXPECT_EQ(results[j].length, expected[j].length); | |
121 } | |
122 } | |
123 #endif | |
124 | |
125 private: | |
126 std::unique_ptr<SpellCheck> spell_check_; | |
127 base::MessageLoop loop; | |
128 }; | |
129 | |
130 // A fake completion object for verification. | |
131 class MockTextCheckingCompletion : public blink::WebTextCheckingCompletion { | |
132 public: | |
133 MockTextCheckingCompletion() | |
134 : completion_count_(0) { | |
135 } | |
136 | |
137 void didFinishCheckingText( | |
138 const blink::WebVector<blink::WebTextCheckingResult>& results) override { | |
139 completion_count_++; | |
140 last_results_ = results; | |
141 } | |
142 | |
143 void didCancelCheckingText() override { | |
144 completion_count_++; | |
145 } | |
146 | |
147 size_t completion_count_; | |
148 blink::WebVector<blink::WebTextCheckingResult> last_results_; | |
149 }; | |
150 | |
151 // Operates unit tests for the content::SpellCheck::SpellCheckWord() function | |
152 // with the US English dictionary. | |
153 // The unit tests in this function consist of: | |
154 // * Tests for the function with empty strings; | |
155 // * Tests for the function with a valid English word; | |
156 // * Tests for the function with a valid non-English word; | |
157 // * Tests for the function with a valid English word with a preceding | |
158 // space character; | |
159 // * Tests for the function with a valid English word with a preceding | |
160 // non-English word; | |
161 // * Tests for the function with a valid English word with a following | |
162 // space character; | |
163 // * Tests for the function with a valid English word with a following | |
164 // non-English word; | |
165 // * Tests for the function with two valid English words concatenated | |
166 // with space characters or non-English words; | |
167 // * Tests for the function with an invalid English word; | |
168 // * Tests for the function with an invalid English word with a preceding | |
169 // space character; | |
170 // * Tests for the function with an invalid English word with a preceding | |
171 // non-English word; | |
172 // * Tests for the function with an invalid English word with a following | |
173 // space character; | |
174 // * Tests for the function with an invalid English word with a following | |
175 // non-English word, and; | |
176 // * Tests for the function with two invalid English words concatenated | |
177 // with space characters or non-English words. | |
178 // A test with a "[ROBUSTNESS]" mark shows it is a robustness test and it uses | |
179 // grammatically incorrect string. | |
180 // TODO(groby): Please feel free to add more tests. | |
181 TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) { | |
182 static const struct { | |
183 // A string to be tested. | |
184 const wchar_t* input; | |
185 // An expected result for this test case. | |
186 // * true: the input string does not have any invalid words. | |
187 // * false: the input string has one or more invalid words. | |
188 bool expected_result; | |
189 // The position and the length of the first invalid word. | |
190 int misspelling_start; | |
191 int misspelling_length; | |
192 } kTestCases[] = { | |
193 // Empty strings. | |
194 {L"", true}, | |
195 {L" ", true}, | |
196 {L"\xA0", true}, | |
197 {L"\x3000", true}, | |
198 | |
199 // A valid English word "hello". | |
200 {L"hello", true}, | |
201 // A valid Chinese word (meaning "hello") consisting of two CJKV | |
202 // ideographs | |
203 {L"\x4F60\x597D", true}, | |
204 // A valid Korean word (meaning "hello") consisting of five hangul | |
205 // syllables | |
206 {L"\xC548\xB155\xD558\xC138\xC694", true}, | |
207 // A valid Japanese word (meaning "hello") consisting of five Hiragana | |
208 // letters | |
209 {L"\x3053\x3093\x306B\x3061\x306F", true}, | |
210 // A valid Hindi word (meaning ?) consisting of six Devanagari letters | |
211 // (This word is copied from "http://b/issue?id=857583".) | |
212 {L"\x0930\x093E\x091C\x0927\x093E\x0928", true}, | |
213 // A valid English word "affix" using a Latin ligature 'ffi' | |
214 {L"a\xFB03x", true}, | |
215 // A valid English word "hello" (fullwidth version) | |
216 {L"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true}, | |
217 // Two valid Greek words (meaning "hello") consisting of seven Greek | |
218 // letters | |
219 {L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5", true}, | |
220 // A valid Russian word (meaning "hello") consisting of twelve Cyrillic | |
221 // letters | |
222 {L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
223 L"\x0442\x0432\x0443\x0439\x0442\x0435", true}, | |
224 // A valid English contraction | |
225 {L"isn't", true}, | |
226 // A valid English contraction with a typographical apostrophe. | |
227 {L"isn" TYPOGRAPHICAL_APOSTROPHE L"t", true}, | |
228 // A valid English word enclosed with underscores. | |
229 {L"_hello_", true}, | |
230 | |
231 // A valid English word with a preceding whitespace | |
232 {L" " L"hello", true}, | |
233 // A valid English word with a preceding no-break space | |
234 {L"\xA0" L"hello", true}, | |
235 // A valid English word with a preceding ideographic space | |
236 {L"\x3000" L"hello", true}, | |
237 // A valid English word with a preceding Chinese word | |
238 {L"\x4F60\x597D" L"hello", true}, | |
239 // [ROBUSTNESS] A valid English word with a preceding Korean word | |
240 {L"\xC548\xB155\xD558\xC138\xC694" L"hello", true}, | |
241 // A valid English word with a preceding Japanese word | |
242 {L"\x3053\x3093\x306B\x3061\x306F" L"hello", true}, | |
243 // [ROBUSTNESS] A valid English word with a preceding Hindi word | |
244 {L"\x0930\x093E\x091C\x0927\x093E\x0928" L"hello", true}, | |
245 // [ROBUSTNESS] A valid English word with two preceding Greek words | |
246 {L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" | |
247 L"hello", true}, | |
248 // [ROBUSTNESS] A valid English word with a preceding Russian word | |
249 {L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
250 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"hello", true}, | |
251 | |
252 // A valid English word with a following whitespace | |
253 {L"hello" L" ", true}, | |
254 // A valid English word with a following no-break space | |
255 {L"hello" L"\xA0", true}, | |
256 // A valid English word with a following ideographic space | |
257 {L"hello" L"\x3000", true}, | |
258 // A valid English word with a following Chinese word | |
259 {L"hello" L"\x4F60\x597D", true}, | |
260 // [ROBUSTNESS] A valid English word with a following Korean word | |
261 {L"hello" L"\xC548\xB155\xD558\xC138\xC694", true}, | |
262 // A valid English word with a following Japanese word | |
263 {L"hello" L"\x3053\x3093\x306B\x3061\x306F", true}, | |
264 // [ROBUSTNESS] A valid English word with a following Hindi word | |
265 {L"hello" L"\x0930\x093E\x091C\x0927\x093E\x0928", true}, | |
266 // [ROBUSTNESS] A valid English word with two following Greek words | |
267 {L"hello" | |
268 L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5", true}, | |
269 // [ROBUSTNESS] A valid English word with a following Russian word | |
270 {L"hello" L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
271 L"\x0442\x0432\x0443\x0439\x0442\x0435", true}, | |
272 | |
273 // Two valid English words concatenated with a whitespace | |
274 {L"hello" L" " L"hello", true}, | |
275 // Two valid English words concatenated with a no-break space | |
276 {L"hello" L"\xA0" L"hello", true}, | |
277 // Two valid English words concatenated with an ideographic space | |
278 {L"hello" L"\x3000" L"hello", true}, | |
279 // Two valid English words concatenated with a Chinese word | |
280 {L"hello" L"\x4F60\x597D" L"hello", true}, | |
281 // [ROBUSTNESS] Two valid English words concatenated with a Korean word | |
282 {L"hello" L"\xC548\xB155\xD558\xC138\xC694" L"hello", true}, | |
283 // Two valid English words concatenated with a Japanese word | |
284 {L"hello" L"\x3053\x3093\x306B\x3061\x306F" L"hello", true}, | |
285 // [ROBUSTNESS] Two valid English words concatenated with a Hindi word | |
286 {L"hello" L"\x0930\x093E\x091C\x0927\x093E\x0928" L"hello" , true}, | |
287 // [ROBUSTNESS] Two valid English words concatenated with two Greek words | |
288 {L"hello" L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" | |
289 L"hello", true}, | |
290 // [ROBUSTNESS] Two valid English words concatenated with a Russian word | |
291 {L"hello" L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
292 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"hello", true}, | |
293 // [ROBUSTNESS] Two valid English words concatenated with a contraction | |
294 // character. | |
295 {L"hello:hello", true}, | |
296 | |
297 // An invalid English word | |
298 {L"ifmmp", false, 0, 5}, | |
299 // An invalid English word "bffly" containing a Latin ligature 'ffl' | |
300 {L"b\xFB04y", false, 0, 3}, | |
301 // An invalid English word "ifmmp" (fullwidth version) | |
302 {L"\xFF29\xFF46\xFF4D\xFF4D\xFF50", false, 0, 5}, | |
303 // An invalid English contraction | |
304 {L"jtm'u", false, 0, 5}, | |
305 // An invalid English word enclosed with underscores. | |
306 {L"_ifmmp_", false, 1, 5}, | |
307 | |
308 // An invalid English word with a preceding whitespace | |
309 {L" " L"ifmmp", false, 1, 5}, | |
310 // An invalid English word with a preceding no-break space | |
311 {L"\xA0" L"ifmmp", false, 1, 5}, | |
312 // An invalid English word with a preceding ideographic space | |
313 {L"\x3000" L"ifmmp", false, 1, 5}, | |
314 // An invalid English word with a preceding Chinese word | |
315 {L"\x4F60\x597D" L"ifmmp", false, 2, 5}, | |
316 // [ROBUSTNESS] An invalid English word with a preceding Korean word | |
317 {L"\xC548\xB155\xD558\xC138\xC694" L"ifmmp", false, 5, 5}, | |
318 // An invalid English word with a preceding Japanese word | |
319 {L"\x3053\x3093\x306B\x3061\x306F" L"ifmmp", false, 5, 5}, | |
320 // [ROBUSTNESS] An invalid English word with a preceding Hindi word | |
321 {L"\x0930\x093E\x091C\x0927\x093E\x0928" L"ifmmp", false, 6, 5}, | |
322 // [ROBUSTNESS] An invalid English word with two preceding Greek words | |
323 {L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" | |
324 L"ifmmp", false, 8, 5}, | |
325 // [ROBUSTNESS] An invalid English word with a preceding Russian word | |
326 {L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
327 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"ifmmp", false, 12, 5}, | |
328 | |
329 // An invalid English word with a following whitespace | |
330 {L"ifmmp" L" ", false, 0, 5}, | |
331 // An invalid English word with a following no-break space | |
332 {L"ifmmp" L"\xA0", false, 0, 5}, | |
333 // An invalid English word with a following ideographic space | |
334 {L"ifmmp" L"\x3000", false, 0, 5}, | |
335 // An invalid English word with a following Chinese word | |
336 {L"ifmmp" L"\x4F60\x597D", false, 0, 5}, | |
337 // [ROBUSTNESS] An invalid English word with a following Korean word | |
338 {L"ifmmp" L"\xC548\xB155\xD558\xC138\xC694", false, 0, 5}, | |
339 // An invalid English word with a following Japanese word | |
340 {L"ifmmp" L"\x3053\x3093\x306B\x3061\x306F", false, 0, 5}, | |
341 // [ROBUSTNESS] An invalid English word with a following Hindi word | |
342 {L"ifmmp" L"\x0930\x093E\x091C\x0927\x093E\x0928", false, 0, 5}, | |
343 // [ROBUSTNESS] An invalid English word with two following Greek words | |
344 {L"ifmmp" | |
345 L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5", false, 0, 5}, | |
346 // [ROBUSTNESS] An invalid English word with a following Russian word | |
347 {L"ifmmp" L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
348 L"\x0442\x0432\x0443\x0439\x0442\x0435", false, 0, 5}, | |
349 | |
350 // Two invalid English words concatenated with a whitespace | |
351 {L"ifmmp" L" " L"ifmmp", false, 0, 5}, | |
352 // Two invalid English words concatenated with a no-break space | |
353 {L"ifmmp" L"\xA0" L"ifmmp", false, 0, 5}, | |
354 // Two invalid English words concatenated with an ideographic space | |
355 {L"ifmmp" L"\x3000" L"ifmmp", false, 0, 5}, | |
356 // Two invalid English words concatenated with a Chinese word | |
357 {L"ifmmp" L"\x4F60\x597D" L"ifmmp", false, 0, 5}, | |
358 // [ROBUSTNESS] Two invalid English words concatenated with a Korean word | |
359 {L"ifmmp" L"\xC548\xB155\xD558\xC138\xC694" L"ifmmp", false, 0, 5}, | |
360 // Two invalid English words concatenated with a Japanese word | |
361 {L"ifmmp" L"\x3053\x3093\x306B\x3061\x306F" L"ifmmp", false, 0, 5}, | |
362 // [ROBUSTNESS] Two invalid English words concatenated with a Hindi word | |
363 {L"ifmmp" L"\x0930\x093E\x091C\x0927\x093E\x0928" L"ifmmp" , false, 0, 5}, | |
364 // [ROBUSTNESS] Two invalid English words concatenated with two Greek words | |
365 {L"ifmmp" L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" | |
366 L"ifmmp", false, 0, 5}, | |
367 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word | |
368 {L"ifmmp" L"\x0437\x0434\x0440\x0430\x0432\x0441" | |
369 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"ifmmp", false, 0, 5}, | |
370 // [ROBUSTNESS] Two invalid English words concatenated with a contraction | |
371 // character. | |
372 {L"ifmmp:ifmmp", false, 0, 11}, | |
373 | |
374 // [REGRESSION] Issue 13432: "Any word of 13 or 14 characters is not | |
375 // spellcheck" <http://crbug.com/13432>. | |
376 {L"qwertyuiopasd", false, 0, 13}, | |
377 {L"qwertyuiopasdf", false, 0, 14}, | |
378 | |
379 // [REGRESSION] Issue 128896: "en_US hunspell dictionary includes | |
380 // acknowledgement but not acknowledgements" <http://crbug.com/128896> | |
381 {L"acknowledgement", true}, | |
382 {L"acknowledgements", true}, | |
383 | |
384 // Issue 123290: "Spellchecker should treat numbers as word characters" | |
385 {L"0th", true}, | |
386 {L"1st", true}, | |
387 {L"2nd", true}, | |
388 {L"3rd", true}, | |
389 {L"4th", true}, | |
390 {L"5th", true}, | |
391 {L"6th", true}, | |
392 {L"7th", true}, | |
393 {L"8th", true}, | |
394 {L"9th", true}, | |
395 {L"10th", true}, | |
396 {L"100th", true}, | |
397 {L"1000th", true}, | |
398 {L"25", true}, | |
399 {L"2012", true}, | |
400 {L"100,000,000", true}, | |
401 {L"3.141592653", true}, | |
402 }; | |
403 | |
404 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
405 size_t input_length = 0; | |
406 if (kTestCases[i].input != NULL) { | |
407 input_length = wcslen(kTestCases[i].input); | |
408 } | |
409 int misspelling_start; | |
410 int misspelling_length; | |
411 bool result = spell_check()->SpellCheckWord( | |
412 base::WideToUTF16(kTestCases[i].input).c_str(), | |
413 kNoOffset, | |
414 static_cast<int>(input_length), | |
415 kNoTag, | |
416 &misspelling_start, | |
417 &misspelling_length, NULL); | |
418 | |
419 EXPECT_EQ(kTestCases[i].expected_result, result); | |
420 EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start); | |
421 EXPECT_EQ(kTestCases[i].misspelling_length, misspelling_length); | |
422 } | |
423 } | |
424 | |
425 TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) { | |
426 static const struct { | |
427 // A string to be tested. | |
428 const wchar_t* input; | |
429 // An expected result for this test case. | |
430 // * true: the input string does not have any invalid words. | |
431 // * false: the input string has one or more invalid words. | |
432 bool expected_result; | |
433 // The position and the length of the first invalid word. | |
434 int misspelling_start; | |
435 int misspelling_length; | |
436 | |
437 // A suggested word that should occur. | |
438 const wchar_t* suggested_word; | |
439 } kTestCases[] = { | |
440 {L"ello", false, 0, 0, L"hello"}, | |
441 {L"ello", false, 0, 0, L"cello"}, | |
442 {L"wate", false, 0, 0, L"water"}, | |
443 {L"wate", false, 0, 0, L"waste"}, | |
444 {L"wate", false, 0, 0, L"sate"}, | |
445 {L"wate", false, 0, 0, L"ate"}, | |
446 {L"jum", false, 0, 0, L"jump"}, | |
447 {L"jum", false, 0, 0, L"hum"}, | |
448 {L"jum", false, 0, 0, L"sum"}, | |
449 {L"jum", false, 0, 0, L"um"}, | |
450 {L"alot", false, 0, 0, L"a lot"}, | |
451 // A regression test for Issue 36523. | |
452 {L"privliged", false, 0, 0, L"privileged"}, | |
453 // TODO (Sidchat): add many more examples. | |
454 }; | |
455 | |
456 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
457 std::vector<base::string16> suggestions; | |
458 size_t input_length = 0; | |
459 if (kTestCases[i].input != NULL) { | |
460 input_length = wcslen(kTestCases[i].input); | |
461 } | |
462 int misspelling_start; | |
463 int misspelling_length; | |
464 bool result = spell_check()->SpellCheckWord( | |
465 base::WideToUTF16(kTestCases[i].input).c_str(), | |
466 kNoOffset, | |
467 static_cast<int>(input_length), | |
468 kNoTag, | |
469 &misspelling_start, | |
470 &misspelling_length, | |
471 &suggestions); | |
472 | |
473 // Check for spelling. | |
474 EXPECT_EQ(kTestCases[i].expected_result, result); | |
475 | |
476 // Check if the suggested words occur. | |
477 bool suggested_word_is_present = false; | |
478 for (int j = 0; j < static_cast<int>(suggestions.size()); j++) { | |
479 if (suggestions.at(j).compare( | |
480 base::WideToUTF16(kTestCases[i].suggested_word)) == 0) { | |
481 suggested_word_is_present = true; | |
482 break; | |
483 } | |
484 } | |
485 | |
486 EXPECT_TRUE(suggested_word_is_present); | |
487 } | |
488 } | |
489 | |
490 // This test verifies our spellchecker can split a text into words and check | |
491 // the spelling of each word in the text. | |
492 #if defined(THREAD_SANITIZER) | |
493 // SpellCheckTest.SpellCheckText fails under ThreadSanitizer v2. | |
494 // See http://crbug.com/217909. | |
495 #define MAYBE_SpellCheckText DISABLED_SpellCheckText | |
496 #else | |
497 #define MAYBE_SpellCheckText SpellCheckText | |
498 #endif // THREAD_SANITIZER | |
499 TEST_F(SpellCheckTest, MAYBE_SpellCheckText) { | |
500 static const struct { | |
501 const char* language; | |
502 const wchar_t* input; | |
503 } kTestCases[] = { | |
504 { | |
505 // Afrikaans | |
506 "af-ZA", | |
507 L"Google se missie is om die w\x00EAreld se inligting te organiseer en " | |
508 L"dit bruikbaar en toeganklik te maak." | |
509 }, { | |
510 // Bulgarian | |
511 "bg-BG", | |
512 L"\x041c\x0438\x0441\x0438\x044f\x0442\x0430 " | |
513 L"\x043d\x0430 Google \x0435 \x0434\x0430 \x043e" | |
514 L"\x0440\x0433\x0430\x043d\x0438\x0437\x0438\x0440" | |
515 L"\x0430 \x0441\x0432\x0435\x0442\x043e\x0432" | |
516 L"\x043d\x0430\x0442\x0430 \x0438\x043d\x0444" | |
517 L"\x043e\x0440\x043c\x0430\x0446\x0438\x044f " | |
518 L"\x0438 \x0434\x0430 \x044f \x043d" | |
519 L"\x0430\x043f\x0440\x0430\x0432\x0438 \x0443" | |
520 L"\x043d\x0438\x0432\x0435\x0440\x0441\x0430\x043b" | |
521 L"\x043d\x043e \x0434\x043e\x0441\x0442\x044a" | |
522 L"\x043f\x043d\x0430 \x0438 \x043f\x043e" | |
523 L"\x043b\x0435\x0437\x043d\x0430." | |
524 }, { | |
525 // Catalan | |
526 "ca-ES", | |
527 L"La missi\x00F3 de Google \x00E9s organitzar la informaci\x00F3 " | |
528 L"del m\x00F3n i fer que sigui \x00FAtil i accessible universalment." | |
529 }, { | |
530 // Czech | |
531 "cs-CZ", | |
532 L"Posl\x00E1n\x00EDm spole\x010Dnosti Google je " | |
533 L"uspo\x0159\x00E1\x0064\x0061t informace z cel\x00E9ho sv\x011Bta " | |
534 L"tak, aby byly v\x0161\x0065obecn\x011B p\x0159\x00EDstupn\x00E9 " | |
535 L"a u\x017Eite\x010Dn\x00E9." | |
536 }, { | |
537 // Danish | |
538 "da-DK", | |
539 L"Googles " | |
540 L"mission er at organisere verdens information og g\x00F8re den " | |
541 L"almindeligt tilg\x00E6ngelig og nyttig." | |
542 }, { | |
543 // German | |
544 "de-DE", | |
545 L"Das Ziel von Google besteht darin, die auf der Welt vorhandenen " | |
546 L"Informationen zu organisieren und allgemein zug\x00E4nglich und " | |
547 L"nutzbar zu machen." | |
548 }, { | |
549 // Greek | |
550 "el-GR", | |
551 L"\x0391\x03C0\x03BF\x03C3\x03C4\x03BF\x03BB\x03AE " | |
552 L"\x03C4\x03B7\x03C2 Google \x03B5\x03AF\x03BD\x03B1\x03B9 " | |
553 L"\x03BD\x03B1 \x03BF\x03C1\x03B3\x03B1\x03BD\x03CE\x03BD\x03B5\x03B9 " | |
554 L"\x03C4\x03B9\x03C2 " | |
555 L"\x03C0\x03BB\x03B7\x03C1\x03BF\x03C6\x03BF\x03C1\x03AF\x03B5\x03C2 " | |
556 L"\x03C4\x03BF\x03C5 \x03BA\x03CC\x03C3\x03BC\x03BF\x03C5 " | |
557 L"\x03BA\x03B1\x03B9 \x03BD\x03B1 \x03C4\x03B9\x03C2 " | |
558 L"\x03BA\x03B1\x03B8\x03B9\x03C3\x03C4\x03AC " | |
559 L"\x03C0\x03C1\x03BF\x03C3\x03B2\x03AC\x03C3\x03B9\x03BC\x03B5\x03C2 " | |
560 L"\x03BA\x03B1\x03B9 \x03C7\x03C1\x03AE\x03C3\x03B9\x03BC\x03B5\x03C2." | |
561 }, { | |
562 // English (Australia) | |
563 "en-AU", | |
564 L"Google's mission is to organise the world's information and make it " | |
565 L"universally accessible and useful." | |
566 }, { | |
567 // English (Canada) | |
568 "en-CA", | |
569 L"Google's mission is to organize the world's information and make it " | |
570 L"universally accessible and useful." | |
571 }, { | |
572 // English (United Kingdom) | |
573 "en-GB", | |
574 L"Google's mission is to organise the world's information and make it " | |
575 L"universally accessible and useful." | |
576 }, { | |
577 // English (United States) | |
578 "en-US", | |
579 L"Google's mission is to organize the world's information and make it " | |
580 L"universally accessible and useful." | |
581 }, { | |
582 // Spanish | |
583 "es-ES", | |
584 L"La misi\x00F3n de " | |
585 // L"Google" - to be added. | |
586 L" es organizar la informaci\x00F3n mundial " | |
587 L"para que resulte universalmente accesible y \x00FAtil." | |
588 }, { | |
589 // Estonian | |
590 "et-EE", | |
591 // L"Google'ile " - to be added. | |
592 L"\x00FClesanne on korraldada maailma teavet ja teeb selle " | |
593 L"k\x00F5igile k\x00E4ttesaadavaks ja kasulikuks.", | |
594 }, { | |
595 // Persian | |
596 "fa", | |
597 L"\x0686\x0647 \x0637\x0648\x0631 \x0622\x06cc\x0627 \x0634\x0645\x0627 " | |
598 L"\x0627\x06cc\x0631\x0627\x0646\x06cc \x0647\x0633\x062a\x06cc\x062f" | |
599 }, { | |
600 // Faroese | |
601 "fo-FO", | |
602 L"Google er at samskipa alla vitan \x00ED heiminum og gera hana alment " | |
603 L"atkomiliga og n\x00FDtiliga." | |
604 }, { | |
605 // French | |
606 "fr-FR", | |
607 L"Google a pour mission d'organiser les informations \x00E0 " | |
608 L"l'\x00E9\x0063helle mondiale dans le but de les rendre accessibles " | |
609 L"et utiles \x00E0 tous." | |
610 }, { | |
611 // Hebrew | |
612 "he-IL", | |
613 L"\x05D4\x05DE\x05E9\x05D9\x05DE\x05D4 \x05E9\x05DC Google " | |
614 L"\x05D4\x05D9\x05D0 \x05DC\x05D0\x05E8\x05D2\x05DF " | |
615 L"\x05D0\x05EA \x05D4\x05DE\x05D9\x05D3\x05E2 " | |
616 L"\x05D4\x05E2\x05D5\x05DC\x05DE\x05D9 " | |
617 L"\x05D5\x05DC\x05D4\x05E4\x05D5\x05DA \x05D0\x05D5\x05EA\x05D5 " | |
618 L"\x05DC\x05D6\x05DE\x05D9\x05DF " | |
619 L"\x05D5\x05E9\x05D9\x05DE\x05D5\x05E9\x05D9 \x05D1\x05DB\x05DC " | |
620 L"\x05D4\x05E2\x05D5\x05DC\x05DD. " | |
621 // Two words with ASCII double/single quoation marks. | |
622 L"\x05DE\x05E0\x05DB\x0022\x05DC \x05E6\x0027\x05D9\x05E4\x05E1" | |
623 }, { | |
624 // Hindi | |
625 "hi-IN", | |
626 L"Google \x0915\x093E \x092E\x093F\x0936\x0928 " | |
627 L"\x0926\x0941\x0928\x093F\x092F\x093E \x0915\x0940 " | |
628 L"\x091C\x093E\x0928\x0915\x093E\x0930\x0940 \x0915\x094B " | |
629 L"\x0935\x094D\x092F\x0935\x0938\x094D\x0925\x093F\x0924 " | |
630 L"\x0915\x0930\x0928\x093E \x0914\x0930 \x0909\x0938\x0947 " | |
631 L"\x0938\x093E\x0930\x094D\x0935\x092D\x094C\x092E\x093F\x0915 " | |
632 L"\x0930\x0942\x092A \x0938\x0947 \x092A\x0939\x0941\x0901\x091A " | |
633 L"\x092E\x0947\x0902 \x0914\x0930 \x0909\x092A\x092F\x094B\x0917\x0940 " | |
634 L"\x092C\x0928\x093E\x0928\x093E \x0939\x0948." | |
635 }, { | |
636 // Hungarian | |
637 "hu-HU", | |
638 L"A Google azt a k\x00FCldet\x00E9st v\x00E1llalta mag\x00E1ra, " | |
639 L"hogy a vil\x00E1gon fellelhet\x0151 inform\x00E1\x0063i\x00F3kat " | |
640 L"rendszerezze \x00E9s \x00E1ltal\x00E1nosan el\x00E9rhet\x0151v\x00E9, " | |
641 L"illetve haszn\x00E1lhat\x00F3v\x00E1 tegye." | |
642 }, { | |
643 // Croatian | |
644 "hr-HR", | |
645 // L"Googleova " - to be added. | |
646 L"je misija organizirati svjetske informacije i u\x010Diniti ih " | |
647 // L"univerzalno " - to be added. | |
648 L"pristupa\x010Dnima i korisnima." | |
649 }, { | |
650 // Indonesian | |
651 "id-ID", | |
652 L"Misi Google adalah untuk mengelola informasi dunia dan membuatnya " | |
653 L"dapat diakses dan bermanfaat secara universal." | |
654 }, { | |
655 // Italian | |
656 "it-IT", | |
657 L"La missione di Google \x00E8 organizzare le informazioni a livello " | |
658 L"mondiale e renderle universalmente accessibili e fruibili." | |
659 }, { | |
660 // Lithuanian | |
661 "lt-LT", | |
662 L"\x201EGoogle\x201C tikslas \x2013 rinkti ir sisteminti pasaulio " | |
663 L"informacij\x0105 bei padaryti j\x0105 prieinam\x0105 ir " | |
664 L"nauding\x0105 visiems." | |
665 }, { | |
666 // Latvian | |
667 "lv-LV", | |
668 L"Google uzdevums ir k\x0101rtot pasaules inform\x0101" | |
669 L"ciju un padar\x012Bt to univers\x0101li pieejamu un noder\x012Bgu." | |
670 }, { | |
671 // Norwegian | |
672 "nb-NO", | |
673 // L"Googles " - to be added. | |
674 L"m\x00E5l er \x00E5 organisere informasjonen i verden og " | |
675 L"gj\x00F8re den tilgjengelig og nyttig for alle." | |
676 }, { | |
677 // Dutch | |
678 "nl-NL", | |
679 L"Het doel van Google is om alle informatie wereldwijd toegankelijk " | |
680 L"en bruikbaar te maken." | |
681 }, { | |
682 // Polish | |
683 "pl-PL", | |
684 L"Misj\x0105 Google jest uporz\x0105" L"dkowanie \x015Bwiatowych " | |
685 L"zasob\x00F3w informacji, aby sta\x0142y si\x0119 one powszechnie " | |
686 L"dost\x0119pne i u\x017Cyteczne." | |
687 }, { | |
688 // Portuguese (Brazil) | |
689 "pt-BR", | |
690 L"A miss\x00E3o do " | |
691 #if !defined(OS_MACOSX) | |
692 L"Google " | |
693 #endif | |
694 L"\x00E9 organizar as informa\x00E7\x00F5" | |
695 L"es do mundo todo e " | |
696 #if !defined(OS_MACOSX) | |
697 L"torn\x00E1-las " | |
698 #endif | |
699 L"acess\x00EDveis e \x00FAteis em car\x00E1ter universal." | |
700 }, { | |
701 // Portuguese (Portugal) | |
702 "pt-PT", | |
703 L"O " | |
704 #if !defined(OS_MACOSX) | |
705 L"Google " | |
706 #endif | |
707 L"tem por miss\x00E3o organizar a informa\x00E7\x00E3o do " | |
708 L"mundo e " | |
709 #if !defined(OS_MACOSX) | |
710 L"torn\x00E1-la " | |
711 #endif | |
712 L"universalmente acess\x00EDvel e \x00FAtil" | |
713 }, { | |
714 // Romanian | |
715 "ro-RO", | |
716 L"Misiunea Google este de a organiza informa\x021B3iile lumii \x0219i de " | |
717 L"a le face accesibile \x0219i utile la nivel universal." | |
718 }, { | |
719 // Russian | |
720 "ru-RU", | |
721 L"\x041C\x0438\x0441\x0441\x0438\x044F Google " | |
722 L"\x0441\x043E\x0441\x0442\x043E\x0438\x0442 \x0432 " | |
723 L"\x043E\x0440\x0433\x0430\x043D\x0438\x0437\x0430\x0446\x0438\x0438 " | |
724 L"\x043C\x0438\x0440\x043E\x0432\x043E\x0439 " | |
725 L"\x0438\x043D\x0444\x043E\x0440\x043C\x0430\x0446\x0438\x0438, " | |
726 L"\x043E\x0431\x0435\x0441\x043F\x0435\x0447\x0435\x043D\x0438\x0438 " | |
727 L"\x0435\x0435 " | |
728 L"\x0434\x043E\x0441\x0442\x0443\x043F\x043D\x043E\x0441\x0442\x0438 " | |
729 L"\x0438 \x043F\x043E\x043B\x044C\x0437\x044B \x0434\x043B\x044F " | |
730 L"\x0432\x0441\x0435\x0445." | |
731 // A Russian word including U+0451. (Bug 15558 <http://crbug.com/15558>) | |
732 L"\x0451\x043B\x043A\x0430" | |
733 }, { | |
734 // Serbo-Croatian (Serbian Latin) | |
735 "sh", | |
736 L"Google-ova misija je da organizuje sve informacije na svetu i " | |
737 L"u\x010dini ih univerzal-no dostupnim i korisnim." | |
738 }, { | |
739 // Serbian | |
740 "sr", | |
741 L"\x0047\x006f\x006f\x0067\x006c\x0065\x002d\x043e\x0432\x0430 " | |
742 L"\x043c\x0438\x0441\x0438\x0458\x0430 \x0458\x0435 \x0434\x0430 " | |
743 L"\x043e\x0440\x0433\x0430\x043d\x0438\x0437\x0443\x0458\x0435 " | |
744 L"\x0441\x0432\x0435 " | |
745 L"\x0438\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0438\x0458\x0435 " | |
746 L"\x043d\x0430 \x0441\x0432\x0435\x0442\x0443 \x0438 " | |
747 L"\x0443\x0447\x0438\x043d\x0438 \x0438\x0445 " | |
748 L"\x0443\x043d\x0438\x0432\x0435\x0440\x0437\x0430\x043b\x043d\x043e " | |
749 L"\x0434\x043e\x0441\x0442\x0443\x043f\x043d\x0438\x043c \x0438 " | |
750 L"\x043a\x043e\x0440\x0438\x0441\x043d\x0438\x043c." | |
751 }, { | |
752 // Slovak | |
753 "sk-SK", | |
754 L"Spolo\x010Dnos\x0165 Google si dala za \x00FAlohu usporiada\x0165 " | |
755 L"inform\x00E1\x0063ie " | |
756 L"z cel\x00E9ho sveta a zabezpe\x010Di\x0165, " | |
757 L"aby boli v\x0161eobecne dostupn\x00E9 a u\x017Eito\x010Dn\x00E9." | |
758 }, { | |
759 // Slovenian | |
760 "sl-SI", | |
761 // L"Googlovo " - to be added. | |
762 L"poslanstvo je organizirati svetovne informacije in " | |
763 L"omogo\x010Diti njihovo dostopnost in s tem uporabnost za vse." | |
764 }, { | |
765 // Swedish | |
766 "sv-SE", | |
767 L"Googles m\x00E5ls\x00E4ttning \x00E4r att ordna v\x00E4rldens " | |
768 L"samlade information och g\x00F6ra den tillg\x00E4nglig f\x00F6r alla." | |
769 }, { | |
770 // Turkish | |
771 "tr-TR", | |
772 // L"Google\x2019\x0131n " - to be added. | |
773 L"misyonu, d\x00FCnyadaki t\x00FCm bilgileri " | |
774 L"organize etmek ve evrensel olarak eri\x015Filebilir ve " | |
775 L"kullan\x0131\x015Fl\x0131 k\x0131lmakt\x0131r." | |
776 }, { | |
777 // Ukranian | |
778 "uk-UA", | |
779 L"\x041c\x0456\x0441\x0456\x044f " | |
780 L"\x043a\x043e\x043c\x043f\x0430\x043d\x0456\x0457 Google " | |
781 L"\x043f\x043e\x043b\x044f\x0433\x0430\x0454 \x0432 " | |
782 L"\x0442\x043e\x043c\x0443, \x0449\x043e\x0431 " | |
783 L"\x0443\x043f\x043e\x0440\x044f\x0434\x043a\x0443\x0432\x0430\x0442" | |
784 L"\x0438 \x0456\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0456\x044e " | |
785 L"\x0437 \x0443\x0441\x044c\x043e\x0433\x043e " | |
786 L"\x0441\x0432\x0456\x0442\x0443 \x0442\x0430 " | |
787 L"\x0437\x0440\x043e\x0431\x0438\x0442\x0438 \x0457\x0457 " | |
788 L"\x0443\x043d\x0456\x0432\x0435\x0440\x0441\x0430\x043b\x044c\x043d" | |
789 L"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e " | |
790 L"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e." | |
791 }, { | |
792 // Vietnamese | |
793 "vi-VN", | |
794 L"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 " | |
795 L"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 " | |
796 L"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 " | |
797 L"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 " | |
798 L"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n." | |
799 }, { | |
800 // Korean | |
801 "ko", | |
802 L"Google\xC758 \xBAA9\xD45C\xB294 \xC804\xC138\xACC4\xC758 " | |
803 L"\xC815\xBCF4\xB97C \xCCB4\xACC4\xD654\xD558\xC5EC \xBAA8\xB450\xAC00 " | |
804 L"\xD3B8\xB9AC\xD558\xAC8C \xC774\xC6A9\xD560 \xC218 " | |
805 L"\xC788\xB3C4\xB85D \xD558\xB294 \xAC83\xC785\xB2C8\xB2E4." | |
806 }, { | |
807 // Albanian | |
808 "sq", | |
809 L"Misioni i Google \x00EBsht\x00EB q\x00EB t\x00EB organizoj\x00EB " | |
810 L"informacionin e bot\x00EBs dhe t\x00EB b\x00EBjn\x00EB at\x00EB " | |
811 L"universalisht t\x00EB arritshme dhe t\x00EB dobishme." | |
812 }, { | |
813 // Tamil | |
814 "ta", | |
815 L"Google \x0B87\x0BA9\x0BCD " | |
816 L"\x0BA8\x0BC7\x0BBE\x0B95\x0BCD\x0B95\x0BAE\x0BCD " | |
817 L"\x0B89\x0BB2\x0B95\x0BBF\x0BA9\x0BCD \x0BA4\x0B95\x0BB5\x0BB2\x0BCD " | |
818 L"\x0B8F\x0BB1\x0BCD\x0BAA\x0BBE\x0B9F\x0BC1 \x0B87\x0BA4\x0BC1 " | |
819 L"\x0B89\x0BB2\x0B95\x0BB3\x0BBE\x0BB5\x0BBF\x0BAF " | |
820 L"\x0B85\x0BA3\x0BC1\x0B95\x0B95\x0BCD \x0B95\x0BC2\x0B9F\x0BBF\x0BAF " | |
821 L"\x0BAE\x0BB1\x0BCD\x0BB1\x0BC1\x0BAE\x0BCD " | |
822 L"\x0BAA\x0BAF\x0BA9\x0BC1\x0BB3\x0BCD\x0BB3 " | |
823 L"\x0B9A\x0BC6\x0BAF\x0BCD\x0BAF \x0B89\x0BB3\x0BCD\x0BB3\x0BA4\x0BC1." | |
824 }, { | |
825 // Tajik | |
826 "tg", | |
827 L"\x041c\x0438\x0441\x0441\x0438\x044f\x0438 Google \x0438\x043d " | |
828 L"\x043c\x0443\x0440\x0430\x0442\x0442\x0430\x0431 " | |
829 L"\x0441\x043e\x0445\x0442\x0430\x043d\x0438 " | |
830 L"\x043c\x0430\x044a\x043b\x0443\x043c\x043e\x0442\x04b3\x043e\x0438 " | |
831 L"\x043c\x0430\x0432\x04b7\x0443\x0434\x0430, \x043e\x0441\x043e\x043d " | |
832 L"\x043d\x0430\x043c\x0443\x0434\x0430\x043d\x0438 " | |
833 L"\x0438\x0441\x0442\x0438\x0444\x043e\x0434\x0430\x0431\x0430\x0440" | |
834 L"\x04e3 \x0432\x0430 \x0434\x0430\x0441\x0442\x0440\x0430\x0441\x0438 " | |
835 L"\x0443\x043c\x0443\x043c " | |
836 L"\x0433\x0430\x0440\x0434\x043e\x043d\x0438\x0434\x0430\x043d\x0438 " | |
837 L"\x043e\x043d\x04b3\x043e \x0430\x0441\x0442." | |
838 }, | |
839 }; | |
840 | |
841 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
842 ReinitializeSpellCheck(kTestCases[i].language); | |
843 size_t input_length = 0; | |
844 if (kTestCases[i].input != NULL) | |
845 input_length = wcslen(kTestCases[i].input); | |
846 | |
847 int misspelling_start = 0; | |
848 int misspelling_length = 0; | |
849 bool result = spell_check()->SpellCheckWord( | |
850 base::WideToUTF16(kTestCases[i].input).c_str(), | |
851 kNoOffset, | |
852 static_cast<int>(input_length), | |
853 kNoTag, | |
854 &misspelling_start, | |
855 &misspelling_length, NULL); | |
856 | |
857 EXPECT_TRUE(result) | |
858 << "\"" | |
859 << std::wstring(kTestCases[i].input).substr( | |
860 misspelling_start, misspelling_length) | |
861 << "\" is misspelled in " | |
862 << kTestCases[i].language | |
863 << "."; | |
864 EXPECT_EQ(0, misspelling_start); | |
865 EXPECT_EQ(0, misspelling_length); | |
866 } | |
867 } | |
868 | |
869 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks | |
870 // misspelled words. | |
871 TEST_F(SpellCheckTest, MisspelledWords) { | |
872 static const struct { | |
873 const char* language; | |
874 const wchar_t* input; | |
875 } kTestCases[] = { | |
876 { | |
877 // A misspelled word for English | |
878 "en-US", | |
879 L"aaaaaaaaaa", | |
880 }, { | |
881 // A misspelled word for Greek. | |
882 "el-GR", | |
883 L"\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1", | |
884 }, { | |
885 // A misspelled word for Persian. | |
886 "fa", | |
887 L"\x06cc\x06a9\x06cc\x0634\x0627\x0646", | |
888 }, { | |
889 // A misspelled word for Hebrew | |
890 "he-IL", | |
891 L"\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0", | |
892 }, { | |
893 // Hindi | |
894 "hi-IN", | |
895 L"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905", | |
896 }, { | |
897 // A misspelled word for Russian | |
898 "ru-RU", | |
899 L"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430", | |
900 }, | |
901 }; | |
902 | |
903 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
904 ReinitializeSpellCheck(kTestCases[i].language); | |
905 | |
906 base::string16 word(base::WideToUTF16(kTestCases[i].input)); | |
907 int word_length = static_cast<int>(word.length()); | |
908 int misspelling_start = 0; | |
909 int misspelling_length = 0; | |
910 bool result = spell_check()->SpellCheckWord(word.c_str(), | |
911 kNoOffset, | |
912 word_length, | |
913 kNoTag, | |
914 &misspelling_start, | |
915 &misspelling_length, | |
916 NULL); | |
917 EXPECT_FALSE(result); | |
918 EXPECT_EQ(0, misspelling_start); | |
919 EXPECT_EQ(word_length, misspelling_length); | |
920 } | |
921 } | |
922 | |
923 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac, | |
924 // we skip these SpellCheckParagraph tests on Mac. | |
925 #if !defined(OS_MACOSX) | |
926 | |
927 // Make sure SpellCheckParagraph does not crash if the input is empty. | |
928 TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) { | |
929 std::vector<SpellCheckResult> expected; | |
930 TestSpellCheckParagraph(base::UTF8ToUTF16(""), expected); | |
931 } | |
932 | |
933 // A simple test case having no misspellings. | |
934 TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) { | |
935 const base::string16 text = base::UTF8ToUTF16("apple"); | |
936 std::vector<SpellCheckResult> expected; | |
937 TestSpellCheckParagraph(text, expected); | |
938 } | |
939 | |
940 // A simple test case having one misspelling. | |
941 TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) { | |
942 const base::string16 text = base::UTF8ToUTF16("zz"); | |
943 std::vector<SpellCheckResult> expected; | |
944 expected.push_back(SpellCheckResult( | |
945 SpellCheckResult::SPELLING, 0, 2)); | |
946 | |
947 TestSpellCheckParagraph(text, expected); | |
948 } | |
949 | |
950 // A simple test case having multiple misspellings. | |
951 TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) { | |
952 const base::string16 text = base::UTF8ToUTF16("zz, zz"); | |
953 std::vector<SpellCheckResult> expected; | |
954 expected.push_back(SpellCheckResult( | |
955 SpellCheckResult::SPELLING, 0, 2)); | |
956 expected.push_back(SpellCheckResult( | |
957 SpellCheckResult::SPELLING, 4, 2)); | |
958 | |
959 TestSpellCheckParagraph(text, expected); | |
960 } | |
961 | |
962 // Make sure a relatively long (correct) sentence can be spellchecked. | |
963 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) { | |
964 std::vector<SpellCheckResult> expected; | |
965 // The text is taken from US constitution preamble. | |
966 const base::string16 text = base::UTF8ToUTF16( | |
967 "We the people of the United States, in order to form a more perfect " | |
968 "union, establish justice, insure domestic tranquility, provide for " | |
969 "the common defense, promote the general welfare, and secure the " | |
970 "blessings of liberty to ourselves and our posterity, do ordain and " | |
971 "establish this Constitution for the United States of America."); | |
972 | |
973 TestSpellCheckParagraph(text, expected); | |
974 } | |
975 | |
976 // Make sure all misspellings can be found in a relatively long sentence. | |
977 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) { | |
978 std::vector<SpellCheckResult> expected; | |
979 | |
980 // All 'the' are converted to 'hte' in US consitition preamble. | |
981 const base::string16 text = base::UTF8ToUTF16( | |
982 "We hte people of hte United States, in order to form a more perfect " | |
983 "union, establish justice, insure domestic tranquility, provide for " | |
984 "hte common defense, promote hte general welfare, and secure hte " | |
985 "blessings of liberty to ourselves and our posterity, do ordain and " | |
986 "establish this Constitution for hte United States of America."); | |
987 | |
988 expected.push_back(SpellCheckResult( | |
989 SpellCheckResult::SPELLING, 3, 3)); | |
990 expected.push_back(SpellCheckResult( | |
991 SpellCheckResult::SPELLING, 17, 3)); | |
992 expected.push_back(SpellCheckResult( | |
993 SpellCheckResult::SPELLING, 135, 3)); | |
994 expected.push_back(SpellCheckResult( | |
995 SpellCheckResult::SPELLING, 163, 3)); | |
996 expected.push_back(SpellCheckResult( | |
997 SpellCheckResult::SPELLING, 195, 3)); | |
998 expected.push_back(SpellCheckResult( | |
999 SpellCheckResult::SPELLING, 298, 3)); | |
1000 | |
1001 TestSpellCheckParagraph(text, expected); | |
1002 } | |
1003 | |
1004 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker | |
1005 // is used on Mac instead of SpellCheck::RequestTextChecking. | |
1006 | |
1007 // Make sure RequestTextChecking does not crash if input is empty. | |
1008 TEST_F(SpellCheckTest, RequestSpellCheckWithEmptyString) { | |
1009 MockTextCheckingCompletion completion; | |
1010 | |
1011 spell_check()->RequestTextChecking(base::string16(), &completion); | |
1012 | |
1013 base::RunLoop().RunUntilIdle(); | |
1014 | |
1015 EXPECT_EQ(completion.completion_count_, 1U); | |
1016 } | |
1017 | |
1018 // A simple test case having no misspellings. | |
1019 TEST_F(SpellCheckTest, RequestSpellCheckWithoutMisspelling) { | |
1020 MockTextCheckingCompletion completion; | |
1021 | |
1022 const base::string16 text = base::ASCIIToUTF16("hello"); | |
1023 spell_check()->RequestTextChecking(text, &completion); | |
1024 | |
1025 base::RunLoop().RunUntilIdle(); | |
1026 | |
1027 EXPECT_EQ(completion.completion_count_, 1U); | |
1028 } | |
1029 | |
1030 // A simple test case having one misspelling. | |
1031 TEST_F(SpellCheckTest, RequestSpellCheckWithSingleMisspelling) { | |
1032 MockTextCheckingCompletion completion; | |
1033 | |
1034 const base::string16 text = base::ASCIIToUTF16("apple, zz"); | |
1035 spell_check()->RequestTextChecking(text, &completion); | |
1036 | |
1037 base::RunLoop().RunUntilIdle(); | |
1038 | |
1039 EXPECT_EQ(completion.completion_count_, 1U); | |
1040 EXPECT_EQ(completion.last_results_.size(), 1U); | |
1041 EXPECT_EQ(completion.last_results_[0].location, 7); | |
1042 EXPECT_EQ(completion.last_results_[0].length, 2); | |
1043 } | |
1044 | |
1045 // A simple test case having a few misspellings. | |
1046 TEST_F(SpellCheckTest, RequestSpellCheckWithMisspellings) { | |
1047 MockTextCheckingCompletion completion; | |
1048 | |
1049 const base::string16 text = base::ASCIIToUTF16("apple, zz, orange, zz"); | |
1050 spell_check()->RequestTextChecking(text, &completion); | |
1051 | |
1052 base::RunLoop().RunUntilIdle(); | |
1053 | |
1054 EXPECT_EQ(completion.completion_count_, 1U); | |
1055 EXPECT_EQ(completion.last_results_.size(), 2U); | |
1056 EXPECT_EQ(completion.last_results_[0].location, 7); | |
1057 EXPECT_EQ(completion.last_results_[0].length, 2); | |
1058 EXPECT_EQ(completion.last_results_[1].location, 19); | |
1059 EXPECT_EQ(completion.last_results_[1].length, 2); | |
1060 } | |
1061 | |
1062 // A test case that multiple requests comes at once. Make sure all | |
1063 // requests are processed. | |
1064 TEST_F(SpellCheckTest, RequestSpellCheckWithMultipleRequests) { | |
1065 MockTextCheckingCompletion completion[3]; | |
1066 | |
1067 const base::string16 text[3] = { | |
1068 base::ASCIIToUTF16("what, zz"), | |
1069 base::ASCIIToUTF16("apple, zz"), | |
1070 base::ASCIIToUTF16("orange, zz") | |
1071 }; | |
1072 | |
1073 for (int i = 0; i < 3; ++i) | |
1074 spell_check()->RequestTextChecking(text[i], &completion[i]); | |
1075 | |
1076 base::RunLoop().RunUntilIdle(); | |
1077 | |
1078 for (int i = 0; i < 3; ++i) { | |
1079 EXPECT_EQ(completion[i].completion_count_, 1U); | |
1080 EXPECT_EQ(completion[i].last_results_.size(), 1U); | |
1081 EXPECT_EQ(completion[i].last_results_[0].location, 6 + i); | |
1082 EXPECT_EQ(completion[i].last_results_[0].length, 2); | |
1083 } | |
1084 } | |
1085 | |
1086 // A test case that spellchecking is requested before initializing. | |
1087 // In this case, we postpone to post a request. | |
1088 TEST_F(SpellCheckTest, RequestSpellCheckWithoutInitialization) { | |
1089 UninitializeSpellCheck(); | |
1090 | |
1091 MockTextCheckingCompletion completion; | |
1092 const base::string16 text = base::ASCIIToUTF16("zz"); | |
1093 | |
1094 spell_check()->RequestTextChecking(text, &completion); | |
1095 | |
1096 // The task will not be posted yet. | |
1097 base::RunLoop().RunUntilIdle(); | |
1098 EXPECT_EQ(completion.completion_count_, 0U); | |
1099 } | |
1100 | |
1101 // Requests several spellchecking before initializing. Except the last one, | |
1102 // posting requests is cancelled and text is rendered as correct one. | |
1103 TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) { | |
1104 UninitializeSpellCheck(); | |
1105 | |
1106 MockTextCheckingCompletion completion[3]; | |
1107 const base::string16 text[3] = { | |
1108 base::ASCIIToUTF16("what, zz"), | |
1109 base::ASCIIToUTF16("apple, zz"), | |
1110 base::ASCIIToUTF16("orange, zz") | |
1111 }; | |
1112 | |
1113 // Calls RequestTextchecking a few times. | |
1114 for (int i = 0; i < 3; ++i) | |
1115 spell_check()->RequestTextChecking(text[i], &completion[i]); | |
1116 | |
1117 // The last task will be posted after initialization, however the other | |
1118 // requests should be pressed without spellchecking. | |
1119 base::RunLoop().RunUntilIdle(); | |
1120 for (int i = 0; i < 2; ++i) | |
1121 EXPECT_EQ(completion[i].completion_count_, 1U); | |
1122 EXPECT_EQ(completion[2].completion_count_, 0U); | |
1123 | |
1124 // Checks the last request is processed after initialization. | |
1125 InitializeSpellCheck("en-US"); | |
1126 | |
1127 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity. | |
1128 spell_check()->PostDelayedSpellCheckTask( | |
1129 spell_check()->pending_request_param_.release()); | |
1130 base::RunLoop().RunUntilIdle(); | |
1131 for (int i = 0; i < 3; ++i) | |
1132 EXPECT_EQ(completion[i].completion_count_, 1U); | |
1133 } | |
1134 | |
1135 #endif | |
1136 | |
1137 // Verify that the SpellCheck class keeps the spelling marker added to a | |
1138 // misspelled word "zz". | |
1139 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsMarkers) { | |
1140 base::string16 text = base::ASCIIToUTF16("zz"); | |
1141 std::vector<SpellCheckResult> spellcheck_results; | |
1142 spellcheck_results.push_back( | |
1143 SpellCheckResult(SpellCheckResult::SPELLING, 0, 2, base::string16())); | |
1144 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | |
1145 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | |
1146 text, spellcheck_results, | |
1147 &textcheck_results); | |
1148 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); | |
1149 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, | |
1150 textcheck_results[0].decoration); | |
1151 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | |
1152 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | |
1153 } | |
1154 | |
1155 // Verify that the SpellCheck class replaces the spelling marker added to a | |
1156 // contextually-misspelled word "bean" with a grammar marker. | |
1157 TEST_F(SpellCheckTest, CreateTextCheckingResultsAddsGrammarMarkers) { | |
1158 base::string16 text = base::ASCIIToUTF16("I have bean to USA."); | |
1159 std::vector<SpellCheckResult> spellcheck_results; | |
1160 spellcheck_results.push_back( | |
1161 SpellCheckResult(SpellCheckResult::SPELLING, 7, 4, base::string16())); | |
1162 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | |
1163 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | |
1164 text, spellcheck_results, | |
1165 &textcheck_results); | |
1166 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); | |
1167 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, | |
1168 textcheck_results[0].decoration); | |
1169 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | |
1170 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | |
1171 } | |
1172 | |
1173 // Verify that the SpellCheck preserves the original apostrophe type in the | |
1174 // checked text, regardless of the type of apostrophe the browser returns. | |
1175 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsTypographicalApostrophe) { | |
1176 base::string16 text = base::WideToUTF16( | |
1177 L"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L"t ni'n" | |
1178 TYPOGRAPHICAL_APOSTROPHE L"out-s I've I" TYPOGRAPHICAL_APOSTROPHE | |
1179 L"ve"); | |
1180 std::vector<SpellCheckResult> spellcheck_results; | |
1181 | |
1182 // All typewriter apostrophe results. | |
1183 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 0, | |
1184 5, base::UTF8ToUTF16("I've"))); | |
1185 spellcheck_results.push_back(SpellCheckResult( | |
1186 SpellCheckResult::SPELLING, 6, 6, base::UTF8ToUTF16("haven't"))); | |
1187 spellcheck_results.push_back(SpellCheckResult( | |
1188 SpellCheckResult::SPELLING, 13, 10, base::UTF8ToUTF16("in'n'out's"))); | |
1189 | |
1190 // Replacements that differ only by apostrophe type should be ignored. | |
1191 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 24, | |
1192 4, base::UTF8ToUTF16("I've"))); | |
1193 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 29, | |
1194 4, base::UTF8ToUTF16("I've"))); | |
1195 | |
1196 // All typographical apostrophe results. | |
1197 spellcheck_results.push_back( | |
1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5, | |
1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | |
1200 spellcheck_results.push_back(SpellCheckResult( | |
1201 SpellCheckResult::SPELLING, 6, 6, | |
1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"))); | |
1203 spellcheck_results.push_back(SpellCheckResult( | |
1204 SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16( | |
1205 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out" | |
1206 TYPOGRAPHICAL_APOSTROPHE L"s"))); | |
1207 | |
1208 // Replacements that differ only by apostrophe type should be ignored. | |
1209 spellcheck_results.push_back( | |
1210 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4, | |
1211 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | |
1212 spellcheck_results.push_back( | |
1213 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4, | |
1214 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | |
1215 | |
1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | |
1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | |
1218 text, spellcheck_results, | |
1219 &textcheck_results); | |
1220 | |
1221 static const wchar_t* kExpectedReplacements[] = { | |
1222 L"I've", | |
1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | |
1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", | |
1225 L"I've", | |
1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | |
1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", | |
1228 }; | |
1229 | |
1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); | |
1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { | |
1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), | |
1233 textcheck_results[i].replacement) | |
1234 << "i=" << i << "\nactual: \"" | |
1235 << base::string16(textcheck_results[i].replacement) << "\""; | |
1236 } | |
1237 } | |
1238 | |
1239 // Checks some words that should be present in all English dictionaries. | |
1240 TEST_F(SpellCheckTest, EnglishWords) { | |
1241 static const struct { | |
1242 const char* input; | |
1243 bool should_pass; | |
1244 } kTestCases[] = { | |
1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking | |
1246 // dictionary. | |
1247 {"Chromebook", true}, | |
1248 {"Chromebooks", true}, | |
1249 {"Chromebox", true}, | |
1250 {"Chromeboxes", true}, | |
1251 {"Chromeblade", true}, | |
1252 {"Chromeblades", true}, | |
1253 {"Chromebase", true}, | |
1254 {"Chromebases", true}, | |
1255 // Issue 94708: Spell-checker incorrectly reports whisky as misspelled. | |
1256 {"whisky", true}, | |
1257 {"whiskey", true}, | |
1258 {"whiskies", true}, | |
1259 // Issue 98678: "Recency" should be included in client-side dictionary. | |
1260 {"recency", true}, | |
1261 {"recencies", false}, | |
1262 // Issue 140486 | |
1263 {"movie", true}, | |
1264 {"movies", true}, | |
1265 }; | |
1266 | |
1267 static const char* const kLocales[] = { "en-GB", "en-US", "en-CA", "en-AU" }; | |
1268 | |
1269 for (size_t j = 0; j < arraysize(kLocales); ++j) { | |
1270 ReinitializeSpellCheck(kLocales[j]); | |
1271 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
1272 size_t input_length = 0; | |
1273 if (kTestCases[i].input != NULL) | |
1274 input_length = strlen(kTestCases[i].input); | |
1275 | |
1276 int misspelling_start = 0; | |
1277 int misspelling_length = 0; | |
1278 bool result = spell_check()->SpellCheckWord( | |
1279 base::ASCIIToUTF16(kTestCases[i].input).c_str(), | |
1280 kNoOffset, | |
1281 static_cast<int>(input_length), | |
1282 kNoTag, | |
1283 &misspelling_start, | |
1284 &misspelling_length, NULL); | |
1285 | |
1286 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << | |
1287 " in " << kLocales[j]; | |
1288 } | |
1289 } | |
1290 } | |
1291 | |
1292 // Checks that NOSUGGEST works in English dictionaries. | |
1293 TEST_F(SpellCheckTest, NoSuggest) { | |
1294 static const struct { | |
1295 const char* input; | |
1296 const char* suggestion; | |
1297 const char* locale; | |
1298 bool should_pass; | |
1299 } kTestCases[] = { | |
1300 {"suckerbert", "cocksucker", "en-GB", true}, | |
1301 {"suckerbert", "cocksucker", "en-US", true}, | |
1302 {"suckerbert", "cocksucker", "en-CA", true}, | |
1303 {"suckerbert", "cocksucker", "en-AU", true}, | |
1304 {"suckerbert", "cocksuckers", "en-GB", true}, | |
1305 {"suckerbert", "cocksuckers", "en-US", true}, | |
1306 {"suckerbert", "cocksuckers", "en-CA", true}, | |
1307 {"suckerbert", "cocksuckers", "en-AU", true}, | |
1308 {"Batasunaa", "Batasuna", "ca-ES", true}, | |
1309 {"pornoo", "porno", "it-IT", true}, | |
1310 {"catass", "catas", "lt-LT", true}, | |
1311 {"kuracc", "kurac", "sl-SI", true}, | |
1312 {"pittt", "pitt", "sv-SE", true}, | |
1313 }; | |
1314 | |
1315 size_t test_cases_size = arraysize(kTestCases); | |
1316 for (size_t i = 0; i < test_cases_size; ++i) { | |
1317 ReinitializeSpellCheck(kTestCases[i].locale); | |
1318 size_t suggestion_length = 0; | |
1319 if (kTestCases[i].suggestion != NULL) | |
1320 suggestion_length = strlen(kTestCases[i].suggestion); | |
1321 | |
1322 // First check that the NOSUGGEST flag didn't mark this word as not being in | |
1323 // the dictionary. | |
1324 int misspelling_start = 0; | |
1325 int misspelling_length = 0; | |
1326 bool result = spell_check()->SpellCheckWord( | |
1327 base::ASCIIToUTF16(kTestCases[i].suggestion).c_str(), | |
1328 kNoOffset, | |
1329 static_cast<int>(suggestion_length), | |
1330 kNoTag, | |
1331 &misspelling_start, | |
1332 &misspelling_length, NULL); | |
1333 | |
1334 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].suggestion << | |
1335 " in " << kTestCases[i].locale; | |
1336 | |
1337 // Now verify that this test case does not show up as a suggestion. | |
1338 std::vector<base::string16> suggestions; | |
1339 size_t input_length = 0; | |
1340 if (kTestCases[i].input != NULL) | |
1341 input_length = strlen(kTestCases[i].input); | |
1342 result = spell_check()->SpellCheckWord( | |
1343 base::ASCIIToUTF16(kTestCases[i].input).c_str(), | |
1344 kNoOffset, | |
1345 static_cast<int>(input_length), | |
1346 kNoTag, | |
1347 &misspelling_start, | |
1348 &misspelling_length, | |
1349 &suggestions); | |
1350 // Input word should be a misspelling. | |
1351 EXPECT_FALSE(result) << kTestCases[i].input | |
1352 << " is not a misspelling in " | |
1353 << kTestCases[i].locale; | |
1354 // Check if the suggested words occur. | |
1355 for (int j = 0; j < static_cast<int>(suggestions.size()); j++) { | |
1356 for (size_t t = 0; t < test_cases_size; t++) { | |
1357 int compare_result = suggestions.at(j).compare( | |
1358 base::ASCIIToUTF16(kTestCases[t].suggestion)); | |
1359 EXPECT_FALSE(compare_result == 0) << kTestCases[t].suggestion << | |
1360 " in " << kTestCases[i].locale; | |
1361 } | |
1362 } | |
1363 } | |
1364 } | |
1365 | |
1366 // Check that the correct dictionary files are checked in. | |
1367 TEST_F(SpellCheckTest, DictionaryFiles) { | |
1368 std::vector<std::string> spellcheck_languages; | |
1369 spellcheck::SpellCheckLanguages(&spellcheck_languages); | |
1370 EXPECT_FALSE(spellcheck_languages.empty()); | |
1371 | |
1372 base::FilePath hunspell = GetHunspellDirectory(); | |
1373 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { | |
1374 base::FilePath dict = | |
1375 spellcheck::GetVersionedFileName(spellcheck_languages[i], hunspell); | |
1376 EXPECT_TRUE(base::PathExists(dict)) << dict.value() << " not found"; | |
1377 } | |
1378 } | |
1379 | |
1380 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded. | |
1381 TEST_F(SpellCheckTest, SpellingEngine_CheckSpelling) { | |
1382 static const struct { | |
1383 const char* word; | |
1384 bool expected_result; | |
1385 } kTestCases[] = { | |
1386 { "", true }, | |
1387 { "automatic", true }, | |
1388 { "hello", true }, | |
1389 { "forglobantic", false }, | |
1390 { "xfdssfsdfaasds", false }, | |
1391 { // 64 chars are the longest word to check - this should fail checking. | |
1392 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", | |
1393 false | |
1394 }, | |
1395 { // Any word longer than 64 chars should be exempt from checking. | |
1396 "reallylongwordthatabsolutelyexceedsthespecifiedcharacterlimitabit", | |
1397 true | |
1398 } | |
1399 }; | |
1400 | |
1401 // Initialization magic - call InitializeIfNeeded twice. The first one simply | |
1402 // flags internal state that a dictionary was requested. The second one will | |
1403 // take the passed-in file and initialize hunspell with it. (The file was | |
1404 // passed to hunspell in the ctor for the test fixture). | |
1405 // This needs to be done since we need to ensure the SpellingEngine objects | |
1406 // contained in the SpellcheckLanguages in |languages_| from the test fixture | |
1407 // does get initialized. | |
1408 // TODO(groby): Clean up this mess. | |
1409 InitializeIfNeeded(); | |
1410 ASSERT_FALSE(InitializeIfNeeded()); | |
1411 | |
1412 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
1413 bool result = CheckSpelling(kTestCases[i].word, 0); | |
1414 EXPECT_EQ(kTestCases[i].expected_result, result) << | |
1415 "Failed test for " << kTestCases[i].word; | |
1416 } | |
1417 } | |
1418 | |
1419 // Chrome should not suggest "Othello" for "hellllo" or "identically" for | |
1420 // "accidently". | |
1421 TEST_F(SpellCheckTest, LogicalSuggestions) { | |
1422 static const struct { | |
1423 const char* misspelled; | |
1424 const char* suggestion; | |
1425 } kTestCases[] = { | |
1426 { "hellllo", "hello" }, | |
1427 { "accidently", "accidentally" } | |
1428 }; | |
1429 | |
1430 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
1431 int misspelling_start = 0; | |
1432 int misspelling_length = 0; | |
1433 std::vector<base::string16> suggestions; | |
1434 EXPECT_FALSE(spell_check()->SpellCheckWord( | |
1435 base::ASCIIToUTF16(kTestCases[i].misspelled).c_str(), | |
1436 kNoOffset, | |
1437 strlen(kTestCases[i].misspelled), | |
1438 kNoTag, | |
1439 &misspelling_start, | |
1440 &misspelling_length, | |
1441 &suggestions)); | |
1442 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); | |
1443 if (suggestions.size() > 0) | |
1444 EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion)); | |
1445 } | |
1446 } | |
1447 | |
1448 // Words with apostrophes should be valid contractions. | |
1449 TEST_F(SpellCheckTest, IsValidContraction) { | |
1450 static const char* kLanguages[] = { | |
1451 "en-AU", | |
1452 "en-CA", | |
1453 "en-GB", | |
1454 "en-US", | |
1455 }; | |
1456 | |
1457 static const wchar_t* kWords[] = { | |
1458 L"in'n'out", | |
1459 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out", | |
1460 }; | |
1461 | |
1462 for (size_t i = 0; i < arraysize(kLanguages); ++i) { | |
1463 ReinitializeSpellCheck(kLanguages[i]); | |
1464 for (size_t j = 0; j < arraysize(kWords); ++j) | |
1465 EXPECT_TRUE(IsValidContraction(base::WideToUTF16(kWords[j]), 0)); | |
1466 } | |
1467 } | |
1468 | |
1469 TEST_F(SpellCheckTest, FillSuggestions_OneLanguageNoSuggestions) { | |
1470 std::vector<std::vector<base::string16>> suggestions_list; | |
1471 std::vector<base::string16> suggestion_results; | |
1472 | |
1473 suggestions_list.resize(1); | |
1474 | |
1475 FillSuggestions(suggestions_list, &suggestion_results); | |
1476 EXPECT_TRUE(suggestion_results.empty()); | |
1477 } | |
1478 | |
1479 TEST_F(SpellCheckTest, FillSuggestions_OneLanguageFewSuggestions) { | |
1480 std::vector<std::vector<base::string16>> suggestions_list; | |
1481 std::vector<base::string16> suggestion_results; | |
1482 | |
1483 suggestions_list.resize(1); | |
1484 suggestions_list[0].push_back(base::ASCIIToUTF16("foo")); | |
1485 | |
1486 FillSuggestions(suggestions_list, &suggestion_results); | |
1487 ASSERT_EQ(1U, suggestion_results.size()); | |
1488 EXPECT_EQ(base::ASCIIToUTF16("foo"), suggestion_results[0]); | |
1489 } | |
1490 | |
1491 TEST_F(SpellCheckTest, FillSuggestions_OneLanguageManySuggestions) { | |
1492 std::vector<std::vector<base::string16>> suggestions_list; | |
1493 std::vector<base::string16> suggestion_results; | |
1494 | |
1495 suggestions_list.resize(1); | |
1496 for (int i = 0; i < spellcheck::kMaxSuggestions + 2; ++i) | |
1497 suggestions_list[0].push_back(base::ASCIIToUTF16(base::IntToString(i))); | |
1498 | |
1499 FillSuggestions(suggestions_list, &suggestion_results); | |
1500 ASSERT_EQ(static_cast<size_t>(spellcheck::kMaxSuggestions), | |
1501 suggestion_results.size()); | |
1502 for (int i = 0; i < spellcheck::kMaxSuggestions; ++i) | |
1503 EXPECT_EQ(base::ASCIIToUTF16(base::IntToString(i)), suggestion_results[i]); | |
1504 } | |
1505 | |
1506 TEST_F(SpellCheckTest, FillSuggestions_RemoveDuplicates) { | |
1507 std::vector<std::vector<base::string16>> suggestions_list; | |
1508 std::vector<base::string16> suggestion_results; | |
1509 | |
1510 suggestions_list.resize(2); | |
1511 for (size_t i = 0; i < 2; ++i) { | |
1512 suggestions_list[i].push_back(base::ASCIIToUTF16("foo")); | |
1513 suggestions_list[i].push_back(base::ASCIIToUTF16("bar")); | |
1514 suggestions_list[i].push_back(base::ASCIIToUTF16("baz")); | |
1515 } | |
1516 | |
1517 FillSuggestions(suggestions_list, &suggestion_results); | |
1518 ASSERT_EQ(3U, suggestion_results.size()); | |
1519 EXPECT_EQ(base::ASCIIToUTF16("foo"), suggestion_results[0]); | |
1520 EXPECT_EQ(base::ASCIIToUTF16("bar"), suggestion_results[1]); | |
1521 EXPECT_EQ(base::ASCIIToUTF16("baz"), suggestion_results[2]); | |
1522 } | |
1523 | |
1524 TEST_F(SpellCheckTest, FillSuggestions_TwoLanguages) { | |
1525 std::vector<std::vector<base::string16>> suggestions_list; | |
1526 std::vector<base::string16> suggestion_results; | |
1527 | |
1528 suggestions_list.resize(2); | |
1529 for (size_t i = 0; i < 2; ++i) { | |
1530 std::string prefix = base::IntToString(i); | |
1531 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo")); | |
1532 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar")); | |
1533 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz")); | |
1534 } | |
1535 | |
1536 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs | |
1537 // to be updated accordingly. | |
1538 ASSERT_EQ(5, spellcheck::kMaxSuggestions); | |
1539 FillSuggestions(suggestions_list, &suggestion_results); | |
1540 ASSERT_EQ(5U, suggestion_results.size()); | |
1541 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); | |
1542 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); | |
1543 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[2]); | |
1544 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[3]); | |
1545 EXPECT_EQ(base::ASCIIToUTF16("0baz"), suggestion_results[4]); | |
1546 } | |
1547 | |
1548 TEST_F(SpellCheckTest, FillSuggestions_ThreeLanguages) { | |
1549 std::vector<std::vector<base::string16>> suggestions_list; | |
1550 std::vector<base::string16> suggestion_results; | |
1551 | |
1552 suggestions_list.resize(3); | |
1553 for (size_t i = 0; i < 3; ++i) { | |
1554 std::string prefix = base::IntToString(i); | |
1555 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo")); | |
1556 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar")); | |
1557 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz")); | |
1558 } | |
1559 | |
1560 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs | |
1561 // to be updated accordingly. | |
1562 ASSERT_EQ(5, spellcheck::kMaxSuggestions); | |
1563 FillSuggestions(suggestions_list, &suggestion_results); | |
1564 ASSERT_EQ(5U, suggestion_results.size()); | |
1565 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); | |
1566 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); | |
1567 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); | |
1568 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); | |
1569 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); | |
1570 } | |
OLD | NEW |