OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <utility> |
6 | 7 |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
11 #include "mojo/message_pump/message_pump_mojo.h" | 12 #include "mojo/message_pump/message_pump_mojo.h" |
12 #include "mojo/public/cpp/bindings/associated_binding.h" | 13 #include "mojo/public/cpp/bindings/associated_binding.h" |
13 #include "mojo/public/cpp/bindings/associated_group.h" | 14 #include "mojo/public/cpp/bindings/associated_group.h" |
14 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
15 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 16 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
16 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 17 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 18 #include "mojo/public/cpp/bindings/binding.h" |
18 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 19 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
19 #include "mojo/public/interfaces/bindings/tests/test_associated_interfaces.mojom
.h" | 20 #include "mojo/public/interfaces/bindings/tests/test_associated_interfaces.mojom
.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace mojo { | 23 namespace mojo { |
23 namespace test { | 24 namespace test { |
24 namespace { | 25 namespace { |
25 | 26 |
26 using mojo::internal::AssociatedInterfacePtrInfoHelper; | 27 using mojo::internal::AssociatedInterfacePtrInfoHelper; |
27 using mojo::internal::AssociatedInterfaceRequestHelper; | 28 using mojo::internal::AssociatedInterfaceRequestHelper; |
28 using mojo::internal::MultiplexRouter; | 29 using mojo::internal::MultiplexRouter; |
29 using mojo::internal::ScopedInterfaceEndpointHandle; | 30 using mojo::internal::ScopedInterfaceEndpointHandle; |
30 | 31 |
31 class IntegerSenderImpl : public IntegerSender { | 32 class IntegerSenderImpl : public IntegerSender { |
32 public: | 33 public: |
33 explicit IntegerSenderImpl(AssociatedInterfaceRequest<IntegerSender> request) | 34 explicit IntegerSenderImpl(AssociatedInterfaceRequest<IntegerSender> request) |
34 : binding_(this, request.Pass()) {} | 35 : binding_(this, std::move(request)) {} |
35 | 36 |
36 ~IntegerSenderImpl() override {} | 37 ~IntegerSenderImpl() override {} |
37 | 38 |
38 void set_notify_send_method_called( | 39 void set_notify_send_method_called( |
39 const base::Callback<void(int32_t)>& callback) { | 40 const base::Callback<void(int32_t)>& callback) { |
40 notify_send_method_called_ = callback; | 41 notify_send_method_called_ = callback; |
41 } | 42 } |
42 | 43 |
43 void Echo(int32_t value, const EchoCallback& callback) override { | 44 void Echo(int32_t value, const EchoCallback& callback) override { |
44 callback.Run(value); | 45 callback.Run(value); |
45 } | 46 } |
46 void Send(int32_t value) override { notify_send_method_called_.Run(value); } | 47 void Send(int32_t value) override { notify_send_method_called_.Run(value); } |
47 | 48 |
48 AssociatedBinding<IntegerSender>* binding() { return &binding_; } | 49 AssociatedBinding<IntegerSender>* binding() { return &binding_; } |
49 | 50 |
50 void set_connection_error_handler(const Closure& handler) { | 51 void set_connection_error_handler(const Closure& handler) { |
51 binding_.set_connection_error_handler(handler); | 52 binding_.set_connection_error_handler(handler); |
52 } | 53 } |
53 | 54 |
54 private: | 55 private: |
55 AssociatedBinding<IntegerSender> binding_; | 56 AssociatedBinding<IntegerSender> binding_; |
56 base::Callback<void(int32_t)> notify_send_method_called_; | 57 base::Callback<void(int32_t)> notify_send_method_called_; |
57 }; | 58 }; |
58 | 59 |
59 class IntegerSenderConnectionImpl : public IntegerSenderConnection { | 60 class IntegerSenderConnectionImpl : public IntegerSenderConnection { |
60 public: | 61 public: |
61 explicit IntegerSenderConnectionImpl( | 62 explicit IntegerSenderConnectionImpl( |
62 InterfaceRequest<IntegerSenderConnection> request) | 63 InterfaceRequest<IntegerSenderConnection> request) |
63 : binding_(this, request.Pass()) {} | 64 : binding_(this, std::move(request)) {} |
64 | 65 |
65 ~IntegerSenderConnectionImpl() override {} | 66 ~IntegerSenderConnectionImpl() override {} |
66 | 67 |
67 void GetSender(AssociatedInterfaceRequest<IntegerSender> sender) override { | 68 void GetSender(AssociatedInterfaceRequest<IntegerSender> sender) override { |
68 IntegerSenderImpl* sender_impl = new IntegerSenderImpl(sender.Pass()); | 69 IntegerSenderImpl* sender_impl = new IntegerSenderImpl(std::move(sender)); |
69 sender_impl->set_connection_error_handler( | 70 sender_impl->set_connection_error_handler( |
70 [sender_impl]() { delete sender_impl; }); | 71 [sender_impl]() { delete sender_impl; }); |
71 } | 72 } |
72 | 73 |
73 void AsyncGetSender(const AsyncGetSenderCallback& callback) override { | 74 void AsyncGetSender(const AsyncGetSenderCallback& callback) override { |
74 AssociatedInterfaceRequest<IntegerSender> request; | 75 AssociatedInterfaceRequest<IntegerSender> request; |
75 AssociatedInterfacePtrInfo<IntegerSender> ptr_info; | 76 AssociatedInterfacePtrInfo<IntegerSender> ptr_info; |
76 binding_.associated_group()->CreateAssociatedInterface( | 77 binding_.associated_group()->CreateAssociatedInterface( |
77 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | 78 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
78 GetSender(request.Pass()); | 79 GetSender(std::move(request)); |
79 callback.Run(ptr_info.Pass()); | 80 callback.Run(std::move(ptr_info)); |
80 } | 81 } |
81 | 82 |
82 Binding<IntegerSenderConnection>* binding() { return &binding_; } | 83 Binding<IntegerSenderConnection>* binding() { return &binding_; } |
83 | 84 |
84 private: | 85 private: |
85 Binding<IntegerSenderConnection> binding_; | 86 Binding<IntegerSenderConnection> binding_; |
86 }; | 87 }; |
87 | 88 |
88 class AssociatedInterfaceTest : public testing::Test { | 89 class AssociatedInterfaceTest : public testing::Test { |
89 public: | 90 public: |
90 AssociatedInterfaceTest() : loop_(common::MessagePumpMojo::Create()) {} | 91 AssociatedInterfaceTest() : loop_(common::MessagePumpMojo::Create()) {} |
91 ~AssociatedInterfaceTest() override { loop_.RunUntilIdle(); } | 92 ~AssociatedInterfaceTest() override { loop_.RunUntilIdle(); } |
92 | 93 |
93 void PumpMessages() { loop_.RunUntilIdle(); } | 94 void PumpMessages() { loop_.RunUntilIdle(); } |
94 | 95 |
95 template <typename T> | 96 template <typename T> |
96 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( | 97 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( |
97 AssociatedInterfacePtrInfo<T> ptr_info, | 98 AssociatedInterfacePtrInfo<T> ptr_info, |
98 scoped_refptr<MultiplexRouter> target) { | 99 scoped_refptr<MultiplexRouter> target) { |
99 ScopedInterfaceEndpointHandle handle = | 100 ScopedInterfaceEndpointHandle handle = |
100 AssociatedInterfacePtrInfoHelper::PassHandle(&ptr_info); | 101 AssociatedInterfacePtrInfoHelper::PassHandle(&ptr_info); |
101 CHECK(!handle.is_local()); | 102 CHECK(!handle.is_local()); |
102 | 103 |
103 ScopedInterfaceEndpointHandle new_handle = | 104 ScopedInterfaceEndpointHandle new_handle = |
104 target->CreateLocalEndpointHandle(handle.release()); | 105 target->CreateLocalEndpointHandle(handle.release()); |
105 | 106 |
106 AssociatedInterfacePtrInfo<T> result; | 107 AssociatedInterfacePtrInfo<T> result; |
107 AssociatedInterfacePtrInfoHelper::SetHandle(&result, new_handle.Pass()); | 108 AssociatedInterfacePtrInfoHelper::SetHandle(&result, std::move(new_handle)); |
108 result.set_version(ptr_info.version()); | 109 result.set_version(ptr_info.version()); |
109 return result.Pass(); | 110 return std::move(result); |
110 } | 111 } |
111 | 112 |
112 template <typename T> | 113 template <typename T> |
113 AssociatedInterfaceRequest<T> EmulatePassingAssociatedRequest( | 114 AssociatedInterfaceRequest<T> EmulatePassingAssociatedRequest( |
114 AssociatedInterfaceRequest<T> request, | 115 AssociatedInterfaceRequest<T> request, |
115 scoped_refptr<MultiplexRouter> target) { | 116 scoped_refptr<MultiplexRouter> target) { |
116 ScopedInterfaceEndpointHandle handle = | 117 ScopedInterfaceEndpointHandle handle = |
117 AssociatedInterfaceRequestHelper::PassHandle(&request); | 118 AssociatedInterfaceRequestHelper::PassHandle(&request); |
118 CHECK(!handle.is_local()); | 119 CHECK(!handle.is_local()); |
119 | 120 |
120 ScopedInterfaceEndpointHandle new_handle = | 121 ScopedInterfaceEndpointHandle new_handle = |
121 target->CreateLocalEndpointHandle(handle.release()); | 122 target->CreateLocalEndpointHandle(handle.release()); |
122 | 123 |
123 AssociatedInterfaceRequest<T> result; | 124 AssociatedInterfaceRequest<T> result; |
124 AssociatedInterfaceRequestHelper::SetHandle(&result, new_handle.Pass()); | 125 AssociatedInterfaceRequestHelper::SetHandle(&result, std::move(new_handle)); |
125 return result.Pass(); | 126 return std::move(result); |
126 } | 127 } |
127 | 128 |
128 // Okay to call from any thread. | 129 // Okay to call from any thread. |
129 void QuitRunLoop(base::RunLoop* run_loop) { | 130 void QuitRunLoop(base::RunLoop* run_loop) { |
130 if (loop_.task_runner()->BelongsToCurrentThread()) { | 131 if (loop_.task_runner()->BelongsToCurrentThread()) { |
131 run_loop->Quit(); | 132 run_loop->Quit(); |
132 } else { | 133 } else { |
133 loop_.PostTask( | 134 loop_.PostTask( |
134 FROM_HERE, | 135 FROM_HERE, |
135 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, | 136 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, |
136 base::Unretained(this), base::Unretained(run_loop))); | 137 base::Unretained(this), base::Unretained(run_loop))); |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 private: | 141 private: |
141 base::MessageLoop loop_; | 142 base::MessageLoop loop_; |
142 }; | 143 }; |
143 | 144 |
144 TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) { | 145 TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) { |
145 // Bind to the same pipe two associated interfaces, whose implementation lives | 146 // Bind to the same pipe two associated interfaces, whose implementation lives |
146 // at different ends. Test that the two don't interfere with each other. | 147 // at different ends. Test that the two don't interfere with each other. |
147 | 148 |
148 MessagePipe pipe; | 149 MessagePipe pipe; |
149 scoped_refptr<MultiplexRouter> router0( | 150 scoped_refptr<MultiplexRouter> router0( |
150 new MultiplexRouter(true, pipe.handle0.Pass())); | 151 new MultiplexRouter(true, std::move(pipe.handle0))); |
151 scoped_refptr<MultiplexRouter> router1( | 152 scoped_refptr<MultiplexRouter> router1( |
152 new MultiplexRouter(false, pipe.handle1.Pass())); | 153 new MultiplexRouter(false, std::move(pipe.handle1))); |
153 | 154 |
154 AssociatedInterfaceRequest<IntegerSender> request; | 155 AssociatedInterfaceRequest<IntegerSender> request; |
155 AssociatedInterfacePtrInfo<IntegerSender> ptr_info; | 156 AssociatedInterfacePtrInfo<IntegerSender> ptr_info; |
156 | 157 |
157 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 158 router0->CreateAssociatedGroup()->CreateAssociatedInterface( |
158 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | 159 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
159 ptr_info = EmulatePassingAssociatedPtrInfo(ptr_info.Pass(), router1); | 160 ptr_info = EmulatePassingAssociatedPtrInfo(std::move(ptr_info), router1); |
160 | 161 |
161 IntegerSenderImpl impl0(request.Pass()); | 162 IntegerSenderImpl impl0(std::move(request)); |
162 AssociatedInterfacePtr<IntegerSender> ptr0; | 163 AssociatedInterfacePtr<IntegerSender> ptr0; |
163 ptr0.Bind(ptr_info.Pass()); | 164 ptr0.Bind(std::move(ptr_info)); |
164 | 165 |
165 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 166 router0->CreateAssociatedGroup()->CreateAssociatedInterface( |
166 AssociatedGroup::WILL_PASS_REQUEST, &ptr_info, &request); | 167 AssociatedGroup::WILL_PASS_REQUEST, &ptr_info, &request); |
167 request = EmulatePassingAssociatedRequest(request.Pass(), router1); | 168 request = EmulatePassingAssociatedRequest(std::move(request), router1); |
168 | 169 |
169 IntegerSenderImpl impl1(request.Pass()); | 170 IntegerSenderImpl impl1(std::move(request)); |
170 AssociatedInterfacePtr<IntegerSender> ptr1; | 171 AssociatedInterfacePtr<IntegerSender> ptr1; |
171 ptr1.Bind(ptr_info.Pass()); | 172 ptr1.Bind(std::move(ptr_info)); |
172 | 173 |
173 bool ptr0_callback_run = false; | 174 bool ptr0_callback_run = false; |
174 ptr0->Echo(123, [&ptr0_callback_run](int32_t value) { | 175 ptr0->Echo(123, [&ptr0_callback_run](int32_t value) { |
175 EXPECT_EQ(123, value); | 176 EXPECT_EQ(123, value); |
176 ptr0_callback_run = true; | 177 ptr0_callback_run = true; |
177 }); | 178 }); |
178 | 179 |
179 bool ptr1_callback_run = false; | 180 bool ptr1_callback_run = false; |
180 ptr1->Echo(456, [&ptr1_callback_run](int32_t value) { | 181 ptr1->Echo(456, [&ptr1_callback_run](int32_t value) { |
181 EXPECT_EQ(456, value); | 182 EXPECT_EQ(456, value); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 base::Bind(&common::MessagePumpMojo::Create); | 215 base::Bind(&common::MessagePumpMojo::Create); |
215 sender_thread_.StartWithOptions(thread_options); | 216 sender_thread_.StartWithOptions(thread_options); |
216 } | 217 } |
217 | 218 |
218 // The following three methods are called on the corresponding sender thread. | 219 // The following three methods are called on the corresponding sender thread. |
219 void SetUp(AssociatedInterfacePtrInfo<IntegerSender> ptr_info, | 220 void SetUp(AssociatedInterfacePtrInfo<IntegerSender> ptr_info, |
220 TestSender* next_sender, | 221 TestSender* next_sender, |
221 int32_t max_value_to_send) { | 222 int32_t max_value_to_send) { |
222 CHECK(sender_thread_.task_runner()->BelongsToCurrentThread()); | 223 CHECK(sender_thread_.task_runner()->BelongsToCurrentThread()); |
223 | 224 |
224 ptr_.Bind(ptr_info.Pass()); | 225 ptr_.Bind(std::move(ptr_info)); |
225 next_sender_ = next_sender ? next_sender : this; | 226 next_sender_ = next_sender ? next_sender : this; |
226 max_value_to_send_ = max_value_to_send; | 227 max_value_to_send_ = max_value_to_send; |
227 } | 228 } |
228 | 229 |
229 void Send(int32_t value) { | 230 void Send(int32_t value) { |
230 CHECK(sender_thread_.task_runner()->BelongsToCurrentThread()); | 231 CHECK(sender_thread_.task_runner()->BelongsToCurrentThread()); |
231 | 232 |
232 if (value > max_value_to_send_) | 233 if (value > max_value_to_send_) |
233 return; | 234 return; |
234 | 235 |
(...skipping 28 matching lines...) Expand all Loading... |
263 base::Bind(&common::MessagePumpMojo::Create); | 264 base::Bind(&common::MessagePumpMojo::Create); |
264 receiver_thread_.StartWithOptions(thread_options); | 265 receiver_thread_.StartWithOptions(thread_options); |
265 } | 266 } |
266 | 267 |
267 void SetUp(AssociatedInterfaceRequest<IntegerSender> request0, | 268 void SetUp(AssociatedInterfaceRequest<IntegerSender> request0, |
268 AssociatedInterfaceRequest<IntegerSender> request1, | 269 AssociatedInterfaceRequest<IntegerSender> request1, |
269 int32_t max_value_to_receive, | 270 int32_t max_value_to_receive, |
270 const base::Closure& notify_finish) { | 271 const base::Closure& notify_finish) { |
271 CHECK(receiver_thread_.task_runner()->BelongsToCurrentThread()); | 272 CHECK(receiver_thread_.task_runner()->BelongsToCurrentThread()); |
272 | 273 |
273 impl0_.reset(new IntegerSenderImpl(request0.Pass())); | 274 impl0_.reset(new IntegerSenderImpl(std::move(request0))); |
274 impl0_->set_notify_send_method_called( | 275 impl0_->set_notify_send_method_called( |
275 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); | 276 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); |
276 impl1_.reset(new IntegerSenderImpl(request1.Pass())); | 277 impl1_.reset(new IntegerSenderImpl(std::move(request1))); |
277 impl1_->set_notify_send_method_called( | 278 impl1_->set_notify_send_method_called( |
278 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); | 279 base::Bind(&TestReceiver::SendMethodCalled, base::Unretained(this))); |
279 | 280 |
280 max_value_to_receive_ = max_value_to_receive; | 281 max_value_to_receive_ = max_value_to_receive; |
281 notify_finish_ = notify_finish; | 282 notify_finish_ = notify_finish; |
282 } | 283 } |
283 | 284 |
284 void TearDown() { | 285 void TearDown() { |
285 CHECK(receiver_thread_.task_runner()->BelongsToCurrentThread()); | 286 CHECK(receiver_thread_.task_runner()->BelongsToCurrentThread()); |
286 | 287 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 }; | 342 }; |
342 | 343 |
343 TEST_F(AssociatedInterfaceTest, MultiThreadAccess) { | 344 TEST_F(AssociatedInterfaceTest, MultiThreadAccess) { |
344 // Set up four associated interfaces on a message pipe. Use the inteface | 345 // Set up four associated interfaces on a message pipe. Use the inteface |
345 // pointers on four threads in parallel; run the interface implementations on | 346 // pointers on four threads in parallel; run the interface implementations on |
346 // two threads. Test that multi-threaded access works. | 347 // two threads. Test that multi-threaded access works. |
347 | 348 |
348 const int32_t kMaxValue = 1000; | 349 const int32_t kMaxValue = 1000; |
349 MessagePipe pipe; | 350 MessagePipe pipe; |
350 scoped_refptr<MultiplexRouter> router0( | 351 scoped_refptr<MultiplexRouter> router0( |
351 new MultiplexRouter(true, pipe.handle0.Pass())); | 352 new MultiplexRouter(true, std::move(pipe.handle0))); |
352 scoped_refptr<MultiplexRouter> router1( | 353 scoped_refptr<MultiplexRouter> router1( |
353 new MultiplexRouter(false, pipe.handle1.Pass())); | 354 new MultiplexRouter(false, std::move(pipe.handle1))); |
354 | 355 |
355 AssociatedInterfaceRequest<IntegerSender> requests[4]; | 356 AssociatedInterfaceRequest<IntegerSender> requests[4]; |
356 AssociatedInterfacePtrInfo<IntegerSender> ptr_infos[4]; | 357 AssociatedInterfacePtrInfo<IntegerSender> ptr_infos[4]; |
357 | 358 |
358 for (size_t i = 0; i < 4; ++i) { | 359 for (size_t i = 0; i < 4; ++i) { |
359 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 360 router0->CreateAssociatedGroup()->CreateAssociatedInterface( |
360 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); | 361 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); |
361 ptr_infos[i] = | 362 ptr_infos[i] = |
362 EmulatePassingAssociatedPtrInfo(ptr_infos[i].Pass(), router1); | 363 EmulatePassingAssociatedPtrInfo(std::move(ptr_infos[i]), router1); |
363 } | 364 } |
364 | 365 |
365 TestSender senders[4]; | 366 TestSender senders[4]; |
366 for (size_t i = 0; i < 4; ++i) { | 367 for (size_t i = 0; i < 4; ++i) { |
367 senders[i].sender_thread()->task_runner()->PostTask( | 368 senders[i].sender_thread()->task_runner()->PostTask( |
368 FROM_HERE, base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), | 369 FROM_HERE, base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), |
369 base::Passed(&ptr_infos[i]), nullptr, | 370 base::Passed(&ptr_infos[i]), nullptr, |
370 static_cast<int32_t>(kMaxValue * (i + 1) / 4))); | 371 static_cast<int32_t>(kMaxValue * (i + 1) / 4))); |
371 } | 372 } |
372 | 373 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 431 |
431 TEST_F(AssociatedInterfaceTest, FIFO) { | 432 TEST_F(AssociatedInterfaceTest, FIFO) { |
432 // Set up four associated interfaces on a message pipe. Use the inteface | 433 // Set up four associated interfaces on a message pipe. Use the inteface |
433 // pointers on four threads; run the interface implementations on two threads. | 434 // pointers on four threads; run the interface implementations on two threads. |
434 // Take turns to make calls using the four pointers. Test that FIFO-ness is | 435 // Take turns to make calls using the four pointers. Test that FIFO-ness is |
435 // preserved. | 436 // preserved. |
436 | 437 |
437 const int32_t kMaxValue = 100; | 438 const int32_t kMaxValue = 100; |
438 MessagePipe pipe; | 439 MessagePipe pipe; |
439 scoped_refptr<MultiplexRouter> router0( | 440 scoped_refptr<MultiplexRouter> router0( |
440 new MultiplexRouter(true, pipe.handle0.Pass())); | 441 new MultiplexRouter(true, std::move(pipe.handle0))); |
441 scoped_refptr<MultiplexRouter> router1( | 442 scoped_refptr<MultiplexRouter> router1( |
442 new MultiplexRouter(false, pipe.handle1.Pass())); | 443 new MultiplexRouter(false, std::move(pipe.handle1))); |
443 | 444 |
444 AssociatedInterfaceRequest<IntegerSender> requests[4]; | 445 AssociatedInterfaceRequest<IntegerSender> requests[4]; |
445 AssociatedInterfacePtrInfo<IntegerSender> ptr_infos[4]; | 446 AssociatedInterfacePtrInfo<IntegerSender> ptr_infos[4]; |
446 | 447 |
447 for (size_t i = 0; i < 4; ++i) { | 448 for (size_t i = 0; i < 4; ++i) { |
448 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 449 router0->CreateAssociatedGroup()->CreateAssociatedInterface( |
449 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); | 450 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); |
450 ptr_infos[i] = | 451 ptr_infos[i] = |
451 EmulatePassingAssociatedPtrInfo(ptr_infos[i].Pass(), router1); | 452 EmulatePassingAssociatedPtrInfo(std::move(ptr_infos[i]), router1); |
452 } | 453 } |
453 | 454 |
454 TestSender senders[4]; | 455 TestSender senders[4]; |
455 for (size_t i = 0; i < 4; ++i) { | 456 for (size_t i = 0; i < 4; ++i) { |
456 senders[i].sender_thread()->task_runner()->PostTask( | 457 senders[i].sender_thread()->task_runner()->PostTask( |
457 FROM_HERE, | 458 FROM_HERE, |
458 base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), | 459 base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), |
459 base::Passed(&ptr_infos[i]), | 460 base::Passed(&ptr_infos[i]), |
460 base::Unretained(&senders[(i + 1) % 4]), kMaxValue)); | 461 base::Unretained(&senders[(i + 1) % 4]), kMaxValue)); |
461 } | 462 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 GetProxy(&sender0, connection_ptr.associated_group())); | 518 GetProxy(&sender0, connection_ptr.associated_group())); |
518 | 519 |
519 int32_t echoed_value = 0; | 520 int32_t echoed_value = 0; |
520 sender0->Echo(123, [&echoed_value](int32_t value) { echoed_value = value; }); | 521 sender0->Echo(123, [&echoed_value](int32_t value) { echoed_value = value; }); |
521 PumpMessages(); | 522 PumpMessages(); |
522 EXPECT_EQ(123, echoed_value); | 523 EXPECT_EQ(123, echoed_value); |
523 | 524 |
524 IntegerSenderAssociatedPtr sender1; | 525 IntegerSenderAssociatedPtr sender1; |
525 connection_ptr->AsyncGetSender( | 526 connection_ptr->AsyncGetSender( |
526 [&sender1](AssociatedInterfacePtrInfo<IntegerSender> ptr_info) { | 527 [&sender1](AssociatedInterfacePtrInfo<IntegerSender> ptr_info) { |
527 sender1.Bind(ptr_info.Pass()); | 528 sender1.Bind(std::move(ptr_info)); |
528 }); | 529 }); |
529 PumpMessages(); | 530 PumpMessages(); |
530 EXPECT_TRUE(sender1); | 531 EXPECT_TRUE(sender1); |
531 | 532 |
532 sender1->Echo(456, [&echoed_value](int32_t value) { echoed_value = value; }); | 533 sender1->Echo(456, [&echoed_value](int32_t value) { echoed_value = value; }); |
533 PumpMessages(); | 534 PumpMessages(); |
534 EXPECT_EQ(456, echoed_value); | 535 EXPECT_EQ(456, echoed_value); |
535 } | 536 } |
536 | 537 |
537 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { | 538 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { |
(...skipping 16 matching lines...) Expand all Loading... |
554 | 555 |
555 // The previous wait has dispatched the GetSender request message, therefore | 556 // The previous wait has dispatched the GetSender request message, therefore |
556 // an associated interface has been set up on the pipe. It is not allowed to | 557 // an associated interface has been set up on the pipe. It is not allowed to |
557 // wait or pause. | 558 // wait or pause. |
558 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); | 559 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); |
559 } | 560 } |
560 | 561 |
561 } // namespace | 562 } // namespace |
562 } // namespace test | 563 } // namespace test |
563 } // namespace mojo | 564 } // namespace mojo |
OLD | NEW |