OLD | NEW |
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 <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" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "ipc/ipc_test_sink.h" | 12 #include "ipc/ipc_test_sink.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/proxy/host_dispatcher.h" | 14 #include "ppapi/proxy/host_dispatcher.h" |
15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
16 #include "ppapi/proxy/plugin_globals.h" | 16 #include "ppapi/proxy/plugin_globals.h" |
17 #include "ppapi/proxy/plugin_proxy_delegate.h" | 17 #include "ppapi/proxy/plugin_proxy_delegate.h" |
18 #include "ppapi/proxy/plugin_resource_tracker.h" | 18 #include "ppapi/proxy/plugin_resource_tracker.h" |
19 #include "ppapi/proxy/plugin_var_tracker.h" | 19 #include "ppapi/proxy/plugin_var_tracker.h" |
| 20 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 21 #include "ppapi/shared_impl/test_globals.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
22 namespace ppapi { | 24 namespace ppapi { |
23 namespace proxy { | 25 namespace proxy { |
24 | 26 |
25 // Base class for plugin and host test harnesses. Tests will not use this | 27 // Base class for plugin and host test harnesses. Tests will not use this |
26 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. | 28 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. |
27 class ProxyTestHarnessBase { | 29 class ProxyTestHarnessBase { |
28 public: | 30 public: |
29 ProxyTestHarnessBase(); | 31 ProxyTestHarnessBase(); |
30 virtual ~ProxyTestHarnessBase(); | 32 virtual ~ProxyTestHarnessBase(); |
31 | 33 |
32 PP_Module pp_module() const { return pp_module_; } | 34 PP_Module pp_module() const { return pp_module_; } |
33 PP_Instance pp_instance() const { return pp_instance_; } | 35 PP_Instance pp_instance() const { return pp_instance_; } |
34 IPC::TestSink& sink() { return sink_; } | 36 IPC::TestSink& sink() { return sink_; } |
35 | 37 |
| 38 virtual PpapiGlobals* GetGlobals() = 0; |
36 // Returns either the plugin or host dispatcher, depending on the test. | 39 // Returns either the plugin or host dispatcher, depending on the test. |
37 virtual Dispatcher* GetDispatcher() = 0; | 40 virtual Dispatcher* GetDispatcher() = 0; |
38 | 41 |
39 // Set up the harness using an IPC::TestSink to capture messages. | 42 // Set up the harness using an IPC::TestSink to capture messages. |
40 virtual void SetUpHarness() = 0; | 43 virtual void SetUpHarness() = 0; |
41 | 44 |
42 // Set up the harness using a real IPC channel. | 45 // Set up the harness using a real IPC channel. |
43 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 46 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
44 base::MessageLoopProxy* ipc_message_loop, | 47 base::MessageLoopProxy* ipc_message_loop, |
45 base::WaitableEvent* shutdown_event, | 48 base::WaitableEvent* shutdown_event, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 84 |
82 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } | 85 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } |
83 PluginResourceTracker& resource_tracker() { | 86 PluginResourceTracker& resource_tracker() { |
84 return *plugin_globals_.plugin_resource_tracker(); | 87 return *plugin_globals_.plugin_resource_tracker(); |
85 } | 88 } |
86 PluginVarTracker& var_tracker() { | 89 PluginVarTracker& var_tracker() { |
87 return *plugin_globals_.plugin_var_tracker(); | 90 return *plugin_globals_.plugin_var_tracker(); |
88 } | 91 } |
89 | 92 |
90 // ProxyTestHarnessBase implementation. | 93 // ProxyTestHarnessBase implementation. |
| 94 virtual PpapiGlobals* GetGlobals() { return &plugin_globals_; } |
91 virtual Dispatcher* GetDispatcher(); | 95 virtual Dispatcher* GetDispatcher(); |
92 virtual void SetUpHarness(); | 96 virtual void SetUpHarness(); |
93 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 97 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
94 base::MessageLoopProxy* ipc_message_loop, | 98 base::MessageLoopProxy* ipc_message_loop, |
95 base::WaitableEvent* shutdown_event, | 99 base::WaitableEvent* shutdown_event, |
96 bool is_client); | 100 bool is_client); |
97 virtual void TearDownHarness(); | 101 virtual void TearDownHarness(); |
98 | 102 |
99 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, | 103 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, |
100 public PluginProxyDelegate { | 104 public PluginProxyDelegate { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); | 136 DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock); |
133 }; | 137 }; |
134 | 138 |
135 private: | 139 private: |
136 PluginGlobals plugin_globals_; | 140 PluginGlobals plugin_globals_; |
137 | 141 |
138 scoped_ptr<PluginDispatcher> plugin_dispatcher_; | 142 scoped_ptr<PluginDispatcher> plugin_dispatcher_; |
139 PluginDelegateMock plugin_delegate_mock_; | 143 PluginDelegateMock plugin_delegate_mock_; |
140 }; | 144 }; |
141 | 145 |
142 class PluginProxyTest : public PluginProxyTestHarness, public testing::Test { | 146 class PPAPI_SHARED_EXPORT PluginProxyTest |
| 147 : public PluginProxyTestHarness, public testing::Test { |
143 public: | 148 public: |
144 PluginProxyTest(); | 149 PluginProxyTest(); |
145 virtual ~PluginProxyTest(); | 150 virtual ~PluginProxyTest(); |
146 | 151 |
147 // testing::Test implementation. | 152 // testing::Test implementation. |
148 virtual void SetUp(); | 153 virtual void SetUp(); |
149 virtual void TearDown(); | 154 virtual void TearDown(); |
150 private: | 155 private: |
151 MessageLoop message_loop_; | 156 MessageLoop message_loop_; |
152 }; | 157 }; |
153 | 158 |
154 class HostProxyTestHarness : public ProxyTestHarnessBase { | 159 class HostProxyTestHarness : public ProxyTestHarnessBase { |
155 public: | 160 public: |
156 HostProxyTestHarness(); | 161 HostProxyTestHarness(); |
157 virtual ~HostProxyTestHarness(); | 162 virtual ~HostProxyTestHarness(); |
158 | 163 |
159 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } | 164 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } |
| 165 ResourceTracker& resource_tracker() { |
| 166 return *host_globals_.GetResourceTracker(); |
| 167 } |
| 168 VarTracker& var_tracker() { |
| 169 return *host_globals_.GetVarTracker(); |
| 170 } |
160 | 171 |
161 // ProxyTestBase implementation. | 172 // ProxyTestBase implementation. |
| 173 virtual PpapiGlobals* GetGlobals() { return &host_globals_; } |
162 virtual Dispatcher* GetDispatcher(); | 174 virtual Dispatcher* GetDispatcher(); |
163 virtual void SetUpHarness(); | 175 virtual void SetUpHarness(); |
164 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 176 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
165 base::MessageLoopProxy* ipc_message_loop, | 177 base::MessageLoopProxy* ipc_message_loop, |
166 base::WaitableEvent* shutdown_event, | 178 base::WaitableEvent* shutdown_event, |
167 bool is_client); | 179 bool is_client); |
168 virtual void TearDownHarness(); | 180 virtual void TearDownHarness(); |
169 | 181 |
170 class DelegateMock : public ProxyChannel::Delegate { | 182 class DelegateMock : public ProxyChannel::Delegate { |
171 public: | 183 public: |
(...skipping 12 matching lines...) Expand all Loading... |
184 virtual base::WaitableEvent* GetShutdownEvent(); | 196 virtual base::WaitableEvent* GetShutdownEvent(); |
185 | 197 |
186 private: | 198 private: |
187 base::MessageLoopProxy* ipc_message_loop_; // Weak | 199 base::MessageLoopProxy* ipc_message_loop_; // Weak |
188 base::WaitableEvent* shutdown_event_; // Weak | 200 base::WaitableEvent* shutdown_event_; // Weak |
189 | 201 |
190 DISALLOW_COPY_AND_ASSIGN(DelegateMock); | 202 DISALLOW_COPY_AND_ASSIGN(DelegateMock); |
191 }; | 203 }; |
192 | 204 |
193 private: | 205 private: |
| 206 ppapi::TestGlobals host_globals_; |
194 scoped_ptr<HostDispatcher> host_dispatcher_; | 207 scoped_ptr<HostDispatcher> host_dispatcher_; |
195 DelegateMock delegate_mock_; | 208 DelegateMock delegate_mock_; |
196 }; | 209 }; |
197 | 210 |
198 class HostProxyTest : public HostProxyTestHarness, public testing::Test { | 211 class PPAPI_SHARED_EXPORT HostProxyTest |
| 212 : public HostProxyTestHarness, public testing::Test { |
199 public: | 213 public: |
200 HostProxyTest(); | 214 HostProxyTest(); |
201 virtual ~HostProxyTest(); | 215 virtual ~HostProxyTest(); |
202 | 216 |
203 // testing::Test implementation. | 217 // testing::Test implementation. |
204 virtual void SetUp(); | 218 virtual void SetUp(); |
205 virtual void TearDown(); | 219 virtual void TearDown(); |
206 private: | 220 private: |
207 MessageLoop message_loop_; | 221 MessageLoop message_loop_; |
208 }; | 222 }; |
209 | 223 |
210 // Use this base class to test both sides of a proxy. | 224 // Use this base class to test both sides of a proxy. |
211 class TwoWayTest : public testing::Test { | 225 class PPAPI_SHARED_EXPORT TwoWayTest : public testing::Test { |
212 public: | 226 public: |
213 enum TwoWayTestMode { | 227 enum TwoWayTestMode { |
214 TEST_PPP_INTERFACE, | 228 TEST_PPP_INTERFACE, |
215 TEST_PPB_INTERFACE | 229 TEST_PPB_INTERFACE |
216 }; | 230 }; |
217 TwoWayTest(TwoWayTestMode test_mode); | 231 TwoWayTest(TwoWayTestMode test_mode); |
218 virtual ~TwoWayTest(); | 232 virtual ~TwoWayTest(); |
219 | 233 |
220 HostProxyTestHarness& host() { return host_; } | 234 HostProxyTestHarness& host() { return host_; } |
221 PluginProxyTestHarness& plugin() { return plugin_; } | 235 PluginProxyTestHarness& plugin() { return plugin_; } |
(...skipping 22 matching lines...) Expand all Loading... |
244 // stopping the harnesses. | 258 // stopping the harnesses. |
245 ProxyTestHarnessBase* remote_harness_; | 259 ProxyTestHarnessBase* remote_harness_; |
246 ProxyTestHarnessBase* local_harness_; | 260 ProxyTestHarnessBase* local_harness_; |
247 | 261 |
248 base::WaitableEvent channel_created_; | 262 base::WaitableEvent channel_created_; |
249 base::WaitableEvent shutdown_event_; | 263 base::WaitableEvent shutdown_event_; |
250 }; | 264 }; |
251 | 265 |
252 } // namespace proxy | 266 } // namespace proxy |
253 } // namespace ppapi | 267 } // namespace ppapi |
OLD | NEW |