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 // Times out on Android; see http://crbug.com/502290
46 #if defined(OS_ANDROID)
47 #define MAYBE_Connect DISABLED_Connect
49 #define MAYBE_Connect Connect
51 TEST_F(IPCMojoBootstrapTest
, MAYBE_Connect
) {
52 Init("IPCMojoBootstrapTestClient");
54 TestingDelegate delegate
;
55 scoped_ptr
<IPC::MojoBootstrap
> bootstrap
= IPC::MojoBootstrap::Create(
56 GetTestChannelHandle(), IPC::Channel::MODE_SERVER
, &delegate
, nullptr);
58 ASSERT_TRUE(bootstrap
->Connect());
60 ASSERT_TRUE(StartClientWithFD(bootstrap
->GetClientFileDescriptor()));
62 ASSERT_TRUE(StartClient());
65 base::MessageLoop::current()->Run();
67 EXPECT_TRUE(delegate
.passed());
68 EXPECT_TRUE(WaitForClientShutdown());
71 // A long running process that connects to us.
72 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient
) {
73 base::MessageLoopForIO main_message_loop
;
75 TestingDelegate delegate
;
76 scoped_ptr
<IPC::MojoBootstrap
> bootstrap
= IPC::MojoBootstrap::Create(
77 IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
78 IPC::Channel::MODE_CLIENT
, &delegate
, nullptr);
82 base::MessageLoop::current()->Run();
84 EXPECT_TRUE(delegate
.passed());