| Index: ipc/mojo/ipc_channel_mojo_unittest.cc
|
| diff --git a/ipc/mojo/ipc_channel_mojo_unittest.cc b/ipc/mojo/ipc_channel_mojo_unittest.cc
|
| index b4f4154c67ce2b9509578f05816e13814abde69c..c85bbe026ba73cad06eff9fbc560c320d8040cbe 100644
|
| --- a/ipc/mojo/ipc_channel_mojo_unittest.cc
|
| +++ b/ipc/mojo/ipc_channel_mojo_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #include <utility>
|
|
|
| #include "base/base_paths.h"
|
| +#include "base/command_line.h"
|
| #include "base/files/file.h"
|
| #include "base/location.h"
|
| #include "base/path_service.h"
|
| @@ -26,6 +27,9 @@
|
| #include "ipc/mojo/ipc_mojo_message_helper.h"
|
| #include "ipc/mojo/ipc_mojo_param_traits.h"
|
| #include "ipc/mojo/scoped_ipc_support.h"
|
| +#include "mojo/edk/embedder/embedder.h"
|
| +#include "mojo/edk/embedder/embedder_internal.h"
|
| +#include "mojo/edk/embedder/platform_channel_pair.h"
|
|
|
| #if defined(OS_POSIX)
|
| #include "base/file_descriptor_posix.h"
|
| @@ -72,9 +76,10 @@ class ListenerThatExpectsOK : public IPC::Listener {
|
| class ChannelClient {
|
| public:
|
| explicit ChannelClient(IPC::Listener* listener, const char* name) {
|
| - channel_ = IPC::ChannelMojo::Create(main_message_loop_.task_runner(),
|
| - IPCTestBase::GetChannelName(name),
|
| - IPC::Channel::MODE_CLIENT, listener);
|
| + channel_ = IPC::ChannelMojo::Create(
|
| + mojo::edk::internal::g_io_thread_task_runner,
|
| + IPCTestBase::GetChannelName(name),
|
| + IPC::Channel::MODE_CLIENT, listener);
|
| }
|
|
|
| void Connect() {
|
| @@ -103,27 +108,53 @@ class IPCChannelMojoTestBase : public IPCTestBase {
|
| Init(test_client_name);
|
| }
|
|
|
| - void TearDown() override {
|
| - // Make sure Mojo IPC support is properly shutdown on the I/O loop before
|
| - // TearDown continues.
|
| - base::RunLoop run_loop;
|
| - task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
|
| - run_loop.Run();
|
| + // IPCTestBase:
|
| + scoped_refptr<base::TaskRunner> io_task_runner() override {
|
| + return make_scoped_refptr(mojo::edk::internal::g_io_thread_task_runner);
|
| + }
|
|
|
| - IPCTestBase::TearDown();
|
| + void AboutToSpawnChild(base::LaunchOptions* options) override {
|
| +#if defined(OS_POSIX)
|
| + base::FileHandleMappingVector* handles =
|
| + const_cast<base::FileHandleMappingVector*>(options->fds_to_remap);
|
| +#else
|
| + base::HandlesToInheritVector* handles =
|
| + const_cast<base::HandlesToInheritVector*>(options->handles_to_inherit);
|
| +#endif
|
| + broker_handle_ = broker_platform_channel_pair_.
|
| + PrepareToPassClientHandleToChildProcessAsString(handles);
|
| }
|
| +
|
| + bool DidStartClient() override {
|
| + broker_platform_channel_pair_.ChildProcessLaunched();
|
| + ChildProcessLaunched(client_process().Handle(),
|
| + broker_platform_channel_pair_.PassServerHandle());
|
| + return IPCTestBase::DidStartClient();
|
| + }
|
| +
|
| + // MultiProcessTest:
|
| + base::CommandLine MakeCmdLine(const std::string& procname) override {
|
| + base::CommandLine command_line = MultiProcessTest::MakeCmdLine(procname);
|
| + command_line.AppendSwitchASCII("broker-handle", broker_handle_);
|
| + return command_line;
|
| + }
|
| +
|
| + private:
|
| + // Used by the broker.
|
| + mojo::edk::PlatformChannelPair broker_platform_channel_pair_;
|
| + std::string broker_handle_;
|
| };
|
|
|
| class IPCChannelMojoTest : public IPCChannelMojoTestBase {
|
| protected:
|
| scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
|
| const IPC::ChannelHandle& handle,
|
| - base::SequencedTaskRunner* runner) override {
|
| - return IPC::ChannelMojo::CreateServerFactory(task_runner(), handle);
|
| + base::TaskRunner* runner) override {
|
| + return IPC::ChannelMojo::CreateServerFactory(io_task_runner(), handle);
|
| }
|
|
|
| bool DidStartClient() override {
|
| - bool ok = IPCTestBase::DidStartClient();
|
| + bool ok = IPCChannelMojoTestBase::DidStartClient();
|
| DCHECK(ok);
|
| return ok;
|
| }
|
| @@ -226,12 +257,12 @@ class IPCChannelMojoErrorTest : public IPCChannelMojoTestBase {
|
| protected:
|
| scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
|
| const IPC::ChannelHandle& handle,
|
| - base::SequencedTaskRunner* runner) override {
|
| - return IPC::ChannelMojo::CreateServerFactory(task_runner(), handle);
|
| + base::TaskRunner* runner) override {
|
| + return IPC::ChannelMojo::CreateServerFactory(io_task_runner(), handle);
|
| }
|
|
|
| bool DidStartClient() override {
|
| - bool ok = IPCTestBase::DidStartClient();
|
| + bool ok = IPCChannelMojoTestBase::DidStartClient();
|
| DCHECK(ok);
|
| return ok;
|
| }
|
| @@ -450,6 +481,8 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestSendMessagePipeClient) {
|
| void ReadOK(mojo::MessagePipeHandle pipe) {
|
| std::string should_be_ok("xx");
|
| uint32_t num_bytes = static_cast<uint32_t>(should_be_ok.size());
|
| + EXPECT_EQ(MOJO_RESULT_OK, mojo::Wait(pipe, MOJO_HANDLE_SIGNAL_READABLE,
|
| + MOJO_DEADLINE_INDEFINITE, nullptr));
|
| CHECK_EQ(MOJO_RESULT_OK,
|
| mojo::ReadMessageRaw(pipe, &should_be_ok[0], &num_bytes, nullptr,
|
| nullptr, 0));
|
| @@ -627,12 +660,12 @@ class IPCChannelMojoDeadHandleTest : public IPCChannelMojoTestBase {
|
| protected:
|
| scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
|
| const IPC::ChannelHandle& handle,
|
| - base::SequencedTaskRunner* runner) override {
|
| - return IPC::ChannelMojo::CreateServerFactory(task_runner(), handle);
|
| + base::TaskRunner* runner) override {
|
| + return IPC::ChannelMojo::CreateServerFactory(io_task_runner(), handle);
|
| }
|
|
|
| bool DidStartClient() override {
|
| - IPCTestBase::DidStartClient();
|
| + IPCChannelMojoTestBase::DidStartClient();
|
| // const base::ProcessHandle client = client_process().Handle();
|
| // Forces GetFileHandleForProcess() fail. It happens occasionally
|
| // in production, so we should exercise it somehow.
|
|
|