Re-land: C++ readability review
[chromium-blink-merge.git] / ipc / mojo / ipc_mojo_bootstrap_unittest.cc
blobfbe0fa89589393c23049bf8e83c98b2540b2e6eb
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"
12 #if defined(OS_POSIX)
13 #include "base/file_descriptor_posix.h"
14 #endif
16 namespace {
18 class IPCMojoBootstrapTest : public IPCTestBase {
19 protected:
22 class TestingDelegate : public IPC::MojoBootstrap::Delegate {
23 public:
24 TestingDelegate() : passed_(false) {}
26 void OnPipeAvailable(mojo::embedder::ScopedPlatformHandle handle) override;
27 void OnBootstrapError() override;
29 bool passed() const { return passed_; }
31 private:
32 bool passed_;
35 void TestingDelegate::OnPipeAvailable(
36 mojo::embedder::ScopedPlatformHandle handle) {
37 passed_ = true;
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());
53 #if defined(OS_POSIX)
54 ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
55 #else
56 ASSERT_TRUE(StartClient());
57 #endif
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,
74 &delegate);
76 bootstrap->Connect();
78 base::MessageLoop::current()->Run();
80 EXPECT_TRUE(delegate.passed());
82 return 0;
85 } // namespace