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_
.front()->platform_spelling_engine_
.reset(
70 spell_check_
->Init(file
.Pass(), std::set
<std::string
>(), language
);
73 void EnableAutoCorrect(bool enable_autocorrect
) {
74 spell_check_
->OnEnableAutoSpellCorrect(enable_autocorrect
);
77 ~SpellCheckTest() override
{}
79 SpellCheck
* spell_check() { return spell_check_
.get(); }
81 bool CheckSpelling(const std::string
& word
, int tag
) {
82 return spell_check_
->languages_
.front()
83 ->platform_spelling_engine_
->CheckSpelling(base::ASCIIToUTF16(word
),
87 bool IsValidContraction(const base::string16
& word
, int tag
) {
88 return spell_check_
->languages_
.front()->IsValidContraction(word
, tag
);
91 #if !defined(OS_MACOSX)
93 void TestSpellCheckParagraph(
94 const base::string16
& input
,
95 const std::vector
<SpellCheckResult
>& expected
) {
96 blink::WebVector
<blink::WebTextCheckingResult
> results
;
97 spell_check()->SpellCheckParagraph(input
,
100 EXPECT_EQ(results
.size(), expected
.size());
101 size_t size
= std::min(results
.size(), expected
.size());
102 for (size_t j
= 0; j
< size
; ++j
) {
103 EXPECT_EQ(results
[j
].decoration
, blink::WebTextDecorationTypeSpelling
);
104 EXPECT_EQ(results
[j
].location
, expected
[j
].location
);
105 EXPECT_EQ(results
[j
].length
, expected
[j
].length
);
111 scoped_ptr
<SpellCheck
> spell_check_
;
112 base::MessageLoop loop
;
115 // A fake completion object for verification.
116 class MockTextCheckingCompletion
: public blink::WebTextCheckingCompletion
{
118 MockTextCheckingCompletion()
119 : completion_count_(0) {
122 void didFinishCheckingText(
123 const blink::WebVector
<blink::WebTextCheckingResult
>& results
) override
{
125 last_results_
= results
;
128 void didCancelCheckingText() override
{
132 size_t completion_count_
;
133 blink::WebVector
<blink::WebTextCheckingResult
> last_results_
;
136 // Operates unit tests for the content::SpellCheck::SpellCheckWord() function
137 // with the US English dictionary.
138 // The unit tests in this function consist of:
139 // * Tests for the function with empty strings;
140 // * Tests for the function with a valid English word;
141 // * Tests for the function with a valid non-English word;
142 // * Tests for the function with a valid English word with a preceding
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 following
148 // * Tests for the function with a valid English word with a following
150 // * Tests for the function with two valid English words concatenated
151 // with space characters or non-English words;
152 // * Tests for the function with an invalid English word;
153 // * Tests for the function with an invalid English word with a preceding
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 following
159 // * Tests for the function with an invalid English word with a following
160 // non-English word, and;
161 // * Tests for the function with two invalid English words concatenated
162 // with space characters or non-English words.
163 // A test with a "[ROBUSTNESS]" mark shows it is a robustness test and it uses
164 // grammatically incorrect string.
165 // TODO(groby): Please feel free to add more tests.
166 TEST_F(SpellCheckTest
, SpellCheckStrings_EN_US
) {
167 static const struct {
168 // A string to be tested.
169 const wchar_t* input
;
170 // An expected result for this test case.
171 // * true: the input string does not have any invalid words.
172 // * false: the input string has one or more invalid words.
173 bool expected_result
;
174 // The position and the length of the first invalid word.
175 int misspelling_start
;
176 int misspelling_length
;
184 // A valid English word "hello".
186 // A valid Chinese word (meaning "hello") consisting of two CJKV
188 {L
"\x4F60\x597D", true},
189 // A valid Korean word (meaning "hello") consisting of five hangul
191 {L
"\xC548\xB155\xD558\xC138\xC694", true},
192 // A valid Japanese word (meaning "hello") consisting of five Hiragana
194 {L
"\x3053\x3093\x306B\x3061\x306F", true},
195 // A valid Hindi word (meaning ?) consisting of six Devanagari letters
196 // (This word is copied from "http://b/issue?id=857583".)
197 {L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
198 // A valid English word "affix" using a Latin ligature 'ffi'
200 // A valid English word "hello" (fullwidth version)
201 {L
"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true},
202 // Two valid Greek words (meaning "hello") consisting of seven Greek
204 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
205 // A valid Russian word (meaning "hello") consisting of twelve Cyrillic
207 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
208 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
209 // A valid English contraction
211 // A valid English contraction with a typographical apostrophe.
212 {L
"isn" TYPOGRAPHICAL_APOSTROPHE L
"t", true},
213 // A valid English word enclosed with underscores.
216 // A valid English word with a preceding whitespace
217 {L
" " L
"hello", true},
218 // A valid English word with a preceding no-break space
219 {L
"\xA0" L
"hello", true},
220 // A valid English word with a preceding ideographic space
221 {L
"\x3000" L
"hello", true},
222 // A valid English word with a preceding Chinese word
223 {L
"\x4F60\x597D" L
"hello", true},
224 // [ROBUSTNESS] A valid English word with a preceding Korean word
225 {L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
226 // A valid English word with a preceding Japanese word
227 {L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
228 // [ROBUSTNESS] A valid English word with a preceding Hindi word
229 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello", true},
230 // [ROBUSTNESS] A valid English word with two preceding Greek words
231 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
233 // [ROBUSTNESS] A valid English word with a preceding Russian word
234 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
235 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
237 // A valid English word with a following whitespace
238 {L
"hello" L
" ", true},
239 // A valid English word with a following no-break space
240 {L
"hello" L
"\xA0", true},
241 // A valid English word with a following ideographic space
242 {L
"hello" L
"\x3000", true},
243 // A valid English word with a following Chinese word
244 {L
"hello" L
"\x4F60\x597D", true},
245 // [ROBUSTNESS] A valid English word with a following Korean word
246 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694", true},
247 // A valid English word with a following Japanese word
248 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F", true},
249 // [ROBUSTNESS] A valid English word with a following Hindi word
250 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
251 // [ROBUSTNESS] A valid English word with two following Greek words
253 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
254 // [ROBUSTNESS] A valid English word with a following Russian word
255 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
256 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
258 // Two valid English words concatenated with a whitespace
259 {L
"hello" L
" " L
"hello", true},
260 // Two valid English words concatenated with a no-break space
261 {L
"hello" L
"\xA0" L
"hello", true},
262 // Two valid English words concatenated with an ideographic space
263 {L
"hello" L
"\x3000" L
"hello", true},
264 // Two valid English words concatenated with a Chinese word
265 {L
"hello" L
"\x4F60\x597D" L
"hello", true},
266 // [ROBUSTNESS] Two valid English words concatenated with a Korean word
267 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
268 // Two valid English words concatenated with a Japanese word
269 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
270 // [ROBUSTNESS] Two valid English words concatenated with a Hindi word
271 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello" , true},
272 // [ROBUSTNESS] Two valid English words concatenated with two Greek words
273 {L
"hello" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
275 // [ROBUSTNESS] Two valid English words concatenated with a Russian word
276 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
277 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
278 // [ROBUSTNESS] Two valid English words concatenated with a contraction
280 {L
"hello:hello", true},
282 // An invalid English word
283 {L
"ifmmp", false, 0, 5},
284 // An invalid English word "bffly" containing a Latin ligature 'ffl'
285 {L
"b\xFB04y", false, 0, 3},
286 // An invalid English word "ifmmp" (fullwidth version)
287 {L
"\xFF29\xFF46\xFF4D\xFF4D\xFF50", false, 0, 5},
288 // An invalid English contraction
289 {L
"jtm'u", false, 0, 5},
290 // An invalid English word enclosed with underscores.
291 {L
"_ifmmp_", false, 1, 5},
293 // An invalid English word with a preceding whitespace
294 {L
" " L
"ifmmp", false, 1, 5},
295 // An invalid English word with a preceding no-break space
296 {L
"\xA0" L
"ifmmp", false, 1, 5},
297 // An invalid English word with a preceding ideographic space
298 {L
"\x3000" L
"ifmmp", false, 1, 5},
299 // An invalid English word with a preceding Chinese word
300 {L
"\x4F60\x597D" L
"ifmmp", false, 2, 5},
301 // [ROBUSTNESS] An invalid English word with a preceding Korean word
302 {L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 5, 5},
303 // An invalid English word with a preceding Japanese word
304 {L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 5, 5},
305 // [ROBUSTNESS] An invalid English word with a preceding Hindi word
306 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp", false, 6, 5},
307 // [ROBUSTNESS] An invalid English word with two preceding Greek words
308 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
309 L
"ifmmp", false, 8, 5},
310 // [ROBUSTNESS] An invalid English word with a preceding Russian word
311 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
312 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 12, 5},
314 // An invalid English word with a following whitespace
315 {L
"ifmmp" L
" ", false, 0, 5},
316 // An invalid English word with a following no-break space
317 {L
"ifmmp" L
"\xA0", false, 0, 5},
318 // An invalid English word with a following ideographic space
319 {L
"ifmmp" L
"\x3000", false, 0, 5},
320 // An invalid English word with a following Chinese word
321 {L
"ifmmp" L
"\x4F60\x597D", false, 0, 5},
322 // [ROBUSTNESS] An invalid English word with a following Korean word
323 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694", false, 0, 5},
324 // An invalid English word with a following Japanese word
325 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F", false, 0, 5},
326 // [ROBUSTNESS] An invalid English word with a following Hindi word
327 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928", false, 0, 5},
328 // [ROBUSTNESS] An invalid English word with two following Greek words
330 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", false, 0, 5},
331 // [ROBUSTNESS] An invalid English word with a following Russian word
332 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
333 L
"\x0442\x0432\x0443\x0439\x0442\x0435", false, 0, 5},
335 // Two invalid English words concatenated with a whitespace
336 {L
"ifmmp" L
" " L
"ifmmp", false, 0, 5},
337 // Two invalid English words concatenated with a no-break space
338 {L
"ifmmp" L
"\xA0" L
"ifmmp", false, 0, 5},
339 // Two invalid English words concatenated with an ideographic space
340 {L
"ifmmp" L
"\x3000" L
"ifmmp", false, 0, 5},
341 // Two invalid English words concatenated with a Chinese word
342 {L
"ifmmp" L
"\x4F60\x597D" L
"ifmmp", false, 0, 5},
343 // [ROBUSTNESS] Two invalid English words concatenated with a Korean word
344 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 0, 5},
345 // Two invalid English words concatenated with a Japanese word
346 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 0, 5},
347 // [ROBUSTNESS] Two invalid English words concatenated with a Hindi word
348 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp" , false, 0, 5},
349 // [ROBUSTNESS] Two invalid English words concatenated with two Greek words
350 {L
"ifmmp" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
351 L
"ifmmp", false, 0, 5},
352 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word
353 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
354 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 0, 5},
355 // [ROBUSTNESS] Two invalid English words concatenated with a contraction
357 {L
"ifmmp:ifmmp", false, 0, 11},
359 // [REGRESSION] Issue 13432: "Any word of 13 or 14 characters is not
360 // spellcheck" <http://crbug.com/13432>.
361 {L
"qwertyuiopasd", false, 0, 13},
362 {L
"qwertyuiopasdf", false, 0, 14},
364 // [REGRESSION] Issue 128896: "en_US hunspell dictionary includes
365 // acknowledgement but not acknowledgements" <http://crbug.com/128896>
366 {L
"acknowledgement", true},
367 {L
"acknowledgements", true},
369 // Issue 123290: "Spellchecker should treat numbers as word characters"
385 {L
"100,000,000", true},
386 {L
"3.141592653", true},
389 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
390 size_t input_length
= 0;
391 if (kTestCases
[i
].input
!= NULL
) {
392 input_length
= wcslen(kTestCases
[i
].input
);
394 int misspelling_start
;
395 int misspelling_length
;
396 bool result
= spell_check()->SpellCheckWord(
397 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
398 static_cast<int>(input_length
),
401 &misspelling_length
, NULL
);
403 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
404 EXPECT_EQ(kTestCases
[i
].misspelling_start
, misspelling_start
);
405 EXPECT_EQ(kTestCases
[i
].misspelling_length
, misspelling_length
);
409 TEST_F(SpellCheckTest
, SpellCheckSuggestions_EN_US
) {
410 static const struct {
411 // A string to be tested.
412 const wchar_t* input
;
413 // An expected result for this test case.
414 // * true: the input string does not have any invalid words.
415 // * false: the input string has one or more invalid words.
416 bool expected_result
;
417 // The position and the length of the first invalid word.
418 int misspelling_start
;
419 int misspelling_length
;
421 // A suggested word that should occur.
422 const wchar_t* suggested_word
;
424 {L
"ello", false, 0, 0, L
"hello"},
425 {L
"ello", false, 0, 0, L
"cello"},
426 {L
"wate", false, 0, 0, L
"water"},
427 {L
"wate", false, 0, 0, L
"waste"},
428 {L
"wate", false, 0, 0, L
"sate"},
429 {L
"wate", false, 0, 0, L
"ate"},
430 {L
"jum", false, 0, 0, L
"jump"},
431 {L
"jum", false, 0, 0, L
"hum"},
432 {L
"jum", false, 0, 0, L
"sum"},
433 {L
"jum", false, 0, 0, L
"um"},
434 {L
"alot", false, 0, 0, L
"a lot"},
435 // A regression test for Issue 36523.
436 {L
"privliged", false, 0, 0, L
"privileged"},
437 // TODO (Sidchat): add many more examples.
440 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
441 std::vector
<base::string16
> suggestions
;
442 size_t input_length
= 0;
443 if (kTestCases
[i
].input
!= NULL
) {
444 input_length
= wcslen(kTestCases
[i
].input
);
446 int misspelling_start
;
447 int misspelling_length
;
448 bool result
= spell_check()->SpellCheckWord(
449 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
450 static_cast<int>(input_length
),
456 // Check for spelling.
457 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
459 // Check if the suggested words occur.
460 bool suggested_word_is_present
= false;
461 for (int j
= 0; j
< static_cast<int>(suggestions
.size()); j
++) {
462 if (suggestions
.at(j
).compare(
463 base::WideToUTF16(kTestCases
[i
].suggested_word
)) == 0) {
464 suggested_word_is_present
= true;
469 EXPECT_TRUE(suggested_word_is_present
);
473 // This test verifies our spellchecker can split a text into words and check
474 // the spelling of each word in the text.
475 #if defined(THREAD_SANITIZER)
476 // SpellCheckTest.SpellCheckText fails under ThreadSanitizer v2.
477 // See http://crbug.com/217909.
478 #define MAYBE_SpellCheckText DISABLED_SpellCheckText
480 #define MAYBE_SpellCheckText SpellCheckText
481 #endif // THREAD_SANITIZER
482 TEST_F(SpellCheckTest
, MAYBE_SpellCheckText
) {
483 static const struct {
484 const char* language
;
485 const wchar_t* input
;
490 L
"Google se missie is om die w\x00EAreld se inligting te organiseer en "
491 L
"dit bruikbaar en toeganklik te maak."
495 L
"La missi\x00F3 de Google \x00E9s organitzar la informaci\x00F3 "
496 L
"del m\x00F3n i fer que sigui \x00FAtil i accessible universalment."
500 L
"Posl\x00E1n\x00EDm spole\x010Dnosti Google je "
501 L
"uspo\x0159\x00E1\x0064\x0061t informace z cel\x00E9ho sv\x011Bta "
502 L
"tak, aby byly v\x0161\x0065obecn\x011B p\x0159\x00EDstupn\x00E9 "
503 L
"a u\x017Eite\x010Dn\x00E9."
508 L
"mission er at organisere verdens information og g\x00F8re den "
509 L
"almindeligt tilg\x00E6ngelig og nyttig."
513 L
"Das Ziel von Google besteht darin, die auf der Welt vorhandenen "
514 L
"Informationen zu organisieren und allgemein zug\x00E4nglich und "
515 L
"nutzbar zu machen."
519 L
"\x0391\x03C0\x03BF\x03C3\x03C4\x03BF\x03BB\x03AE "
520 L
"\x03C4\x03B7\x03C2 Google \x03B5\x03AF\x03BD\x03B1\x03B9 "
521 L
"\x03BD\x03B1 \x03BF\x03C1\x03B3\x03B1\x03BD\x03CE\x03BD\x03B5\x03B9 "
522 L
"\x03C4\x03B9\x03C2 "
523 L
"\x03C0\x03BB\x03B7\x03C1\x03BF\x03C6\x03BF\x03C1\x03AF\x03B5\x03C2 "
524 L
"\x03C4\x03BF\x03C5 \x03BA\x03CC\x03C3\x03BC\x03BF\x03C5 "
525 L
"\x03BA\x03B1\x03B9 \x03BD\x03B1 \x03C4\x03B9\x03C2 "
526 L
"\x03BA\x03B1\x03B8\x03B9\x03C3\x03C4\x03AC "
527 L
"\x03C0\x03C1\x03BF\x03C3\x03B2\x03AC\x03C3\x03B9\x03BC\x03B5\x03C2 "
528 L
"\x03BA\x03B1\x03B9 \x03C7\x03C1\x03AE\x03C3\x03B9\x03BC\x03B5\x03C2."
530 // English (Australia)
532 L
"Google's mission is to organise the world's information and make it "
533 L
"universally accessible and useful."
537 L
"Google's mission is to organize the world's information and make it "
538 L
"universally accessible and useful."
540 // English (United Kingdom)
542 L
"Google's mission is to organise the world's information and make it "
543 L
"universally accessible and useful."
545 // English (United States)
547 L
"Google's mission is to organize the world's information and make it "
548 L
"universally accessible and useful."
552 L
"\x041c\x0438\x0441\x0438\x044f\x0442\x0430 "
553 L
"\x043d\x0430 Google \x0435 \x0434\x0430 \x043e"
554 L
"\x0440\x0433\x0430\x043d\x0438\x0437\x0438\x0440"
555 L
"\x0430 \x0441\x0432\x0435\x0442\x043e\x0432"
556 L
"\x043d\x0430\x0442\x0430 \x0438\x043d\x0444"
557 L
"\x043e\x0440\x043c\x0430\x0446\x0438\x044f "
558 L
"\x0438 \x0434\x0430 \x044f \x043d"
559 L
"\x0430\x043f\x0440\x0430\x0432\x0438 \x0443"
560 L
"\x043d\x0438\x0432\x0435\x0440\x0441\x0430\x043b"
561 L
"\x043d\x043e \x0434\x043e\x0441\x0442\x044a"
562 L
"\x043f\x043d\x0430 \x0438 \x043f\x043e"
563 L
"\x043b\x0435\x0437\x043d\x0430."
567 L
"La misi\x00F3n de "
568 // L"Google" - to be added.
569 L
" es organizar la informaci\x00F3n mundial "
570 L
"para que resulte universalmente accesible y \x00FAtil."
574 // L"Google'ile " - to be added.
575 L
"\x00FClesanne on korraldada maailma teavet ja teeb selle "
576 L
"k\x00F5igile k\x00E4ttesaadavaks ja kasulikuks.",
580 L
"Google er at samskipa alla vitan \x00ED heiminum og gera hana alment "
581 L
"atkomiliga og n\x00FDtiliga."
585 L
"Google a pour mission d'organiser les informations \x00E0 "
586 L
"l'\x00E9\x0063helle mondiale dans le but de les rendre accessibles "
587 L
"et utiles \x00E0 tous."
591 L
"\x05D4\x05DE\x05E9\x05D9\x05DE\x05D4 \x05E9\x05DC Google "
592 L
"\x05D4\x05D9\x05D0 \x05DC\x05D0\x05E8\x05D2\x05DF "
593 L
"\x05D0\x05EA \x05D4\x05DE\x05D9\x05D3\x05E2 "
594 L
"\x05D4\x05E2\x05D5\x05DC\x05DE\x05D9 "
595 L
"\x05D5\x05DC\x05D4\x05E4\x05D5\x05DA \x05D0\x05D5\x05EA\x05D5 "
596 L
"\x05DC\x05D6\x05DE\x05D9\x05DF "
597 L
"\x05D5\x05E9\x05D9\x05DE\x05D5\x05E9\x05D9 \x05D1\x05DB\x05DC "
598 L
"\x05D4\x05E2\x05D5\x05DC\x05DD. "
599 // Two words with ASCII double/single quoation marks.
600 L
"\x05DE\x05E0\x05DB\x0022\x05DC \x05E6\x0027\x05D9\x05E4\x05E1"
604 L
"Google \x0915\x093E \x092E\x093F\x0936\x0928 "
605 L
"\x0926\x0941\x0928\x093F\x092F\x093E \x0915\x0940 "
606 L
"\x091C\x093E\x0928\x0915\x093E\x0930\x0940 \x0915\x094B "
607 L
"\x0935\x094D\x092F\x0935\x0938\x094D\x0925\x093F\x0924 "
608 L
"\x0915\x0930\x0928\x093E \x0914\x0930 \x0909\x0938\x0947 "
609 L
"\x0938\x093E\x0930\x094D\x0935\x092D\x094C\x092E\x093F\x0915 "
610 L
"\x0930\x0942\x092A \x0938\x0947 \x092A\x0939\x0941\x0901\x091A "
611 L
"\x092E\x0947\x0902 \x0914\x0930 \x0909\x092A\x092F\x094B\x0917\x0940 "
612 L
"\x092C\x0928\x093E\x0928\x093E \x0939\x0948."
616 L
"A Google azt a k\x00FCldet\x00E9st v\x00E1llalta mag\x00E1ra, "
617 L
"hogy a vil\x00E1gon fellelhet\x0151 inform\x00E1\x0063i\x00F3kat "
618 L
"rendszerezze \x00E9s \x00E1ltal\x00E1nosan el\x00E9rhet\x0151v\x00E9, "
619 L
"illetve haszn\x00E1lhat\x00F3v\x00E1 tegye."
623 // L"Googleova " - to be added.
624 L
"je misija organizirati svjetske informacije i u\x010Diniti ih "
625 // L"univerzalno " - to be added.
626 L
"pristupa\x010Dnima i korisnima."
630 L
"Misi Google adalah untuk mengelola informasi dunia dan membuatnya "
631 L
"dapat diakses dan bermanfaat secara universal."
635 L
"La missione di Google \x00E8 organizzare le informazioni a livello "
636 L
"mondiale e renderle universalmente accessibili e fruibili."
640 L
"\x201EGoogle\x201C tikslas \x2013 rinkti ir sisteminti pasaulio "
641 L
"informacij\x0105 bei padaryti j\x0105 prieinam\x0105 ir "
642 L
"nauding\x0105 visiems."
646 L
"Google uzdevums ir k\x0101rtot pasaules inform\x0101"
647 L
"ciju un padar\x012Bt to univers\x0101li pieejamu un noder\x012Bgu."
651 // L"Googles " - to be added.
652 L
"m\x00E5l er \x00E5 organisere informasjonen i verden og "
653 L
"gj\x00F8re den tilgjengelig og nyttig for alle."
657 L
"Het doel van Google is om alle informatie wereldwijd toegankelijk "
658 L
"en bruikbaar te maken."
662 L
"Misj\x0105 Google jest uporz\x0105" L
"dkowanie \x015Bwiatowych "
663 L
"zasob\x00F3w informacji, aby sta\x0142y si\x0119 one powszechnie "
664 L
"dost\x0119pne i u\x017Cyteczne."
666 // Portuguese (Brazil)
669 #if !defined(OS_MACOSX)
672 L
"\x00E9 organizar as informa\x00E7\x00F5"
673 L
"es do mundo todo e "
674 #if !defined(OS_MACOSX)
677 L
"acess\x00EDveis e \x00FAteis em car\x00E1ter universal."
679 // Portuguese (Portugal)
682 #if !defined(OS_MACOSX)
685 L
"tem por miss\x00E3o organizar a informa\x00E7\x00E3o do "
687 #if !defined(OS_MACOSX)
690 L
"universalmente acess\x00EDvel e \x00FAtil"
694 L
"Misiunea Google este de a organiza informa\x021B3iile lumii \x0219i de "
695 L
"a le face accesibile \x0219i utile la nivel universal."
699 L
"\x041C\x0438\x0441\x0441\x0438\x044F Google "
700 L
"\x0441\x043E\x0441\x0442\x043E\x0438\x0442 \x0432 "
701 L
"\x043E\x0440\x0433\x0430\x043D\x0438\x0437\x0430\x0446\x0438\x0438 "
702 L
"\x043C\x0438\x0440\x043E\x0432\x043E\x0439 "
703 L
"\x0438\x043D\x0444\x043E\x0440\x043C\x0430\x0446\x0438\x0438, "
704 L
"\x043E\x0431\x0435\x0441\x043F\x0435\x0447\x0435\x043D\x0438\x0438 "
706 L
"\x0434\x043E\x0441\x0442\x0443\x043F\x043D\x043E\x0441\x0442\x0438 "
707 L
"\x0438 \x043F\x043E\x043B\x044C\x0437\x044B \x0434\x043B\x044F "
708 L
"\x0432\x0441\x0435\x0445."
709 // A Russian word including U+0451. (Bug 15558 <http://crbug.com/15558>)
710 L
"\x0451\x043B\x043A\x0430"
712 // Serbo-Croatian (Serbian Latin)
714 L
"Google-ova misija je da organizuje sve informacije na svetu i "
715 L
"u\x010dini ih univerzal-no dostupnim i korisnim."
719 L
"\x0047\x006f\x006f\x0067\x006c\x0065\x002d\x043e\x0432\x0430 "
720 L
"\x043c\x0438\x0441\x0438\x0458\x0430 \x0458\x0435 \x0434\x0430 "
721 L
"\x043e\x0440\x0433\x0430\x043d\x0438\x0437\x0443\x0458\x0435 "
722 L
"\x0441\x0432\x0435 "
723 L
"\x0438\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0438\x0458\x0435 "
724 L
"\x043d\x0430 \x0441\x0432\x0435\x0442\x0443 \x0438 "
725 L
"\x0443\x0447\x0438\x043d\x0438 \x0438\x0445 "
726 L
"\x0443\x043d\x0438\x0432\x0435\x0440\x0437\x0430\x043b\x043d\x043e "
727 L
"\x0434\x043e\x0441\x0442\x0443\x043f\x043d\x0438\x043c \x0438 "
728 L
"\x043a\x043e\x0440\x0438\x0441\x043d\x0438\x043c."
732 L
"Spolo\x010Dnos\x0165 Google si dala za \x00FAlohu usporiada\x0165 "
733 L
"inform\x00E1\x0063ie "
734 L
"z cel\x00E9ho sveta a zabezpe\x010Di\x0165, "
735 L
"aby boli v\x0161eobecne dostupn\x00E9 a u\x017Eito\x010Dn\x00E9."
739 // L"Googlovo " - to be added.
740 L
"poslanstvo je organizirati svetovne informacije in "
741 L
"omogo\x010Diti njihovo dostopnost in s tem uporabnost za vse."
745 L
"Googles m\x00E5ls\x00E4ttning \x00E4r att ordna v\x00E4rldens "
746 L
"samlade information och g\x00F6ra den tillg\x00E4nglig f\x00F6r alla."
750 // L"Google\x2019\x0131n " - to be added.
751 L
"misyonu, d\x00FCnyadaki t\x00FCm bilgileri "
752 L
"organize etmek ve evrensel olarak eri\x015Filebilir ve "
753 L
"kullan\x0131\x015Fl\x0131 k\x0131lmakt\x0131r."
757 L
"\x041c\x0456\x0441\x0456\x044f "
758 L
"\x043a\x043e\x043c\x043f\x0430\x043d\x0456\x0457 Google "
759 L
"\x043f\x043e\x043b\x044f\x0433\x0430\x0454 \x0432 "
760 L
"\x0442\x043e\x043c\x0443, \x0449\x043e\x0431 "
761 L
"\x0443\x043f\x043e\x0440\x044f\x0434\x043a\x0443\x0432\x0430\x0442"
762 L
"\x0438 \x0456\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0456\x044e "
763 L
"\x0437 \x0443\x0441\x044c\x043e\x0433\x043e "
764 L
"\x0441\x0432\x0456\x0442\x0443 \x0442\x0430 "
765 L
"\x0437\x0440\x043e\x0431\x0438\x0442\x0438 \x0457\x0457 "
766 L
"\x0443\x043d\x0456\x0432\x0435\x0440\x0441\x0430\x043b\x044c\x043d"
767 L
"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e "
768 L
"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e."
772 L
"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 "
773 L
"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 "
774 L
"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 "
775 L
"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 "
776 L
"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n."
780 L
"Google\xC758 \xBAA9\xD45C\xB294 \xC804\xC138\xACC4\xC758 "
781 L
"\xC815\xBCF4\xB97C \xCCB4\xACC4\xD654\xD558\xC5EC \xBAA8\xB450\xAC00 "
782 L
"\xD3B8\xB9AC\xD558\xAC8C \xC774\xC6A9\xD560 \xC218 "
783 L
"\xC788\xB3C4\xB85D \xD558\xB294 \xAC83\xC785\xB2C8\xB2E4."
787 L
"Misioni i Google \x00EBsht\x00EB q\x00EB t\x00EB organizoj\x00EB "
788 L
"informacionin e bot\x00EBs dhe t\x00EB b\x00EBjn\x00EB at\x00EB "
789 L
"universalisht t\x00EB arritshme dhe t\x00EB dobishme."
793 L
"Google \x0B87\x0BA9\x0BCD "
794 L
"\x0BA8\x0BC7\x0BBE\x0B95\x0BCD\x0B95\x0BAE\x0BCD "
795 L
"\x0B89\x0BB2\x0B95\x0BBF\x0BA9\x0BCD \x0BA4\x0B95\x0BB5\x0BB2\x0BCD "
796 L
"\x0B8F\x0BB1\x0BCD\x0BAA\x0BBE\x0B9F\x0BC1 \x0B87\x0BA4\x0BC1 "
797 L
"\x0B89\x0BB2\x0B95\x0BB3\x0BBE\x0BB5\x0BBF\x0BAF "
798 L
"\x0B85\x0BA3\x0BC1\x0B95\x0B95\x0BCD \x0B95\x0BC2\x0B9F\x0BBF\x0BAF "
799 L
"\x0BAE\x0BB1\x0BCD\x0BB1\x0BC1\x0BAE\x0BCD "
800 L
"\x0BAA\x0BAF\x0BA9\x0BC1\x0BB3\x0BCD\x0BB3 "
801 L
"\x0B9A\x0BC6\x0BAF\x0BCD\x0BAF \x0B89\x0BB3\x0BCD\x0BB3\x0BA4\x0BC1."
805 L
"\x041c\x0438\x0441\x0441\x0438\x044f\x0438 Google \x0438\x043d "
806 L
"\x043c\x0443\x0440\x0430\x0442\x0442\x0430\x0431 "
807 L
"\x0441\x043e\x0445\x0442\x0430\x043d\x0438 "
808 L
"\x043c\x0430\x044a\x043b\x0443\x043c\x043e\x0442\x04b3\x043e\x0438 "
809 L
"\x043c\x0430\x0432\x04b7\x0443\x0434\x0430, \x043e\x0441\x043e\x043d "
810 L
"\x043d\x0430\x043c\x0443\x0434\x0430\x043d\x0438 "
811 L
"\x0438\x0441\x0442\x0438\x0444\x043e\x0434\x0430\x0431\x0430\x0440"
812 L
"\x04e3 \x0432\x0430 \x0434\x0430\x0441\x0442\x0440\x0430\x0441\x0438 "
813 L
"\x0443\x043c\x0443\x043c "
814 L
"\x0433\x0430\x0440\x0434\x043e\x043d\x0438\x0434\x0430\x043d\x0438 "
815 L
"\x043e\x043d\x04b3\x043e \x0430\x0441\x0442."
819 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
820 ReinitializeSpellCheck(kTestCases
[i
].language
);
821 size_t input_length
= 0;
822 if (kTestCases
[i
].input
!= NULL
)
823 input_length
= wcslen(kTestCases
[i
].input
);
825 int misspelling_start
= 0;
826 int misspelling_length
= 0;
827 bool result
= spell_check()->SpellCheckWord(
828 base::WideToUTF16(kTestCases
[i
].input
).c_str(),
829 static_cast<int>(input_length
),
832 &misspelling_length
, NULL
);
836 << std::wstring(kTestCases
[i
].input
).substr(
837 misspelling_start
, misspelling_length
)
838 << "\" is misspelled in "
839 << kTestCases
[i
].language
841 EXPECT_EQ(0, misspelling_start
);
842 EXPECT_EQ(0, misspelling_length
);
846 TEST_F(SpellCheckTest
, GetAutoCorrectionWord_EN_US
) {
847 static const struct {
848 // A misspelled word.
851 // An expected result for this test case.
852 // Should be an empty string if there are no suggestions for auto correct.
853 const char* expected_result
;
862 EnableAutoCorrect(true);
864 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
865 base::string16
misspelled_word(base::UTF8ToUTF16(kTestCases
[i
].input
));
866 base::string16
expected_autocorrect_word(
867 base::UTF8ToUTF16(kTestCases
[i
].expected_result
));
868 base::string16 autocorrect_word
= spell_check()->GetAutoCorrectionWord(
871 // Check for spelling.
872 EXPECT_EQ(expected_autocorrect_word
, autocorrect_word
);
876 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks
878 TEST_F(SpellCheckTest
, MisspelledWords
) {
879 static const struct {
880 const char* language
;
881 const wchar_t* input
;
884 // A misspelled word for English
888 // A misspelled word for Greek.
890 L
"\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1",
892 // A misspelled word for Hebrew
894 L
"\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0",
898 L
"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905",
900 // A misspelled word for Russian
902 L
"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430",
906 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
907 ReinitializeSpellCheck(kTestCases
[i
].language
);
909 base::string16
word(base::WideToUTF16(kTestCases
[i
].input
));
910 int word_length
= static_cast<int>(word
.length());
911 int misspelling_start
= 0;
912 int misspelling_length
= 0;
913 bool result
= spell_check()->SpellCheckWord(word
.c_str(),
919 EXPECT_FALSE(result
);
920 EXPECT_EQ(0, misspelling_start
);
921 EXPECT_EQ(word_length
, misspelling_length
);
925 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac,
926 // we skip these SpellCheckParagraph tests on Mac.
927 #if !defined(OS_MACOSX)
929 // Make sure SpellCheckParagraph does not crash if the input is empty.
930 TEST_F(SpellCheckTest
, SpellCheckParagraphEmptyParagraph
) {
931 std::vector
<SpellCheckResult
> expected
;
932 TestSpellCheckParagraph(base::UTF8ToUTF16(""), expected
);
935 // A simple test case having no misspellings.
936 TEST_F(SpellCheckTest
, SpellCheckParagraphNoMisspellings
) {
937 const base::string16 text
= base::UTF8ToUTF16("apple");
938 std::vector
<SpellCheckResult
> expected
;
939 TestSpellCheckParagraph(text
, expected
);
942 // A simple test case having one misspelling.
943 TEST_F(SpellCheckTest
, SpellCheckParagraphSingleMisspellings
) {
944 const base::string16 text
= base::UTF8ToUTF16("zz");
945 std::vector
<SpellCheckResult
> expected
;
946 expected
.push_back(SpellCheckResult(
947 SpellCheckResult::SPELLING
, 0, 2));
949 TestSpellCheckParagraph(text
, expected
);
952 // A simple test case having multiple misspellings.
953 TEST_F(SpellCheckTest
, SpellCheckParagraphMultipleMisspellings
) {
954 const base::string16 text
= base::UTF8ToUTF16("zz, zz");
955 std::vector
<SpellCheckResult
> expected
;
956 expected
.push_back(SpellCheckResult(
957 SpellCheckResult::SPELLING
, 0, 2));
958 expected
.push_back(SpellCheckResult(
959 SpellCheckResult::SPELLING
, 4, 2));
961 TestSpellCheckParagraph(text
, expected
);
964 // Make sure a relatively long (correct) sentence can be spellchecked.
965 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentence
) {
966 std::vector
<SpellCheckResult
> expected
;
967 // The text is taken from US constitution preamble.
968 const base::string16 text
= base::UTF8ToUTF16(
969 "We the people of the United States, in order to form a more perfect "
970 "union, establish justice, insure domestic tranquility, provide for "
971 "the common defense, promote the general welfare, and secure the "
972 "blessings of liberty to ourselves and our posterity, do ordain and "
973 "establish this Constitution for the United States of America.");
975 TestSpellCheckParagraph(text
, expected
);
978 // Make sure all misspellings can be found in a relatively long sentence.
979 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentenceMultipleMisspellings
) {
980 std::vector
<SpellCheckResult
> expected
;
982 // All 'the' are converted to 'hte' in US consitition preamble.
983 const base::string16 text
= base::UTF8ToUTF16(
984 "We hte people of hte United States, in order to form a more perfect "
985 "union, establish justice, insure domestic tranquility, provide for "
986 "hte common defense, promote hte general welfare, and secure hte "
987 "blessings of liberty to ourselves and our posterity, do ordain and "
988 "establish this Constitution for hte United States of America.");
990 expected
.push_back(SpellCheckResult(
991 SpellCheckResult::SPELLING
, 3, 3));
992 expected
.push_back(SpellCheckResult(
993 SpellCheckResult::SPELLING
, 17, 3));
994 expected
.push_back(SpellCheckResult(
995 SpellCheckResult::SPELLING
, 135, 3));
996 expected
.push_back(SpellCheckResult(
997 SpellCheckResult::SPELLING
, 163, 3));
998 expected
.push_back(SpellCheckResult(
999 SpellCheckResult::SPELLING
, 195, 3));
1000 expected
.push_back(SpellCheckResult(
1001 SpellCheckResult::SPELLING
, 298, 3));
1003 TestSpellCheckParagraph(text
, expected
);
1006 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker
1007 // is used on Mac instead of SpellCheck::RequestTextChecking.
1009 // Make sure RequestTextChecking does not crash if input is empty.
1010 TEST_F(SpellCheckTest
, RequestSpellCheckWithEmptyString
) {
1011 MockTextCheckingCompletion completion
;
1013 spell_check()->RequestTextChecking(base::string16(), &completion
);
1015 base::MessageLoop::current()->RunUntilIdle();
1017 EXPECT_EQ(completion
.completion_count_
, 1U);
1020 // A simple test case having no misspellings.
1021 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutMisspelling
) {
1022 MockTextCheckingCompletion completion
;
1024 const base::string16 text
= base::ASCIIToUTF16("hello");
1025 spell_check()->RequestTextChecking(text
, &completion
);
1027 base::MessageLoop::current()->RunUntilIdle();
1029 EXPECT_EQ(completion
.completion_count_
, 1U);
1032 // A simple test case having one misspelling.
1033 TEST_F(SpellCheckTest
, RequestSpellCheckWithSingleMisspelling
) {
1034 MockTextCheckingCompletion completion
;
1036 const base::string16 text
= base::ASCIIToUTF16("apple, zz");
1037 spell_check()->RequestTextChecking(text
, &completion
);
1039 base::MessageLoop::current()->RunUntilIdle();
1041 EXPECT_EQ(completion
.completion_count_
, 1U);
1042 EXPECT_EQ(completion
.last_results_
.size(), 1U);
1043 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1044 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1047 // A simple test case having a few misspellings.
1048 TEST_F(SpellCheckTest
, RequestSpellCheckWithMisspellings
) {
1049 MockTextCheckingCompletion completion
;
1051 const base::string16 text
= base::ASCIIToUTF16("apple, zz, orange, zz");
1052 spell_check()->RequestTextChecking(text
, &completion
);
1054 base::MessageLoop::current()->RunUntilIdle();
1056 EXPECT_EQ(completion
.completion_count_
, 1U);
1057 EXPECT_EQ(completion
.last_results_
.size(), 2U);
1058 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1059 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1060 EXPECT_EQ(completion
.last_results_
[1].location
, 19);
1061 EXPECT_EQ(completion
.last_results_
[1].length
, 2);
1064 // A test case that multiple requests comes at once. Make sure all
1065 // requests are processed.
1066 TEST_F(SpellCheckTest
, RequestSpellCheckWithMultipleRequests
) {
1067 MockTextCheckingCompletion completion
[3];
1069 const base::string16 text
[3] = {
1070 base::ASCIIToUTF16("what, zz"),
1071 base::ASCIIToUTF16("apple, zz"),
1072 base::ASCIIToUTF16("orange, zz")
1075 for (int i
= 0; i
< 3; ++i
)
1076 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1078 base::MessageLoop::current()->RunUntilIdle();
1080 for (int i
= 0; i
< 3; ++i
) {
1081 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1082 EXPECT_EQ(completion
[i
].last_results_
.size(), 1U);
1083 EXPECT_EQ(completion
[i
].last_results_
[0].location
, 6 + i
);
1084 EXPECT_EQ(completion
[i
].last_results_
[0].length
, 2);
1088 // A test case that spellchecking is requested before initializing.
1089 // In this case, we postpone to post a request.
1090 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutInitialization
) {
1091 UninitializeSpellCheck();
1093 MockTextCheckingCompletion completion
;
1094 const base::string16 text
= base::ASCIIToUTF16("zz");
1096 spell_check()->RequestTextChecking(text
, &completion
);
1098 // The task will not be posted yet.
1099 base::MessageLoop::current()->RunUntilIdle();
1100 EXPECT_EQ(completion
.completion_count_
, 0U);
1103 // Requests several spellchecking before initializing. Except the last one,
1104 // posting requests is cancelled and text is rendered as correct one.
1105 TEST_F(SpellCheckTest
, RequestSpellCheckMultipleTimesWithoutInitialization
) {
1106 UninitializeSpellCheck();
1108 MockTextCheckingCompletion completion
[3];
1109 const base::string16 text
[3] = {
1110 base::ASCIIToUTF16("what, zz"),
1111 base::ASCIIToUTF16("apple, zz"),
1112 base::ASCIIToUTF16("orange, zz")
1115 // Calls RequestTextchecking a few times.
1116 for (int i
= 0; i
< 3; ++i
)
1117 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1119 // The last task will be posted after initialization, however the other
1120 // requests should be pressed without spellchecking.
1121 base::MessageLoop::current()->RunUntilIdle();
1122 for (int i
= 0; i
< 2; ++i
)
1123 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1124 EXPECT_EQ(completion
[2].completion_count_
, 0U);
1126 // Checks the last request is processed after initialization.
1127 InitializeSpellCheck("en-US");
1129 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity.
1130 spell_check()->PostDelayedSpellCheckTask(
1131 spell_check()->pending_request_param_
.release());
1132 base::MessageLoop::current()->RunUntilIdle();
1133 for (int i
= 0; i
< 3; ++i
)
1134 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1139 // Verify that the SpellCheck class keeps the spelling marker added to a
1140 // misspelled word "zz".
1141 TEST_F(SpellCheckTest
, CreateTextCheckingResultsKeepsMarkers
) {
1142 base::string16 text
= base::ASCIIToUTF16("zz");
1143 std::vector
<SpellCheckResult
> spellcheck_results
;
1144 spellcheck_results
.push_back(
1145 SpellCheckResult(SpellCheckResult::SPELLING
, 0, 2, base::string16()));
1146 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1147 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1148 text
, spellcheck_results
,
1149 &textcheck_results
);
1150 ASSERT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1151 EXPECT_EQ(blink::WebTextDecorationTypeSpelling
,
1152 textcheck_results
[0].decoration
);
1153 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1154 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1157 // Verify that the SpellCheck class replaces the spelling marker added to a
1158 // contextually-misspelled word "bean" with a grammar marker.
1159 TEST_F(SpellCheckTest
, CreateTextCheckingResultsAddsGrammarMarkers
) {
1160 base::string16 text
= base::ASCIIToUTF16("I have bean to USA.");
1161 std::vector
<SpellCheckResult
> spellcheck_results
;
1162 spellcheck_results
.push_back(
1163 SpellCheckResult(SpellCheckResult::SPELLING
, 7, 4, base::string16()));
1164 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1165 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1166 text
, spellcheck_results
,
1167 &textcheck_results
);
1168 ASSERT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1169 EXPECT_EQ(blink::WebTextDecorationTypeGrammar
,
1170 textcheck_results
[0].decoration
);
1171 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1172 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1175 // Verify that the SpellCheck preserves the original apostrophe type in the
1176 // checked text, regardless of the type of apostrophe the browser returns.
1177 TEST_F(SpellCheckTest
, CreateTextCheckingResultsKeepsTypographicalApostrophe
) {
1178 base::string16 text
= base::WideToUTF16(
1179 L
"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L
"t ni'n"
1180 TYPOGRAPHICAL_APOSTROPHE L
"out-s I've I" TYPOGRAPHICAL_APOSTROPHE
1182 std::vector
<SpellCheckResult
> spellcheck_results
;
1184 // All typewriter apostrophe results.
1185 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 0,
1186 5, base::UTF8ToUTF16("I've")));
1187 spellcheck_results
.push_back(SpellCheckResult(
1188 SpellCheckResult::SPELLING
, 6, 6, base::UTF8ToUTF16("haven't")));
1189 spellcheck_results
.push_back(SpellCheckResult(
1190 SpellCheckResult::SPELLING
, 13, 10, base::UTF8ToUTF16("in'n'out's")));
1192 // Replacements that differ only by apostrophe type should be ignored.
1193 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 24,
1194 4, base::UTF8ToUTF16("I've")));
1195 spellcheck_results
.push_back(SpellCheckResult(SpellCheckResult::SPELLING
, 29,
1196 4, base::UTF8ToUTF16("I've")));
1198 // All typographical apostrophe results.
1199 spellcheck_results
.push_back(
1200 SpellCheckResult(SpellCheckResult::SPELLING
, 0, 5,
1201 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1202 spellcheck_results
.push_back(SpellCheckResult(
1203 SpellCheckResult::SPELLING
, 6, 6,
1204 base::WideToUTF16(L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t")));
1205 spellcheck_results
.push_back(SpellCheckResult(
1206 SpellCheckResult::SPELLING
, 13, 10, base::WideToUTF16(
1207 L
"in" TYPOGRAPHICAL_APOSTROPHE L
"n" TYPOGRAPHICAL_APOSTROPHE L
"out"
1208 TYPOGRAPHICAL_APOSTROPHE L
"s")));
1210 // Replacements that differ only by apostrophe type should be ignored.
1211 spellcheck_results
.push_back(
1212 SpellCheckResult(SpellCheckResult::SPELLING
, 24, 4,
1213 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1214 spellcheck_results
.push_back(
1215 SpellCheckResult(SpellCheckResult::SPELLING
, 29, 4,
1216 base::WideToUTF16(L
"I" TYPOGRAPHICAL_APOSTROPHE L
"ve")));
1218 blink::WebVector
<blink::WebTextCheckingResult
> textcheck_results
;
1219 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
, 0,
1220 text
, spellcheck_results
,
1221 &textcheck_results
);
1223 static const wchar_t* kExpectedReplacements
[] = {
1225 L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t",
1226 L
"in'n" TYPOGRAPHICAL_APOSTROPHE L
"out's",
1228 L
"haven" TYPOGRAPHICAL_APOSTROPHE L
"t",
1229 L
"in'n" TYPOGRAPHICAL_APOSTROPHE L
"out" TYPOGRAPHICAL_APOSTROPHE L
"s",
1232 ASSERT_EQ(arraysize(kExpectedReplacements
), textcheck_results
.size());
1233 for (size_t i
= 0; i
< arraysize(kExpectedReplacements
); ++i
) {
1234 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements
[i
]),
1235 textcheck_results
[i
].replacement
)
1236 << "i=" << i
<< "\nactual: \""
1237 << base::string16(textcheck_results
[i
].replacement
) << "\"";
1241 // Checks some words that should be present in all English dictionaries.
1242 TEST_F(SpellCheckTest
, EnglishWords
) {
1243 static const struct {
1247 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking
1249 {"Chromebook", true},
1250 {"Chromebooks", true},
1251 {"Chromebox", true},
1252 {"Chromeboxes", true},
1253 {"Chromeblade", true},
1254 {"Chromeblades", true},
1255 {"Chromebase", true},
1256 {"Chromebases", true},
1257 // Issue 94708: Spell-checker incorrectly reports whisky as misspelled.
1261 // Issue 98678: "Recency" should be included in client-side dictionary.
1263 {"recencies", false},
1269 static const char* const kLocales
[] = { "en-GB", "en-US", "en-CA", "en-AU" };
1271 for (size_t j
= 0; j
< arraysize(kLocales
); ++j
) {
1272 ReinitializeSpellCheck(kLocales
[j
]);
1273 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
1274 size_t input_length
= 0;
1275 if (kTestCases
[i
].input
!= NULL
)
1276 input_length
= strlen(kTestCases
[i
].input
);
1278 int misspelling_start
= 0;
1279 int misspelling_length
= 0;
1280 bool result
= spell_check()->SpellCheckWord(
1281 base::ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1282 static_cast<int>(input_length
),
1285 &misspelling_length
, NULL
);
1287 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].input
<<
1288 " in " << kLocales
[j
];
1293 // Checks that NOSUGGEST works in English dictionaries.
1294 TEST_F(SpellCheckTest
, NoSuggest
) {
1295 static const struct {
1297 const char* suggestion
;
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},
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
);
1323 // First check that the NOSUGGEST flag didn't mark this word as not being in
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 static_cast<int>(suggestion_length
),
1332 &misspelling_length
, NULL
);
1334 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].suggestion
<<
1335 " in " << kTestCases
[i
].locale
;
1337 // Now verify that this test case does not show up as a suggestion.
1338 std::vector
<base::string16
> suggestions
;
1339 size_t input_length
= 0;
1340 if (kTestCases
[i
].input
!= NULL
)
1341 input_length
= strlen(kTestCases
[i
].input
);
1342 result
= spell_check()->SpellCheckWord(
1343 base::ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1344 static_cast<int>(input_length
),
1347 &misspelling_length
,
1349 // Input word should be a misspelling.
1350 EXPECT_FALSE(result
) << kTestCases
[i
].input
1351 << " is not a misspelling in "
1352 << kTestCases
[i
].locale
;
1353 // Check if the suggested words occur.
1354 for (int j
= 0; j
< static_cast<int>(suggestions
.size()); j
++) {
1355 for (size_t t
= 0; t
< test_cases_size
; t
++) {
1356 int compare_result
= suggestions
.at(j
).compare(
1357 base::ASCIIToUTF16(kTestCases
[t
].suggestion
));
1358 EXPECT_FALSE(compare_result
== 0) << kTestCases
[t
].suggestion
<<
1359 " in " << kTestCases
[i
].locale
;
1365 // Check that the correct dictionary files are checked in.
1366 TEST_F(SpellCheckTest
, DictionaryFiles
) {
1367 std::vector
<std::string
> spellcheck_languages
;
1368 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages
);
1369 EXPECT_FALSE(spellcheck_languages
.empty());
1371 base::FilePath hunspell
= GetHunspellDirectory();
1372 for (size_t i
= 0; i
< spellcheck_languages
.size(); ++i
) {
1373 base::FilePath dict
= chrome::spellcheck_common::GetVersionedFileName(
1374 spellcheck_languages
[i
], hunspell
);
1375 EXPECT_TRUE(base::PathExists(dict
)) << dict
.value() << " not found";
1379 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded.
1380 TEST_F(SpellCheckTest
, SpellingEngine_CheckSpelling
) {
1381 static const struct {
1383 bool expected_result
;
1386 { "automatic", true },
1388 { "forglobantic", false },
1389 { "xfdssfsdfaasds", false },
1390 { // 64 chars are the longest word to check - this should fail checking.
1391 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl",
1394 { // Any word longer than 64 chars should be exempt from checking.
1395 "reallylongwordthatabsolutelyexceedsthespecifiedcharacterlimitabit",
1400 // Initialization magic - call InitializeIfNeeded twice. The first one simply
1401 // flags internal state that a dictionary was requested. The second one will
1402 // take the passed-in file and initialize hunspell with it. (The file was
1403 // passed to hunspell in the ctor for the test fixture).
1404 // This needs to be done since we need to ensure the SpellingEngine objects
1405 // contained in the SpellcheckLanguages in |languages_| from the test fixture
1406 // does get initialized.
1407 // TODO(groby): Clean up this mess.
1408 InitializeIfNeeded();
1409 ASSERT_FALSE(InitializeIfNeeded());
1411 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
1412 bool result
= CheckSpelling(kTestCases
[i
].word
, 0);
1413 EXPECT_EQ(kTestCases
[i
].expected_result
, result
) <<
1414 "Failed test for " << kTestCases
[i
].word
;
1418 // Chrome should not suggest "Othello" for "hellllo" or "identically" for
1420 TEST_F(SpellCheckTest
, LogicalSuggestions
) {
1421 static const struct {
1422 const char* misspelled
;
1423 const char* suggestion
;
1425 { "hellllo", "hello" },
1426 { "accidently", "accidentally" }
1429 for (size_t i
= 0; i
< arraysize(kTestCases
); ++i
) {
1430 int misspelling_start
= 0;
1431 int misspelling_length
= 0;
1432 std::vector
<base::string16
> suggestions
;
1433 EXPECT_FALSE(spell_check()->SpellCheckWord(
1434 base::ASCIIToUTF16(kTestCases
[i
].misspelled
).c_str(),
1435 strlen(kTestCases
[i
].misspelled
),
1438 &misspelling_length
,
1440 EXPECT_GE(suggestions
.size(), static_cast<size_t>(1));
1441 if (suggestions
.size() > 0)
1442 EXPECT_EQ(suggestions
[0], base::ASCIIToUTF16(kTestCases
[i
].suggestion
));
1446 // Words with apostrophes should be valid contractions.
1447 TEST_F(SpellCheckTest
, IsValidContraction
) {
1448 static const char* kLanguages
[] = {
1455 static const wchar_t* kWords
[] = {
1457 L
"in" TYPOGRAPHICAL_APOSTROPHE L
"n" TYPOGRAPHICAL_APOSTROPHE L
"out",
1460 for (size_t i
= 0; i
< arraysize(kLanguages
); ++i
) {
1461 ReinitializeSpellCheck(kLanguages
[i
]);
1462 for (size_t j
= 0; j
< arraysize(kWords
); ++j
)
1463 EXPECT_TRUE(IsValidContraction(base::WideToUTF16(kWords
[j
]), 0));