Chromium Code Reviews| Index: ipc/mojo/ipc_mojo_bootstrap_unittest.cc |
| diff --git a/ipc/mojo/ipc_mojo_bootstrap_unittest.cc b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..59cac991211b4b6c6544412a1cb2f6999bc5cf60 |
| --- /dev/null |
| +++ b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ipc/mojo/ipc_mojo_bootstrap.h" |
| + |
| +#include "base/base_paths.h" |
| +#include "base/files/file.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "ipc/ipc_test_base.h" |
| + |
| +#if defined(OS_POSIX) |
| +#include "base/file_descriptor_posix.h" |
| +#endif |
| + |
| +namespace { |
| + |
| +class IPCMojoBootstrapTest : public IPCTestBase { |
| + protected: |
| +}; |
| + |
| +class TestingDelegate : public IPC::MojoBootstrap::Delegate { |
| + public: |
| + TestingDelegate() : passed_(false) {} |
| + |
| + virtual void OnPipeAvailable( |
| + mojo::embedder::ScopedPlatformHandle handle) OVERRIDE; |
| + virtual void OnBootstrapError() OVERRIDE; |
| + |
| + bool passed() const { return passed_; } |
| + |
| + private: |
| + bool passed_; |
| +}; |
| + |
| +void TestingDelegate::OnPipeAvailable( |
| + mojo::embedder::ScopedPlatformHandle handle) { |
| + passed_ = true; |
| + base::MessageLoop::current()->Quit(); |
| +} |
| + |
| +void TestingDelegate::OnBootstrapError() { |
| + base::MessageLoop::current()->Quit(); |
| +} |
| + |
| +TEST_F(IPCMojoBootstrapTest, Connect) { |
| + Init("IPCMojoBootstrapTestClient"); |
| + |
| + TestingDelegate delegate; |
| + scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create( |
| + GetTestChannelHandle(), IPC::Channel::MODE_SERVER, &delegate); |
| + |
| + ASSERT_TRUE(bootstrap->Connect()); |
| +#if defined(OS_POSIX) |
| + ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor())); |
| +#else |
| + ASSERT_TRUE(StartClient()); |
| +#endif |
| + bootstrap->OnClientLaunched(client_process()); |
| + |
| + base::MessageLoop::current()->Run(); |
| + |
| + EXPECT_TRUE(delegate.passed()); |
| + EXPECT_TRUE(WaitForClientShutdown()); |
| +} |
| + |
| +// A long running process that connects to us |
|
viettrungluu
2014/09/22 19:13:08
nit: Needs a period at the end.
Hajime Morrita
2014/09/22 19:32:48
Done.
|
| +MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient) { |
| + base::MessageLoopForIO main_message_loop; |
| + |
| + TestingDelegate delegate; |
| + scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create( |
| + IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"), |
| + IPC::Channel::MODE_CLIENT, |
| + &delegate); |
| + |
| + bootstrap->Connect(); |
| + |
| + base::MessageLoop::current()->Run(); |
| + |
| + EXPECT_TRUE(delegate.passed()); |
| + |
| + return 0; |
| +} |
| + |
| +} // namespace |