OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h" | |
6 | |
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" | |
12 | |
13 class MockSpellcheck: public SpellCheck { | |
14 }; | |
15 | |
16 FakeTextCheckingCompletion::FakeTextCheckingCompletion() | |
17 : completion_count_(0), | |
18 cancellation_count_(0) { | |
19 } | |
20 | |
21 FakeTextCheckingCompletion::~FakeTextCheckingCompletion() {} | |
22 | |
23 void FakeTextCheckingCompletion::didFinishCheckingText( | |
24 const blink::WebVector<blink::WebTextCheckingResult>& results) { | |
25 ++completion_count_; | |
26 } | |
27 | |
28 void FakeTextCheckingCompletion::didCancelCheckingText() { | |
29 ++completion_count_; | |
30 ++cancellation_count_; | |
31 } | |
32 | |
33 TestingSpellCheckProvider::TestingSpellCheckProvider() | |
34 : SpellCheckProvider(NULL, new MockSpellcheck), | |
35 spelling_service_call_count_(0) { | |
36 } | |
37 | |
38 TestingSpellCheckProvider::TestingSpellCheckProvider( | |
39 SpellCheck* spellcheck) | |
40 : SpellCheckProvider(nullptr, spellcheck), | |
41 spelling_service_call_count_(0) { | |
42 } | |
43 | |
44 TestingSpellCheckProvider::~TestingSpellCheckProvider() { | |
45 delete spellcheck_; | |
46 } | |
47 | |
48 bool TestingSpellCheckProvider::Send(IPC::Message* message) { | |
49 #if !defined(USE_BROWSER_SPELLCHECKER) | |
50 // Call our mock message handlers. | |
51 bool handled = true; | |
52 IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message) | |
53 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, | |
54 OnCallSpellingService) | |
55 IPC_MESSAGE_UNHANDLED(handled = false) | |
56 IPC_END_MESSAGE_MAP() | |
57 | |
58 if (handled) { | |
59 delete message; | |
60 return true; | |
61 } | |
62 #endif | |
63 | |
64 messages_.push_back(message); | |
65 return true; | |
66 } | |
67 | |
68 void TestingSpellCheckProvider::OnCallSpellingService(int route_id, | |
69 int identifier, | |
70 const base::string16& text, | |
71 const std::vector<SpellCheckMarker>& markers) { | |
72 #if defined (USE_BROWSER_SPELLCHECKER) | |
73 NOTREACHED(); | |
74 #else | |
75 ++spelling_service_call_count_; | |
76 blink::WebTextCheckingCompletion* completion = | |
77 text_check_completions_.Lookup(identifier); | |
78 if (!completion) { | |
79 ResetResult(); | |
80 return; | |
81 } | |
82 text_.assign(text); | |
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); | |
89 last_request_ = text; | |
90 last_results_ = results; | |
91 #endif | |
92 } | |
93 | |
94 void TestingSpellCheckProvider::ResetResult() { | |
95 text_.clear(); | |
96 } | |
97 | |
98 SpellCheckProviderTest::SpellCheckProviderTest() {} | |
99 SpellCheckProviderTest::~SpellCheckProviderTest() {} | |
100 | |
101 | |
OLD | NEW |