| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
| 12 #include "chrome/common/print_messages.h" | 12 #include "chrome/common/print_messages.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "ipc/ipc_message_utils.h" | 16 #include "ipc/ipc_message_utils.h" |
| 17 #include "ipc/ipc_sync_message.h" | 17 #include "ipc/ipc_sync_message.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 MockRenderThread::MockRenderThread() | 20 MockRenderThread::MockRenderThread() |
| 21 : routing_id_(0), | 21 : routing_id_(0), |
| 22 opener_id_(0), | 22 opener_id_(0), |
| 23 widget_(NULL), | 23 widget_(NULL), |
| 24 reply_deserializer_(NULL), | 24 reply_deserializer_(NULL), |
| 25 printer_(new MockPrinter), | 25 printer_(new MockPrinter), |
| 26 is_extension_process_(false), | |
| 27 print_dialog_user_response_(true) { | 26 print_dialog_user_response_(true) { |
| 28 } | 27 } |
| 29 | 28 |
| 30 MockRenderThread::~MockRenderThread() { | 29 MockRenderThread::~MockRenderThread() { |
| 31 } | 30 } |
| 32 | 31 |
| 33 const ExtensionSet* MockRenderThread::GetExtensions() const { | |
| 34 return &extensions_; | |
| 35 } | |
| 36 | |
| 37 // Called by the Widget. The routing_id must match the routing id assigned | 32 // Called by the Widget. The routing_id must match the routing id assigned |
| 38 // to the Widget in reply to ViewHostMsg_CreateWidget message. | 33 // to the Widget in reply to ViewHostMsg_CreateWidget message. |
| 39 void MockRenderThread::AddRoute(int32 routing_id, | 34 void MockRenderThread::AddRoute(int32 routing_id, |
| 40 IPC::Channel::Listener* listener) { | 35 IPC::Channel::Listener* listener) { |
| 41 EXPECT_EQ(routing_id_, routing_id); | 36 EXPECT_EQ(routing_id_, routing_id); |
| 42 widget_ = listener; | 37 widget_ = listener; |
| 43 } | 38 } |
| 44 | 39 |
| 45 // Called by the Widget. The routing id must match the routing id of AddRoute. | 40 // Called by the Widget. The routing id must match the routing id of AddRoute. |
| 46 void MockRenderThread::RemoveRoute(int32 routing_id) { | 41 void MockRenderThread::RemoveRoute(int32 routing_id) { |
| 47 EXPECT_EQ(routing_id_, routing_id); | 42 EXPECT_EQ(routing_id_, routing_id); |
| 48 widget_ = NULL; | 43 widget_ = NULL; |
| 49 } | 44 } |
| 50 | 45 |
| 51 // Called by, for example, RenderView::Init(), when adding a new message filter. | 46 // Called by, for example, RenderView::Init(), when adding a new message filter. |
| 52 void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { | 47 void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 53 filter->OnFilterAdded(&sink()); | 48 filter->OnFilterAdded(&sink()); |
| 54 } | 49 } |
| 55 | 50 |
| 56 // Called when the filter is removed. | 51 // Called when the filter is removed. |
| 57 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { | 52 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 58 filter->OnFilterRemoved(); | 53 filter->OnFilterRemoved(); |
| 59 } | 54 } |
| 60 | 55 |
| 61 bool MockRenderThread::IsExtensionProcess() const { | |
| 62 return is_extension_process_; | |
| 63 } | |
| 64 | 56 |
| 65 bool MockRenderThread::IsIncognitoProcess() const { | 57 bool MockRenderThread::IsIncognitoProcess() const { |
| 66 return false; | 58 return false; |
| 67 } | 59 } |
| 68 | 60 |
| 69 // Called by the Widget. Used to send messages to the browser. | 61 // Called by the Widget. Used to send messages to the browser. |
| 70 // We short-circuit the mechanim and handle the messages right here on this | 62 // We short-circuit the mechanim and handle the messages right here on this |
| 71 // class. | 63 // class. |
| 72 bool MockRenderThread::Send(IPC::Message* msg) { | 64 bool MockRenderThread::Send(IPC::Message* msg) { |
| 73 // We need to simulate a synchronous channel, thus we are going to receive | 65 // We need to simulate a synchronous channel, thus we are going to receive |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 204 |
| 213 void MockRenderThread::OnDidPrintPage( | 205 void MockRenderThread::OnDidPrintPage( |
| 214 const PrintHostMsg_DidPrintPage_Params& params) { | 206 const PrintHostMsg_DidPrintPage_Params& params) { |
| 215 if (printer_.get()) | 207 if (printer_.get()) |
| 216 printer_->PrintPage(params); | 208 printer_->PrintPage(params); |
| 217 } | 209 } |
| 218 | 210 |
| 219 void MockRenderThread::set_print_dialog_user_response(bool response) { | 211 void MockRenderThread::set_print_dialog_user_response(bool response) { |
| 220 print_dialog_user_response_ = response; | 212 print_dialog_user_response_ = response; |
| 221 } | 213 } |
| OLD | NEW |