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 #ifndef CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ |
6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ | 6 #define CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
17 #include "ipc/ipc_test_sink.h" | 17 #include "ipc/ipc_test_sink.h" |
18 #include "ipc/message_filter.h" | 18 #include "ipc/message_filter.h" |
19 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 19 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
20 #include "third_party/WebKit/public/web/WebPopupType.h" | 20 #include "third_party/WebKit/public/web/WebPopupType.h" |
21 | 21 |
22 struct FrameHostMsg_CreateChildFrame_Params; | 22 struct FrameHostMsg_CreateChildFrame_Params; |
23 struct ViewHostMsg_CreateWindow_Params; | |
24 struct ViewHostMsg_CreateWindow_Reply; | |
25 | 23 |
26 namespace IPC { | 24 namespace IPC { |
27 class MessageFilter; | 25 class MessageFilter; |
28 class MessageReplyDeserializer; | 26 class MessageReplyDeserializer; |
29 } | 27 } |
30 | 28 |
31 namespace blink { | 29 namespace blink { |
32 enum class WebSandboxFlags; | 30 enum class WebSandboxFlags; |
33 enum class WebTreeScopeType; | 31 enum class WebTreeScopeType; |
34 } | 32 } |
35 | 33 |
36 namespace content { | 34 namespace content { |
37 | 35 |
36 namespace mojom { | |
37 class CreateNewWindowParams; | |
38 class CreateNewWindowReply; | |
39 class RenderMessageFilter; | |
40 } | |
41 | |
38 // This class is a very simple mock of RenderThread. It simulates an IPC channel | 42 // This class is a very simple mock of RenderThread. It simulates an IPC channel |
39 // which supports only three messages: | 43 // which supports only three messages: |
40 // ViewHostMsg_CreateWidget : sync message sent by the Widget. | 44 // ViewHostMsg_CreateWidget : sync message sent by the Widget. |
41 // ViewHostMsg_CreateWindow : sync message sent by the Widget. | |
42 // ViewMsg_Close : async, send to the Widget. | 45 // ViewMsg_Close : async, send to the Widget. |
ncarter (slow)
2016/09/27 20:32:41
Let's redo this class comment so that it better de
Ken Rockot(use gerrit already)
2016/09/27 21:05:42
SGTM as-is. Done.
| |
43 class MockRenderThread : public RenderThread { | 46 class MockRenderThread : public RenderThread { |
44 public: | 47 public: |
45 MockRenderThread(); | 48 MockRenderThread(); |
46 ~MockRenderThread() override; | 49 ~MockRenderThread() override; |
47 | 50 |
48 // Provides access to the messages that have been received by this thread. | 51 // Provides access to the messages that have been received by this thread. |
49 IPC::TestSink& sink() { return sink_; } | 52 IPC::TestSink& sink() { return sink_; } |
50 | 53 |
51 // RenderThread implementation: | 54 // RenderThread implementation: |
52 bool Send(IPC::Message* msg) override; | 55 bool Send(IPC::Message* msg) override; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 // Simulates the Widget receiving a close message. This should result | 107 // Simulates the Widget receiving a close message. This should result |
105 // on releasing the internal reference counts and destroying the internal | 108 // on releasing the internal reference counts and destroying the internal |
106 // state. | 109 // state. |
107 void SendCloseMessage(); | 110 void SendCloseMessage(); |
108 | 111 |
109 // Dispatches control messages to observers. | 112 // Dispatches control messages to observers. |
110 bool OnControlMessageReceived(const IPC::Message& msg); | 113 bool OnControlMessageReceived(const IPC::Message& msg); |
111 | 114 |
112 base::ObserverList<RenderThreadObserver>& observers() { return observers_; } | 115 base::ObserverList<RenderThreadObserver>& observers() { return observers_; } |
113 | 116 |
117 // The View expects to be returned a valid |reply.route_id| different from its | |
118 // own. We do not keep track of the newly created widget in MockRenderThread, | |
119 // so it must be cleaned up on its own. | |
120 void OnCreateWindow(const mojom::CreateNewWindowParams& params, | |
121 mojom::CreateNewWindowReply* reply); | |
122 | |
114 protected: | 123 protected: |
115 // This function operates as a regular IPC listener. Subclasses | 124 // This function operates as a regular IPC listener. Subclasses |
116 // overriding this should first delegate to this implementation. | 125 // overriding this should first delegate to this implementation. |
117 virtual bool OnMessageReceived(const IPC::Message& msg); | 126 virtual bool OnMessageReceived(const IPC::Message& msg); |
118 | 127 |
119 // The Widget expects to be returned valid route_id. | 128 // The Widget expects to be returned valid route_id. |
120 void OnCreateWidget(int opener_id, | 129 void OnCreateWidget(int opener_id, |
121 blink::WebPopupType popup_type, | 130 blink::WebPopupType popup_type, |
122 int* route_id); | 131 int* route_id); |
123 | 132 |
124 // The View expects to be returned a valid |reply.route_id| different from its | |
125 // own. We do not keep track of the newly created widget in MockRenderThread, | |
126 // so it must be cleaned up on its own. | |
127 void OnCreateWindow(const ViewHostMsg_CreateWindow_Params& params, | |
128 ViewHostMsg_CreateWindow_Reply* reply); | |
129 | |
130 // The Frame expects to be returned a valid route_id different from its own. | 133 // The Frame expects to be returned a valid route_id different from its own. |
131 void OnCreateChildFrame(const FrameHostMsg_CreateChildFrame_Params& params, | 134 void OnCreateChildFrame(const FrameHostMsg_CreateChildFrame_Params& params, |
132 int* new_render_frame_id); | 135 int* new_render_frame_id); |
133 | 136 |
134 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
135 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, | 138 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle, |
136 base::SharedMemoryHandle* browser_handle); | 139 base::SharedMemoryHandle* browser_handle); |
137 #endif | 140 #endif |
138 | 141 |
139 IPC::TestSink sink_; | 142 IPC::TestSink sink_; |
(...skipping 17 matching lines...) Expand all Loading... | |
157 std::vector<scoped_refptr<IPC::MessageFilter> > filters_; | 160 std::vector<scoped_refptr<IPC::MessageFilter> > filters_; |
158 | 161 |
159 // Observers to notify. | 162 // Observers to notify. |
160 base::ObserverList<RenderThreadObserver> observers_; | 163 base::ObserverList<RenderThreadObserver> observers_; |
161 | 164 |
162 cc::TestSharedBitmapManager shared_bitmap_manager_; | 165 cc::TestSharedBitmapManager shared_bitmap_manager_; |
163 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 166 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; |
164 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | 167 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; |
165 shell::mojom::InterfaceProviderRequest | 168 shell::mojom::InterfaceProviderRequest |
166 pending_remote_interface_provider_request_; | 169 pending_remote_interface_provider_request_; |
170 | |
171 std::unique_ptr<mojom::RenderMessageFilter> mock_render_message_filter_; | |
167 }; | 172 }; |
168 | 173 |
169 } // namespace content | 174 } // namespace content |
170 | 175 |
171 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ | 176 #endif // CONTENT_PUBLIC_TEST_MOCK_RENDER_THREAD_H_ |
OLD | NEW |