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
3 // found in the LICENSE file.
5 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h"
7 #include "base/stl_util.h"
8 #include "chrome/common/spellcheck_marker.h"
9 #include "chrome/common/spellcheck_messages.h"
10 #include "chrome/renderer/spellchecker/spellcheck.h"
11 #include "ipc/ipc_message_macros.h"
13 class MockSpellcheck
: public SpellCheck
{
16 FakeTextCheckingCompletion::FakeTextCheckingCompletion()
17 : completion_count_(0),
18 cancellation_count_(0) {
21 FakeTextCheckingCompletion::~FakeTextCheckingCompletion() {}
23 void FakeTextCheckingCompletion::didFinishCheckingText(
24 const blink::WebVector
<blink::WebTextCheckingResult
>& results
) {
28 void FakeTextCheckingCompletion::didCancelCheckingText() {
30 ++cancellation_count_
;
33 TestingSpellCheckProvider::TestingSpellCheckProvider()
34 : SpellCheckProvider(NULL
, new MockSpellcheck
),
35 spelling_service_call_count_(0) {
38 TestingSpellCheckProvider::TestingSpellCheckProvider(
39 SpellCheck
* spellcheck
)
40 : SpellCheckProvider(nullptr, spellcheck
),
41 spelling_service_call_count_(0) {
44 TestingSpellCheckProvider::~TestingSpellCheckProvider() {
48 bool TestingSpellCheckProvider::Send(IPC::Message
* message
) {
49 #if !defined(USE_BROWSER_SPELLCHECKER)
50 // Call our mock message handlers.
52 IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider
, *message
)
53 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService
,
54 OnCallSpellingService
)
55 IPC_MESSAGE_UNHANDLED(handled
= false)
64 messages_
.push_back(message
);
68 void TestingSpellCheckProvider::OnCallSpellingService(int route_id
,
70 const base::string16
& text
,
71 const std::vector
<SpellCheckMarker
>& markers
) {
72 #if defined (USE_BROWSER_SPELLCHECKER)
75 ++spelling_service_call_count_
;
76 blink::WebTextCheckingCompletion
* completion
=
77 text_check_completions_
.Lookup(identifier
);
83 text_check_completions_
.Remove(identifier
);
84 std::vector
<blink::WebTextCheckingResult
> results
;
85 results
.push_back(blink::WebTextCheckingResult(
86 blink::WebTextDecorationTypeSpelling
,
87 0, 5, blink::WebString("hello")));
88 completion
->didFinishCheckingText(results
);
90 last_results_
= results
;
94 void TestingSpellCheckProvider::ResetResult() {
98 SpellCheckProviderTest::SpellCheckProviderTest() {}
99 SpellCheckProviderTest::~SpellCheckProviderTest() {}