| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 protected: | 74 protected: |
| 75 void ExpectSpellCheckWordResults(const std::string& languages, | 75 void ExpectSpellCheckWordResults(const std::string& languages, |
| 76 const SpellcheckTestCase* test_cases, | 76 const SpellcheckTestCase* test_cases, |
| 77 size_t num_test_cases) { | 77 size_t num_test_cases) { |
| 78 ReinitializeSpellCheck(languages); | 78 ReinitializeSpellCheck(languages); |
| 79 | 79 |
| 80 for (size_t i = 0; i < num_test_cases; ++i) { | 80 for (size_t i = 0; i < num_test_cases; ++i) { |
| 81 int misspelling_start = 0; | 81 int misspelling_start = 0; |
| 82 int misspelling_length = 0; | 82 int misspelling_length = 0; |
| 83 static_cast<blink::WebSpellCheckClient*>(provider()) | 83 static_cast<blink::WebSpellCheckClient*>(provider()) |
| 84 ->checkSpelling( | 84 ->checkSpelling(blink::WebString::fromUTF16( |
| 85 blink::WebString(base::WideToUTF16(test_cases[i].input)), | 85 base::WideToUTF16(test_cases[i].input)), |
| 86 misspelling_start, misspelling_length, nullptr); | 86 misspelling_start, misspelling_length, nullptr); |
| 87 | 87 |
| 88 EXPECT_EQ(test_cases[i].expected_misspelling_start, misspelling_start) | 88 EXPECT_EQ(test_cases[i].expected_misspelling_start, misspelling_start) |
| 89 << "Improper misspelling location found with the languages " | 89 << "Improper misspelling location found with the languages " |
| 90 << languages << " when checking \"" << test_cases[i].input << "\"."; | 90 << languages << " when checking \"" << test_cases[i].input << "\"."; |
| 91 EXPECT_EQ(test_cases[i].expected_misspelling_length, misspelling_length) | 91 EXPECT_EQ(test_cases[i].expected_misspelling_length, misspelling_length) |
| 92 << "Improper misspelling length found with the languages " | 92 << "Improper misspelling length found with the languages " |
| 93 << languages << " when checking \"" << test_cases[i].input << "\"."; | 93 << languages << " when checking \"" << test_cases[i].input << "\"."; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ExpectSpellCheckParagraphResults( | 97 void ExpectSpellCheckParagraphResults( |
| 98 const base::string16& input, | 98 const base::string16& input, |
| 99 const std::vector<SpellCheckResult>& expected) { | 99 const std::vector<SpellCheckResult>& expected) { |
| 100 blink::WebVector<blink::WebTextCheckingResult> results; | 100 blink::WebVector<blink::WebTextCheckingResult> results; |
| 101 spellcheck_->SpellCheckParagraph(blink::WebString(input), &results); | 101 spellcheck_->SpellCheckParagraph(input, &results); |
| 102 | 102 |
| 103 EXPECT_EQ(expected.size(), results.size()); | 103 EXPECT_EQ(expected.size(), results.size()); |
| 104 size_t size = std::min(results.size(), expected.size()); | 104 size_t size = std::min(results.size(), expected.size()); |
| 105 for (size_t i = 0; i < size; ++i) { | 105 for (size_t i = 0; i < size; ++i) { |
| 106 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, results[i].decoration); | 106 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, results[i].decoration); |
| 107 EXPECT_EQ(expected[i].location, results[i].location); | 107 EXPECT_EQ(expected[i].location, results[i].location); |
| 108 EXPECT_EQ(expected[i].length, results[i].length); | 108 EXPECT_EQ(expected[i].length, results[i].length); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 {L"jum", 0, 3, L"hum,jun,ju,um,juma"}, | 228 {L"jum", 0, 3, L"hum,jun,ju,um,juma"}, |
| 229 {L"asdne", 0, 5, L"sadness,desasne"}, | 229 {L"asdne", 0, 5, L"sadness,desasne"}, |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 232 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 233 blink::WebVector<blink::WebString> suggestions; | 233 blink::WebVector<blink::WebString> suggestions; |
| 234 int misspelling_start; | 234 int misspelling_start; |
| 235 int misspelling_length; | 235 int misspelling_length; |
| 236 static_cast<blink::WebSpellCheckClient*>(provider()) | 236 static_cast<blink::WebSpellCheckClient*>(provider()) |
| 237 ->checkSpelling( | 237 ->checkSpelling( |
| 238 blink::WebString(base::WideToUTF16(kTestCases[i].input)), | 238 blink::WebString::fromUTF16(base::WideToUTF16(kTestCases[i].input)), |
| 239 misspelling_start, misspelling_length, &suggestions); | 239 misspelling_start, misspelling_length, &suggestions); |
| 240 | 240 |
| 241 EXPECT_EQ(kTestCases[i].expected_misspelling_start, misspelling_start); | 241 EXPECT_EQ(kTestCases[i].expected_misspelling_start, misspelling_start); |
| 242 EXPECT_EQ(kTestCases[i].expected_misspelling_length, misspelling_length); | 242 EXPECT_EQ(kTestCases[i].expected_misspelling_length, misspelling_length); |
| 243 if (!kTestCases[i].expected_suggestions) { | 243 if (!kTestCases[i].expected_suggestions) { |
| 244 EXPECT_EQ(0UL, suggestions.size()); | 244 EXPECT_EQ(0UL, suggestions.size()); |
| 245 continue; | 245 continue; |
| 246 } | 246 } |
| 247 | 247 |
| 248 std::vector<base::string16> expected_suggestions = base::SplitString( | 248 std::vector<base::string16> expected_suggestions = base::SplitString( |
| 249 base::WideToUTF16(kTestCases[i].expected_suggestions), | 249 base::WideToUTF16(kTestCases[i].expected_suggestions), |
| 250 base::string16(1, ','), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 250 base::string16(1, ','), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 251 | 251 |
| 252 EXPECT_EQ(expected_suggestions.size(), suggestions.size()); | 252 EXPECT_EQ(expected_suggestions.size(), suggestions.size()); |
| 253 for (size_t j = 0; | 253 for (size_t j = 0; |
| 254 j < std::min(expected_suggestions.size(), suggestions.size()); j++) { | 254 j < std::min(expected_suggestions.size(), suggestions.size()); j++) { |
| 255 EXPECT_EQ(expected_suggestions[j], base::string16(suggestions[j])); | 255 EXPECT_EQ(expected_suggestions[j], suggestions[j].utf16()); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } | 258 } |
| OLD | NEW |