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 virtual void OnPipeAvailable(
27 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
28 virtual void OnBootstrapError() OVERRIDE;
30 bool passed() const { return passed_; }
36 void TestingDelegate::OnPipeAvailable(
37 mojo::embedder::ScopedPlatformHandle handle) {
39 base::MessageLoop::current()->Quit();
42 void TestingDelegate::OnBootstrapError() {
43 base::MessageLoop::current()->Quit();
46 TEST_F(IPCMojoBootstrapTest, Connect) {
47 Init("IPCMojoBootstrapTestClient");
49 TestingDelegate delegate;
50 scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
51 GetTestChannelHandle(), IPC::Channel::MODE_SERVER, &delegate);
53 ASSERT_TRUE(bootstrap->Connect());
55 ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
57 ASSERT_TRUE(StartClient());
59 bootstrap->OnClientLaunched(client_process());
61 base::MessageLoop::current()->Run();
63 EXPECT_TRUE(delegate.passed());
64 EXPECT_TRUE(WaitForClientShutdown());
67 // A long running process that connects to us.
68 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient) {
69 base::MessageLoopForIO main_message_loop;
71 TestingDelegate delegate;
72 scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
73 IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
74 IPC::Channel::MODE_CLIENT,
79 base::MessageLoop::current()->Run();
81 EXPECT_TRUE(delegate.passed());