OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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 WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_ | |
6 #define WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/string16.h" | |
12 | |
13 // A mock implementation of a spell-checker used for WebKit tests. | |
14 // This class only implements the minimal functionarities required by WebKit | |
15 // tests, i.e. this class just compares the given string with known misspelled | |
16 // words in webkit tests and mark them as missspelled. | |
17 // Even though this is sufficent for webkit tests, this class is not suitable | |
18 // for any other usages. | |
19 class MockSpellCheck { | |
20 public: | |
21 MockSpellCheck(); | |
22 ~MockSpellCheck(); | |
23 | |
24 // Checks the spellings of the specified text. | |
25 // This function returns true if the text consists of valid words, and | |
26 // returns false if it includes invalid words. | |
27 // When the given text includes invalid words, this function sets the | |
28 // position of the first invalid word to misspelledOffset, and the length of | |
29 // the first invalid word to misspelledLength, respectively. | |
30 // For example, when the given text is " zz zz", this function sets 3 to | |
31 // misspelledOffset and 2 to misspelledLength, respectively. | |
32 bool SpellCheckWord(const base::string16& text, | |
33 int* misspelledOffset, | |
34 int* misspelledLength); | |
35 | |
36 // Emulates suggestions for misspelled words. | |
37 // The suggestions are pushed to |suggestions| parameters. | |
38 void FillSuggestions(const base::string16& word, | |
39 std::vector<base::string16>* suggestions); | |
40 private: | |
41 // Initialize the internal resources if we need to initialize it. | |
42 // Initializing this object may take long time. To prevent from hurting | |
43 // the performance of test_shell, we initialize this object when | |
44 // SpellCheckWord() is called for the first time. | |
45 // To be compliant with SpellCheck:InitializeIfNeeded(), this function | |
46 // returns true if this object is downloading a dictionary, otherwise | |
47 // it returns false. | |
48 bool InitializeIfNeeded(); | |
49 | |
50 // A table that consists of misspelled words. | |
51 std::map<base::string16, bool> misspelled_words_; | |
52 | |
53 // A flag representing whether or not this object is initialized. | |
54 bool initialized_; | |
55 }; | |
56 | |
57 #endif // WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_ | |
OLD | NEW |