| OLD | NEW |
| 1 // Copyright (c) 2012 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/test_globals.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace ppapi { | 22 namespace ppapi { |
| 24 namespace proxy { | 23 namespace proxy { |
| 25 | 24 |
| 26 // Base class for plugin and host test harnesses. Tests will not use this | 25 // Base class for plugin and host test harnesses. Tests will not use this |
| 27 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. | 26 // directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest. |
| 28 class ProxyTestHarnessBase { | 27 class ProxyTestHarnessBase { |
| 29 public: | 28 public: |
| 30 ProxyTestHarnessBase(); | 29 ProxyTestHarnessBase(); |
| 31 virtual ~ProxyTestHarnessBase(); | 30 virtual ~ProxyTestHarnessBase(); |
| 32 | 31 |
| 33 PP_Module pp_module() const { return pp_module_; } | 32 PP_Module pp_module() const { return pp_module_; } |
| 34 PP_Instance pp_instance() const { return pp_instance_; } | 33 PP_Instance pp_instance() const { return pp_instance_; } |
| 35 IPC::TestSink& sink() { return sink_; } | 34 IPC::TestSink& sink() { return sink_; } |
| 36 | 35 |
| 37 virtual PpapiGlobals* GetGlobals() = 0; | |
| 38 // Returns either the plugin or host dispatcher, depending on the test. | 36 // Returns either the plugin or host dispatcher, depending on the test. |
| 39 virtual Dispatcher* GetDispatcher() = 0; | 37 virtual Dispatcher* GetDispatcher() = 0; |
| 40 | 38 |
| 41 // Set up the harness using an IPC::TestSink to capture messages. | 39 // Set up the harness using an IPC::TestSink to capture messages. |
| 42 virtual void SetUpHarness() = 0; | 40 virtual void SetUpHarness() = 0; |
| 43 | 41 |
| 44 // Set up the harness using a real IPC channel. | 42 // Set up the harness using a real IPC channel. |
| 45 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 43 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
| 46 base::MessageLoopProxy* ipc_message_loop, | 44 base::MessageLoopProxy* ipc_message_loop, |
| 47 base::WaitableEvent* shutdown_event, | 45 base::WaitableEvent* shutdown_event, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 81 |
| 84 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } | 82 PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); } |
| 85 PluginResourceTracker& resource_tracker() { | 83 PluginResourceTracker& resource_tracker() { |
| 86 return *plugin_globals_.plugin_resource_tracker(); | 84 return *plugin_globals_.plugin_resource_tracker(); |
| 87 } | 85 } |
| 88 PluginVarTracker& var_tracker() { | 86 PluginVarTracker& var_tracker() { |
| 89 return *plugin_globals_.plugin_var_tracker(); | 87 return *plugin_globals_.plugin_var_tracker(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 // ProxyTestHarnessBase implementation. | 90 // ProxyTestHarnessBase implementation. |
| 93 virtual PpapiGlobals* GetGlobals() { return &plugin_globals_; } | |
| 94 virtual Dispatcher* GetDispatcher(); | 91 virtual Dispatcher* GetDispatcher(); |
| 95 virtual void SetUpHarness(); | 92 virtual void SetUpHarness(); |
| 96 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 93 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
| 97 base::MessageLoopProxy* ipc_message_loop, | 94 base::MessageLoopProxy* ipc_message_loop, |
| 98 base::WaitableEvent* shutdown_event, | 95 base::WaitableEvent* shutdown_event, |
| 99 bool is_client); | 96 bool is_client); |
| 100 virtual void TearDownHarness(); | 97 virtual void TearDownHarness(); |
| 101 | 98 |
| 102 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, | 99 class PluginDelegateMock : public PluginDispatcher::PluginDelegate, |
| 103 public PluginProxyDelegate { | 100 public PluginProxyDelegate { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 private: | 150 private: |
| 154 MessageLoop message_loop_; | 151 MessageLoop message_loop_; |
| 155 }; | 152 }; |
| 156 | 153 |
| 157 class HostProxyTestHarness : public ProxyTestHarnessBase { | 154 class HostProxyTestHarness : public ProxyTestHarnessBase { |
| 158 public: | 155 public: |
| 159 HostProxyTestHarness(); | 156 HostProxyTestHarness(); |
| 160 virtual ~HostProxyTestHarness(); | 157 virtual ~HostProxyTestHarness(); |
| 161 | 158 |
| 162 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } | 159 HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); } |
| 163 ResourceTracker& resource_tracker() { | |
| 164 return *host_globals_.GetResourceTracker(); | |
| 165 } | |
| 166 VarTracker& var_tracker() { | |
| 167 return *host_globals_.GetVarTracker(); | |
| 168 } | |
| 169 | 160 |
| 170 // ProxyTestBase implementation. | 161 // ProxyTestBase implementation. |
| 171 virtual PpapiGlobals* GetGlobals() { return &host_globals_; } | |
| 172 virtual Dispatcher* GetDispatcher(); | 162 virtual Dispatcher* GetDispatcher(); |
| 173 virtual void SetUpHarness(); | 163 virtual void SetUpHarness(); |
| 174 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, | 164 virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle, |
| 175 base::MessageLoopProxy* ipc_message_loop, | 165 base::MessageLoopProxy* ipc_message_loop, |
| 176 base::WaitableEvent* shutdown_event, | 166 base::WaitableEvent* shutdown_event, |
| 177 bool is_client); | 167 bool is_client); |
| 178 virtual void TearDownHarness(); | 168 virtual void TearDownHarness(); |
| 179 | 169 |
| 180 class DelegateMock : public ProxyChannel::Delegate { | 170 class DelegateMock : public ProxyChannel::Delegate { |
| 181 public: | 171 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 194 virtual base::WaitableEvent* GetShutdownEvent(); | 184 virtual base::WaitableEvent* GetShutdownEvent(); |
| 195 | 185 |
| 196 private: | 186 private: |
| 197 base::MessageLoopProxy* ipc_message_loop_; // Weak | 187 base::MessageLoopProxy* ipc_message_loop_; // Weak |
| 198 base::WaitableEvent* shutdown_event_; // Weak | 188 base::WaitableEvent* shutdown_event_; // Weak |
| 199 | 189 |
| 200 DISALLOW_COPY_AND_ASSIGN(DelegateMock); | 190 DISALLOW_COPY_AND_ASSIGN(DelegateMock); |
| 201 }; | 191 }; |
| 202 | 192 |
| 203 private: | 193 private: |
| 204 ppapi::TestGlobals host_globals_; | |
| 205 scoped_ptr<HostDispatcher> host_dispatcher_; | 194 scoped_ptr<HostDispatcher> host_dispatcher_; |
| 206 DelegateMock delegate_mock_; | 195 DelegateMock delegate_mock_; |
| 207 }; | 196 }; |
| 208 | 197 |
| 209 class HostProxyTest : public HostProxyTestHarness, public testing::Test { | 198 class HostProxyTest : public HostProxyTestHarness, public testing::Test { |
| 210 public: | 199 public: |
| 211 HostProxyTest(); | 200 HostProxyTest(); |
| 212 virtual ~HostProxyTest(); | 201 virtual ~HostProxyTest(); |
| 213 | 202 |
| 214 // testing::Test implementation. | 203 // testing::Test implementation. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // stopping the harnesses. | 244 // stopping the harnesses. |
| 256 ProxyTestHarnessBase* remote_harness_; | 245 ProxyTestHarnessBase* remote_harness_; |
| 257 ProxyTestHarnessBase* local_harness_; | 246 ProxyTestHarnessBase* local_harness_; |
| 258 | 247 |
| 259 base::WaitableEvent channel_created_; | 248 base::WaitableEvent channel_created_; |
| 260 base::WaitableEvent shutdown_event_; | 249 base::WaitableEvent shutdown_event_; |
| 261 }; | 250 }; |
| 262 | 251 |
| 263 } // namespace proxy | 252 } // namespace proxy |
| 264 } // namespace ppapi | 253 } // namespace ppapi |
| OLD | NEW |