Commit 566c2689 authored by Mohamed Mansour's avatar Mohamed Mansour Committed by Commit Bot

Cleanup offensive terms in spellcheck_unittest.cc

- The tests now use the testing locale "xx-XX", which marks
  certain words offensive to make this unit test correct.
- Re-enabled the remaining part of the test since the
  suggestions are now sped up.
- Added extra test check to verify spellchecker loaded the
  local correctly, otherwise it defaults to en-US

Bug: 981132, 673424
Change-Id: Idc84ddba5dc40a2bd2b47cc6fa58a622ab30ca2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1701958
Commit-Queue: Mohamed Mansour <mmansour@microsoft.com>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685304}
parent 91ab4daf
...@@ -996,7 +996,7 @@ deps = { ...@@ -996,7 +996,7 @@ deps = {
}, },
'src/third_party/hunspell_dictionaries': 'src/third_party/hunspell_dictionaries':
Var('chromium_git') + '/chromium/deps/hunspell_dictionaries.git' + '@' + '3874188bd69fe67a825d07584c74451e45063e95', Var('chromium_git') + '/chromium/deps/hunspell_dictionaries.git' + '@' + 'ecb3c4f4ce2c13278699489bd6356a31e1ee4d11',
'src/third_party/icu': 'src/third_party/icu':
Var('chromium_git') + '/chromium/deps/icu.git' + '@' + '682a230923933a7157a41b88c7804b6b7d2abdfa', Var('chromium_git') + '/chromium/deps/icu.git' + '@' + '682a230923933a7157a41b88c7804b6b7d2abdfa',
......
...@@ -70,9 +70,12 @@ class SpellCheckTest : public testing::Test { ...@@ -70,9 +70,12 @@ class SpellCheckTest : public testing::Test {
void InitializeSpellCheck(const std::string& language) { void InitializeSpellCheck(const std::string& language) {
base::FilePath hunspell_directory = GetHunspellDirectory(); base::FilePath hunspell_directory = GetHunspellDirectory();
EXPECT_FALSE(hunspell_directory.empty()); EXPECT_FALSE(hunspell_directory.empty());
base::File file( base::FilePath hunspell_file_path =
spellcheck::GetVersionedFileName(language, hunspell_directory), spellcheck::GetVersionedFileName(language, hunspell_directory);
base::File::FLAG_OPEN | base::File::FLAG_READ); base::File file(hunspell_file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
EXPECT_TRUE(file.IsValid()) << hunspell_file_path << " is not valid"
<< file.ErrorToString(file.GetLastFileError());
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// TODO(groby): Forcing spellcheck to use hunspell, even on OSX. // TODO(groby): Forcing spellcheck to use hunspell, even on OSX.
// Instead, tests should exercise individual spelling engines. // Instead, tests should exercise individual spelling engines.
...@@ -1338,29 +1341,16 @@ TEST_F(SpellCheckTest, EnglishWords) { ...@@ -1338,29 +1341,16 @@ TEST_F(SpellCheckTest, EnglishWords) {
// Checks that NOSUGGEST works in English dictionaries. // Checks that NOSUGGEST works in English dictionaries.
TEST_F(SpellCheckTest, NoSuggest) { TEST_F(SpellCheckTest, NoSuggest) {
ReinitializeSpellCheck("xx-XX");
static const struct { static const struct {
const char* input; const char* input;
const char* suggestion; const char* suggestion;
const char* locale;
bool should_pass; bool should_pass;
} kTestCases[] = { } kTestCases[] = {{"typograpy", "typographit", true},
{"suckerbert", "cocksucker", "en-GB", true}, {"typograpy", "typographits", true}};
{"suckerbert", "cocksucker", "en-US", true},
{"suckerbert", "cocksucker", "en-CA", true},
{"suckerbert", "cocksucker", "en-AU", true},
{"suckerbert", "cocksuckers", "en-GB", true},
{"suckerbert", "cocksuckers", "en-US", true},
{"suckerbert", "cocksuckers", "en-CA", true},
{"suckerbert", "cocksuckers", "en-AU", true},
{"Batasunaa", "Batasuna", "ca-ES", true},
{"pornoo", "porno", "it-IT", true},
{"catass", "catas", "lt-LT", true},
{"kuracc", "kurac", "sl-SI", true},
{"pittt", "pitt", "sv-SE", true},
};
for (const auto& test_case : kTestCases) { for (const auto& test_case : kTestCases) {
ReinitializeSpellCheck(test_case.locale);
size_t suggestion_length = 0; size_t suggestion_length = 0;
if (test_case.suggestion) if (test_case.suggestion)
suggestion_length = strlen(test_case.suggestion); suggestion_length = strlen(test_case.suggestion);
...@@ -1374,10 +1364,8 @@ TEST_F(SpellCheckTest, NoSuggest) { ...@@ -1374,10 +1364,8 @@ TEST_F(SpellCheckTest, NoSuggest) {
suggestion_length, kNoTag, &misspelling_start, &misspelling_length, suggestion_length, kNoTag, &misspelling_start, &misspelling_length,
nullptr); nullptr);
EXPECT_EQ(test_case.should_pass, result) EXPECT_EQ(test_case.should_pass, result) << test_case.suggestion;
<< test_case.suggestion << " in " << test_case.locale;
// TODO(cb/673424): Bring this back when suggestions are sped up.
#if 0
// Now verify that this test case does not show up as a suggestion. // Now verify that this test case does not show up as a suggestion.
std::vector<base::string16> suggestions; std::vector<base::string16> suggestions;
size_t input_length = 0; size_t input_length = 0;
...@@ -1387,19 +1375,18 @@ TEST_F(SpellCheckTest, NoSuggest) { ...@@ -1387,19 +1375,18 @@ TEST_F(SpellCheckTest, NoSuggest) {
base::ASCIIToUTF16(test_case.input).c_str(), kNoOffset, base::ASCIIToUTF16(test_case.input).c_str(), kNoOffset,
input_length, kNoTag, &misspelling_start, input_length, kNoTag, &misspelling_start,
&misspelling_length, &suggestions); &misspelling_length, &suggestions);
// Input word should be a misspelling. // Input word should be a misspelling.
EXPECT_FALSE(result) << test_case.input << " is not a misspelling in " EXPECT_FALSE(result) << test_case.input << " is not a misspelling";
<< test_case.locale;
// Check if the suggested words occur. // Check if the suggested words occur.
for (const base::string16& suggestion : suggestions) { for (const base::string16& suggestion : suggestions) {
for (const auto& test_case_to_check : kTestCases) { for (const auto& test_case_to_check : kTestCases) {
int compare_result = suggestion.compare( int compare_result = suggestion.compare(
base::ASCIIToUTF16(test_case_to_check.suggestion)); base::ASCIIToUTF16(test_case_to_check.suggestion));
EXPECT_FALSE(compare_result == 0) EXPECT_FALSE(compare_result == 0) << test_case_to_check.suggestion;
<< test_case_to_check.suggestion << " in " << test_case.locale;
} }
} }
#endif
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment