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