Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / renderer / spellchecker / spellcheck_provider_test.cc
blobefb175f94dfee0d97fab2389b8862a6570ff9d6b
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) {
25 ++completion_count_;
28 void FakeTextCheckingCompletion::didCancelCheckingText() {
29 ++completion_count_;
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() {
45 delete spellcheck_;
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()
58 if (handled) {
59 delete message;
60 return true;
62 #endif
64 messages_.push_back(message);
65 return true;
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;
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
94 void TestingSpellCheckProvider::ResetResult() {
95 text_.clear();
98 SpellCheckProviderTest::SpellCheckProviderTest() {}
99 SpellCheckProviderTest::~SpellCheckProviderTest() {}