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 "webkit/glue/webkit_glue.h"
7 #include "base/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
10 #include "base/platform_file.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/spellcheck_common.h"
15 #include "chrome/common/spellcheck_result.h"
16 #include "chrome/renderer/spellchecker/hunspell_engine.h"
17 #include "chrome/renderer/spellchecker/spellcheck.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
21 #include "ui/base/l10n/l10n_util.h"
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());
60 base::PlatformFile file
= base::CreatePlatformFile(
61 chrome::spellcheck_common::GetVersionedFileName(language
,
63 base::PLATFORM_FILE_OPEN
| base::PLATFORM_FILE_READ
, NULL
, NULL
);
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_
->spellcheck_
.platform_spelling_engine_
.reset(
70 spell_check_
->Init(file
, std::set
<std::string
>(), language
);
73 void EnableAutoCorrect(bool enable_autocorrect
) {
74 spell_check_
->OnEnableAutoSpellCorrect(enable_autocorrect
);
77 virtual ~SpellCheckTest() {
80 SpellCheck
* spell_check() { return spell_check_
.get(); }
82 bool CheckSpelling(const std::string
& word
, int tag
) {
83 return spell_check_
->spellcheck_
.platform_spelling_engine_
->CheckSpelling(
84 ASCIIToUTF16(word
), tag
);
87 #if !defined(OS_MACOSX)
89 void TestSpellCheckParagraph(
90 const string16
& input
,
91 const std::vector
<SpellCheckResult
>& expected
) {
92 WebKit::WebVector
<WebKit::WebTextCheckingResult
> results
;
93 spell_check()->SpellCheckParagraph(input
,
96 EXPECT_EQ(results
.size(), expected
.size());
97 size_t size
= std::min(results
.size(), expected
.size());
98 for (size_t j
= 0; j
< size
; ++j
) {
99 EXPECT_EQ(results
[j
].type
, WebKit::WebTextCheckingTypeSpelling
);
100 EXPECT_EQ(results
[j
].location
, expected
[j
].location
);
101 EXPECT_EQ(results
[j
].length
, expected
[j
].length
);
107 scoped_ptr
<SpellCheck
> spell_check_
;
108 base::MessageLoop loop
;
111 // A fake completion object for verification.
112 class MockTextCheckingCompletion
: public WebKit::WebTextCheckingCompletion
{
114 MockTextCheckingCompletion()
115 : completion_count_(0) {
118 virtual void didFinishCheckingText(
119 const WebKit::WebVector
<WebKit::WebTextCheckingResult
>& results
)
122 last_results_
= results
;
125 virtual void didCancelCheckingText() OVERRIDE
{
129 size_t completion_count_
;
130 WebKit::WebVector
<WebKit::WebTextCheckingResult
> last_results_
;
133 // Operates unit tests for the webkit_glue::SpellCheckWord() function
134 // with the US English dictionary.
135 // The unit tests in this function consist of:
136 // * Tests for the function with empty strings;
137 // * Tests for the function with a valid English word;
138 // * Tests for the function with a valid non-English word;
139 // * Tests for the function with a valid English word with a preceding
141 // * Tests for the function with a valid English word with a preceding
143 // * Tests for the function with a valid English word with a following
145 // * Tests for the function with a valid English word with a following
147 // * Tests for the function with two valid English words concatenated
148 // with space characters or non-English words;
149 // * Tests for the function with an invalid English word;
150 // * Tests for the function with an invalid English word with a preceding
152 // * Tests for the function with an invalid English word with a preceding
154 // * Tests for the function with an invalid English word with a following
156 // * Tests for the function with an invalid English word with a following
157 // non-English word, and;
158 // * Tests for the function with two invalid English words concatenated
159 // with space characters or non-English words.
160 // A test with a "[ROBUSTNESS]" mark shows it is a robustness test and it uses
161 // grammatically incorrect string.
162 // TODO(groby): Please feel free to add more tests.
163 TEST_F(SpellCheckTest
, SpellCheckStrings_EN_US
) {
164 static const struct {
165 // A string to be tested.
166 const wchar_t* input
;
167 // An expected result for this test case.
168 // * true: the input string does not have any invalid words.
169 // * false: the input string has one or more invalid words.
170 bool expected_result
;
171 // The position and the length of the first invalid word.
172 int misspelling_start
;
173 int misspelling_length
;
181 // A valid English word "hello".
183 // A valid Chinese word (meaning "hello") consisting of two CJKV
185 {L
"\x4F60\x597D", true},
186 // A valid Korean word (meaning "hello") consisting of five hangul
188 {L
"\xC548\xB155\xD558\xC138\xC694", true},
189 // A valid Japanese word (meaning "hello") consisting of five Hiragana
191 {L
"\x3053\x3093\x306B\x3061\x306F", true},
192 // A valid Hindi word (meaning ?) consisting of six Devanagari letters
193 // (This word is copied from "http://b/issue?id=857583".)
194 {L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
195 // A valid English word "affix" using a Latin ligature 'ffi'
197 // A valid English word "hello" (fullwidth version)
198 {L
"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true},
199 // Two valid Greek words (meaning "hello") consisting of seven Greek
201 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
202 // A valid Russian word (meaning "hello") consisting of twelve Cyrillic
204 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
205 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
206 // A valid English contraction
208 // A valid English word enclosed with underscores.
211 // A valid English word with a preceding whitespace
212 {L
" " L
"hello", true},
213 // A valid English word with a preceding no-break space
214 {L
"\xA0" L
"hello", true},
215 // A valid English word with a preceding ideographic space
216 {L
"\x3000" L
"hello", true},
217 // A valid English word with a preceding Chinese word
218 {L
"\x4F60\x597D" L
"hello", true},
219 // [ROBUSTNESS] A valid English word with a preceding Korean word
220 {L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
221 // A valid English word with a preceding Japanese word
222 {L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
223 // [ROBUSTNESS] A valid English word with a preceding Hindi word
224 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello", true},
225 // [ROBUSTNESS] A valid English word with two preceding Greek words
226 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
228 // [ROBUSTNESS] A valid English word with a preceding Russian word
229 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
230 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
232 // A valid English word with a following whitespace
233 {L
"hello" L
" ", true},
234 // A valid English word with a following no-break space
235 {L
"hello" L
"\xA0", true},
236 // A valid English word with a following ideographic space
237 {L
"hello" L
"\x3000", true},
238 // A valid English word with a following Chinese word
239 {L
"hello" L
"\x4F60\x597D", true},
240 // [ROBUSTNESS] A valid English word with a following Korean word
241 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694", true},
242 // A valid English word with a following Japanese word
243 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F", true},
244 // [ROBUSTNESS] A valid English word with a following Hindi word
245 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928", true},
246 // [ROBUSTNESS] A valid English word with two following Greek words
248 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", true},
249 // [ROBUSTNESS] A valid English word with a following Russian word
250 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
251 L
"\x0442\x0432\x0443\x0439\x0442\x0435", true},
253 // Two valid English words concatenated with a whitespace
254 {L
"hello" L
" " L
"hello", true},
255 // Two valid English words concatenated with a no-break space
256 {L
"hello" L
"\xA0" L
"hello", true},
257 // Two valid English words concatenated with an ideographic space
258 {L
"hello" L
"\x3000" L
"hello", true},
259 // Two valid English words concatenated with a Chinese word
260 {L
"hello" L
"\x4F60\x597D" L
"hello", true},
261 // [ROBUSTNESS] Two valid English words concatenated with a Korean word
262 {L
"hello" L
"\xC548\xB155\xD558\xC138\xC694" L
"hello", true},
263 // Two valid English words concatenated with a Japanese word
264 {L
"hello" L
"\x3053\x3093\x306B\x3061\x306F" L
"hello", true},
265 // [ROBUSTNESS] Two valid English words concatenated with a Hindi word
266 {L
"hello" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"hello" , true},
267 // [ROBUSTNESS] Two valid English words concatenated with two Greek words
268 {L
"hello" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
270 // [ROBUSTNESS] Two valid English words concatenated with a Russian word
271 {L
"hello" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
272 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"hello", true},
273 // [ROBUSTNESS] Two valid English words concatenated with a contraction
275 {L
"hello:hello", true},
277 // An invalid English word
278 {L
"ifmmp", false, 0, 5},
279 // An invalid English word "bffly" containing a Latin ligature 'ffl'
280 {L
"b\xFB04y", false, 0, 3},
281 // An invalid English word "ifmmp" (fullwidth version)
282 {L
"\xFF29\xFF46\xFF4D\xFF4D\xFF50", false, 0, 5},
283 // An invalid English contraction
284 {L
"jtm'u", false, 0, 5},
285 // An invalid English word enclosed with underscores.
286 {L
"_ifmmp_", false, 1, 5},
288 // An invalid English word with a preceding whitespace
289 {L
" " L
"ifmmp", false, 1, 5},
290 // An invalid English word with a preceding no-break space
291 {L
"\xA0" L
"ifmmp", false, 1, 5},
292 // An invalid English word with a preceding ideographic space
293 {L
"\x3000" L
"ifmmp", false, 1, 5},
294 // An invalid English word with a preceding Chinese word
295 {L
"\x4F60\x597D" L
"ifmmp", false, 2, 5},
296 // [ROBUSTNESS] An invalid English word with a preceding Korean word
297 {L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 5, 5},
298 // An invalid English word with a preceding Japanese word
299 {L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 5, 5},
300 // [ROBUSTNESS] An invalid English word with a preceding Hindi word
301 {L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp", false, 6, 5},
302 // [ROBUSTNESS] An invalid English word with two preceding Greek words
303 {L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
304 L
"ifmmp", false, 8, 5},
305 // [ROBUSTNESS] An invalid English word with a preceding Russian word
306 {L
"\x0437\x0434\x0440\x0430\x0432\x0441"
307 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 12, 5},
309 // An invalid English word with a following whitespace
310 {L
"ifmmp" L
" ", false, 0, 5},
311 // An invalid English word with a following no-break space
312 {L
"ifmmp" L
"\xA0", false, 0, 5},
313 // An invalid English word with a following ideographic space
314 {L
"ifmmp" L
"\x3000", false, 0, 5},
315 // An invalid English word with a following Chinese word
316 {L
"ifmmp" L
"\x4F60\x597D", false, 0, 5},
317 // [ROBUSTNESS] An invalid English word with a following Korean word
318 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694", false, 0, 5},
319 // An invalid English word with a following Japanese word
320 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F", false, 0, 5},
321 // [ROBUSTNESS] An invalid English word with a following Hindi word
322 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928", false, 0, 5},
323 // [ROBUSTNESS] An invalid English word with two following Greek words
325 L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5", false, 0, 5},
326 // [ROBUSTNESS] An invalid English word with a following Russian word
327 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
328 L
"\x0442\x0432\x0443\x0439\x0442\x0435", false, 0, 5},
330 // Two invalid English words concatenated with a whitespace
331 {L
"ifmmp" L
" " L
"ifmmp", false, 0, 5},
332 // Two invalid English words concatenated with a no-break space
333 {L
"ifmmp" L
"\xA0" L
"ifmmp", false, 0, 5},
334 // Two invalid English words concatenated with an ideographic space
335 {L
"ifmmp" L
"\x3000" L
"ifmmp", false, 0, 5},
336 // Two invalid English words concatenated with a Chinese word
337 {L
"ifmmp" L
"\x4F60\x597D" L
"ifmmp", false, 0, 5},
338 // [ROBUSTNESS] Two invalid English words concatenated with a Korean word
339 {L
"ifmmp" L
"\xC548\xB155\xD558\xC138\xC694" L
"ifmmp", false, 0, 5},
340 // Two invalid English words concatenated with a Japanese word
341 {L
"ifmmp" L
"\x3053\x3093\x306B\x3061\x306F" L
"ifmmp", false, 0, 5},
342 // [ROBUSTNESS] Two invalid English words concatenated with a Hindi word
343 {L
"ifmmp" L
"\x0930\x093E\x091C\x0927\x093E\x0928" L
"ifmmp" , false, 0, 5},
344 // [ROBUSTNESS] Two invalid English words concatenated with two Greek words
345 {L
"ifmmp" L
"\x03B3\x03B5\x03B9\x03AC" L
" " L
"\x03C3\x03BF\x03C5"
346 L
"ifmmp", false, 0, 5},
347 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word
348 {L
"ifmmp" L
"\x0437\x0434\x0440\x0430\x0432\x0441"
349 L
"\x0442\x0432\x0443\x0439\x0442\x0435" L
"ifmmp", false, 0, 5},
350 // [ROBUSTNESS] Two invalid English words concatenated with a contraction
352 {L
"ifmmp:ifmmp", false, 0, 11},
354 // [REGRESSION] Issue 13432: "Any word of 13 or 14 characters is not
355 // spellcheck" <http://crbug.com/13432>.
356 {L
"qwertyuiopasd", false, 0, 13},
357 {L
"qwertyuiopasdf", false, 0, 14},
359 // [REGRESSION] Issue 128896: "en_US hunspell dictionary includes
360 // acknowledgement but not acknowledgements" <http://crbug.com/128896>
361 {L
"acknowledgement", true},
362 {L
"acknowledgements", true},
364 // Issue 123290: "Spellchecker should treat numbers as word characters"
380 {L
"100,000,000", true},
381 {L
"3.141592653", true},
385 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
386 size_t input_length
= 0;
387 if (kTestCases
[i
].input
!= NULL
) {
388 input_length
= wcslen(kTestCases
[i
].input
);
390 int misspelling_start
;
391 int misspelling_length
;
392 bool result
= spell_check()->SpellCheckWord(
393 WideToUTF16(kTestCases
[i
].input
).c_str(),
394 static_cast<int>(input_length
),
397 &misspelling_length
, NULL
);
399 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
400 EXPECT_EQ(kTestCases
[i
].misspelling_start
, misspelling_start
);
401 EXPECT_EQ(kTestCases
[i
].misspelling_length
, misspelling_length
);
405 TEST_F(SpellCheckTest
, SpellCheckSuggestions_EN_US
) {
406 static const struct {
407 // A string to be tested.
408 const wchar_t* input
;
409 // An expected result for this test case.
410 // * true: the input string does not have any invalid words.
411 // * false: the input string has one or more invalid words.
412 bool expected_result
;
413 // The position and the length of the first invalid word.
414 int misspelling_start
;
415 int misspelling_length
;
417 // A suggested word that should occur.
418 const wchar_t* suggested_word
;
420 {L
"ello", false, 0, 0, L
"hello"},
421 {L
"ello", false, 0, 0, L
"cello"},
422 {L
"wate", false, 0, 0, L
"water"},
423 {L
"wate", false, 0, 0, L
"waste"},
424 {L
"wate", false, 0, 0, L
"sate"},
425 {L
"wate", false, 0, 0, L
"ate"},
426 {L
"jum", false, 0, 0, L
"jump"},
427 {L
"jum", false, 0, 0, L
"hum"},
428 {L
"jum", false, 0, 0, L
"sum"},
429 {L
"jum", false, 0, 0, L
"um"},
430 // A regression test for Issue 36523.
431 {L
"privliged", false, 0, 0, L
"privileged"},
432 // TODO (Sidchat): add many more examples.
435 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
436 std::vector
<string16
> suggestions
;
437 size_t input_length
= 0;
438 if (kTestCases
[i
].input
!= NULL
) {
439 input_length
= wcslen(kTestCases
[i
].input
);
441 int misspelling_start
;
442 int misspelling_length
;
443 bool result
= spell_check()->SpellCheckWord(
444 WideToUTF16(kTestCases
[i
].input
).c_str(),
445 static_cast<int>(input_length
),
451 // Check for spelling.
452 EXPECT_EQ(kTestCases
[i
].expected_result
, result
);
454 // Check if the suggested words occur.
455 bool suggested_word_is_present
= false;
456 for (int j
= 0; j
< static_cast<int>(suggestions
.size()); j
++) {
457 if (suggestions
.at(j
).compare(WideToUTF16(kTestCases
[i
].suggested_word
))
459 suggested_word_is_present
= true;
464 EXPECT_TRUE(suggested_word_is_present
);
468 // This test verifies our spellchecker can split a text into words and check
469 // the spelling of each word in the text.
470 #if defined(THREAD_SANITIZER)
471 // SpellCheckTest.SpellCheckText fails under ThreadSanitizer v2.
472 // See http://crbug.com/217909.
473 #define MAYBE_SpellCheckText DISABLED_SpellCheckText
475 #define MAYBE_SpellCheckText SpellCheckText
476 #endif // THREAD_SANITIZER
477 TEST_F(SpellCheckTest
, MAYBE_SpellCheckText
) {
478 static const struct {
479 const char* language
;
480 const wchar_t* input
;
485 L
"Google se missie is om die w\x00EAreld se inligting te organiseer en "
486 L
"dit bruikbaar en toeganklik te maak."
490 L
"La missi\x00F3 de Google \x00E9s organitzar la informaci\x00F3 "
491 L
"del m\x00F3n i fer que sigui \x00FAtil i accessible universalment."
495 L
"Posl\x00E1n\x00EDm spole\x010Dnosti Google je "
496 L
"uspo\x0159\x00E1\x0064\x0061t informace z cel\x00E9ho sv\x011Bta "
497 L
"tak, aby byly v\x0161\x0065obecn\x011B p\x0159\x00EDstupn\x00E9 "
498 L
"a u\x017Eite\x010Dn\x00E9."
503 L
"mission er at organisere verdens information og g\x00F8re den "
504 L
"almindeligt tilg\x00E6ngelig og nyttig."
508 L
"Das Ziel von Google besteht darin, die auf der Welt vorhandenen "
509 L
"Informationen zu organisieren und allgemein zug\x00E4nglich und "
510 L
"nutzbar zu machen."
514 L
"\x0391\x03C0\x03BF\x03C3\x03C4\x03BF\x03BB\x03AE "
515 L
"\x03C4\x03B7\x03C2 Google \x03B5\x03AF\x03BD\x03B1\x03B9 "
516 L
"\x03BD\x03B1 \x03BF\x03C1\x03B3\x03B1\x03BD\x03CE\x03BD\x03B5\x03B9 "
517 L
"\x03C4\x03B9\x03C2 "
518 L
"\x03C0\x03BB\x03B7\x03C1\x03BF\x03C6\x03BF\x03C1\x03AF\x03B5\x03C2 "
519 L
"\x03C4\x03BF\x03C5 \x03BA\x03CC\x03C3\x03BC\x03BF\x03C5 "
520 L
"\x03BA\x03B1\x03B9 \x03BD\x03B1 \x03C4\x03B9\x03C2 "
521 L
"\x03BA\x03B1\x03B8\x03B9\x03C3\x03C4\x03AC "
522 L
"\x03C0\x03C1\x03BF\x03C3\x03B2\x03AC\x03C3\x03B9\x03BC\x03B5\x03C2 "
523 L
"\x03BA\x03B1\x03B9 \x03C7\x03C1\x03AE\x03C3\x03B9\x03BC\x03B5\x03C2."
525 // English (Australia)
527 L
"Google's mission is to organise the world's information and make it "
528 L
"universally accessible and useful."
532 L
"Google's mission is to organize the world's information and make it "
533 L
"universally accessible and useful."
535 // English (United Kingdom)
537 L
"Google's mission is to organise the world's information and make it "
538 L
"universally accessible and useful."
540 // English (United States)
542 L
"Google's mission is to organize the world's information and make it "
543 L
"universally accessible and useful."
547 L
"\x041c\x0438\x0441\x0438\x044f\x0442\x0430 "
548 L
"\x043d\x0430 Google \x0435 \x0434\x0430 \x043e"
549 L
"\x0440\x0433\x0430\x043d\x0438\x0437\x0438\x0440"
550 L
"\x0430 \x0441\x0432\x0435\x0442\x043e\x0432"
551 L
"\x043d\x0430\x0442\x0430 \x0438\x043d\x0444"
552 L
"\x043e\x0440\x043c\x0430\x0446\x0438\x044f "
553 L
"\x0438 \x0434\x0430 \x044f \x043d"
554 L
"\x0430\x043f\x0440\x0430\x0432\x0438 \x0443"
555 L
"\x043d\x0438\x0432\x0435\x0440\x0441\x0430\x043b"
556 L
"\x043d\x043e \x0434\x043e\x0441\x0442\x044a"
557 L
"\x043f\x043d\x0430 \x0438 \x043f\x043e"
558 L
"\x043b\x0435\x0437\x043d\x0430."
562 L
"La misi\x00F3n de "
563 // L"Google" - to be added.
564 L
" es organizar la informaci\x00F3n mundial "
565 L
"para que resulte universalmente accesible y \x00FAtil."
569 // L"Google'ile " - to be added.
570 L
"\x00FClesanne on korraldada maailma teavet ja teeb selle "
571 L
"k\x00F5igile k\x00E4ttesaadavaks ja kasulikuks.",
575 L
"Google er at samskipa alla vitan \x00ED heiminum og gera hana alment "
576 L
"atkomiliga og n\x00FDtiliga."
580 L
"Google a pour mission d'organiser les informations \x00E0 "
581 L
"l'\x00E9\x0063helle mondiale dans le but de les rendre accessibles "
582 L
"et utiles \x00E0 tous."
586 L
"\x05D4\x05DE\x05E9\x05D9\x05DE\x05D4 \x05E9\x05DC Google "
587 L
"\x05D4\x05D9\x05D0 \x05DC\x05D0\x05E8\x05D2\x05DF "
588 L
"\x05D0\x05EA \x05D4\x05DE\x05D9\x05D3\x05E2 "
589 L
"\x05D4\x05E2\x05D5\x05DC\x05DE\x05D9 "
590 L
"\x05D5\x05DC\x05D4\x05E4\x05D5\x05DA \x05D0\x05D5\x05EA\x05D5 "
591 L
"\x05DC\x05D6\x05DE\x05D9\x05DF "
592 L
"\x05D5\x05E9\x05D9\x05DE\x05D5\x05E9\x05D9 \x05D1\x05DB\x05DC "
593 L
"\x05D4\x05E2\x05D5\x05DC\x05DD. "
594 // Two words with ASCII double/single quoation marks.
595 L
"\x05DE\x05E0\x05DB\x0022\x05DC \x05E6\x0027\x05D9\x05E4\x05E1"
599 L
"Google \x0915\x093E \x092E\x093F\x0936\x0928 "
600 L
"\x0926\x0941\x0928\x093F\x092F\x093E \x0915\x0940 "
601 L
"\x091C\x093E\x0928\x0915\x093E\x0930\x0940 \x0915\x094B "
602 L
"\x0935\x094D\x092F\x0935\x0938\x094D\x0925\x093F\x0924 "
603 L
"\x0915\x0930\x0928\x093E \x0914\x0930 \x0909\x0938\x0947 "
604 L
"\x0938\x093E\x0930\x094D\x0935\x092D\x094C\x092E\x093F\x0915 "
605 L
"\x0930\x0942\x092A \x0938\x0947 \x092A\x0939\x0941\x0901\x091A "
606 L
"\x092E\x0947\x0902 \x0914\x0930 \x0909\x092A\x092F\x094B\x0917\x0940 "
607 L
"\x092C\x0928\x093E\x0928\x093E \x0939\x0948."
611 L
"A Google azt a k\x00FCldet\x00E9st v\x00E1llalta mag\x00E1ra, "
612 L
"hogy a vil\x00E1gon fellelhet\x0151 inform\x00E1\x0063i\x00F3kat "
613 L
"rendszerezze \x00E9s \x00E1ltal\x00E1nosan el\x00E9rhet\x0151v\x00E9, "
614 L
"illetve haszn\x00E1lhat\x00F3v\x00E1 tegye."
618 // L"Googleova " - to be added.
619 L
"je misija organizirati svjetske informacije i u\x010Diniti ih "
620 // L"univerzalno " - to be added.
621 L
"pristupa\x010Dnima i korisnima."
625 L
"Misi Google adalah untuk mengelola informasi dunia dan membuatnya "
626 L
"dapat diakses dan bermanfaat secara universal."
630 L
"La missione di Google \x00E8 organizzare le informazioni a livello "
631 L
"mondiale e renderle universalmente accessibili e fruibili."
635 L
"\x201EGoogle\x201C tikslas \x2013 rinkti ir sisteminti pasaulio "
636 L
"informacij\x0105 bei padaryti j\x0105 prieinam\x0105 ir "
637 L
"nauding\x0105 visiems."
641 L
"Google uzdevums ir k\x0101rtot pasaules inform\x0101"
642 L
"ciju un padar\x012Bt to univers\x0101li pieejamu un noder\x012Bgu."
646 // L"Googles " - to be added.
647 L
"m\x00E5l er \x00E5 organisere informasjonen i verden og "
648 L
"gj\x00F8re den tilgjengelig og nyttig for alle."
652 L
"Het doel van Google is om alle informatie wereldwijd toegankelijk "
653 L
"en bruikbaar te maken."
657 L
"Misj\x0105 Google jest uporz\x0105" L
"dkowanie \x015Bwiatowych "
658 L
"zasob\x00F3w informacji, aby sta\x0142y si\x0119 one powszechnie "
659 L
"dost\x0119pne i u\x017Cyteczne."
661 // Portuguese (Brazil)
664 #if !defined(OS_MACOSX)
667 L
"\x00E9 organizar as informa\x00E7\x00F5"
668 L
"es do mundo todo e "
669 #if !defined(OS_MACOSX)
672 L
"acess\x00EDveis e \x00FAteis em car\x00E1ter universal."
674 // Portuguese (Portugal)
677 #if !defined(OS_MACOSX)
680 L
"tem por miss\x00E3o organizar a informa\x00E7\x00E3o do "
682 #if !defined(OS_MACOSX)
685 L
"universalmente acess\x00EDvel e \x00FAtil"
689 L
"Misiunea Google este de a organiza informa\x021B3iile lumii \x0219i de "
690 L
"a le face accesibile \x0219i utile la nivel universal."
694 L
"\x041C\x0438\x0441\x0441\x0438\x044F Google "
695 L
"\x0441\x043E\x0441\x0442\x043E\x0438\x0442 \x0432 "
696 L
"\x043E\x0440\x0433\x0430\x043D\x0438\x0437\x0430\x0446\x0438\x0438 "
697 L
"\x043C\x0438\x0440\x043E\x0432\x043E\x0439 "
698 L
"\x0438\x043D\x0444\x043E\x0440\x043C\x0430\x0446\x0438\x0438, "
699 L
"\x043E\x0431\x0435\x0441\x043F\x0435\x0447\x0435\x043D\x0438\x0438 "
701 L
"\x0434\x043E\x0441\x0442\x0443\x043F\x043D\x043E\x0441\x0442\x0438 "
702 L
"\x0438 \x043F\x043E\x043B\x044C\x0437\x044B \x0434\x043B\x044F "
703 L
"\x0432\x0441\x0435\x0445."
704 // A Russian word including U+0451. (Bug 15558 <http://crbug.com/15558>)
705 L
"\u0451\u043B\u043A\u0430"
707 // Serbo-Croatian (Serbian Latin)
709 L
"Google-ova misija je da organizuje sve informacije na svetu i "
710 L
"u\x010dini ih univerzal-no dostupnim i korisnim."
714 L
"\x0047\x006f\x006f\x0067\x006c\x0065\x002d\x043e\x0432\x0430 "
715 L
"\x043c\x0438\x0441\x0438\x0458\x0430 \x0458\x0435 \x0434\x0430 "
716 L
"\x043e\x0440\x0433\x0430\x043d\x0438\x0437\x0443\x0458\x0435 "
717 L
"\x0441\x0432\x0435 "
718 L
"\x0438\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0438\x0458\x0435 "
719 L
"\x043d\x0430 \x0441\x0432\x0435\x0442\x0443 \x0438 "
720 L
"\x0443\x0447\x0438\x043d\x0438 \x0438\x0445 "
721 L
"\x0443\x043d\x0438\x0432\x0435\x0440\x0437\x0430\x043b\x043d\x043e "
722 L
"\x0434\x043e\x0441\x0442\x0443\x043f\x043d\x0438\x043c \x0438 "
723 L
"\x043a\x043e\x0440\x0438\x0441\x043d\x0438\x043c."
727 L
"Spolo\x010Dnos\x0165 Google si dala za \x00FAlohu usporiada\x0165 "
728 L
"inform\x00E1\x0063ie "
729 L
"z cel\x00E9ho sveta a zabezpe\x010Di\x0165, "
730 L
"aby boli v\x0161eobecne dostupn\x00E9 a u\x017Eito\x010Dn\x00E9."
734 // L"Googlovo " - to be added.
735 L
"poslanstvo je organizirati svetovne informacije in "
736 L
"omogo\x010Diti njihovo dostopnost in s tem uporabnost za vse."
740 L
"Googles m\x00E5ls\x00E4ttning \x00E4r att ordna v\x00E4rldens "
741 L
"samlade information och g\x00F6ra den tillg\x00E4nglig f\x00F6r alla."
745 // L"Google\x2019\x0131n " - to be added.
746 L
"misyonu, d\x00FCnyadaki t\x00FCm bilgileri "
747 L
"organize etmek ve evrensel olarak eri\x015Filebilir ve "
748 L
"kullan\x0131\x015Fl\x0131 k\x0131lmakt\x0131r."
752 L
"\x041c\x0456\x0441\x0456\x044f "
753 L
"\x043a\x043e\x043c\x043f\x0430\x043d\x0456\x0457 Google "
754 L
"\x043f\x043e\x043b\x044f\x0433\x0430\x0454 \x0432 "
755 L
"\x0442\x043e\x043c\x0443, \x0449\x043e\x0431 "
756 L
"\x0443\x043f\x043e\x0440\x044f\x0434\x043a\x0443\x0432\x0430\x0442"
757 L
"\x0438 \x0456\x043d\x0444\x043e\x0440\x043c\x0430\x0446\x0456\x044e "
758 L
"\x0437 \x0443\x0441\x044c\x043e\x0433\x043e "
759 L
"\x0441\x0432\x0456\x0442\x0443 \x0442\x0430 "
760 L
"\x0437\x0440\x043e\x0431\x0438\x0442\x0438 \x0457\x0457 "
761 L
"\x0443\x043d\x0456\x0432\x0435\x0440\x0441\x0430\x043b\x044c\x043d"
762 L
"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e "
763 L
"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e."
767 L
"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 "
768 L
"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 "
769 L
"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 "
770 L
"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 "
771 L
"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n."
775 L
"Google\xC758 \xBAA9\xD45C\xB294 \xC804\xC138\xACC4\xC758 "
776 L
"\xC815\xBCF4\xB97C \xCCB4\xACC4\xD654\xD558\xC5EC \xBAA8\xB450\xAC00 "
777 L
"\xD3B8\xB9AC\xD558\xAC8C \xC774\xC6A9\xD560 \xC218 "
778 L
"\xC788\xB3C4\xB85D \xD558\xB294 \xAC83\xC785\xB2C8\xB2E4."
782 L
"Misioni i Google \x00EBsht\x00EB q\x00EB t\x00EB organizoj\x00EB "
783 L
"informacionin e bot\x00EBs dhe t\x00EB b\x00EBjn\x00EB at\x00EB "
784 L
"universalisht t\x00EB arritshme dhe t\x00EB dobishme."
788 L
"Google \x0B87\x0BA9\x0BCD "
789 L
"\x0BA8\x0BC7\x0BBE\x0B95\x0BCD\x0B95\x0BAE\x0BCD "
790 L
"\x0B89\x0BB2\x0B95\x0BBF\x0BA9\x0BCD \x0BA4\x0B95\x0BB5\x0BB2\x0BCD "
791 L
"\x0B8F\x0BB1\x0BCD\x0BAA\x0BBE\x0B9F\x0BC1 \x0B87\x0BA4\x0BC1 "
792 L
"\u0B89\u0BB2\u0B95\u0BB3\u0BBE\u0BB5\u0BBF\u0BAF "
793 L
"\x0B85\x0BA3\x0BC1\x0B95\x0B95\x0BCD \x0B95\x0BC2\x0B9F\x0BBF\x0BAF "
794 L
"\x0BAE\x0BB1\x0BCD\x0BB1\x0BC1\x0BAE\x0BCD "
795 L
"\x0BAA\x0BAF\x0BA9\x0BC1\x0BB3\x0BCD\x0BB3 "
796 L
"\x0B9A\x0BC6\x0BAF\x0BCD\x0BAF \x0B89\x0BB3\x0BCD\x0BB3\x0BA4\x0BC1."
800 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
801 ReinitializeSpellCheck(kTestCases
[i
].language
);
802 size_t input_length
= 0;
803 if (kTestCases
[i
].input
!= NULL
)
804 input_length
= wcslen(kTestCases
[i
].input
);
806 int misspelling_start
= 0;
807 int misspelling_length
= 0;
808 bool result
= spell_check()->SpellCheckWord(
809 WideToUTF16(kTestCases
[i
].input
).c_str(),
810 static_cast<int>(input_length
),
813 &misspelling_length
, NULL
);
817 << std::wstring(kTestCases
[i
].input
).substr(
818 misspelling_start
, misspelling_length
)
819 << "\" is misspelled in "
820 << kTestCases
[i
].language
822 EXPECT_EQ(0, misspelling_start
);
823 EXPECT_EQ(0, misspelling_length
);
827 TEST_F(SpellCheckTest
, GetAutoCorrectionWord_EN_US
) {
828 static const struct {
829 // A misspelled word.
832 // An expected result for this test case.
833 // Should be an empty string if there are no suggestions for auto correct.
834 const char* expected_result
;
843 EnableAutoCorrect(true);
845 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
846 string16
misspelled_word(UTF8ToUTF16(kTestCases
[i
].input
));
847 string16
expected_autocorrect_word(
848 UTF8ToUTF16(kTestCases
[i
].expected_result
));
849 string16 autocorrect_word
= spell_check()->GetAutoCorrectionWord(
852 // Check for spelling.
853 EXPECT_EQ(expected_autocorrect_word
, autocorrect_word
);
857 // Verify that our SpellCheck::SpellCheckWord() returns false when it checks
859 TEST_F(SpellCheckTest
, MisspelledWords
) {
860 static const struct {
861 const char* language
;
862 const wchar_t* input
;
865 // A misspelled word for English
869 // A misspelled word for Greek.
871 L
"\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1\x03B1",
873 // A misspelled word for Hebrew
875 L
"\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0\x05D0",
879 L
"\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905\x0905",
881 // A misspelled word for Russian
883 L
"\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430\x0430",
887 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
888 ReinitializeSpellCheck(kTestCases
[i
].language
);
890 string16
word(WideToUTF16(kTestCases
[i
].input
));
891 int word_length
= static_cast<int>(word
.length());
892 int misspelling_start
= 0;
893 int misspelling_length
= 0;
894 bool result
= spell_check()->SpellCheckWord(word
.c_str(),
900 EXPECT_FALSE(result
);
901 EXPECT_EQ(0, misspelling_start
);
902 EXPECT_EQ(word_length
, misspelling_length
);
906 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac,
907 // we skip these SpellCheckParagraph tests on Mac.
908 #if !defined(OS_MACOSX)
910 // Make sure SpellCheckParagraph does not crash if the input is empty.
911 TEST_F(SpellCheckTest
, SpellCheckParagraphEmptyParagraph
) {
912 std::vector
<SpellCheckResult
> expected
;
913 TestSpellCheckParagraph(UTF8ToUTF16(""), expected
);
916 // A simple test case having no misspellings.
917 TEST_F(SpellCheckTest
, SpellCheckParagraphNoMisspellings
) {
918 const string16 text
= UTF8ToUTF16("apple");
919 std::vector
<SpellCheckResult
> expected
;
920 TestSpellCheckParagraph(text
, expected
);
923 // A simple test case having one misspelling.
924 TEST_F(SpellCheckTest
, SpellCheckParagraphSingleMisspellings
) {
925 const string16 text
= UTF8ToUTF16("zz");
926 std::vector
<SpellCheckResult
> expected
;
927 expected
.push_back(SpellCheckResult(
928 SpellCheckResult::SPELLING
, 0, 2));
930 TestSpellCheckParagraph(text
, expected
);
933 // A simple test case having multiple misspellings.
934 TEST_F(SpellCheckTest
, SpellCheckParagraphMultipleMisspellings
) {
935 const string16 text
= UTF8ToUTF16("zz, zz");
936 std::vector
<SpellCheckResult
> expected
;
937 expected
.push_back(SpellCheckResult(
938 SpellCheckResult::SPELLING
, 0, 2));
939 expected
.push_back(SpellCheckResult(
940 SpellCheckResult::SPELLING
, 4, 2));
942 TestSpellCheckParagraph(text
, expected
);
945 // Make sure a relatively long (correct) sentence can be spellchecked.
946 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentence
) {
947 std::vector
<SpellCheckResult
> expected
;
948 // The text is taken from US constitution preamble.
949 const string16 text
= UTF8ToUTF16(
950 "We the people of the United States, in order to form a more perfect "
951 "union, establish justice, insure domestic tranquility, provide for "
952 "the common defense, promote the general welfare, and secure the "
953 "blessings of liberty to ourselves and our posterity, do ordain and "
954 "establish this Constitution for the United States of America.");
956 TestSpellCheckParagraph(text
, expected
);
959 // Make sure all misspellings can be found in a relatively long sentence.
960 TEST_F(SpellCheckTest
, SpellCheckParagraphLongSentenceMultipleMisspellings
) {
961 std::vector
<SpellCheckResult
> expected
;
963 // All 'the' are converted to 'hte' in US consitition preamble.
964 const string16 text
= UTF8ToUTF16(
965 "We hte people of hte United States, in order to form a more perfect "
966 "union, establish justice, insure domestic tranquility, provide for "
967 "hte common defense, promote hte general welfare, and secure hte "
968 "blessings of liberty to ourselves and our posterity, do ordain and "
969 "establish this Constitution for hte United States of America.");
971 expected
.push_back(SpellCheckResult(
972 SpellCheckResult::SPELLING
, 3, 3));
973 expected
.push_back(SpellCheckResult(
974 SpellCheckResult::SPELLING
, 17, 3));
975 expected
.push_back(SpellCheckResult(
976 SpellCheckResult::SPELLING
, 135, 3));
977 expected
.push_back(SpellCheckResult(
978 SpellCheckResult::SPELLING
, 163, 3));
979 expected
.push_back(SpellCheckResult(
980 SpellCheckResult::SPELLING
, 195, 3));
981 expected
.push_back(SpellCheckResult(
982 SpellCheckResult::SPELLING
, 298, 3));
984 TestSpellCheckParagraph(text
, expected
);
987 // We also skip RequestSpellCheck tests on Mac, because a system spellchecker
988 // is used on Mac instead of SpellCheck::RequestTextChecking.
990 // Make sure RequestTextChecking does not crash if input is empty.
991 TEST_F(SpellCheckTest
, RequestSpellCheckWithEmptyString
) {
992 MockTextCheckingCompletion completion
;
994 spell_check()->RequestTextChecking(string16(), &completion
);
996 base::MessageLoop::current()->RunUntilIdle();
998 EXPECT_EQ(completion
.completion_count_
, 1U);
1001 // A simple test case having no misspellings.
1002 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutMisspelling
) {
1003 MockTextCheckingCompletion completion
;
1005 const string16 text
= ASCIIToUTF16("hello");
1006 spell_check()->RequestTextChecking(text
, &completion
);
1008 base::MessageLoop::current()->RunUntilIdle();
1010 EXPECT_EQ(completion
.completion_count_
, 1U);
1013 // A simple test case having one misspelling.
1014 TEST_F(SpellCheckTest
, RequestSpellCheckWithSingleMisspelling
) {
1015 MockTextCheckingCompletion completion
;
1017 const string16 text
= ASCIIToUTF16("apple, zz");
1018 spell_check()->RequestTextChecking(text
, &completion
);
1020 base::MessageLoop::current()->RunUntilIdle();
1022 EXPECT_EQ(completion
.completion_count_
, 1U);
1023 EXPECT_EQ(completion
.last_results_
.size(), 1U);
1024 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1025 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1028 // A simple test case having a few misspellings.
1029 TEST_F(SpellCheckTest
, RequestSpellCheckWithMisspellings
) {
1030 MockTextCheckingCompletion completion
;
1032 const string16 text
= ASCIIToUTF16("apple, zz, orange, zz");
1033 spell_check()->RequestTextChecking(text
, &completion
);
1035 base::MessageLoop::current()->RunUntilIdle();
1037 EXPECT_EQ(completion
.completion_count_
, 1U);
1038 EXPECT_EQ(completion
.last_results_
.size(), 2U);
1039 EXPECT_EQ(completion
.last_results_
[0].location
, 7);
1040 EXPECT_EQ(completion
.last_results_
[0].length
, 2);
1041 EXPECT_EQ(completion
.last_results_
[1].location
, 19);
1042 EXPECT_EQ(completion
.last_results_
[1].length
, 2);
1045 // A test case that multiple requests comes at once. Make sure all
1046 // requests are processed.
1047 TEST_F(SpellCheckTest
, RequestSpellCheckWithMultipleRequests
) {
1048 MockTextCheckingCompletion completion
[3];
1050 const string16 text
[3] = {
1051 ASCIIToUTF16("what, zz"),
1052 ASCIIToUTF16("apple, zz"),
1053 ASCIIToUTF16("orange, zz")
1056 for (int i
= 0; i
< 3; ++i
)
1057 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1059 base::MessageLoop::current()->RunUntilIdle();
1061 for (int i
= 0; i
< 3; ++i
) {
1062 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1063 EXPECT_EQ(completion
[i
].last_results_
.size(), 1U);
1064 EXPECT_EQ(completion
[i
].last_results_
[0].location
, 6 + i
);
1065 EXPECT_EQ(completion
[i
].last_results_
[0].length
, 2);
1069 // A test case that spellchecking is requested before initializing.
1070 // In this case, we postpone to post a request.
1071 TEST_F(SpellCheckTest
, RequestSpellCheckWithoutInitialization
) {
1072 UninitializeSpellCheck();
1074 MockTextCheckingCompletion completion
;
1075 const string16 text
= ASCIIToUTF16("zz");
1077 spell_check()->RequestTextChecking(text
, &completion
);
1079 // The task will not be posted yet.
1080 base::MessageLoop::current()->RunUntilIdle();
1081 EXPECT_EQ(completion
.completion_count_
, 0U);
1084 // Requests several spellchecking before initializing. Except the last one,
1085 // posting requests is cancelled and text is rendered as correct one.
1086 TEST_F(SpellCheckTest
, RequestSpellCheckMultipleTimesWithoutInitialization
) {
1087 UninitializeSpellCheck();
1089 MockTextCheckingCompletion completion
[3];
1090 const string16 text
[3] = {
1091 ASCIIToUTF16("what, zz"),
1092 ASCIIToUTF16("apple, zz"),
1093 ASCIIToUTF16("orange, zz")
1096 // Calls RequestTextchecking a few times.
1097 for (int i
= 0; i
< 3; ++i
)
1098 spell_check()->RequestTextChecking(text
[i
], &completion
[i
]);
1100 // The last task will be posted after initialization, however the other
1101 // requests should be pressed without spellchecking.
1102 base::MessageLoop::current()->RunUntilIdle();
1103 for (int i
= 0; i
< 2; ++i
)
1104 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1105 EXPECT_EQ(completion
[2].completion_count_
, 0U);
1107 // Checks the last request is processed after initialization.
1108 InitializeSpellCheck("en-US");
1110 // Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity.
1111 spell_check()->PostDelayedSpellCheckTask(
1112 spell_check()->pending_request_param_
.release());
1113 base::MessageLoop::current()->RunUntilIdle();
1114 for (int i
= 0; i
< 3; ++i
)
1115 EXPECT_EQ(completion
[i
].completion_count_
, 1U);
1118 TEST_F(SpellCheckTest
, CreateTextCheckingResults
) {
1119 // Verify that the SpellCheck class keeps the spelling marker added to a
1120 // misspelled word "zz".
1122 string16 text
= ASCIIToUTF16("zz");
1123 std::vector
<SpellCheckResult
> spellcheck_results
;
1124 spellcheck_results
.push_back(SpellCheckResult(
1125 SpellCheckResult::SPELLING
, 0, 2, string16()));
1126 WebKit::WebVector
<WebKit::WebTextCheckingResult
> textcheck_results
;
1127 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
,
1131 &textcheck_results
);
1132 EXPECT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1133 EXPECT_EQ(WebKit::WebTextCheckingTypeSpelling
, textcheck_results
[0].type
);
1134 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1135 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1138 // Verify that the SpellCheck class replaces the spelling marker added to a
1139 // contextually-misspelled word "bean" with a grammar marker.
1141 string16 text
= ASCIIToUTF16("I have bean to USA.");
1142 std::vector
<SpellCheckResult
> spellcheck_results
;
1143 spellcheck_results
.push_back(SpellCheckResult(
1144 SpellCheckResult::SPELLING
, 7, 4, string16()));
1145 WebKit::WebVector
<WebKit::WebTextCheckingResult
> textcheck_results
;
1146 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER
,
1150 &textcheck_results
);
1151 EXPECT_EQ(spellcheck_results
.size(), textcheck_results
.size());
1152 EXPECT_EQ(WebKit::WebTextCheckingTypeGrammar
, textcheck_results
[0].type
);
1153 EXPECT_EQ(spellcheck_results
[0].location
, textcheck_results
[0].location
);
1154 EXPECT_EQ(spellcheck_results
[0].length
, textcheck_results
[0].length
);
1160 // Checks some words that should be present in all English dictionaries.
1161 TEST_F(SpellCheckTest
, EnglishWords
) {
1162 static const struct {
1166 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking
1168 {"Chromebook", true},
1169 {"Chromebooks", true},
1170 {"Chromebox", true},
1171 {"Chromeboxes", true},
1172 {"Chromeblade", true},
1173 {"Chromeblades", true},
1174 {"Chromebase", true},
1175 {"Chromebases", true},
1176 // Issue 94708: Spell-checker incorrectly reports whisky as misspelled.
1180 // Issue 98678: "Recency" should be included in client-side dictionary.
1182 {"recencies", false},
1188 static const char* kLocales
[] = { "en-GB", "en-US", "en-CA", "en-AU" };
1190 for (size_t j
= 0; j
< arraysize(kLocales
); ++j
) {
1191 ReinitializeSpellCheck(kLocales
[j
]);
1192 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
1193 size_t input_length
= 0;
1194 if (kTestCases
[i
].input
!= NULL
)
1195 input_length
= strlen(kTestCases
[i
].input
);
1197 int misspelling_start
= 0;
1198 int misspelling_length
= 0;
1199 bool result
= spell_check()->SpellCheckWord(
1200 ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1201 static_cast<int>(input_length
),
1204 &misspelling_length
, NULL
);
1206 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].input
<<
1207 " in " << kLocales
[j
];
1212 // Checks that NOSUGGEST works in English dictionaries.
1213 TEST_F(SpellCheckTest
, NoSuggest
) {
1214 static const struct {
1216 const char* suggestion
;
1220 {"suckerbert", "cocksucker", "en-GB", true},
1221 {"suckerbert", "cocksucker", "en-US", true},
1222 {"suckerbert", "cocksucker", "en-CA", true},
1223 {"suckerbert", "cocksucker", "en-AU", true},
1224 {"suckerbert", "cocksuckers", "en-GB", true},
1225 {"suckerbert", "cocksuckers", "en-US", true},
1226 {"suckerbert", "cocksuckers", "en-CA", true},
1227 {"suckerbert", "cocksuckers", "en-AU", true},
1228 {"Batasunaa", "Batasuna", "ca-ES", true},
1229 {"pornoo", "porno", "it-IT", true},
1230 {"catass", "catas", "lt-LT", true},
1231 {"kuracc", "kurac", "sl-SI", true},
1232 {"pittt", "pitt", "sv-SE", true},
1235 size_t test_cases_size
= ARRAYSIZE_UNSAFE(kTestCases
);
1236 for (size_t i
= 0; i
< test_cases_size
; ++i
) {
1237 ReinitializeSpellCheck(kTestCases
[i
].locale
);
1238 size_t suggestion_length
= 0;
1239 if (kTestCases
[i
].suggestion
!= NULL
)
1240 suggestion_length
= strlen(kTestCases
[i
].suggestion
);
1242 // First check that the NOSUGGEST flag didn't mark this word as not being in
1244 int misspelling_start
= 0;
1245 int misspelling_length
= 0;
1246 bool result
= spell_check()->SpellCheckWord(
1247 ASCIIToUTF16(kTestCases
[i
].suggestion
).c_str(),
1248 static_cast<int>(suggestion_length
),
1251 &misspelling_length
, NULL
);
1253 EXPECT_EQ(kTestCases
[i
].should_pass
, result
) << kTestCases
[i
].suggestion
<<
1254 " in " << kTestCases
[i
].locale
;
1256 // Now verify that this test case does not show up as a suggestion.
1257 std::vector
<string16
> suggestions
;
1258 size_t input_length
= 0;
1259 if (kTestCases
[i
].input
!= NULL
)
1260 input_length
= strlen(kTestCases
[i
].input
);
1261 result
= spell_check()->SpellCheckWord(
1262 ASCIIToUTF16(kTestCases
[i
].input
).c_str(),
1263 static_cast<int>(input_length
),
1266 &misspelling_length
,
1268 // Input word should be a misspelling.
1269 EXPECT_FALSE(result
) << kTestCases
[i
].input
1270 << " is not a misspelling in "
1271 << kTestCases
[i
].locale
;
1272 // Check if the suggested words occur.
1273 for (int j
= 0; j
< static_cast<int>(suggestions
.size()); j
++) {
1274 for (size_t t
= 0; t
< test_cases_size
; t
++) {
1275 int compare_result
=
1276 suggestions
.at(j
).compare(ASCIIToUTF16(kTestCases
[t
].suggestion
));
1277 EXPECT_FALSE(compare_result
== 0) << kTestCases
[t
].suggestion
<<
1278 " in " << kTestCases
[i
].locale
;
1284 // Check that the correct dictionary files are checked in.
1285 TEST_F(SpellCheckTest
, DictionaryFiles
) {
1286 std::vector
<std::string
> spellcheck_languages
;
1287 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages
);
1288 EXPECT_FALSE(spellcheck_languages
.empty());
1290 base::FilePath hunspell
= GetHunspellDirectory();
1291 for (size_t i
= 0; i
< spellcheck_languages
.size(); ++i
) {
1292 base::FilePath dict
= chrome::spellcheck_common::GetVersionedFileName(
1293 spellcheck_languages
[i
], hunspell
);
1294 EXPECT_TRUE(base::PathExists(dict
)) << dict
.value() << " not found";
1298 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded.
1299 TEST_F(SpellCheckTest
, SpellingEngine_CheckSpelling
) {
1300 static const struct {
1302 bool expected_result
;
1305 { "automatic", true },
1307 { "forglobantic", false },
1308 { "xfdssfsdfaasds", false },
1309 { // 64 chars are the longest word to check - this should fail checking.
1310 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl",
1313 { // Any word longer than 64 chars should be exempt from checking.
1314 "reallylongwordthatabsolutelyexceedsthespecifiedcharacterlimitabit",
1319 // Initialization magic - call InitializeIfNeeded twice. The first one simply
1320 // flags internal state that a dictionary was requested. The second one will
1321 // take the passed-in file and initialize hunspell with it. (The file was
1322 // passed to hunspell in the ctor for the test fixture).
1323 // This needs to be done since we need to ensure the SpellingEngine object
1324 // contained in |spellcheck_| from the test fixture does get initialized.
1325 // TODO(groby): Clean up this mess.
1326 InitializeIfNeeded();
1327 ASSERT_FALSE(InitializeIfNeeded());
1329 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
1330 bool result
= CheckSpelling(kTestCases
[i
].word
, 0);
1331 EXPECT_EQ(kTestCases
[i
].expected_result
, result
) <<
1332 "Failed test for " << kTestCases
[i
].word
;
1336 // Chrome should not suggest "Othello" for "hellllo" or "identically" for
1338 TEST_F(SpellCheckTest
, LogicalSuggestions
) {
1339 static const struct {
1340 const char* misspelled
;
1341 const char* suggestion
;
1343 { "hellllo", "hello" },
1344 { "accidently", "accidentally" }
1347 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(kTestCases
); ++i
) {
1348 int misspelling_start
= 0;
1349 int misspelling_length
= 0;
1350 std::vector
<string16
> suggestions
;
1351 EXPECT_FALSE(spell_check()->SpellCheckWord(
1352 ASCIIToUTF16(kTestCases
[i
].misspelled
).c_str(),
1353 strlen(kTestCases
[i
].misspelled
),
1356 &misspelling_length
,
1358 EXPECT_GE(suggestions
.size(), static_cast<size_t>(1));
1359 if (suggestions
.size() > 0)
1360 EXPECT_EQ(suggestions
[0], ASCIIToUTF16(kTestCases
[i
].suggestion
));