| 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 |
| 164 ppapi::TestGlobals* host_globals() { return &host_globals_; } |
| 159 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } | 165 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } |
| 166 VarTracker& var_tracker() { |
| 167 return *host_globals_.GetVarTracker(); |
| 168 } |
| 160 | 169 |
| 161 // ProxyTestBase implementation. | 170 // ProxyTestBase implementation. |
| 171 virtual PpapiGlobals* GetGlobals() { return &host_globals_; } |
| 162 virtual Dispatcher* GetDispatcher(); | 172 virtual Dispatcher* GetDispatcher(); |
| 163 virtual void SetUpHarness(); | 173 virtual void SetUpHarness(); |
| 164 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 174 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
| 165 base::MessageLoopProxy* ipc_message_loop, | 175 base::MessageLoopProxy* ipc_message_loop, |
| 166 base::WaitableEvent* shutdown_event, | 176 base::WaitableEvent* shutdown_event, |
| 167 bool is_client); | 177 bool is_client); |
| 168 virtual void TearDownHarness(); | 178 virtual void TearDownHarness(); |
| 169 | 179 |
| 170 class DelegateMock : public ProxyChannel::Delegate { | 180 class DelegateMock : public ProxyChannel::Delegate { |
| 171 public: | 181 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 virtual base::WaitableEvent* GetShutdownEvent(); | 194 virtual base::WaitableEvent* GetShutdownEvent(); |
| 185 | 195 |
| 186 private: | 196 private: |
| 187 base::MessageLoopProxy* ipc_message_loop_; // Weak | 197 base::MessageLoopProxy* ipc_message_loop_; // Weak |
| 188 base::WaitableEvent* shutdown_event_; // Weak | 198 base::WaitableEvent* shutdown_event_; // Weak |
| 189 | 199 |
| 190 DISALLOW_COPY_AND_ASSIGN(DelegateMock); | 200 DISALLOW_COPY_AND_ASSIGN(DelegateMock); |
| 191 }; | 201 }; |
| 192 | 202 |
| 193 private: | 203 private: |
| 204 ppapi::TestGlobals host_globals_; |
| 194 scoped_ptr<HostDispatcher> host_dispatcher_; | 205 scoped_ptr<HostDispatcher> host_dispatcher_; |
| 195 DelegateMock delegate_mock_; | 206 DelegateMock delegate_mock_; |
| 196 }; | 207 }; |
| 197 | 208 |
| 198 class HostProxyTest : public HostProxyTestHarness, public testing::Test { | 209 class PPAPI_SHARED_EXPORT HostProxyTest |
| 210 : public HostProxyTestHarness, public testing::Test { |
| 199 public: | 211 public: |
| 200 HostProxyTest(); | 212 HostProxyTest(); |
| 201 virtual ~HostProxyTest(); | 213 virtual ~HostProxyTest(); |
| 202 | 214 |
| 203 // testing::Test implementation. | 215 // testing::Test implementation. |
| 204 virtual void SetUp(); | 216 virtual void SetUp(); |
| 205 virtual void TearDown(); | 217 virtual void TearDown(); |
| 206 private: | 218 private: |
| 207 MessageLoop message_loop_; | 219 MessageLoop message_loop_; |
| 208 }; | 220 }; |
| 209 | 221 |
| 210 // Use this base class to test both sides of a proxy. | 222 // Use this base class to test both sides of a proxy. |
| 211 class TwoWayTest : public testing::Test { | 223 class PPAPI_SHARED_EXPORT TwoWayTest : public testing::Test { |
| 212 public: | 224 public: |
| 213 enum TwoWayTestMode { | 225 enum TwoWayTestMode { |
| 214 TEST_PPP_INTERFACE, | 226 TEST_PPP_INTERFACE, |
| 215 TEST_PPB_INTERFACE | 227 TEST_PPB_INTERFACE |
| 216 }; | 228 }; |
| 217 TwoWayTest(TwoWayTestMode test_mode); | 229 TwoWayTest(TwoWayTestMode test_mode); |
| 218 virtual ~TwoWayTest(); | 230 virtual ~TwoWayTest(); |
| 219 | 231 |
| 220 HostProxyTestHarness& host() { return host_; } | 232 HostProxyTestHarness& host() { return host_; } |
| 221 PluginProxyTestHarness& plugin() { return plugin_; } | 233 PluginProxyTestHarness& plugin() { return plugin_; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 244 // stopping the harnesses. | 256 // stopping the harnesses. |
| 245 ProxyTestHarnessBase* remote_harness_; | 257 ProxyTestHarnessBase* remote_harness_; |
| 246 ProxyTestHarnessBase* local_harness_; | 258 ProxyTestHarnessBase* local_harness_; |
| 247 | 259 |
| 248 base::WaitableEvent channel_created_; | 260 base::WaitableEvent channel_created_; |
| 249 base::WaitableEvent shutdown_event_; | 261 base::WaitableEvent shutdown_event_; |
| 250 }; | 262 }; |
| 251 | 263 |
| 252 } // namespace proxy | 264 } // namespace proxy |
| 253 } // namespace ppapi | 265 } // namespace ppapi |
| OLD | NEW |