| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ | 5 #ifndef COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ |
| 6 #define COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ | 6 #define COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/test_runner/mock_spell_check.h" | 12 #include "components/test_runner/mock_spell_check.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 #include "third_party/WebKit/public/platform/WebVector.h" | 14 #include "third_party/WebKit/public/platform/WebVector.h" |
| 15 #include "third_party/WebKit/public/web/WebSpellCheckClient.h" | 15 #include "third_party/WebKit/public/web/WebSpellCheckClient.h" |
| 16 #include "v8/include/v8.h" |
| 16 | 17 |
| 17 namespace blink { | 18 namespace blink { |
| 18 class WebTextCheckingCompletion; | 19 class WebTextCheckingCompletion; |
| 19 } // namespace blink | 20 } // namespace blink |
| 20 | 21 |
| 21 namespace test_runner { | 22 namespace test_runner { |
| 22 | 23 |
| 23 class TestRunner; | 24 class TestRunner; |
| 24 class WebTestDelegate; | 25 class WebTestDelegate; |
| 25 | 26 |
| 26 class SpellCheckClient : public blink::WebSpellCheckClient { | 27 class SpellCheckClient : public blink::WebSpellCheckClient { |
| 27 public: | 28 public: |
| 28 explicit SpellCheckClient(TestRunner* test_runner); | 29 explicit SpellCheckClient(TestRunner* test_runner); |
| 29 virtual ~SpellCheckClient(); | 30 virtual ~SpellCheckClient(); |
| 30 | 31 |
| 31 void SetDelegate(WebTestDelegate* delegate); | 32 void SetDelegate(WebTestDelegate* delegate); |
| 32 void SetEnabled(bool enabled); | 33 void SetEnabled(bool enabled); |
| 33 | 34 |
| 35 // Sets a callback that will be invoked after each request is revoled. |
| 36 void SetSpellCheckResolvedCallback(v8::Local<v8::Function> callback); |
| 37 |
| 38 void Reset(); |
| 39 |
| 34 // blink::WebSpellCheckClient implementation. | 40 // blink::WebSpellCheckClient implementation. |
| 35 void spellCheck( | 41 void spellCheck( |
| 36 const blink::WebString& text, | 42 const blink::WebString& text, |
| 37 int& offset, | 43 int& offset, |
| 38 int& length, | 44 int& length, |
| 39 blink::WebVector<blink::WebString>* optional_suggestions) override; | 45 blink::WebVector<blink::WebString>* optional_suggestions) override; |
| 40 void requestCheckingOfText( | 46 void requestCheckingOfText( |
| 41 const blink::WebString& text, | 47 const blink::WebString& text, |
| 42 const blink::WebVector<uint32_t>& markers, | 48 const blink::WebVector<uint32_t>& markers, |
| 43 const blink::WebVector<unsigned>& marker_offsets, | 49 const blink::WebVector<unsigned>& marker_offsets, |
| 44 blink::WebTextCheckingCompletion* completion) override; | 50 blink::WebTextCheckingCompletion* completion) override; |
| 45 void cancelAllPendingRequests() override; | 51 void cancelAllPendingRequests() override; |
| 46 | 52 |
| 47 private: | 53 private: |
| 48 void FinishLastTextCheck(); | 54 void FinishLastTextCheck(); |
| 49 | 55 |
| 56 void RequestResolved(); |
| 57 |
| 50 // Do not perform any checking when |enabled_ == false|. | 58 // Do not perform any checking when |enabled_ == false|. |
| 51 // Tests related to spell checking should enable it manually. | 59 // Tests related to spell checking should enable it manually. |
| 52 bool enabled_ = false; | 60 bool enabled_ = false; |
| 53 | 61 |
| 54 // The mock spellchecker used in spellCheck(). | 62 // The mock spellchecker used in spellCheck(). |
| 55 MockSpellCheck spell_check_; | 63 MockSpellCheck spell_check_; |
| 56 | 64 |
| 57 blink::WebString last_requested_text_check_string_; | 65 blink::WebString last_requested_text_check_string_; |
| 58 blink::WebTextCheckingCompletion* last_requested_text_checking_completion_; | 66 blink::WebTextCheckingCompletion* last_requested_text_checking_completion_; |
| 59 | 67 |
| 68 v8::Persistent<v8::Function> resolved_callback_; |
| 69 |
| 60 TestRunner* test_runner_; | 70 TestRunner* test_runner_; |
| 61 WebTestDelegate* delegate_; | 71 WebTestDelegate* delegate_; |
| 62 | 72 |
| 63 base::WeakPtrFactory<SpellCheckClient> weak_factory_; | 73 base::WeakPtrFactory<SpellCheckClient> weak_factory_; |
| 64 | 74 |
| 65 DISALLOW_COPY_AND_ASSIGN(SpellCheckClient); | 75 DISALLOW_COPY_AND_ASSIGN(SpellCheckClient); |
| 66 }; | 76 }; |
| 67 | 77 |
| 68 } // namespace test_runner | 78 } // namespace test_runner |
| 69 | 79 |
| 70 #endif // COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ | 80 #endif // COMPONENTS_TEST_RUNNER_SPELL_CHECK_CLIENT_H_ |
| OLD | NEW |