| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include <stdio.h> | 28 #include <stdio.h> |
| 29 | 29 |
| 30 #include <algorithm> | 30 #include <algorithm> |
| 31 #include <list> | 31 #include <list> |
| 32 #include <map> | 32 #include <map> |
| 33 #include <utility> | 33 #include <utility> |
| 34 #include <vector> | 34 #include <vector> |
| 35 | 35 |
| 36 #include "talk/app/webrtc/dtmfsender.h" | 36 #include "talk/app/webrtc/dtmfsender.h" |
| 37 #include "talk/app/webrtc/fakemetricsobserver.h" | 37 #include "talk/app/webrtc/fakemetricsobserver.h" |
| 38 #include "talk/app/webrtc/fakeportallocatorfactory.h" | |
| 39 #include "talk/app/webrtc/localaudiosource.h" | 38 #include "talk/app/webrtc/localaudiosource.h" |
| 40 #include "talk/app/webrtc/mediastreaminterface.h" | 39 #include "talk/app/webrtc/mediastreaminterface.h" |
| 41 #include "talk/app/webrtc/peerconnection.h" | 40 #include "talk/app/webrtc/peerconnection.h" |
| 42 #include "talk/app/webrtc/peerconnectionfactory.h" | 41 #include "talk/app/webrtc/peerconnectionfactory.h" |
| 43 #include "talk/app/webrtc/peerconnectioninterface.h" | 42 #include "talk/app/webrtc/peerconnectioninterface.h" |
| 44 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" | 43 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" |
| 45 #include "talk/app/webrtc/test/fakeconstraints.h" | 44 #include "talk/app/webrtc/test/fakeconstraints.h" |
| 46 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 45 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
| 47 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" | 46 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" |
| 48 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" | 47 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
| 49 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | 48 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
| 50 #include "talk/app/webrtc/videosourceinterface.h" | 49 #include "talk/app/webrtc/videosourceinterface.h" |
| 51 #include "talk/media/webrtc/fakewebrtcvideoengine.h" | 50 #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
| 52 #include "talk/session/media/mediasession.h" | 51 #include "talk/session/media/mediasession.h" |
| 53 #include "webrtc/base/gunit.h" | 52 #include "webrtc/base/gunit.h" |
| 54 #include "webrtc/base/physicalsocketserver.h" | 53 #include "webrtc/base/physicalsocketserver.h" |
| 55 #include "webrtc/base/scoped_ptr.h" | 54 #include "webrtc/base/scoped_ptr.h" |
| 56 #include "webrtc/base/ssladapter.h" | 55 #include "webrtc/base/ssladapter.h" |
| 57 #include "webrtc/base/sslstreamadapter.h" | 56 #include "webrtc/base/sslstreamadapter.h" |
| 58 #include "webrtc/base/thread.h" | 57 #include "webrtc/base/thread.h" |
| 59 #include "webrtc/base/virtualsocketserver.h" | 58 #include "webrtc/base/virtualsocketserver.h" |
| 60 #include "webrtc/p2p/base/constants.h" | 59 #include "webrtc/p2p/base/constants.h" |
| 61 #include "webrtc/p2p/base/sessiondescription.h" | 60 #include "webrtc/p2p/base/sessiondescription.h" |
| 61 #include "webrtc/p2p/client/fakeportallocator.h" |
| 62 | 62 |
| 63 #define MAYBE_SKIP_TEST(feature) \ | 63 #define MAYBE_SKIP_TEST(feature) \ |
| 64 if (!(feature())) { \ | 64 if (!(feature())) { \ |
| 65 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 65 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 66 return; \ | 66 return; \ |
| 67 } | 67 } |
| 68 | 68 |
| 69 using cricket::ContentInfo; | 69 using cricket::ContentInfo; |
| 70 using cricket::FakeWebRtcVideoDecoder; | 70 using cricket::FakeWebRtcVideoDecoder; |
| 71 using cricket::FakeWebRtcVideoDecoderFactory; | 71 using cricket::FakeWebRtcVideoDecoderFactory; |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 }; | 733 }; |
| 734 | 734 |
| 735 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | 735 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
| 736 | 736 |
| 737 bool Init( | 737 bool Init( |
| 738 const MediaConstraintsInterface* constraints, | 738 const MediaConstraintsInterface* constraints, |
| 739 const PeerConnectionFactory::Options* options, | 739 const PeerConnectionFactory::Options* options, |
| 740 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 740 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
| 741 EXPECT_TRUE(!peer_connection_); | 741 EXPECT_TRUE(!peer_connection_); |
| 742 EXPECT_TRUE(!peer_connection_factory_); | 742 EXPECT_TRUE(!peer_connection_factory_); |
| 743 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); | 743 rtc::scoped_ptr<cricket::PortAllocator> port_allocator( |
| 744 if (!allocator_factory_) { | 744 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 745 return false; | |
| 746 } | |
| 747 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); | 745 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
| 748 | 746 |
| 749 if (fake_audio_capture_module_ == nullptr) { | 747 if (fake_audio_capture_module_ == nullptr) { |
| 750 return false; | 748 return false; |
| 751 } | 749 } |
| 752 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); | 750 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
| 753 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); | 751 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
| 754 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | 752 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
| 755 rtc::Thread::Current(), rtc::Thread::Current(), | 753 rtc::Thread::Current(), rtc::Thread::Current(), |
| 756 fake_audio_capture_module_, fake_video_encoder_factory_, | 754 fake_audio_capture_module_, fake_video_encoder_factory_, |
| 757 fake_video_decoder_factory_); | 755 fake_video_decoder_factory_); |
| 758 if (!peer_connection_factory_) { | 756 if (!peer_connection_factory_) { |
| 759 return false; | 757 return false; |
| 760 } | 758 } |
| 761 if (options) { | 759 if (options) { |
| 762 peer_connection_factory_->SetOptions(*options); | 760 peer_connection_factory_->SetOptions(*options); |
| 763 } | 761 } |
| 764 peer_connection_ = CreatePeerConnection( | 762 peer_connection_ = CreatePeerConnection( |
| 765 allocator_factory_.get(), constraints, std::move(dtls_identity_store)); | 763 std::move(port_allocator), constraints, std::move(dtls_identity_store)); |
| 766 return peer_connection_.get() != nullptr; | 764 return peer_connection_.get() != nullptr; |
| 767 } | 765 } |
| 768 | 766 |
| 769 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 767 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
| 770 webrtc::PortAllocatorFactoryInterface* factory, | 768 rtc::scoped_ptr<cricket::PortAllocator> port_allocator, |
| 771 const MediaConstraintsInterface* constraints, | 769 const MediaConstraintsInterface* constraints, |
| 772 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 770 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
| 773 // CreatePeerConnection with IceServers. | 771 // CreatePeerConnection with RTCConfiguration. |
| 774 webrtc::PeerConnectionInterface::IceServers ice_servers; | 772 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 775 webrtc::PeerConnectionInterface::IceServer ice_server; | 773 webrtc::PeerConnectionInterface::IceServer ice_server; |
| 776 ice_server.uri = "stun:stun.l.google.com:19302"; | 774 ice_server.uri = "stun:stun.l.google.com:19302"; |
| 777 ice_servers.push_back(ice_server); | 775 config.servers.push_back(ice_server); |
| 778 | 776 |
| 779 return peer_connection_factory_->CreatePeerConnection( | 777 return peer_connection_factory_->CreatePeerConnection( |
| 780 ice_servers, constraints, factory, std::move(dtls_identity_store), | 778 config, constraints, std::move(port_allocator), |
| 781 this); | 779 std::move(dtls_identity_store), this); |
| 782 } | 780 } |
| 783 | 781 |
| 784 void HandleIncomingOffer(const std::string& msg) { | 782 void HandleIncomingOffer(const std::string& msg) { |
| 785 LOG(INFO) << id_ << "HandleIncomingOffer "; | 783 LOG(INFO) << id_ << "HandleIncomingOffer "; |
| 786 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { | 784 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { |
| 787 // If we are not sending any streams ourselves it is time to add some. | 785 // If we are not sending any streams ourselves it is time to add some. |
| 788 AddMediaStream(true, true); | 786 AddMediaStream(true, true); |
| 789 } | 787 } |
| 790 rtc::scoped_ptr<SessionDescriptionInterface> desc( | 788 rtc::scoped_ptr<SessionDescriptionInterface> desc( |
| 791 webrtc::CreateSessionDescription("offer", msg, nullptr)); | 789 webrtc::CreateSessionDescription("offer", msg, nullptr)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 RemoveLinesFromSdp(kSdpBundleAttribute, sdp); | 876 RemoveLinesFromSdp(kSdpBundleAttribute, sdp); |
| 879 } | 877 } |
| 880 if (remove_sdes_) { | 878 if (remove_sdes_) { |
| 881 const char kSdpSdesCryptoAttribute[] = "a=crypto"; | 879 const char kSdpSdesCryptoAttribute[] = "a=crypto"; |
| 882 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); | 880 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); |
| 883 } | 881 } |
| 884 } | 882 } |
| 885 | 883 |
| 886 std::string id_; | 884 std::string id_; |
| 887 | 885 |
| 888 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> allocator_factory_; | |
| 889 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 886 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 890 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> | 887 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
| 891 peer_connection_factory_; | 888 peer_connection_factory_; |
| 892 | 889 |
| 893 bool auto_add_stream_ = true; | 890 bool auto_add_stream_ = true; |
| 894 | 891 |
| 895 typedef std::pair<std::string, std::string> IceUfragPwdPair; | 892 typedef std::pair<std::string, std::string> IceUfragPwdPair; |
| 896 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; | 893 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; |
| 897 bool expect_ice_restart_ = false; | 894 bool expect_ice_restart_ = false; |
| 898 | 895 |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 | 1855 |
| 1859 bool ParseUrl(const std::string& url, | 1856 bool ParseUrl(const std::string& url, |
| 1860 const std::string& username, | 1857 const std::string& username, |
| 1861 const std::string& password) { | 1858 const std::string& password) { |
| 1862 PeerConnectionInterface::IceServers servers; | 1859 PeerConnectionInterface::IceServers servers; |
| 1863 PeerConnectionInterface::IceServer server; | 1860 PeerConnectionInterface::IceServer server; |
| 1864 server.urls.push_back(url); | 1861 server.urls.push_back(url); |
| 1865 server.username = username; | 1862 server.username = username; |
| 1866 server.password = password; | 1863 server.password = password; |
| 1867 servers.push_back(server); | 1864 servers.push_back(server); |
| 1868 return webrtc::ParseIceServers(servers, &stun_configurations_, | 1865 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_); |
| 1869 &turn_configurations_); | |
| 1870 } | 1866 } |
| 1871 | 1867 |
| 1872 protected: | 1868 protected: |
| 1873 webrtc::StunConfigurations stun_configurations_; | 1869 cricket::ServerAddresses stun_servers_; |
| 1874 webrtc::TurnConfigurations turn_configurations_; | 1870 std::vector<cricket::RelayServerConfig> turn_servers_; |
| 1875 }; | 1871 }; |
| 1876 | 1872 |
| 1877 // Make sure all STUN/TURN prefixes are parsed correctly. | 1873 // Make sure all STUN/TURN prefixes are parsed correctly. |
| 1878 TEST_F(IceServerParsingTest, ParseStunPrefixes) { | 1874 TEST_F(IceServerParsingTest, ParseStunPrefixes) { |
| 1879 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1875 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1880 EXPECT_EQ(1U, stun_configurations_.size()); | 1876 EXPECT_EQ(1U, stun_servers_.size()); |
| 1881 EXPECT_EQ(0U, turn_configurations_.size()); | 1877 EXPECT_EQ(0U, turn_servers_.size()); |
| 1882 stun_configurations_.clear(); | 1878 stun_servers_.clear(); |
| 1883 | 1879 |
| 1884 EXPECT_TRUE(ParseUrl("stuns:hostname")); | 1880 EXPECT_TRUE(ParseUrl("stuns:hostname")); |
| 1885 EXPECT_EQ(1U, stun_configurations_.size()); | 1881 EXPECT_EQ(1U, stun_servers_.size()); |
| 1886 EXPECT_EQ(0U, turn_configurations_.size()); | 1882 EXPECT_EQ(0U, turn_servers_.size()); |
| 1887 stun_configurations_.clear(); | 1883 stun_servers_.clear(); |
| 1888 | 1884 |
| 1889 EXPECT_TRUE(ParseUrl("turn:hostname")); | 1885 EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1890 EXPECT_EQ(0U, stun_configurations_.size()); | 1886 EXPECT_EQ(0U, stun_servers_.size()); |
| 1891 EXPECT_EQ(1U, turn_configurations_.size()); | 1887 EXPECT_EQ(1U, turn_servers_.size()); |
| 1892 EXPECT_FALSE(turn_configurations_[0].secure); | 1888 EXPECT_FALSE(turn_servers_[0].ports[0].secure); |
| 1893 turn_configurations_.clear(); | 1889 turn_servers_.clear(); |
| 1894 | 1890 |
| 1895 EXPECT_TRUE(ParseUrl("turns:hostname")); | 1891 EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1896 EXPECT_EQ(0U, stun_configurations_.size()); | 1892 EXPECT_EQ(0U, stun_servers_.size()); |
| 1897 EXPECT_EQ(1U, turn_configurations_.size()); | 1893 EXPECT_EQ(1U, turn_servers_.size()); |
| 1898 EXPECT_TRUE(turn_configurations_[0].secure); | 1894 EXPECT_TRUE(turn_servers_[0].ports[0].secure); |
| 1899 turn_configurations_.clear(); | 1895 turn_servers_.clear(); |
| 1900 | 1896 |
| 1901 // invalid prefixes | 1897 // invalid prefixes |
| 1902 EXPECT_FALSE(ParseUrl("stunn:hostname")); | 1898 EXPECT_FALSE(ParseUrl("stunn:hostname")); |
| 1903 EXPECT_FALSE(ParseUrl(":hostname")); | 1899 EXPECT_FALSE(ParseUrl(":hostname")); |
| 1904 EXPECT_FALSE(ParseUrl(":")); | 1900 EXPECT_FALSE(ParseUrl(":")); |
| 1905 EXPECT_FALSE(ParseUrl("")); | 1901 EXPECT_FALSE(ParseUrl("")); |
| 1906 } | 1902 } |
| 1907 | 1903 |
| 1908 TEST_F(IceServerParsingTest, VerifyDefaults) { | 1904 TEST_F(IceServerParsingTest, VerifyDefaults) { |
| 1909 // TURNS defaults | 1905 // TURNS defaults |
| 1910 EXPECT_TRUE(ParseUrl("turns:hostname")); | 1906 EXPECT_TRUE(ParseUrl("turns:hostname")); |
| 1911 EXPECT_EQ(1U, turn_configurations_.size()); | 1907 EXPECT_EQ(1U, turn_servers_.size()); |
| 1912 EXPECT_EQ(5349, turn_configurations_[0].server.port()); | 1908 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port()); |
| 1913 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | 1909 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
| 1914 turn_configurations_.clear(); | 1910 turn_servers_.clear(); |
| 1915 | 1911 |
| 1916 // TURN defaults | 1912 // TURN defaults |
| 1917 EXPECT_TRUE(ParseUrl("turn:hostname")); | 1913 EXPECT_TRUE(ParseUrl("turn:hostname")); |
| 1918 EXPECT_EQ(1U, turn_configurations_.size()); | 1914 EXPECT_EQ(1U, turn_servers_.size()); |
| 1919 EXPECT_EQ(3478, turn_configurations_[0].server.port()); | 1915 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port()); |
| 1920 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | 1916 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
| 1921 turn_configurations_.clear(); | 1917 turn_servers_.clear(); |
| 1922 | 1918 |
| 1923 // STUN defaults | 1919 // STUN defaults |
| 1924 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1920 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1925 EXPECT_EQ(1U, stun_configurations_.size()); | 1921 EXPECT_EQ(1U, stun_servers_.size()); |
| 1926 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1922 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 1927 stun_configurations_.clear(); | 1923 stun_servers_.clear(); |
| 1928 } | 1924 } |
| 1929 | 1925 |
| 1930 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port | 1926 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port |
| 1931 // can be parsed correctly. | 1927 // can be parsed correctly. |
| 1932 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { | 1928 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { |
| 1933 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); | 1929 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); |
| 1934 EXPECT_EQ(1U, stun_configurations_.size()); | 1930 EXPECT_EQ(1U, stun_servers_.size()); |
| 1935 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | 1931 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
| 1936 EXPECT_EQ(1234, stun_configurations_[0].server.port()); | 1932 EXPECT_EQ(1234, stun_servers_.begin()->port()); |
| 1937 stun_configurations_.clear(); | 1933 stun_servers_.clear(); |
| 1938 | 1934 |
| 1939 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); | 1935 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); |
| 1940 EXPECT_EQ(1U, stun_configurations_.size()); | 1936 EXPECT_EQ(1U, stun_servers_.size()); |
| 1941 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | 1937 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
| 1942 EXPECT_EQ(4321, stun_configurations_[0].server.port()); | 1938 EXPECT_EQ(4321, stun_servers_.begin()->port()); |
| 1943 stun_configurations_.clear(); | 1939 stun_servers_.clear(); |
| 1944 | 1940 |
| 1945 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); | 1941 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); |
| 1946 EXPECT_EQ(1U, stun_configurations_.size()); | 1942 EXPECT_EQ(1U, stun_servers_.size()); |
| 1947 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | 1943 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
| 1948 EXPECT_EQ(9999, stun_configurations_[0].server.port()); | 1944 EXPECT_EQ(9999, stun_servers_.begin()->port()); |
| 1949 stun_configurations_.clear(); | 1945 stun_servers_.clear(); |
| 1950 | 1946 |
| 1951 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); | 1947 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); |
| 1952 EXPECT_EQ(1U, stun_configurations_.size()); | 1948 EXPECT_EQ(1U, stun_servers_.size()); |
| 1953 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | 1949 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
| 1954 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1950 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 1955 stun_configurations_.clear(); | 1951 stun_servers_.clear(); |
| 1956 | 1952 |
| 1957 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); | 1953 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); |
| 1958 EXPECT_EQ(1U, stun_configurations_.size()); | 1954 EXPECT_EQ(1U, stun_servers_.size()); |
| 1959 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | 1955 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
| 1960 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1956 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 1961 stun_configurations_.clear(); | 1957 stun_servers_.clear(); |
| 1962 | 1958 |
| 1963 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1959 EXPECT_TRUE(ParseUrl("stun:hostname")); |
| 1964 EXPECT_EQ(1U, stun_configurations_.size()); | 1960 EXPECT_EQ(1U, stun_servers_.size()); |
| 1965 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | 1961 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
| 1966 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1962 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
| 1967 stun_configurations_.clear(); | 1963 stun_servers_.clear(); |
| 1968 | 1964 |
| 1969 // Try some invalid hostname:port strings. | 1965 // Try some invalid hostname:port strings. |
| 1970 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); | 1966 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); |
| 1971 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); | 1967 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); |
| 1968 EXPECT_FALSE(ParseUrl("stun:hostname:port:more")); |
| 1969 EXPECT_FALSE(ParseUrl("stun:hostname:port more")); |
| 1972 EXPECT_FALSE(ParseUrl("stun:hostname:")); | 1970 EXPECT_FALSE(ParseUrl("stun:hostname:")); |
| 1973 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); | 1971 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); |
| 1974 EXPECT_FALSE(ParseUrl("stun::5555")); | 1972 EXPECT_FALSE(ParseUrl("stun::5555")); |
| 1975 EXPECT_FALSE(ParseUrl("stun:")); | 1973 EXPECT_FALSE(ParseUrl("stun:")); |
| 1976 } | 1974 } |
| 1977 | 1975 |
| 1978 // Test parsing the "?transport=xxx" part of the URL. | 1976 // Test parsing the "?transport=xxx" part of the URL. |
| 1979 TEST_F(IceServerParsingTest, ParseTransport) { | 1977 TEST_F(IceServerParsingTest, ParseTransport) { |
| 1980 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); | 1978 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); |
| 1981 EXPECT_EQ(1U, turn_configurations_.size()); | 1979 EXPECT_EQ(1U, turn_servers_.size()); |
| 1982 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | 1980 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
| 1983 turn_configurations_.clear(); | 1981 turn_servers_.clear(); |
| 1984 | 1982 |
| 1985 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); | 1983 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); |
| 1986 EXPECT_EQ(1U, turn_configurations_.size()); | 1984 EXPECT_EQ(1U, turn_servers_.size()); |
| 1987 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | 1985 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
| 1988 turn_configurations_.clear(); | 1986 turn_servers_.clear(); |
| 1989 | 1987 |
| 1990 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); | 1988 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); |
| 1991 } | 1989 } |
| 1992 | 1990 |
| 1993 // Test parsing ICE username contained in URL. | 1991 // Test parsing ICE username contained in URL. |
| 1994 TEST_F(IceServerParsingTest, ParseUsername) { | 1992 TEST_F(IceServerParsingTest, ParseUsername) { |
| 1995 EXPECT_TRUE(ParseUrl("turn:user@hostname")); | 1993 EXPECT_TRUE(ParseUrl("turn:user@hostname")); |
| 1996 EXPECT_EQ(1U, turn_configurations_.size()); | 1994 EXPECT_EQ(1U, turn_servers_.size()); |
| 1997 EXPECT_EQ("user", turn_configurations_[0].username); | 1995 EXPECT_EQ("user", turn_servers_[0].credentials.username); |
| 1998 turn_configurations_.clear(); | 1996 turn_servers_.clear(); |
| 1999 | 1997 |
| 2000 EXPECT_FALSE(ParseUrl("turn:@hostname")); | 1998 EXPECT_FALSE(ParseUrl("turn:@hostname")); |
| 2001 EXPECT_FALSE(ParseUrl("turn:username@")); | 1999 EXPECT_FALSE(ParseUrl("turn:username@")); |
| 2002 EXPECT_FALSE(ParseUrl("turn:@")); | 2000 EXPECT_FALSE(ParseUrl("turn:@")); |
| 2003 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); | 2001 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); |
| 2004 } | 2002 } |
| 2005 | 2003 |
| 2006 // Test that username and password from IceServer is copied into the resulting | 2004 // Test that username and password from IceServer is copied into the resulting |
| 2007 // TurnConfiguration. | 2005 // RelayServerConfig. |
| 2008 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { | 2006 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { |
| 2009 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); | 2007 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); |
| 2010 EXPECT_EQ(1U, turn_configurations_.size()); | 2008 EXPECT_EQ(1U, turn_servers_.size()); |
| 2011 EXPECT_EQ("username", turn_configurations_[0].username); | 2009 EXPECT_EQ("username", turn_servers_[0].credentials.username); |
| 2012 EXPECT_EQ("password", turn_configurations_[0].password); | 2010 EXPECT_EQ("password", turn_servers_[0].credentials.password); |
| 2013 } | 2011 } |
| 2014 | 2012 |
| 2015 // Ensure that if a server has multiple URLs, each one is parsed. | 2013 // Ensure that if a server has multiple URLs, each one is parsed. |
| 2016 TEST_F(IceServerParsingTest, ParseMultipleUrls) { | 2014 TEST_F(IceServerParsingTest, ParseMultipleUrls) { |
| 2017 PeerConnectionInterface::IceServers servers; | 2015 PeerConnectionInterface::IceServers servers; |
| 2018 PeerConnectionInterface::IceServer server; | 2016 PeerConnectionInterface::IceServer server; |
| 2019 server.urls.push_back("stun:hostname"); | 2017 server.urls.push_back("stun:hostname"); |
| 2020 server.urls.push_back("turn:hostname"); | 2018 server.urls.push_back("turn:hostname"); |
| 2021 servers.push_back(server); | 2019 servers.push_back(server); |
| 2022 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 2020 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
| 2023 &turn_configurations_)); | 2021 EXPECT_EQ(1U, stun_servers_.size()); |
| 2024 EXPECT_EQ(1U, stun_configurations_.size()); | 2022 EXPECT_EQ(1U, turn_servers_.size()); |
| 2025 EXPECT_EQ(1U, turn_configurations_.size()); | |
| 2026 } | 2023 } |
| 2027 | 2024 |
| 2028 #endif // if !defined(THREAD_SANITIZER) | 2025 #endif // if !defined(THREAD_SANITIZER) |
| OLD | NEW |