Index: chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc |
diff --git a/chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc b/chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc |
index 53873f4aecbe3a03022413fc7d75d2af31a82776..34a883fe92c7b013606432edebbc3b5a1423f53f 100644 |
--- a/chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc |
+++ b/chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc |
@@ -28,6 +28,17 @@ struct SpellcheckTestCase { |
int expected_misspelling_length; |
}; |
+struct SpellingSuggestionTestCase { |
+ // A string of text for checking. |
+ const wchar_t* input; |
+ // The position and the length of the first invalid word. |
+ int expected_misspelling_start; |
+ int expected_misspelling_length; |
+ // A comma separated string of suggested words that should occur, in their |
+ // expected order. |
+ const wchar_t* expected_suggestions; |
+}; |
+ |
base::FilePath GetHunspellDirectory() { |
base::FilePath hunspell_directory; |
if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) |
@@ -104,6 +115,36 @@ class MultilingualSpellCheckTest : public testing::Test { |
} |
} |
+ void ExpectSpellCheckSuggestionResults( |
+ const SpellingSuggestionTestCase* test_cases, |
+ size_t num_test_cases) { |
+ for (size_t i = 0; i < num_test_cases; ++i) { |
+ blink::WebVector<blink::WebString> suggestions; |
+ int misspelling_start; |
+ int misspelling_length; |
+ static_cast<blink::WebSpellCheckClient*>(provider()) |
+ ->spellCheck(blink::WebString(base::WideToUTF16(test_cases[i].input)), |
+ misspelling_start, misspelling_length, &suggestions); |
+ |
+ EXPECT_EQ(test_cases[i].expected_misspelling_start, misspelling_start); |
+ EXPECT_EQ(test_cases[i].expected_misspelling_length, misspelling_length); |
+ if (!test_cases[i].expected_suggestions) { |
+ EXPECT_EQ(0UL, suggestions.size()); |
+ continue; |
+ } |
+ |
+ std::vector<base::string16> expected_suggestions = base::SplitString( |
+ base::WideToUTF16(test_cases[i].expected_suggestions), |
+ base::string16(1, ','), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
+ |
+ EXPECT_EQ(expected_suggestions.size(), suggestions.size()); |
please use gerrit instead
2015/08/20 18:40:23
Does EXPECT_EQ(expected_suggestions, suggestions);
Julius
2015/08/20 21:52:51
expected_suggestions is of type std::vector<base::
|
+ for (size_t j = 0; |
+ j < std::min(expected_suggestions.size(), suggestions.size()); j++) { |
+ EXPECT_EQ(expected_suggestions[j], base::string16(suggestions[j])); |
+ } |
+ } |
+ } |
+ |
private: |
// Owned by |provider_|. |
SpellCheck* spellcheck_; |
@@ -203,3 +244,16 @@ TEST_F(MultilingualSpellCheckTest, MultilingualSpellCheckParagraph) { |
// English, German, Spanish, and a misspelled word. |
base::UTF8ToUTF16("rocket Schwarzkommando destruyan pcnyhon"), expected); |
} |
+ |
+// Ensure that suggestions are handled properly for multiple languages. |
+TEST_F(MultilingualSpellCheckTest, MultilingualSpellCheckSuggestions) { |
+ ReinitializeSpellCheck("en-US,es-ES"); |
+ static const SpellingSuggestionTestCase kTestCases[] = { |
+ {L"rocket", 0, 0}, |
+ {L"destruyan", 0, 0}, |
+ {L"rocet", 0, 5, L"rocket,roce,crochet,troce,rocen"}, |
+ {L"jum", 0, 3, L"hum,jun,ju,um,juma"}, |
+ {L"asdne", 0, 5, L"sadness,desasne"}, |
+ }; |
+ ExpectSpellCheckSuggestionResults(kTestCases, arraysize(kTestCases)); |
please use gerrit instead
2015/08/20 18:40:23
Inline this function, because it's used only once.
Julius
2015/08/20 21:52:51
Done.
|
+} |