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

Unified Diff: ipc/ipc_test_base.cc

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_test_base.h ('k') | ipc/sync_socket_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_test_base.cc
diff --git a/ipc/ipc_test_base.cc b/ipc/ipc_test_base.cc
index 880e49555efe35fee6abcfd552bf512b92f77e89..8bc6bfc7c81e8e6bd29ce6895a9d62e3009e35d6 100644
--- a/ipc/ipc_test_base.cc
+++ b/ipc/ipc_test_base.cc
@@ -9,10 +9,12 @@
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/process/kill.h"
+#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
+#include "ipc/ipc_channel_mojo.h"
#include "ipc/ipc_descriptors.h"
#if defined(OS_POSIX)
@@ -168,3 +170,59 @@ std::unique_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory(
base::SingleThreadTaskRunner* runner) {
return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER, runner);
}
+IPCChannelMojoTestBase::IPCChannelMojoTestBase() = default;
+IPCChannelMojoTestBase::~IPCChannelMojoTestBase() = default;
+
+void IPCChannelMojoTestBase::Init(const std::string& test_client_name) {
+ handle_ = helper_.StartChild(test_client_name);
+}
+
+bool IPCChannelMojoTestBase::WaitForClientShutdown() {
+ return helper_.WaitForChildTestShutdown();
+}
+
+void IPCChannelMojoTestBase::TearDown() {
+ base::RunLoop().RunUntilIdle();
+}
+
+void IPCChannelMojoTestBase::CreateChannel(IPC::Listener* listener) {
+ channel_ =
+ IPC::ChannelMojo::Create(TakeHandle(), IPC::Channel::MODE_SERVER,
+ listener, base::ThreadTaskRunnerHandle::Get());
+}
+
+bool IPCChannelMojoTestBase::ConnectChannel() {
+ return channel_->Connect();
+}
+
+void IPCChannelMojoTestBase::DestroyChannel() {
+ channel_.reset();
+}
+
+mojo::ScopedMessagePipeHandle IPCChannelMojoTestBase::TakeHandle() {
+ return std::move(handle_);
+}
+
+IpcChannelMojoTestClient::IpcChannelMojoTestClient() = default;
+
+IpcChannelMojoTestClient::~IpcChannelMojoTestClient() = default;
+
+void IpcChannelMojoTestClient::Init(mojo::ScopedMessagePipeHandle handle) {
+ handle_ = std::move(handle);
+}
+
+void IpcChannelMojoTestClient::Connect(IPC::Listener* listener) {
+ channel_ =
+ IPC::ChannelMojo::Create(std::move(handle_), IPC::Channel::MODE_CLIENT,
+ listener, base::ThreadTaskRunnerHandle::Get());
+ CHECK(channel_->Connect());
+}
+
+void IpcChannelMojoTestClient::Close() {
+ channel_->Close();
+
+ base::RunLoop run_loop;
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ run_loop.QuitClosure());
+ run_loop.Run();
+}
« no previous file with comments | « ipc/ipc_test_base.h ('k') | ipc/sync_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698