Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Unified Diff: ipc/ipc_test_base.h

Issue 2451953003: Change most IPC tests to use ChannelMojo. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_sync_channel_unittest.cc ('k') | ipc/ipc_test_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_test_base.h
diff --git a/ipc/ipc_test_base.h b/ipc/ipc_test_base.h
index 86dc8fc80551ea8a28dfc0f4b9ec1f907a881582..8a84fb672786daf12173017fac8e8d799be87e0e 100644
--- a/ipc/ipc_test_base.h
+++ b/ipc/ipc_test_base.h
@@ -16,6 +16,8 @@
#include "ipc/ipc_channel_factory.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_multiprocess_test.h"
+#include "mojo/edk/test/mojo_test_base.h"
+#include "mojo/edk/test/multiprocess_test_helper.h"
namespace base {
class MessageLoop;
@@ -133,8 +135,90 @@ class IPCTestBase : public base::MultiProcessTest {
DISALLOW_COPY_AND_ASSIGN(IPCTestBase);
};
+class IPCChannelMojoTestBase : public testing::Test {
+ public:
+ IPCChannelMojoTestBase();
+ ~IPCChannelMojoTestBase() override;
+
+ void Init(const std::string& test_client_name);
+
+ bool WaitForClientShutdown();
+
+ void TearDown() override;
+
+ void CreateChannel(IPC::Listener* listener);
+
+ bool ConnectChannel();
+
+ void DestroyChannel();
+
+ IPC::Sender* sender() { return channel(); }
+ IPC::Channel* channel() { return channel_.get(); }
+ const base::Process& client_process() const { return helper_.test_child(); }
+
+ protected:
+ mojo::ScopedMessagePipeHandle TakeHandle();
+
+ private:
+ base::MessageLoop message_loop_;
+
+ mojo::ScopedMessagePipeHandle handle_;
+ mojo::edk::test::MultiprocessTestHelper helper_;
+
+ std::unique_ptr<IPC::Channel> channel_;
+
+ DISALLOW_COPY_AND_ASSIGN(IPCChannelMojoTestBase);
+};
+
+class IpcChannelMojoTestClient {
+ public:
+ IpcChannelMojoTestClient();
+ ~IpcChannelMojoTestClient();
+
+ void Init(mojo::ScopedMessagePipeHandle handle);
+
+ void Connect(IPC::Listener* listener);
+
+ void Close();
+
+ IPC::Channel* channel() const { return channel_.get(); }
+
+ private:
+ base::MessageLoopForIO main_message_loop_;
+ mojo::ScopedMessagePipeHandle handle_;
+ std::unique_ptr<IPC::Channel> channel_;
+};
+
// Use this to declare the client side for tests using IPCTestBase.
#define MULTIPROCESS_IPC_TEST_CLIENT_MAIN(test_client_name) \
MULTIPROCESS_IPC_TEST_MAIN(test_client_name ## TestClientMain)
+// Use this to declare the client side for tests using IPCChannelMojoTestBase
+// when a custom test fixture class is required in the client. |test_base| must
+// be derived from IpcChannelMojoTestClient.
+#define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(client_name, \
+ test_base) \
+ class client_name##_MainFixture : public test_base { \
+ public: \
+ void Main(); \
+ }; \
+ MULTIPROCESS_TEST_MAIN_WITH_SETUP( \
+ client_name##TestChildMain, \
+ ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) { \
+ client_name##_MainFixture test; \
+ test.Init( \
+ std::move(mojo::edk::test::MultiprocessTestHelper::primordial_pipe)); \
+ test.Main(); \
+ return (::testing::Test::HasFatalFailure() || \
+ ::testing::Test::HasNonfatalFailure()) \
+ ? 1 \
+ : 0; \
+ } \
+ void client_name##_MainFixture::Main()
+
+// Use this to declare the client side for tests using IPCChannelMojoTestBase.
+#define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(client_name) \
+ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE( \
+ client_name, IpcChannelMojoTestClient)
+
#endif // IPC_IPC_TEST_BASE_H_
« no previous file with comments | « ipc/ipc_sync_channel_unittest.cc ('k') | ipc/ipc_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698