• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef MockSpellCheck_h
32 #define MockSpellCheck_h
33 
34 #include "public/platform/WebNonCopyable.h"
35 #include "public/platform/WebString.h"
36 #include "public/platform/WebVector.h"
37 #include "public/web/WebTextCheckingResult.h"
38 #include <vector>
39 
40 namespace WebTestRunner {
41 
42 // A mock implementation of a spell-checker used for WebKit tests.
43 // This class only implements the minimal functionarities required by WebKit
44 // tests, i.e. this class just compares the given string with known misspelled
45 // words in webkit tests and mark them as missspelled.
46 // Even though this is sufficent for webkit tests, this class is not suitable
47 // for any other usages.
48 class MockSpellCheck : public blink::WebNonCopyable {
49 public:
50     static void fillSuggestionList(const blink::WebString& word, blink::WebVector<blink::WebString>* suggestions);
51 
52     MockSpellCheck();
53     ~MockSpellCheck();
54 
55     // Checks the spellings of the specified text.
56     // This function returns true if the text consists of valid words, and
57     // returns false if it includes invalid words.
58     // When the given text includes invalid words, this function sets the
59     // position of the first invalid word to misspelledOffset, and the length of
60     // the first invalid word to misspelledLength, respectively.
61     // For example, when the given text is "   zz zz", this function sets 3 to
62     // misspelledOffset and 2 to misspelledLength, respectively.
63     bool spellCheckWord(const blink::WebString& text, int* misspelledOffset, int* misspelledLength);
64 
65     // Checks whether the specified text can be spell checked immediately using
66     // the spell checker cache.
67     bool hasInCache(const blink::WebString& text);
68 
69     // Checks whether the specified text is a misspelling comprised of more
70     // than one word. If it is, append multiple results to the results vector.
71     bool isMultiWordMisspelling(const blink::WebString& text, std::vector<blink::WebTextCheckingResult>* results);
72 
73 private:
74     // Initialize the internal resources if we need to initialize it.
75     // Initializing this object may take long time. To prevent from hurting
76     // the performance of test_shell, we initialize this object when
77     // SpellCheckWord() is called for the first time.
78     // To be compliant with SpellCheck:InitializeIfNeeded(), this function
79     // returns true if this object is downloading a dictionary, otherwise
80     // it returns false.
81     bool initializeIfNeeded();
82 
83     // A table that consists of misspelled words.
84     std::vector<string16> m_misspelledWords;
85 
86     // A flag representing whether or not this object is initialized.
87     bool m_initialized;
88 };
89 
90 }
91 
92 #endif // MockSpellCheck_h
93