Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ipc / mojo / ipc_mojo_bootstrap_unittest.cc
blob3eabf1ff958c52066b42869bdc17d44d9c77e97e
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 // Times out on Android; see http://crbug.com/502290
46 #if defined(OS_ANDROID)
47 #define MAYBE_Connect DISABLED_Connect
48 #else
49 #define MAYBE_Connect Connect
50 #endif
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());
59 #if defined(OS_POSIX)
60 ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
61 #else
62 ASSERT_TRUE(StartClient());
63 #endif
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);
80 bootstrap->Connect();
82 base::MessageLoop::current()->Run();
84 EXPECT_TRUE(delegate.passed());
86 return 0;
89 } // namespace