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

Side by Side Diff: mojo/public/cpp/bindings/tests/associated_interface_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698