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_thread.h" | 5 #include "content/public/test/mock_render_thread.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "content/common/frame_messages.h" | 8 #include "content/common/frame_messages.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/public/renderer/render_process_observer.h" | 10 #include "content/public/renderer/render_process_observer.h" |
11 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
12 #include "ipc/ipc_message_utils.h" | 12 #include "ipc/ipc_message_utils.h" |
13 #include "ipc/ipc_sync_message.h" | 13 #include "ipc/ipc_sync_message.h" |
| 14 #include "ipc/message_filter.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/web/WebScriptController.h" | 16 #include "third_party/WebKit/public/web/WebScriptController.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 MockRenderThread::MockRenderThread() | 20 MockRenderThread::MockRenderThread() |
20 : routing_id_(0), | 21 : routing_id_(0), |
21 surface_id_(0), | 22 surface_id_(0), |
22 opener_id_(0), | 23 opener_id_(0), |
23 new_window_routing_id_(0), | 24 new_window_routing_id_(0), |
24 new_window_main_frame_routing_id_(0), | 25 new_window_main_frame_routing_id_(0), |
25 new_frame_routing_id_(0) { | 26 new_frame_routing_id_(0) { |
26 } | 27 } |
27 | 28 |
28 MockRenderThread::~MockRenderThread() { | 29 MockRenderThread::~MockRenderThread() { |
29 while (!filters_.empty()) { | 30 while (!filters_.empty()) { |
30 scoped_refptr<IPC::ChannelProxy::MessageFilter> filter = filters_.back(); | 31 scoped_refptr<IPC::MessageFilter> filter = filters_.back(); |
31 filters_.pop_back(); | 32 filters_.pop_back(); |
32 filter->OnFilterRemoved(); | 33 filter->OnFilterRemoved(); |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 // Called by the Widget. Used to send messages to the browser. | 37 // Called by the Widget. Used to send messages to the browser. |
37 // We short-circuit the mechanism and handle the messages right here on this | 38 // We short-circuit the mechanism and handle the messages right here on this |
38 // class. | 39 // class. |
39 bool MockRenderThread::Send(IPC::Message* msg) { | 40 bool MockRenderThread::Send(IPC::Message* msg) { |
40 // 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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 | 88 |
88 void MockRenderThread::RemoveRoute(int32 routing_id) { | 89 void MockRenderThread::RemoveRoute(int32 routing_id) { |
89 } | 90 } |
90 | 91 |
91 int MockRenderThread::GenerateRoutingID() { | 92 int MockRenderThread::GenerateRoutingID() { |
92 NOTREACHED(); | 93 NOTREACHED(); |
93 return MSG_ROUTING_NONE; | 94 return MSG_ROUTING_NONE; |
94 } | 95 } |
95 | 96 |
96 void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { | 97 void MockRenderThread::AddFilter(IPC::MessageFilter* filter) { |
97 filter->OnFilterAdded(&sink()); | 98 filter->OnFilterAdded(&sink()); |
98 // Add this filter to a vector so the MockRenderThread::RemoveFilter function | 99 // Add this filter to a vector so the MockRenderThread::RemoveFilter function |
99 // can check if this filter is added. | 100 // can check if this filter is added. |
100 filters_.push_back(make_scoped_refptr(filter)); | 101 filters_.push_back(make_scoped_refptr(filter)); |
101 } | 102 } |
102 | 103 |
103 void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { | 104 void MockRenderThread::RemoveFilter(IPC::MessageFilter* filter) { |
104 // Emulate the IPC::ChannelProxy::OnRemoveFilter function. | 105 // Emulate the IPC::ChannelProxy::OnRemoveFilter function. |
105 for (size_t i = 0; i < filters_.size(); ++i) { | 106 for (size_t i = 0; i < filters_.size(); ++i) { |
106 if (filters_[i].get() == filter) { | 107 if (filters_[i].get() == filter) { |
107 filter->OnFilterRemoved(); | 108 filter->OnFilterRemoved(); |
108 filters_.erase(filters_.begin() + i); | 109 filters_.erase(filters_.begin() + i); |
109 return; | 110 return; |
110 } | 111 } |
111 } | 112 } |
112 NOTREACHED() << "filter to be removed not found"; | 113 NOTREACHED() << "filter to be removed not found"; |
113 } | 114 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 void MockRenderThread::OnDuplicateSection( | 252 void MockRenderThread::OnDuplicateSection( |
252 base::SharedMemoryHandle renderer_handle, | 253 base::SharedMemoryHandle renderer_handle, |
253 base::SharedMemoryHandle* browser_handle) { | 254 base::SharedMemoryHandle* browser_handle) { |
254 // We don't have to duplicate the input handles since RenderViewTest does not | 255 // We don't have to duplicate the input handles since RenderViewTest does not |
255 // separate a browser process from a renderer process. | 256 // separate a browser process from a renderer process. |
256 *browser_handle = renderer_handle; | 257 *browser_handle = renderer_handle; |
257 } | 258 } |
258 #endif // defined(OS_WIN) | 259 #endif // defined(OS_WIN) |
259 | 260 |
260 } // namespace content | 261 } // namespace content |
OLD | NEW |