OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_SPELL_CHECK_H_ |
| 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_SPELL_CHECK_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/public/platform/WebVector.h" |
| 13 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // A mock implementation of a spell-checker used for WebKit tests. |
| 18 // This class only implements the minimal functionarities required by WebKit |
| 19 // tests, i.e. this class just compares the given string with known misspelled |
| 20 // words in webkit tests and mark them as missspelled. |
| 21 // Even though this is sufficent for webkit tests, this class is not suitable |
| 22 // for any other usages. |
| 23 class MockSpellCheck { |
| 24 public: |
| 25 static void FillSuggestionList( |
| 26 const blink::WebString& word, |
| 27 blink::WebVector<blink::WebString>* suggestions); |
| 28 |
| 29 MockSpellCheck(); |
| 30 ~MockSpellCheck(); |
| 31 |
| 32 // Checks the spellings of the specified text. |
| 33 // This function returns true if the text consists of valid words, and |
| 34 // returns false if it includes invalid words. |
| 35 // When the given text includes invalid words, this function sets the |
| 36 // position of the first invalid word to misspelledOffset, and the length of |
| 37 // the first invalid word to misspelledLength, respectively. |
| 38 // For example, when the given text is " zz zz", this function sets 3 to |
| 39 // misspelledOffset and 2 to misspelledLength, respectively. |
| 40 bool SpellCheckWord(const blink::WebString& text, |
| 41 int* misspelled_offset, |
| 42 int* misspelled_length); |
| 43 |
| 44 // Checks whether the specified text can be spell checked immediately using |
| 45 // the spell checker cache. |
| 46 bool HasInCache(const blink::WebString& text); |
| 47 |
| 48 // Checks whether the specified text is a misspelling comprised of more |
| 49 // than one word. If it is, append multiple results to the results vector. |
| 50 bool IsMultiWordMisspelling( |
| 51 const blink::WebString& text, |
| 52 std::vector<blink::WebTextCheckingResult>* results); |
| 53 |
| 54 private: |
| 55 // Initialize the internal resources if we need to initialize it. |
| 56 // Initializing this object may take long time. To prevent from hurting |
| 57 // the performance of test_shell, we initialize this object when |
| 58 // SpellCheckWord() is called for the first time. |
| 59 // To be compliant with SpellCheck:InitializeIfNeeded(), this function |
| 60 // returns true if this object is downloading a dictionary, otherwise |
| 61 // it returns false. |
| 62 bool InitializeIfNeeded(); |
| 63 |
| 64 // A table that consists of misspelled words. |
| 65 std::vector<base::string16> misspelled_words_; |
| 66 |
| 67 // A flag representing whether or not this object is initialized. |
| 68 bool initialized_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(MockSpellCheck); |
| 71 }; |
| 72 |
| 73 } // namespace content |
| 74 |
| 75 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_SPELL_CHECK_H_ |
OLD | NEW |