[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / MockSpellCheck.h
blob86918daedc9bc13108c3a5b95e2b3aff39209e19
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.
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKSPELLCHECK_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKSPELLCHECK_H_
8 #include <vector>
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"
15 namespace WebTestRunner {
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(const blink::WebString& word, blink::WebVector<blink::WebString>* suggestions);
27 MockSpellCheck();
28 ~MockSpellCheck();
30 // Checks the spellings of the specified text.
31 // This function returns true if the text consists of valid words, and
32 // returns false if it includes invalid words.
33 // When the given text includes invalid words, this function sets the
34 // position of the first invalid word to misspelledOffset, and the length of
35 // the first invalid word to misspelledLength, respectively.
36 // For example, when the given text is " zz zz", this function sets 3 to
37 // misspelledOffset and 2 to misspelledLength, respectively.
38 bool spellCheckWord(const blink::WebString& text, int* misspelledOffset, int* misspelledLength);
40 // Checks whether the specified text can be spell checked immediately using
41 // the spell checker cache.
42 bool hasInCache(const blink::WebString& text);
44 // Checks whether the specified text is a misspelling comprised of more
45 // than one word. If it is, append multiple results to the results vector.
46 bool isMultiWordMisspelling(const blink::WebString& text, std::vector<blink::WebTextCheckingResult>* results);
48 private:
49 // Initialize the internal resources if we need to initialize it.
50 // Initializing this object may take long time. To prevent from hurting
51 // the performance of test_shell, we initialize this object when
52 // SpellCheckWord() is called for the first time.
53 // To be compliant with SpellCheck:InitializeIfNeeded(), this function
54 // returns true if this object is downloading a dictionary, otherwise
55 // it returns false.
56 bool initializeIfNeeded();
58 // A table that consists of misspelled words.
59 std::vector<base::string16> m_misspelledWords;
61 // A flag representing whether or not this object is initialized.
62 bool m_initialized;
64 DISALLOW_COPY_AND_ASSIGN(MockSpellCheck);
69 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKSPELLCHECK_H_