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" |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 | 1181 |
1182 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << | 1182 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << |
1183 " in " << kLocales[j]; | 1183 " in " << kLocales[j]; |
1184 } | 1184 } |
1185 } | 1185 } |
1186 } | 1186 } |
1187 | 1187 |
1188 // Checks that NOSUGGEST works in English dictionaries. | 1188 // Checks that NOSUGGEST works in English dictionaries. |
1189 TEST_F(SpellCheckTest, NoSuggest) { | 1189 TEST_F(SpellCheckTest, NoSuggest) { |
1190 static const struct { | 1190 static const struct { |
1191 const char* misspelling; | |
1192 const char* input; | 1191 const char* input; |
| 1192 const char* suggestion; |
1193 const char* locale; | 1193 const char* locale; |
1194 bool should_pass; | 1194 bool should_pass; |
1195 } kTestCases[] = { | 1195 } kTestCases[] = { |
1196 {"suckerbert", "cocksucker", "en-GB", true}, | 1196 {"suckerbert", "cocksucker", "en-GB", true}, |
1197 {"suckerbert", "cocksucker", "en-US", true}, | 1197 {"suckerbert", "cocksucker", "en-US", true}, |
1198 {"suckerbert", "cocksucker", "en-CA", true}, | 1198 {"suckerbert", "cocksucker", "en-CA", true}, |
1199 {"suckerbert", "cocksucker", "en-AU", true}, | 1199 {"suckerbert", "cocksucker", "en-AU", true}, |
1200 {"suckerbert", "cocksuckers", "en-GB", true}, | 1200 {"suckerbert", "cocksuckers", "en-GB", true}, |
1201 {"suckerbert", "cocksuckers", "en-US", true}, | 1201 {"suckerbert", "cocksuckers", "en-US", true}, |
1202 {"suckerbert", "cocksuckers", "en-CA", true}, | 1202 {"suckerbert", "cocksuckers", "en-CA", true}, |
1203 {"suckerbert", "cocksuckers", "en-AU", true}, | 1203 {"suckerbert", "cocksuckers", "en-AU", true}, |
1204 {"Batasunaa", "Batasuna", "ca-ES", true}, | 1204 {"Batasunaa", "Batasuna", "ca-ES", true}, |
1205 {"pornoo", "porno", "it-IT", true}, | 1205 {"pornoo", "porno", "it-IT", true}, |
1206 {"catass", "catas", "lt-LT", true}, | 1206 {"catass", "catas", "lt-LT", true}, |
1207 {"kuracc", "kurac", "sl-SI", true}, | 1207 {"kuracc", "kurac", "sl-SI", true}, |
1208 {"pittt", "pitt", "sv-SE", true}, | 1208 {"pittt", "pitt", "sv-SE", true}, |
1209 }; | 1209 }; |
1210 | 1210 |
1211 size_t test_cases_size = ARRAYSIZE_UNSAFE(kTestCases); | 1211 size_t test_cases_size = ARRAYSIZE_UNSAFE(kTestCases); |
1212 for (size_t i = 0; i < test_cases_size; ++i) { | 1212 for (size_t i = 0; i < test_cases_size; ++i) { |
1213 ReinitializeSpellCheck(kTestCases[i].locale); | 1213 ReinitializeSpellCheck(kTestCases[i].locale); |
1214 size_t input_length = 0; | 1214 size_t suggestion_length = 0; |
1215 if (kTestCases[i].input != NULL) | 1215 if (kTestCases[i].suggestion != NULL) |
1216 input_length = strlen(kTestCases[i].input); | 1216 suggestion_length = strlen(kTestCases[i].suggestion); |
1217 | 1217 |
1218 // First check that the NOSUGGEST flag didn't mark this word as not being in | 1218 // First check that the NOSUGGEST flag didn't mark this word as not being in |
1219 // the dictionary. | 1219 // the dictionary. |
1220 int misspelling_start = 0; | 1220 int misspelling_start = 0; |
1221 int misspelling_length = 0; | 1221 int misspelling_length = 0; |
1222 bool result = spell_check()->SpellCheckWord( | 1222 bool result = spell_check()->SpellCheckWord( |
1223 ASCIIToUTF16(kTestCases[i].input).c_str(), | 1223 ASCIIToUTF16(kTestCases[i].suggestion).c_str(), |
1224 static_cast<int>(input_length), | 1224 static_cast<int>(suggestion_length), |
1225 0, | 1225 0, |
1226 &misspelling_start, | 1226 &misspelling_start, |
1227 &misspelling_length, NULL); | 1227 &misspelling_length, NULL); |
1228 | 1228 |
1229 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].input << | 1229 EXPECT_EQ(kTestCases[i].should_pass, result) << kTestCases[i].suggestion << |
1230 " in " << kTestCases[i].input; | 1230 " in " << kTestCases[i].locale; |
1231 | 1231 |
1232 // Now verify that this test case does not show up as a suggestion. | 1232 // Now verify that this test case does not show up as a suggestion. |
1233 std::vector<string16> suggestions; | 1233 std::vector<string16> suggestions; |
1234 input_length = 0; | 1234 size_t input_length = 0; |
1235 if (kTestCases[i].misspelling != NULL) | 1235 if (kTestCases[i].input != NULL) |
1236 input_length = strlen(kTestCases[i].misspelling); | 1236 input_length = strlen(kTestCases[i].input); |
1237 result = spell_check()->SpellCheckWord( | 1237 result = spell_check()->SpellCheckWord( |
1238 ASCIIToUTF16(kTestCases[i].misspelling).c_str(), | 1238 ASCIIToUTF16(kTestCases[i].input).c_str(), |
1239 static_cast<int>(input_length), | 1239 static_cast<int>(input_length), |
1240 0, | 1240 0, |
1241 &misspelling_start, | 1241 &misspelling_start, |
1242 &misspelling_length, | 1242 &misspelling_length, |
1243 &suggestions); | 1243 &suggestions); |
1244 // Check if the suggested words occur. | 1244 // Input word should be a misspelling. |
1245 EXPECT_FALSE(result) << kTestCases[i].misspelling | 1245 EXPECT_FALSE(result) << kTestCases[i].input |
1246 << " is not a misspelling in " | 1246 << " is not a misspelling in " |
1247 << kTestCases[i].locale; | 1247 << kTestCases[i].locale; |
| 1248 // Check if the suggested words occur. |
1248 for (int j = 0; j < static_cast<int>(suggestions.size()); j++) { | 1249 for (int j = 0; j < static_cast<int>(suggestions.size()); j++) { |
1249 for (size_t t = 0; t < test_cases_size; t++) { | 1250 for (size_t t = 0; t < test_cases_size; t++) { |
1250 int compare_result = | 1251 int compare_result = |
1251 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].input)); | 1252 suggestions.at(j).compare(ASCIIToUTF16(kTestCases[t].suggestion)); |
1252 EXPECT_FALSE(compare_result == 0) << kTestCases[t].input << | 1253 EXPECT_FALSE(compare_result == 0) << kTestCases[t].suggestion << |
1253 " in " << kTestCases[i].locale; | 1254 " in " << kTestCases[i].locale; |
1254 } | 1255 } |
1255 } | 1256 } |
1256 } | 1257 } |
1257 } | 1258 } |
1258 | 1259 |
1259 // Check that the correct dictionary files are checked in. | 1260 // Check that the correct dictionary files are checked in. |
1260 TEST_F(SpellCheckTest, DictionaryFiles) { | 1261 TEST_F(SpellCheckTest, DictionaryFiles) { |
1261 std::vector<std::string> locale_codes; | |
1262 l10n_util::GetAcceptLanguagesForLocale("C", &locale_codes); | |
1263 EXPECT_FALSE(locale_codes.empty()); | |
1264 | |
1265 std::vector<std::string> spellcheck_languages; | 1262 std::vector<std::string> spellcheck_languages; |
1266 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages); | 1263 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages); |
1267 EXPECT_FALSE(spellcheck_languages.empty()); | 1264 EXPECT_FALSE(spellcheck_languages.empty()); |
1268 EXPECT_LE(spellcheck_languages.size(), locale_codes.size()); | |
1269 | 1265 |
1270 FilePath hunspell = GetHunspellDirectory(); | 1266 FilePath hunspell = GetHunspellDirectory(); |
1271 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { | 1267 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { |
1272 FilePath dict = chrome::spellcheck_common::GetVersionedFileName( | 1268 FilePath dict = chrome::spellcheck_common::GetVersionedFileName( |
1273 spellcheck_languages[i], hunspell); | 1269 spellcheck_languages[i], hunspell); |
1274 EXPECT_TRUE(file_util::PathExists(dict)) << dict.value() << " not found"; | 1270 EXPECT_TRUE(file_util::PathExists(dict)) << dict.value() << " not found"; |
1275 } | 1271 } |
1276 } | 1272 } |
1277 | 1273 |
| 1274 // Check for correct behavior around the maximum word length boundary. |
| 1275 TEST_F(SpellCheckTest, MaxWordLengthBoundary) { |
| 1276 static const char* kTestCases[] = { |
| 1277 // 96 characters. |
| 1278 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqr", |
| 1279 // 97 characters. |
| 1280 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrs", |
| 1281 // 98 characters. |
| 1282 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrst", |
| 1283 // 99 characters. |
| 1284 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrstu", |
| 1285 // 100 characters. |
| 1286 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrstuv", |
| 1287 // 101 characters. |
| 1288 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrstuvw", |
| 1289 // 102 characters. |
| 1290 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw
xyzabcdefghijklmnopqrstuvwx" |
| 1291 }; |
| 1292 |
| 1293 ReinitializeSpellCheck("en-US"); |
| 1294 size_t test_cases_size = ARRAYSIZE_UNSAFE(kTestCases); |
| 1295 for (size_t i = 0; i < test_cases_size; ++i) { |
| 1296 size_t input_length = strlen(kTestCases[i]); |
| 1297 |
| 1298 int misspelling_start = 0; |
| 1299 int misspelling_length = 0; |
| 1300 std::vector<string16> suggestions; |
| 1301 bool result = spell_check()->SpellCheckWord( |
| 1302 ASCIIToUTF16(kTestCases[i]).c_str(), |
| 1303 static_cast<int>(input_length), |
| 1304 0, |
| 1305 &misspelling_start, |
| 1306 &misspelling_length, |
| 1307 &suggestions); |
| 1308 |
| 1309 EXPECT_FALSE(result) << kTestCases[i] << " is spelled correctly"; |
| 1310 EXPECT_TRUE(suggestions.empty()) << kTestCases[i] << " has suggestions"; |
| 1311 } |
| 1312 } |
| 1313 |
1278 #endif | 1314 #endif |
OLD | NEW |