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 "components/spellcheck/renderer/spellcheck.h" | 5 #include "components/spellcheck/renderer/spellcheck.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 4, base::UTF8ToUTF16("I've"))); | 1194 4, base::UTF8ToUTF16("I've"))); |
1195 | 1195 |
1196 // All typographical apostrophe results. | 1196 // All typographical apostrophe results. |
1197 spellcheck_results.push_back( | 1197 spellcheck_results.push_back( |
1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5, | 1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5, |
1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); |
1200 spellcheck_results.push_back(SpellCheckResult( | 1200 spellcheck_results.push_back(SpellCheckResult( |
1201 SpellCheckResult::SPELLING, 6, 6, | 1201 SpellCheckResult::SPELLING, 6, 6, |
1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"))); | 1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"))); |
1203 spellcheck_results.push_back(SpellCheckResult( | 1203 spellcheck_results.push_back(SpellCheckResult( |
1204 SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16( | 1204 SpellCheckResult::SPELLING, 13, 10, |
1205 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out" | 1205 base::WideToUTF16( |
1206 TYPOGRAPHICAL_APOSTROPHE L"s"))); | 1206 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"ou" |
| 1207 L"t" TYPOGRAPHICAL_APOSTROPHE L"s"))); |
1207 | 1208 |
1208 // Replacements that differ only by apostrophe type should be ignored. | 1209 // Replacements that differ only by apostrophe type should be ignored. |
1209 spellcheck_results.push_back( | 1210 spellcheck_results.push_back( |
1210 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4, | 1211 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4, |
1211 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1212 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); |
1212 spellcheck_results.push_back( | 1213 spellcheck_results.push_back( |
1213 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4, | 1214 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4, |
1214 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1215 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); |
1215 | 1216 |
| 1217 // If we have multiple replacements that all differ only by apostrophe type, |
| 1218 // we should ignore this misspelling. |
| 1219 spellcheck_results.push_back(SpellCheckResult( |
| 1220 SpellCheckResult::SPELLING, 0, 11, |
| 1221 std::vector<base::string16>( |
| 1222 {base::UTF8ToUTF16("Ik've havn'"), |
| 1223 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE |
| 1224 "ve havn" TYPOGRAPHICAL_APOSTROPHE)}))); |
| 1225 |
| 1226 // If we have multiple replacements where some only differ by apostrophe type |
| 1227 // and some don't, we should keep this misspelling, but remove the |
| 1228 // replacements that only differ by apostrophe type. |
| 1229 spellcheck_results.push_back(SpellCheckResult( |
| 1230 SpellCheckResult::SPELLING, 0, 5, |
| 1231 std::vector<base::string16>( |
| 1232 {base::UTF8ToUTF16("I've"), base::UTF8ToUTF16("Ive"), |
| 1233 base::WideToUTF16(L"Ik" TYPOGRAPHICAL_APOSTROPHE "ve")}))); |
| 1234 |
| 1235 // Similar to the previous case except with the apostrophe changing from |
| 1236 // typographical to straight instead of the other direction |
| 1237 spellcheck_results.push_back(SpellCheckResult( |
| 1238 SpellCheckResult::SPELLING, 6, 6, |
| 1239 std::vector<base::string16>({base::UTF8ToUTF16("havn't"), |
| 1240 base::UTF8ToUTF16("havnt"), |
| 1241 base::UTF8ToUTF16("haven't")}))); |
| 1242 |
| 1243 // If we have multiple replacements, none of which differ only by apostrophe |
| 1244 // type, we should keep this misspelling. |
| 1245 spellcheck_results.push_back(SpellCheckResult( |
| 1246 SpellCheckResult::SPELLING, 6, 6, |
| 1247 std::vector<base::string16>( |
| 1248 {base::UTF8ToUTF16("have"), base::UTF8ToUTF16("haven't")}))); |
| 1249 |
1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1250 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | 1251 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, |
1218 text, spellcheck_results, | 1252 text, spellcheck_results, |
1219 &textcheck_results); | 1253 &textcheck_results); |
1220 | 1254 |
1221 static const wchar_t* kExpectedReplacements[] = { | 1255 static std::vector<std::vector<const wchar_t*>> kExpectedReplacements = { |
1222 L"I've", | 1256 {L"I've"}, |
1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | 1257 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"}, |
1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", | 1258 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's"}, |
1225 L"I've", | 1259 {L"I've"}, |
1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | 1260 {L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"}, |
1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", | 1261 {L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s"}, |
| 1262 {L"I've", L"Ive"}, |
| 1263 {L"havnt", L"haven" TYPOGRAPHICAL_APOSTROPHE "t"}, |
| 1264 {L"have", L"haven" TYPOGRAPHICAL_APOSTROPHE "t"}, |
1228 }; | 1265 }; |
1229 | 1266 |
1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); | 1267 ASSERT_EQ(kExpectedReplacements.size(), textcheck_results.size()); |
1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { | 1268 for (size_t i = 0; i < kExpectedReplacements.size(); ++i) { |
1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), | 1269 EXPECT_EQ(kExpectedReplacements[i].size(), |
1233 textcheck_results[i].replacement.Utf16()) | 1270 textcheck_results[i].replacements.size()); |
1234 << "i=" << i << "\nactual: \"" | 1271 for (size_t j = 0; j < kExpectedReplacements[i].size(); ++j) { |
1235 << textcheck_results[i].replacement.Utf16() << "\""; | 1272 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i][j]), |
| 1273 textcheck_results[i].replacements[j].Utf16()) |
| 1274 << "i=" << i << "\nj=" << j << "\nactual: \"" |
| 1275 << textcheck_results[i].replacements[j].Utf16() << "\""; |
| 1276 } |
1236 } | 1277 } |
1237 } | 1278 } |
1238 | 1279 |
1239 // Checks some words that should be present in all English dictionaries. | 1280 // Checks some words that should be present in all English dictionaries. |
1240 TEST_F(SpellCheckTest, EnglishWords) { | 1281 TEST_F(SpellCheckTest, EnglishWords) { |
1241 static const struct { | 1282 static const struct { |
1242 const char* input; | 1283 const char* input; |
1243 bool should_pass; | 1284 bool should_pass; |
1244 } kTestCases[] = { | 1285 } kTestCases[] = { |
1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking | 1286 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 // to be updated accordingly. | 1604 // to be updated accordingly. |
1564 ASSERT_EQ(5, spellcheck::kMaxSuggestions); | 1605 ASSERT_EQ(5, spellcheck::kMaxSuggestions); |
1565 FillSuggestions(suggestions_list, &suggestion_results); | 1606 FillSuggestions(suggestions_list, &suggestion_results); |
1566 ASSERT_EQ(5U, suggestion_results.size()); | 1607 ASSERT_EQ(5U, suggestion_results.size()); |
1567 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); | 1608 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); |
1568 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); | 1609 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); |
1569 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); | 1610 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); |
1570 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); | 1611 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); |
1571 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); | 1612 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); |
1572 } | 1613 } |
OLD | NEW |