| 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 #include "components/spellcheck/renderer/spellcheck_provider_test.h" | 5 #include "components/spellcheck/renderer/spellcheck_provider_test.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "components/spellcheck/common/spellcheck_marker.h" | 8 #include "components/spellcheck/common/spellcheck_marker.h" |
| 9 #include "components/spellcheck/common/spellcheck_messages.h" | 9 #include "components/spellcheck/common/spellcheck_messages.h" |
| 10 #include "components/spellcheck/renderer/spellcheck.h" | 10 #include "components/spellcheck/renderer/spellcheck.h" |
| 11 #include "components/spellcheck/spellcheck_build_features.h" |
| 11 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 12 | 13 |
| 13 class MockSpellcheck: public SpellCheck { | 14 class MockSpellcheck: public SpellCheck { |
| 14 }; | 15 }; |
| 15 | 16 |
| 16 FakeTextCheckingCompletion::FakeTextCheckingCompletion() | 17 FakeTextCheckingCompletion::FakeTextCheckingCompletion() |
| 17 : completion_count_(0), | 18 : completion_count_(0), |
| 18 cancellation_count_(0) { | 19 cancellation_count_(0) { |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 SpellCheck* spellcheck) | 40 SpellCheck* spellcheck) |
| 40 : SpellCheckProvider(nullptr, spellcheck), | 41 : SpellCheckProvider(nullptr, spellcheck), |
| 41 spelling_service_call_count_(0) { | 42 spelling_service_call_count_(0) { |
| 42 } | 43 } |
| 43 | 44 |
| 44 TestingSpellCheckProvider::~TestingSpellCheckProvider() { | 45 TestingSpellCheckProvider::~TestingSpellCheckProvider() { |
| 45 delete spellcheck_; | 46 delete spellcheck_; |
| 46 } | 47 } |
| 47 | 48 |
| 48 bool TestingSpellCheckProvider::Send(IPC::Message* message) { | 49 bool TestingSpellCheckProvider::Send(IPC::Message* message) { |
| 49 #if !defined(USE_BROWSER_SPELLCHECKER) | 50 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 50 // Call our mock message handlers. | 51 // Call our mock message handlers. |
| 51 bool handled = true; | 52 bool handled = true; |
| 52 IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message) | 53 IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message) |
| 53 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, | 54 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, |
| 54 OnCallSpellingService) | 55 OnCallSpellingService) |
| 55 IPC_MESSAGE_UNHANDLED(handled = false) | 56 IPC_MESSAGE_UNHANDLED(handled = false) |
| 56 IPC_END_MESSAGE_MAP() | 57 IPC_END_MESSAGE_MAP() |
| 57 | 58 |
| 58 if (handled) { | 59 if (handled) { |
| 59 delete message; | 60 delete message; |
| 60 return true; | 61 return true; |
| 61 } | 62 } |
| 62 #endif | 63 #endif |
| 63 | 64 |
| 64 messages_.push_back(message); | 65 messages_.push_back(message); |
| 65 return true; | 66 return true; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void TestingSpellCheckProvider::OnCallSpellingService(int route_id, | 69 void TestingSpellCheckProvider::OnCallSpellingService(int route_id, |
| 69 int identifier, | 70 int identifier, |
| 70 const base::string16& text, | 71 const base::string16& text, |
| 71 const std::vector<SpellCheckMarker>& markers) { | 72 const std::vector<SpellCheckMarker>& markers) { |
| 72 #if defined (USE_BROWSER_SPELLCHECKER) | 73 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 73 NOTREACHED(); | 74 NOTREACHED(); |
| 74 #else | 75 #else |
| 75 ++spelling_service_call_count_; | 76 ++spelling_service_call_count_; |
| 76 blink::WebTextCheckingCompletion* completion = | 77 blink::WebTextCheckingCompletion* completion = |
| 77 text_check_completions_.Lookup(identifier); | 78 text_check_completions_.Lookup(identifier); |
| 78 if (!completion) { | 79 if (!completion) { |
| 79 ResetResult(); | 80 ResetResult(); |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 text_.assign(text); | 83 text_.assign(text); |
| 83 text_check_completions_.Remove(identifier); | 84 text_check_completions_.Remove(identifier); |
| 84 std::vector<blink::WebTextCheckingResult> results; | 85 std::vector<blink::WebTextCheckingResult> results; |
| 85 results.push_back(blink::WebTextCheckingResult( | 86 results.push_back(blink::WebTextCheckingResult( |
| 86 blink::WebTextDecorationTypeSpelling, | 87 blink::WebTextDecorationTypeSpelling, |
| 87 0, 5, blink::WebString("hello"))); | 88 0, 5, blink::WebString("hello"))); |
| 88 completion->didFinishCheckingText(results); | 89 completion->didFinishCheckingText(results); |
| 89 last_request_ = text; | 90 last_request_ = text; |
| 90 last_results_ = results; | 91 last_results_ = results; |
| 91 #endif | 92 #endif |
| 92 } | 93 } |
| 93 | 94 |
| 94 void TestingSpellCheckProvider::ResetResult() { | 95 void TestingSpellCheckProvider::ResetResult() { |
| 95 text_.clear(); | 96 text_.clear(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 SpellCheckProviderTest::SpellCheckProviderTest() {} | 99 SpellCheckProviderTest::SpellCheckProviderTest() {} |
| 99 SpellCheckProviderTest::~SpellCheckProviderTest() {} | 100 SpellCheckProviderTest::~SpellCheckProviderTest() {} |
| 100 | 101 |
| OLD | NEW |