| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/test_runner/mock_spell_check.h" | 5 #include "content/shell/test_runner/mock_spell_check.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "components/test_runner/test_common.h" | 13 #include "content/shell/test_runner/test_common.h" |
| 14 | 14 |
| 15 namespace test_runner { | 15 namespace test_runner { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void Append(blink::WebVector<blink::WebString>* data, | 19 void Append(blink::WebVector<blink::WebString>* data, |
| 20 const blink::WebString& item) { | 20 const blink::WebString& item) { |
| 21 blink::WebVector<blink::WebString> result(data->size() + 1); | 21 blink::WebVector<blink::WebString> result(data->size() + 1); |
| 22 for (size_t i = 0; i < data->size(); ++i) | 22 for (size_t i = 0; i < data->size(); ++i) |
| 23 result[i] = (*data)[i]; | 23 result[i] = (*data)[i]; |
| 24 result[data->size()] = item; | 24 result[data->size()] = item; |
| 25 data->swap(result); | 25 data->swap(result); |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 MockSpellCheck::MockSpellCheck() : initialized_(false) { | 30 MockSpellCheck::MockSpellCheck() : initialized_(false) {} |
| 31 } | |
| 32 | 31 |
| 33 MockSpellCheck::~MockSpellCheck() { | 32 MockSpellCheck::~MockSpellCheck() {} |
| 34 } | |
| 35 | 33 |
| 36 bool MockSpellCheck::SpellCheckWord(const blink::WebString& text, | 34 bool MockSpellCheck::SpellCheckWord(const blink::WebString& text, |
| 37 int* misspelled_offset, | 35 int* misspelled_offset, |
| 38 int* misspelled_length) { | 36 int* misspelled_length) { |
| 39 DCHECK(misspelled_offset); | 37 DCHECK(misspelled_offset); |
| 40 DCHECK(misspelled_length); | 38 DCHECK(misspelled_length); |
| 41 | 39 |
| 42 // Initialize this spellchecker. | 40 // Initialize this spellchecker. |
| 43 InitializeIfNeeded(); | 41 InitializeIfNeeded(); |
| 44 | 42 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 143 |
| 146 // Create a table that consists of misspelled words used in WebKit layout | 144 // Create a table that consists of misspelled words used in WebKit layout |
| 147 // tests. | 145 // tests. |
| 148 // Since WebKit layout tests don't have so many misspelled words as | 146 // Since WebKit layout tests don't have so many misspelled words as |
| 149 // well-spelled words, it is easier to compare the given word with misspelled | 147 // well-spelled words, it is easier to compare the given word with misspelled |
| 150 // ones than to compare with well-spelled ones. | 148 // ones than to compare with well-spelled ones. |
| 151 static const char* misspelled_words[] = { | 149 static const char* misspelled_words[] = { |
| 152 // These words are known misspelled words in webkit tests. | 150 // These words are known misspelled words in webkit tests. |
| 153 // If there are other misspelled words in webkit tests, please add them in | 151 // If there are other misspelled words in webkit tests, please add them in |
| 154 // this array. | 152 // this array. |
| 155 "foo", "Foo", "baz", "fo", "LibertyF", | 153 "foo", "Foo", "baz", "fo", "LibertyF", "chello", "xxxtestxxx", "XXxxx", |
| 156 "chello", "xxxtestxxx", "XXxxx", "Textx", "blockquoted", | 154 "Textx", "blockquoted", "asd", "Lorem", "Nunc", "Curabitur", "eu", "adlj", |
| 157 "asd", "Lorem", "Nunc", "Curabitur", "eu", | 155 "adaasj", "sdklj", "jlkds", "jsaada", "jlda", "zz", "contentEditable", |
| 158 "adlj", "adaasj", "sdklj", "jlkds", "jsaada", | |
| 159 "jlda", "zz", "contentEditable", | |
| 160 // The following words are used by unit tests. | 156 // The following words are used by unit tests. |
| 161 "ifmmp", "qwertyuiopasd", "qwertyuiopasdf", "upper case", "wellcome"}; | 157 "ifmmp", "qwertyuiopasd", "qwertyuiopasdf", "upper case", "wellcome"}; |
| 162 | 158 |
| 163 misspelled_words_.clear(); | 159 misspelled_words_.clear(); |
| 164 for (size_t i = 0; i < arraysize(misspelled_words); ++i) | 160 for (size_t i = 0; i < arraysize(misspelled_words); ++i) |
| 165 misspelled_words_.push_back( | 161 misspelled_words_.push_back( |
| 166 base::string16(misspelled_words[i], | 162 base::string16(misspelled_words[i], |
| 167 misspelled_words[i] + strlen(misspelled_words[i]))); | 163 misspelled_words[i] + strlen(misspelled_words[i]))); |
| 168 | 164 |
| 169 // Mark as initialized to prevent this object from being initialized twice | 165 // Mark as initialized to prevent this object from being initialized twice |
| 170 // or more. | 166 // or more. |
| 171 initialized_ = true; | 167 initialized_ = true; |
| 172 | 168 |
| 173 // Since this MockSpellCheck class doesn't download dictionaries, this | 169 // Since this MockSpellCheck class doesn't download dictionaries, this |
| 174 // function always returns false. | 170 // function always returns false. |
| 175 return false; | 171 return false; |
| 176 } | 172 } |
| 177 | 173 |
| 178 } // namespace test_runner | 174 } // namespace test_runner |
| OLD | NEW |