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

Side by Side Diff: ipc/ipc_mojo_bootstrap_unittest.cc

Issue 2163633003: Support early associated interface binding on ChannelMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-channel-ipc-task-runner
Patch Set: . Created 4 years, 5 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/ipc_mojo_bootstrap.cc ('k') | mojo/public/cpp/bindings/lib/interface_endpoint_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ipc/ipc_mojo_bootstrap.h" 5 #include "ipc/ipc_mojo_bootstrap.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 17 matching lines...) Expand all
28 class IPCMojoBootstrapTest : public testing::Test { 28 class IPCMojoBootstrapTest : public testing::Test {
29 protected: 29 protected:
30 mojo::edk::test::MultiprocessTestHelper helper_; 30 mojo::edk::test::MultiprocessTestHelper helper_;
31 }; 31 };
32 32
33 class TestingDelegate : public IPC::MojoBootstrap::Delegate { 33 class TestingDelegate : public IPC::MojoBootstrap::Delegate {
34 public: 34 public:
35 explicit TestingDelegate(const base::Closure& quit_callback) 35 explicit TestingDelegate(const base::Closure& quit_callback)
36 : passed_(false), quit_callback_(quit_callback) {} 36 : passed_(false), quit_callback_(quit_callback) {}
37 37
38 void OnPipesAvailable(IPC::mojom::ChannelAssociatedPtrInfo send_channel, 38 void OnPipesAvailable(
39 IPC::mojom::ChannelAssociatedRequest receive_channel, 39 IPC::mojom::ChannelAssociatedPtr sender,
40 int32_t peer_pid) override; 40 IPC::mojom::ChannelAssociatedRequest receiver) override;
41 void OnBootstrapError() override;
42 41
43 bool passed() const { return passed_; } 42 bool passed() const { return passed_; }
44 43
45 private: 44 private:
46 bool passed_; 45 bool passed_;
47 const base::Closure quit_callback_; 46 const base::Closure quit_callback_;
48 }; 47 };
49 48
50 void TestingDelegate::OnPipesAvailable( 49 void TestingDelegate::OnPipesAvailable(
51 IPC::mojom::ChannelAssociatedPtrInfo send_channel, 50 IPC::mojom::ChannelAssociatedPtr sender,
52 IPC::mojom::ChannelAssociatedRequest receive_channel, 51 IPC::mojom::ChannelAssociatedRequest receiver) {
53 int32_t peer_pid) {
54 passed_ = true; 52 passed_ = true;
55 quit_callback_.Run(); 53 quit_callback_.Run();
56 } 54 }
57 55
58 void TestingDelegate::OnBootstrapError() {
59 quit_callback_.Run();
60 }
61
62 TEST_F(IPCMojoBootstrapTest, Connect) { 56 TEST_F(IPCMojoBootstrapTest, Connect) {
63 base::MessageLoop message_loop; 57 base::MessageLoop message_loop;
64 base::RunLoop run_loop; 58 base::RunLoop run_loop;
65 TestingDelegate delegate(run_loop.QuitClosure()); 59 TestingDelegate delegate(run_loop.QuitClosure());
66 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create( 60 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
67 helper_.StartChild("IPCMojoBootstrapTestClient"), 61 helper_.StartChild("IPCMojoBootstrapTestClient"),
68 IPC::Channel::MODE_SERVER, &delegate); 62 IPC::Channel::MODE_SERVER, &delegate,
63 base::ThreadTaskRunnerHandle::Get());
69 64
70 bootstrap->Connect(); 65 bootstrap->Connect();
71 run_loop.Run(); 66 run_loop.Run();
72 67
73 EXPECT_TRUE(delegate.passed()); 68 EXPECT_TRUE(delegate.passed());
74 EXPECT_TRUE(helper_.WaitForChildTestShutdown()); 69 EXPECT_TRUE(helper_.WaitForChildTestShutdown());
75 } 70 }
76 71
77 // A long running process that connects to us. 72 // A long running process that connects to us.
78 MULTIPROCESS_TEST_MAIN_WITH_SETUP( 73 MULTIPROCESS_TEST_MAIN_WITH_SETUP(
79 IPCMojoBootstrapTestClientTestChildMain, 74 IPCMojoBootstrapTestClientTestChildMain,
80 ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) { 75 ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) {
81 base::MessageLoop message_loop; 76 base::MessageLoop message_loop;
82 base::RunLoop run_loop; 77 base::RunLoop run_loop;
83 TestingDelegate delegate(run_loop.QuitClosure()); 78 TestingDelegate delegate(run_loop.QuitClosure());
84 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create( 79 std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
85 mojo::edk::CreateChildMessagePipe( 80 mojo::edk::CreateChildMessagePipe(
86 mojo::edk::test::MultiprocessTestHelper::primordial_pipe_token), 81 mojo::edk::test::MultiprocessTestHelper::primordial_pipe_token),
87 IPC::Channel::MODE_CLIENT, &delegate); 82 IPC::Channel::MODE_CLIENT, &delegate,
83 base::ThreadTaskRunnerHandle::Get());
88 84
89 bootstrap->Connect(); 85 bootstrap->Connect();
90 86
91 run_loop.Run(); 87 run_loop.Run();
92 88
93 return delegate.passed() ? 0 : 1; 89 return delegate.passed() ? 0 : 1;
94 } 90 }
95 91
96 } // namespace 92 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_mojo_bootstrap.cc ('k') | mojo/public/cpp/bindings/lib/interface_endpoint_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698