Chromium Code Reviews| 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 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 #endif | 1135 #endif |
| 1136 | 1136 |
| 1137 // Verify that the SpellCheck class keeps the spelling marker added to a | 1137 // Verify that the SpellCheck class keeps the spelling marker added to a |
| 1138 // misspelled word "zz". | 1138 // misspelled word "zz". |
| 1139 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsMarkers) { | 1139 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsMarkers) { |
| 1140 base::string16 text = base::ASCIIToUTF16("zz"); | 1140 base::string16 text = base::ASCIIToUTF16("zz"); |
| 1141 std::vector<SpellCheckResult> spellcheck_results; | 1141 std::vector<SpellCheckResult> spellcheck_results; |
| 1142 spellcheck_results.push_back( | 1142 spellcheck_results.push_back( |
| 1143 SpellCheckResult(SpellCheckResult::SPELLING, 0, 2, base::string16())); | 1143 SpellCheckResult(SpellCheckResult::SPELLING, 0, 2)); |
| 1144 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1144 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1145 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | 1145 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, |
| 1146 text, spellcheck_results, | 1146 text, spellcheck_results, |
| 1147 &textcheck_results); | 1147 &textcheck_results); |
| 1148 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1148 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); |
| 1149 EXPECT_EQ(blink::kWebTextDecorationTypeSpelling, | 1149 EXPECT_EQ(blink::kWebTextDecorationTypeSpelling, |
| 1150 textcheck_results[0].decoration); | 1150 textcheck_results[0].decoration); |
| 1151 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1151 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
| 1152 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1152 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
| 1153 } | 1153 } |
| 1154 | 1154 |
| 1155 // Verify that the SpellCheck class replaces the spelling marker added to a | 1155 // Verify that the SpellCheck class replaces the spelling marker added to a |
| 1156 // contextually-misspelled word "bean" with a grammar marker. | 1156 // contextually-misspelled word "bean" with a grammar marker. |
| 1157 TEST_F(SpellCheckTest, CreateTextCheckingResultsAddsGrammarMarkers) { | 1157 TEST_F(SpellCheckTest, CreateTextCheckingResultsAddsGrammarMarkers) { |
| 1158 base::string16 text = base::ASCIIToUTF16("I have bean to USA."); | 1158 base::string16 text = base::ASCIIToUTF16("I have bean to USA."); |
| 1159 std::vector<SpellCheckResult> spellcheck_results; | 1159 std::vector<SpellCheckResult> spellcheck_results; |
| 1160 spellcheck_results.push_back( | 1160 spellcheck_results.push_back( |
| 1161 SpellCheckResult(SpellCheckResult::SPELLING, 7, 4, base::string16())); | 1161 SpellCheckResult(SpellCheckResult::SPELLING, 7, 4)); |
| 1162 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1162 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1163 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | 1163 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, |
| 1164 text, spellcheck_results, | 1164 text, spellcheck_results, |
| 1165 &textcheck_results); | 1165 &textcheck_results); |
| 1166 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1166 ASSERT_EQ(spellcheck_results.size(), textcheck_results.size()); |
| 1167 EXPECT_EQ(blink::kWebTextDecorationTypeGrammar, | 1167 EXPECT_EQ(blink::kWebTextDecorationTypeGrammar, |
| 1168 textcheck_results[0].decoration); | 1168 textcheck_results[0].decoration); |
| 1169 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1169 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
| 1170 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1170 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 // Verify that the SpellCheck preserves the original apostrophe type in the | 1173 // Verify that the SpellCheck preserves the original apostrophe type in the |
| 1174 // checked text, regardless of the type of apostrophe the browser returns. | 1174 // checked text, regardless of the type of apostrophe the browser returns. |
| 1175 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsTypographicalApostrophe) { | 1175 TEST_F(SpellCheckTest, CreateTextCheckingResultsKeepsTypographicalApostrophe) { |
| 1176 base::string16 text = base::WideToUTF16( | 1176 base::string16 text = base::WideToUTF16( |
| 1177 L"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L"t ni'n" | 1177 L"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L"t ni'n" |
| 1178 TYPOGRAPHICAL_APOSTROPHE L"out-s I've I" TYPOGRAPHICAL_APOSTROPHE | 1178 TYPOGRAPHICAL_APOSTROPHE L"out-s I've I" TYPOGRAPHICAL_APOSTROPHE |
| 1179 L"ve"); | 1179 L"ve"); |
| 1180 std::vector<SpellCheckResult> spellcheck_results; | 1180 std::vector<SpellCheckResult> spellcheck_results; |
| 1181 | 1181 |
| 1182 // All typewriter apostrophe results. | 1182 // All typewriter apostrophe results. |
| 1183 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 0, | |
| 1184 5, base::UTF8ToUTF16("I've"))); | |
| 1185 spellcheck_results.push_back(SpellCheckResult( | 1183 spellcheck_results.push_back(SpellCheckResult( |
| 1186 SpellCheckResult::SPELLING, 6, 6, base::UTF8ToUTF16("haven't"))); | 1184 SpellCheckResult::SPELLING, 0, 5, |
| 1185 std::vector<base::string16>({base::UTF8ToUTF16("I've")}))); | |
|
groby-ooo-7-16
2017/04/28 23:45:55
That code is fairly ugly by now... I wonder if we
| |
| 1187 spellcheck_results.push_back(SpellCheckResult( | 1186 spellcheck_results.push_back(SpellCheckResult( |
| 1188 SpellCheckResult::SPELLING, 13, 10, base::UTF8ToUTF16("in'n'out's"))); | 1187 SpellCheckResult::SPELLING, 6, 6, |
| 1188 std::vector<base::string16>({base::UTF8ToUTF16("haven't")}))); | |
| 1189 spellcheck_results.push_back(SpellCheckResult( | |
| 1190 SpellCheckResult::SPELLING, 13, 10, | |
| 1191 std::vector<base::string16>({base::UTF8ToUTF16("in'n'out's")}))); | |
| 1189 | 1192 |
| 1190 // Replacements that differ only by apostrophe type should be ignored. | 1193 // Replacements that differ only by apostrophe type should be ignored. |
| 1191 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 24, | 1194 spellcheck_results.push_back(SpellCheckResult( |
| 1192 4, base::UTF8ToUTF16("I've"))); | 1195 SpellCheckResult::SPELLING, 24, 4, |
| 1193 spellcheck_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 29, | 1196 std::vector<base::string16>({base::UTF8ToUTF16("I've")}))); |
| 1194 4, base::UTF8ToUTF16("I've"))); | 1197 spellcheck_results.push_back(SpellCheckResult( |
| 1198 SpellCheckResult::SPELLING, 29, 4, | |
| 1199 std::vector<base::string16>({base::UTF8ToUTF16("I've")}))); | |
| 1195 | 1200 |
| 1196 // All typographical apostrophe results. | 1201 // All typographical apostrophe results. |
| 1197 spellcheck_results.push_back( | 1202 spellcheck_results.push_back(SpellCheckResult( |
| 1198 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5, | 1203 SpellCheckResult::SPELLING, 0, 5, |
| 1199 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1204 std::vector<base::string16>( |
| 1205 {base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")}))); | |
| 1200 spellcheck_results.push_back(SpellCheckResult( | 1206 spellcheck_results.push_back(SpellCheckResult( |
| 1201 SpellCheckResult::SPELLING, 6, 6, | 1207 SpellCheckResult::SPELLING, 6, 6, |
| 1202 base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t"))); | 1208 std::vector<base::string16>( |
| 1209 {base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t")}))); | |
| 1203 spellcheck_results.push_back(SpellCheckResult( | 1210 spellcheck_results.push_back(SpellCheckResult( |
| 1204 SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16( | 1211 SpellCheckResult::SPELLING, 13, 10, |
| 1205 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out" | 1212 std::vector<base::string16>({base::WideToUTF16( |
| 1206 TYPOGRAPHICAL_APOSTROPHE L"s"))); | 1213 L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"ou" |
| 1214 L"t" TYPOGRAPHICAL_APOSTROPHE L"s")}))); | |
| 1207 | 1215 |
| 1208 // Replacements that differ only by apostrophe type should be ignored. | 1216 // Replacements that differ only by apostrophe type should be ignored. |
| 1209 spellcheck_results.push_back( | 1217 spellcheck_results.push_back(SpellCheckResult( |
| 1210 SpellCheckResult(SpellCheckResult::SPELLING, 24, 4, | 1218 SpellCheckResult::SPELLING, 24, 4, |
| 1211 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1219 std::vector<base::string16>( |
| 1212 spellcheck_results.push_back( | 1220 {base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")}))); |
| 1213 SpellCheckResult(SpellCheckResult::SPELLING, 29, 4, | 1221 spellcheck_results.push_back(SpellCheckResult( |
| 1214 base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve"))); | 1222 SpellCheckResult::SPELLING, 29, 4, |
| 1223 std::vector<base::string16>( | |
| 1224 {base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")}))); | |
| 1215 | 1225 |
| 1216 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; | 1226 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1217 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, | 1227 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, 0, |
| 1218 text, spellcheck_results, | 1228 text, spellcheck_results, |
| 1219 &textcheck_results); | 1229 &textcheck_results); |
| 1220 | 1230 |
| 1221 static const wchar_t* kExpectedReplacements[] = { | 1231 static const wchar_t* kExpectedReplacements[] = { |
| 1222 L"I've", | 1232 L"I've", |
| 1223 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | 1233 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", |
| 1224 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", | 1234 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's", |
| 1225 L"I've", | 1235 L"I've", |
| 1226 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", | 1236 L"haven" TYPOGRAPHICAL_APOSTROPHE L"t", |
| 1227 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", | 1237 L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s", |
| 1228 }; | 1238 }; |
| 1229 | 1239 |
| 1230 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); | 1240 ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size()); |
| 1231 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { | 1241 for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) { |
| 1232 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), | 1242 EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]), |
| 1233 textcheck_results[i].replacement.Utf16()) | 1243 textcheck_results[i].replacements[0].Utf16()) |
| 1234 << "i=" << i << "\nactual: \"" | 1244 << "i=" << i << "\nactual: \"" |
| 1235 << textcheck_results[i].replacement.Utf16() << "\""; | 1245 << textcheck_results[i].replacements[0].Utf16() << "\""; |
| 1236 } | 1246 } |
| 1237 } | 1247 } |
| 1238 | 1248 |
| 1239 // Checks some words that should be present in all English dictionaries. | 1249 // Checks some words that should be present in all English dictionaries. |
| 1240 TEST_F(SpellCheckTest, EnglishWords) { | 1250 TEST_F(SpellCheckTest, EnglishWords) { |
| 1241 static const struct { | 1251 static const struct { |
| 1242 const char* input; | 1252 const char* input; |
| 1243 bool should_pass; | 1253 bool should_pass; |
| 1244 } kTestCases[] = { | 1254 } kTestCases[] = { |
| 1245 // Issue 146093: "Chromebook" and "Chromebox" not included in spell-checking | 1255 // 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. | 1573 // to be updated accordingly. |
| 1564 ASSERT_EQ(5, spellcheck::kMaxSuggestions); | 1574 ASSERT_EQ(5, spellcheck::kMaxSuggestions); |
| 1565 FillSuggestions(suggestions_list, &suggestion_results); | 1575 FillSuggestions(suggestions_list, &suggestion_results); |
| 1566 ASSERT_EQ(5U, suggestion_results.size()); | 1576 ASSERT_EQ(5U, suggestion_results.size()); |
| 1567 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); | 1577 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); |
| 1568 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); | 1578 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); |
| 1569 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); | 1579 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); |
| 1570 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); | 1580 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); |
| 1571 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); | 1581 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); |
| 1572 } | 1582 } |
| OLD | NEW |