| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( | 103 AssociatedInterfacePtrInfo<T> EmulatePassingAssociatedPtrInfo( |
| 104 AssociatedInterfacePtrInfo<T> ptr_info, | 104 AssociatedInterfacePtrInfo<T> ptr_info, |
| 105 scoped_refptr<MultiplexRouter> target) { | 105 scoped_refptr<MultiplexRouter> target) { |
| 106 ScopedInterfaceEndpointHandle handle = ptr_info.PassHandle(); | 106 ScopedInterfaceEndpointHandle handle = ptr_info.PassHandle(); |
| 107 CHECK(!handle.is_local()); | 107 CHECK(!handle.is_local()); |
| 108 return AssociatedInterfacePtrInfo<T>( | 108 return AssociatedInterfacePtrInfo<T>( |
| 109 target->CreateLocalEndpointHandle(handle.release()), | 109 target->CreateLocalEndpointHandle(handle.release()), |
| 110 ptr_info.version()); | 110 ptr_info.version()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 template <typename T> | 113 void CreateRouterPair(scoped_refptr<MultiplexRouter>* router0, |
| 114 AssociatedInterfaceRequest<T> EmulatePassingAssociatedRequest( | 114 scoped_refptr<MultiplexRouter>* router1) { |
| 115 AssociatedInterfaceRequest<T> request, | 115 MessagePipe pipe; |
| 116 scoped_refptr<MultiplexRouter> target) { | 116 *router0 = new MultiplexRouter(true, std::move(pipe.handle0), |
| 117 ScopedInterfaceEndpointHandle handle = request.PassHandle(); | 117 base::ThreadTaskRunnerHandle::Get()); |
| 118 CHECK(!handle.is_local()); | 118 *router1 = new MultiplexRouter(false, std::move(pipe.handle1), |
| 119 return MakeAssociatedRequest<T>( | 119 base::ThreadTaskRunnerHandle::Get()); |
| 120 target->CreateLocalEndpointHandle(handle.release())); | 120 } |
| 121 |
| 122 void CreateIntegerSenderWithExistingRouters( |
| 123 scoped_refptr<MultiplexRouter> router0, |
| 124 IntegerSenderAssociatedPtrInfo* ptr_info0, |
| 125 scoped_refptr<MultiplexRouter> router1, |
| 126 IntegerSenderAssociatedRequest* request1) { |
| 127 router1->CreateAssociatedGroup()->CreateAssociatedInterface( |
| 128 AssociatedGroup::WILL_PASS_PTR, ptr_info0, request1); |
| 129 *ptr_info0 = |
| 130 EmulatePassingAssociatedPtrInfo(std::move(*ptr_info0), router0); |
| 131 } |
| 132 |
| 133 void CreateIntegerSender(IntegerSenderAssociatedPtrInfo* ptr_info, |
| 134 IntegerSenderAssociatedRequest* request) { |
| 135 scoped_refptr<MultiplexRouter> router0; |
| 136 scoped_refptr<MultiplexRouter> router1; |
| 137 CreateRouterPair(&router0, &router1); |
| 138 CreateIntegerSenderWithExistingRouters(router1, ptr_info, router0, request); |
| 121 } | 139 } |
| 122 | 140 |
| 123 // Okay to call from any thread. | 141 // Okay to call from any thread. |
| 124 void QuitRunLoop(base::RunLoop* run_loop) { | 142 void QuitRunLoop(base::RunLoop* run_loop) { |
| 125 if (loop_.task_runner()->BelongsToCurrentThread()) { | 143 if (loop_.task_runner()->BelongsToCurrentThread()) { |
| 126 run_loop->Quit(); | 144 run_loop->Quit(); |
| 127 } else { | 145 } else { |
| 128 loop_.task_runner()->PostTask( | 146 loop_.task_runner()->PostTask( |
| 129 FROM_HERE, | 147 FROM_HERE, |
| 130 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, | 148 base::Bind(&AssociatedInterfaceTest::QuitRunLoop, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 180 } |
| 163 | 181 |
| 164 void Fail() { | 182 void Fail() { |
| 165 FAIL() << "Unexpected connection error"; | 183 FAIL() << "Unexpected connection error"; |
| 166 } | 184 } |
| 167 | 185 |
| 168 TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) { | 186 TEST_F(AssociatedInterfaceTest, InterfacesAtBothEnds) { |
| 169 // Bind to the same pipe two associated interfaces, whose implementation lives | 187 // Bind to the same pipe two associated interfaces, whose implementation lives |
| 170 // at different ends. Test that the two don't interfere with each other. | 188 // at different ends. Test that the two don't interfere with each other. |
| 171 | 189 |
| 172 MessagePipe pipe; | 190 scoped_refptr<MultiplexRouter> router0; |
| 173 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | 191 scoped_refptr<MultiplexRouter> router1; |
| 174 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | 192 CreateRouterPair(&router0, &router1); |
| 175 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | |
| 176 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 177 | 193 |
| 178 AssociatedInterfaceRequest<IntegerSender> request; | 194 AssociatedInterfaceRequest<IntegerSender> request; |
| 179 IntegerSenderAssociatedPtrInfo ptr_info; | 195 IntegerSenderAssociatedPtrInfo ptr_info; |
| 180 | 196 CreateIntegerSenderWithExistingRouters(router1, &ptr_info, router0, &request); |
| 181 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | |
| 182 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | |
| 183 ptr_info = EmulatePassingAssociatedPtrInfo(std::move(ptr_info), router1); | |
| 184 | 197 |
| 185 IntegerSenderImpl impl0(std::move(request)); | 198 IntegerSenderImpl impl0(std::move(request)); |
| 186 AssociatedInterfacePtr<IntegerSender> ptr0; | 199 AssociatedInterfacePtr<IntegerSender> ptr0; |
| 187 ptr0.Bind(std::move(ptr_info)); | 200 ptr0.Bind(std::move(ptr_info)); |
| 188 | 201 |
| 189 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 202 CreateIntegerSenderWithExistingRouters(router0, &ptr_info, router1, &request); |
| 190 AssociatedGroup::WILL_PASS_REQUEST, &ptr_info, &request); | |
| 191 request = EmulatePassingAssociatedRequest(std::move(request), router1); | |
| 192 | 203 |
| 193 IntegerSenderImpl impl1(std::move(request)); | 204 IntegerSenderImpl impl1(std::move(request)); |
| 194 AssociatedInterfacePtr<IntegerSender> ptr1; | 205 AssociatedInterfacePtr<IntegerSender> ptr1; |
| 195 ptr1.Bind(std::move(ptr_info)); | 206 ptr1.Bind(std::move(ptr_info)); |
| 196 | 207 |
| 197 base::RunLoop run_loop, run_loop2; | 208 base::RunLoop run_loop, run_loop2; |
| 198 bool ptr0_callback_run = false; | 209 bool ptr0_callback_run = false; |
| 199 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure(123, &ptr0_callback_run, | 210 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure(123, &ptr0_callback_run, |
| 200 run_loop.QuitClosure())); | 211 run_loop.QuitClosure())); |
| 201 | 212 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 base::Closure notify_finish_; | 369 base::Closure notify_finish_; |
| 359 }; | 370 }; |
| 360 | 371 |
| 361 TEST_F(AssociatedInterfaceTest, MultiThreadAccess) { | 372 TEST_F(AssociatedInterfaceTest, MultiThreadAccess) { |
| 362 // Set up four associated interfaces on a message pipe. Use the inteface | 373 // Set up four associated interfaces on a message pipe. Use the inteface |
| 363 // pointers on four threads in parallel; run the interface implementations on | 374 // pointers on four threads in parallel; run the interface implementations on |
| 364 // two threads. Test that multi-threaded access works. | 375 // two threads. Test that multi-threaded access works. |
| 365 | 376 |
| 366 const int32_t kMaxValue = 1000; | 377 const int32_t kMaxValue = 1000; |
| 367 MessagePipe pipe; | 378 MessagePipe pipe; |
| 368 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | 379 scoped_refptr<MultiplexRouter> router0; |
| 369 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | 380 scoped_refptr<MultiplexRouter> router1; |
| 370 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | 381 CreateRouterPair(&router0, &router1); |
| 371 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 372 | 382 |
| 373 AssociatedInterfaceRequest<IntegerSender> requests[4]; | 383 AssociatedInterfaceRequest<IntegerSender> requests[4]; |
| 374 IntegerSenderAssociatedPtrInfo ptr_infos[4]; | 384 IntegerSenderAssociatedPtrInfo ptr_infos[4]; |
| 375 | |
| 376 for (size_t i = 0; i < 4; ++i) { | 385 for (size_t i = 0; i < 4; ++i) { |
| 377 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 386 CreateIntegerSenderWithExistingRouters(router1, &ptr_infos[i], router0, |
| 378 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); | 387 &requests[i]); |
| 379 ptr_infos[i] = | |
| 380 EmulatePassingAssociatedPtrInfo(std::move(ptr_infos[i]), router1); | |
| 381 } | 388 } |
| 382 | 389 |
| 383 TestSender senders[4]; | 390 TestSender senders[4]; |
| 384 for (size_t i = 0; i < 4; ++i) { | 391 for (size_t i = 0; i < 4; ++i) { |
| 385 senders[i].sender_thread()->task_runner()->PostTask( | 392 senders[i].sender_thread()->task_runner()->PostTask( |
| 386 FROM_HERE, base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), | 393 FROM_HERE, base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), |
| 387 base::Passed(&ptr_infos[i]), nullptr, | 394 base::Passed(&ptr_infos[i]), nullptr, |
| 388 kMaxValue * (i + 1) / 4)); | 395 kMaxValue * (i + 1) / 4)); |
| 389 } | 396 } |
| 390 | 397 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 454 } |
| 448 | 455 |
| 449 TEST_F(AssociatedInterfaceTest, FIFO) { | 456 TEST_F(AssociatedInterfaceTest, FIFO) { |
| 450 // Set up four associated interfaces on a message pipe. Use the inteface | 457 // Set up four associated interfaces on a message pipe. Use the inteface |
| 451 // pointers on four threads; run the interface implementations on two threads. | 458 // pointers on four threads; run the interface implementations on two threads. |
| 452 // Take turns to make calls using the four pointers. Test that FIFO-ness is | 459 // Take turns to make calls using the four pointers. Test that FIFO-ness is |
| 453 // preserved. | 460 // preserved. |
| 454 | 461 |
| 455 const int32_t kMaxValue = 100; | 462 const int32_t kMaxValue = 100; |
| 456 MessagePipe pipe; | 463 MessagePipe pipe; |
| 457 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | 464 scoped_refptr<MultiplexRouter> router0; |
| 458 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | 465 scoped_refptr<MultiplexRouter> router1; |
| 459 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | 466 CreateRouterPair(&router0, &router1); |
| 460 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 461 | 467 |
| 462 AssociatedInterfaceRequest<IntegerSender> requests[4]; | 468 AssociatedInterfaceRequest<IntegerSender> requests[4]; |
| 463 IntegerSenderAssociatedPtrInfo ptr_infos[4]; | 469 IntegerSenderAssociatedPtrInfo ptr_infos[4]; |
| 464 | |
| 465 for (size_t i = 0; i < 4; ++i) { | 470 for (size_t i = 0; i < 4; ++i) { |
| 466 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 471 CreateIntegerSenderWithExistingRouters(router1, &ptr_infos[i], router0, |
| 467 AssociatedGroup::WILL_PASS_PTR, &ptr_infos[i], &requests[i]); | 472 &requests[i]); |
| 468 ptr_infos[i] = | |
| 469 EmulatePassingAssociatedPtrInfo(std::move(ptr_infos[i]), router1); | |
| 470 } | 473 } |
| 471 | 474 |
| 472 TestSender senders[4]; | 475 TestSender senders[4]; |
| 473 for (size_t i = 0; i < 4; ++i) { | 476 for (size_t i = 0; i < 4; ++i) { |
| 474 senders[i].sender_thread()->task_runner()->PostTask( | 477 senders[i].sender_thread()->task_runner()->PostTask( |
| 475 FROM_HERE, | 478 FROM_HERE, |
| 476 base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), | 479 base::Bind(&TestSender::SetUp, base::Unretained(&senders[i]), |
| 477 base::Passed(&ptr_infos[i]), | 480 base::Passed(&ptr_infos[i]), |
| 478 base::Unretained(&senders[(i + 1) % 4]), kMaxValue)); | 481 base::Unretained(&senders[(i + 1) % 4]), kMaxValue)); |
| 479 } | 482 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 ping_b->Ping(loop.QuitClosure()); | 742 ping_b->Ping(loop.QuitClosure()); |
| 740 loop.Run(); | 743 loop.Run(); |
| 741 } | 744 } |
| 742 | 745 |
| 743 EXPECT_EQ(3, a_status); | 746 EXPECT_EQ(3, a_status); |
| 744 EXPECT_EQ(3, b_status); | 747 EXPECT_EQ(3, b_status); |
| 745 } | 748 } |
| 746 } | 749 } |
| 747 | 750 |
| 748 TEST_F(AssociatedInterfaceTest, AssociatedPtrFlushForTesting) { | 751 TEST_F(AssociatedInterfaceTest, AssociatedPtrFlushForTesting) { |
| 749 MessagePipe pipe; | |
| 750 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | |
| 751 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | |
| 752 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | |
| 753 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 754 | |
| 755 AssociatedInterfaceRequest<IntegerSender> request; | 752 AssociatedInterfaceRequest<IntegerSender> request; |
| 756 IntegerSenderAssociatedPtrInfo ptr_info; | 753 IntegerSenderAssociatedPtrInfo ptr_info; |
| 757 | 754 CreateIntegerSender(&ptr_info, &request); |
| 758 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | |
| 759 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | |
| 760 ptr_info = EmulatePassingAssociatedPtrInfo(std::move(ptr_info), router1); | |
| 761 | 755 |
| 762 IntegerSenderImpl impl0(std::move(request)); | 756 IntegerSenderImpl impl0(std::move(request)); |
| 763 AssociatedInterfacePtr<IntegerSender> ptr0; | 757 AssociatedInterfacePtr<IntegerSender> ptr0; |
| 764 ptr0.Bind(std::move(ptr_info)); | 758 ptr0.Bind(std::move(ptr_info)); |
| 765 ptr0.set_connection_error_handler(base::Bind(&Fail)); | 759 ptr0.set_connection_error_handler(base::Bind(&Fail)); |
| 766 | 760 |
| 767 bool ptr0_callback_run = false; | 761 bool ptr0_callback_run = false; |
| 768 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure( | 762 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure( |
| 769 123, &ptr0_callback_run, base::Bind(&base::DoNothing))); | 763 123, &ptr0_callback_run, base::Bind(&base::DoNothing))); |
| 770 ptr0.FlushForTesting(); | 764 ptr0.FlushForTesting(); |
| 771 EXPECT_TRUE(ptr0_callback_run); | 765 EXPECT_TRUE(ptr0_callback_run); |
| 772 } | 766 } |
| 773 | 767 |
| 774 void SetBool(bool* value) { | 768 void SetBool(bool* value) { |
| 775 *value = true; | 769 *value = true; |
| 776 } | 770 } |
| 777 | 771 |
| 778 template <typename T> | 772 template <typename T> |
| 779 void SetBoolWithUnusedParameter(bool* value, T unused) { | 773 void SetBoolWithUnusedParameter(bool* value, T unused) { |
| 780 *value = true; | 774 *value = true; |
| 781 } | 775 } |
| 782 | 776 |
| 783 TEST_F(AssociatedInterfaceTest, AssociatedPtrFlushForTestingWithClosedPeer) { | 777 TEST_F(AssociatedInterfaceTest, AssociatedPtrFlushForTestingWithClosedPeer) { |
| 784 MessagePipe pipe; | |
| 785 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | |
| 786 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | |
| 787 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | |
| 788 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 789 | |
| 790 AssociatedInterfaceRequest<IntegerSender> request; | 778 AssociatedInterfaceRequest<IntegerSender> request; |
| 791 IntegerSenderAssociatedPtrInfo ptr_info; | 779 IntegerSenderAssociatedPtrInfo ptr_info; |
| 792 | 780 CreateIntegerSender(&ptr_info, &request); |
| 793 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | |
| 794 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | |
| 795 ptr_info = EmulatePassingAssociatedPtrInfo(std::move(ptr_info), router1); | |
| 796 | 781 |
| 797 AssociatedInterfacePtr<IntegerSender> ptr0; | 782 AssociatedInterfacePtr<IntegerSender> ptr0; |
| 798 ptr0.Bind(std::move(ptr_info)); | 783 ptr0.Bind(std::move(ptr_info)); |
| 799 bool called = false; | 784 bool called = false; |
| 800 ptr0.set_connection_error_handler(base::Bind(&SetBool, &called)); | 785 ptr0.set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 801 request = nullptr; | 786 request = nullptr; |
| 802 | 787 |
| 803 ptr0.FlushForTesting(); | 788 ptr0.FlushForTesting(); |
| 804 EXPECT_TRUE(called); | 789 EXPECT_TRUE(called); |
| 805 ptr0.FlushForTesting(); | 790 ptr0.FlushForTesting(); |
| 806 } | 791 } |
| 807 | 792 |
| 808 TEST_F(AssociatedInterfaceTest, AssociatedBindingFlushForTesting) { | 793 TEST_F(AssociatedInterfaceTest, AssociatedBindingFlushForTesting) { |
| 809 MessagePipe pipe; | |
| 810 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | |
| 811 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | |
| 812 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | |
| 813 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 814 | |
| 815 AssociatedInterfaceRequest<IntegerSender> request; | 794 AssociatedInterfaceRequest<IntegerSender> request; |
| 816 IntegerSenderAssociatedPtrInfo ptr_info; | 795 IntegerSenderAssociatedPtrInfo ptr_info; |
| 817 | 796 CreateIntegerSender(&ptr_info, &request); |
| 818 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | |
| 819 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | |
| 820 ptr_info = EmulatePassingAssociatedPtrInfo(std::move(ptr_info), router1); | |
| 821 | 797 |
| 822 IntegerSenderImpl impl0(std::move(request)); | 798 IntegerSenderImpl impl0(std::move(request)); |
| 823 impl0.set_connection_error_handler(base::Bind(&Fail)); | 799 impl0.set_connection_error_handler(base::Bind(&Fail)); |
| 824 AssociatedInterfacePtr<IntegerSender> ptr0; | 800 AssociatedInterfacePtr<IntegerSender> ptr0; |
| 825 ptr0.Bind(std::move(ptr_info)); | 801 ptr0.Bind(std::move(ptr_info)); |
| 826 | 802 |
| 827 bool ptr0_callback_run = false; | 803 bool ptr0_callback_run = false; |
| 828 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure( | 804 ptr0->Echo(123, ExpectValueSetFlagAndRunClosure( |
| 829 123, &ptr0_callback_run, base::Bind(&base::DoNothing))); | 805 123, &ptr0_callback_run, base::Bind(&base::DoNothing))); |
| 830 // Because the flush is sent from the binding, it only guarantees that the | 806 // Because the flush is sent from the binding, it only guarantees that the |
| 831 // request has been received, not the response. The second flush waits for the | 807 // request has been received, not the response. The second flush waits for the |
| 832 // response to be received. | 808 // response to be received. |
| 833 impl0.binding()->FlushForTesting(); | 809 impl0.binding()->FlushForTesting(); |
| 834 impl0.binding()->FlushForTesting(); | 810 impl0.binding()->FlushForTesting(); |
| 835 EXPECT_TRUE(ptr0_callback_run); | 811 EXPECT_TRUE(ptr0_callback_run); |
| 836 } | 812 } |
| 837 | 813 |
| 838 TEST_F(AssociatedInterfaceTest, | 814 TEST_F(AssociatedInterfaceTest, |
| 839 AssociatedBindingFlushForTestingWithClosedPeer) { | 815 AssociatedBindingFlushForTestingWithClosedPeer) { |
| 840 MessagePipe pipe; | 816 scoped_refptr<MultiplexRouter> router0; |
| 841 scoped_refptr<MultiplexRouter> router0(new MultiplexRouter( | 817 scoped_refptr<MultiplexRouter> router1; |
| 842 true, std::move(pipe.handle0), base::ThreadTaskRunnerHandle::Get())); | 818 CreateRouterPair(&router0, &router1); |
| 843 scoped_refptr<MultiplexRouter> router1(new MultiplexRouter( | |
| 844 false, std::move(pipe.handle1), base::ThreadTaskRunnerHandle::Get())); | |
| 845 | 819 |
| 846 AssociatedInterfaceRequest<IntegerSender> request; | 820 AssociatedInterfaceRequest<IntegerSender> request; |
| 847 { | 821 { |
| 848 IntegerSenderAssociatedPtrInfo ptr_info; | 822 IntegerSenderAssociatedPtrInfo ptr_info; |
| 849 | 823 CreateIntegerSenderWithExistingRouters(router1, &ptr_info, router0, |
| 850 router0->CreateAssociatedGroup()->CreateAssociatedInterface( | 824 &request); |
| 851 AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); | |
| 852 } | 825 } |
| 853 | 826 |
| 854 IntegerSenderImpl impl(std::move(request)); | 827 IntegerSenderImpl impl(std::move(request)); |
| 855 bool called = false; | 828 bool called = false; |
| 856 impl.set_connection_error_handler(base::Bind(&SetBool, &called)); | 829 impl.set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 857 impl.binding()->FlushForTesting(); | 830 impl.binding()->FlushForTesting(); |
| 858 EXPECT_TRUE(called); | 831 EXPECT_TRUE(called); |
| 859 impl.binding()->FlushForTesting(); | 832 impl.binding()->FlushForTesting(); |
| 860 } | 833 } |
| 861 | 834 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 IntegerSenderConnectionPtr ptr; | 913 IntegerSenderConnectionPtr ptr; |
| 941 GetProxy(&ptr); | 914 GetProxy(&ptr); |
| 942 bool called = false; | 915 bool called = false; |
| 943 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); | 916 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 944 EXPECT_FALSE(called); | 917 EXPECT_FALSE(called); |
| 945 ptr.FlushForTesting(); | 918 ptr.FlushForTesting(); |
| 946 EXPECT_TRUE(called); | 919 EXPECT_TRUE(called); |
| 947 ptr.FlushForTesting(); | 920 ptr.FlushForTesting(); |
| 948 } | 921 } |
| 949 | 922 |
| 923 TEST_F(AssociatedInterfaceTest, AssociatedBindingConnectionErrorWithReason) { |
| 924 AssociatedInterfaceRequest<IntegerSender> request; |
| 925 IntegerSenderAssociatedPtrInfo ptr_info; |
| 926 CreateIntegerSender(&ptr_info, &request); |
| 927 |
| 928 IntegerSenderImpl impl(std::move(request)); |
| 929 AssociatedInterfacePtr<IntegerSender> ptr; |
| 930 ptr.Bind(std::move(ptr_info)); |
| 931 |
| 932 base::RunLoop run_loop; |
| 933 impl.binding()->set_connection_error_with_reason_handler(base::Bind( |
| 934 [](const base::Closure& quit_closure, uint32_t custom_reason, |
| 935 const std::string& description) { |
| 936 EXPECT_EQ(123u, custom_reason); |
| 937 EXPECT_EQ("farewell", description); |
| 938 quit_closure.Run(); |
| 939 }, |
| 940 run_loop.QuitClosure())); |
| 941 |
| 942 ptr.ResetWithReason(123u, "farewell"); |
| 943 |
| 944 run_loop.Run(); |
| 945 } |
| 946 |
| 947 TEST_F(AssociatedInterfaceTest, AssociatedPtrConnectionErrorWithReason) { |
| 948 AssociatedInterfaceRequest<IntegerSender> request; |
| 949 IntegerSenderAssociatedPtrInfo ptr_info; |
| 950 CreateIntegerSender(&ptr_info, &request); |
| 951 |
| 952 IntegerSenderImpl impl(std::move(request)); |
| 953 AssociatedInterfacePtr<IntegerSender> ptr; |
| 954 ptr.Bind(std::move(ptr_info)); |
| 955 |
| 956 base::RunLoop run_loop; |
| 957 ptr.set_connection_error_with_reason_handler(base::Bind( |
| 958 [](const base::Closure& quit_closure, uint32_t custom_reason, |
| 959 const std::string& description) { |
| 960 EXPECT_EQ(456u, custom_reason); |
| 961 EXPECT_EQ("farewell", description); |
| 962 quit_closure.Run(); |
| 963 }, |
| 964 run_loop.QuitClosure())); |
| 965 |
| 966 impl.binding()->CloseWithReason(456u, "farewell"); |
| 967 |
| 968 run_loop.Run(); |
| 969 } |
| 970 |
| 950 } // namespace | 971 } // namespace |
| 951 } // namespace test | 972 } // namespace test |
| 952 } // namespace mojo | 973 } // namespace mojo |
| OLD | NEW |