1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ipc/mojo/ipc_mojo_bootstrap.h"
7 #include "base/base_paths.h"
8 #include "base/files/file.h"
9 #include "base/message_loop/message_loop.h"
10 #include "ipc/ipc_test_base.h"
13 #include "base/file_descriptor_posix.h"
18 class IPCMojoBootstrapTest
: public IPCTestBase
{
22 class TestingDelegate
: public IPC::MojoBootstrap::Delegate
{
24 TestingDelegate() : passed_(false) {}
26 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle
) override
;
27 void OnBootstrapError() override
;
29 bool passed() const { return passed_
; }
35 void TestingDelegate::OnPipeAvailable(
36 mojo::embedder::ScopedPlatformHandle handle
) {
38 base::MessageLoop::current()->Quit();
41 void TestingDelegate::OnBootstrapError() {
42 base::MessageLoop::current()->Quit();
45 TEST_F(IPCMojoBootstrapTest
, Connect
) {
46 Init("IPCMojoBootstrapTestClient");
48 TestingDelegate delegate
;
49 scoped_ptr
<IPC::MojoBootstrap
> bootstrap
= IPC::MojoBootstrap::Create(
50 GetTestChannelHandle(), IPC::Channel::MODE_SERVER
, &delegate
);
52 ASSERT_TRUE(bootstrap
->Connect());
54 ASSERT_TRUE(StartClientWithFD(bootstrap
->GetClientFileDescriptor()));
56 ASSERT_TRUE(StartClient());
58 bootstrap
->OnClientLaunched(client_process().Handle());
60 base::MessageLoop::current()->Run();
62 EXPECT_TRUE(delegate
.passed());
63 EXPECT_TRUE(WaitForClientShutdown());
66 // A long running process that connects to us.
67 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient
) {
68 base::MessageLoopForIO main_message_loop
;
70 TestingDelegate delegate
;
71 scoped_ptr
<IPC::MojoBootstrap
> bootstrap
= IPC::MojoBootstrap::Create(
72 IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
73 IPC::Channel::MODE_CLIENT
,
78 base::MessageLoop::current()->Run();
80 EXPECT_TRUE(delegate
.passed());