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