| 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 impl.binding()->set_connection_error_handler(base::Bind(&SetBool, &called)); | 882 impl.binding()->set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 883 ptr.reset(); | 883 ptr.reset(); |
| 884 EXPECT_FALSE(called); | 884 EXPECT_FALSE(called); |
| 885 impl.binding()->FlushForTesting(); | 885 impl.binding()->FlushForTesting(); |
| 886 EXPECT_TRUE(called); | 886 EXPECT_TRUE(called); |
| 887 impl.binding()->FlushForTesting(); | 887 impl.binding()->FlushForTesting(); |
| 888 } | 888 } |
| 889 | 889 |
| 890 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTesting) { | 890 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTesting) { |
| 891 IntegerSenderConnectionPtr ptr; | 891 IntegerSenderConnectionPtr ptr; |
| 892 IntegerSenderConnectionImpl impl(IntegerSenderConnectionRequest{}); | 892 auto binding = |
| 893 mojo::StrongBinding<IntegerSenderConnection> binding(&impl, GetProxy(&ptr)); | 893 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( |
| 894 binding.set_connection_error_handler(base::Bind(&Fail)); | 894 IntegerSenderConnectionRequest{}), |
| 895 GetProxy(&ptr)); |
| 895 bool called = false; | 896 bool called = false; |
| 896 IntegerSenderAssociatedPtr sender_ptr; | 897 IntegerSenderAssociatedPtr sender_ptr; |
| 897 ptr->GetSender(GetProxy(&sender_ptr, ptr.associated_group())); | 898 ptr->GetSender(GetProxy(&sender_ptr, ptr.associated_group())); |
| 898 sender_ptr->Echo(1, base::Bind(&SetBoolWithUnusedParameter<int>, &called)); | 899 sender_ptr->Echo(1, base::Bind(&SetBoolWithUnusedParameter<int>, &called)); |
| 899 EXPECT_FALSE(called); | 900 EXPECT_FALSE(called); |
| 900 // Because the flush is sent from the binding, it only guarantees that the | 901 // Because the flush is sent from the binding, it only guarantees that the |
| 901 // request has been received, not the response. The second flush waits for the | 902 // request has been received, not the response. The second flush waits for the |
| 902 // response to be received. | 903 // response to be received. |
| 903 binding.FlushForTesting(); | 904 ASSERT_TRUE(binding); |
| 904 binding.FlushForTesting(); | 905 binding->FlushForTesting(); |
| 906 ASSERT_TRUE(binding); |
| 907 binding->FlushForTesting(); |
| 905 EXPECT_TRUE(called); | 908 EXPECT_TRUE(called); |
| 906 } | 909 } |
| 907 | 910 |
| 908 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTestingWithClosedPeer) { | 911 TEST_F(AssociatedInterfaceTest, StrongBindingFlushForTestingWithClosedPeer) { |
| 909 IntegerSenderConnectionPtr ptr; | 912 IntegerSenderConnectionPtr ptr; |
| 910 mojo::StrongBinding<IntegerSenderConnection> binding( | |
| 911 new IntegerSenderConnectionImpl(IntegerSenderConnectionRequest{}), | |
| 912 GetProxy(&ptr)); | |
| 913 bool called = false; | 913 bool called = false; |
| 914 binding.set_connection_error_handler(base::Bind(&SetBool, &called)); | 914 auto binding = |
| 915 MakeStrongBinding(base::MakeUnique<IntegerSenderConnectionImpl>( |
| 916 IntegerSenderConnectionRequest{}), |
| 917 GetProxy(&ptr)); |
| 918 binding->set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 915 ptr.reset(); | 919 ptr.reset(); |
| 916 EXPECT_FALSE(called); | 920 EXPECT_FALSE(called); |
| 917 binding.FlushForTesting(); | 921 ASSERT_TRUE(binding); |
| 922 binding->FlushForTesting(); |
| 918 EXPECT_TRUE(called); | 923 EXPECT_TRUE(called); |
| 919 binding.FlushForTesting(); | 924 ASSERT_FALSE(binding); |
| 920 } | 925 } |
| 921 | 926 |
| 922 TEST_F(AssociatedInterfaceTest, PtrFlushForTesting) { | 927 TEST_F(AssociatedInterfaceTest, PtrFlushForTesting) { |
| 923 IntegerSenderConnectionPtr ptr; | 928 IntegerSenderConnectionPtr ptr; |
| 924 IntegerSenderConnectionImpl impl(GetProxy(&ptr)); | 929 IntegerSenderConnectionImpl impl(GetProxy(&ptr)); |
| 925 bool called = false; | 930 bool called = false; |
| 926 ptr.set_connection_error_handler(base::Bind(&Fail)); | 931 ptr.set_connection_error_handler(base::Bind(&Fail)); |
| 927 ptr->AsyncGetSender(base::Bind( | 932 ptr->AsyncGetSender(base::Bind( |
| 928 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); | 933 &SetBoolWithUnusedParameter<IntegerSenderAssociatedPtrInfo>, &called)); |
| 929 EXPECT_FALSE(called); | 934 EXPECT_FALSE(called); |
| 930 ptr.FlushForTesting(); | 935 ptr.FlushForTesting(); |
| 931 EXPECT_TRUE(called); | 936 EXPECT_TRUE(called); |
| 932 } | 937 } |
| 933 | 938 |
| 934 TEST_F(AssociatedInterfaceTest, PtrFlushForTestingWithClosedPeer) { | 939 TEST_F(AssociatedInterfaceTest, PtrFlushForTestingWithClosedPeer) { |
| 935 IntegerSenderConnectionPtr ptr; | 940 IntegerSenderConnectionPtr ptr; |
| 936 GetProxy(&ptr); | 941 GetProxy(&ptr); |
| 937 bool called = false; | 942 bool called = false; |
| 938 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); | 943 ptr.set_connection_error_handler(base::Bind(&SetBool, &called)); |
| 939 EXPECT_FALSE(called); | 944 EXPECT_FALSE(called); |
| 940 ptr.FlushForTesting(); | 945 ptr.FlushForTesting(); |
| 941 EXPECT_TRUE(called); | 946 EXPECT_TRUE(called); |
| 942 ptr.FlushForTesting(); | 947 ptr.FlushForTesting(); |
| 943 } | 948 } |
| 944 | 949 |
| 945 } // namespace | 950 } // namespace |
| 946 } // namespace test | 951 } // namespace test |
| 947 } // namespace mojo | 952 } // namespace mojo |
| OLD | NEW |