Chromium Code Reviews| 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 if (!plugin_globals_.get()) | |
| 157 plugin_globals_.reset(new PluginGlobals(PpapiGlobals::ForTest())); | |
| 158 return plugin_globals_.get(); | |
|
dmichael (off chromium)
2012/09/17 15:27:29
What about explicitly setting it in SetUpHarness a
raymes
2012/09/18 21:29:15
Done.
| |
| 159 } | |
| 160 | |
| 150 Dispatcher* PluginProxyTestHarness::GetDispatcher() { | 161 Dispatcher* PluginProxyTestHarness::GetDispatcher() { |
| 151 return plugin_dispatcher_.get(); | 162 return plugin_dispatcher_.get(); |
| 152 } | 163 } |
| 153 | 164 |
| 154 void PluginProxyTestHarness::SetUpHarness() { | 165 void PluginProxyTestHarness::SetUpHarness() { |
| 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 // |PluginPepperDelegate::GetBrowserSender| which is used | |
|
dmichael (off chromium)
2012/09/17 15:27:29
PluginProxyDelegate
raymes
2012/09/18 21:29:15
Done.
| |
| 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) { |
| 171 // These must be first since the dispatcher set-up uses them. | 189 // These must be first since the dispatcher set-up uses them. |
| 172 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 190 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 173 resource_tracker().DidCreateInstance(pp_instance()); | 191 resource_tracker().DidCreateInstance(pp_instance()); |
| 174 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); | 192 plugin_delegate_mock_.Init(ipc_message_loop, shutdown_event); |
| 175 | 193 |
| 176 plugin_dispatcher_.reset(new PluginDispatcher( | 194 plugin_dispatcher_.reset(new PluginDispatcher( |
| 177 &MockGetInterface, | 195 &MockGetInterface, |
| 178 false)); | 196 false)); |
| 179 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, | 197 plugin_dispatcher_->InitPluginWithChannel(&plugin_delegate_mock_, |
| 180 channel_handle, | 198 channel_handle, |
| 181 is_client); | 199 is_client); |
| 182 plugin_dispatcher_->DidCreateInstance(pp_instance()); | 200 plugin_dispatcher_->DidCreateInstance(pp_instance()); |
| 183 } | 201 } |
| 184 | 202 |
| 185 void PluginProxyTestHarness::TearDownHarness() { | 203 void PluginProxyTestHarness::TearDownHarness() { |
| 186 plugin_dispatcher_->DidDestroyInstance(pp_instance()); | 204 plugin_dispatcher_->DidDestroyInstance(pp_instance()); |
| 187 plugin_dispatcher_.reset(); | 205 plugin_dispatcher_.reset(); |
| 188 | 206 |
| 189 resource_tracker().DidDeleteInstance(pp_instance()); | 207 resource_tracker().DidDeleteInstance(pp_instance()); |
| 208 plugin_globals_.reset(); | |
| 190 } | 209 } |
| 191 | 210 |
| 192 base::MessageLoopProxy* | 211 base::MessageLoopProxy* |
| 193 PluginProxyTestHarness::PluginDelegateMock::GetIPCMessageLoop() { | 212 PluginProxyTestHarness::PluginDelegateMock::GetIPCMessageLoop() { |
| 194 return ipc_message_loop_; | 213 return ipc_message_loop_; |
| 195 } | 214 } |
| 196 | 215 |
| 197 base::WaitableEvent* | 216 base::WaitableEvent* |
| 198 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { | 217 PluginProxyTestHarness::PluginDelegateMock::GetShutdownEvent() { |
| 199 return shutdown_event_; | 218 return shutdown_event_; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 223 uint32 plugin_dispatcher_id) { | 242 uint32 plugin_dispatcher_id) { |
| 224 } | 243 } |
| 225 | 244 |
| 226 bool PluginProxyTestHarness::PluginDelegateMock::SendToBrowser( | 245 bool PluginProxyTestHarness::PluginDelegateMock::SendToBrowser( |
| 227 IPC::Message* msg) { | 246 IPC::Message* msg) { |
| 228 NOTREACHED(); | 247 NOTREACHED(); |
| 229 return false; | 248 return false; |
| 230 } | 249 } |
| 231 | 250 |
| 232 IPC::Sender* PluginProxyTestHarness::PluginDelegateMock::GetBrowserSender() { | 251 IPC::Sender* PluginProxyTestHarness::PluginDelegateMock::GetBrowserSender() { |
| 233 NOTREACHED(); | 252 return browser_sender_; |
| 234 return NULL; | |
| 235 } | 253 } |
| 236 | 254 |
| 237 std::string PluginProxyTestHarness::PluginDelegateMock::GetUILanguage() { | 255 std::string PluginProxyTestHarness::PluginDelegateMock::GetUILanguage() { |
| 238 return std::string("en-US"); | 256 return std::string("en-US"); |
| 239 } | 257 } |
| 240 | 258 |
| 241 void PluginProxyTestHarness::PluginDelegateMock::PreCacheFont( | 259 void PluginProxyTestHarness::PluginDelegateMock::PreCacheFont( |
| 242 const void* logfontw) { | 260 const void* logfontw) { |
| 243 } | 261 } |
| 244 | 262 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 265 // HostProxyTestHarness -------------------------------------------------------- | 283 // HostProxyTestHarness -------------------------------------------------------- |
| 266 | 284 |
| 267 class HostProxyTestHarness::MockSyncMessageStatusReceiver | 285 class HostProxyTestHarness::MockSyncMessageStatusReceiver |
| 268 : public HostDispatcher::SyncMessageStatusReceiver { | 286 : public HostDispatcher::SyncMessageStatusReceiver { |
| 269 public: | 287 public: |
| 270 virtual void BeginBlockOnSyncMessage() OVERRIDE {} | 288 virtual void BeginBlockOnSyncMessage() OVERRIDE {} |
| 271 virtual void EndBlockOnSyncMessage() OVERRIDE {} | 289 virtual void EndBlockOnSyncMessage() OVERRIDE {} |
| 272 }; | 290 }; |
| 273 | 291 |
| 274 HostProxyTestHarness::HostProxyTestHarness() | 292 HostProxyTestHarness::HostProxyTestHarness() |
| 275 : host_globals_(PpapiGlobals::ForTest()), | 293 : status_receiver_(new MockSyncMessageStatusReceiver) { |
| 276 status_receiver_(new MockSyncMessageStatusReceiver) { | |
| 277 } | 294 } |
| 278 | 295 |
| 279 HostProxyTestHarness::~HostProxyTestHarness() { | 296 HostProxyTestHarness::~HostProxyTestHarness() { |
| 280 } | 297 } |
| 281 | 298 |
| 299 PpapiGlobals* HostProxyTestHarness::GetGlobals() { | |
| 300 if (!host_globals_.get()) | |
| 301 host_globals_.reset(new ppapi::TestGlobals(PpapiGlobals::ForTest())); | |
| 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() { |
| 287 // These must be first since the dispatcher set-up uses them. | 310 // These must be first since the dispatcher set-up uses them. |
| 288 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); | 311 PpapiGlobals::SetPpapiGlobalsOnThreadForTest(GetGlobals()); |
| 289 host_dispatcher_.reset(new HostDispatcher( | 312 host_dispatcher_.reset(new HostDispatcher( |
| 290 pp_module(), | 313 pp_module(), |
| 291 &MockGetInterface, | 314 &MockGetInterface, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 309 status_receiver_.release())); | 332 status_receiver_.release())); |
| 310 ppapi::Preferences preferences; | 333 ppapi::Preferences preferences; |
| 311 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, | 334 host_dispatcher_->InitHostWithChannel(&delegate_mock_, channel_handle, |
| 312 is_client, preferences); | 335 is_client, preferences); |
| 313 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); | 336 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| 314 } | 337 } |
| 315 | 338 |
| 316 void HostProxyTestHarness::TearDownHarness() { | 339 void HostProxyTestHarness::TearDownHarness() { |
| 317 HostDispatcher::RemoveForInstance(pp_instance()); | 340 HostDispatcher::RemoveForInstance(pp_instance()); |
| 318 host_dispatcher_.reset(); | 341 host_dispatcher_.reset(); |
| 342 host_globals_.reset(); | |
| 319 } | 343 } |
| 320 | 344 |
| 321 base::MessageLoopProxy* | 345 base::MessageLoopProxy* |
| 322 HostProxyTestHarness::DelegateMock::GetIPCMessageLoop() { | 346 HostProxyTestHarness::DelegateMock::GetIPCMessageLoop() { |
| 323 return ipc_message_loop_; | 347 return ipc_message_loop_; |
| 324 } | 348 } |
| 325 | 349 |
| 326 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { | 350 base::WaitableEvent* HostProxyTestHarness::DelegateMock::GetShutdownEvent() { |
| 327 return shutdown_event_; | 351 return shutdown_event_; |
| 328 } | 352 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 base::Bind(&TearDownRemoteHarness, | 432 base::Bind(&TearDownRemoteHarness, |
| 409 remote_harness_, | 433 remote_harness_, |
| 410 &remote_harness_torn_down)); | 434 &remote_harness_torn_down)); |
| 411 remote_harness_torn_down.Wait(); | 435 remote_harness_torn_down.Wait(); |
| 412 | 436 |
| 413 local_harness_->TearDownHarness(); | 437 local_harness_->TearDownHarness(); |
| 414 | 438 |
| 415 io_thread_.Stop(); | 439 io_thread_.Stop(); |
| 416 } | 440 } |
| 417 | 441 |
| 442 void TwoWayTest::PostTaskOnRemoteHarness(const base::Closure& task) { | |
| 443 base::WaitableEvent task_complete(true, false); | |
| 444 plugin_thread_.message_loop_proxy()->PostTask(FROM_HERE, | |
| 445 base::Bind(&RunTaskOnRemoteHarness, | |
| 446 task, | |
| 447 &task_complete)); | |
| 448 task_complete.Wait(); | |
| 449 } | |
| 450 | |
| 451 | |
| 418 } // namespace proxy | 452 } // namespace proxy |
| 419 } // namespace ppapi | 453 } // namespace ppapi |
| OLD | NEW |