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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
13 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
14 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
15 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
16 #include "ppapi/c/pp_instance.h" | 15 #include "ppapi/c/pp_instance.h" |
17 #include "ppapi/proxy/host_dispatcher.h" | 16 #include "ppapi/proxy/host_dispatcher.h" |
18 #include "ppapi/proxy/plugin_dispatcher.h" | 17 #include "ppapi/proxy/plugin_dispatcher.h" |
19 #include "ppapi/proxy/plugin_globals.h" | 18 #include "ppapi/proxy/plugin_globals.h" |
20 #include "ppapi/proxy/plugin_proxy_delegate.h" | 19 #include "ppapi/proxy/plugin_proxy_delegate.h" |
21 #include "ppapi/proxy/plugin_resource_tracker.h" | 20 #include "ppapi/proxy/plugin_resource_tracker.h" |
22 #include "ppapi/proxy/plugin_var_tracker.h" | 21 #include "ppapi/proxy/plugin_var_tracker.h" |
23 #include "ppapi/proxy/resource_message_test_sink.h" | 22 #include "ppapi/proxy/resource_message_test_sink.h" |
24 #include "ppapi/shared_impl/proxy_lock.h" | 23 #include "ppapi/shared_impl/proxy_lock.h" |
25 #include "ppapi/shared_impl/test_globals.h" | 24 #include "ppapi/shared_impl/test_globals.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 class MessageLoopProxy; | |
30 class RunLoop; | 28 class RunLoop; |
| 29 class SingleThreadTaskRunner; |
31 } | 30 } |
32 | 31 |
33 namespace ppapi { | 32 namespace ppapi { |
34 namespace proxy { | 33 namespace proxy { |
35 | 34 |
36 class MessageLoopResource; | 35 class MessageLoopResource; |
37 | 36 |
38 // Base class for plugin and host test harnesses. Tests will not use this | 37 // Base class for plugin and host test harnesses. Tests will not use this |
39 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. | 38 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. |
40 class ProxyTestHarnessBase { | 39 class ProxyTestHarnessBase { |
(...skipping 11 matching lines...) Expand all Loading... |
52 ResourceMessageTestSink& sink() { return sink_; } | 51 ResourceMessageTestSink& sink() { return sink_; } |
53 | 52 |
54 virtual PpapiGlobals* GetGlobals() = 0; | 53 virtual PpapiGlobals* GetGlobals() = 0; |
55 // Returns either the plugin or host dispatcher, depending on the test. | 54 // Returns either the plugin or host dispatcher, depending on the test. |
56 virtual Dispatcher* GetDispatcher() = 0; | 55 virtual Dispatcher* GetDispatcher() = 0; |
57 | 56 |
58 // Set up the harness using an IPC::TestSink to capture messages. | 57 // Set up the harness using an IPC::TestSink to capture messages. |
59 virtual void SetUpHarness() = 0; | 58 virtual void SetUpHarness() = 0; |
60 | 59 |
61 // Set up the harness using a real IPC channel. | 60 // Set up the harness using a real IPC channel. |
62 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 61 virtual void SetUpHarnessWithChannel( |
63 base::MessageLoopProxy* ipc_message_loop, | 62 const IPC::ChannelHandle& channel_handle, |
64 base::WaitableEvent* shutdown_event, | 63 base::SingleThreadTaskRunner* ipc_task_runner, |
65 bool is_client) = 0; | 64 base::WaitableEvent* shutdown_event, |
| 65 bool is_client) = 0; |
66 | 66 |
67 virtual void TearDownHarness() = 0; | 67 virtual void TearDownHarness() = 0; |
68 | 68 |
69 // Implementation of GetInterface for the dispatcher. This will | 69 // Implementation of GetInterface for the dispatcher. This will |
70 // return NULL for all interfaces unless one is registered by calling | 70 // return NULL for all interfaces unless one is registered by calling |
71 // RegisterTestInterface(); | 71 // RegisterTestInterface(); |
72 const void* GetInterface(const char* name); | 72 const void* GetInterface(const char* name); |
73 | 73 |
74 // Allows the test to specify an interface implementation for a given | 74 // Allows the test to specify an interface implementation for a given |
75 // interface name. This will be returned when any of the proxy logic | 75 // interface name. This will be returned when any of the proxy logic |
(...skipping 27 matching lines...) Expand all Loading... |
103 return *plugin_globals_->plugin_resource_tracker(); | 103 return *plugin_globals_->plugin_resource_tracker(); |
104 } | 104 } |
105 PluginVarTracker& var_tracker() { | 105 PluginVarTracker& var_tracker() { |
106 return *plugin_globals_->plugin_var_tracker(); | 106 return *plugin_globals_->plugin_var_tracker(); |
107 } | 107 } |
108 | 108 |
109 // ProxyTestHarnessBase implementation. | 109 // ProxyTestHarnessBase implementation. |
110 virtual PpapiGlobals* GetGlobals(); | 110 virtual PpapiGlobals* GetGlobals(); |
111 virtual Dispatcher* GetDispatcher(); | 111 virtual Dispatcher* GetDispatcher(); |
112 virtual void SetUpHarness(); | 112 virtual void SetUpHarness(); |
113 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 113 virtual void SetUpHarnessWithChannel( |
114 base::MessageLoopProxy* ipc_message_loop, | 114 const IPC::ChannelHandle& channel_handle, |
115 base::WaitableEvent* shutdown_event, | 115 base::SingleThreadTaskRunner* ipc_task_runner, |
116 bool is_client); | 116 base::WaitableEvent* shutdown_event, |
| 117 bool is_client); |
117 virtual void TearDownHarness(); | 118 virtual void TearDownHarness(); |
118 | 119 |
119 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, | 120 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, |
120 public PluginProxyDelegate { | 121 public PluginProxyDelegate { |
121 public: | 122 public: |
122 PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {} | 123 PluginDelegateMock() : ipc_task_runner_(NULL), shutdown_event_() {} |
123 ~PluginDelegateMock() override {} | 124 ~PluginDelegateMock() override {} |
124 | 125 |
125 void Init(base::MessageLoopProxy* ipc_message_loop, | 126 void Init(base::SingleThreadTaskRunner* ipc_task_runner, |
126 base::WaitableEvent* shutdown_event) { | 127 base::WaitableEvent* shutdown_event) { |
127 ipc_message_loop_ = ipc_message_loop; | 128 ipc_task_runner_ = ipc_task_runner; |
128 shutdown_event_ = shutdown_event; | 129 shutdown_event_ = shutdown_event; |
129 } | 130 } |
130 | 131 |
131 void set_browser_sender(IPC::Sender* browser_sender) { | 132 void set_browser_sender(IPC::Sender* browser_sender) { |
132 browser_sender_ = browser_sender; | 133 browser_sender_ = browser_sender; |
133 } | 134 } |
134 | 135 |
135 // ProxyChannel::Delegate implementation. | 136 // ProxyChannel::Delegate implementation. |
136 base::SingleThreadTaskRunner* GetIPCTaskRunner() override; | 137 base::SingleThreadTaskRunner* GetIPCTaskRunner() override; |
137 base::WaitableEvent* GetShutdownEvent() override; | 138 base::WaitableEvent* GetShutdownEvent() override; |
(...skipping 15 matching lines...) Expand all Loading... |
153 std::string GetUILanguage() override; | 154 std::string GetUILanguage() override; |
154 void PreCacheFont(const void* logfontw) override; | 155 void PreCacheFont(const void* logfontw) override; |
155 void SetActiveURL(const std::string& url) override; | 156 void SetActiveURL(const std::string& url) override; |
156 PP_Resource CreateBrowserFont( | 157 PP_Resource CreateBrowserFont( |
157 Connection connection, | 158 Connection connection, |
158 PP_Instance instance, | 159 PP_Instance instance, |
159 const PP_BrowserFont_Trusted_Description& desc, | 160 const PP_BrowserFont_Trusted_Description& desc, |
160 const Preferences& prefs) override; | 161 const Preferences& prefs) override; |
161 | 162 |
162 private: | 163 private: |
163 base::MessageLoopProxy* ipc_message_loop_; // Weak | 164 base::SingleThreadTaskRunner* ipc_task_runner_; // Weak |
164 base::WaitableEvent* shutdown_event_; // Weak | 165 base::WaitableEvent* shutdown_event_; // Weak |
165 std::set<PP_Instance> instance_id_set_; | 166 std::set<PP_Instance> instance_id_set_; |
166 IPC::Sender* browser_sender_; | 167 IPC::Sender* browser_sender_; |
167 | 168 |
168 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); | 169 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); |
169 }; | 170 }; |
170 | 171 |
171 private: | 172 private: |
172 void CreatePluginGlobals( | 173 void CreatePluginGlobals( |
173 const scoped_refptr<base::TaskRunner>& ipc_task_runner); | 174 const scoped_refptr<base::TaskRunner>& ipc_task_runner); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 SECONDARY_THREAD | 219 SECONDARY_THREAD |
219 }; | 220 }; |
220 void CheckOnThread(ThreadType thread_type); | 221 void CheckOnThread(ThreadType thread_type); |
221 | 222 |
222 // These can be called on any thread. | 223 // These can be called on any thread. |
223 void PostQuitForMainThread(); | 224 void PostQuitForMainThread(); |
224 void PostQuitForSecondaryThread(); | 225 void PostQuitForSecondaryThread(); |
225 | 226 |
226 protected: | 227 protected: |
227 scoped_refptr<MessageLoopResource> secondary_thread_message_loop_; | 228 scoped_refptr<MessageLoopResource> secondary_thread_message_loop_; |
228 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_proxy_; | 229 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
229 | 230 |
230 private: | 231 private: |
231 // base::DelegateSimpleThread::Delegate implementation. | 232 // base::DelegateSimpleThread::Delegate implementation. |
232 void Run() override; | 233 void Run() override; |
233 | 234 |
234 void QuitNestedLoop(); | 235 void QuitNestedLoop(); |
235 | 236 |
236 static void InternalSetUpTestOnSecondaryThread(void* user_data, | 237 static void InternalSetUpTestOnSecondaryThread(void* user_data, |
237 int32_t result); | 238 int32_t result); |
238 | 239 |
(...skipping 11 matching lines...) Expand all Loading... |
250 return *host_globals_->GetResourceTracker(); | 251 return *host_globals_->GetResourceTracker(); |
251 } | 252 } |
252 VarTracker& var_tracker() { | 253 VarTracker& var_tracker() { |
253 return *host_globals_->GetVarTracker(); | 254 return *host_globals_->GetVarTracker(); |
254 } | 255 } |
255 | 256 |
256 // ProxyTestBase implementation. | 257 // ProxyTestBase implementation. |
257 virtual PpapiGlobals* GetGlobals(); | 258 virtual PpapiGlobals* GetGlobals(); |
258 virtual Dispatcher* GetDispatcher(); | 259 virtual Dispatcher* GetDispatcher(); |
259 virtual void SetUpHarness(); | 260 virtual void SetUpHarness(); |
260 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 261 virtual void SetUpHarnessWithChannel( |
261 base::MessageLoopProxy* ipc_message_loop, | 262 const IPC::ChannelHandle& channel_handle, |
262 base::WaitableEvent* shutdown_event, | 263 base::SingleThreadTaskRunner* ipc_task_runner, |
263 bool is_client); | 264 base::WaitableEvent* shutdown_event, |
| 265 bool is_client); |
264 virtual void TearDownHarness(); | 266 virtual void TearDownHarness(); |
265 | 267 |
266 class DelegateMock : public ProxyChannel::Delegate { | 268 class DelegateMock : public ProxyChannel::Delegate { |
267 public: | 269 public: |
268 DelegateMock() : ipc_message_loop_(NULL), shutdown_event_(NULL) { | 270 DelegateMock() : ipc_task_runner_(NULL), shutdown_event_(NULL) {} |
269 } | |
270 ~DelegateMock() override {} | 271 ~DelegateMock() override {} |
271 | 272 |
272 void Init(base::MessageLoopProxy* ipc_message_loop, | 273 void Init(base::SingleThreadTaskRunner* ipc_task_runner, |
273 base::WaitableEvent* shutdown_event) { | 274 base::WaitableEvent* shutdown_event) { |
274 ipc_message_loop_ = ipc_message_loop; | 275 ipc_task_runner_ = ipc_task_runner; |
275 shutdown_event_ = shutdown_event; | 276 shutdown_event_ = shutdown_event; |
276 } | 277 } |
277 | 278 |
278 // ProxyChannel::Delegate implementation. | 279 // ProxyChannel::Delegate implementation. |
279 base::MessageLoopProxy* GetIPCTaskRunner() override; | 280 base::SingleThreadTaskRunner* GetIPCTaskRunner() override; |
280 base::WaitableEvent* GetShutdownEvent() override; | 281 base::WaitableEvent* GetShutdownEvent() override; |
281 IPC::PlatformFileForTransit ShareHandleWithRemote( | 282 IPC::PlatformFileForTransit ShareHandleWithRemote( |
282 base::PlatformFile handle, | 283 base::PlatformFile handle, |
283 base::ProcessId remote_pid, | 284 base::ProcessId remote_pid, |
284 bool should_close_source) override; | 285 bool should_close_source) override; |
285 base::SharedMemoryHandle ShareSharedMemoryHandleWithRemote( | 286 base::SharedMemoryHandle ShareSharedMemoryHandleWithRemote( |
286 const base::SharedMemoryHandle& handle, | 287 const base::SharedMemoryHandle& handle, |
287 base::ProcessId remote_pid) override; | 288 base::ProcessId remote_pid) override; |
288 | 289 |
289 private: | 290 private: |
290 base::MessageLoopProxy* ipc_message_loop_; // Weak | 291 base::SingleThreadTaskRunner* ipc_task_runner_; // Weak |
291 base::WaitableEvent* shutdown_event_; // Weak | 292 base::WaitableEvent* shutdown_event_; // Weak |
292 | 293 |
293 DISALLOW_COPY_AND_ASSIGN(DelegateMock); | 294 DISALLOW_COPY_AND_ASSIGN(DelegateMock); |
294 }; | 295 }; |
295 | 296 |
296 private: | 297 private: |
297 void CreateHostGlobals(); | 298 void CreateHostGlobals(); |
298 | 299 |
299 GlobalsConfiguration globals_config_; | 300 GlobalsConfiguration globals_config_; |
300 scoped_ptr<ppapi::TestGlobals> host_globals_; | 301 scoped_ptr<ppapi::TestGlobals> host_globals_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // EXPECT_VAR_IS_STRING("foo", my_var); | 372 // EXPECT_VAR_IS_STRING("foo", my_var); |
372 #define EXPECT_VAR_IS_STRING(str, var) { \ | 373 #define EXPECT_VAR_IS_STRING(str, var) { \ |
373 StringVar* sv = StringVar::FromPPVar(var); \ | 374 StringVar* sv = StringVar::FromPPVar(var); \ |
374 EXPECT_TRUE(sv); \ | 375 EXPECT_TRUE(sv); \ |
375 if (sv) \ | 376 if (sv) \ |
376 EXPECT_EQ(str, sv->value()); \ | 377 EXPECT_EQ(str, sv->value()); \ |
377 } | 378 } |
378 | 379 |
379 } // namespace proxy | 380 } // namespace proxy |
380 } // namespace ppapi | 381 } // namespace ppapi |
OLD | NEW |