Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ipc / ipc_test_base.h
index ce3328a..65af35e 100644 (file)
 #include "base/process/process.h"
 #include "base/test/multiprocess_test.h"
 #include "ipc/ipc_channel.h"
+#include "ipc/ipc_channel_factory.h"
 #include "ipc/ipc_channel_proxy.h"
 #include "ipc/ipc_multiprocess_test.h"
 
 namespace base {
-class MessageLoopForIO;
+class MessageLoop;
 }
 
 // A test fixture for multiprocess IPC tests. Such tests include a "client" side
@@ -33,11 +34,17 @@ class IPCTestBase : public base::MultiProcessTest {
   IPCTestBase();
   virtual ~IPCTestBase();
 
-  virtual void SetUp() OVERRIDE;
   virtual void TearDown() OVERRIDE;
 
-  // Initializes the test to use the given client.
+  // Initializes the test to use the given client and creates an IO message loop
+  // on the current thread.
   void Init(const std::string& test_client_name);
+  // Some tests create separate thread for IO message loop and run non-IO
+  // message loop on the main thread. As IPCTestBase creates IO message loop by
+  // default, such tests need to provide a custom message loop for the main
+  // thread.
+  void InitWithCustomMessageLoop(const std::string& test_client_name,
+                                 scoped_ptr<base::MessageLoop> message_loop);
 
   // Creates a channel with the given listener and connects to the channel
   // (returning true if successful), respectively. Use these to use a channel
@@ -61,20 +68,28 @@ class IPCTestBase : public base::MultiProcessTest {
   // channel proxy will automatically create and connect a channel.) You must
   // (manually) destroy the channel proxy before the task runner's thread is
   // destroyed.
-  void CreateChannelProxy(IPC::Listener* listener,
-                          base::SingleThreadTaskRunner* ipc_task_runner);
+  void CreateChannelProxy(
+      IPC::Listener* listener,
+      const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner);
   void DestroyChannelProxy();
 
   // Starts the client process, returning true if successful; this should be
   // done after connecting to the channel.
   bool StartClient();
 
+#if defined(OS_POSIX)
+  // A StartClient() variant that allows caller to pass the FD of IPC pipe
+  bool StartClientWithFD(int ipcfd);
+#endif
+
   // Waits for the client to shut down, returning true if successful. Note that
   // this does not initiate client shutdown; that must be done by the test
   // (somehow). This must be called before the end of the test whenever
   // StartClient() was called successfully.
   bool WaitForClientShutdown();
 
+  IPC::ChannelHandle GetTestChannelHandle();
+
   // Use this to send IPC messages (when you don't care if you're using a
   // channel or a proxy).
   IPC::Sender* sender() {
@@ -86,11 +101,18 @@ class IPCTestBase : public base::MultiProcessTest {
   IPC::ChannelProxy* channel_proxy() { return channel_proxy_.get(); }
 
   const base::ProcessHandle& client_process() const { return client_process_; }
-  scoped_refptr<base::TaskRunner> io_thread_task_runner();
+  scoped_refptr<base::TaskRunner> task_runner();
+
+  virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
+      const IPC::ChannelHandle& handle, base::TaskRunner* runner);
+
+  virtual bool DidStartClient();
 
  private:
+  std::string GetTestMainName() const;
+
   std::string test_client_name_;
-  scoped_ptr<base::MessageLoopForIO> message_loop_;
+  scoped_ptr<base::MessageLoop> message_loop_;
 
   scoped_ptr<IPC::Channel> channel_;
   scoped_ptr<IPC::ChannelProxy> channel_proxy_;