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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 base::string16 text = base::ASCIIToUTF16("zz"); | 1133 base::string16 text = base::ASCIIToUTF16("zz"); |
1134 std::vector<SpellCheckResult> spellcheck_results; | 1134 std::vector<SpellCheckResult> spellcheck_results; |
1135 spellcheck_results.push_back(SpellCheckResult( | 1135 spellcheck_results.push_back(SpellCheckResult( |
1136 SpellCheckResult::SPELLING, 0, 2, base::string16())); | 1136 SpellCheckResult::SPELLING, 0, 2, base::string16())); |
1137 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1137 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
1138 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1138 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1139 0, | 1139 0, |
1140 text, | 1140 text, |
1141 spellcheck_results, | 1141 spellcheck_results, |
1142 &textcheck_results); | 1142 &textcheck_results); |
1143 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1143 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1144 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, | 1144 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, |
1145 textcheck_results[0].decoration); | 1145 textcheck_results[0].decoration); |
1146 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1146 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
1147 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1147 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
1148 } | 1148 } |
1149 | 1149 |
1150 // Verify that the SpellCheck class replaces the spelling marker added to a | 1150 // Verify that the SpellCheck class replaces the spelling marker added to a |
1151 // contextually-misspelled word "bean" with a grammar marker. | 1151 // contextually-misspelled word "bean" with a grammar marker. |
1152 { | 1152 { |
1153 base::string16 text = base::ASCIIToUTF16("I have bean to USA."); | 1153 base::string16 text = base::ASCIIToUTF16("I have bean to USA."); |
1154 std::vector<SpellCheckResult> spellcheck_results; | 1154 std::vector<SpellCheckResult> spellcheck_results; |
1155 spellcheck_results.push_back(SpellCheckResult( | 1155 spellcheck_results.push_back(SpellCheckResult( |
1156 SpellCheckResult::SPELLING, 7, 4, base::string16())); | 1156 SpellCheckResult::SPELLING, 7, 4, base::string16())); |
1157 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1157 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
1158 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1158 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
1159 0, | 1159 0, |
1160 text, | 1160 text, |
1161 spellcheck_results, | 1161 spellcheck_results, |
1162 &textcheck_results); | 1162 &textcheck_results); |
1163 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1163 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); |
1164 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, | 1164 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, |
1165 textcheck_results[0].decoration); | 1165 textcheck_results[0].decoration); |
1166 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1166 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
1167 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1167 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
1168 } | 1168 } |
| 1169 |
| 1170 // Verify that the SpellCheck class removes the spelling marker caused only by |
| 1171 // a typographical apostrophe. |
| 1172 { |
| 1173 base::string16 text = |
| 1174 base::WideToUTF16(L"I\x2019ve bean here before, hasn\x2019t I?"); |
| 1175 std::vector<SpellCheckResult> spellcheck_results; |
| 1176 |
| 1177 // Typographical apostrophe correction should be ignored. |
| 1178 spellcheck_results.push_back(SpellCheckResult( |
| 1179 SpellCheckResult::SPELLING, 0, 4, base::ASCIIToUTF16("I've"))); |
| 1180 |
| 1181 // Contextual mistake should be marked as grammar mistake. |
| 1182 spellcheck_results.push_back(SpellCheckResult( |
| 1183 SpellCheckResult::SPELLING, 5, 4, base::ASCIIToUTF16("been"))); |
| 1184 |
| 1185 // Contextual mistake in addition to a typographical apostrophe correction |
| 1186 // should be marked as grammar mistake. |
| 1187 spellcheck_results.push_back(SpellCheckResult( |
| 1188 SpellCheckResult::SPELLING, 23, 6, base::ASCIIToUTF16("haven't"))); |
| 1189 |
| 1190 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1191 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
| 1192 0, |
| 1193 text, |
| 1194 spellcheck_results, |
| 1195 &textcheck_results); |
| 1196 ASSERT_EQ(2UL, textcheck_results.size()); |
| 1197 |
| 1198 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, |
| 1199 textcheck_results[0].decoration); |
| 1200 EXPECT_EQ(spellcheck_results[1].location, textcheck_results[0].location); |
| 1201 EXPECT_EQ(spellcheck_results[1].length, textcheck_results[0].length); |
| 1202 |
| 1203 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, |
| 1204 textcheck_results[1].decoration); |
| 1205 EXPECT_EQ(spellcheck_results[2].location, textcheck_results[1].location); |
| 1206 EXPECT_EQ(spellcheck_results[2].length, textcheck_results[1].length); |
| 1207 } |
1169 } | 1208 } |
1170 | 1209 |
1171 #endif | 1210 #endif |
1172 | 1211 |
1173 // Checks some words that should be present in all English dictionaries. | 1212 // Checks some words that should be present in all English dictionaries. |
1174 TEST_F(SpellCheckTest, EnglishWords) { | 1213 TEST_F(SpellCheckTest, EnglishWords) { |
1175 static const struct { | 1214 static const struct { |
1176 const char* input; | 1215 const char* input; |
1177 bool should_pass; | 1216 bool should_pass; |
1178 } kTestCases[] = { | 1217 } kTestCases[] = { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 strlen(kTestCases[i].misspelled), | 1405 strlen(kTestCases[i].misspelled), |
1367 0, | 1406 0, |
1368 &misspelling_start, | 1407 &misspelling_start, |
1369 &misspelling_length, | 1408 &misspelling_length, |
1370 &suggestions)); | 1409 &suggestions)); |
1371 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); | 1410 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); |
1372 if (suggestions.size() > 0) | 1411 if (suggestions.size() > 0) |
1373 EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion)); | 1412 EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion)); |
1374 } | 1413 } |
1375 } | 1414 } |
OLD | NEW |