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

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

Issue 11859015: Pepper: Introduce ThreadAwareCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and update tests accordingly. Created 7 years, 11 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
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/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 11 #include "base/message_loop.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/simple_thread.h"
11 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
12 #include "ppapi/c/pp_instance.h" 15 #include "ppapi/c/pp_instance.h"
13 #include "ppapi/proxy/host_dispatcher.h" 16 #include "ppapi/proxy/host_dispatcher.h"
14 #include "ppapi/proxy/plugin_dispatcher.h" 17 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/plugin_globals.h" 18 #include "ppapi/proxy/plugin_globals.h"
16 #include "ppapi/proxy/plugin_proxy_delegate.h" 19 #include "ppapi/proxy/plugin_proxy_delegate.h"
17 #include "ppapi/proxy/plugin_resource_tracker.h" 20 #include "ppapi/proxy/plugin_resource_tracker.h"
18 #include "ppapi/proxy/plugin_var_tracker.h" 21 #include "ppapi/proxy/plugin_var_tracker.h"
19 #include "ppapi/proxy/resource_message_test_sink.h" 22 #include "ppapi/proxy/resource_message_test_sink.h"
20 #include "ppapi/shared_impl/test_globals.h" 23 #include "ppapi/shared_impl/test_globals.h"
21 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
22 25
26 namespace base {
27 class MessageLoopProxy;
28 class RunLoop;
29 }
30
23 namespace ppapi { 31 namespace ppapi {
24 namespace proxy { 32 namespace proxy {
25 33
34 class MessageLoopResource;
35
26 // Base class for plugin and host test harnesses. Tests will not use this 36 // Base class for plugin and host test harnesses. Tests will not use this
27 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. 37 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest.
28 class ProxyTestHarnessBase { 38 class ProxyTestHarnessBase {
29 public: 39 public:
30 ProxyTestHarnessBase(); 40 ProxyTestHarnessBase();
31 virtual ~ProxyTestHarnessBase(); 41 virtual ~ProxyTestHarnessBase();
32 42
33 PP_Module pp_module() const { return pp_module_; } 43 PP_Module pp_module() const { return pp_module_; }
34 PP_Instance pp_instance() const { return pp_instance_; } 44 PP_Instance pp_instance() const { return pp_instance_; }
35 ResourceMessageTestSink& sink() { return sink_; } 45 ResourceMessageTestSink& sink() { return sink_; }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 PP_Module pp_module_; 81 PP_Module pp_module_;
72 PP_Instance pp_instance_; 82 PP_Instance pp_instance_;
73 83
74 // Stores the data for GetInterface/RegisterTestInterface. 84 // Stores the data for GetInterface/RegisterTestInterface.
75 std::map<std::string, const void*> registered_interfaces_; 85 std::map<std::string, const void*> registered_interfaces_;
76 }; 86 };
77 87
78 // Test harness for the plugin side of the proxy. 88 // Test harness for the plugin side of the proxy.
79 class PluginProxyTestHarness : public ProxyTestHarnessBase { 89 class PluginProxyTestHarness : public ProxyTestHarnessBase {
80 public: 90 public:
81 PluginProxyTestHarness(); 91 explicit PluginProxyTestHarness(bool per_thread_globals);
dmichael (off chromium) 2013/01/15 22:43:52 I almost always prefer a simple enum over bool for
yzshen1 2013/01/16 18:55:59 Done.
82 virtual ~PluginProxyTestHarness(); 92 virtual ~PluginProxyTestHarness();
83 93
84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } 94 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
85 PluginResourceTracker& resource_tracker() { 95 PluginResourceTracker& resource_tracker() {
86 return *plugin_globals_->plugin_resource_tracker(); 96 return *plugin_globals_->plugin_resource_tracker();
87 } 97 }
88 PluginVarTracker& var_tracker() { 98 PluginVarTracker& var_tracker() {
89 return *plugin_globals_->plugin_var_tracker(); 99 return *plugin_globals_->plugin_var_tracker();
90 } 100 }
91 101
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 private: 147 private:
138 base::MessageLoopProxy* ipc_message_loop_; // Weak 148 base::MessageLoopProxy* ipc_message_loop_; // Weak
139 base::WaitableEvent* shutdown_event_; // Weak 149 base::WaitableEvent* shutdown_event_; // Weak
140 std::set<PP_Instance> instance_id_set_; 150 std::set<PP_Instance> instance_id_set_;
141 IPC::Sender* browser_sender_; 151 IPC::Sender* browser_sender_;
142 152
143 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); 153 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock);
144 }; 154 };
145 155
146 private: 156 private:
157 void CreatePluginGlobals();
158
159 bool per_thread_globals_;
147 scoped_ptr<PluginGlobals> plugin_globals_; 160 scoped_ptr<PluginGlobals> plugin_globals_;
148 161
149 scoped_ptr<PluginDispatcher> plugin_dispatcher_; 162 scoped_ptr<PluginDispatcher> plugin_dispatcher_;
150 PluginDelegateMock plugin_delegate_mock_; 163 PluginDelegateMock plugin_delegate_mock_;
151 }; 164 };
152 165
153 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { 166 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test {
154 public: 167 public:
155 PluginProxyTest(); 168 PluginProxyTest();
156 virtual ~PluginProxyTest(); 169 virtual ~PluginProxyTest();
157 170
158 // testing::Test implementation. 171 // testing::Test implementation.
159 virtual void SetUp(); 172 virtual void SetUp();
160 virtual void TearDown(); 173 virtual void TearDown();
161 private: 174 private:
162 MessageLoop message_loop_; 175 MessageLoop message_loop_;
163 }; 176 };
164 177
178 // This class provides support for multi-thread testing. A secondary thread is
179 // created with a Pepper message loop.
180 // Subclasses need to implement the two SetUpTestOn*Thread() methods to do the
181 // actual testing work; and call both PostQuitFor*Thread() when testing is
182 // done.
183 class PluginProxyMultiThreadTest
184 : public PluginProxyTest,
185 public base::DelegateSimpleThread::Delegate {
186 public:
187 PluginProxyMultiThreadTest();
188 virtual ~PluginProxyMultiThreadTest();
189
190 // Called before the secondary thread is started, but after all the member
191 // variables, including |secondary_thread_| and
192 // |secondary_thread_message_loop_|, are initialized.
193 virtual void SetUpTestOnMainThread() = 0;
194
195 virtual void SetUpTestOnSecondaryThread() = 0;
196
197 // TEST_F() should call this method.
198 void RunTest();
199
200 void CheckOnValidThread(bool main_thread);
dmichael (off chromium) 2013/01/15 22:43:52 Ditto... an enum would be more readable, e.g.: Ass
yzshen1 2013/01/16 18:55:59 Done.
201
202 // They can be called on any thread.
dmichael (off chromium) 2013/01/15 22:43:52 nit s/They/These
yzshen1 2013/01/16 18:55:59 Done.
203 void PostQuitForMainThread();
204 void PostQuitForSecondaryThread();
205
206 protected:
207 scoped_refptr<MessageLoopResource> secondary_thread_message_loop_;
208 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_proxy_;
209
210 private:
211 // base::DelegateSimpleThread::Delegate implementation.
212 virtual void Run() OVERRIDE;
213
214 void QuitNestedLoop();
215
216 static void InternalSetUpTestOnSecondaryThread(void* user_data,
217 int32_t result);
218
219 scoped_ptr<base::DelegateSimpleThread> secondary_thread_;
220 scoped_ptr<base::RunLoop> nested_main_thread_message_loop_;
221 };
222
165 class HostProxyTestHarness : public ProxyTestHarnessBase { 223 class HostProxyTestHarness : public ProxyTestHarnessBase {
166 public: 224 public:
167 HostProxyTestHarness(); 225 explicit HostProxyTestHarness(bool per_thread_globals);
168 virtual ~HostProxyTestHarness(); 226 virtual ~HostProxyTestHarness();
169 227
170 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } 228 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }
171 ResourceTracker& resource_tracker() { 229 ResourceTracker& resource_tracker() {
172 return *host_globals_->GetResourceTracker(); 230 return *host_globals_->GetResourceTracker();
173 } 231 }
174 VarTracker& var_tracker() { 232 VarTracker& var_tracker() {
175 return *host_globals_->GetVarTracker(); 233 return *host_globals_->GetVarTracker();
176 } 234 }
177 235
(...skipping 30 matching lines...) Expand all
208 private: 266 private:
209 base::MessageLoopProxy* ipc_message_loop_; // Weak 267 base::MessageLoopProxy* ipc_message_loop_; // Weak
210 base::WaitableEvent* shutdown_event_; // Weak 268 base::WaitableEvent* shutdown_event_; // Weak
211 269
212 DISALLOW_COPY_AND_ASSIGN(DelegateMock); 270 DISALLOW_COPY_AND_ASSIGN(DelegateMock);
213 }; 271 };
214 272
215 private: 273 private:
216 class MockSyncMessageStatusReceiver; 274 class MockSyncMessageStatusReceiver;
217 275
276 void CreateHostGlobals();
277
278 bool per_thread_globals_;
218 scoped_ptr<ppapi::TestGlobals> host_globals_; 279 scoped_ptr<ppapi::TestGlobals> host_globals_;
219 scoped_ptr<HostDispatcher> host_dispatcher_; 280 scoped_ptr<HostDispatcher> host_dispatcher_;
220 DelegateMock delegate_mock_; 281 DelegateMock delegate_mock_;
221 282
222 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_; 283 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_;
223 }; 284 };
224 285
225 class HostProxyTest : public HostProxyTestHarness, public testing::Test { 286 class HostProxyTest : public HostProxyTestHarness, public testing::Test {
226 public: 287 public:
227 HostProxyTest(); 288 HostProxyTest();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // EXPECT_VAR_IS_STRING("foo", my_var); 349 // EXPECT_VAR_IS_STRING("foo", my_var);
289 #define EXPECT_VAR_IS_STRING(str, var) { \ 350 #define EXPECT_VAR_IS_STRING(str, var) { \
290 StringVar* sv = StringVar::FromPPVar(var); \ 351 StringVar* sv = StringVar::FromPPVar(var); \
291 EXPECT_TRUE(sv); \ 352 EXPECT_TRUE(sv); \
292 if (sv) \ 353 if (sv) \
293 EXPECT_EQ(str, sv->value()); \ 354 EXPECT_EQ(str, sv->value()); \
294 } 355 }
295 356
296 } // namespace proxy 357 } // namespace proxy
297 } // namespace ppapi 358 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698