| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/webkit_glue.h" | 5 #include "webkit/glue/webkit_glue.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/spellchecker.h" | 10 #include "chrome/browser/spellchecker.h" |
| 11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 const FilePath::CharType kTempCustomDictionaryFile[] = | 15 const FilePath::CharType kTempCustomDictionaryFile[] = |
| 16 FILE_PATH_LITERAL("temp_custom_dictionary.txt"); | 16 FILE_PATH_LITERAL("temp_custom_dictionary.txt"); |
| 17 } // namespace | 17 } // namespace |
| 18 | 18 |
| 19 class SpellCheckTest : public testing::Test { | 19 class SpellCheckTest : public testing::Test { |
| 20 private: | 20 private: |
| 21 MessageLoop message_loop_; | 21 MessageLoop message_loop_; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 // Represents a special initialization function used only for the unit tests | 24 // Represents a special initialization function used only for the unit tests |
| 25 // in this file. | 25 // in this file. |
| 26 extern void InitHunspellWithFiles(FILE* file_aff_hunspell, | 26 extern void InitHunspellWithFiles(FILE* file_aff_hunspell, |
| 27 FILE* file_dic_hunspell); | 27 FILE* file_dic_hunspell); |
| 28 | 28 |
| 29 FilePath GetHunspellDirectory() { |
| 30 FilePath hunspell_directory; |
| 31 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) |
| 32 return FilePath(); |
| 33 |
| 34 hunspell_directory = hunspell_directory.AppendASCII("chrome"); |
| 35 hunspell_directory = hunspell_directory.AppendASCII("third_party"); |
| 36 hunspell_directory = hunspell_directory.AppendASCII("hunspell"); |
| 37 hunspell_directory = hunspell_directory.AppendASCII("dictionaries"); |
| 38 return hunspell_directory; |
| 39 } |
| 40 |
| 29 // Operates unit tests for the webkit_glue::SpellCheckWord() function | 41 // Operates unit tests for the webkit_glue::SpellCheckWord() function |
| 30 // with the US English dictionary. | 42 // with the US English dictionary. |
| 31 // The unit tests in this function consist of: | 43 // The unit tests in this function consist of: |
| 32 // * Tests for the function with empty strings; | 44 // * Tests for the function with empty strings; |
| 33 // * Tests for the function with a valid English word; | 45 // * Tests for the function with a valid English word; |
| 34 // * Tests for the function with a valid non-English word; | 46 // * Tests for the function with a valid non-English word; |
| 35 // * Tests for the function with a valid English word with a preceding | 47 // * Tests for the function with a valid English word with a preceding |
| 36 // space character; | 48 // space character; |
| 37 // * Tests for the function with a valid English word with a preceding | 49 // * Tests for the function with a valid English word with a preceding |
| 38 // non-English word; | 50 // non-English word; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 {L"ifmmp" L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" | 254 {L"ifmmp" L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5" |
| 243 L"ifmmp", false, 0, 5}, | 255 L"ifmmp", false, 0, 5}, |
| 244 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word | 256 // [ROBUSTNESS] Two invalid English words concatenated with a Russian word |
| 245 {L"ifmmp" L"\x0437\x0434\x0440\x0430\x0432\x0441" | 257 {L"ifmmp" L"\x0437\x0434\x0440\x0430\x0432\x0441" |
| 246 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"ifmmp", false, 0, 5}, | 258 L"\x0442\x0432\x0443\x0439\x0442\x0435" L"ifmmp", false, 0, 5}, |
| 247 // [ROBUSTNESS] Two invalid English words concatenated with a contraction | 259 // [ROBUSTNESS] Two invalid English words concatenated with a contraction |
| 248 // character. | 260 // character. |
| 249 {L"ifmmp:ifmmp", false, 0, 11}, | 261 {L"ifmmp:ifmmp", false, 0, 11}, |
| 250 }; | 262 }; |
| 251 | 263 |
| 252 FilePath hunspell_directory; | 264 FilePath hunspell_directory = GetHunspellDirectory(); |
| 253 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 265 ASSERT_FALSE(hunspell_directory.empty()); |
| 254 &hunspell_directory)); | |
| 255 | 266 |
| 256 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 267 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 257 hunspell_directory, L"en-US", NULL, FilePath())); | 268 hunspell_directory, L"en-US", NULL, FilePath())); |
| 258 | 269 |
| 259 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 270 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 260 size_t input_length = 0; | 271 size_t input_length = 0; |
| 261 if (kTestCases[i].input != NULL) { | 272 if (kTestCases[i].input != NULL) { |
| 262 input_length = wcslen(kTestCases[i].input); | 273 input_length = wcslen(kTestCases[i].input); |
| 263 } | 274 } |
| 264 int misspelling_start; | 275 int misspelling_start; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 {L"wate", false, 0, 0, L"waste"}, | 307 {L"wate", false, 0, 0, L"waste"}, |
| 297 {L"wate", false, 0, 0, L"sate"}, | 308 {L"wate", false, 0, 0, L"sate"}, |
| 298 {L"wate", false, 0, 0, L"rate"}, | 309 {L"wate", false, 0, 0, L"rate"}, |
| 299 {L"jum", false, 0, 0, L"jump"}, | 310 {L"jum", false, 0, 0, L"jump"}, |
| 300 {L"jum", false, 0, 0, L"rum"}, | 311 {L"jum", false, 0, 0, L"rum"}, |
| 301 {L"jum", false, 0, 0, L"sum"}, | 312 {L"jum", false, 0, 0, L"sum"}, |
| 302 {L"jum", false, 0, 0, L"tum"}, | 313 {L"jum", false, 0, 0, L"tum"}, |
| 303 // TODO (Sidchat): add many more examples. | 314 // TODO (Sidchat): add many more examples. |
| 304 }; | 315 }; |
| 305 | 316 |
| 306 FilePath hunspell_directory; | 317 FilePath hunspell_directory = GetHunspellDirectory(); |
| 307 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 318 ASSERT_FALSE(hunspell_directory.empty()); |
| 308 &hunspell_directory)); | |
| 309 | 319 |
| 310 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 320 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 311 hunspell_directory, L"en-US", NULL, FilePath())); | 321 hunspell_directory, L"en-US", NULL, FilePath())); |
| 312 | 322 |
| 313 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 314 std::vector<std::wstring> suggestions; | 324 std::vector<std::wstring> suggestions; |
| 315 size_t input_length = 0; | 325 size_t input_length = 0; |
| 316 if (kTestCases[i].input != NULL) { | 326 if (kTestCases[i].input != NULL) { |
| 317 input_length = wcslen(kTestCases[i].input); | 327 input_length = wcslen(kTestCases[i].input); |
| 318 } | 328 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 344 TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) { | 354 TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) { |
| 345 static const struct { | 355 static const struct { |
| 346 // A string to be added to SpellChecker. | 356 // A string to be added to SpellChecker. |
| 347 const wchar_t* word_to_add; | 357 const wchar_t* word_to_add; |
| 348 } kTestCases[] = { // word to be added to SpellChecker | 358 } kTestCases[] = { // word to be added to SpellChecker |
| 349 {L"Googley"}, | 359 {L"Googley"}, |
| 350 {L"Googleplex"}, | 360 {L"Googleplex"}, |
| 351 {L"Googler"}, | 361 {L"Googler"}, |
| 352 }; | 362 }; |
| 353 | 363 |
| 354 FilePath hunspell_directory; | |
| 355 FilePath custom_dictionary_file(kTempCustomDictionaryFile); | 364 FilePath custom_dictionary_file(kTempCustomDictionaryFile); |
| 356 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 365 FilePath hunspell_directory = GetHunspellDirectory(); |
| 357 &hunspell_directory)); | 366 ASSERT_FALSE(hunspell_directory.empty()); |
| 358 | 367 |
| 359 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 368 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 360 hunspell_directory, L"en-US", NULL, custom_dictionary_file)); | 369 hunspell_directory, L"en-US", NULL, custom_dictionary_file)); |
| 361 | 370 |
| 362 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 371 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 363 // Add the word to spellchecker. | 372 // Add the word to spellchecker. |
| 364 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); | 373 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); |
| 365 | 374 |
| 366 // Now check whether it is added to Spellchecker. | 375 // Now check whether it is added to Spellchecker. |
| 367 std::vector<std::wstring> suggestions; | 376 std::vector<std::wstring> suggestions; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) { | 422 TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) { |
| 414 static const struct { | 423 static const struct { |
| 415 // A string to be added to SpellChecker. | 424 // A string to be added to SpellChecker. |
| 416 const wchar_t* word_to_add; | 425 const wchar_t* word_to_add; |
| 417 } kTestCases[] = { // word to be added to SpellChecker | 426 } kTestCases[] = { // word to be added to SpellChecker |
| 418 {L"Googley"}, | 427 {L"Googley"}, |
| 419 {L"Googleplex"}, | 428 {L"Googleplex"}, |
| 420 {L"Googler"}, | 429 {L"Googler"}, |
| 421 }; | 430 }; |
| 422 | 431 |
| 423 FilePath hunspell_directory; | |
| 424 FilePath custom_dictionary_file(kTempCustomDictionaryFile); | 432 FilePath custom_dictionary_file(kTempCustomDictionaryFile); |
| 425 ASSERT_TRUE(PathService::Get(chrome::DIR_APP_DICTIONARIES, | 433 FilePath hunspell_directory = GetHunspellDirectory(); |
| 426 &hunspell_directory)); | 434 ASSERT_FALSE(hunspell_directory.empty()); |
| 427 | 435 |
| 428 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( | 436 scoped_refptr<SpellChecker> spell_checker(new SpellChecker( |
| 429 hunspell_directory, L"en-US", NULL, custom_dictionary_file)); | 437 hunspell_directory, L"en-US", NULL, custom_dictionary_file)); |
| 430 | 438 |
| 431 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 439 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 432 // Add the word to spellchecker. | 440 // Add the word to spellchecker. |
| 433 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); | 441 spell_checker->AddWord(std::wstring(kTestCases[i].word_to_add)); |
| 434 } | 442 } |
| 435 | 443 |
| 436 // Now check to see whether the custom words are suggested for | 444 // Now check to see whether the custom words are suggested for |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 break; | 488 break; |
| 481 } | 489 } |
| 482 } | 490 } |
| 483 | 491 |
| 484 EXPECT_TRUE(suggested_word_is_present); | 492 EXPECT_TRUE(suggested_word_is_present); |
| 485 } | 493 } |
| 486 | 494 |
| 487 // Remove the temp custom dictionary file. | 495 // Remove the temp custom dictionary file. |
| 488 file_util::Delete(custom_dictionary_file, false); | 496 file_util::Delete(custom_dictionary_file, false); |
| 489 } | 497 } |
| OLD | NEW |