OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/public/test/mock_render_process_host.h" | 5 #include "content/public/test/mock_render_process_host.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 bool MockRenderProcessHost::Init() { | 47 bool MockRenderProcessHost::Init() { |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
51 int MockRenderProcessHost::GetNextRoutingID() { | 51 int MockRenderProcessHost::GetNextRoutingID() { |
52 static int prev_routing_id = 0; | 52 static int prev_routing_id = 0; |
53 return ++prev_routing_id; | 53 return ++prev_routing_id; |
54 } | 54 } |
55 | 55 |
| 56 void MockRenderProcessHost::AddRoute( |
| 57 int32 routing_id, |
| 58 IPC::Listener* listener) { |
| 59 listeners_.AddWithID(listener, routing_id); |
| 60 } |
| 61 |
| 62 void MockRenderProcessHost::RemoveRoute(int32 routing_id) { |
| 63 DCHECK(listeners_.Lookup(routing_id) != NULL); |
| 64 listeners_.Remove(routing_id); |
| 65 Cleanup(); |
| 66 } |
| 67 |
56 void MockRenderProcessHost::SimulateSwapOutACK( | 68 void MockRenderProcessHost::SimulateSwapOutACK( |
57 const ViewMsg_SwapOut_Params& params) { | 69 const ViewMsg_SwapOut_Params& params) { |
58 } | 70 } |
59 | 71 |
60 bool MockRenderProcessHost::WaitForBackingStoreMsg( | 72 bool MockRenderProcessHost::WaitForBackingStoreMsg( |
61 int render_widget_id, | 73 int render_widget_id, |
62 const base::TimeDelta& max_delay, | 74 const base::TimeDelta& max_delay, |
63 IPC::Message* msg) { | 75 IPC::Message* msg) { |
64 return false; | 76 return false; |
65 } | 77 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return true; | 162 return true; |
151 } | 163 } |
152 | 164 |
153 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { | 165 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { |
154 } | 166 } |
155 | 167 |
156 bool MockRenderProcessHost::IgnoreInputEvents() const { | 168 bool MockRenderProcessHost::IgnoreInputEvents() const { |
157 return false; | 169 return false; |
158 } | 170 } |
159 | 171 |
160 void MockRenderProcessHost::Attach(RenderWidgetHost* host, | |
161 int routing_id) { | |
162 render_widget_hosts_.AddWithID(host, routing_id); | |
163 } | |
164 | |
165 void MockRenderProcessHost::Release(int routing_id) { | |
166 render_widget_hosts_.Remove(routing_id); | |
167 Cleanup(); | |
168 } | |
169 | |
170 void MockRenderProcessHost::Cleanup() { | 172 void MockRenderProcessHost::Cleanup() { |
171 if (render_widget_hosts_.IsEmpty()) { | 173 if (listeners_.IsEmpty()) { |
172 NotificationService::current()->Notify( | 174 NotificationService::current()->Notify( |
173 NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 175 NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
174 Source<RenderProcessHost>(this), | 176 Source<RenderProcessHost>(this), |
175 NotificationService::NoDetails()); | 177 NotificationService::NoDetails()); |
176 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 178 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
177 RenderProcessHostImpl::UnregisterHost(GetID()); | 179 RenderProcessHostImpl::UnregisterHost(GetID()); |
178 } | 180 } |
179 } | 181 } |
180 | 182 |
181 void MockRenderProcessHost::AddPendingView() { | 183 void MockRenderProcessHost::AddPendingView() { |
182 } | 184 } |
183 | 185 |
184 void MockRenderProcessHost::RemovePendingView() { | 186 void MockRenderProcessHost::RemovePendingView() { |
185 } | 187 } |
186 | 188 |
187 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { | 189 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { |
188 } | 190 } |
189 | 191 |
190 bool MockRenderProcessHost::SuddenTerminationAllowed() const { | 192 bool MockRenderProcessHost::SuddenTerminationAllowed() const { |
191 return true; | 193 return true; |
192 } | 194 } |
193 | 195 |
194 RenderWidgetHost* MockRenderProcessHost::GetRenderWidgetHostByID( | |
195 int routing_id) { | |
196 return render_widget_hosts_.Lookup(routing_id); | |
197 } | |
198 | |
199 BrowserContext* MockRenderProcessHost::GetBrowserContext() const { | 196 BrowserContext* MockRenderProcessHost::GetBrowserContext() const { |
200 return browser_context_; | 197 return browser_context_; |
201 } | 198 } |
202 | 199 |
203 bool MockRenderProcessHost::InSameStoragePartition( | 200 bool MockRenderProcessHost::InSameStoragePartition( |
204 StoragePartition* partition) const { | 201 StoragePartition* partition) const { |
205 // Mock RPHs only have one partition. | 202 // Mock RPHs only have one partition. |
206 return true; | 203 return true; |
207 } | 204 } |
208 | 205 |
209 IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { | 206 IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { |
210 return NULL; | 207 return NULL; |
211 } | 208 } |
212 | 209 |
213 bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { | 210 bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { |
214 if (render_widget_hosts_.size() == count) | 211 if (listeners_.size() == count) |
215 return FastShutdownIfPossible(); | 212 return FastShutdownIfPossible(); |
216 return false; | 213 return false; |
217 } | 214 } |
218 | 215 |
219 base::TimeDelta MockRenderProcessHost::GetChildProcessIdleTime() const { | 216 base::TimeDelta MockRenderProcessHost::GetChildProcessIdleTime() const { |
220 return base::TimeDelta::FromMilliseconds(0); | 217 return base::TimeDelta::FromMilliseconds(0); |
221 } | 218 } |
222 | 219 |
223 void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { | 220 void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { |
224 } | 221 } |
225 | 222 |
226 void MockRenderProcessHost::ResumeRequestsForView(int route_id) { | 223 void MockRenderProcessHost::ResumeRequestsForView(int route_id) { |
227 } | 224 } |
228 | 225 |
229 RenderProcessHost::RenderWidgetHostsIterator | |
230 MockRenderProcessHost::GetRenderWidgetHostsIterator() { | |
231 return RenderWidgetHostsIterator(&render_widget_hosts_); | |
232 } | |
233 | 226 |
234 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { | 227 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { |
235 RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); | 228 IPC::Listener* listener = listeners_.Lookup(msg.routing_id()); |
236 if (rwh) | 229 if (listener) |
237 return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); | 230 return listener->OnMessageReceived(msg); |
238 return false; | 231 return false; |
239 } | 232 } |
240 | 233 |
241 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { | 234 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { |
242 } | 235 } |
243 | 236 |
244 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} | 237 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} |
245 | 238 |
246 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { | 239 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { |
247 // Detach this object from MockRenderProcesses to prevent STLDeleteElements() | 240 // Detach this object from MockRenderProcesses to prevent STLDeleteElements() |
(...skipping 19 matching lines...) Expand all Loading... |
267 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); | 260 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); |
268 it != processes_.end(); ++it) { | 261 it != processes_.end(); ++it) { |
269 if (*it == host) { | 262 if (*it == host) { |
270 processes_.weak_erase(it); | 263 processes_.weak_erase(it); |
271 break; | 264 break; |
272 } | 265 } |
273 } | 266 } |
274 } | 267 } |
275 | 268 |
276 } // content | 269 } // content |
OLD | NEW |