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

Side by Side Diff: ppapi/proxy/ppapi_proxy_test.h

Issue 10913258: Various fixes to make ppapi_unittests pass again. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 | « no previous file | ppapi/proxy/ppapi_proxy_test.cc » ('j') | ppapi/proxy/ppapi_proxy_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 16 matching lines...) Expand all
27 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. 27 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest.
28 class ProxyTestHarnessBase { 28 class ProxyTestHarnessBase {
29 public: 29 public:
30 ProxyTestHarnessBase(); 30 ProxyTestHarnessBase();
31 virtual ~ProxyTestHarnessBase(); 31 virtual ~ProxyTestHarnessBase();
32 32
33 PP_Module pp_module() const { return pp_module_; } 33 PP_Module pp_module() const { return pp_module_; }
34 PP_Instance pp_instance() const { return pp_instance_; } 34 PP_Instance pp_instance() const { return pp_instance_; }
35 ResourceMessageTestSink& sink() { return sink_; } 35 ResourceMessageTestSink& sink() { return sink_; }
36 36
37 // This should lazily initialize the globals so they are constructed on
38 // the thread of use.
37 virtual PpapiGlobals* GetGlobals() = 0; 39 virtual PpapiGlobals* GetGlobals() = 0;
38 // Returns either the plugin or host dispatcher, depending on the test. 40 // Returns either the plugin or host dispatcher, depending on the test.
39 virtual Dispatcher* GetDispatcher() = 0; 41 virtual Dispatcher* GetDispatcher() = 0;
40 42
41 // Set up the harness using an IPC::TestSink to capture messages. 43 // Set up the harness using an IPC::TestSink to capture messages.
42 virtual void SetUpHarness() = 0; 44 virtual void SetUpHarness() = 0;
43 45
44 // Set up the harness using a real IPC channel. 46 // Set up the harness using a real IPC channel.
45 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, 47 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
46 base::MessageLoopProxy* ipc_message_loop, 48 base::MessageLoopProxy* ipc_message_loop,
(...skipping 29 matching lines...) Expand all
76 }; 78 };
77 79
78 // Test harness for the plugin side of the proxy. 80 // Test harness for the plugin side of the proxy.
79 class PluginProxyTestHarness : public ProxyTestHarnessBase { 81 class PluginProxyTestHarness : public ProxyTestHarnessBase {
80 public: 82 public:
81 PluginProxyTestHarness(); 83 PluginProxyTestHarness();
82 virtual ~PluginProxyTestHarness(); 84 virtual ~PluginProxyTestHarness();
83 85
84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } 86 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
85 PluginResourceTracker& resource_tracker() { 87 PluginResourceTracker& resource_tracker() {
86 return *plugin_globals_.plugin_resource_tracker(); 88 return *plugin_globals_->plugin_resource_tracker();
87 } 89 }
88 PluginVarTracker& var_tracker() { 90 PluginVarTracker& var_tracker() {
89 return *plugin_globals_.plugin_var_tracker(); 91 return *plugin_globals_->plugin_var_tracker();
90 } 92 }
91 93
92 // ProxyTestHarnessBase implementation. 94 // ProxyTestHarnessBase implementation.
93 virtual PpapiGlobals* GetGlobals() { return &plugin_globals_; } 95 virtual PpapiGlobals* GetGlobals();
94 virtual Dispatcher* GetDispatcher(); 96 virtual Dispatcher* GetDispatcher();
95 virtual void SetUpHarness(); 97 virtual void SetUpHarness();
96 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, 98 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
97 base::MessageLoopProxy* ipc_message_loop, 99 base::MessageLoopProxy* ipc_message_loop,
98 base::WaitableEvent* shutdown_event, 100 base::WaitableEvent* shutdown_event,
99 bool is_client); 101 bool is_client);
100 virtual void TearDownHarness(); 102 virtual void TearDownHarness();
101 103
102 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, 104 class PluginDelegateMock : public PluginDispatcher::PluginDelegate,
103 public PluginProxyDelegate { 105 public PluginProxyDelegate {
104 public: 106 public:
105 PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {} 107 PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {}
106 virtual ~PluginDelegateMock() {} 108 virtual ~PluginDelegateMock() {}
107 109
108 void Init(base::MessageLoopProxy* ipc_message_loop, 110 void Init(base::MessageLoopProxy* ipc_message_loop,
109 base::WaitableEvent* shutdown_event) { 111 base::WaitableEvent* shutdown_event) {
110 ipc_message_loop_ = ipc_message_loop; 112 ipc_message_loop_ = ipc_message_loop;
111 shutdown_event_ = shutdown_event; 113 shutdown_event_ = shutdown_event;
112 } 114 }
113 115
116 void set_browser_sender(IPC::Sender* browser_sender) {
117 browser_sender_ = browser_sender;
118 }
119
114 // ProxyChannel::Delegate implementation. 120 // ProxyChannel::Delegate implementation.
115 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE; 121 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE;
116 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE; 122 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE;
117 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( 123 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
118 base::PlatformFile handle, 124 base::PlatformFile handle,
119 const IPC::SyncChannel& /* channel */, 125 const IPC::SyncChannel& /* channel */,
120 bool should_close_source) OVERRIDE; 126 bool should_close_source) OVERRIDE;
121 127
122 // PluginDispatcher::PluginDelegate implementation. 128 // PluginDispatcher::PluginDelegate implementation.
123 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE; 129 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE;
124 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE; 130 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE;
125 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE; 131 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE;
126 132
127 // PluginPepperDelegate implementation. 133 // PluginPepperDelegate implementation.
dmichael (off chromium) 2012/09/17 15:27:29 Can you change this to say PluginProxyDelegate, si
raymes 2012/09/18 21:29:15 Done.
128 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE; 134 virtual bool SendToBrowser(IPC::Message* msg) OVERRIDE;
129 virtual IPC::Sender* GetBrowserSender() OVERRIDE; 135 virtual IPC::Sender* GetBrowserSender() OVERRIDE;
130 virtual std::string GetUILanguage() OVERRIDE; 136 virtual std::string GetUILanguage() OVERRIDE;
131 virtual void PreCacheFont(const void* logfontw) OVERRIDE; 137 virtual void PreCacheFont(const void* logfontw) OVERRIDE;
132 virtual void SetActiveURL(const std::string& url) OVERRIDE; 138 virtual void SetActiveURL(const std::string& url) OVERRIDE;
133 139
134 private: 140 private:
135 base::MessageLoopProxy* ipc_message_loop_; // Weak 141 base::MessageLoopProxy* ipc_message_loop_; // Weak
136 base::WaitableEvent* shutdown_event_; // Weak 142 base::WaitableEvent* shutdown_event_; // Weak
137 std::set<PP_Instance> instance_id_set_; 143 std::set<PP_Instance> instance_id_set_;
144 IPC::Sender* browser_sender_;
138 145
139 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); 146 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock);
140 }; 147 };
141 148
142 private: 149 private:
143 PluginGlobals plugin_globals_; 150 scoped_ptr<PluginGlobals> plugin_globals_;
144 151
145 scoped_ptr<PluginDispatcher> plugin_dispatcher_; 152 scoped_ptr<PluginDispatcher> plugin_dispatcher_;
146 PluginDelegateMock plugin_delegate_mock_; 153 PluginDelegateMock plugin_delegate_mock_;
147 }; 154 };
148 155
149 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { 156 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test {
150 public: 157 public:
151 PluginProxyTest(); 158 PluginProxyTest();
152 virtual ~PluginProxyTest(); 159 virtual ~PluginProxyTest();
153 160
154 // testing::Test implementation. 161 // testing::Test implementation.
155 virtual void SetUp(); 162 virtual void SetUp();
156 virtual void TearDown(); 163 virtual void TearDown();
157 private: 164 private:
158 MessageLoop message_loop_; 165 MessageLoop message_loop_;
159 }; 166 };
160 167
161 class HostProxyTestHarness : public ProxyTestHarnessBase { 168 class HostProxyTestHarness : public ProxyTestHarnessBase {
162 public: 169 public:
163 HostProxyTestHarness(); 170 HostProxyTestHarness();
164 virtual ~HostProxyTestHarness(); 171 virtual ~HostProxyTestHarness();
165 172
166 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } 173 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }
167 ResourceTracker& resource_tracker() { 174 ResourceTracker& resource_tracker() {
168 return *host_globals_.GetResourceTracker(); 175 return *host_globals_->GetResourceTracker();
169 } 176 }
170 VarTracker& var_tracker() { 177 VarTracker& var_tracker() {
171 return *host_globals_.GetVarTracker(); 178 return *host_globals_->GetVarTracker();
172 } 179 }
173 180
174 // ProxyTestBase implementation. 181 // ProxyTestBase implementation.
175 virtual PpapiGlobals* GetGlobals() { return &host_globals_; } 182 virtual PpapiGlobals* GetGlobals();
176 virtual Dispatcher* GetDispatcher(); 183 virtual Dispatcher* GetDispatcher();
177 virtual void SetUpHarness(); 184 virtual void SetUpHarness();
178 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, 185 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
179 base::MessageLoopProxy* ipc_message_loop, 186 base::MessageLoopProxy* ipc_message_loop,
180 base::WaitableEvent* shutdown_event, 187 base::WaitableEvent* shutdown_event,
181 bool is_client); 188 bool is_client);
182 virtual void TearDownHarness(); 189 virtual void TearDownHarness();
183 190
184 class DelegateMock : public ProxyChannel::Delegate { 191 class DelegateMock : public ProxyChannel::Delegate {
185 public: 192 public:
(...skipping 18 matching lines...) Expand all
204 private: 211 private:
205 base::MessageLoopProxy* ipc_message_loop_; // Weak 212 base::MessageLoopProxy* ipc_message_loop_; // Weak
206 base::WaitableEvent* shutdown_event_; // Weak 213 base::WaitableEvent* shutdown_event_; // Weak
207 214
208 DISALLOW_COPY_AND_ASSIGN(DelegateMock); 215 DISALLOW_COPY_AND_ASSIGN(DelegateMock);
209 }; 216 };
210 217
211 private: 218 private:
212 class MockSyncMessageStatusReceiver; 219 class MockSyncMessageStatusReceiver;
213 220
214 ppapi::TestGlobals host_globals_; 221 scoped_ptr<ppapi::TestGlobals> host_globals_;
215 scoped_ptr<HostDispatcher> host_dispatcher_; 222 scoped_ptr<HostDispatcher> host_dispatcher_;
216 DelegateMock delegate_mock_; 223 DelegateMock delegate_mock_;
217 224
218 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_; 225 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_;
219 }; 226 };
220 227
221 class HostProxyTest : public HostProxyTestHarness, public testing::Test { 228 class HostProxyTest : public HostProxyTestHarness, public testing::Test {
222 public: 229 public:
223 HostProxyTest(); 230 HostProxyTest();
224 virtual ~HostProxyTest(); 231 virtual ~HostProxyTest();
(...skipping 18 matching lines...) Expand all
243 HostProxyTestHarness& host() { return host_; } 250 HostProxyTestHarness& host() { return host_; }
244 PluginProxyTestHarness& plugin() { return plugin_; } 251 PluginProxyTestHarness& plugin() { return plugin_; }
245 PP_Module pp_module() const { return host_.pp_module(); } 252 PP_Module pp_module() const { return host_.pp_module(); }
246 PP_Instance pp_instance() const { return host_.pp_instance(); } 253 PP_Instance pp_instance() const { return host_.pp_instance(); }
247 TwoWayTestMode test_mode() { return test_mode_; } 254 TwoWayTestMode test_mode() { return test_mode_; }
248 255
249 // testing::Test implementation. 256 // testing::Test implementation.
250 virtual void SetUp(); 257 virtual void SetUp();
251 virtual void TearDown(); 258 virtual void TearDown();
252 259
260 protected:
261 // Post a task to the thread where the remote harness lives. This
262 // is typically used to test the state of the var tracker on the plugin
263 // thread. This runs the task synchronously for convenience.
264 void PostTaskOnRemoteHarness(const base::Closure& task);
265
253 private: 266 private:
254 TwoWayTestMode test_mode_; 267 TwoWayTestMode test_mode_;
255 HostProxyTestHarness host_; 268 HostProxyTestHarness host_;
256 PluginProxyTestHarness plugin_; 269 PluginProxyTestHarness plugin_;
257 // In order to use sync IPC, we need to have an IO thread. 270 // In order to use sync IPC, we need to have an IO thread.
258 base::Thread io_thread_; 271 base::Thread io_thread_;
259 // The plugin side of the proxy runs on its own thread. 272 // The plugin side of the proxy runs on its own thread.
260 base::Thread plugin_thread_; 273 base::Thread plugin_thread_;
261 // The message loop for the main (host) thread. 274 // The message loop for the main (host) thread.
262 MessageLoop message_loop_; 275 MessageLoop message_loop_;
(...skipping 15 matching lines...) Expand all
278 // EXPECT_VAR_IS_STRING("foo", my_var); 291 // EXPECT_VAR_IS_STRING("foo", my_var);
279 #define EXPECT_VAR_IS_STRING(str, var) { \ 292 #define EXPECT_VAR_IS_STRING(str, var) { \
280 StringVar* sv = StringVar::FromPPVar(var); \ 293 StringVar* sv = StringVar::FromPPVar(var); \
281 EXPECT_TRUE(sv); \ 294 EXPECT_TRUE(sv); \
282 if (sv) \ 295 if (sv) \
283 EXPECT_EQ(str, sv->value()); \ 296 EXPECT_EQ(str, sv->value()); \
284 } 297 }
285 298
286 } // namespace proxy 299 } // namespace proxy
287 } // namespace ppapi 300 } // namespace ppapi
OLDNEW
« no previous file with comments | « no previous file | ppapi/proxy/ppapi_proxy_test.cc » ('j') | ppapi/proxy/ppapi_proxy_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698