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

Unified Diff: ipc/ipc_channel_mojo_unittest.cc

Issue 2455583002: Revert of 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/DEPS ('k') | ipc/ipc_channel_proxy_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_channel_mojo_unittest.cc
diff --git a/ipc/ipc_channel_mojo_unittest.cc b/ipc/ipc_channel_mojo_unittest.cc
index 229716edc0dbae08db8694e8537745961347d0bc..5493ac11ec829f951dadc05c5a1cd106b6156f0a 100644
--- a/ipc/ipc_channel_mojo_unittest.cc
+++ b/ipc/ipc_channel_mojo_unittest.cc
@@ -37,12 +37,33 @@
#include "ipc/ipc_test.mojom.h"
#include "ipc/ipc_test_base.h"
#include "ipc/ipc_test_channel_listener.h"
+#include "mojo/edk/test/mojo_test_base.h"
+#include "mojo/edk/test/multiprocess_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
#include "ipc/ipc_platform_file_attachment_posix.h"
#endif
+
+#define DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(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()
namespace {
@@ -87,7 +108,73 @@
bool received_ok_;
};
-using IPCChannelMojoTest = IPCChannelMojoTestBase;
+class ChannelClient {
+ public:
+ void Init(mojo::ScopedMessagePipeHandle handle) {
+ handle_ = std::move(handle);
+ }
+
+ void Connect(IPC::Listener* listener) {
+ channel_ = IPC::ChannelMojo::Create(
+ std::move(handle_), IPC::Channel::MODE_CLIENT, listener,
+ base::ThreadTaskRunnerHandle::Get());
+ CHECK(channel_->Connect());
+ }
+
+ void Close() {
+ channel_->Close();
+
+ base::RunLoop run_loop;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ IPC::ChannelMojo* channel() const { return channel_.get(); }
+
+ private:
+ base::MessageLoopForIO main_message_loop_;
+ mojo::ScopedMessagePipeHandle handle_;
+ std::unique_ptr<IPC::ChannelMojo> channel_;
+};
+
+class IPCChannelMojoTestBase : public testing::Test {
+ public:
+ void InitWithMojo(const std::string& test_client_name) {
+ handle_ = helper_.StartChild(test_client_name);
+ }
+
+ bool WaitForClientShutdown() { return helper_.WaitForChildTestShutdown(); }
+
+ protected:
+ mojo::ScopedMessagePipeHandle TakeHandle() { return std::move(handle_); }
+
+ private:
+ mojo::ScopedMessagePipeHandle handle_;
+ mojo::edk::test::MultiprocessTestHelper helper_;
+};
+
+class IPCChannelMojoTest : public IPCChannelMojoTestBase {
+ public:
+ void TearDown() override { base::RunLoop().RunUntilIdle(); }
+
+ void CreateChannel(IPC::Listener* listener) {
+ channel_ = IPC::ChannelMojo::Create(
+ TakeHandle(), IPC::Channel::MODE_SERVER, listener,
+ base::ThreadTaskRunnerHandle::Get());
+ }
+
+ bool ConnectChannel() { return channel_->Connect(); }
+
+ void DestroyChannel() { channel_.reset(); }
+
+ IPC::Sender* sender() { return channel(); }
+ IPC::Channel* channel() { return channel_.get(); }
+
+ private:
+ base::MessageLoop message_loop_;
+ std::unique_ptr<IPC::Channel> channel_;
+};
class TestChannelListenerWithExtraExpectations
: public IPC::TestChannelListener {
@@ -107,7 +194,7 @@
};
TEST_F(IPCChannelMojoTest, ConnectedFromClient) {
- Init("IPCChannelMojoTestClient");
+ InitWithMojo("IPCChannelMojoTestClient");
// Set up IPC channel and start client.
TestChannelListenerWithExtraExpectations listener;
@@ -129,7 +216,7 @@
}
// A long running process that connects to us
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient, ChannelClient) {
TestChannelListenerWithExtraExpectations listener;
Connect(&listener);
listener.Init(channel());
@@ -171,7 +258,8 @@
};
// A long running process that connects to us.
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient,
+ ChannelClient) {
ListenerThatQuits listener;
Connect(&listener);
@@ -181,7 +269,7 @@
}
TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) {
- Init("IPCChannelMojoErraticTestClient");
+ InitWithMojo("IPCChannelMojoErraticTestClient");
// Set up IPC channel and start client.
ListenerExpectingErrors listener;
@@ -325,7 +413,7 @@
};
TEST_F(IPCChannelMojoTest, SendMessagePipe) {
- Init("IPCChannelMojoTestSendMessagePipeClient");
+ InitWithMojo("IPCChannelMojoTestSendMessagePipeClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -341,7 +429,8 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient,
+ ChannelClient) {
ListenerThatExpectsMessagePipe listener;
Connect(&listener);
listener.set_sender(channel());
@@ -402,7 +491,7 @@
bool receiving_valid_;
};
-class ParamTraitMessagePipeClient : public IpcChannelMojoTestClient {
+class ParamTraitMessagePipeClient : public ChannelClient {
public:
void RunTest(bool receiving_valid_handle) {
ListenerThatExpectsMessagePipeUsingParamTrait listener(
@@ -417,7 +506,7 @@
};
TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) {
- Init("ParamTraitValidMessagePipeClient");
+ InitWithMojo("ParamTraitValidMessagePipeClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -438,14 +527,13 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
- ParamTraitValidMessagePipeClient,
- ParamTraitMessagePipeClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitValidMessagePipeClient,
+ ParamTraitMessagePipeClient) {
RunTest(true);
}
TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) {
- Init("ParamTraitInvalidMessagePipeClient");
+ InitWithMojo("ParamTraitInvalidMessagePipeClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -464,14 +552,13 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
- ParamTraitInvalidMessagePipeClient,
- ParamTraitMessagePipeClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitInvalidMessagePipeClient,
+ ParamTraitMessagePipeClient) {
RunTest(false);
}
TEST_F(IPCChannelMojoTest, SendFailAfterClose) {
- Init("IPCChannelMojoTestSendOkClient");
+ InitWithMojo("IPCChannelMojoTestSendOkClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -502,7 +589,8 @@
IPC::Sender* sender_;
};
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient,
+ ChannelClient) {
ListenerSendingOneOk listener;
Connect(&listener);
listener.set_sender(channel());
@@ -607,7 +695,7 @@
};
TEST_F(IPCChannelMojoTest, SimpleAssociatedInterface) {
- Init("SimpleAssociatedInterfaceClient");
+ InitWithMojo("SimpleAssociatedInterfaceClient");
ListenerWithSimpleAssociatedInterface listener;
CreateChannel(&listener);
@@ -622,7 +710,8 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SimpleAssociatedInterfaceClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SimpleAssociatedInterfaceClient,
+ ChannelClient) {
ListenerSendingAssociatedMessages listener;
Connect(&listener);
listener.set_channel(channel());
@@ -677,8 +766,8 @@
class IPCChannelProxyMojoTest : public IPCChannelMojoTestBase {
public:
- void Init(const std::string& client_name) {
- IPCChannelMojoTestBase::Init(client_name);
+ void InitWithMojo(const std::string& client_name) {
+ IPCChannelMojoTestBase::InitWithMojo(client_name);
runner_.reset(new ChannelProxyRunner(TakeHandle(), true));
}
void CreateProxy(IPC::Listener* listener) { runner_->CreateProxy(listener); }
@@ -693,6 +782,7 @@
IPC::ChannelProxy* proxy() { return runner_->proxy(); }
private:
+ base::MessageLoop message_loop_;
std::unique_ptr<ChannelProxyRunner> runner_;
};
@@ -768,7 +858,7 @@
const int ListenerWithSimpleProxyAssociatedInterface::kNumMessages = 1000;
TEST_F(IPCChannelProxyMojoTest, ProxyThreadAssociatedInterface) {
- Init("ProxyThreadAssociatedInterfaceClient");
+ InitWithMojo("ProxyThreadAssociatedInterfaceClient");
ListenerWithSimpleProxyAssociatedInterface listener;
CreateProxy(&listener);
@@ -816,9 +906,8 @@
bool OnMessageReceived(const IPC::Message& message) override { return true; }
};
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
- ProxyThreadAssociatedInterfaceClient,
- ChannelProxyClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ProxyThreadAssociatedInterfaceClient,
+ ChannelProxyClient) {
DummyListener listener;
CreateProxy(&listener);
RunProxy();
@@ -888,7 +977,7 @@
// targeting proxy thread bindings, and the channel will still dispatch
// messages appropriately.
- Init("ProxyThreadAssociatedInterfaceIndirectClient");
+ InitWithMojo("ProxyThreadAssociatedInterfaceIndirectClient");
ListenerWithIndirectProxyAssociatedInterface listener;
CreateProxy(&listener);
@@ -904,7 +993,7 @@
DestroyProxy();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
ProxyThreadAssociatedInterfaceIndirectClient,
ChannelProxyClient) {
DummyListener listener;
@@ -1021,7 +1110,7 @@
};
TEST_F(IPCChannelProxyMojoTest, SyncAssociatedInterface) {
- Init("SyncAssociatedInterface");
+ InitWithMojo("SyncAssociatedInterface");
ListenerWithSyncAssociatedInterface listener;
CreateProxy(&listener);
@@ -1127,8 +1216,8 @@
DISALLOW_COPY_AND_ASSIGN(SimpleTestClientImpl);
};
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(SyncAssociatedInterface,
- ChannelProxyClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SyncAssociatedInterface,
+ ChannelProxyClient) {
SimpleTestClientImpl client_impl;
CreateProxy(&client_impl);
client_impl.set_sync_sender(proxy());
@@ -1187,7 +1276,7 @@
// sufficient to leave this up to the consumer to implement since associated
// interface requests and messages also need to be queued according to the
// same policy.
- Init("CreatePausedClient");
+ InitWithMojo("CreatePausedClient");
DummyListener listener;
CreateProxy(&listener);
@@ -1240,8 +1329,7 @@
DISALLOW_COPY_AND_ASSIGN(ExpectValueSequenceListener);
};
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(CreatePausedClient,
- ChannelProxyClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(CreatePausedClient, ChannelProxyClient) {
std::queue<int32_t> expected_values;
ExpectValueSequenceListener listener(&expected_values);
CreateProxy(&listener);
@@ -1282,7 +1370,7 @@
};
TEST_F(IPCChannelMojoTest, SendPlatformHandle) {
- Init("IPCChannelMojoTestSendPlatformHandleClient");
+ InitWithMojo("IPCChannelMojoTestSendPlatformHandleClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -1302,8 +1390,8 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
- IPCChannelMojoTestSendPlatformHandleClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendPlatformHandleClient,
+ ChannelClient) {
ListenerThatExpectsFile listener;
Connect(&listener);
listener.set_sender(channel());
@@ -1338,7 +1426,7 @@
};
TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) {
- Init("IPCChannelMojoTestSendPlatformHandleAndPipeClient");
+ InitWithMojo("IPCChannelMojoTestSendPlatformHandleAndPipeClient");
ListenerThatExpectsOK listener;
CreateChannel(&listener);
@@ -1360,7 +1448,8 @@
}
DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
- IPCChannelMojoTestSendPlatformHandleAndPipeClient) {
+ IPCChannelMojoTestSendPlatformHandleAndPipeClient,
+ ChannelClient) {
ListenerThatExpectsFileAndPipe listener;
Connect(&listener);
listener.set_sender(channel());
@@ -1390,7 +1479,7 @@
};
TEST_F(IPCChannelMojoTest, VerifyGlobalPid) {
- Init("IPCChannelMojoTestVerifyGlobalPidClient");
+ InitWithMojo("IPCChannelMojoTestVerifyGlobalPidClient");
ListenerThatVerifiesPeerPid listener;
CreateChannel(&listener);
@@ -1403,7 +1492,8 @@
DestroyChannel();
}
-DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient) {
+DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient,
+ ChannelClient) {
IPC::Channel::SetGlobalPid(kMagicChildId);
ListenerThatQuits listener;
Connect(&listener);
« no previous file with comments | « ipc/DEPS ('k') | ipc/ipc_channel_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698