| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/mock_render_thread.h" | 5 #include "chrome/renderer/mock_render_thread.h" |
| 6 | 6 |
| 7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "ipc/ipc_message_utils.h" | 9 #include "ipc/ipc_message_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 EXPECT_EQ(routing_id_, routing_id); | 27 EXPECT_EQ(routing_id_, routing_id); |
| 28 widget_ = listener; | 28 widget_ = listener; |
| 29 } | 29 } |
| 30 | 30 |
| 31 // Called by the Widget. The routing id must match the routing id of AddRoute. | 31 // Called by the Widget. The routing id must match the routing id of AddRoute. |
| 32 void MockRenderThread::RemoveRoute(int32 routing_id) { | 32 void MockRenderThread::RemoveRoute(int32 routing_id) { |
| 33 EXPECT_EQ(routing_id_, routing_id); | 33 EXPECT_EQ(routing_id_, routing_id); |
| 34 widget_ = NULL; | 34 widget_ = NULL; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Called by, for example, RenderView::Init(), when adding a new message filter |
| 38 void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 39 filter->OnFilterAdded(&sink()); |
| 40 } |
| 41 |
| 42 // Called when the filter is removed |
| 43 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 44 filter->OnFilterRemoved(); |
| 45 } |
| 46 |
| 37 // Called by the Widget. Used to send messages to the browser. | 47 // Called by the Widget. Used to send messages to the browser. |
| 38 // We short-circuit the mechanim and handle the messages right here on this | 48 // We short-circuit the mechanim and handle the messages right here on this |
| 39 // class. | 49 // class. |
| 40 bool MockRenderThread::Send(IPC::Message* msg) { | 50 bool MockRenderThread::Send(IPC::Message* msg) { |
| 41 // We need to simulate a synchronous channel, thus we are going to receive | 51 // We need to simulate a synchronous channel, thus we are going to receive |
| 42 // through this function messages, messages with reply and reply messages. | 52 // through this function messages, messages with reply and reply messages. |
| 43 // We can only handle one synchronous message at a time. | 53 // We can only handle one synchronous message at a time. |
| 44 if (msg->is_reply()) { | 54 if (msg->is_reply()) { |
| 45 if (reply_deserializer_.get()) { | 55 if (reply_deserializer_.get()) { |
| 46 reply_deserializer_->SerializeOutputParameters(*msg); | 56 reply_deserializer_->SerializeOutputParameters(*msg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 return true; | 69 return true; |
| 60 } | 70 } |
| 61 | 71 |
| 62 void MockRenderThread::SendCloseMessage() { | 72 void MockRenderThread::SendCloseMessage() { |
| 63 ViewMsg_Close msg(routing_id_); | 73 ViewMsg_Close msg(routing_id_); |
| 64 widget_->OnMessageReceived(msg); | 74 widget_->OnMessageReceived(msg); |
| 65 } | 75 } |
| 66 | 76 |
| 67 void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { | 77 void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { |
| 68 // Save the message in the sink. | 78 // Save the message in the sink. |
| 69 sink_.OnMessageReceived(msg); | 79 sink_.Send(const_cast<IPC::Message*>(&msg)); |
| 70 | 80 |
| 71 // Some messages we do special handling. | 81 // Some messages we do special handling. |
| 72 bool handled = true; | 82 bool handled = true; |
| 73 bool msg_is_ok = true; | 83 bool msg_is_ok = true; |
| 74 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) | 84 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) |
| 75 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); | 85 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); |
| 76 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, | 86 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, |
| 77 OnMsgOpenChannelToExtension); | 87 OnMsgOpenChannelToExtension); |
| 78 #if defined(OS_WIN) || defined(OS_MACOSX) | 88 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 79 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, | 89 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 163 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
| 154 if (printer_.get()) | 164 if (printer_.get()) |
| 155 printer_->SetPrintedPagesCount(cookie, number_pages); | 165 printer_->SetPrintedPagesCount(cookie, number_pages); |
| 156 } | 166 } |
| 157 | 167 |
| 158 void MockRenderThread::OnDidPrintPage( | 168 void MockRenderThread::OnDidPrintPage( |
| 159 const ViewHostMsg_DidPrintPage_Params& params) { | 169 const ViewHostMsg_DidPrintPage_Params& params) { |
| 160 if (printer_.get()) | 170 if (printer_.get()) |
| 161 printer_->PrintPage(params); | 171 printer_->PrintPage(params); |
| 162 } | 172 } |
| OLD | NEW |