| Index: ppapi/proxy/ppapi_proxy_test.h
|
| diff --git a/ppapi/proxy/ppapi_proxy_test.h b/ppapi/proxy/ppapi_proxy_test.h
|
| index 2c1ae1fb3299b20acdb53f0444bf773e158d1dbb..5067c965a1c367ee6fdd9ac049d75c1fa6ccb333 100644
|
| --- a/ppapi/proxy/ppapi_proxy_test.h
|
| +++ b/ppapi/proxy/ppapi_proxy_test.h
|
| @@ -5,7 +5,10 @@
|
| #include <map>
|
| #include <string>
|
|
|
| +#include "base/message_loop.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/synchronization/waitable_event.h"
|
| +#include "base/threading/thread.h"
|
| #include "ipc/ipc_test_sink.h"
|
| #include "ppapi/c/pp_instance.h"
|
| #include "ppapi/proxy/host_dispatcher.h"
|
| @@ -17,12 +20,12 @@
|
| namespace pp {
|
| namespace proxy {
|
|
|
| -// Base class for plugin and host tests. Tests will not use this directly.
|
| -// Instead, use the Plugin or HostProxyTest.
|
| -class ProxyTestBase : public testing::Test {
|
| +// Base class for plugin and host test harnesses. Tests will not use this
|
| +// directly. Instead, use the PluginProxyTest, HostProxyTest, or TwoWayTest.
|
| +class ProxyTestHarnessBase {
|
| public:
|
| - ProxyTestBase();
|
| - virtual ~ProxyTestBase();
|
| + ProxyTestHarnessBase();
|
| + virtual ~ProxyTestHarnessBase();
|
|
|
| PP_Module pp_module() const { return pp_module_; }
|
| PP_Instance pp_instance() const { return pp_instance_; }
|
| @@ -31,6 +34,17 @@ class ProxyTestBase : public testing::Test {
|
| // Returns either the plugin or host dispatcher, depending on the test.
|
| virtual Dispatcher* GetDispatcher() = 0;
|
|
|
| + // Set up the harness using an IPC::TestSink to capture messages.
|
| + virtual void SetUpHarness() = 0;
|
| +
|
| + // Set up the harness using a real IPC channel.
|
| + virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
|
| + base::MessageLoopProxy* ipc_message_loop,
|
| + base::WaitableEvent* shutdown_event,
|
| + bool is_client) = 0;
|
| +
|
| + virtual void TearDownHarness() = 0;
|
| +
|
| // Implementation of GetInterface for the dispatcher. This will
|
| // return NULL for all interfaces unless one is registered by calling
|
| // RegisterTestInterface();
|
| @@ -58,44 +72,165 @@ class ProxyTestBase : public testing::Test {
|
| };
|
|
|
| // Test harness for the plugin side of the proxy.
|
| -class PluginProxyTest : public ProxyTestBase {
|
| +class PluginProxyTestHarness : public ProxyTestHarnessBase {
|
| public:
|
| - PluginProxyTest();
|
| - virtual ~PluginProxyTest();
|
| + PluginProxyTestHarness();
|
| + virtual ~PluginProxyTestHarness();
|
|
|
| PluginDispatcher* plugin_dispatcher() { return plugin_dispatcher_.get(); }
|
| PluginResourceTracker& resource_tracker() { return resource_tracker_; }
|
| PluginVarTracker& var_tracker() { return var_tracker_; }
|
|
|
| - // ProxyTestBase implementation.
|
| + // ProxyTestHarnessBase implementation.
|
| virtual Dispatcher* GetDispatcher();
|
| -
|
| - // testing::Test implementation.
|
| - virtual void SetUp();
|
| - virtual void TearDown();
|
| + virtual void SetUpHarness();
|
| + virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
|
| + base::MessageLoopProxy* ipc_message_loop,
|
| + base::WaitableEvent* shutdown_event,
|
| + bool is_client);
|
| + virtual void TearDownHarness();
|
| +
|
| + class PluginDelegateMock : public PluginDispatcher::PluginDelegate {
|
| + public:
|
| + PluginDelegateMock() : ipc_message_loop_(NULL), shutdown_event_() {}
|
| + virtual ~PluginDelegateMock() {}
|
| +
|
| + void Init(base::MessageLoopProxy* ipc_message_loop,
|
| + base::WaitableEvent* shutdown_event) {
|
| + ipc_message_loop_ = ipc_message_loop;
|
| + shutdown_event_ = shutdown_event;
|
| + }
|
| +
|
| + // ProxyChannel::Delegate implementation.
|
| + virtual base::MessageLoopProxy* GetIPCMessageLoop();
|
| + virtual base::WaitableEvent* GetShutdownEvent();
|
| +
|
| + // PluginDispatcher::PluginDelegate implementation.
|
| + virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet();
|
| + virtual ppapi::WebKitForwarding* GetWebKitForwarding();
|
| + virtual void PostToWebKitThread(const tracked_objects::Location& from_here,
|
| + const base::Closure& task);
|
| + virtual bool SendToBrowser(IPC::Message* msg);
|
| +
|
| + private:
|
| + base::MessageLoopProxy* ipc_message_loop_; // Weak
|
| + base::WaitableEvent* shutdown_event_; // Weak
|
| + std::set<PP_Instance> instance_id_set_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PluginDelegateMock);
|
| + };
|
|
|
| private:
|
| PluginResourceTracker resource_tracker_;
|
| PluginVarTracker var_tracker_;
|
| scoped_ptr<PluginDispatcher> plugin_dispatcher_;
|
| + PluginDelegateMock plugin_delegate_mock_;
|
| };
|
|
|
| -class HostProxyTest : public ProxyTestBase {
|
| +class PluginProxyTest : public PluginProxyTestHarness, public testing::Test {
|
| public:
|
| - HostProxyTest();
|
| - virtual ~HostProxyTest();
|
| + PluginProxyTest();
|
| + virtual ~PluginProxyTest();
|
| +
|
| + // testing::Test implementation.
|
| + virtual void SetUp();
|
| + virtual void TearDown();
|
| +};
|
| +
|
| +class HostProxyTestHarness : public ProxyTestHarnessBase {
|
| + public:
|
| + HostProxyTestHarness();
|
| + virtual ~HostProxyTestHarness();
|
|
|
| HostDispatcher* host_dispatcher() { return host_dispatcher_.get(); }
|
|
|
| // ProxyTestBase implementation.
|
| virtual Dispatcher* GetDispatcher();
|
| + virtual void SetUpHarness();
|
| + virtual void SetUpHarnessWithChannel(const IPC::ChannelHandle& channel_handle,
|
| + base::MessageLoopProxy* ipc_message_loop,
|
| + base::WaitableEvent* shutdown_event,
|
| + bool is_client);
|
| + virtual void TearDownHarness();
|
| +
|
| + class DelegateMock : public ProxyChannel::Delegate {
|
| + public:
|
| + DelegateMock() : ipc_message_loop_(NULL), shutdown_event_(NULL) {
|
| + }
|
| + virtual ~DelegateMock() {}
|
| +
|
| + void Init(base::MessageLoopProxy* ipc_message_loop,
|
| + base::WaitableEvent* shutdown_event) {
|
| + ipc_message_loop_ = ipc_message_loop;
|
| + shutdown_event_ = shutdown_event;
|
| + }
|
| +
|
| + // ProxyChannel::Delegate implementation.
|
| + virtual base::MessageLoopProxy* GetIPCMessageLoop();
|
| + virtual base::WaitableEvent* GetShutdownEvent();
|
| +
|
| + private:
|
| + base::MessageLoopProxy* ipc_message_loop_; // Weak
|
| + base::WaitableEvent* shutdown_event_; // Weak
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DelegateMock);
|
| + };
|
| +
|
| + private:
|
| + scoped_ptr<HostDispatcher> host_dispatcher_;
|
| + DelegateMock delegate_mock_;
|
| +};
|
| +
|
| +class HostProxyTest : public HostProxyTestHarness, public testing::Test {
|
| + public:
|
| + HostProxyTest();
|
| + virtual ~HostProxyTest();
|
| +
|
| + // testing::Test implementation.
|
| + virtual void SetUp();
|
| + virtual void TearDown();
|
| +};
|
| +
|
| +// Use this base class to test both sides of a proxy.
|
| +class TwoWayTest : public testing::Test {
|
| + public:
|
| + enum TwoWayTestMode {
|
| + TEST_PPP_INTERFACE,
|
| + TEST_PPB_INTERFACE
|
| + };
|
| + TwoWayTest(TwoWayTestMode test_mode);
|
| + virtual ~TwoWayTest();
|
| +
|
| + HostProxyTestHarness& host() { return host_; }
|
| + PluginProxyTestHarness& plugin() { return plugin_; }
|
| + PP_Module pp_module() const { return host_.pp_module(); }
|
| + PP_Instance pp_instance() const { return host_.pp_instance(); }
|
| + TwoWayTestMode test_mode() { return test_mode_; }
|
|
|
| // testing::Test implementation.
|
| virtual void SetUp();
|
| virtual void TearDown();
|
|
|
| private:
|
| - scoped_ptr<HostDispatcher> host_dispatcher_;
|
| + TwoWayTestMode test_mode_;
|
| + HostProxyTestHarness host_;
|
| + PluginProxyTestHarness plugin_;
|
| + // In order to use sync IPC, we need to have an IO thread.
|
| + base::Thread io_thread_;
|
| + // The plugin side of the proxy runs on its own thread.
|
| + base::Thread plugin_thread_;
|
| + // The message loop for the main (host) thread.
|
| + MessageLoop message_loop_;
|
| +
|
| + // Aliases for the host and plugin harnesses; if we're testing a PPP
|
| + // interface, remote_harness will point to plugin_, and local_harness
|
| + // will point to host_. This makes it convenient when we're starting and
|
| + // stopping the harnesses.
|
| + ProxyTestHarnessBase* remote_harness_;
|
| + ProxyTestHarnessBase* local_harness_;
|
| +
|
| + base::WaitableEvent channel_created_;
|
| + base::WaitableEvent shutdown_event_;
|
| };
|
|
|
| } // namespace proxy
|
|
|