Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / renderer / spellchecker / spellcheck_provider_test.cc
blobd28cd886abc180e8b9aa9f2c3216af52e258f68a
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 delete spellcheck_;
42 bool TestingSpellCheckProvider::Send(IPC::Message* message) {
43 #if !defined(OS_MACOSX)
44 // Call our mock message handlers.
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message)
47 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService,
48 OnCallSpellingService)
49 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP()
52 if (handled) {
53 delete message;
54 return true;
56 #endif
58 messages_.push_back(message);
59 return true;
62 void TestingSpellCheckProvider::OnCallSpellingService(int route_id,
63 int identifier,
64 const base::string16& text,
65 const std::vector<SpellCheckMarker>& markers) {
66 #if defined (OS_MACOSX)
67 NOTREACHED();
68 #else
69 ++spelling_service_call_count_;
70 blink::WebTextCheckingCompletion* completion =
71 text_check_completions_.Lookup(identifier);
72 if (!completion) {
73 ResetResult();
74 return;
76 text_.assign(text);
77 text_check_completions_.Remove(identifier);
78 std::vector<blink::WebTextCheckingResult> results;
79 results.push_back(blink::WebTextCheckingResult(
80 blink::WebTextDecorationTypeSpelling,
81 0, 5, blink::WebString("hello")));
82 completion->didFinishCheckingText(results);
83 last_request_ = text;
84 last_results_ = results;
85 #endif
88 void TestingSpellCheckProvider::ResetResult() {
89 text_.clear();
92 SpellCheckProviderTest::SpellCheckProviderTest() {}
93 SpellCheckProviderTest::~SpellCheckProviderTest() {}