Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: ipc/mojo/ipc_mojo_bootstrap_unittest.cc

Issue 2069803003: Fold //ipc/mojo into //ipc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-ipc-deps
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/mojo/ipc_mojo_bootstrap.cc ('k') | ipc/mojo/ipc_mojo_handle_attachment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <stdint.h>
8 #include <memory>
9
10 #include "base/base_paths.h"
11 #include "base/files/file.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "build/build_config.h"
15 #include "ipc/ipc_test_base.h"
16 #include "ipc/mojo/ipc.mojom.h"
17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/test/mojo_test_base.h"
19 #include "mojo/edk/test/multiprocess_test_helper.h"
20 #include "mojo/edk/test/scoped_ipc_support.h"
21
22 #if defined(OS_POSIX)
23 #include "base/file_descriptor_posix.h"
24 #endif
25
26 namespace {
27
28 class IPCMojoBootstrapTest : public testing::Test {
29 protected:
30 mojo::edk::test::MultiprocessTestHelper helper_;
31 };
32
33 class TestingDelegate : public IPC::MojoBootstrap::Delegate {
34 public:
35 explicit TestingDelegate(const base::Closure& quit_callback)
36 : passed_(false), quit_callback_(quit_callback) {}
37
38 void OnPipesAvailable(IPC::mojom::ChannelAssociatedPtrInfo send_channel,
39 IPC::mojom::ChannelAssociatedRequest receive_channel,
40 int32_t peer_pid) override;
41 void OnBootstrapError() override;
42
43 bool passed() const { return passed_; }
44
45 private:
46 bool passed_;
47 const base::Closure quit_callback_;
48 };
49
50 void TestingDelegate::OnPipesAvailable(
51 IPC::mojom::ChannelAssociatedPtrInfo send_channel,
52 IPC::mojom::ChannelAssociatedRequest receive_channel,
53 int32_t peer_pid) {
54 passed_ = true;
55 quit_callback_.Run();
56 }
57
58 void TestingDelegate::OnBootstrapError() {
59 quit_callback_.Run();
60 }
61
62 TEST_F(IPCMojoBootstrapTest, Connect) {
63 base::MessageLoop message_loop;
64 base::RunLoop run_loop;
65 TestingDelegate delegate(run_loop.QuitClosure());
66 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
67 helper_.StartChild("IPCMojoBootstrapTestClient"),
68 IPC::Channel::MODE_SERVER, &delegate);
69
70 bootstrap->Connect();
71 run_loop.Run();
72
73 EXPECT_TRUE(delegate.passed());
74 EXPECT_TRUE(helper_.WaitForChildTestShutdown());
75 }
76
77 // A long running process that connects to us.
78 MULTIPROCESS_TEST_MAIN_WITH_SETUP(
79 IPCMojoBootstrapTestClientTestChildMain,
80 ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) {
81 base::MessageLoop message_loop;
82 base::RunLoop run_loop;
83 TestingDelegate delegate(run_loop.QuitClosure());
84 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
85 mojo::edk::CreateChildMessagePipe(
86 mojo::edk::test::MultiprocessTestHelper::primordial_pipe_token),
87 IPC::Channel::MODE_CLIENT, &delegate);
88
89 bootstrap->Connect();
90
91 run_loop.Run();
92
93 return delegate.passed() ? 0 : 1;
94 }
95
96 } // namespace
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_mojo_bootstrap.cc ('k') | ipc/mojo/ipc_mojo_handle_attachment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698