OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/renderer/spellchecker/hunspell_engine.h" | 13 #include "chrome/renderer/spellchecker/hunspell_engine.h" |
14 #include "chrome/renderer/spellchecker/spellcheck.h" | 14 #include "chrome/renderer/spellchecker/spellcheck.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/spellcheck_common.h" | 16 #include "chrome/common/spellcheck_common.h" |
17 #include "chrome/common/spellcheck_result.h" | 17 #include "chrome/common/spellcheck_result.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h" |
21 #include "ui/base/l10n/l10n_util.h" | |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 FilePath GetHunspellDirectory() { | 25 FilePath GetHunspellDirectory() { |
25 FilePath hunspell_directory; | 26 FilePath hunspell_directory; |
26 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) | 27 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) |
27 return FilePath(); | 28 return FilePath(); |
28 | 29 |
29 hunspell_directory = hunspell_directory.AppendASCII("third_party"); | 30 hunspell_directory = hunspell_directory.AppendASCII("third_party"); |
30 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); | 31 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 L"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e " | 741 L"\x043e \x0434\x043e\x0441\x0442\x0443\x043f\x043d\x043e\x044e " |
741 L"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e." | 742 L"\x0442\x0430 \x043a\x043e\x0440\x0438\x0441\x043d\x043e\x044e." |
742 }, { | 743 }, { |
743 // Vietnamese | 744 // Vietnamese |
744 "vi-VN", | 745 "vi-VN", |
745 L"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 " | 746 L"Nhi\x1EC7m v\x1EE5 c\x1EE7\x0061 " |
746 L"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 " | 747 L"Google la \x0111\x1EC3 t\x1ED5 ch\x1EE9\x0063 " |
747 L"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 " | 748 L"c\x00E1\x0063 th\x00F4ng tin c\x1EE7\x0061 " |
748 L"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 " | 749 L"th\x1EBF gi\x1EDBi va l\x00E0m cho n\x00F3 universal c\x00F3 " |
749 L"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n." | 750 L"th\x1EC3 truy c\x1EADp va h\x1EEFu d\x1EE5ng h\x01A1n." |
751 }, { | |
752 // Korean | |
753 "ko", | |
754 L"Google\xC758 \xBAA9\xD45C\xB294 \xC804\xC138\xACC4\xC758 " | |
755 L"\xC815\xBCF4\xB97C \xCCB4\xACC4\xD654\xD558\xC5EC \xBAA8\xB450\xAC00 " | |
756 L"\xD3B8\xB9AC\xD558\xAC8C \xC774\xC6A9\xD560 \xC218 " | |
757 L"\xC788\xB3C4\xB85D \xD558\xB294 \xAC83\xC785\xB2C8\xB2E4." | |
758 }, { | |
759 // Albanian | |
760 "sq", | |
761 L"Misioni i Google \x00EBsht\x00EB q\x00EB t\x00EB organizoj\x00EB " | |
762 L"informacionin e bot\x00EBs dhe t\x00EB b\x00EBjn\x00EB at\x00EB " | |
763 L"universalisht t\x00EB arritshme dhe t\x00EB dobishme." | |
764 }, { | |
765 // Tamil | |
766 "ta", | |
767 L"Google \x0B87\x0BA9\x0BCD " | |
768 L"\x0BA8\x0BC7\x0BBE\x0B95\x0BCD\x0B95\x0BAE\x0BCD " | |
769 L"\x0B89\x0BB2\x0B95\x0BBF\x0BA9\x0BCD \x0BA4\x0B95\x0BB5\x0BB2\x0BCD " | |
770 L"\x0B8F\x0BB1\x0BCD\x0BAA\x0BBE\x0B9F\x0BC1 \x0B87\x0BA4\x0BC1 " | |
771 L"\u0B89\u0BB2\u0B95\u0BB3\u0BBE\u0BB5\u0BBF\u0BAF " | |
772 L"\x0B85\x0BA3\x0BC1\x0B95\x0B95\x0BCD \x0B95\x0BC2\x0B9F\x0BBF\x0BAF " | |
773 L"\x0BAE\x0BB1\x0BCD\x0BB1\x0BC1\x0BAE\x0BCD " | |
774 L"\x0BAA\x0BAF\x0BA9\x0BC1\x0BB3\x0BCD\x0BB3 " | |
775 L"\x0B9A\x0BC6\x0BAF\x0BCD\x0BAF \x0B89\x0BB3\x0BCD\x0BB3\x0BA4\x0BC1." | |
750 }, | 776 }, |
751 }; | 777 }; |
752 | 778 |
753 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { | 779 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
754 ReinitializeSpellCheck(kTestCases[i].language); | 780 ReinitializeSpellCheck(kTestCases[i].language); |
755 size_t input_length = 0; | 781 size_t input_length = 0; |
756 if (kTestCases[i].input != NULL) | 782 if (kTestCases[i].input != NULL) |
757 input_length = wcslen(kTestCases[i].input); | 783 input_length = wcslen(kTestCases[i].input); |
758 | 784 |
759 int misspelling_start = 0; | 785 int misspelling_start = 0; |
760 int misspelling_length = 0; | 786 int misspelling_length = 0; |
761 bool result = spell_check()->SpellCheckWord( | 787 bool result = spell_check()->SpellCheckWord( |
762 WideToUTF16(kTestCases[i].input).c_str(), | 788 WideToUTF16(kTestCases[i].input).c_str(), |
763 static_cast<int>(input_length), | 789 static_cast<int>(input_length), |
764 0, | 790 0, |
765 &misspelling_start, | 791 &misspelling_start, |
766 &misspelling_length, NULL); | 792 &misspelling_length, NULL); |
767 | 793 |
768 EXPECT_TRUE(result) << kTestCases[i].language; | 794 EXPECT_TRUE(result) |
795 << "\"" | |
796 << std::wstring(kTestCases[i].input).substr( | |
797 misspelling_start, misspelling_length) | |
798 << "\" is misspelled in " | |
799 << kTestCases[i].language | |
800 << "."; | |
769 EXPECT_EQ(0, misspelling_start); | 801 EXPECT_EQ(0, misspelling_start); |
770 EXPECT_EQ(0, misspelling_length); | 802 EXPECT_EQ(0, misspelling_length); |
771 } | 803 } |
772 } | 804 } |
773 | 805 |
774 TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) { | 806 TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) { |
775 static const struct { | 807 static const struct { |
776 // A misspelled word. | 808 // A misspelled word. |
777 const char* input; | 809 const char* input; |
778 | 810 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1207 for (size_t t = 0; t < test_cases_size; t++) { | 1239 for (size_t t = 0; t < test_cases_size; t++) { |
1208 int compare_result = | 1240 int compare_result = |
1209 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].input)); | 1241 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].input)); |
1210 EXPECT_FALSE(compare_result == 0) << kTestCases[t].input << | 1242 EXPECT_FALSE(compare_result == 0) << kTestCases[t].input << |
1211 " in " << kLocales[d]; | 1243 " in " << kLocales[d]; |
1212 } | 1244 } |
1213 } | 1245 } |
1214 } | 1246 } |
1215 } | 1247 } |
1216 | 1248 |
1249 // Check that the correct dictionary files are checked in. | |
1250 TEST_F(SpellCheckTest, DictionaryFiles) { | |
1251 std::vector<std::string> locale_codes; | |
1252 l10n_util::GetAcceptLanguagesForLocale("C", &locale_codes); | |
1253 EXPECT_FALSE(locale_codes.empty()); | |
1254 | |
1255 std::vector<std::string> spellcheck_languages; | |
1256 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages); | |
1257 EXPECT_FALSE(spellcheck_languages.empty()); | |
1258 EXPECT_LE(spellcheck_languages.size(), locale_codes.size()); | |
1259 | |
1260 FilePath hunspell = GetHunspellDirectory(); | |
1261 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { | |
1262 FilePath dict = chrome::spellcheck_common::GetVersionedFileName( | |
1263 spellcheck_languages[i], hunspell); | |
1264 EXPECT_TRUE(file_util::PathExists(dict)) << dict.value() << " not found"; | |
1265 ReinitializeSpellCheck(spellcheck_languages[i]); | |
rpetterson
2012/12/15 03:53:47
The only error this function will output (from wha
please use gerrit instead
2012/12/15 04:19:14
Removed.
| |
1266 } | |
1267 } | |
1268 | |
1217 #endif | 1269 #endif |
OLD | NEW |