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

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1308753003: Revert "Reland "Remove GICE (gone forever!) and PORTALLOCATOR_ENABLE_SHARED_UFRAG (enabled forever)… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 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 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 uint32 total_ports, 246 uint32 total_ports,
247 const rtc::IPAddress& host_candidate_addr, 247 const rtc::IPAddress& host_candidate_addr,
248 const rtc::IPAddress& stun_candidate_addr, 248 const rtc::IPAddress& stun_candidate_addr,
249 const rtc::IPAddress& relay_candidate_udp_transport_addr, 249 const rtc::IPAddress& relay_candidate_udp_transport_addr,
250 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { 250 const rtc::IPAddress& relay_candidate_tcp_transport_addr) {
251 if (!session_) { 251 if (!session_) {
252 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 252 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
253 } 253 }
254 session_->set_flags(session_->flags() | 254 session_->set_flags(session_->flags() |
255 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | 255 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
256 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
256 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 257 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
257 allocator().set_allow_tcp_listen(false); 258 allocator().set_allow_tcp_listen(false);
258 session_->StartGettingPorts(); 259 session_->StartGettingPorts();
259 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 260 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
260 261
261 uint32 total_candidates = 0; 262 uint32 total_candidates = 0;
262 if (!host_candidate_addr.IsNil()) { 263 if (!host_candidate_addr.IsNil()) {
263 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 264 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
264 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 265 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
265 rtc::SocketAddress(host_candidate_addr, 0)); 266 rtc::SocketAddress(host_candidate_addr, 0));
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 for (size_t i = 0; i < candidates_.size(); ++i) { 770 for (size_t i = 0; i < candidates_.size(); ++i) {
770 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); 771 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type());
771 EXPECT_EQ( 772 EXPECT_EQ(
772 candidates_[0].related_address(), 773 candidates_[0].related_address(),
773 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 774 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
774 } 775 }
775 } 776 }
776 777
777 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { 778 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) {
778 AddInterface(kClientAddr); 779 AddInterface(kClientAddr);
779 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 780 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
781 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
780 allocator().set_candidate_filter(cricket::CF_HOST); 782 allocator().set_candidate_filter(cricket::CF_HOST);
781 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 783 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
782 session_->StartGettingPorts(); 784 session_->StartGettingPorts();
783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 785 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
784 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. 786 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
785 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. 787 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
786 for (size_t i = 0; i < candidates_.size(); ++i) { 788 for (size_t i = 0; i < candidates_.size(); ++i) {
787 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); 789 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type());
788 } 790 }
789 } 791 }
790 792
791 // Host is behind the NAT. 793 // Host is behind the NAT.
792 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { 794 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
793 AddInterface(kPrivateAddr); 795 AddInterface(kPrivateAddr);
794 ResetWithStunServerAndNat(kStunAddr); 796 ResetWithStunServerAndNat(kStunAddr);
795 797
796 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 798 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
799 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
797 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); 800 allocator().set_candidate_filter(cricket::CF_REFLEXIVE);
798 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 801 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
799 session_->StartGettingPorts(); 802 session_->StartGettingPorts();
800 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 803 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
801 // Host is behind NAT, no private address will be exposed. Hence only UDP 804 // Host is behind NAT, no private address will be exposed. Hence only UDP
802 // port with STUN candidate will be sent outside. 805 // port with STUN candidate will be sent outside.
803 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. 806 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
804 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. 807 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state.
805 for (size_t i = 0; i < candidates_.size(); ++i) { 808 for (size_t i = 0; i < candidates_.size(); ++i) {
806 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); 809 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type());
807 EXPECT_EQ( 810 EXPECT_EQ(
808 candidates_[0].related_address(), 811 candidates_[0].related_address(),
809 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 812 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
810 } 813 }
811 } 814 }
812 815
813 // Host is not behind the NAT. 816 // Host is not behind the NAT.
814 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { 817 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) {
815 AddInterface(kClientAddr); 818 AddInterface(kClientAddr);
816 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 819 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
820 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
817 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); 821 allocator().set_candidate_filter(cricket::CF_REFLEXIVE);
818 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 822 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
819 session_->StartGettingPorts(); 823 session_->StartGettingPorts();
820 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 824 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
821 // Host has a public address, both UDP and TCP candidates will be exposed. 825 // Host has a public address, both UDP and TCP candidates will be exposed.
822 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. 826 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate.
823 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. 827 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state.
824 for (size_t i = 0; i < candidates_.size(); ++i) { 828 for (size_t i = 0; i < candidates_.size(); ++i) {
825 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); 829 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type());
826 } 830 }
827 } 831 }
828 832
829 // Test that we get the same ufrag and pwd for all candidates. 833 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG is enabled we got same
834 // ufrag and pwd for the collected candidates.
830 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { 835 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) {
836 allocator().set_flags(allocator().flags() |
837 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
831 AddInterface(kClientAddr); 838 AddInterface(kClientAddr);
832 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 839 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
833 session_->StartGettingPorts(); 840 session_->StartGettingPorts();
834 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 841 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
835 EXPECT_PRED5(CheckCandidate, candidates_[0], 842 EXPECT_PRED5(CheckCandidate, candidates_[0],
836 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 843 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
837 EXPECT_PRED5(CheckCandidate, candidates_[1], 844 EXPECT_PRED5(CheckCandidate, candidates_[1],
838 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); 845 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr);
839 EXPECT_PRED5(CheckCandidate, candidates_[5], 846 EXPECT_PRED5(CheckCandidate, candidates_[5],
840 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); 847 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr);
841 EXPECT_EQ(4U, ports_.size()); 848 EXPECT_EQ(4U, ports_.size());
842 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); 849 EXPECT_EQ(kIceUfrag0, candidates_[0].username());
843 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); 850 EXPECT_EQ(kIceUfrag0, candidates_[1].username());
844 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); 851 EXPECT_EQ(kIceUfrag0, candidates_[2].username());
845 EXPECT_EQ(kIcePwd0, candidates_[0].password()); 852 EXPECT_EQ(kIcePwd0, candidates_[0].password());
846 EXPECT_EQ(kIcePwd0, candidates_[1].password()); 853 EXPECT_EQ(kIcePwd0, candidates_[1].password());
847 EXPECT_TRUE(candidate_allocation_done_); 854 EXPECT_TRUE(candidate_allocation_done_);
848 } 855 }
849 856
857 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG isn't enabled we got
858 // different ufrag and pwd for the collected candidates.
859 TEST_F(PortAllocatorTest, TestDisableSharedUfrag) {
860 allocator().set_flags(allocator().flags() &
861 ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
862 AddInterface(kClientAddr);
863 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
864 session_->StartGettingPorts();
865 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
866 EXPECT_PRED5(CheckCandidate, candidates_[0],
867 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
868 EXPECT_PRED5(CheckCandidate, candidates_[1],
869 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr);
870 EXPECT_EQ(4U, ports_.size());
871 // Port should generate random ufrag and pwd.
872 EXPECT_NE(kIceUfrag0, candidates_[0].username());
873 EXPECT_NE(kIceUfrag0, candidates_[1].username());
874 EXPECT_NE(candidates_[0].username(), candidates_[1].username());
875 EXPECT_NE(kIcePwd0, candidates_[0].password());
876 EXPECT_NE(kIcePwd0, candidates_[1].password());
877 EXPECT_NE(candidates_[0].password(), candidates_[1].password());
878 EXPECT_TRUE(candidate_allocation_done_);
879 }
880
850 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 881 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
851 // is allocated for udp and stun. Also verify there is only one candidate 882 // is allocated for udp and stun. Also verify there is only one candidate
852 // (local) if stun candidate is same as local candidate, which will be the case 883 // (local) if stun candidate is same as local candidate, which will be the case
853 // in a public network like the below test. 884 // in a public network like the below test.
854 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { 885 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) {
855 AddInterface(kClientAddr); 886 AddInterface(kClientAddr);
856 allocator_->set_flags(allocator().flags() | 887 allocator_->set_flags(allocator().flags() |
888 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
857 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 889 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
858 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 890 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
859 session_->StartGettingPorts(); 891 session_->StartGettingPorts();
860 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); 892 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout);
861 EXPECT_EQ(3U, ports_.size()); 893 EXPECT_EQ(3U, ports_.size());
862 EXPECT_PRED5(CheckCandidate, candidates_[0], 894 EXPECT_PRED5(CheckCandidate, candidates_[0],
863 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 895 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
864 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 896 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
865 } 897 }
866 898
867 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 899 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
868 // is allocated for udp and stun. In this test we should expect both stun and 900 // is allocated for udp and stun. In this test we should expect both stun and
869 // local candidates as client behind a nat. 901 // local candidates as client behind a nat.
870 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { 902 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) {
871 AddInterface(kClientAddr); 903 AddInterface(kClientAddr);
872 ResetWithStunServerAndNat(kStunAddr); 904 ResetWithStunServerAndNat(kStunAddr);
873 905
874 allocator_->set_flags(allocator().flags() | 906 allocator_->set_flags(allocator().flags() |
907 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
875 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 908 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
876 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 909 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
877 session_->StartGettingPorts(); 910 session_->StartGettingPorts();
878 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 911 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
879 ASSERT_EQ(2U, ports_.size()); 912 ASSERT_EQ(2U, ports_.size());
880 EXPECT_PRED5(CheckCandidate, candidates_[0], 913 EXPECT_PRED5(CheckCandidate, candidates_[0],
881 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 914 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
882 EXPECT_PRED5(CheckCandidate, candidates_[1], 915 EXPECT_PRED5(CheckCandidate, candidates_[1],
883 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 916 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
884 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 917 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
885 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 918 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
886 EXPECT_EQ(3U, candidates_.size()); 919 EXPECT_EQ(3U, candidates_.size());
887 } 920 }
888 921
889 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. 922 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
890 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 923 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
891 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 924 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
892 AddInterface(kClientAddr); 925 AddInterface(kClientAddr);
893 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 926 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
894 927
895 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 928 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
896 929
897 allocator_->set_step_delay(cricket::kMinimumStepDelay); 930 allocator_->set_step_delay(cricket::kMinimumStepDelay);
898 allocator_->set_flags(allocator().flags() | 931 allocator_->set_flags(allocator().flags() |
932 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
899 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 933 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
900 cricket::PORTALLOCATOR_DISABLE_TCP); 934 cricket::PORTALLOCATOR_DISABLE_TCP);
901 935
902 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 936 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
903 session_->StartGettingPorts(); 937 session_->StartGettingPorts();
904 938
905 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 939 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
906 ASSERT_EQ(3U, ports_.size()); 940 ASSERT_EQ(3U, ports_.size());
907 EXPECT_PRED5(CheckCandidate, candidates_[0], 941 EXPECT_PRED5(CheckCandidate, candidates_[0],
908 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 942 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
(...skipping 17 matching lines...) Expand all
926 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 960 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
927 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); 961 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
928 relay_server.credentials = credentials; 962 relay_server.credentials = credentials;
929 relay_server.ports.push_back(cricket::ProtocolAddress( 963 relay_server.ports.push_back(cricket::ProtocolAddress(
930 rtc::SocketAddress("localhost", 3478), 964 rtc::SocketAddress("localhost", 3478),
931 cricket::PROTO_UDP, false)); 965 cricket::PROTO_UDP, false));
932 allocator_->AddRelay(relay_server); 966 allocator_->AddRelay(relay_server);
933 967
934 allocator_->set_step_delay(cricket::kMinimumStepDelay); 968 allocator_->set_step_delay(cricket::kMinimumStepDelay);
935 allocator_->set_flags(allocator().flags() | 969 allocator_->set_flags(allocator().flags() |
970 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
936 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 971 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
937 cricket::PORTALLOCATOR_DISABLE_TCP); 972 cricket::PORTALLOCATOR_DISABLE_TCP);
938 973
939 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 974 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
940 session_->StartGettingPorts(); 975 session_->StartGettingPorts();
941 976
942 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); 977 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout);
943 } 978 }
944 979
945 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 980 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
946 // is allocated for udp/stun/turn. In this test we should expect all local, 981 // is allocated for udp/stun/turn. In this test we should expect all local,
947 // stun and turn candidates. 982 // stun and turn candidates.
948 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { 983 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) {
949 AddInterface(kClientAddr); 984 AddInterface(kClientAddr);
950 ResetWithStunServerAndNat(kStunAddr); 985 ResetWithStunServerAndNat(kStunAddr);
951 986
952 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 987 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
953 988
954 allocator_->set_flags(allocator().flags() | 989 allocator_->set_flags(allocator().flags() |
990 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
955 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 991 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
956 cricket::PORTALLOCATOR_DISABLE_TCP); 992 cricket::PORTALLOCATOR_DISABLE_TCP);
957 993
958 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 994 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
959 session_->StartGettingPorts(); 995 session_->StartGettingPorts();
960 996
961 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 997 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
962 ASSERT_EQ(2U, ports_.size()); 998 ASSERT_EQ(2U, ports_.size());
963 EXPECT_PRED5(CheckCandidate, candidates_[0], 999 EXPECT_PRED5(CheckCandidate, candidates_[0],
964 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 1000 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
(...skipping 18 matching lines...) Expand all
983 // Use an empty SocketAddress to add a NAT without STUN server. 1019 // Use an empty SocketAddress to add a NAT without STUN server.
984 ResetWithStunServerAndNat(SocketAddress()); 1020 ResetWithStunServerAndNat(SocketAddress());
985 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1021 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
986 1022
987 // Must set the step delay to 0 to make sure the relay allocation phase is 1023 // Must set the step delay to 0 to make sure the relay allocation phase is
988 // started before the STUN candidates are obtained, so that the STUN binding 1024 // started before the STUN candidates are obtained, so that the STUN binding
989 // response is processed when both StunPort and TurnPort exist to reproduce 1025 // response is processed when both StunPort and TurnPort exist to reproduce
990 // webrtc issue 3537. 1026 // webrtc issue 3537.
991 allocator_->set_step_delay(0); 1027 allocator_->set_step_delay(0);
992 allocator_->set_flags(allocator().flags() | 1028 allocator_->set_flags(allocator().flags() |
1029 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
993 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1030 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
994 cricket::PORTALLOCATOR_DISABLE_TCP); 1031 cricket::PORTALLOCATOR_DISABLE_TCP);
995 1032
996 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1033 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
997 session_->StartGettingPorts(); 1034 session_->StartGettingPorts();
998 1035
999 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1036 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1000 EXPECT_PRED5(CheckCandidate, candidates_[0], 1037 EXPECT_PRED5(CheckCandidate, candidates_[0],
1001 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 1038 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1002 EXPECT_PRED5(CheckCandidate, candidates_[1], 1039 EXPECT_PRED5(CheckCandidate, candidates_[1],
(...skipping 14 matching lines...) Expand all
1017 // Test that when only a TCP TURN server is available, we do NOT use it as 1054 // Test that when only a TCP TURN server is available, we do NOT use it as
1018 // a UDP STUN server, as this could leak our IP address. Thus we should only 1055 // a UDP STUN server, as this could leak our IP address. Thus we should only
1019 // expect two ports, a UDPPort and TurnPort. 1056 // expect two ports, a UDPPort and TurnPort.
1020 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 1057 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
1021 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 1058 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
1022 AddInterface(kClientAddr); 1059 AddInterface(kClientAddr);
1023 ResetWithStunServerAndNat(rtc::SocketAddress()); 1060 ResetWithStunServerAndNat(rtc::SocketAddress());
1024 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 1061 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
1025 1062
1026 allocator_->set_flags(allocator().flags() | 1063 allocator_->set_flags(allocator().flags() |
1064 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1027 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1065 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1028 cricket::PORTALLOCATOR_DISABLE_TCP); 1066 cricket::PORTALLOCATOR_DISABLE_TCP);
1029 1067
1030 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1068 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1031 session_->StartGettingPorts(); 1069 session_->StartGettingPorts();
1032 1070
1033 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 1071 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
1034 ASSERT_EQ(2U, ports_.size()); 1072 ASSERT_EQ(2U, ports_.size());
1035 EXPECT_PRED5(CheckCandidate, candidates_[0], 1073 EXPECT_PRED5(CheckCandidate, candidates_[0],
1036 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 1074 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
(...skipping 12 matching lines...) Expand all
1049 // 'relay' candidates. 1087 // 'relay' candidates.
1050 // TODO(deadbeef): Remove this test when support for non-shared socket mode 1088 // TODO(deadbeef): Remove this test when support for non-shared socket mode
1051 // is removed. 1089 // is removed.
1052 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 1090 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
1053 AddInterface(kClientAddr); 1091 AddInterface(kClientAddr);
1054 // Use an empty SocketAddress to add a NAT without STUN server. 1092 // Use an empty SocketAddress to add a NAT without STUN server.
1055 ResetWithStunServerAndNat(SocketAddress()); 1093 ResetWithStunServerAndNat(SocketAddress());
1056 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1094 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1057 1095
1058 allocator_->set_flags(allocator().flags() | 1096 allocator_->set_flags(allocator().flags() |
1097 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1059 cricket::PORTALLOCATOR_DISABLE_TCP); 1098 cricket::PORTALLOCATOR_DISABLE_TCP);
1060 1099
1061 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1100 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1062 session_->StartGettingPorts(); 1101 session_->StartGettingPorts();
1063 1102
1064 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1103 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1065 ASSERT_EQ(3U, ports_.size()); 1104 ASSERT_EQ(3U, ports_.size());
1066 EXPECT_PRED5(CheckCandidate, candidates_[0], 1105 EXPECT_PRED5(CheckCandidate, candidates_[0],
1067 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 1106 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
1068 kClientAddr); 1107 kClientAddr);
(...skipping 18 matching lines...) Expand all
1087 // server is used as a STUN server and we get a 'stun' candidate. 1126 // server is used as a STUN server and we get a 'stun' candidate.
1088 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 1127 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
1089 AddInterface(kClientAddr); 1128 AddInterface(kClientAddr);
1090 // Configure with STUN server but destroy it, so we can ensure that it's 1129 // Configure with STUN server but destroy it, so we can ensure that it's
1091 // the TURN server actually being used as a STUN server. 1130 // the TURN server actually being used as a STUN server.
1092 ResetWithStunServerAndNat(kStunAddr); 1131 ResetWithStunServerAndNat(kStunAddr);
1093 stun_server_.reset(); 1132 stun_server_.reset();
1094 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1133 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1095 1134
1096 allocator_->set_flags(allocator().flags() | 1135 allocator_->set_flags(allocator().flags() |
1136 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1097 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1137 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1098 cricket::PORTALLOCATOR_DISABLE_TCP); 1138 cricket::PORTALLOCATOR_DISABLE_TCP);
1099 1139
1100 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1140 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1101 session_->StartGettingPorts(); 1141 session_->StartGettingPorts();
1102 1142
1103 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1143 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1104 EXPECT_PRED5(CheckCandidate, candidates_[0], 1144 EXPECT_PRED5(CheckCandidate, candidates_[0],
1105 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 1145 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
1106 kClientAddr); 1146 kClientAddr);
1107 EXPECT_PRED5(CheckCandidate, candidates_[1], 1147 EXPECT_PRED5(CheckCandidate, candidates_[1],
1108 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 1148 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
1109 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1149 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1110 EXPECT_PRED5(CheckCandidate, candidates_[2], 1150 EXPECT_PRED5(CheckCandidate, candidates_[2],
1111 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 1151 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
1112 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1152 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1113 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 1153 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
1114 1154
1115 // Don't bother waiting for STUN timeout, since we already verified 1155 // Don't bother waiting for STUN timeout, since we already verified
1116 // that we got a STUN candidate from the TURN server. 1156 // that we got a STUN candidate from the TURN server.
1117 } 1157 }
1118 1158
1119 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1159 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
1120 // and fail to generate STUN candidate, local UDP candidate is generated 1160 // and fail to generate STUN candidate, local UDP candidate is generated
1121 // properly. 1161 // properly.
1122 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1162 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) {
1123 allocator().set_flags(allocator().flags() | 1163 allocator().set_flags(allocator().flags() |
1124 cricket::PORTALLOCATOR_DISABLE_RELAY | 1164 cricket::PORTALLOCATOR_DISABLE_RELAY |
1125 cricket::PORTALLOCATOR_DISABLE_TCP | 1165 cricket::PORTALLOCATOR_DISABLE_TCP |
1166 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1126 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1167 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1127 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1168 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1128 AddInterface(kClientAddr); 1169 AddInterface(kClientAddr);
1129 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1170 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1130 session_->StartGettingPorts(); 1171 session_->StartGettingPorts();
1131 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1172 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1132 EXPECT_EQ(1U, candidates_.size()); 1173 EXPECT_EQ(1U, candidates_.size());
1133 EXPECT_PRED5(CheckCandidate, candidates_[0], 1174 EXPECT_PRED5(CheckCandidate, candidates_[0],
1134 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 1175 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1135 // STUN timeout is 9sec. We need to wait to get candidate done signal. 1176 // STUN timeout is 9sec. We need to wait to get candidate done signal.
1136 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); 1177 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000);
1137 EXPECT_EQ(1U, candidates_.size()); 1178 EXPECT_EQ(1U, candidates_.size());
1138 } 1179 }
1139 1180
1140 // Test that when the NetworkManager doesn't have permission to enumerate 1181 // Test that when the NetworkManager doesn't have permission to enumerate
1141 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified 1182 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified
1142 // automatically. 1183 // automatically.
1143 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) { 1184 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) {
1144 AddInterface(kClientAddr); 1185 AddInterface(kClientAddr);
1145 network_manager_.set_enumeration_permission( 1186 network_manager_.set_enumeration_permission(
1146 rtc::NetworkManager::kEnumerationDisallowed); 1187 rtc::NetworkManager::kEnumerationDisallowed);
1147 allocator().set_flags(allocator().flags() | 1188 allocator().set_flags(allocator().flags() |
1148 cricket::PORTALLOCATOR_DISABLE_RELAY | 1189 cricket::PORTALLOCATOR_DISABLE_RELAY |
1149 cricket::PORTALLOCATOR_DISABLE_TCP | 1190 cricket::PORTALLOCATOR_DISABLE_TCP |
1191 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1150 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1192 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1151 EXPECT_EQ( 1193 EXPECT_EQ(
1152 allocator_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION, 1194 allocator_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION,
1153 0U); 1195 0U);
1154 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1196 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1155 EXPECT_EQ( 1197 EXPECT_EQ(
1156 session_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION, 1198 session_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION,
1157 0U); 1199 0U);
1158 session_->StartGettingPorts(); 1200 session_->StartGettingPorts();
1159 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1201 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1160 EXPECT_EQ(0U, candidates_.size()); 1202 EXPECT_EQ(0U, candidates_.size());
1161 EXPECT_TRUE((session_->flags() & 1203 EXPECT_TRUE((session_->flags() &
1162 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0); 1204 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0);
1163 } 1205 }
1164 1206
1165 // This test verifies allocator can use IPv6 addresses along with IPv4. 1207 // This test verifies allocator can use IPv6 addresses along with IPv4.
1166 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { 1208 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) {
1167 allocator().set_flags(allocator().flags() | 1209 allocator().set_flags(allocator().flags() |
1168 cricket::PORTALLOCATOR_DISABLE_RELAY | 1210 cricket::PORTALLOCATOR_DISABLE_RELAY |
1169 cricket::PORTALLOCATOR_ENABLE_IPV6 | 1211 cricket::PORTALLOCATOR_ENABLE_IPV6 |
1212 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1170 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1213 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1171 AddInterface(kClientIPv6Addr); 1214 AddInterface(kClientIPv6Addr);
1172 AddInterface(kClientAddr); 1215 AddInterface(kClientAddr);
1173 allocator_->set_step_delay(cricket::kMinimumStepDelay); 1216 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1174 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1217 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1175 session_->StartGettingPorts(); 1218 session_->StartGettingPorts();
1176 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); 1219 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout);
1177 EXPECT_EQ(4U, candidates_.size()); 1220 EXPECT_EQ(4U, candidates_.size());
1178 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1221 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1179 EXPECT_PRED5(CheckCandidate, candidates_[0], 1222 EXPECT_PRED5(CheckCandidate, candidates_[0],
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 alloc.SetStunHosts(stun_servers); 1261 alloc.SetStunHosts(stun_servers);
1219 EXPECT_EQ(2U, alloc.relay_hosts().size()); 1262 EXPECT_EQ(2U, alloc.relay_hosts().size());
1220 EXPECT_EQ(2U, alloc.stun_hosts().size()); 1263 EXPECT_EQ(2U, alloc.stun_hosts().size());
1221 } 1264 }
1222 1265
1223 // Test that the HttpPortAllocator uses correct URL to create sessions. 1266 // Test that the HttpPortAllocator uses correct URL to create sessions.
1224 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) { 1267 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) {
1225 rtc::FakeNetworkManager network_manager; 1268 rtc::FakeNetworkManager network_manager;
1226 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent"); 1269 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent");
1227 1270
1271 // Disable PORTALLOCATOR_ENABLE_SHARED_UFRAG.
1272 alloc.set_flags(alloc.flags() & ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
1228 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session( 1273 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session(
1229 static_cast<cricket::HttpPortAllocatorSession*>( 1274 static_cast<cricket::HttpPortAllocatorSession*>(
1230 alloc.CreateSessionInternal( 1275 alloc.CreateSessionInternal(
1231 "test content", 0, kIceUfrag0, kIcePwd0))); 1276 "test content", 0, kIceUfrag0, kIcePwd0)));
1232 std::string url = session->GetSessionRequestUrl(); 1277 std::string url = session->GetSessionRequestUrl();
1233 LOG(LS_INFO) << "url: " << url; 1278 LOG(LS_INFO) << "url: " << url;
1279 EXPECT_EQ(std::string(cricket::HttpPortAllocator::kCreateSessionURL), url);
1280
1281 // Enable PORTALLOCATOR_ENABLE_SHARED_UFRAG.
1282 alloc.set_flags(alloc.flags() | cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
1283 session.reset(static_cast<cricket::HttpPortAllocatorSession*>(
1284 alloc.CreateSessionInternal("test content", 0, kIceUfrag0, kIcePwd0)));
1285 url = session->GetSessionRequestUrl();
1286 LOG(LS_INFO) << "url: " << url;
1234 std::vector<std::string> parts; 1287 std::vector<std::string> parts;
1235 rtc::split(url, '?', &parts); 1288 rtc::split(url, '?', &parts);
1236 ASSERT_EQ(2U, parts.size()); 1289 ASSERT_EQ(2U, parts.size());
1237 1290
1238 std::vector<std::string> args_parts; 1291 std::vector<std::string> args_parts;
1239 rtc::split(parts[1], '&', &args_parts); 1292 rtc::split(parts[1], '&', &args_parts);
1240 1293
1241 std::map<std::string, std::string> args; 1294 std::map<std::string, std::string> args;
1242 for (std::vector<std::string>::iterator it = args_parts.begin(); 1295 for (std::vector<std::string>::iterator it = args_parts.begin();
1243 it != args_parts.end(); ++it) { 1296 it != args_parts.end(); ++it) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 AllocationSequenceForTest alloc_sequence( 1342 AllocationSequenceForTest alloc_sequence(
1290 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), 1343 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()),
1291 &network1, &config, flag); 1344 &network1, &config, flag);
1292 // This simply tests it will not crash if udp_socket_ in the 1345 // This simply tests it will not crash if udp_socket_ in the
1293 // AllocationSequence is null, which is chosen in the constructor. 1346 // AllocationSequence is null, which is chosen in the constructor.
1294 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1347 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1295 relay_server.ports.push_back( 1348 relay_server.ports.push_back(
1296 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 1349 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1297 alloc_sequence.CreateTurnPort(relay_server); 1350 alloc_sequence.CreateTurnPort(relay_server);
1298 } 1351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698