| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/renderer_host/mock_render_process_host.h" | |
| 6 | |
| 7 #include "chrome/browser/child_process_security_policy.h" | |
| 8 | |
| 9 MockRenderProcessHost::MockRenderProcessHost(Profile* profile) | |
| 10 : RenderProcessHost(profile), | |
| 11 transport_dib_(NULL), | |
| 12 bad_msg_count_(0), | |
| 13 factory_(NULL) { | |
| 14 // Child process security operations can't be unit tested unless we add | |
| 15 // ourselves as an existing child process. | |
| 16 ChildProcessSecurityPolicy::GetInstance()->Add(id()); | |
| 17 } | |
| 18 | |
| 19 MockRenderProcessHost::~MockRenderProcessHost() { | |
| 20 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); | |
| 21 delete transport_dib_; | |
| 22 if (factory_) | |
| 23 factory_->Remove(this); | |
| 24 } | |
| 25 | |
| 26 bool MockRenderProcessHost::Init( | |
| 27 bool is_accessibility_enabled, bool is_extensions_process) { | |
| 28 return true; | |
| 29 } | |
| 30 | |
| 31 int MockRenderProcessHost::GetNextRoutingID() { | |
| 32 static int prev_routing_id = 0; | |
| 33 return ++prev_routing_id; | |
| 34 } | |
| 35 | |
| 36 void MockRenderProcessHost::CancelResourceRequests(int render_widget_id) { | |
| 37 } | |
| 38 | |
| 39 void MockRenderProcessHost::CrossSiteClosePageACK( | |
| 40 const ViewMsg_ClosePage_Params& params) { | |
| 41 } | |
| 42 | |
| 43 bool MockRenderProcessHost::WaitForUpdateMsg(int render_widget_id, | |
| 44 const base::TimeDelta& max_delay, | |
| 45 IPC::Message* msg) { | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 void MockRenderProcessHost::ReceivedBadMessage() { | |
| 50 ++bad_msg_count_; | |
| 51 } | |
| 52 | |
| 53 void MockRenderProcessHost::WidgetRestored() { | |
| 54 } | |
| 55 | |
| 56 void MockRenderProcessHost::WidgetHidden() { | |
| 57 } | |
| 58 | |
| 59 void MockRenderProcessHost::ViewCreated() { | |
| 60 } | |
| 61 | |
| 62 void MockRenderProcessHost::AddWord(const string16& word) { | |
| 63 } | |
| 64 | |
| 65 void MockRenderProcessHost::SendVisitedLinkTable( | |
| 66 base::SharedMemory* table_memory) { | |
| 67 } | |
| 68 | |
| 69 void MockRenderProcessHost::AddVisitedLinks( | |
| 70 const VisitedLinkCommon::Fingerprints& links) { | |
| 71 } | |
| 72 | |
| 73 void MockRenderProcessHost::ResetVisitedLinks() { | |
| 74 } | |
| 75 | |
| 76 bool MockRenderProcessHost::FastShutdownIfPossible() { | |
| 77 // We aren't actually going to do anything, but set |fast_shutdown_started_| | |
| 78 // to true so that tests know we've been called. | |
| 79 fast_shutdown_started_ = true; | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 bool MockRenderProcessHost::SendWithTimeout(IPC::Message* msg, int timeout_ms) { | |
| 84 // Save the message in the sink. Just ignore timeout_ms. | |
| 85 sink_.OnMessageReceived(*msg); | |
| 86 delete msg; | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 base::ProcessHandle MockRenderProcessHost::GetHandle() { | |
| 91 return base::kNullProcessHandle; | |
| 92 } | |
| 93 | |
| 94 bool MockRenderProcessHost::Send(IPC::Message* msg) { | |
| 95 // Save the message in the sink. | |
| 96 sink_.OnMessageReceived(*msg); | |
| 97 delete msg; | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 TransportDIB* MockRenderProcessHost::GetTransportDIB(TransportDIB::Id dib_id) { | |
| 102 if (transport_dib_) | |
| 103 return transport_dib_; | |
| 104 #if defined(OS_WIN) | |
| 105 HANDLE duped; | |
| 106 DuplicateHandle(GetCurrentProcess(), dib_id.handle, GetCurrentProcess(), | |
| 107 &duped, 0, TRUE, DUPLICATE_SAME_ACCESS); | |
| 108 transport_dib_ = TransportDIB::Map(duped); | |
| 109 #elif defined(OS_MACOSX) | |
| 110 // On Mac, TransportDIBs are always created in the browser, so we cannot map | |
| 111 // one from a dib_id. | |
| 112 transport_dib_ = TransportDIB::Create(100 * 100 * 4, 0); | |
| 113 #elif defined(OS_POSIX) | |
| 114 transport_dib_ = TransportDIB::Map(dib_id); | |
| 115 #endif | |
| 116 | |
| 117 return transport_dib_; | |
| 118 } | |
| 119 | |
| 120 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { | |
| 121 return false; | |
| 122 } | |
| 123 | |
| 124 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { | |
| 125 } | |
| 126 | |
| 127 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} | |
| 128 | |
| 129 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { | |
| 130 // Detach this object from MockRenderProcesses to prevent STLDeleteElements() | |
| 131 // from calling MockRenderProcessHostFactory::Remove(). | |
| 132 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); | |
| 133 it != processes_.end(); ++it) { | |
| 134 (*it)->SetFactory(NULL); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 RenderProcessHost* MockRenderProcessHostFactory::CreateRenderProcessHost( | |
| 139 Profile* profile) const { | |
| 140 MockRenderProcessHost* host = new MockRenderProcessHost(profile); | |
| 141 if (host) { | |
| 142 processes_.push_back(host); | |
| 143 host->SetFactory(this); | |
| 144 } | |
| 145 return host; | |
| 146 } | |
| 147 | |
| 148 void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const { | |
| 149 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); | |
| 150 it != processes_.end(); ++it) { | |
| 151 if (*it == host) { | |
| 152 processes_.weak_erase(it); | |
| 153 break; | |
| 154 } | |
| 155 } | |
| 156 } | |
| OLD | NEW |