| 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/message_loop.h" | 8 #include "base/message_loop/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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 bool CheckSpelling(const std::string& word, int tag) { | 82 bool CheckSpelling(const std::string& word, int tag) { |
| 83 return spell_check_->spellcheck_.platform_spelling_engine_->CheckSpelling( | 83 return spell_check_->spellcheck_.platform_spelling_engine_->CheckSpelling( |
| 84 ASCIIToUTF16(word), tag); | 84 ASCIIToUTF16(word), tag); |
| 85 } | 85 } |
| 86 | 86 |
| 87 #if !defined(OS_MACOSX) | 87 #if !defined(OS_MACOSX) |
| 88 protected: | 88 protected: |
| 89 void TestSpellCheckParagraph( | 89 void TestSpellCheckParagraph( |
| 90 const string16& input, | 90 const string16& input, |
| 91 const std::vector<SpellCheckResult>& expected) { | 91 const std::vector<SpellCheckResult>& expected) { |
| 92 WebKit::WebVector<WebKit::WebTextCheckingResult> results; | 92 blink::WebVector<blink::WebTextCheckingResult> results; |
| 93 spell_check()->SpellCheckParagraph(input, | 93 spell_check()->SpellCheckParagraph(input, |
| 94 &results); | 94 &results); |
| 95 | 95 |
| 96 EXPECT_EQ(results.size(), expected.size()); | 96 EXPECT_EQ(results.size(), expected.size()); |
| 97 size_t size = std::min(results.size(), expected.size()); | 97 size_t size = std::min(results.size(), expected.size()); |
| 98 for (size_t j = 0; j < size; ++j) { | 98 for (size_t j = 0; j < size; ++j) { |
| 99 EXPECT_EQ(results[j].decoration, WebKit::WebTextDecorationTypeSpelling); | 99 EXPECT_EQ(results[j].decoration, blink::WebTextDecorationTypeSpelling); |
| 100 EXPECT_EQ(results[j].location, expected[j].location); | 100 EXPECT_EQ(results[j].location, expected[j].location); |
| 101 EXPECT_EQ(results[j].length, expected[j].length); | 101 EXPECT_EQ(results[j].length, expected[j].length); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 #endif | 104 #endif |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 scoped_ptr<SpellCheck> spell_check_; | 107 scoped_ptr<SpellCheck> spell_check_; |
| 108 base::MessageLoop loop; | 108 base::MessageLoop loop; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // A fake completion object for verification. | 111 // A fake completion object for verification. |
| 112 class MockTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { | 112 class MockTextCheckingCompletion : public blink::WebTextCheckingCompletion { |
| 113 public: | 113 public: |
| 114 MockTextCheckingCompletion() | 114 MockTextCheckingCompletion() |
| 115 : completion_count_(0) { | 115 : completion_count_(0) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual void didFinishCheckingText( | 118 virtual void didFinishCheckingText( |
| 119 const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) | 119 const blink::WebVector<blink::WebTextCheckingResult>& results) |
| 120 OVERRIDE { | 120 OVERRIDE { |
| 121 completion_count_++; | 121 completion_count_++; |
| 122 last_results_ = results; | 122 last_results_ = results; |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void didCancelCheckingText() OVERRIDE { | 125 virtual void didCancelCheckingText() OVERRIDE { |
| 126 completion_count_++; | 126 completion_count_++; |
| 127 } | 127 } |
| 128 | 128 |
| 129 size_t completion_count_; | 129 size_t completion_count_; |
| 130 WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; | 130 blink::WebVector<blink::WebTextCheckingResult> last_results_; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 // Operates unit tests for the webkit_glue::SpellCheckWord() function | 133 // Operates unit tests for the webkit_glue::SpellCheckWord() function |
| 134 // with the US English dictionary. | 134 // with the US English dictionary. |
| 135 // The unit tests in this function consist of: | 135 // The unit tests in this function consist of: |
| 136 // * Tests for the function with empty strings; | 136 // * Tests for the function with empty strings; |
| 137 // * Tests for the function with a valid English word; | 137 // * Tests for the function with a valid English word; |
| 138 // * Tests for the function with a valid non-English word; | 138 // * Tests for the function with a valid non-English word; |
| 139 // * Tests for the function with a valid English word with a preceding | 139 // * Tests for the function with a valid English word with a preceding |
| 140 // space character; | 140 // space character; |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 TEST_F(SpellCheckTest, CreateTextCheckingResults) { | 1118 TEST_F(SpellCheckTest, CreateTextCheckingResults) { |
| 1119 // Verify that the SpellCheck class keeps the spelling marker added to a | 1119 // Verify that the SpellCheck class keeps the spelling marker added to a |
| 1120 // misspelled word "zz". | 1120 // misspelled word "zz". |
| 1121 { | 1121 { |
| 1122 string16 text = ASCIIToUTF16("zz"); | 1122 string16 text = ASCIIToUTF16("zz"); |
| 1123 std::vector<SpellCheckResult> spellcheck_results; | 1123 std::vector<SpellCheckResult> spellcheck_results; |
| 1124 spellcheck_results.push_back(SpellCheckResult( | 1124 spellcheck_results.push_back(SpellCheckResult( |
| 1125 SpellCheckResult::SPELLING, 0, 2, string16())); | 1125 SpellCheckResult::SPELLING, 0, 2, string16())); |
| 1126 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; | 1126 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1127 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1127 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
| 1128 0, | 1128 0, |
| 1129 text, | 1129 text, |
| 1130 spellcheck_results, | 1130 spellcheck_results, |
| 1131 &textcheck_results); | 1131 &textcheck_results); |
| 1132 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1132 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
| 1133 EXPECT_EQ(WebKit::WebTextDecorationTypeSpelling, | 1133 EXPECT_EQ(blink::WebTextDecorationTypeSpelling, |
| 1134 textcheck_results[0].decoration); | 1134 textcheck_results[0].decoration); |
| 1135 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1135 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
| 1136 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1136 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 // Verify that the SpellCheck class replaces the spelling marker added to a | 1139 // Verify that the SpellCheck class replaces the spelling marker added to a |
| 1140 // contextually-misspelled word "bean" with a grammar marker. | 1140 // contextually-misspelled word "bean" with a grammar marker. |
| 1141 { | 1141 { |
| 1142 string16 text = ASCIIToUTF16("I have bean to USA."); | 1142 string16 text = ASCIIToUTF16("I have bean to USA."); |
| 1143 std::vector<SpellCheckResult> spellcheck_results; | 1143 std::vector<SpellCheckResult> spellcheck_results; |
| 1144 spellcheck_results.push_back(SpellCheckResult( | 1144 spellcheck_results.push_back(SpellCheckResult( |
| 1145 SpellCheckResult::SPELLING, 7, 4, string16())); | 1145 SpellCheckResult::SPELLING, 7, 4, string16())); |
| 1146 WebKit::WebVector<WebKit::WebTextCheckingResult> textcheck_results; | 1146 blink::WebVector<blink::WebTextCheckingResult> textcheck_results; |
| 1147 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, | 1147 spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER, |
| 1148 0, | 1148 0, |
| 1149 text, | 1149 text, |
| 1150 spellcheck_results, | 1150 spellcheck_results, |
| 1151 &textcheck_results); | 1151 &textcheck_results); |
| 1152 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); | 1152 EXPECT_EQ(spellcheck_results.size(), textcheck_results.size()); |
| 1153 EXPECT_EQ(WebKit::WebTextDecorationTypeGrammar, | 1153 EXPECT_EQ(blink::WebTextDecorationTypeGrammar, |
| 1154 textcheck_results[0].decoration); | 1154 textcheck_results[0].decoration); |
| 1155 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); | 1155 EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location); |
| 1156 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); | 1156 EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length); |
| 1157 } | 1157 } |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 #endif | 1160 #endif |
| 1161 | 1161 |
| 1162 // Checks some words that should be present in all English dictionaries. | 1162 // Checks some words that should be present in all English dictionaries. |
| 1163 TEST_F(SpellCheckTest, EnglishWords) { | 1163 TEST_F(SpellCheckTest, EnglishWords) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 strlen(kTestCases[i].misspelled), | 1355 strlen(kTestCases[i].misspelled), |
| 1356 0, | 1356 0, |
| 1357 &misspelling_start, | 1357 &misspelling_start, |
| 1358 &misspelling_length, | 1358 &misspelling_length, |
| 1359 &suggestions)); | 1359 &suggestions)); |
| 1360 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); | 1360 EXPECT_GE(suggestions.size(), static_cast<size_t>(1)); |
| 1361 if (suggestions.size() > 0) | 1361 if (suggestions.size() > 0) |
| 1362 EXPECT_EQ(suggestions[0], ASCIIToUTF16(kTestCases[i].suggestion)); | 1362 EXPECT_EQ(suggestions[0], ASCIIToUTF16(kTestCases[i].suggestion)); |
| 1363 } | 1363 } |
| 1364 } | 1364 } |
| OLD | NEW |