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/spellcheck.h" | 14 #include "chrome/renderer/spellchecker/spellcheck.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/spellcheck_common.h" | 16 #include "chrome/common/spellcheck_common.h" |
16 #include "chrome/common/spellcheck_result.h" | 17 #include "chrome/common/spellcheck_result.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 24 matching lines...) Expand all Loading... |
47 spell_check_.reset(new SpellCheck()); | 48 spell_check_.reset(new SpellCheck()); |
48 } | 49 } |
49 | 50 |
50 void InitializeSpellCheck(const std::string& language) { | 51 void InitializeSpellCheck(const std::string& language) { |
51 FilePath hunspell_directory = GetHunspellDirectory(); | 52 FilePath hunspell_directory = GetHunspellDirectory(); |
52 EXPECT_FALSE(hunspell_directory.empty()); | 53 EXPECT_FALSE(hunspell_directory.empty()); |
53 base::PlatformFile file = base::CreatePlatformFile( | 54 base::PlatformFile file = base::CreatePlatformFile( |
54 chrome::spellcheck_common::GetVersionedFileName(language, | 55 chrome::spellcheck_common::GetVersionedFileName(language, |
55 hunspell_directory), | 56 hunspell_directory), |
56 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, NULL, NULL); | 57 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, NULL, NULL); |
| 58 #if defined(OS_MACOSX) |
| 59 // TODO(groby): Forcing spellcheck to use hunspell, even on OSX. |
| 60 // Instead, tests should exercise individual spelling engines. |
| 61 spell_check_->platform_spelling_engine_.reset(new HunspellEngine); |
| 62 #endif |
57 spell_check_->Init( | 63 spell_check_->Init( |
58 file, std::vector<std::string>(), language); | 64 file, std::vector<std::string>(), language); |
59 } | 65 } |
60 | 66 |
61 virtual ~SpellCheckTest() { | 67 virtual ~SpellCheckTest() { |
62 } | 68 } |
63 | 69 |
64 SpellCheck* spell_check() { return spell_check_.get(); } | 70 SpellCheck* spell_check() { return spell_check_.get(); } |
65 | 71 |
66 #if !defined(OS_MACOSX) | 72 #if !defined(OS_MACOSX) |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 | 1063 |
1058 TEST_F(SpellCheckTest, CreateTextCheckingResults) { | 1064 TEST_F(SpellCheckTest, CreateTextCheckingResults) { |
1059 // Verify that the SpellCheck class keeps the spelling marker added to a | 1065 // Verify that the SpellCheck class keeps the spelling marker added to a |
1060 // misspelled word "zz". | 1066 // misspelled word "zz". |
1061 { | 1067 { |
1062 string16 text = ASCIIToUTF16("zz"); | 1068 string16 text = ASCIIToUTF16("zz"); |
1063 std::vector<SpellCheckResult> spellcheck_results; | 1069 std::vector<SpellCheckResult> spellcheck_results; |
1064 spellcheck_results.push_back(SpellCheckResult( | 1070 spellcheck_results.push_back(SpellCheckResult( |
1065 SpellCheckResult::SPELLING, 0, 2, string16())); | 1071 SpellCheckResult::SPELLING, 0, 2, string16())); |
1066 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; | 1072 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; |
1067 spell_check()->CreateTextCheckingResults( | 1073 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1068 0, text, spellcheck_results, &textcheck_results); | 1074 0, |
| 1075 text, |
| 1076 spellcheck_results, |
| 1077 &textcheck_results); |
1069 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1078 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1070 EXPECT_EQ(WebKit::WebTextCheckingTypeSpelling, textcheck_results[0].type); | 1079 EXPECT_EQ(WebKit::WebTextCheckingTypeSpelling, textcheck_results[0].type); |
1071 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1080 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
1072 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1081 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
1073 } | 1082 } |
1074 | 1083 |
1075 // Verify that the SpellCheck class replaces the spelling marker added to a | 1084 // Verify that the SpellCheck class replaces the spelling marker added to a |
1076 // contextually-misspelled word "bean" with a grammar marker. | 1085 // contextually-misspelled word "bean" with a grammar marker. |
1077 { | 1086 { |
1078 string16 text = ASCIIToUTF16("I have bean to USA."); | 1087 string16 text = ASCIIToUTF16("I have bean to USA."); |
1079 std::vector<SpellCheckResult> spellcheck_results; | 1088 std::vector<SpellCheckResult> spellcheck_results; |
1080 spellcheck_results.push_back(SpellCheckResult( | 1089 spellcheck_results.push_back(SpellCheckResult( |
1081 SpellCheckResult::SPELLING, 7, 4, string16())); | 1090 SpellCheckResult::SPELLING, 7, 4, string16())); |
1082 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; | 1091 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; |
1083 spell_check()->CreateTextCheckingResults( | 1092 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1084 0, text, spellcheck_results, &textcheck_results); | 1093 0, |
| 1094 text, |
| 1095 spellcheck_results, |
| 1096 &textcheck_results); |
1085 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1097 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1086 EXPECT_EQ(WebKit::WebTextCheckingTypeGrammar, textcheck_results[0].type); | 1098 EXPECT_EQ(WebKit::WebTextCheckingTypeGrammar, textcheck_results[0].type); |
1087 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1099 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
1088 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1100 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
1089 } | 1101 } |
1090 } | 1102 } |
1091 | 1103 |
1092 // Checks some words that should be present in all English dictionaries. | 1104 // Checks some words that should be present in all English dictionaries. |
1093 TEST_F(SpellCheckTest, EnglishWords) { | 1105 TEST_F(SpellCheckTest, EnglishWords) { |
1094 static const struct { | 1106 static const struct { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 &misspelling_start, | 1147 &misspelling_start, |
1136 &misspelling_length, NULL); | 1148 &misspelling_length, NULL); |
1137 | 1149 |
1138 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << | 1150 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << |
1139 " in " << kLocales[j]; | 1151 " in " << kLocales[j]; |
1140 } | 1152 } |
1141 } | 1153 } |
1142 } | 1154 } |
1143 | 1155 |
1144 #endif | 1156 #endif |
OLD | NEW |