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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 8
9 namespace pp { 9 namespace pp {
10 namespace proxy { 10 namespace proxy {
11 11
12 namespace { 12 namespace {
13 13
14 const void* MockGetInterface(const char*) { 14 ProxyTestBase* current_test = NULL;
15 return NULL; 15
16 const void* MockGetInterface(const char* name) {
17 if (!current_test) {
18 NOTREACHED();
19 return NULL;
20 }
21 return current_test->GetInterface(name);
16 } 22 }
17 23
18 int32_t MockInitModule(PP_Module, Dispatcher::GetInterfaceFunc) { 24 int32_t MockInitModule(PP_Module, Dispatcher::GetInterfaceFunc) {
19 return PP_OK; 25 return PP_OK;
20 } 26 }
21 27
22 void MockShutdownModuleFunc() { 28 void MockShutdownModuleFunc() {
23 } 29 }
24 30
25 } // namespace 31 } // namespace
26 32
33 // ProxyTestBase ---------------------------------------------------------------
34
35 ProxyTestBase::ProxyTestBase() : pp_module_(0x98765), pp_instance_(0x12345) {
36 DCHECK(!current_test);
37 current_test = this;
38 }
39
40 ProxyTestBase::~ProxyTestBase() {
41 DCHECK(current_test == this);
42 current_test = NULL;
43 }
44
45 const void* ProxyTestBase::GetInterface(const char* name) {
46 return registered_interfaces_[name];
47 }
48
49 void ProxyTestBase::RegisterTestInterface(const char* name,
50 const void* interface) {
51 registered_interfaces_[name] = interface;
52 }
53
54 bool ProxyTestBase::SupportsInterface(const char* name) {
55 sink().ClearMessages();
56
57 // IPC doesn't actually write to this when we send a message manually
58 // not actually using IPC.
59 bool unused_result = false;
60 PpapiMsg_SupportsInterface msg(name, &unused_result);
61 plugin_dispatcher()->OnMessageReceived(msg);
62
63 const IPC::Message* reply_msg =
64 sink().GetUniqueMessageMatching(IPC_REPLY_ID);
65 EXPECT_TRUE(reply_msg);
66 if (!reply_msg)
67 return false;
68
69 TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data;
70 EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam(
71 reply_msg, &reply_data));
72
73 sink().ClearMessages();
74 return reply_data.a;
75 }
76
77 // PluginProxyTest -------------------------------------------------------------
78
27 PluginProxyTest::PluginProxyTest() { 79 PluginProxyTest::PluginProxyTest() {
28 } 80 }
29 81
30 PluginProxyTest::~PluginProxyTest() { 82 PluginProxyTest::~PluginProxyTest() {
31 } 83 }
32 84
85 Dispatcher* PluginProxyTest::GetDispatcher() {
86 return plugin_dispatcher_.get();
87 }
88
33 void PluginProxyTest::SetUp() { 89 void PluginProxyTest::SetUp() {
34 // These must be first since the dispatcher set-up uses them. 90 // These must be first since the dispatcher set-up uses them.
35 PluginResourceTracker::SetInstanceForTest(&resource_tracker_); 91 PluginResourceTracker::SetInstanceForTest(&resource_tracker_);
36 PluginVarTracker::SetInstanceForTest(&var_tracker_); 92 PluginVarTracker::SetInstanceForTest(&var_tracker_);
37 93
38 pp_instance_ = 0x1234;
39 plugin_dispatcher_.reset(new PluginDispatcher( 94 plugin_dispatcher_.reset(new PluginDispatcher(
40 base::Process::Current().handle(), 95 base::Process::Current().handle(),
41 &MockGetInterface, 96 &MockGetInterface,
42 &MockInitModule, 97 &MockInitModule,
43 &MockShutdownModuleFunc)); 98 &MockShutdownModuleFunc));
44 plugin_dispatcher_->InitWithTestSink(&sink_); 99 plugin_dispatcher_->InitWithTestSink(&sink());
45 // When the plugin dispatcher is per-instance, this is the line to use: 100 plugin_dispatcher_->DidCreateInstance(pp_instance());
46 // PluginDispatcher::SetForInstance(pp_instance_, plugin_dispatcher_.get());
47 PluginDispatcher::SetGlobal(plugin_dispatcher_.get());
48 } 101 }
49 102
50 void PluginProxyTest::TearDown() { 103 void PluginProxyTest::TearDown() {
51 PluginDispatcher::SetGlobal(NULL); 104 plugin_dispatcher_->DidDestroyInstance(pp_instance());
52 plugin_dispatcher_.reset(); 105 plugin_dispatcher_.reset();
53 106
54 PluginVarTracker::SetInstanceForTest(NULL); 107 PluginVarTracker::SetInstanceForTest(NULL);
55 PluginResourceTracker::SetInstanceForTest(NULL); 108 PluginResourceTracker::SetInstanceForTest(NULL);
56 } 109 }
57 110
111 // HostProxyTest ---------------------------------------------------------------
112
113 HostProxyTest::HostProxyTest() {
114 }
115
116 HostProxyTest::~HostProxyTest() {
117 }
118
119 Dispatcher* HostProxyTest::GetDispatcher() {
120 return host_dispatcher_.get();
121 }
122
123 void HostProxyTest::SetUp() {
124 host_dispatcher_.reset(new HostDispatcher(
125 base::Process::Current().handle(),
126 pp_module(),
127 &MockGetInterface));
128 host_dispatcher_->InitWithTestSink(&sink());
129 HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get());
130 }
131
132 void HostProxyTest::TearDown() {
133 HostDispatcher::RemoveForInstance(pp_instance());
134 host_dispatcher_.reset();
135 }
136
58 } // namespace proxy 137 } // namespace proxy
59 } // namespace pp 138 } // namespace pp
OLDNEW
« 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