blob: 8bffd8877e58efc2df3b2224a6eb3c79079284b5 [file] [log] [blame]
morrita7c48ab82014-09-24 06:16:00 +09001// 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.
4
5#include "ipc/mojo/ipc_mojo_bootstrap.h"
6
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"
11
12#if defined(OS_POSIX)
13#include "base/file_descriptor_posix.h"
14#endif
15
16namespace {
17
18class IPCMojoBootstrapTest : public IPCTestBase {
19 protected:
20};
21
22class TestingDelegate : public IPC::MojoBootstrap::Delegate {
23 public:
24 TestingDelegate() : passed_(false) {}
25
26 virtual void OnPipeAvailable(
mostynbd41cdbb2014-10-07 16:17:16 +090027 mojo::embedder::ScopedPlatformHandle handle) override;
28 virtual void OnBootstrapError() override;
morrita7c48ab82014-09-24 06:16:00 +090029
30 bool passed() const { return passed_; }
31
32 private:
33 bool passed_;
34};
35
36void TestingDelegate::OnPipeAvailable(
37 mojo::embedder::ScopedPlatformHandle handle) {
38 passed_ = true;
39 base::MessageLoop::current()->Quit();
40}
41
42void TestingDelegate::OnBootstrapError() {
43 base::MessageLoop::current()->Quit();
44}
45
46TEST_F(IPCMojoBootstrapTest, Connect) {
47 Init("IPCMojoBootstrapTestClient");
48
49 TestingDelegate delegate;
50 scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
51 GetTestChannelHandle(), IPC::Channel::MODE_SERVER, &delegate);
52
53 ASSERT_TRUE(bootstrap->Connect());
54#if defined(OS_POSIX)
55 ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
56#else
57 ASSERT_TRUE(StartClient());
58#endif
59 bootstrap->OnClientLaunched(client_process());
60
61 base::MessageLoop::current()->Run();
62
63 EXPECT_TRUE(delegate.passed());
64 EXPECT_TRUE(WaitForClientShutdown());
65}
66
67// A long running process that connects to us.
68MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient) {
69 base::MessageLoopForIO main_message_loop;
70
71 TestingDelegate delegate;
72 scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
73 IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
74 IPC::Channel::MODE_CLIENT,
75 &delegate);
76
77 bootstrap->Connect();
78
79 base::MessageLoop::current()->Run();
80
81 EXPECT_TRUE(delegate.passed());
82
83 return 0;
84}
85
86} // namespace