| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 ptr0.Bind(std::move(ptr_info)); | 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(std::move(request), router1); | 170 request = EmulatePassingAssociatedRequest(std::move(request), router1); |
| 171 | 171 |
| 172 IntegerSenderImpl impl1(std::move(request)); | 172 IntegerSenderImpl impl1(std::move(request)); |
| 173 AssociatedInterfacePtr<IntegerSender> ptr1; | 173 AssociatedInterfacePtr<IntegerSender> ptr1; |
| 174 ptr1.Bind(std::move(ptr_info)); | 174 ptr1.Bind(std::move(ptr_info)); |
| 175 | 175 |
| 176 base::RunLoop run_loop, run_loop2; |
| 176 bool ptr0_callback_run = false; | 177 bool ptr0_callback_run = false; |
| 177 ptr0->Echo(123, [&ptr0_callback_run](int32_t value) { | 178 ptr0->Echo(123, [&ptr0_callback_run, &run_loop](int32_t value) { |
| 178 EXPECT_EQ(123, value); | 179 EXPECT_EQ(123, value); |
| 179 ptr0_callback_run = true; | 180 ptr0_callback_run = true; |
| 181 run_loop.Quit(); |
| 180 }); | 182 }); |
| 181 | 183 |
| 182 bool ptr1_callback_run = false; | 184 bool ptr1_callback_run = false; |
| 183 ptr1->Echo(456, [&ptr1_callback_run](int32_t value) { | 185 ptr1->Echo(456, [&ptr1_callback_run, &run_loop2](int32_t value) { |
| 184 EXPECT_EQ(456, value); | 186 EXPECT_EQ(456, value); |
| 185 ptr1_callback_run = true; | 187 ptr1_callback_run = true; |
| 188 run_loop2.Quit(); |
| 186 }); | 189 }); |
| 187 | 190 |
| 188 PumpMessages(); | 191 run_loop.Run(); |
| 192 run_loop2.Run(); |
| 189 EXPECT_TRUE(ptr0_callback_run); | 193 EXPECT_TRUE(ptr0_callback_run); |
| 190 EXPECT_TRUE(ptr1_callback_run); | 194 EXPECT_TRUE(ptr1_callback_run); |
| 191 | 195 |
| 192 bool ptr0_error_callback_run = false; | 196 bool ptr0_error_callback_run = false; |
| 193 ptr0.set_connection_error_handler( | 197 base::RunLoop run_loop3; |
| 194 [&ptr0_error_callback_run]() { ptr0_error_callback_run = true; }); | 198 ptr0.set_connection_error_handler([&ptr0_error_callback_run, &run_loop3]() { |
| 199 ptr0_error_callback_run = true; |
| 200 run_loop3.Quit(); |
| 201 }); |
| 195 | 202 |
| 196 impl0.binding()->Close(); | 203 impl0.binding()->Close(); |
| 197 PumpMessages(); | 204 run_loop3.Run(); |
| 198 EXPECT_TRUE(ptr0_error_callback_run); | 205 EXPECT_TRUE(ptr0_error_callback_run); |
| 199 | 206 |
| 200 bool impl1_error_callback_run = false; | 207 bool impl1_error_callback_run = false; |
| 208 base::RunLoop run_loop4; |
| 201 impl1.binding()->set_connection_error_handler( | 209 impl1.binding()->set_connection_error_handler( |
| 202 [&impl1_error_callback_run]() { impl1_error_callback_run = true; }); | 210 [&impl1_error_callback_run, &run_loop4]() { |
| 211 impl1_error_callback_run = true; |
| 212 run_loop4.Quit(); |
| 213 }); |
| 203 | 214 |
| 204 ptr1.reset(); | 215 ptr1.reset(); |
| 205 PumpMessages(); | 216 run_loop4.Run(); |
| 206 EXPECT_TRUE(impl1_error_callback_run); | 217 EXPECT_TRUE(impl1_error_callback_run); |
| 207 } | 218 } |
| 208 | 219 |
| 209 class TestSender { | 220 class TestSender { |
| 210 public: | 221 public: |
| 211 TestSender() | 222 TestSender() |
| 212 : sender_thread_("TestSender"), | 223 : sender_thread_("TestSender"), |
| 213 next_sender_(nullptr), | 224 next_sender_(nullptr), |
| 214 max_value_to_send_(-1) { | 225 max_value_to_send_(-1) { |
| 215 base::Thread::Options thread_options; | 226 base::Thread::Options thread_options; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 524 |
| 514 TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) { | 525 TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) { |
| 515 IntegerSenderConnectionPtr connection_ptr; | 526 IntegerSenderConnectionPtr connection_ptr; |
| 516 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); | 527 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); |
| 517 | 528 |
| 518 IntegerSenderAssociatedPtr sender0; | 529 IntegerSenderAssociatedPtr sender0; |
| 519 connection_ptr->GetSender( | 530 connection_ptr->GetSender( |
| 520 GetProxy(&sender0, connection_ptr.associated_group())); | 531 GetProxy(&sender0, connection_ptr.associated_group())); |
| 521 | 532 |
| 522 int32_t echoed_value = 0; | 533 int32_t echoed_value = 0; |
| 523 sender0->Echo(123, [&echoed_value](int32_t value) { echoed_value = value; }); | 534 base::RunLoop run_loop; |
| 524 PumpMessages(); | 535 sender0->Echo(123, [&echoed_value, &run_loop](int32_t value) { |
| 536 echoed_value = value; |
| 537 run_loop.Quit(); |
| 538 }); |
| 539 run_loop.Run(); |
| 525 EXPECT_EQ(123, echoed_value); | 540 EXPECT_EQ(123, echoed_value); |
| 526 | 541 |
| 527 IntegerSenderAssociatedPtr sender1; | 542 IntegerSenderAssociatedPtr sender1; |
| 543 base::RunLoop run_loop2; |
| 528 connection_ptr->AsyncGetSender( | 544 connection_ptr->AsyncGetSender( |
| 529 [&sender1](AssociatedInterfacePtrInfo<IntegerSender> ptr_info) { | 545 [&sender1, &run_loop2]( |
| 546 AssociatedInterfacePtrInfo<IntegerSender> ptr_info) { |
| 530 sender1.Bind(std::move(ptr_info)); | 547 sender1.Bind(std::move(ptr_info)); |
| 548 run_loop2.Quit(); |
| 531 }); | 549 }); |
| 532 PumpMessages(); | 550 run_loop2.Run(); |
| 533 EXPECT_TRUE(sender1); | 551 EXPECT_TRUE(sender1); |
| 534 | 552 |
| 535 sender1->Echo(456, [&echoed_value](int32_t value) { echoed_value = value; }); | 553 base::RunLoop run_loop3; |
| 536 PumpMessages(); | 554 sender1->Echo(456, [&echoed_value, &run_loop3](int32_t value) { |
| 555 echoed_value = value; |
| 556 run_loop3.Quit(); |
| 557 }); |
| 558 run_loop3.Run(); |
| 537 EXPECT_EQ(456, echoed_value); | 559 EXPECT_EQ(456, echoed_value); |
| 538 } | 560 } |
| 539 | 561 |
| 540 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { | 562 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { |
| 541 IntegerSenderConnectionPtr connection_ptr; | 563 IntegerSenderConnectionPtr connection_ptr; |
| 542 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); | 564 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); |
| 543 | 565 |
| 544 IntegerSenderAssociatedPtr sender0; | 566 IntegerSenderAssociatedPtr sender0; |
| 545 connection_ptr->GetSender( | 567 connection_ptr->GetSender( |
| 546 GetProxy(&sender0, connection_ptr.associated_group())); | 568 GetProxy(&sender0, connection_ptr.associated_group())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 557 | 579 |
| 558 // The previous wait has dispatched the GetSender request message, therefore | 580 // 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 | 581 // an associated interface has been set up on the pipe. It is not allowed to |
| 560 // wait or pause. | 582 // wait or pause. |
| 561 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); | 583 EXPECT_TRUE(connection.binding()->HasAssociatedInterfaces()); |
| 562 } | 584 } |
| 563 | 585 |
| 564 } // namespace | 586 } // namespace |
| 565 } // namespace test | 587 } // namespace test |
| 566 } // namespace mojo | 588 } // namespace mojo |
| OLD | NEW |