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.
5 #include "chrome/renderer/spellchecker/spellcheck.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/common/spellcheck_common.h"
13 #include "chrome/common/spellcheck_result.h"
14 #include "chrome/renderer/spellchecker/hunspell_engine.h"
15 #include "chrome/renderer/spellchecker/spellcheck_language.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
19 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
21 #define TYPOGRAPHICAL_APOSTROPHE L"\x2019"
25 base::FilePath
GetHunspellDirectory() {
26 base::FilePath hunspell_directory
;
27 if (!PathService::Get(base::DIR_SOURCE_ROOT
, &hunspell_directory
))
28 return base::FilePath();
30 hunspell_directory
= hunspell_directory
.AppendASCII("third_party");
31 hunspell_directory
= hunspell_directory
.AppendASCII("hunspell_dictionaries");
32 return hunspell_directory
;
37 // TODO(groby): This needs to be a BrowserTest for OSX.
38 class SpellCheckTest
: public testing::Test
{
41 ReinitializeSpellCheck("en-US");
44 void ReinitializeSpellCheck(const std::string
& language
) {
45 spell_check_
.reset(new SpellCheck());
46 InitializeSpellCheck(language
);
49 void UninitializeSpellCheck() {
50 spell_check_
.reset(new SpellCheck());
53 bool InitializeIfNeeded() {
54 return spell_check()->InitializeIfNeeded();
57 void InitializeSpellCheck(const std::string
& language
) {
58 base::FilePath hunspell_directory
= GetHunspellDirectory();
59 EXPECT_FALSE(hunspell_directory
.empty());
61 chrome::spellcheck_common::GetVersionedFileName(language
,
63 base::File::FLAG_OPEN
| base::File::FLAG_READ
);
64 #if defined(OS_MACOSX)
65 // TODO(groby): Forcing spellcheck to use hunspell, even on OSX.
66 // Instead, tests should exercise individual spelling engines.
67 spell_check_
->languages_
.push_back(new SpellcheckLanguage());
68 spell_check_
->languages_
.front()->platform_spelling_engine_
.reset(
70 spell_check_
->languages_
.front()->Init(file
.Pass(), language
);
72 spell_check_
->AddSpellcheckLanguage(file
.Pass(), language
);
75 void EnableAutoCorrect(bool enable_autocorrect
) {
76 spell_check_
->OnEnableAutoSpellCorrect(enable_autocorrect
);
79 ~SpellCheckTest() override
{}
81 SpellCheck
* spell_check() { return spell_check_
.get(); }
83 bool CheckSpelling(const std::string
& word
, int tag
) {
84 return spell_check_
->languages_
.front()
85 ->platform_spelling_engine_
->CheckSpelling(base::ASCIIToUTF16(word
),
89 bool IsValidContraction(const base::string16
& word
, int tag
) {
90 return spell_check_
->languages_
.front()->IsValidContraction(word
, tag
);
93 #if !defined(OS_MACOSX)
95 void TestSpellCheckParagraph(
96 const base::string16
& input
,
97 const std::vector
<SpellCheckResult
>& expected
) {
98 blink::WebVector
<blink::WebTextCheckingResult
> results
;
99 spell_check()->SpellCheckParagraph(input
,
102 EXPECT_EQ(results
.size(), expected
.size());
103 size_t size
= std::min(results
.size(), expected
.size());
104 for (size_t j
= 0; j
< size
; ++j
) {
105 EXPECT_EQ(results
[j
].decoration
, blink::WebTextDecorationTypeSpelling
);
106 EXPECT_EQ(results
[j
].location
, expected
[j
].location
);
107 EXPECT_EQ(results
[j
].length
, expected
[j
].length
);
113 scoped_ptr
<SpellCheck
> spell_check_
;
114 base::MessageLoop loop
;
117 // A fake completion object for verification.
118 class MockTextCheckingCompletion
: public blink::WebTextCheckingCompletion
{
120 MockTextCheckingCompletion()
121 : completion_count_(0) {
124 void didFinishCheckingText(
125 const blink::WebVector
<blink::WebTextCheckingResult
>& results
) override
{
127 last_results_
= results
;
130 void didCancelCheckingText() override
{
134 size_t completion_count_
;
135 blink::WebVector
<blink::WebTextCheckingResult
> last_results_
;
138 // Operates unit tests for the content::SpellCheck::SpellCheckWord() function
139 // with the US English dictionary.
140 // The unit tests in this function consist of:
141 // * Tests for the function with empty strings;
142 // * Tests for the function with a valid English word;
143 // * Tests for the function with a valid non-English word;
144 // * Tests for the function with a valid English word with a preceding
146 // * Tests for the function with a valid English word with a preceding
148 // * Tests for the function with a valid English word with a following
150 // * Tests for the function with a valid English word with a following
152 // * Tests for the function with two valid English words concatenated
153 // with space characters or non-English words;
154 // * Tests for the function with an invalid English word;
155 // * Tests for the function with an invalid English word with a preceding
157 // * Tests for the function with an invalid English word with a preceding
159 // * Tests for the function with an invalid English word with a following
161 // * Tests for the function with an invalid English word with a following
162 // non-English word, and;
163 // * Tests for the function with two invalid English words concatenated
164 // with space characters or non-English words.
165 // A test with a "[ROBUSTNESS]" mark shows it is a robustness test and it uses
166 // grammatically incorrect string.
167 // TODO(groby): Please feel free to add more tests.
168 TEST_F(SpellCheckTest
, SpellCheckStrings_EN_US
) {
169 static const struct {
170 // A string to be tested.
171 const wchar_t* input
;
172 // An expected result for this test case.
173 // * true: the input string does not have any invalid words.
174 // * false: the input string has one or more invalid words.
175 bool expected_result
;
176 // The position and the length of the first invalid word.
177 int misspelling_start
;
178 int misspelling_length
;
186 // A valid English word "hello".
188 // A valid Chinese word (meaning "hello") consisting of two CJKV
190 {L
"\x4F60\x597D", true},
191 // A valid Korean word (meaning "hello") consisting of five hangul
193 {L
"\xC548\xB155\xD558\xC138\xC694", true},
194 // A valid Japanese word (meaning "hello") consisting of five Hiragana
196 {L
"\x3053\x3093\x306B\x3061\x306F", true},
197 // A valid Hindi word (meaning ?) consisting of six Devanagari letters
198 // (This word is copied from "http://b/issue?id=857583".)
199 {L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
200 // A valid English word "affix" using a Latin ligature 'ffi'
202 // A valid English word "hello" (fullwidth version)
203 {L
"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true},
204 // Two valid Greek words (meaning "hello") consisting of seven Greek
206 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
207 // A valid Russian word (meaning "hello") consisting of twelve Cyrillic
209 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
210 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
211 // A valid English contraction
213 // A valid English contraction with a typographical apostrophe.
214 {L
"isn" TYPOGRAPHICAL_APOSTROPHE L
"t", true},
215 // A valid English word enclosed with underscores.
218 // A valid English word with a preceding whitespace
219 {L
" " L
"hello", true},
220 // A valid English word with a preceding no-break space
221 {L
"\xA0" L
"hello", true},
222 // A valid English word with a preceding ideographic space
223 {L
"\x3000" L
"hello", true},
224 // A valid English word with a preceding Chinese word
225 {L
"\x4F60\x597D" L
"hello", true},
226 // [ROBUSTNESS] A valid English word with a preceding Korean word
227 {L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
228 // A valid English word with a preceding Japanese word
229 {L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
230 // [ROBUSTNESS] A valid English word with a preceding Hindi word
231 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello", true},
232 // [ROBUSTNESS] A valid English word with two preceding Greek words
233 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
235 // [ROBUSTNESS] A valid English word with a preceding Russian word
236 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
237 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
239 // A valid English word with a following whitespace
240 {L
"hello" L
" ", true},
241 // A valid English word with a following no-break space
242 {L
"hello" L
"\xA0", true},
243 // A valid English word with a following ideographic space
244 {L
"hello" L
"\x3000", true},
245 // A valid English word with a following Chinese word
246 {L
"hello" L
"\x4F60\x597D", true},
247 // [ROBUSTNESS] A valid English word with a following Korean word
248 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694", true},
249 // A valid English word with a following Japanese word
250 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F", true},
251 // [ROBUSTNESS] A valid English word with a following Hindi word
252 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
253 // [ROBUSTNESS] A valid English word with two following Greek words
255 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
256 // [ROBUSTNESS] A valid English word with a following Russian word
257 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
258 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
260 // Two valid English words concatenated with a whitespace
261 {L
"hello" L
" " L
"hello", true},
262 // Two valid English words concatenated with a no-break space
263 {L
"hello" L
"\xA0" L
"hello", true},
264 // Two valid English words concatenated with an ideographic space
265 {L
"hello" L
"\x3000" L
"hello", true},
266 // Two valid English words concatenated with a Chinese word
267 {L
"hello" L
"\x4F60\x597D" L
"hello", true},
268 // [ROBUSTNESS] Two valid English words concatenated with a Korean word
269 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
270 // Two valid English words concatenated with a Japanese word
271 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
272 // [ROBUSTNESS] Two valid English words concatenated with a Hindi word
273 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello" , true},
274 // [ROBUSTNESS] Two valid English words concatenated with two Greek words
275 {L
"hello" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
277 // [ROBUSTNESS] Two valid English words concatenated with a Russian word
278 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
279 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
280 // [ROBUSTNESS] Two valid English words concatenated with a contraction
282 {L
"hello:hello", true},
284 // An invalid English word
285 {L
"ifmmp", false, 0, 5},
286 // An invalid English word "bffly" containing a Latin ligature 'ffl'
287 {L
"b\xFB04y", false, 0, 3},
288 // An invalid English word "ifmmp" (fullwidth version)
289 {L
"\xFF29\xFF46\xFF4D\xFF4D\xFF50", false, 0, 5},
290 // An invalid English contraction
291 {L
"jtm'u", false, 0, 5},
292 // An invalid English word enclosed with underscores.
293 {L
"_ifmmp_", false, 1, 5},
295 // An invalid English word with a preceding whitespace
296 {L
" " L
"ifmmp", false, 1, 5},
297 // An invalid English word with a preceding no-break space
298 {L
"\xA0" L
"ifmmp", false, 1, 5},
299 // An invalid English word with a preceding ideographic space
300 {L
"\x3000" L
"ifmmp", false, 1, 5},
301 // An invalid English word with a preceding Chinese word
302 {L
"\x4F60\x597D" L
"ifmmp", false, 2, 5},
303 // [ROBUSTNESS] An invalid English word with a preceding Korean word
304 {L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 5, 5},
305 // An invalid English word with a preceding Japanese word
306 {L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 5, 5},
307 // [ROBUSTNESS] An invalid English word with a preceding Hindi word
308 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp", false, 6, 5},
309 // [ROBUSTNESS] An invalid English word with two preceding Greek words
310 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
311 L
"ifmmp", false, 8, 5},
312 // [ROBUSTNESS] An invalid English word with a preceding Russian word
313 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
314 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 12, 5},
316 // An invalid English word with a following whitespace
317 {L
"ifmmp" L
" ", false, 0, 5},
318 // An invalid English word with a following no-break space
319 {L
"ifmmp" L
"\xA0", false, 0, 5},
320 // An invalid English word with a following ideographic space
321 {L
"ifmmp" L
"\x3000", false, 0, 5},
322 // An invalid English word with a following Chinese word
323 {L
"ifmmp" L
"\x4F60\x597D", false, 0, 5},
324 // [ROBUSTNESS] An invalid English word with a following Korean word
325 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694", false, 0, 5},
326 // An invalid English word with a following Japanese word
327 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F", false, 0, 5},
328 // [ROBUSTNESS] An invalid English word with a following Hindi word
329 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928", false, 0, 5},
330 // [ROBUSTNESS] An invalid English word with two following Greek words
332 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", false, 0, 5},
333 // [ROBUSTNESS] An invalid English word with a following Russian word
334 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
335 L
"\x0442\x0432\x0443\x0439\x0442\x0435", false, 0, 5},
337 // Two invalid English words concatenated with a whitespace
338 {L
"ifmmp" L
" " L
"ifmmp", false, 0, 5},
339 // Two invalid English words concatenated with a no-break space
340 {L
"ifmmp" L
"\xA0" L
"ifmmp", false, 0, 5},
341 // Two invalid English words concatenated with an ideographic space
342 {L
"ifmmp" L
"\x3000" L
"ifmmp", false, 0, 5},
343 // Two invalid English words concatenated with a Chinese word
344 {L
"ifmmp" L
"\x4F60\x597D" L
"ifmmp", false, 0, 5},
345 // [ROBUSTNESS] Two invalid English words concatenated with a Korean word
346 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 0, 5},
347 // Two invalid English words concatenated with a Japanese word
348 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 0, 5},
349 // [ROBUSTNESS] Two invalid English words concatenated with a Hindi word
350 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp" , false, 0, 5},
351 // [ROBUSTNESS] Two invalid English words concatenated with two Greek words
352 {L
"ifmmp" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
353 L
"ifmmp", false, 0, 5},
354 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word
355 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
356 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 0, 5},
357 // [ROBUSTNESS] Two invalid English words concatenated with a contraction
359 {L
"ifmmp:ifmmp", false, 0, 11},
361 // [REGRESSION] Issue 13432: "Any word of 13 or 14 characters is not
362 // spellcheck" <http://crbug.com/13432>.
363 {L
"qwertyuiopasd", false, 0, 13},
364 {L
"qwertyuiopasdf", false, 0, 14},
366 // [REGRESSION] Issue 128896: "en_US hunspell dictionary includes
367 // acknowledgement but not acknowledgements" <http://crbug.com/128896>
368 {L
"acknowledgement", true},
369 {L
"acknowledgements", true},
371 // Issue 123290: "Spellchecker should treat numbers as word characters"
387 {L
"100,000,000", true},
388 {L
"3.141592653", true},
391 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
392 size_t input_length
= 0;
393 if (kTestCases
[i
].input
!= NULL
) {
394 input_length
= wcslen(kTestCases
[i
].input
);
396 int misspelling_start
;
397 int misspelling_length
;
398 bool result
= spell_check()->SpellCheckWord(
399 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
400 static_cast<int>(input_length
),
403 &misspelling_length
, NULL
);
405 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
406 EXPECT_EQ(kTestCases
[i
].misspelling_start
, misspelling_start
);
407 EXPECT_EQ(kTestCases
[i
].misspelling_length
, misspelling_length
);
411 TEST_F(SpellCheckTest
, SpellCheckSuggestions_EN_US
) {
412 static const struct {
413 // A string to be tested.
414 const wchar_t* input
;
415 // An expected result for this test case.
416 // * true: the input string does not have any invalid words.
417 // * false: the input string has one or more invalid words.
418 bool expected_result
;
419 // The position and the length of the first invalid word.
420 int misspelling_start
;
421 int misspelling_length
;
423 // A suggested word that should occur.
424 const wchar_t* suggested_word
;
426 {L
"ello", false, 0, 0, L
"hello"},
427 {L
"ello", false, 0, 0, L
"cello"},
428 {L
"wate", false, 0, 0, L
"water"},
429 {L
"wate", false, 0, 0, L
"waste"},
430 {L
"wate", false, 0, 0, L
"sate"},
431 {L
"wate", false, 0, 0, L
"ate"},
432 {L
"jum", false, 0, 0, L
"jump"},
433 {L
"jum", false, 0, 0, L
"hum"},
434 {L
"jum", false, 0, 0, L
"sum"},
435 {L
"jum", false, 0, 0, L
"um"},
436 {L
"alot", false, 0, 0, L
"a lot"},
437 // A regression test for Issue 36523.
438 {L
"privliged", false, 0, 0, L
"privileged"},
439 // TODO (Sidchat): add many more examples.
442 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
443 std::vector
<base::string16
> suggestions
;
444 size_t input_length
= 0;
445 if (kTestCases
[i
].input
!= NULL
) {
446 input_length
= wcslen(kTestCases
[i
].input
);
448 int misspelling_start
;
449 int misspelling_length
;
450 bool result
= spell_check()->SpellCheckWord(
451 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
452 static_cast<int>(input_length
),
458 // Check for spelling.
459 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
461 // Check if the suggested words occur.
462 bool suggested_word_is_present
= false;
463 for (int j
= 0; j
< static_cast<int>(suggestions
.size()); j
++) {
464 if (suggestions
.at(j
).compare(
465 base::WideToUTF16(kTestCases
[i
].suggested_word
)) == 0) {
466 suggested_word_is_present
= true;
471 EXPECT_TRUE(suggested_word_is_present
);
475 // This test verifies our spellchecker can split a text into words and check
476 // the spelling of each word in the text.
477 #if defined(THREAD_SANITIZER)
478 // SpellCheckTest.SpellCheckText fails under ThreadSanitizer v2.
479 // See http://crbug.com/217909.
480 #define MAYBE_SpellCheckText DISABLED_SpellCheckText
482 #define MAYBE_SpellCheckText SpellCheckText
483 #endif // THREAD_SANITIZER
484 TEST_F(SpellCheckTest
, MAYBE_SpellCheckText
) {
485 static const struct {
486 const char* language
;
487 const wchar_t* input
;
492 L
"Google se missie is om die w\x00EAreld se inligting te organiseer en "
493 L
"dit bruikbaar en toeganklik te maak."
497 L
"La missi\x00F3 de Google \x00E9s organitzar la informaci\x00F3 "
498 L
"del m\x00F3n i fer que sigui \x00FAtil i accessible universalment."
502 L
"Posl\x00E1n\x00EDm spole\x010Dnosti Google je "
503 L
"uspo\x0159\x00E1\x0064\x0061t informace z cel\x00E9ho sv\x011Bta "
504 L
"tak, aby byly v\x0161\x0065obecn\x011B p\x0159\x00EDstupn\x00E9 "
505 L
"a u\x017Eite\x010Dn\x00E9."
510 L
"mission er at organisere verdens information og g\x00F8re den "
511 L
"almindeligt tilg\x00E6ngelig og nyttig."
515 L
"Das Ziel von Google besteht darin, die auf der Welt vorhandenen "
516 L
"Informationen zu organisieren und allgemein zug\x00E4nglich und "
517 L
"nutzbar zu machen."
521 L
"\x0391\x03C0\x03BF\x03C3\x03C4\x03BF\x03BB\x03AE "
522 L
"\x03C4\x03B7\x03C2 Google \x03B5\x03AF\x03BD\x03B1\x03B9 "
523 L
"\x03BD\x03B1 \x03BF\x03C1\x03B3\x03B1\x03BD\x03CE\x03BD\x03B5\x03B9 "
524 L
"\x03C4\x03B9\x03C2 "
525 L
"\x03C0\x03BB\x03B7\x03C1\x03BF\x03C6\x03BF\x03C1\x03AF\x03B5\x03C2 "
526 L
"\x03C4\x03BF\x03C5 \x03BA\x03CC\x03C3\x03BC\x03BF\x03C5 "
527 L
"\x03BA\x03B1\x03B9 \x03BD\x03B1 \x03C4\x03B9\x03C2 "
528 L
"\x03BA\x03B1\x03B8\x03B9\x03C3\x03C4\x03AC "
529 L
"\x03C0\x03C1\x03BF\x03C3\x03B2\x03AC\x03C3\x03B9\x03BC\x03B5\x03C2 "
530 L
"\x03BA\x03B1\x03B9 \x03C7\x03C1\x03AE\x03C3\x03B9\x03BC\x03B5\x03C2."
532 // English (Australia)
534 L
"Google's mission is to organise the world's information and make it "
535 L
"universally accessible and useful."
539 L
"Google's mission is to organize the world's information and make it "
540 L
"universally accessible and useful."
542 // English (United Kingdom)
544 L
"Google's mission is to organise the world's information and make it "
545 L
"universally accessible and useful."
547 // English (United States)
549 L
"Google's mission is to organize the world's information and make it "
550 L
"universally accessible and useful."
554 L
"\x041c\x0438\x0441\x0438\x044f\x0442\x0430 "
555 L
"\x043d\x0430 Google \x0435 \x0434\x0430 \x043e"
556 L
"\x0440\x0433\x0430\x043d\x0438\x0437\x0438\x0440"
557 L
"\x0430 \x0441\x0432\x0435\x0442\x043e\x0432"
558 L
"\x043d\x0430\x0442\x0430 \x0438\x043d\x0444"
559 L
"\x043e\x0440\x043c\x0430\x0446\x0438\x044f "
560 L
"\x0438 \x0434\x0430 \x044f \x043d"
561 L
"\x0430\x043f\x0440\x0430\x0432\x0438 \x0443"
562 L
"\x043d\x0438\x0432\x0435\x0440\x0441\x0430\x043b"
563 L
"\x043d\x043e \x0434\x043e\x0441\x0442\x044a"
564 L
"\x043f\x043d\x0430 \x0438 \x043f\x043e"
565 L
"\x043b\x0435\x0437\x043d\x0430."
569 L
"La misi\x00F3n de "
570 // L"Google" - to be added.
571 L
" es organizar la informaci\x00F3n mundial "
572 L
"para que resulte universalmente accesible y \x00FAtil."
576 // L"Google'ile " - to be added.
577 L
"\x00FClesanne on korraldada maailma teavet ja teeb selle "
578 L
"k\x00F5igile k\x00E4ttesaadavaks ja kasulikuks.",
582 L
"Google er at samskipa alla vitan \x00ED heiminum og gera hana alment "
583 L
"atkomiliga og n\x00FDtiliga."
587 L
"Google a pour mission d'organiser les informations \x00E0 "
588 L
"l'\x00E9\x0063helle mondiale dans le but de les rendre accessibles "
589 L
"et utiles \x00E0 tous."
593 L
"\x05D4\x05DE\x05E9\x05D9\x05DE\x05D4 \x05E9\x05DC Google "
594 L
"\x05D4\x05D9\x05D0 \x05DC\x05D0\x05E8\x05D2\x05DF "
595 L
"\x05D0\x05EA \x05D4\x05DE\x05D9\x05D3\x05E2 "
596 L
"\x05D4\x05E2\x05D5\x05DC\x05DE\x05D9 "
597 L
"\x05D5\x05DC\x05D4\x05E4\x05D5\x05DA \x05D0\x05D5\x05EA\x05D5 "
598 L
"\x05DC\x05D6\x05DE\x05D9\x05DF "
599 L
"\x05D5\x05E9\x05D9\x05DE\x05D5\x05E9\x05D9 \x05D1\x05DB\x05DC "
600 L
"\x05D4\x05E2\x05D5\x05DC\x05DD. "
601 // Two words with ASCII double/single quoation marks.
602 L
"\x05DE\x05E0\x05DB\x0022\x05DC \x05E6\x0027\x05D9\x05E4\x05E1"
606 L
"Google \x0915\x093E \x092E\x093F\x0936\x0928 "
607 L
"\x0926\x0941\x0928\x093F\x092F\x093E \x0915\x0940 "
608 L
"\x091C\x093E\x0928\x0915\x093E\x0930\x0940 \x0915\x094B "
609 L
"\x0935\x094D\x092F\x0935\x0938\x094D\x0925\x093F\x0924 "
610 L
"\x0915\x0930\x0928\x093E \x0914\x0930 \x0909\x0938\x0947 "
611 L
"\x0938\x093E\x0930\x094D\x0935\x092D\x094C\x092E\x093F\x0915 "
612 L
"\x0930\x0942\x092A \x0938\x0947 \x092A\x0939\x0941\x0901\x091A "
613 L
"\x092E\x0947\x0902 \x0914\x0930 \x0909\x092A\x092F\x094B\x0917\x0940 "
614 L
"\x092C\x0928\x093E\x0928\x093E \x0939\x0948."
618 L
"A Google azt a k\x00FCldet\x00E9st v\x00E1llalta mag\x00E1ra, "
619 L
"hogy a vil\x00E1gon fellelhet\x0151 inform\x00E1\x0063i\x00F3kat "
620 L
"rendszerezze \x00E9s \x00E1ltal\x00E1nosan el\x00E9rhet\x0151v\x00E9, "
621 L
"illetve haszn\x00E1lhat\x00F3v\x00E1 tegye."
625 // L"Googleova " - to be added.
626 L
"je misija organizirati svjetske informacije i u\x010Diniti ih "
627 // L"univerzalno " - to be added.
628 L
"pristupa\x010Dnima i korisnima."
632 L
"Misi Google adalah untuk mengelola informasi dunia dan membuatnya "
633 L
"dapat diakses dan bermanfaat secara universal."
637 L
"La missione di Google \x00E8 organizzare le informazioni a livello "
638 L
"mondiale e renderle universalmente accessibili e fruibili."
642 L
"\x201EGoogle\x201C tikslas \x2013 rinkti ir sisteminti pasaulio "
643 L
"informacij\x0105 bei padaryti j\x0105 prieinam\x0105 ir "
644 L
"nauding\x0105 visiems."
648 L
"Google uzdevums ir k\x0101rtot pasaules inform\x0101"
649 L
"ciju un padar\x012Bt to univers\x0101li pieejamu un noder\x012Bgu."
653 // L"Googles " - to be added.
654 L
"m\x00E5l er \x00E5 organisere informasjonen i verden og "
655 L
"gj\x00F8re den tilgjengelig og nyttig for alle."
659 L
"Het doel van Google is om alle informatie wereldwijd toegankelijk "
660 L
"en bruikbaar te maken."
664 L
"Misj\x0105 Google jest uporz\x0105" L
"dkowanie \x015Bwiatowych "
665 L
"zasob\x00F3w informacji, aby sta\x0142y si\x0119 one powszechnie "
666 L
"dost\x0119pne i u\x017Cyteczne."
668 // Portuguese (Brazil)
671 #if !defined(OS_MACOSX)
674 L
"\x00E9 organizar as informa\x00E7\x00F5"
675 L
"es do mundo todo e "
676 #if !defined(OS_MACOSX)
679 L
"acess\x00EDveis e \x00FAteis em car\x00E1ter universal."
681 // Portuguese (Portugal)
684 #if !defined(OS_MACOSX)
687 L
"tem por miss\x00E3o organizar a informa\x00E7\x00E3o do "
689 #if !defined(OS_MACOSX)
692 L
"universalmente acess\x00EDvel e \x00FAtil"
696 L
"Misiunea Google este de a organiza informa\x021B3iile lumii \x0219i de "
697 L
"a le face accesibile \x0219i utile la nivel universal."
701 L
"\x041C\x0438\x0441\x0441\x0438\x044F Google "
702 L
"\x0441\x043E\x0441\x0442\x043E\x0438\x0442 \x0432 "
703 L
"\x043E\x0440\x0433\x0430\x043D\x0438\x0437\x0430\x0446\x0438\x0438 "
704 L
"\x043C\x0438\x0440\x043E\x0432\x043E\x0439 "
705 L
"\x0438\x043D\x0444\x043E\x0440\x043C\x0430\x0446\x0438\x0438, "
706 L
"\x043E\x0431\x0435\x0441\x043F\x0435\x0447\x0435\x043D\x0438\x0438 "
708 L
"\x0434\x043E\x0441\x0442\x0443\x043F\x043D\x043E\x0441\x0442\x0438 "
709 L
"\x0438 \x043F\x043E\x043B\x044C\x0437\x044B \x0434\x043B\x044F "
710 L
"\x0432\x0441\x0435\x0445."
711 // A Russian word including U+0451. (Bug 15558 <http://crbug.com/15558>)
712 L
"\x0451\x043B\x043A\x0430"
714 // Serbo-Croatian (Serbian Latin)
716 L
"Google-ova misija je da organizuje sve informacije na svetu i "
717 L
"u\x010dini ih univerzal-no dostupnim i korisnim."
721 L
"\x0047\x006f\x006f\x0067\x006c\x0065\x002d\x043e\x0432\x0430 "
722 L
"\x043c\x0438\x0441\x0438\x0458\x0430 \x0458\x0435 \x0434\x0430 "
723 L
"\x043e\x0440\x0433\x0430\x043d\x0438\x0437\x0443\x0458\x0435 "
724 L
"\x0441\x0432\x0435 "
725 L
"\x0438\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0438\x0458\x0435 "
726 L
"\x043d\x0430 \x0441\x0432\x0435\x0442\x0443 \x0438 "
727 L
"\x0443\x0447\x0438\x043d\x0438 \x0438\x0445 "
728 L
"\x0443\x043d\x0438\x0432\x0435\x0440\x0437\x0430\x043b\x043d\x043e "
729 L
"\x0434\x043e\x0441\x0442\x0443\x043f\x043d\x0438\x043c \x0438 "
730 L
"\x043a\x043e\x0440\x0438\x0441\x043d\x0438\x043c."
734 L
"Spolo\x010Dnos\x0165 Google si dala za \x00FAlohu usporiada\x0165 "
735 L
"inform\x00E1\x0063ie "
736 L
"z cel\x00E9ho sveta a zabezpe\x010Di\x0165, "
737 L
"aby boli v\x0161eobecne dostupn\x00E9 a u\x017Eito\x010Dn\x00E9."
741 // L"Googlovo " - to be added.
742 L
"poslanstvo je organizirati svetovne informacije in "
743 L
"omogo\x010Diti njihovo dostopnost in s tem uporabnost za vse."
747 L
"Googles m\x00E5ls\x00E4ttning \x00E4r att ordna v\x00E4rldens "
748 L
"samlade information och g\x00F6ra den tillg\x00E4nglig f\x00F6r alla."
752 // L"Google\x2019\x0131n " - to be added.
753 L
"misyonu, d\x00FCnyadaki t\x00FCm bilgileri "
754 L
"organize etmek ve evrensel olarak eri\x015Filebilir ve "
755 L
"kullan\x0131\x015Fl\x0131 k\x0131lmakt\x0131r."
759 L
"\x041c\x0456\x0441\x0456\x044f "
760 L
"\x043a\x043e\x043c\x043f\x0430\x043d\x0456\x0457 Google "
761 L
"\x043f\x043e\x043b\x044f\x0433\x0430\x0454 \x0432 "
762 L
"\x0442\x043e\x043c\x0443, \x0449\x043e\x0431 "
763 L
"\x0443\x043f\x043e\x0440\x044f\x0434\x043a\x0443\x0432\x0430\x0442"
764 L
"\x0438 \x0456\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0456\x044e "
765 L
"\x0437 \x0443\x0441\x044c\x043e\x0433\x043e "
766 L
"\x0441\x0432\x0456\x0442\x0443 \x0442\x0430 "
767 L
"\x0437\x0440\x043e\x0431\x0438\x0442\x0438 \x0457\x0457 "
768 L
"\x0443\x043d\x0456\x0432\x0435\x0440\x0441\x0430\x043b\x044c\x043d"
769 L
"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e "
770 L
"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e."
774 L
"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 "
775 L
"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 "
776 L
"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 "
777 L
"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 "
778 L
"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n."
782 L
"Google\xC758 \xBAA9\xD45C\xB294 \xC804\xC138\xACC4\xC758 "
783 L
"\xC815\xBCF4\xB97C \xCCB4\xACC4\xD654\xD558\xC5EC \xBAA8\xB450\xAC00 "
784 L
"\xD3B8\xB9AC\xD558\xAC8C \xC774\xC6A9\xD560 \xC218 "
785 L
"\xC788\xB3C4\xB85D \xD558\xB294 \xAC83\xC785\xB2C8\xB2E4."
789 L
"Misioni i Google \x00EBsht\x00EB q\x00EB t\x00EB organizoj\x00EB "
790 L
"informacionin e bot\x00EBs dhe t\x00EB b\x00EBjn\x00EB at\x00EB "
791 L
"universalisht t\x00EB arritshme dhe t\x00EB dobishme."
795 L
"Google \x0B87\x0BA9\x0BCD "
796 L
"\x0BA8\x0BC7\x0BBE\x0B95\x0BCD\x0B95\x0BAE\x0BCD "
797 L
"\x0B89\x0BB2\x0B95\x0BBF\x0BA9\x0BCD \x0BA4\x0B95\x0BB5\x0BB2\x0BCD "
798 L
"\x0B8F\x0BB1\x0BCD\x0BAA\x0BBE\x0B9F\x0BC1 \x0B87\x0BA4\x0BC1 "
799 L
"\x0B89\x0BB2\x0B95\x0BB3\x0BBE\x0BB5\x0BBF\x0BAF "
800 L
"\x0B85\x0BA3\x0BC1\x0B95\x0B95\x0BCD \x0B95\x0BC2\x0B9F\x0BBF\x0BAF "
801 L
"\x0BAE\x0BB1\x0BCD\x0BB1\x0BC1\x0BAE\x0BCD "
802 L
"\x0BAA\x0BAF\x0BA9\x0BC1\x0BB3\x0BCD\x0BB3 "
803 L
"\x0B9A\x0BC6\x0BAF\x0BCD\x0BAF \x0B89\x0BB3\x0BCD\x0BB3\x0BA4\x0BC1."
807 L
"\x041c\x0438\x0441\x0441\x0438\x044f\x0438 Google \x0438\x043d "
808 L
"\x043c\x0443\x0440\x0430\x0442\x0442\x0430\x0431 "
809 L
"\x0441\x043e\x0445\x0442\x0430\x043d\x0438 "
810 L
"\x043c\x0430\x044a\x043b\x0443\x043c\x043e\x0442\x04b3\x043e\x0438 "
811 L
"\x043c\x0430\x0432\x04b7\x0443\x0434\x0430, \x043e\x0441\x043e\x043d "
812 L
"\x043d\x0430\x043c\x0443\x0434\x0430\x043d\x0438 "
813 L
"\x0438\x0441\x0442\x0438\x0444\x043e\x0434\x0430\x0431\x0430\x0440"
814 L
"\x04e3 \x0432\x0430 \x0434\x0430\x0441\x0442\x0440\x0430\x0441\x0438 "
815 L
"\x0443\x043c\x0443\x043c "
816 L
"\x0433\x0430\x0440\x0434\x043e\x043d\x0438\x0434\x0430\x043d\x0438 "
817 L
"\x043e\x043d\x04b3\x043e \x0430\x0441\x0442."
821 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
822 ReinitializeSpellCheck(kTestCases
[i
].language
);
823 size_t input_length
= 0;
824 if (kTestCases
[i
].input
!= NULL
)
825 input_length
= wcslen(kTestCases
[i
].input
);
827 int misspelling_start
= 0;
828 int misspelling_length
= 0;
829 bool result
= spell_check()->SpellCheckWord(
830 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
831 static_cast<int>(input_length
),
834 &misspelling_length
, NULL
);
838 << std::wstring(kTestCases
[i
].input
).substr(
839 misspelling_start
, misspelling_length
)
840 << "\" is misspelled in "
841 << kTestCases
[i
].language
843 EXPECT_EQ(0, misspelling_start
);
844 EXPECT_EQ(0, misspelling_length
);
848 TEST_F(SpellCheckTest
, GetAutoCorrectionWord_EN_US
) {
849 static const struct {
850 // A misspelled word.
853 // An expected result for this test case.
854 // Should be an empty string if there are no suggestions for auto correct.
855 const char* expected_result
;
864 EnableAutoCorrect(true);
866 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
867 base::string16
misspelled_word(base::UTF8ToUTF16(kTestCases
[i
].input
));
868 base::string16
expected_autocorrect_word(
869 base::UTF8ToUTF16(kTestCases
[i
].expected_result
));
870 base::string16 autocorrect_word
= spell_check()->GetAutoCorrectionWord(
873 // Check for spelling.
874 EXPECT_EQ(expected_autocorrect_word
, autocorrect_word
);
878 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks
880 TEST_F(SpellCheckTest
, MisspelledWords
) {
881 static const struct {
882 const char* language
;
883 const wchar_t* input
;
886 // A misspelled word for English
890 // A misspelled word for Greek.
892 L
"\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1",
894 // A misspelled word for Hebrew
896 L
"\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0",
900 L
"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905",
902 // A misspelled word for Russian
904 L
"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430",
908 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
909 ReinitializeSpellCheck(kTestCases
[i
].language
);
911 base::string16
word(base::WideToUTF16(kTestCases
[i
].input
));
912 int word_length
= static_cast<int>(word
.length());
913 int misspelling_start
= 0;
914 int misspelling_length
= 0;
915 bool result
= spell_check()->SpellCheckWord(word
.c_str(),
921 EXPECT_FALSE(result
);
922 EXPECT_EQ(0, misspelling_start
);
923 EXPECT_EQ(word_length
, misspelling_length
);
927 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac,
928 // we skip these SpellCheckParagraph tests on Mac.
929 #if !defined(OS_MACOSX)
931 // Make sure SpellCheckParagraph does not crash if the input is empty.
932 TEST_F(SpellCheckTest
, SpellCheckParagraphEmptyParagraph
) {
933 std::vector
<SpellCheckResult
> expected
;
934 TestSpellCheckParagraph(base::UTF8ToUTF16(""), expected
);
937 // A simple test case having no misspellings.
938 TEST_F(SpellCheckTest
, SpellCheckParagraphNoMisspellings
) {
939 const base::string16 text
= base::UTF8ToUTF16("apple");
940 std::vector
<SpellCheckResult
> expected
;
941 TestSpellCheckParagraph(text
, expected
);
944 // A simple test case having one misspelling.
945 TEST_F(SpellCheckTest
, SpellCheckParagraphSingleMisspellings
) {
946 const base::string16 text
= base::UTF8ToUTF16("zz");
947 std::vector
<SpellCheckResult
> expected
;
948 expected
.push_back(SpellCheckResult(
949 SpellCheckResult::SPELLING
, 0, 2));
951 TestSpellCheckParagraph(text
, expected
);
954 // A simple test case having multiple misspellings.
955 TEST_F(SpellCheckTest
, SpellCheckParagraphMultipleMisspellings
) {
956 const base::string16 text
= base::UTF8ToUTF16("zz, zz");
957 std::vector
<SpellCheckResult
> expected
;
958 expected
.push_back(SpellCheckResult(
959 SpellCheckResult::SPELLING
, 0, 2));
960 expected
.push_back(SpellCheckResult(
961 SpellCheckResult::SPELLING
, 4, 2));
963 TestSpellCheckParagraph(text
, expected
);
966 // Make sure a relatively long (correct) sentence can be spellchecked.
967 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentence
) {
968 std::vector
<SpellCheckResult
> expected
;
969 // The text is taken from US constitution preamble.
970 const base::string16 text
= base::UTF8ToUTF16(
971 "We the people of the United States, in order to form a more perfect "
972 "union, establish justice, insure domestic tranquility, provide for "
973 "the common defense, promote the general welfare, and secure the "
974 "blessings of liberty to ourselves and our posterity, do ordain and "
975 "establish this Constitution for the United States of America.");
977 TestSpellCheckParagraph(text
, expected
);
980 // Make sure all misspellings can be found in a relatively long sentence.
981 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentenceMultipleMisspellings
) {
982 std::vector
<SpellCheckResult
> expected
;
984 // All 'the' are converted to 'hte' in US consitition preamble.
985 const base::string16 text
= base::UTF8ToUTF16(
986 "We hte people of hte United States, in order to form a more perfect "
987 "union, establish justice, insure domestic tranquility, provide for "
988 "hte common defense, promote hte general welfare, and secure hte "
989 "blessings of liberty to ourselves and our posterity, do ordain and "
990 "establish this Constitution for hte United States of America.");
992 expected
.push_back(SpellCheckResult(
993 SpellCheckResult::SPELLING
, 3, 3));
994 expected
.push_back(SpellCheckResult(
995 SpellCheckResult::SPELLING
, 17, 3));
996 expected
.push_back(SpellCheckResult(
997 SpellCheckResult::SPELLING
, 135, 3));
998 expected
.push_back(SpellCheckResult(
999 SpellCheckResult::SPELLING
, 163, 3));
1000 expected
.push_back(SpellCheckResult(
1001 SpellCheckResult::SPELLING
, 195, 3));
1002 expected
.push_back(SpellCheckResult(
1003 SpellCheckResult::SPELLING
, 298, 3));
1005 TestSpellCheckParagraph(text
, expected
);
1008 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker
1009 // is used on Mac instead of SpellCheck::RequestTextChecking.
1011 // Make sure RequestTextChecking does not crash if input is empty.
1012 TEST_F(SpellCheckTest
, RequestSpellCheckWithEmptyString
) {
1013 MockTextCheckingCompletion completion
;
1015 spell_check()->RequestTextChecking(base::string16(), &completion
);
1017 base::MessageLoop::current()->RunUntilIdle();
1019 EXPECT_EQ(completion
.completion_count_
, 1U);
1022 // A simple test case having no misspellings.
1023 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutMisspelling
) {
1024 MockTextCheckingCompletion completion
;
1026 const base::string16 text
= base::ASCIIToUTF16("hello");
1027 spell_check()->RequestTextChecking(text
, &completion
);
1029 base::MessageLoop::current()->RunUntilIdle();
1031 EXPECT_EQ(completion
.completion_count_
, 1U);
1034 // A simple test case having one misspelling.
1035 TEST_F(SpellCheckTest
, RequestSpellCheckWithSingleMisspelling
) {
1036 MockTextCheckingCompletion completion
;
1038 const base::string16 text
= base::ASCIIToUTF16("apple, zz");
1039 spell_check()->RequestTextChecking(text
, &completion
);
1041 base::MessageLoop::current()->RunUntilIdle();
1043 EXPECT_EQ(completion
.completion_count_
, 1U);
1044 EXPECT_EQ(completion
.last_results_
.size(), 1U);
1045 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1046 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1049 // A simple test case having a few misspellings.
1050 TEST_F(SpellCheckTest
, RequestSpellCheckWithMisspellings
) {
1051 MockTextCheckingCompletion completion
;
1053 const base::string16 text
= base::ASCIIToUTF16("apple, zz, orange, zz");
1054 spell_check()->RequestTextChecking(text
, &completion
);
1056 base::MessageLoop::current()->RunUntilIdle();
1058 EXPECT_EQ(completion
.completion_count_
, 1U);
1059 EXPECT_EQ(completion
.last_results_
.size(), 2U);
1060 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1061 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1062 EXPECT_EQ(completion
.last_results_
[1].location
, 19);
1063 EXPECT_EQ(completion
.last_results_
[1].length
, 2);
1066 // A test case that multiple requests comes at once. Make sure all
1067 // requests are processed.
1068 TEST_F(SpellCheckTest
, RequestSpellCheckWithMultipleRequests
) {
1069 MockTextCheckingCompletion completion
[3];
1071 const base::string16 text
[3] = {
1072 base::ASCIIToUTF16("what, zz"),
1073 base::ASCIIToUTF16("apple, zz"),
1074 base::ASCIIToUTF16("orange, zz")
1077 for (int i
= 0; i
< 3; ++i
)
1078 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1080 base::MessageLoop::current()->RunUntilIdle();
1082 for (int i
= 0; i
< 3; ++i
) {
1083 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1084 EXPECT_EQ(completion
[i
].last_results_
.size(), 1U);
1085 EXPECT_EQ(completion
[i
].last_results_
[0].location
, 6 + i
);
1086 EXPECT_EQ(completion
[i
].last_results_
[0].length
, 2);
1090 // A test case that spellchecking is requested before initializing.
1091 // In this case, we postpone to post a request.
1092 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutInitialization
) {
1093 UninitializeSpellCheck();
1095 MockTextCheckingCompletion completion
;
1096 const base::string16 text
= base::ASCIIToUTF16("zz");
1098 spell_check()->RequestTextChecking(text
, &completion
);
1100 // The task will not be posted yet.
1101 base::MessageLoop::current()->RunUntilIdle();
1102 EXPECT_EQ(completion
.completion_count_
, 0U);
1105 // Requests several spellchecking before initializing. Except the last one,
1106 // posting requests is cancelled and text is rendered as correct one.
1107 TEST_F(SpellCheckTest
, RequestSpellCheckMultipleTimesWithoutInitialization
) {
1108 UninitializeSpellCheck();
1110 MockTextCheckingCompletion completion
[3];
1111 const base::string16 text
[3] = {
1112 base::ASCIIToUTF16("what, zz"),
1113 base::ASCIIToUTF16("apple, zz"),
1114 base::ASCIIToUTF16("orange, zz")
1117 // Calls RequestTextchecking a few times.
1118 for (int i
= 0; i
< 3; ++i
)
1119 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1121 // The last task will be posted after initialization, however the other
1122 // requests should be pressed without spellchecking.
1123 base::MessageLoop::current()->RunUntilIdle();
1124 for (int i
= 0; i
< 2; ++i
)
1125 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1126 EXPECT_EQ(completion
[2].completion_count_
, 0U);
1128 // Checks the last request is processed after initialization.
1129 InitializeSpellCheck("en-US");
1131 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity.
1132 spell_check()->PostDelayedSpellCheckTask(
1133 spell_check()->pending_request_param_
.release());
1134 base::MessageLoop::current()->RunUntilIdle();
1135 for (int i
= 0; i
< 3; ++i
)
1136 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1141 // Verify that the SpellCheck class keeps the spelling marker added to a
1142 // misspelled word "zz".
1143 TEST_F(SpellCheckTest
, CreateTextCheckingResultsKeepsMarkers
) {
1144 base::string16 text
= base::ASCIIToUTF16("zz");
1145 std::vector
<SpellCheckResult
> spellcheck_results
;
1146 spellcheck_results
.push_back(
1147 SpellCheckResult(SpellCheckResult::SPELLING
, 0, 2, base::string16()));
1148 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1149 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1150 text
, spellcheck_results
,
1151 &textcheck_results
);
1152 ASSERT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1153 EXPECT_EQ(blink::WebTextDecorationTypeSpelling
,
1154 textcheck_results
[0].decoration
);
1155 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1156 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1159 // Verify that the SpellCheck class replaces the spelling marker added to a
1160 // contextually-misspelled word "bean" with a grammar marker.
1161 TEST_F(SpellCheckTest
, CreateTextCheckingResultsAddsGrammarMarkers
) {
1162 base::string16 text
= base::ASCIIToUTF16("I have bean to USA.");
1163 std::vector
<SpellCheckResult
> spellcheck_results
;
1164 spellcheck_results
.push_back(
1165 SpellCheckResult(SpellCheckResult::SPELLING
, 7, 4, base::string16()));
1166 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1167 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1168 text
, spellcheck_results
,
1169 &textcheck_results
);
1170 ASSERT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1171 EXPECT_EQ(blink::WebTextDecorationTypeGrammar
,
1172 textcheck_results
[0].decoration
);
1173 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1174 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1177 // Verify that the SpellCheck preserves the original apostrophe type in the
1178 // checked text, regardless of the type of apostrophe the browser returns.
1179 TEST_F(SpellCheckTest
, CreateTextCheckingResultsKeepsTypographicalApostrophe
) {
1180 base::string16 text
= base::WideToUTF16(
1181 L
"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L
"t ni'n"
1182 TYPOGRAPHICAL_APOSTROPHE L
"out-s I've I" TYPOGRAPHICAL_APOSTROPHE
1184 std::vector
<SpellCheckResult
> spellcheck_results
;
1186 // All typewriter apostrophe results.
1187 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 0,
1188 5, base::UTF8ToUTF16("I've")));
1189 spellcheck_results
.push_back(SpellCheckResult(
1190 SpellCheckResult::SPELLING
, 6, 6, base::UTF8ToUTF16("haven't")));
1191 spellcheck_results
.push_back(SpellCheckResult(
1192 SpellCheckResult::SPELLING
, 13, 10, base::UTF8ToUTF16("in'n'out's")));
1194 // Replacements that differ only by apostrophe type should be ignored.
1195 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 24,
1196 4, base::UTF8ToUTF16("I've")));
1197 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 29,
1198 4, base::UTF8ToUTF16("I've")));
1200 // All typographical apostrophe results.
1201 spellcheck_results
.push_back(
1202 SpellCheckResult(SpellCheckResult::SPELLING
, 0, 5,
1203 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1204 spellcheck_results
.push_back(SpellCheckResult(
1205 SpellCheckResult::SPELLING
, 6, 6,
1206 base::WideToUTF16(L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t")));
1207 spellcheck_results
.push_back(SpellCheckResult(
1208 SpellCheckResult::SPELLING
, 13, 10, base::WideToUTF16(
1209 L
"in" TYPOGRAPHICAL_APOSTROPHE L
"n" TYPOGRAPHICAL_APOSTROPHE L
"out"
1210 TYPOGRAPHICAL_APOSTROPHE L
"s")));
1212 // Replacements that differ only by apostrophe type should be ignored.
1213 spellcheck_results
.push_back(
1214 SpellCheckResult(SpellCheckResult::SPELLING
, 24, 4,
1215 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1216 spellcheck_results
.push_back(
1217 SpellCheckResult(SpellCheckResult::SPELLING
, 29, 4,
1218 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1220 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1221 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1222 text
, spellcheck_results
,
1223 &textcheck_results
);
1225 static const wchar_t* kExpectedReplacements
[] = {
1227 L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t",
1228 L
"in'n" TYPOGRAPHICAL_APOSTROPHE L
"out's",
1230 L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t",
1231 L
"in'n" TYPOGRAPHICAL_APOSTROPHE L
"out" TYPOGRAPHICAL_APOSTROPHE L
"s",
1234 ASSERT_EQ(arraysize(kExpectedReplacements
), textcheck_results
.size());
1235 for (size_t i
= 0; i
< arraysize(kExpectedReplacements
); ++i
) {
1236 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements
[i
]),
1237 textcheck_results
[i
].replacement
)
1238 << "i=" << i
<< "\nactual: \""
1239 << base::string16(textcheck_results
[i
].replacement
) << "\"";
1243 // Checks some words that should be present in all English dictionaries.
1244 TEST_F(SpellCheckTest
, EnglishWords
) {
1245 static const struct {
1249 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking
1251 {"Chromebook", true},
1252 {"Chromebooks", true},
1253 {"Chromebox", true},
1254 {"Chromeboxes", true},
1255 {"Chromeblade", true},
1256 {"Chromeblades", true},
1257 {"Chromebase", true},
1258 {"Chromebases", true},
1259 // Issue 94708: Spell-checker incorrectly reports whisky as misspelled.
1263 // Issue 98678: "Recency" should be included in client-side dictionary.
1265 {"recencies", false},
1271 static const char* const kLocales
[] = { "en-GB", "en-US", "en-CA", "en-AU" };
1273 for (size_t j
= 0; j
< arraysize(kLocales
); ++j
) {
1274 ReinitializeSpellCheck(kLocales
[j
]);
1275 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
1276 size_t input_length
= 0;
1277 if (kTestCases
[i
].input
!= NULL
)
1278 input_length
= strlen(kTestCases
[i
].input
);
1280 int misspelling_start
= 0;
1281 int misspelling_length
= 0;
1282 bool result
= spell_check()->SpellCheckWord(
1283 base::ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1284 static_cast<int>(input_length
),
1287 &misspelling_length
, NULL
);
1289 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].input
<<
1290 " in " << kLocales
[j
];
1295 // Checks that NOSUGGEST works in English dictionaries.
1296 TEST_F(SpellCheckTest
, NoSuggest
) {
1297 static const struct {
1299 const char* suggestion
;
1303 {"suckerbert", "cocksucker", "en-GB", true},
1304 {"suckerbert", "cocksucker", "en-US", true},
1305 {"suckerbert", "cocksucker", "en-CA", true},
1306 {"suckerbert", "cocksucker", "en-AU", true},
1307 {"suckerbert", "cocksuckers", "en-GB", true},
1308 {"suckerbert", "cocksuckers", "en-US", true},
1309 {"suckerbert", "cocksuckers", "en-CA", true},
1310 {"suckerbert", "cocksuckers", "en-AU", true},
1311 {"Batasunaa", "Batasuna", "ca-ES", true},
1312 {"pornoo", "porno", "it-IT", true},
1313 {"catass", "catas", "lt-LT", true},
1314 {"kuracc", "kurac", "sl-SI", true},
1315 {"pittt", "pitt", "sv-SE", true},
1318 size_t test_cases_size
= arraysize(kTestCases
);
1319 for (size_t i
= 0; i
< test_cases_size
; ++i
) {
1320 ReinitializeSpellCheck(kTestCases
[i
].locale
);
1321 size_t suggestion_length
= 0;
1322 if (kTestCases
[i
].suggestion
!= NULL
)
1323 suggestion_length
= strlen(kTestCases
[i
].suggestion
);
1325 // First check that the NOSUGGEST flag didn't mark this word as not being in
1327 int misspelling_start
= 0;
1328 int misspelling_length
= 0;
1329 bool result
= spell_check()->SpellCheckWord(
1330 base::ASCIIToUTF16(kTestCases
[i
].suggestion
).c_str(),
1331 static_cast<int>(suggestion_length
),
1334 &misspelling_length
, NULL
);
1336 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].suggestion
<<
1337 " in " << kTestCases
[i
].locale
;
1339 // Now verify that this test case does not show up as a suggestion.
1340 std::vector
<base::string16
> suggestions
;
1341 size_t input_length
= 0;
1342 if (kTestCases
[i
].input
!= NULL
)
1343 input_length
= strlen(kTestCases
[i
].input
);
1344 result
= spell_check()->SpellCheckWord(
1345 base::ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1346 static_cast<int>(input_length
),
1349 &misspelling_length
,
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
;
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());
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";
1381 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded.
1382 TEST_F(SpellCheckTest
, SpellingEngine_CheckSpelling
) {
1383 static const struct {
1385 bool expected_result
;
1388 { "automatic", true },
1390 { "forglobantic", false },
1391 { "xfdssfsdfaasds", false },
1392 { // 64 chars are the longest word to check - this should fail checking.
1393 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl",
1396 { // Any word longer than 64 chars should be exempt from checking.
1397 "reallylongwordthatabsolutelyexceedsthespecifiedcharacterlimitabit",
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());
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
;
1420 // Chrome should not suggest "Othello" for "hellllo" or "identically" for
1422 TEST_F(SpellCheckTest
, LogicalSuggestions
) {
1423 static const struct {
1424 const char* misspelled
;
1425 const char* suggestion
;
1427 { "hellllo", "hello" },
1428 { "accidently", "accidentally" }
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 strlen(kTestCases
[i
].misspelled
),
1440 &misspelling_length
,
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
));
1448 // Words with apostrophes should be valid contractions.
1449 TEST_F(SpellCheckTest
, IsValidContraction
) {
1450 static const char* kLanguages
[] = {
1457 static const wchar_t* kWords
[] = {
1459 L
"in" TYPOGRAPHICAL_APOSTROPHE L
"n" TYPOGRAPHICAL_APOSTROPHE L
"out",
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));