| 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 "ppapi/proxy/ppapi_proxy_test.h" | 5 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 shutdown_event, false); | 86 shutdown_event, false); |
| 87 harness_set_up->Signal(); | 87 harness_set_up->Signal(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void TearDownRemoteHarness(ProxyTestHarnessBase* harness, | 90 void TearDownRemoteHarness(ProxyTestHarnessBase* harness, |
| 91 base::WaitableEvent* harness_torn_down) { | 91 base::WaitableEvent* harness_torn_down) { |
| 92 harness->TearDownHarness(); | 92 harness->TearDownHarness(); |
| 93 harness_torn_down->Signal(); | 93 harness_torn_down->Signal(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void RunTaskOnRemoteHarness(const base::Closure& task, |
| 97 base::WaitableEvent* task_complete) { |
| 98 task.Run(); |
| 99 task_complete->Signal(); |
| 100 } |
| 101 |
| 96 } // namespace | 102 } // namespace |
| 97 | 103 |
| 98 // ProxyTestHarnessBase -------------------------------------------------------- | 104 // ProxyTestHarnessBase -------------------------------------------------------- |
| 99 | 105 |
| 100 ProxyTestHarnessBase::ProxyTestHarnessBase() : pp_module_(0x98765), | 106 ProxyTestHarnessBase::ProxyTestHarnessBase() : pp_module_(0x98765), |
| 101 pp_instance_(0x12345) { | 107 pp_instance_(0x12345) { |
| 102 get_interface_handlers_.AddObserver(this); | 108 get_interface_handlers_.AddObserver(this); |
| 103 } | 109 } |
| 104 | 110 |
| 105 ProxyTestHarnessBase::~ProxyTestHarnessBase() { | 111 ProxyTestHarnessBase::~ProxyTestHarnessBase() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 133 TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data; | 139 TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data; |
| 134 EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( | 140 EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( |
| 135 reply_msg, &reply_data)); | 141 reply_msg, &reply_data)); |
| 136 | 142 |
| 137 sink().ClearMessages(); | 143 sink().ClearMessages(); |
| 138 return reply_data.a; | 144 return reply_data.a; |
| 139 } | 145 } |
| 140 | 146 |
| 141 // PluginProxyTestHarness ------------------------------------------------------ | 147 // PluginProxyTestHarness ------------------------------------------------------ |
| 142 | 148 |
| 143 PluginProxyTestHarness::PluginProxyTestHarness() | 149 PluginProxyTestHarness::PluginProxyTestHarness() { |
| 144 : plugin_globals_(PpapiGlobals::ForTest()) { | |
| 145 } | 150 } |
| 146 | 151 |
| 147 PluginProxyTestHarness::~PluginProxyTestHarness() { | 152 PluginProxyTestHarness::~PluginProxyTestHarness() { |
| 148 } | 153 } |
| 149 | 154 |
| 155 PpapiGlobals* PluginProxyTestHarness::GetGlobals() { |
| 156 return plugin_globals_.get(); |
| 157 } |
| 158 |
| 150 Dispatcher* PluginProxyTestHarness::GetDispatcher() { | 159 Dispatcher* PluginProxyTestHarness::GetDispatcher() { |
| 151 return plugin_dispatcher_.get(); | 160 return plugin_dispatcher_.get(); |
| 152 } | 161 } |
| 153 | 162 |
| 154 void PluginProxyTestHarness::SetUpHarness() { | 163 void PluginProxyTestHarness::SetUpHarness() { |
| 164 plugin_globals_.reset(new PluginGlobals(PpapiGlobals::ForTest())); |
| 165 |
| 155 // These must be first since the dispatcher set-up uses them. | 166 // These must be first since the dispatcher set-up uses them. |
| 156 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 167 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 157 resource_tracker().DidCreateInstance(pp_instance()); | 168 resource_tracker().DidCreateInstance(pp_instance()); |
| 158 | 169 |
| 159 plugin_dispatcher_.reset(new PluginDispatcher( | 170 plugin_dispatcher_.reset(new PluginDispatcher( |
| 160 &MockGetInterface, | 171 &MockGetInterface, |
| 161 false)); | 172 false)); |
| 162 plugin_dispatcher_->InitWithTestSink(&sink()); | 173 plugin_dispatcher_->InitWithTestSink(&sink()); |
| 163 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 174 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
| 175 // The plugin proxy delegate is needed for |
| 176 // |PluginProxyDelegate::GetBrowserSender| which is used |
| 177 // in |ResourceCreationProxy::GetConnection| to get the channel to the |
| 178 // browser. In this case we just use the |plugin_dispatcher_| as the channel |
| 179 // for test purposes. |
| 180 plugin_delegate_mock_.set_browser_sender(plugin_dispatcher_.get()); |
| 181 PluginGlobals::Get()->set_plugin_proxy_delegate(&plugin_delegate_mock_); |
| 164 } | 182 } |
| 165 | 183 |
| 166 void PluginProxyTestHarness::SetUpHarnessWithChannel( | 184 void PluginProxyTestHarness::SetUpHarnessWithChannel( |
| 167 const IPC::ChannelHandle& channel_handle, | 185 const IPC::ChannelHandle& channel_handle, |
| 168 base::MessageLoopProxy* ipc_message_loop, | 186 base::MessageLoopProxy* ipc_message_loop, |
| 169 base::WaitableEvent* shutdown_event, | 187 base::WaitableEvent* shutdown_event, |
| 170 bool is_client) { | 188 bool is_client) { |
| 189 plugin_globals_.reset(new PluginGlobals(PpapiGlobals::ForTest())); |
| 190 |
| 171 // These must be first since the dispatcher set-up uses them. | 191 // These must be first since the dispatcher set-up uses them. |
| 172 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 192 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 173 resource_tracker().DidCreateInstance(pp_instance()); | 193 resource_tracker().DidCreateInstance(pp_instance()); |
| 174 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); | 194 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); |
| 175 | 195 |
| 176 plugin_dispatcher_.reset(new PluginDispatcher( | 196 plugin_dispatcher_.reset(new PluginDispatcher( |
| 177 &MockGetInterface, | 197 &MockGetInterface, |
| 178 false)); | 198 false)); |
| 179 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, | 199 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, |
| 180 channel_handle, | 200 channel_handle, |
| 181 is_client); | 201 is_client); |
| 182 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 202 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
| 183 } | 203 } |
| 184 | 204 |
| 185 void PluginProxyTestHarness::TearDownHarness() { | 205 void PluginProxyTestHarness::TearDownHarness() { |
| 186 plugin_dispatcher_->DidDestroyInstance(pp_instance()); | 206 plugin_dispatcher_->DidDestroyInstance(pp_instance()); |
| 187 plugin_dispatcher_.reset(); | 207 plugin_dispatcher_.reset(); |
| 188 | 208 |
| 189 resource_tracker().DidDeleteInstance(pp_instance()); | 209 resource_tracker().DidDeleteInstance(pp_instance()); |
| 210 plugin_globals_.reset(); |
| 190 } | 211 } |
| 191 | 212 |
| 192 base::MessageLoopProxy* | 213 base::MessageLoopProxy* |
| 193 PluginProxyTestHarness::PluginDelegateMock::GetIPCMessageLoop() { | 214 PluginProxyTestHarness::PluginDelegateMock::GetIPCMessageLoop() { |
| 194 return ipc_message_loop_; | 215 return ipc_message_loop_; |
| 195 } | 216 } |
| 196 | 217 |
| 197 base::WaitableEvent* | 218 base::WaitableEvent* |
| 198 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { | 219 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { |
| 199 return shutdown_event_; | 220 return shutdown_event_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 223 uint32 plugin_dispatcher_id) { | 244 uint32 plugin_dispatcher_id) { |
| 224 } | 245 } |
| 225 | 246 |
| 226 bool PluginProxyTestHarness::PluginDelegateMock::SendToBrowser( | 247 bool PluginProxyTestHarness::PluginDelegateMock::SendToBrowser( |
| 227 IPC::Message* msg) { | 248 IPC::Message* msg) { |
| 228 NOTREACHED(); | 249 NOTREACHED(); |
| 229 return false; | 250 return false; |
| 230 } | 251 } |
| 231 | 252 |
| 232 IPC::Sender* PluginProxyTestHarness::PluginDelegateMock::GetBrowserSender() { | 253 IPC::Sender* PluginProxyTestHarness::PluginDelegateMock::GetBrowserSender() { |
| 233 NOTREACHED(); | 254 return browser_sender_; |
| 234 return NULL; | |
| 235 } | 255 } |
| 236 | 256 |
| 237 std::string PluginProxyTestHarness::PluginDelegateMock::GetUILanguage() { | 257 std::string PluginProxyTestHarness::PluginDelegateMock::GetUILanguage() { |
| 238 return std::string("en-US"); | 258 return std::string("en-US"); |
| 239 } | 259 } |
| 240 | 260 |
| 241 void PluginProxyTestHarness::PluginDelegateMock::PreCacheFont( | 261 void PluginProxyTestHarness::PluginDelegateMock::PreCacheFont( |
| 242 const void* logfontw) { | 262 const void* logfontw) { |
| 243 } | 263 } |
| 244 | 264 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 265 // HostProxyTestHarness -------------------------------------------------------- | 285 // HostProxyTestHarness -------------------------------------------------------- |
| 266 | 286 |
| 267 class HostProxyTestHarness::MockSyncMessageStatusReceiver | 287 class HostProxyTestHarness::MockSyncMessageStatusReceiver |
| 268 : public HostDispatcher::SyncMessageStatusReceiver { | 288 : public HostDispatcher::SyncMessageStatusReceiver { |
| 269 public: | 289 public: |
| 270 virtual void BeginBlockOnSyncMessage() OVERRIDE {} | 290 virtual void BeginBlockOnSyncMessage() OVERRIDE {} |
| 271 virtual void EndBlockOnSyncMessage() OVERRIDE {} | 291 virtual void EndBlockOnSyncMessage() OVERRIDE {} |
| 272 }; | 292 }; |
| 273 | 293 |
| 274 HostProxyTestHarness::HostProxyTestHarness() | 294 HostProxyTestHarness::HostProxyTestHarness() |
| 275 : host_globals_(PpapiGlobals::ForTest()), | 295 : status_receiver_(new MockSyncMessageStatusReceiver) { |
| 276 status_receiver_(new MockSyncMessageStatusReceiver) { | |
| 277 } | 296 } |
| 278 | 297 |
| 279 HostProxyTestHarness::~HostProxyTestHarness() { | 298 HostProxyTestHarness::~HostProxyTestHarness() { |
| 280 } | 299 } |
| 281 | 300 |
| 301 PpapiGlobals* HostProxyTestHarness::GetGlobals() { |
| 302 return host_globals_.get(); |
| 303 } |
| 304 |
| 282 Dispatcher* HostProxyTestHarness::GetDispatcher() { | 305 Dispatcher* HostProxyTestHarness::GetDispatcher() { |
| 283 return host_dispatcher_.get(); | 306 return host_dispatcher_.get(); |
| 284 } | 307 } |
| 285 | 308 |
| 286 void HostProxyTestHarness::SetUpHarness() { | 309 void HostProxyTestHarness::SetUpHarness() { |
| 310 host_globals_.reset(new ppapi::TestGlobals(PpapiGlobals::ForTest())); |
| 311 |
| 287 // These must be first since the dispatcher set-up uses them. | 312 // These must be first since the dispatcher set-up uses them. |
| 288 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 313 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 289 host_dispatcher_.reset(new HostDispatcher( | 314 host_dispatcher_.reset(new HostDispatcher( |
| 290 pp_module(), | 315 pp_module(), |
| 291 &MockGetInterface, | 316 &MockGetInterface, |
| 292 status_receiver_.release())); | 317 status_receiver_.release())); |
| 293 host_dispatcher_->InitWithTestSink(&sink()); | 318 host_dispatcher_->InitWithTestSink(&sink()); |
| 294 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 319 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| 295 } | 320 } |
| 296 | 321 |
| 297 void HostProxyTestHarness::SetUpHarnessWithChannel( | 322 void HostProxyTestHarness::SetUpHarnessWithChannel( |
| 298 const IPC::ChannelHandle& channel_handle, | 323 const IPC::ChannelHandle& channel_handle, |
| 299 base::MessageLoopProxy* ipc_message_loop, | 324 base::MessageLoopProxy* ipc_message_loop, |
| 300 base::WaitableEvent* shutdown_event, | 325 base::WaitableEvent* shutdown_event, |
| 301 bool is_client) { | 326 bool is_client) { |
| 327 host_globals_.reset(new ppapi::TestGlobals(PpapiGlobals::ForTest())); |
| 328 |
| 302 // These must be first since the dispatcher set-up uses them. | 329 // These must be first since the dispatcher set-up uses them. |
| 303 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 330 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 304 delegate_mock_.Init(ipc_message_loop, shutdown_event); | 331 delegate_mock_.Init(ipc_message_loop, shutdown_event); |
| 305 | 332 |
| 306 host_dispatcher_.reset(new HostDispatcher( | 333 host_dispatcher_.reset(new HostDispatcher( |
| 307 pp_module(), | 334 pp_module(), |
| 308 &MockGetInterface, | 335 &MockGetInterface, |
| 309 status_receiver_.release())); | 336 status_receiver_.release())); |
| 310 ppapi::Preferences preferences; | 337 ppapi::Preferences preferences; |
| 311 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, | 338 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, |
| 312 is_client, preferences); | 339 is_client, preferences); |
| 313 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 340 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| 314 } | 341 } |
| 315 | 342 |
| 316 void HostProxyTestHarness::TearDownHarness() { | 343 void HostProxyTestHarness::TearDownHarness() { |
| 317 HostDispatcher::RemoveForInstance(pp_instance()); | 344 HostDispatcher::RemoveForInstance(pp_instance()); |
| 318 host_dispatcher_.reset(); | 345 host_dispatcher_.reset(); |
| 346 host_globals_.reset(); |
| 319 } | 347 } |
| 320 | 348 |
| 321 base::MessageLoopProxy* | 349 base::MessageLoopProxy* |
| 322 HostProxyTestHarness::DelegateMock::GetIPCMessageLoop() { | 350 HostProxyTestHarness::DelegateMock::GetIPCMessageLoop() { |
| 323 return ipc_message_loop_; | 351 return ipc_message_loop_; |
| 324 } | 352 } |
| 325 | 353 |
| 326 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { | 354 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { |
| 327 return shutdown_event_; | 355 return shutdown_event_; |
| 328 } | 356 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 base::Bind(&TearDownRemoteHarness, | 436 base::Bind(&TearDownRemoteHarness, |
| 409 remote_harness_, | 437 remote_harness_, |
| 410 &remote_harness_torn_down)); | 438 &remote_harness_torn_down)); |
| 411 remote_harness_torn_down.Wait(); | 439 remote_harness_torn_down.Wait(); |
| 412 | 440 |
| 413 local_harness_->TearDownHarness(); | 441 local_harness_->TearDownHarness(); |
| 414 | 442 |
| 415 io_thread_.Stop(); | 443 io_thread_.Stop(); |
| 416 } | 444 } |
| 417 | 445 |
| 446 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { |
| 447 base::WaitableEvent task_complete(true, false); |
| 448 plugin_thread_.message_loop_proxy()->PostTask(FROM_HERE, |
| 449 base::Bind(&RunTaskOnRemoteHarness, |
| 450 task, |
| 451 &task_complete)); |
| 452 task_complete.Wait(); |
| 453 } |
| 454 |
| 455 |
| 418 } // namespace proxy | 456 } // namespace proxy |
| 419 } // namespace ppapi | 457 } // namespace ppapi |
| OLD | NEW |