Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: ppapi/proxy/ppapi_proxy_test.cc

Issue 6286070: Remove all uses of the global Dispatcher Get function. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/ppapi_proxy_test.h ('k') | ppapi/proxy/ppb_audio_config_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/ppapi_proxy_test.cc
===================================================================
--- ppapi/proxy/ppapi_proxy_test.cc (revision 74021)
+++ 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;
+}
+
+// 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());
+ plugin_dispatcher_->DidCreateInstance(pp_instance());
}
void PluginProxyTest::TearDown() {
- PluginDispatcher::SetGlobal(NULL);
+ plugin_dispatcher_->DidDestroyInstance(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
« no previous file with comments | « ppapi/proxy/ppapi_proxy_test.h ('k') | ppapi/proxy/ppb_audio_config_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698