OLD | NEW |
---|---|
(Empty) | |
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. | |
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 | |
16 namespace { | |
17 | |
18 class IPCMojoBootstrapTest : public IPCTestBase { | |
19 protected: | |
20 }; | |
21 | |
22 class TestingDelegate : public IPC::MojoBootstrap::Delegate { | |
23 public: | |
24 TestingDelegate() : passed_(false) {} | |
25 | |
26 virtual void OnPipeAvailable( | |
27 mojo::embedder::ScopedPlatformHandle handle) OVERRIDE; | |
28 virtual void OnBootstrapError() OVERRIDE; | |
29 | |
30 bool passed() const { return passed_; } | |
31 | |
32 private: | |
33 bool passed_; | |
34 }; | |
35 | |
36 void TestingDelegate::OnPipeAvailable( | |
37 mojo::embedder::ScopedPlatformHandle handle) { | |
38 passed_ = true; | |
39 base::MessageLoop::current()->Quit(); | |
40 } | |
41 | |
42 void TestingDelegate::OnBootstrapError() { | |
43 base::MessageLoop::current()->Quit(); | |
44 } | |
45 | |
46 TEST_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 | |
viettrungluu
2014/09/22 19:13:08
nit: Needs a period at the end.
Hajime Morrita
2014/09/22 19:32:48
Done.
| |
68 MULTIPROCESS_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 | |
OLD | NEW |