| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ | 5 #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ |
| 6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ | 6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <memory> |
| 9 | |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 13 #include "components/spellcheck/renderer/spellcheck_provider.h" | 12 #include "components/spellcheck/renderer/spellcheck_provider.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
| 16 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 16 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
| 17 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 17 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
| 18 | 18 |
| 19 namespace base { |
| 20 class MessageLoop; |
| 21 } |
| 22 |
| 19 namespace IPC { | 23 namespace IPC { |
| 20 class Message; | 24 class Message; |
| 21 } | 25 } |
| 22 | 26 |
| 23 // A fake completion object for verification. | 27 // A fake completion object for verification. |
| 24 class FakeTextCheckingCompletion : public blink::WebTextCheckingCompletion { | 28 class FakeTextCheckingCompletion : public blink::WebTextCheckingCompletion { |
| 25 public: | 29 public: |
| 26 FakeTextCheckingCompletion(); | 30 FakeTextCheckingCompletion(); |
| 27 ~FakeTextCheckingCompletion(); | 31 ~FakeTextCheckingCompletion(); |
| 28 | 32 |
| 29 void DidFinishCheckingText( | 33 void DidFinishCheckingText( |
| 30 const blink::WebVector<blink::WebTextCheckingResult>& results) override; | 34 const blink::WebVector<blink::WebTextCheckingResult>& results) override; |
| 31 void DidCancelCheckingText() override; | 35 void DidCancelCheckingText() override; |
| 32 | 36 |
| 33 size_t completion_count_; | 37 size_t completion_count_; |
| 34 size_t cancellation_count_; | 38 size_t cancellation_count_; |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 // Faked test target, which stores sent message for verification. | 41 // Faked test target, which stores sent message for verification. |
| 38 class TestingSpellCheckProvider : public SpellCheckProvider { | 42 class TestingSpellCheckProvider : public SpellCheckProvider, |
| 43 public spellcheck::mojom::SpellCheckHost { |
| 39 public: | 44 public: |
| 40 TestingSpellCheckProvider(); | 45 TestingSpellCheckProvider(); |
| 41 // Takes ownership of |spellcheck|. | 46 // Takes ownership of |spellcheck|. |
| 42 explicit TestingSpellCheckProvider(SpellCheck* spellcheck); | 47 explicit TestingSpellCheckProvider(SpellCheck* spellcheck); |
| 43 | 48 |
| 44 ~TestingSpellCheckProvider() override; | 49 ~TestingSpellCheckProvider() override; |
| 50 |
| 51 void RequestTextChecking(const base::string16& text, |
| 52 blink::WebTextCheckingCompletion* completion); |
| 53 |
| 45 bool Send(IPC::Message* message) override; | 54 bool Send(IPC::Message* message) override; |
| 46 void OnCallSpellingService(int route_id, | 55 void OnCallSpellingService(const base::string16& text); |
| 47 int identifier, | |
| 48 const base::string16& text); | |
| 49 void ResetResult(); | 56 void ResetResult(); |
| 50 | 57 |
| 51 void SetLastResults( | 58 void SetLastResults( |
| 52 const base::string16 last_request, | 59 const base::string16 last_request, |
| 53 blink::WebVector<blink::WebTextCheckingResult>& last_results); | 60 blink::WebVector<blink::WebTextCheckingResult>& last_results); |
| 54 bool SatisfyRequestFromCache(const base::string16& text, | 61 bool SatisfyRequestFromCache(const base::string16& text, |
| 55 blink::WebTextCheckingCompletion* completion); | 62 blink::WebTextCheckingCompletion* completion); |
| 56 | 63 |
| 57 base::string16 text_; | 64 base::string16 text_; |
| 58 std::vector<std::unique_ptr<IPC::Message>> messages_; | 65 std::vector<std::unique_ptr<IPC::Message>> messages_; |
| 59 size_t spelling_service_call_count_; | 66 size_t spelling_service_call_count_; |
| 67 |
| 68 private: |
| 69 // spellcheck::mojom::SpellCheckerHost: |
| 70 void RequestDictionary() override; |
| 71 void NotifyChecked(const base::string16& word, bool misspelled) override; |
| 72 void CallSpellingService( |
| 73 const base::string16& text, |
| 74 const CallSpellingServiceCallback& callback) override; |
| 75 |
| 76 // Message loop (if needed) to deliver the SpellCheckHost request flow. |
| 77 std::unique_ptr<base::MessageLoop> loop_; |
| 78 |
| 79 // Binding to receive the SpellCheckHost request flow. |
| 80 mojo::Binding<spellcheck::mojom::SpellCheckHost> binding_; |
| 60 }; | 81 }; |
| 61 | 82 |
| 62 // SpellCheckProvider test fixture. | 83 // SpellCheckProvider test fixture. |
| 63 class SpellCheckProviderTest : public testing::Test { | 84 class SpellCheckProviderTest : public testing::Test { |
| 64 public: | 85 public: |
| 65 SpellCheckProviderTest(); | 86 SpellCheckProviderTest(); |
| 66 ~SpellCheckProviderTest() override; | 87 ~SpellCheckProviderTest() override; |
| 67 | 88 |
| 68 protected: | 89 protected: |
| 69 TestingSpellCheckProvider provider_; | 90 TestingSpellCheckProvider provider_; |
| 70 }; | 91 }; |
| 71 | 92 |
| 72 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ | 93 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_TEST_H_ |
| OLD | NEW |