| 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 | |
| 47 // Called by the Widget. Used to send messages to the browser. | 37 // Called by the Widget. Used to send messages to the browser. |
| 48 // We short-circuit the mechanim and handle the messages right here on this | 38 // We short-circuit the mechanim and handle the messages right here on this |
| 49 // class. | 39 // class. |
| 50 bool MockRenderThread::Send(IPC::Message* msg) { | 40 bool MockRenderThread::Send(IPC::Message* msg) { |
| 51 // We need to simulate a synchronous channel, thus we are going to receive | 41 // We need to simulate a synchronous channel, thus we are going to receive |
| 52 // through this function messages, messages with reply and reply messages. | 42 // through this function messages, messages with reply and reply messages. |
| 53 // We can only handle one synchronous message at a time. | 43 // We can only handle one synchronous message at a time. |
| 54 if (msg->is_reply()) { | 44 if (msg->is_reply()) { |
| 55 if (reply_deserializer_.get()) { | 45 if (reply_deserializer_.get()) { |
| 56 reply_deserializer_->SerializeOutputParameters(*msg); | 46 reply_deserializer_->SerializeOutputParameters(*msg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 69 return true; | 59 return true; |
| 70 } | 60 } |
| 71 | 61 |
| 72 void MockRenderThread::SendCloseMessage() { | 62 void MockRenderThread::SendCloseMessage() { |
| 73 ViewMsg_Close msg(routing_id_); | 63 ViewMsg_Close msg(routing_id_); |
| 74 widget_->OnMessageReceived(msg); | 64 widget_->OnMessageReceived(msg); |
| 75 } | 65 } |
| 76 | 66 |
| 77 void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { | 67 void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { |
| 78 // Save the message in the sink. | 68 // Save the message in the sink. |
| 79 sink_.Send(const_cast<IPC::Message*>(&msg)); | 69 sink_.OnMessageReceived(msg); |
| 80 | 70 |
| 81 // Some messages we do special handling. | 71 // Some messages we do special handling. |
| 82 bool handled = true; | 72 bool handled = true; |
| 83 bool msg_is_ok = true; | 73 bool msg_is_ok = true; |
| 84 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) | 74 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) |
| 85 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); | 75 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); |
| 86 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, | 76 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, |
| 87 OnMsgOpenChannelToExtension); | 77 OnMsgOpenChannelToExtension); |
| 88 #if defined(OS_WIN) || defined(OS_MACOSX) | 78 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 89 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, | 79 IPC_MESSAGE_HANDLER(ViewHostMsg_GetDefaultPrintSettings, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 153 void MockRenderThread::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
| 164 if (printer_.get()) | 154 if (printer_.get()) |
| 165 printer_->SetPrintedPagesCount(cookie, number_pages); | 155 printer_->SetPrintedPagesCount(cookie, number_pages); |
| 166 } | 156 } |
| 167 | 157 |
| 168 void MockRenderThread::OnDidPrintPage( | 158 void MockRenderThread::OnDidPrintPage( |
| 169 const ViewHostMsg_DidPrintPage_Params& params) { | 159 const ViewHostMsg_DidPrintPage_Params& params) { |
| 170 if (printer_.get()) | 160 if (printer_.get()) |
| 171 printer_->PrintPage(params); | 161 printer_->PrintPage(params); |
| 172 } | 162 } |
| OLD | NEW |