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

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: Changes in response to David's suggestions 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
« no previous file with comments | « ppapi/proxy/plugin_globals.cc ('k') | ppapi/proxy/ppapi_proxy_test.cc » ('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) 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:
40 enum GlobalsConfiguration {
41 PER_THREAD_GLOBALS,
42 SINGLETON_GLOBALS
43 };
44
30 ProxyTestHarnessBase(); 45 ProxyTestHarnessBase();
31 virtual ~ProxyTestHarnessBase(); 46 virtual ~ProxyTestHarnessBase();
32 47
33 PP_Module pp_module() const { return pp_module_; } 48 PP_Module pp_module() const { return pp_module_; }
34 PP_Instance pp_instance() const { return pp_instance_; } 49 PP_Instance pp_instance() const { return pp_instance_; }
35 ResourceMessageTestSink& sink() { return sink_; } 50 ResourceMessageTestSink& sink() { return sink_; }
36 51
37 virtual PpapiGlobals* GetGlobals() = 0; 52 virtual PpapiGlobals* GetGlobals() = 0;
38 // Returns either the plugin or host dispatcher, depending on the test. 53 // Returns either the plugin or host dispatcher, depending on the test.
39 virtual Dispatcher* GetDispatcher() = 0; 54 virtual Dispatcher* GetDispatcher() = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 PP_Module pp_module_; 86 PP_Module pp_module_;
72 PP_Instance pp_instance_; 87 PP_Instance pp_instance_;
73 88
74 // Stores the data for GetInterface/RegisterTestInterface. 89 // Stores the data for GetInterface/RegisterTestInterface.
75 std::map<std::string, const void*> registered_interfaces_; 90 std::map<std::string, const void*> registered_interfaces_;
76 }; 91 };
77 92
78 // Test harness for the plugin side of the proxy. 93 // Test harness for the plugin side of the proxy.
79 class PluginProxyTestHarness : public ProxyTestHarnessBase { 94 class PluginProxyTestHarness : public ProxyTestHarnessBase {
80 public: 95 public:
81 PluginProxyTestHarness(); 96 explicit PluginProxyTestHarness(GlobalsConfiguration globals_config);
82 virtual ~PluginProxyTestHarness(); 97 virtual ~PluginProxyTestHarness();
83 98
84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } 99 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
85 PluginResourceTracker& resource_tracker() { 100 PluginResourceTracker& resource_tracker() {
86 return *plugin_globals_->plugin_resource_tracker(); 101 return *plugin_globals_->plugin_resource_tracker();
87 } 102 }
88 PluginVarTracker& var_tracker() { 103 PluginVarTracker& var_tracker() {
89 return *plugin_globals_->plugin_var_tracker(); 104 return *plugin_globals_->plugin_var_tracker();
90 } 105 }
91 106
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 private: 152 private:
138 base::MessageLoopProxy* ipc_message_loop_; // Weak 153 base::MessageLoopProxy* ipc_message_loop_; // Weak
139 base::WaitableEvent* shutdown_event_; // Weak 154 base::WaitableEvent* shutdown_event_; // Weak
140 std::set<PP_Instance> instance_id_set_; 155 std::set<PP_Instance> instance_id_set_;
141 IPC::Sender* browser_sender_; 156 IPC::Sender* browser_sender_;
142 157
143 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); 158 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock);
144 }; 159 };
145 160
146 private: 161 private:
162 void CreatePluginGlobals();
163
164 GlobalsConfiguration globals_config_;
147 scoped_ptr<PluginGlobals> plugin_globals_; 165 scoped_ptr<PluginGlobals> plugin_globals_;
148 166
149 scoped_ptr<PluginDispatcher> plugin_dispatcher_; 167 scoped_ptr<PluginDispatcher> plugin_dispatcher_;
150 PluginDelegateMock plugin_delegate_mock_; 168 PluginDelegateMock plugin_delegate_mock_;
151 }; 169 };
152 170
153 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { 171 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test {
154 public: 172 public:
155 PluginProxyTest(); 173 PluginProxyTest();
156 virtual ~PluginProxyTest(); 174 virtual ~PluginProxyTest();
157 175
158 // testing::Test implementation. 176 // testing::Test implementation.
159 virtual void SetUp(); 177 virtual void SetUp();
160 virtual void TearDown(); 178 virtual void TearDown();
161 private: 179 private:
162 MessageLoop message_loop_; 180 MessageLoop message_loop_;
163 }; 181 };
164 182
183 // This class provides support for multi-thread testing. A secondary thread is
184 // created with a Pepper message loop.
185 // Subclasses need to implement the two SetUpTestOn*Thread() methods to do the
186 // actual testing work; and call both PostQuitFor*Thread() when testing is
187 // done.
188 class PluginProxyMultiThreadTest
189 : public PluginProxyTest,
190 public base::DelegateSimpleThread::Delegate {
191 public:
192 PluginProxyMultiThreadTest();
193 virtual ~PluginProxyMultiThreadTest();
194
195 // Called before the secondary thread is started, but after all the member
196 // variables, including |secondary_thread_| and
197 // |secondary_thread_message_loop_|, are initialized.
198 virtual void SetUpTestOnMainThread() = 0;
199
200 virtual void SetUpTestOnSecondaryThread() = 0;
201
202 // TEST_F() should call this method.
203 void RunTest();
204
205 enum ThreadType {
206 MAIN_THREAD,
207 SECONDARY_THREAD
208 };
209 void CheckOnValidThread(ThreadType thread_type);
dmichael (off chromium) 2013/01/16 19:21:01 nit: I think it's clearer now without "Valid"
yzshen1 2013/01/16 22:37:37 Done.
210
211 // These can be called on any thread.
212 void PostQuitForMainThread();
213 void PostQuitForSecondaryThread();
214
215 protected:
216 scoped_refptr<MessageLoopResource> secondary_thread_message_loop_;
217 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_proxy_;
218
219 private:
220 // base::DelegateSimpleThread::Delegate implementation.
221 virtual void Run() OVERRIDE;
222
223 void QuitNestedLoop();
224
225 static void InternalSetUpTestOnSecondaryThread(void* user_data,
226 int32_t result);
227
228 scoped_ptr<base::DelegateSimpleThread> secondary_thread_;
229 scoped_ptr<base::RunLoop> nested_main_thread_message_loop_;
230 };
231
165 class HostProxyTestHarness : public ProxyTestHarnessBase { 232 class HostProxyTestHarness : public ProxyTestHarnessBase {
166 public: 233 public:
167 HostProxyTestHarness(); 234 explicit HostProxyTestHarness(GlobalsConfiguration globals_config);
168 virtual ~HostProxyTestHarness(); 235 virtual ~HostProxyTestHarness();
169 236
170 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } 237 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }
171 ResourceTracker& resource_tracker() { 238 ResourceTracker& resource_tracker() {
172 return *host_globals_->GetResourceTracker(); 239 return *host_globals_->GetResourceTracker();
173 } 240 }
174 VarTracker& var_tracker() { 241 VarTracker& var_tracker() {
175 return *host_globals_->GetVarTracker(); 242 return *host_globals_->GetVarTracker();
176 } 243 }
177 244
(...skipping 30 matching lines...) Expand all
208 private: 275 private:
209 base::MessageLoopProxy* ipc_message_loop_; // Weak 276 base::MessageLoopProxy* ipc_message_loop_; // Weak
210 base::WaitableEvent* shutdown_event_; // Weak 277 base::WaitableEvent* shutdown_event_; // Weak
211 278
212 DISALLOW_COPY_AND_ASSIGN(DelegateMock); 279 DISALLOW_COPY_AND_ASSIGN(DelegateMock);
213 }; 280 };
214 281
215 private: 282 private:
216 class MockSyncMessageStatusReceiver; 283 class MockSyncMessageStatusReceiver;
217 284
285 void CreateHostGlobals();
286
287 GlobalsConfiguration globals_config_;
218 scoped_ptr<ppapi::TestGlobals> host_globals_; 288 scoped_ptr<ppapi::TestGlobals> host_globals_;
219 scoped_ptr<HostDispatcher> host_dispatcher_; 289 scoped_ptr<HostDispatcher> host_dispatcher_;
220 DelegateMock delegate_mock_; 290 DelegateMock delegate_mock_;
221 291
222 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_; 292 scoped_ptr<MockSyncMessageStatusReceiver> status_receiver_;
223 }; 293 };
224 294
225 class HostProxyTest : public HostProxyTestHarness, public testing::Test { 295 class HostProxyTest : public HostProxyTestHarness, public testing::Test {
226 public: 296 public:
227 HostProxyTest(); 297 HostProxyTest();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // EXPECT_VAR_IS_STRING("foo", my_var); 358 // EXPECT_VAR_IS_STRING("foo", my_var);
289 #define EXPECT_VAR_IS_STRING(str, var) { \ 359 #define EXPECT_VAR_IS_STRING(str, var) { \
290 StringVar* sv = StringVar::FromPPVar(var); \ 360 StringVar* sv = StringVar::FromPPVar(var); \
291 EXPECT_TRUE(sv); \ 361 EXPECT_TRUE(sv); \
292 if (sv) \ 362 if (sv) \
293 EXPECT_EQ(str, sv->value()); \ 363 EXPECT_EQ(str, sv->value()); \
294 } 364 }
295 365
296 } // namespace proxy 366 } // namespace proxy
297 } // namespace ppapi 367 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_globals.cc ('k') | ppapi/proxy/ppapi_proxy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698