Chromium Code Reviews| Index: ppapi/proxy/ppapi_proxy_test.cc |
| =================================================================== |
| --- ppapi/proxy/ppapi_proxy_test.cc (revision 73960) |
| +++ ppapi/proxy/ppapi_proxy_test.cc (working copy) |
| @@ -11,8 +11,14 @@ |
| namespace { |
| -const void* MockGetInterface(const char*) { |
| - return NULL; |
| +ProxyTestBase* current_test = NULL; |
| + |
| +const void* MockGetInterface(const char* name) { |
| + if (!current_test) { |
| + NOTREACHED(); |
| + return NULL; |
| + } |
| + return current_test->GetInterface(name); |
| } |
| int32_t MockInitModule(PP_Module, Dispatcher::GetInterfaceFunc) { |
| @@ -24,36 +30,109 @@ |
| } // namespace |
| +// ProxyTestBase --------------------------------------------------------------- |
| + |
| +ProxyTestBase::ProxyTestBase() : pp_module_(0x98765), pp_instance_(0x12345) { |
| + DCHECK(!current_test); |
| + current_test = this; |
| +} |
| + |
| +ProxyTestBase::~ProxyTestBase() { |
| + DCHECK(current_test == this); |
| + current_test = NULL; |
| +} |
| + |
| +const void* ProxyTestBase::GetInterface(const char* name) { |
| + return registered_interfaces_[name]; |
| +} |
| + |
| +void ProxyTestBase::RegisterTestInterface(const char* name, |
| + const void* interface) { |
| + registered_interfaces_[name] = interface; |
| +} |
| + |
| +bool ProxyTestBase::SupportsInterface(const char* name) { |
| + sink().ClearMessages(); |
| + |
| + // IPC doesn't actually write to this when we send a message manually |
| + // not actually using IPC. |
| + bool unused_result = false; |
| + PpapiMsg_SupportsInterface msg(name, &unused_result); |
| + plugin_dispatcher()->OnMessageReceived(msg); |
| + |
| + const IPC::Message* reply_msg = |
| + sink().GetUniqueMessageMatching(IPC_REPLY_ID); |
| + EXPECT_TRUE(reply_msg); |
| + if (!reply_msg) |
| + return false; |
| + |
| + TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data; |
| + EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam( |
| + reply_msg, &reply_data)); |
| + |
| + sink().ClearMessages(); |
| + return reply_data.a; |
| +} |
| + |
| +// PluginProxyTes -------------------------------------------------------------- |
|
piman
2011/02/07 21:29:22
typo: PluginProxyTest
|
| + |
| PluginProxyTest::PluginProxyTest() { |
| } |
| PluginProxyTest::~PluginProxyTest() { |
| } |
| +Dispatcher* PluginProxyTest::GetDispatcher() { |
| + return plugin_dispatcher_.get(); |
| +} |
| + |
| void PluginProxyTest::SetUp() { |
| // These must be first since the dispatcher set-up uses them. |
| PluginResourceTracker::SetInstanceForTest(&resource_tracker_); |
| PluginVarTracker::SetInstanceForTest(&var_tracker_); |
| - pp_instance_ = 0x1234; |
| plugin_dispatcher_.reset(new PluginDispatcher( |
| base::Process::Current().handle(), |
| &MockGetInterface, |
| &MockInitModule, |
| &MockShutdownModuleFunc)); |
| - plugin_dispatcher_->InitWithTestSink(&sink_); |
| - // When the plugin dispatcher is per-instance, this is the line to use: |
| - // PluginDispatcher::SetForInstance(pp_instance_, plugin_dispatcher_.get()); |
| - PluginDispatcher::SetGlobal(plugin_dispatcher_.get()); |
| + plugin_dispatcher_->InitWithTestSink(&sink()); |
| + PluginDispatcher::SetForInstance(pp_instance(), plugin_dispatcher_.get()); |
| } |
| void PluginProxyTest::TearDown() { |
| - PluginDispatcher::SetGlobal(NULL); |
| + PluginDispatcher::RemoveForInstance(pp_instance()); |
| plugin_dispatcher_.reset(); |
| PluginVarTracker::SetInstanceForTest(NULL); |
| PluginResourceTracker::SetInstanceForTest(NULL); |
| } |
| +// HostProxyTest --------------------------------------------------------------- |
| + |
| +HostProxyTest::HostProxyTest() { |
| +} |
| + |
| +HostProxyTest::~HostProxyTest() { |
| +} |
| + |
| +Dispatcher* HostProxyTest::GetDispatcher() { |
| + return host_dispatcher_.get(); |
| +} |
| + |
| +void HostProxyTest::SetUp() { |
| + host_dispatcher_.reset(new HostDispatcher( |
| + base::Process::Current().handle(), |
| + pp_module(), |
| + &MockGetInterface)); |
| + host_dispatcher_->InitWithTestSink(&sink()); |
| + HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get()); |
| +} |
| + |
| +void HostProxyTest::TearDown() { |
| + HostDispatcher::RemoveForInstance(pp_instance()); |
| + host_dispatcher_.reset(); |
| +} |
| + |
| } // namespace proxy |
| } // namespace pp |