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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 545 |
546 void CaptureSenderPtrInfo(IntegerSenderAssociatedPtr* storage, | 546 void CaptureSenderPtrInfo(IntegerSenderAssociatedPtr* storage, |
547 const base::Closure& closure, | 547 const base::Closure& closure, |
548 IntegerSenderAssociatedPtrInfo info) { | 548 IntegerSenderAssociatedPtrInfo info) { |
549 storage->Bind(std::move(info)); | 549 storage->Bind(std::move(info)); |
550 closure.Run(); | 550 closure.Run(); |
551 } | 551 } |
552 | 552 |
553 TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) { | 553 TEST_F(AssociatedInterfaceTest, PassAssociatedInterfaces) { |
554 IntegerSenderConnectionPtr connection_ptr; | 554 IntegerSenderConnectionPtr connection_ptr; |
555 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); | 555 IntegerSenderConnectionImpl connection(MakeRequest(&connection_ptr)); |
556 | 556 |
557 IntegerSenderAssociatedPtr sender0; | 557 IntegerSenderAssociatedPtr sender0; |
558 connection_ptr->GetSender( | 558 connection_ptr->GetSender( |
559 GetProxy(&sender0, connection_ptr.associated_group())); | 559 MakeRequest(&sender0, connection_ptr.associated_group())); |
560 | 560 |
561 int32_t echoed_value = 0; | 561 int32_t echoed_value = 0; |
562 base::RunLoop run_loop; | 562 base::RunLoop run_loop; |
563 sender0->Echo(123, base::Bind(&CaptureInt32, &echoed_value, | 563 sender0->Echo(123, base::Bind(&CaptureInt32, &echoed_value, |
564 run_loop.QuitClosure())); | 564 run_loop.QuitClosure())); |
565 run_loop.Run(); | 565 run_loop.Run(); |
566 EXPECT_EQ(123, echoed_value); | 566 EXPECT_EQ(123, echoed_value); |
567 | 567 |
568 IntegerSenderAssociatedPtr sender1; | 568 IntegerSenderAssociatedPtr sender1; |
569 base::RunLoop run_loop2; | 569 base::RunLoop run_loop2; |
570 connection_ptr->AsyncGetSender( | 570 connection_ptr->AsyncGetSender( |
571 base::Bind(&CaptureSenderPtrInfo, &sender1, run_loop2.QuitClosure())); | 571 base::Bind(&CaptureSenderPtrInfo, &sender1, run_loop2.QuitClosure())); |
572 run_loop2.Run(); | 572 run_loop2.Run(); |
573 EXPECT_TRUE(sender1); | 573 EXPECT_TRUE(sender1); |
574 | 574 |
575 base::RunLoop run_loop3; | 575 base::RunLoop run_loop3; |
576 sender1->Echo(456, base::Bind(&CaptureInt32, &echoed_value, | 576 sender1->Echo(456, base::Bind(&CaptureInt32, &echoed_value, |
577 run_loop3.QuitClosure())); | 577 run_loop3.QuitClosure())); |
578 run_loop3.Run(); | 578 run_loop3.Run(); |
579 EXPECT_EQ(456, echoed_value); | 579 EXPECT_EQ(456, echoed_value); |
580 } | 580 } |
581 | 581 |
582 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { | 582 TEST_F(AssociatedInterfaceTest, BindingWaitAndPauseWhenNoAssociatedInterfaces) { |
583 IntegerSenderConnectionPtr connection_ptr; | 583 IntegerSenderConnectionPtr connection_ptr; |
584 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); | 584 IntegerSenderConnectionImpl connection(MakeRequest(&connection_ptr)); |
585 | 585 |
586 IntegerSenderAssociatedPtr sender0; | 586 IntegerSenderAssociatedPtr sender0; |
587 connection_ptr->GetSender( | 587 connection_ptr->GetSender( |
588 GetProxy(&sender0, connection_ptr.associated_group())); | 588 MakeRequest(&sender0, connection_ptr.associated_group())); |
589 | 589 |
590 EXPECT_FALSE(connection.binding()->HasAssociatedInterfaces()); | 590 EXPECT_FALSE(connection.binding()->HasAssociatedInterfaces()); |
591 // There are no associated interfaces running on the pipe yet. It is okay to | 591 // There are no associated interfaces running on the pipe yet. It is okay to |
592 // pause. | 592 // pause. |
593 connection.binding()->PauseIncomingMethodCallProcessing(); | 593 connection.binding()->PauseIncomingMethodCallProcessing(); |
594 connection.binding()->ResumeIncomingMethodCallProcessing(); | 594 connection.binding()->ResumeIncomingMethodCallProcessing(); |
595 | 595 |
596 // There are no associated interfaces running on the pipe yet. It is okay to | 596 // There are no associated interfaces running on the pipe yet. It is okay to |
597 // wait. | 597 // wait. |
598 EXPECT_TRUE(connection.binding()->WaitForIncomingMethodCall()); | 598 EXPECT_TRUE(connection.binding()->WaitForIncomingMethodCall()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 683 |
684 private: | 684 private: |
685 const base::Closure callback_; | 685 const base::Closure callback_; |
686 }; | 686 }; |
687 | 687 |
688 // Verifies that filters work as expected on associated bindings, i.e. that | 688 // Verifies that filters work as expected on associated bindings, i.e. that |
689 // they're notified in order, before dispatch; and that each associated | 689 // they're notified in order, before dispatch; and that each associated |
690 // binding in a group operates with its own set of filters. | 690 // binding in a group operates with its own set of filters. |
691 TEST_F(AssociatedInterfaceTest, BindingWithFilters) { | 691 TEST_F(AssociatedInterfaceTest, BindingWithFilters) { |
692 AssociatedPingProviderPtr provider; | 692 AssociatedPingProviderPtr provider; |
693 PingProviderImpl provider_impl(GetProxy(&provider)); | 693 PingProviderImpl provider_impl(MakeRequest(&provider)); |
694 | 694 |
695 PingServiceAssociatedPtr ping_a, ping_b; | 695 PingServiceAssociatedPtr ping_a, ping_b; |
696 provider->GetPing(GetProxy(&ping_a, provider.associated_group())); | 696 provider->GetPing(MakeRequest(&ping_a, provider.associated_group())); |
697 provider->GetPing(GetProxy(&ping_b, provider.associated_group())); | 697 provider->GetPing(MakeRequest(&ping_b, provider.associated_group())); |
698 provider_impl.WaitForBindings(2); | 698 provider_impl.WaitForBindings(2); |
699 | 699 |
700 ASSERT_EQ(2u, provider_impl.ping_services().size()); | 700 ASSERT_EQ(2u, provider_impl.ping_services().size()); |
701 PingServiceImpl& ping_a_impl = *provider_impl.ping_services()[0]; | 701 PingServiceImpl& ping_a_impl = *provider_impl.ping_services()[0]; |
702 PingServiceImpl& ping_b_impl = *provider_impl.ping_services()[1]; | 702 PingServiceImpl& ping_b_impl = *provider_impl.ping_services()[1]; |
703 | 703 |
704 int a_status, b_status; | 704 int a_status, b_status; |
705 auto handler_helper = [] (int* a_status, int* b_status, int expected_a_status, | 705 auto handler_helper = [] (int* a_status, int* b_status, int expected_a_status, |
706 int new_a_status, int expected_b_status, | 706 int new_a_status, int expected_b_status, |
707 int new_b_status) { | 707 int new_b_status) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 IntegerSenderImpl impl(std::move(request)); | 831 IntegerSenderImpl impl(std::move(request)); |
832 bool called = false; | 832 bool called = false; |
833 impl.set_connection_error_handler(base::Bind(&SetBool, &called)); | 833 impl.set_connection_error_handler(base::Bind(&SetBool, &called)); |
834 impl.binding()->FlushForTesting(); | 834 impl.binding()->FlushForTesting(); |
835 EXPECT_TRUE(called); | 835 EXPECT_TRUE(called); |
836 impl.binding()->FlushForTesting(); | 836 impl.binding()->FlushForTesting(); |
837 } | 837 } |
838 | 838 |
839 TEST_F(AssociatedInterfaceTest, BindingFlushForTesting) { | 839 TEST_F(AssociatedInterfaceTest, BindingFlushForTesting) { |
840 IntegerSenderConnectionPtr ptr; | 840 IntegerSenderConnectionPtr ptr; |
841 IntegerSenderConnectionImpl impl(GetProxy(&ptr)); | 841 IntegerSenderConnectionImpl impl(MakeRequest(&ptr)); |
842 bool called = false; | 842 bool called = false; |
843 ptr->AsyncGetSender(base::Bind( | 843 ptr->AsyncGetSender(base::Bind( |
844 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); | 844 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); |
845 EXPECT_FALSE(called); | 845 EXPECT_FALSE(called); |
846 impl.binding()->set_connection_error_handler(base::Bind(&Fail)); | 846 impl.binding()->set_connection_error_handler(base::Bind(&Fail)); |
847 // Because the flush is sent from the binding, it only guarantees that the | 847 // Because the flush is sent from the binding, it only guarantees that the |
848 // request has been received, not the response. The second flush waits for the | 848 // request has been received, not the response. The second flush waits for the |
849 // response to be received. | 849 // response to be received. |
850 impl.binding()->FlushForTesting(); | 850 impl.binding()->FlushForTesting(); |
851 impl.binding()->FlushForTesting(); | 851 impl.binding()->FlushForTesting(); |
852 EXPECT_TRUE(called); | 852 EXPECT_TRUE(called); |
853 } | 853 } |
854 | 854 |
855 TEST_F(AssociatedInterfaceTest, BindingFlushForTestingWithClosedPeer) { | 855 TEST_F(AssociatedInterfaceTest, BindingFlushForTestingWithClosedPeer) { |
856 IntegerSenderConnectionPtr ptr; | 856 IntegerSenderConnectionPtr ptr; |
857 IntegerSenderConnectionImpl impl(GetProxy(&ptr)); | 857 IntegerSenderConnectionImpl impl(MakeRequest(&ptr)); |
858 bool called = false; | 858 bool called = false; |
859 impl.binding()->set_connection_error_handler(base::Bind(&SetBool, &called)); | 859 impl.binding()->set_connection_error_handler(base::Bind(&SetBool, &called)); |
860 ptr.reset(); | 860 ptr.reset(); |
861 EXPECT_FALSE(called); | 861 EXPECT_FALSE(called); |
862 impl.binding()->FlushForTesting(); | 862 impl.binding()->FlushForTesting(); |
863 EXPECT_TRUE(called); | 863 EXPECT_TRUE(called); |
864 impl.binding()->FlushForTesting(); | 864 impl.binding()->FlushForTesting(); |
865 } | 865 } |
866 | 866 |
867 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTesting) { | 867 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTesting) { |
868 IntegerSenderConnectionPtr ptr; | 868 IntegerSenderConnectionPtr ptr; |
869 auto binding = | 869 auto binding = |
870 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( | 870 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( |
871 IntegerSenderConnectionRequest{}), | 871 IntegerSenderConnectionRequest{}), |
872 GetProxy(&ptr)); | 872 MakeRequest(&ptr)); |
873 bool called = false; | 873 bool called = false; |
874 IntegerSenderAssociatedPtr sender_ptr; | 874 IntegerSenderAssociatedPtr sender_ptr; |
875 ptr->GetSender(GetProxy(&sender_ptr, ptr.associated_group())); | 875 ptr->GetSender(MakeRequest(&sender_ptr, ptr.associated_group())); |
876 sender_ptr->Echo(1, base::Bind(&SetBoolWithUnusedParameter<int>, &called)); | 876 sender_ptr->Echo(1, base::Bind(&SetBoolWithUnusedParameter<int>, &called)); |
877 EXPECT_FALSE(called); | 877 EXPECT_FALSE(called); |
878 // Because the flush is sent from the binding, it only guarantees that the | 878 // Because the flush is sent from the binding, it only guarantees that the |
879 // request has been received, not the response. The second flush waits for the | 879 // request has been received, not the response. The second flush waits for the |
880 // response to be received. | 880 // response to be received. |
881 ASSERT_TRUE(binding); | 881 ASSERT_TRUE(binding); |
882 binding->FlushForTesting(); | 882 binding->FlushForTesting(); |
883 ASSERT_TRUE(binding); | 883 ASSERT_TRUE(binding); |
884 binding->FlushForTesting(); | 884 binding->FlushForTesting(); |
885 EXPECT_TRUE(called); | 885 EXPECT_TRUE(called); |
886 } | 886 } |
887 | 887 |
888 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTestingWithClosedPeer) { | 888 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTestingWithClosedPeer) { |
889 IntegerSenderConnectionPtr ptr; | 889 IntegerSenderConnectionPtr ptr; |
890 bool called = false; | 890 bool called = false; |
891 auto binding = | 891 auto binding = |
892 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( | 892 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( |
893 IntegerSenderConnectionRequest{}), | 893 IntegerSenderConnectionRequest{}), |
894 GetProxy(&ptr)); | 894 MakeRequest(&ptr)); |
895 binding->set_connection_error_handler(base::Bind(&SetBool, &called)); | 895 binding->set_connection_error_handler(base::Bind(&SetBool, &called)); |
896 ptr.reset(); | 896 ptr.reset(); |
897 EXPECT_FALSE(called); | 897 EXPECT_FALSE(called); |
898 ASSERT_TRUE(binding); | 898 ASSERT_TRUE(binding); |
899 binding->FlushForTesting(); | 899 binding->FlushForTesting(); |
900 EXPECT_TRUE(called); | 900 EXPECT_TRUE(called); |
901 ASSERT_FALSE(binding); | 901 ASSERT_FALSE(binding); |
902 } | 902 } |
903 | 903 |
904 TEST_F(AssociatedInterfaceTest, PtrFlushForTesting) { | 904 TEST_F(AssociatedInterfaceTest, PtrFlushForTesting) { |
905 IntegerSenderConnectionPtr ptr; | 905 IntegerSenderConnectionPtr ptr; |
906 IntegerSenderConnectionImpl impl(GetProxy(&ptr)); | 906 IntegerSenderConnectionImpl impl(MakeRequest(&ptr)); |
907 bool called = false; | 907 bool called = false; |
908 ptr.set_connection_error_handler(base::Bind(&Fail)); | 908 ptr.set_connection_error_handler(base::Bind(&Fail)); |
909 ptr->AsyncGetSender(base::Bind( | 909 ptr->AsyncGetSender(base::Bind( |
910 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); | 910 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); |
911 EXPECT_FALSE(called); | 911 EXPECT_FALSE(called); |
912 ptr.FlushForTesting(); | 912 ptr.FlushForTesting(); |
913 EXPECT_TRUE(called); | 913 EXPECT_TRUE(called); |
914 } | 914 } |
915 | 915 |
916 TEST_F(AssociatedInterfaceTest, PtrFlushForTestingWithClosedPeer) { | 916 TEST_F(AssociatedInterfaceTest, PtrFlushForTestingWithClosedPeer) { |
917 IntegerSenderConnectionPtr ptr; | 917 IntegerSenderConnectionPtr ptr; |
918 GetProxy(&ptr); | 918 MakeRequest(&ptr); |
919 bool called = false; | 919 bool called = false; |
920 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); | 920 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); |
921 EXPECT_FALSE(called); | 921 EXPECT_FALSE(called); |
922 ptr.FlushForTesting(); | 922 ptr.FlushForTesting(); |
923 EXPECT_TRUE(called); | 923 EXPECT_TRUE(called); |
924 ptr.FlushForTesting(); | 924 ptr.FlushForTesting(); |
925 } | 925 } |
926 | 926 |
927 TEST_F(AssociatedInterfaceTest, AssociatedBindingConnectionErrorWithReason) { | 927 TEST_F(AssociatedInterfaceTest, AssociatedBindingConnectionErrorWithReason) { |
928 AssociatedInterfaceRequest<IntegerSender> request; | 928 AssociatedInterfaceRequest<IntegerSender> request; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 }, | 990 }, |
991 run_loop.QuitClosure())); | 991 run_loop.QuitClosure())); |
992 | 992 |
993 request.ResetWithReason(789u, "long time no see"); | 993 request.ResetWithReason(789u, "long time no see"); |
994 | 994 |
995 run_loop.Run(); | 995 run_loop.Run(); |
996 } | 996 } |
997 | 997 |
998 TEST_F(AssociatedInterfaceTest, ThreadSafeAssociatedInterfacePtr) { | 998 TEST_F(AssociatedInterfaceTest, ThreadSafeAssociatedInterfacePtr) { |
999 IntegerSenderConnectionPtr connection_ptr; | 999 IntegerSenderConnectionPtr connection_ptr; |
1000 IntegerSenderConnectionImpl connection(GetProxy(&connection_ptr)); | 1000 IntegerSenderConnectionImpl connection(MakeRequest(&connection_ptr)); |
1001 | 1001 |
1002 IntegerSenderAssociatedPtr sender; | 1002 IntegerSenderAssociatedPtr sender; |
1003 connection_ptr->GetSender( | 1003 connection_ptr->GetSender( |
1004 GetProxy(&sender, connection_ptr.associated_group())); | 1004 MakeRequest(&sender, connection_ptr.associated_group())); |
1005 | 1005 |
1006 scoped_refptr<ThreadSafeIntegerSenderAssociatedPtr> thread_safe_sender = | 1006 scoped_refptr<ThreadSafeIntegerSenderAssociatedPtr> thread_safe_sender = |
1007 ThreadSafeIntegerSenderAssociatedPtr::Create(std::move(sender)); | 1007 ThreadSafeIntegerSenderAssociatedPtr::Create(std::move(sender)); |
1008 | 1008 |
1009 { | 1009 { |
1010 // Test the thread safe pointer can be used from the interface ptr thread. | 1010 // Test the thread safe pointer can be used from the interface ptr thread. |
1011 int32_t echoed_value = 0; | 1011 int32_t echoed_value = 0; |
1012 base::RunLoop run_loop; | 1012 base::RunLoop run_loop; |
1013 (*thread_safe_sender) | 1013 (*thread_safe_sender) |
1014 ->Echo(123, base::Bind(&CaptureInt32, &echoed_value, | 1014 ->Echo(123, base::Bind(&CaptureInt32, &echoed_value, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 base::RunLoop run_loop; | 1070 base::RunLoop run_loop; |
1071 auto run_method = base::Bind( | 1071 auto run_method = base::Bind( |
1072 [](const scoped_refptr<base::TaskRunner>& main_task_runner, | 1072 [](const scoped_refptr<base::TaskRunner>& main_task_runner, |
1073 const base::Closure& quit_closure, | 1073 const base::Closure& quit_closure, |
1074 const scoped_refptr<ThreadSafeIntegerSenderAssociatedPtr>& | 1074 const scoped_refptr<ThreadSafeIntegerSenderAssociatedPtr>& |
1075 thread_safe_ptr, | 1075 thread_safe_ptr, |
1076 ForwarderTestContext* context) { | 1076 ForwarderTestContext* context) { |
1077 // We are on the background thread, create the interface ptr. | 1077 // We are on the background thread, create the interface ptr. |
1078 context->interface_impl = | 1078 context->interface_impl = |
1079 base::MakeUnique<IntegerSenderConnectionImpl>( | 1079 base::MakeUnique<IntegerSenderConnectionImpl>( |
1080 GetProxy(&(context->connection_ptr))); | 1080 MakeRequest(&(context->connection_ptr))); |
1081 IntegerSenderAssociatedPtr sender; | 1081 IntegerSenderAssociatedPtr sender; |
1082 context->connection_ptr->GetSender( | 1082 context->connection_ptr->GetSender( |
1083 GetProxy(&sender, context->connection_ptr.associated_group())); | 1083 MakeRequest(&sender, context->connection_ptr.associated_group())); |
1084 thread_safe_ptr->Bind(std::move(sender)); | 1084 thread_safe_ptr->Bind(std::move(sender)); |
1085 main_task_runner->PostTask(FROM_HERE, quit_closure); | 1085 main_task_runner->PostTask(FROM_HERE, quit_closure); |
1086 }, | 1086 }, |
1087 base::SequencedTaskRunnerHandle::Get(), run_loop.QuitClosure(), | 1087 base::SequencedTaskRunnerHandle::Get(), run_loop.QuitClosure(), |
1088 thread_safe_ptr, context); | 1088 thread_safe_ptr, context); |
1089 | 1089 |
1090 other_thread_task_runner->PostTask(FROM_HERE, run_method); | 1090 other_thread_task_runner->PostTask(FROM_HERE, run_method); |
1091 // Block until the associated pointer is bound. | 1091 // Block until the associated pointer is bound. |
1092 run_loop.Run(); | 1092 run_loop.Run(); |
1093 } | 1093 } |
(...skipping 15 matching lines...) Expand all Loading... |
1109 other_thread_task_runner->DeleteSoon(FROM_HERE, context); | 1109 other_thread_task_runner->DeleteSoon(FROM_HERE, context); |
1110 | 1110 |
1111 // Reset the pointer now so the InterfacePtr associated resources can be | 1111 // Reset the pointer now so the InterfacePtr associated resources can be |
1112 // deleted before the background thread's message loop is invalidated. | 1112 // deleted before the background thread's message loop is invalidated. |
1113 thread_safe_ptr = nullptr; | 1113 thread_safe_ptr = nullptr; |
1114 } | 1114 } |
1115 | 1115 |
1116 } // namespace | 1116 } // namespace |
1117 } // namespace test | 1117 } // namespace test |
1118 } // namespace mojo | 1118 } // namespace mojo |
OLD | NEW |