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 16 matching lines...) Expand all Loading... |
27 | 27 |
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 <vector> | 33 #include <vector> |
34 | 34 |
35 #include "talk/app/webrtc/dtmfsender.h" | 35 #include "talk/app/webrtc/dtmfsender.h" |
36 #include "talk/app/webrtc/fakemetricsobserver.h" | 36 #include "talk/app/webrtc/fakemetricsobserver.h" |
37 #include "talk/app/webrtc/fakeportallocatorfactory.h" | |
38 #include "talk/app/webrtc/localaudiosource.h" | 37 #include "talk/app/webrtc/localaudiosource.h" |
39 #include "talk/app/webrtc/mediastreaminterface.h" | 38 #include "talk/app/webrtc/mediastreaminterface.h" |
40 #include "talk/app/webrtc/peerconnection.h" | 39 #include "talk/app/webrtc/peerconnection.h" |
41 #include "talk/app/webrtc/peerconnectionfactory.h" | 40 #include "talk/app/webrtc/peerconnectionfactory.h" |
42 #include "talk/app/webrtc/peerconnectioninterface.h" | 41 #include "talk/app/webrtc/peerconnectioninterface.h" |
43 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" | 42 #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" |
44 #include "talk/app/webrtc/test/fakeconstraints.h" | 43 #include "talk/app/webrtc/test/fakeconstraints.h" |
45 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" | 44 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
46 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" | 45 #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" |
47 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" | 46 #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
48 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" | 47 #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
49 #include "talk/app/webrtc/videosourceinterface.h" | 48 #include "talk/app/webrtc/videosourceinterface.h" |
50 #include "talk/media/webrtc/fakewebrtcvideoengine.h" | 49 #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
51 #include "talk/session/media/mediasession.h" | 50 #include "talk/session/media/mediasession.h" |
52 #include "webrtc/base/gunit.h" | 51 #include "webrtc/base/gunit.h" |
53 #include "webrtc/base/physicalsocketserver.h" | 52 #include "webrtc/base/physicalsocketserver.h" |
54 #include "webrtc/base/scoped_ptr.h" | 53 #include "webrtc/base/scoped_ptr.h" |
55 #include "webrtc/base/ssladapter.h" | 54 #include "webrtc/base/ssladapter.h" |
56 #include "webrtc/base/sslstreamadapter.h" | 55 #include "webrtc/base/sslstreamadapter.h" |
57 #include "webrtc/base/thread.h" | 56 #include "webrtc/base/thread.h" |
58 #include "webrtc/base/virtualsocketserver.h" | 57 #include "webrtc/base/virtualsocketserver.h" |
59 #include "webrtc/p2p/base/constants.h" | 58 #include "webrtc/p2p/base/constants.h" |
60 #include "webrtc/p2p/base/sessiondescription.h" | 59 #include "webrtc/p2p/base/sessiondescription.h" |
| 60 #include "webrtc/p2p/client/fakeportallocator.h" |
61 | 61 |
62 #define MAYBE_SKIP_TEST(feature) \ | 62 #define MAYBE_SKIP_TEST(feature) \ |
63 if (!(feature())) { \ | 63 if (!(feature())) { \ |
64 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 64 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
65 return; \ | 65 return; \ |
66 } | 66 } |
67 | 67 |
68 using cricket::ContentInfo; | 68 using cricket::ContentInfo; |
69 using cricket::FakeWebRtcVideoDecoder; | 69 using cricket::FakeWebRtcVideoDecoder; |
70 using cricket::FakeWebRtcVideoDecoderFactory; | 70 using cricket::FakeWebRtcVideoDecoderFactory; |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 }; | 716 }; |
717 | 717 |
718 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} | 718 explicit PeerConnectionTestClient(const std::string& id) : id_(id) {} |
719 | 719 |
720 bool Init( | 720 bool Init( |
721 const MediaConstraintsInterface* constraints, | 721 const MediaConstraintsInterface* constraints, |
722 const PeerConnectionFactory::Options* options, | 722 const PeerConnectionFactory::Options* options, |
723 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 723 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
724 EXPECT_TRUE(!peer_connection_); | 724 EXPECT_TRUE(!peer_connection_); |
725 EXPECT_TRUE(!peer_connection_factory_); | 725 EXPECT_TRUE(!peer_connection_factory_); |
726 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); | 726 rtc::scoped_ptr<cricket::PortAllocator> port_allocator( |
727 if (!allocator_factory_) { | 727 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
728 return false; | |
729 } | |
730 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); | 728 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
731 | 729 |
732 if (fake_audio_capture_module_ == nullptr) { | 730 if (fake_audio_capture_module_ == nullptr) { |
733 return false; | 731 return false; |
734 } | 732 } |
735 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); | 733 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
736 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); | 734 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
737 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( | 735 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
738 rtc::Thread::Current(), rtc::Thread::Current(), | 736 rtc::Thread::Current(), rtc::Thread::Current(), |
739 fake_audio_capture_module_, fake_video_encoder_factory_, | 737 fake_audio_capture_module_, fake_video_encoder_factory_, |
740 fake_video_decoder_factory_); | 738 fake_video_decoder_factory_); |
741 if (!peer_connection_factory_) { | 739 if (!peer_connection_factory_) { |
742 return false; | 740 return false; |
743 } | 741 } |
744 if (options) { | 742 if (options) { |
745 peer_connection_factory_->SetOptions(*options); | 743 peer_connection_factory_->SetOptions(*options); |
746 } | 744 } |
747 peer_connection_ = CreatePeerConnection( | 745 peer_connection_ = CreatePeerConnection( |
748 allocator_factory_.get(), constraints, dtls_identity_store.Pass()); | 746 std::move(port_allocator), constraints, std::move(dtls_identity_store)); |
749 return peer_connection_.get() != nullptr; | 747 return peer_connection_.get() != nullptr; |
750 } | 748 } |
751 | 749 |
752 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( | 750 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection( |
753 webrtc::PortAllocatorFactoryInterface* factory, | 751 rtc::scoped_ptr<cricket::PortAllocator> port_allocator, |
754 const MediaConstraintsInterface* constraints, | 752 const MediaConstraintsInterface* constraints, |
755 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 753 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
756 // CreatePeerConnection with IceServers. | 754 // CreatePeerConnection with RTCConfiguration. |
757 webrtc::PeerConnectionInterface::IceServers ice_servers; | 755 webrtc::PeerConnectionInterface::RTCConfiguration config; |
758 webrtc::PeerConnectionInterface::IceServer ice_server; | 756 webrtc::PeerConnectionInterface::IceServer ice_server; |
759 ice_server.uri = "stun:stun.l.google.com:19302"; | 757 ice_server.uri = "stun:stun.l.google.com:19302"; |
760 ice_servers.push_back(ice_server); | 758 config.servers.push_back(ice_server); |
761 | 759 |
762 return peer_connection_factory_->CreatePeerConnection( | 760 return peer_connection_factory_->CreatePeerConnection( |
763 ice_servers, constraints, factory, dtls_identity_store.Pass(), this); | 761 config, constraints, std::move(port_allocator), |
| 762 std::move(dtls_identity_store), this); |
764 } | 763 } |
765 | 764 |
766 void HandleIncomingOffer(const std::string& msg) { | 765 void HandleIncomingOffer(const std::string& msg) { |
767 LOG(INFO) << id_ << "HandleIncomingOffer "; | 766 LOG(INFO) << id_ << "HandleIncomingOffer "; |
768 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { | 767 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { |
769 // If we are not sending any streams ourselves it is time to add some. | 768 // If we are not sending any streams ourselves it is time to add some. |
770 AddMediaStream(true, true); | 769 AddMediaStream(true, true); |
771 } | 770 } |
772 rtc::scoped_ptr<SessionDescriptionInterface> desc( | 771 rtc::scoped_ptr<SessionDescriptionInterface> desc( |
773 webrtc::CreateSessionDescription("offer", msg, nullptr)); | 772 webrtc::CreateSessionDescription("offer", msg, nullptr)); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 RemoveLinesFromSdp(kSdpBundleAttribute, sdp); | 859 RemoveLinesFromSdp(kSdpBundleAttribute, sdp); |
861 } | 860 } |
862 if (remove_sdes_) { | 861 if (remove_sdes_) { |
863 const char kSdpSdesCryptoAttribute[] = "a=crypto"; | 862 const char kSdpSdesCryptoAttribute[] = "a=crypto"; |
864 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); | 863 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); |
865 } | 864 } |
866 } | 865 } |
867 | 866 |
868 std::string id_; | 867 std::string id_; |
869 | 868 |
870 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> allocator_factory_; | |
871 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; | 869 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
872 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> | 870 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
873 peer_connection_factory_; | 871 peer_connection_factory_; |
874 | 872 |
875 bool auto_add_stream_ = true; | 873 bool auto_add_stream_ = true; |
876 | 874 |
877 typedef std::pair<std::string, std::string> IceUfragPwdPair; | 875 typedef std::pair<std::string, std::string> IceUfragPwdPair; |
878 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; | 876 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; |
879 bool expect_ice_restart_ = false; | 877 bool expect_ice_restart_ = false; |
880 | 878 |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 | 1795 |
1798 bool ParseUrl(const std::string& url, | 1796 bool ParseUrl(const std::string& url, |
1799 const std::string& username, | 1797 const std::string& username, |
1800 const std::string& password) { | 1798 const std::string& password) { |
1801 PeerConnectionInterface::IceServers servers; | 1799 PeerConnectionInterface::IceServers servers; |
1802 PeerConnectionInterface::IceServer server; | 1800 PeerConnectionInterface::IceServer server; |
1803 server.urls.push_back(url); | 1801 server.urls.push_back(url); |
1804 server.username = username; | 1802 server.username = username; |
1805 server.password = password; | 1803 server.password = password; |
1806 servers.push_back(server); | 1804 servers.push_back(server); |
1807 return webrtc::ParseIceServers(servers, &stun_configurations_, | 1805 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_); |
1808 &turn_configurations_); | |
1809 } | 1806 } |
1810 | 1807 |
1811 protected: | 1808 protected: |
1812 webrtc::StunConfigurations stun_configurations_; | 1809 cricket::ServerAddresses stun_servers_; |
1813 webrtc::TurnConfigurations turn_configurations_; | 1810 std::vector<cricket::RelayServerConfig> turn_servers_; |
1814 }; | 1811 }; |
1815 | 1812 |
1816 // Make sure all STUN/TURN prefixes are parsed correctly. | 1813 // Make sure all STUN/TURN prefixes are parsed correctly. |
1817 TEST_F(IceServerParsingTest, ParseStunPrefixes) { | 1814 TEST_F(IceServerParsingTest, ParseStunPrefixes) { |
1818 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1815 EXPECT_TRUE(ParseUrl("stun:hostname")); |
1819 EXPECT_EQ(1U, stun_configurations_.size()); | 1816 EXPECT_EQ(1U, stun_servers_.size()); |
1820 EXPECT_EQ(0U, turn_configurations_.size()); | 1817 EXPECT_EQ(0U, turn_servers_.size()); |
1821 stun_configurations_.clear(); | 1818 stun_servers_.clear(); |
1822 | 1819 |
1823 EXPECT_TRUE(ParseUrl("stuns:hostname")); | 1820 EXPECT_TRUE(ParseUrl("stuns:hostname")); |
1824 EXPECT_EQ(1U, stun_configurations_.size()); | 1821 EXPECT_EQ(1U, stun_servers_.size()); |
1825 EXPECT_EQ(0U, turn_configurations_.size()); | 1822 EXPECT_EQ(0U, turn_servers_.size()); |
1826 stun_configurations_.clear(); | 1823 stun_servers_.clear(); |
1827 | 1824 |
1828 EXPECT_TRUE(ParseUrl("turn:hostname")); | 1825 EXPECT_TRUE(ParseUrl("turn:hostname")); |
1829 EXPECT_EQ(0U, stun_configurations_.size()); | 1826 EXPECT_EQ(0U, stun_servers_.size()); |
1830 EXPECT_EQ(1U, turn_configurations_.size()); | 1827 EXPECT_EQ(1U, turn_servers_.size()); |
1831 EXPECT_FALSE(turn_configurations_[0].secure); | 1828 EXPECT_FALSE(turn_servers_[0].ports[0].secure); |
1832 turn_configurations_.clear(); | 1829 turn_servers_.clear(); |
1833 | 1830 |
1834 EXPECT_TRUE(ParseUrl("turns:hostname")); | 1831 EXPECT_TRUE(ParseUrl("turns:hostname")); |
1835 EXPECT_EQ(0U, stun_configurations_.size()); | 1832 EXPECT_EQ(0U, stun_servers_.size()); |
1836 EXPECT_EQ(1U, turn_configurations_.size()); | 1833 EXPECT_EQ(1U, turn_servers_.size()); |
1837 EXPECT_TRUE(turn_configurations_[0].secure); | 1834 EXPECT_TRUE(turn_servers_[0].ports[0].secure); |
1838 turn_configurations_.clear(); | 1835 turn_servers_.clear(); |
1839 | 1836 |
1840 // invalid prefixes | 1837 // invalid prefixes |
1841 EXPECT_FALSE(ParseUrl("stunn:hostname")); | 1838 EXPECT_FALSE(ParseUrl("stunn:hostname")); |
1842 EXPECT_FALSE(ParseUrl(":hostname")); | 1839 EXPECT_FALSE(ParseUrl(":hostname")); |
1843 EXPECT_FALSE(ParseUrl(":")); | 1840 EXPECT_FALSE(ParseUrl(":")); |
1844 EXPECT_FALSE(ParseUrl("")); | 1841 EXPECT_FALSE(ParseUrl("")); |
1845 } | 1842 } |
1846 | 1843 |
1847 TEST_F(IceServerParsingTest, VerifyDefaults) { | 1844 TEST_F(IceServerParsingTest, VerifyDefaults) { |
1848 // TURNS defaults | 1845 // TURNS defaults |
1849 EXPECT_TRUE(ParseUrl("turns:hostname")); | 1846 EXPECT_TRUE(ParseUrl("turns:hostname")); |
1850 EXPECT_EQ(1U, turn_configurations_.size()); | 1847 EXPECT_EQ(1U, turn_servers_.size()); |
1851 EXPECT_EQ(5349, turn_configurations_[0].server.port()); | 1848 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port()); |
1852 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | 1849 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
1853 turn_configurations_.clear(); | 1850 turn_servers_.clear(); |
1854 | 1851 |
1855 // TURN defaults | 1852 // TURN defaults |
1856 EXPECT_TRUE(ParseUrl("turn:hostname")); | 1853 EXPECT_TRUE(ParseUrl("turn:hostname")); |
1857 EXPECT_EQ(1U, turn_configurations_.size()); | 1854 EXPECT_EQ(1U, turn_servers_.size()); |
1858 EXPECT_EQ(3478, turn_configurations_[0].server.port()); | 1855 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port()); |
1859 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | 1856 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
1860 turn_configurations_.clear(); | 1857 turn_servers_.clear(); |
1861 | 1858 |
1862 // STUN defaults | 1859 // STUN defaults |
1863 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1860 EXPECT_TRUE(ParseUrl("stun:hostname")); |
1864 EXPECT_EQ(1U, stun_configurations_.size()); | 1861 EXPECT_EQ(1U, stun_servers_.size()); |
1865 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1862 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
1866 stun_configurations_.clear(); | 1863 stun_servers_.clear(); |
1867 } | 1864 } |
1868 | 1865 |
1869 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port | 1866 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port |
1870 // can be parsed correctly. | 1867 // can be parsed correctly. |
1871 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { | 1868 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { |
1872 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); | 1869 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); |
1873 EXPECT_EQ(1U, stun_configurations_.size()); | 1870 EXPECT_EQ(1U, stun_servers_.size()); |
1874 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | 1871 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
1875 EXPECT_EQ(1234, stun_configurations_[0].server.port()); | 1872 EXPECT_EQ(1234, stun_servers_.begin()->port()); |
1876 stun_configurations_.clear(); | 1873 stun_servers_.clear(); |
1877 | 1874 |
1878 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); | 1875 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); |
1879 EXPECT_EQ(1U, stun_configurations_.size()); | 1876 EXPECT_EQ(1U, stun_servers_.size()); |
1880 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | 1877 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
1881 EXPECT_EQ(4321, stun_configurations_[0].server.port()); | 1878 EXPECT_EQ(4321, stun_servers_.begin()->port()); |
1882 stun_configurations_.clear(); | 1879 stun_servers_.clear(); |
1883 | 1880 |
1884 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); | 1881 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); |
1885 EXPECT_EQ(1U, stun_configurations_.size()); | 1882 EXPECT_EQ(1U, stun_servers_.size()); |
1886 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | 1883 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
1887 EXPECT_EQ(9999, stun_configurations_[0].server.port()); | 1884 EXPECT_EQ(9999, stun_servers_.begin()->port()); |
1888 stun_configurations_.clear(); | 1885 stun_servers_.clear(); |
1889 | 1886 |
1890 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); | 1887 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); |
1891 EXPECT_EQ(1U, stun_configurations_.size()); | 1888 EXPECT_EQ(1U, stun_servers_.size()); |
1892 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); | 1889 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname()); |
1893 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1890 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
1894 stun_configurations_.clear(); | 1891 stun_servers_.clear(); |
1895 | 1892 |
1896 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); | 1893 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); |
1897 EXPECT_EQ(1U, stun_configurations_.size()); | 1894 EXPECT_EQ(1U, stun_servers_.size()); |
1898 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); | 1895 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname()); |
1899 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1896 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
1900 stun_configurations_.clear(); | 1897 stun_servers_.clear(); |
1901 | 1898 |
1902 EXPECT_TRUE(ParseUrl("stun:hostname")); | 1899 EXPECT_TRUE(ParseUrl("stun:hostname")); |
1903 EXPECT_EQ(1U, stun_configurations_.size()); | 1900 EXPECT_EQ(1U, stun_servers_.size()); |
1904 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); | 1901 EXPECT_EQ("hostname", stun_servers_.begin()->hostname()); |
1905 EXPECT_EQ(3478, stun_configurations_[0].server.port()); | 1902 EXPECT_EQ(3478, stun_servers_.begin()->port()); |
1906 stun_configurations_.clear(); | 1903 stun_servers_.clear(); |
1907 | 1904 |
1908 // Try some invalid hostname:port strings. | 1905 // Try some invalid hostname:port strings. |
1909 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); | 1906 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); |
1910 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); | 1907 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); |
| 1908 EXPECT_FALSE(ParseUrl("stun:hostname:port:more")); |
| 1909 EXPECT_FALSE(ParseUrl("stun:hostname:port more")); |
1911 EXPECT_FALSE(ParseUrl("stun:hostname:")); | 1910 EXPECT_FALSE(ParseUrl("stun:hostname:")); |
1912 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); | 1911 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); |
1913 EXPECT_FALSE(ParseUrl("stun::5555")); | 1912 EXPECT_FALSE(ParseUrl("stun::5555")); |
1914 EXPECT_FALSE(ParseUrl("stun:")); | 1913 EXPECT_FALSE(ParseUrl("stun:")); |
1915 } | 1914 } |
1916 | 1915 |
1917 // Test parsing the "?transport=xxx" part of the URL. | 1916 // Test parsing the "?transport=xxx" part of the URL. |
1918 TEST_F(IceServerParsingTest, ParseTransport) { | 1917 TEST_F(IceServerParsingTest, ParseTransport) { |
1919 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); | 1918 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); |
1920 EXPECT_EQ(1U, turn_configurations_.size()); | 1919 EXPECT_EQ(1U, turn_servers_.size()); |
1921 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); | 1920 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto); |
1922 turn_configurations_.clear(); | 1921 turn_servers_.clear(); |
1923 | 1922 |
1924 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); | 1923 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); |
1925 EXPECT_EQ(1U, turn_configurations_.size()); | 1924 EXPECT_EQ(1U, turn_servers_.size()); |
1926 EXPECT_EQ("udp", turn_configurations_[0].transport_type); | 1925 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto); |
1927 turn_configurations_.clear(); | 1926 turn_servers_.clear(); |
1928 | 1927 |
1929 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); | 1928 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); |
1930 } | 1929 } |
1931 | 1930 |
1932 // Test parsing ICE username contained in URL. | 1931 // Test parsing ICE username contained in URL. |
1933 TEST_F(IceServerParsingTest, ParseUsername) { | 1932 TEST_F(IceServerParsingTest, ParseUsername) { |
1934 EXPECT_TRUE(ParseUrl("turn:user@hostname")); | 1933 EXPECT_TRUE(ParseUrl("turn:user@hostname")); |
1935 EXPECT_EQ(1U, turn_configurations_.size()); | 1934 EXPECT_EQ(1U, turn_servers_.size()); |
1936 EXPECT_EQ("user", turn_configurations_[0].username); | 1935 EXPECT_EQ("user", turn_servers_[0].credentials.username); |
1937 turn_configurations_.clear(); | 1936 turn_servers_.clear(); |
1938 | 1937 |
1939 EXPECT_FALSE(ParseUrl("turn:@hostname")); | 1938 EXPECT_FALSE(ParseUrl("turn:@hostname")); |
1940 EXPECT_FALSE(ParseUrl("turn:username@")); | 1939 EXPECT_FALSE(ParseUrl("turn:username@")); |
1941 EXPECT_FALSE(ParseUrl("turn:@")); | 1940 EXPECT_FALSE(ParseUrl("turn:@")); |
1942 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); | 1941 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); |
1943 } | 1942 } |
1944 | 1943 |
1945 // Test that username and password from IceServer is copied into the resulting | 1944 // Test that username and password from IceServer is copied into the resulting |
1946 // TurnConfiguration. | 1945 // RelayServerConfig. |
1947 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { | 1946 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { |
1948 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); | 1947 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); |
1949 EXPECT_EQ(1U, turn_configurations_.size()); | 1948 EXPECT_EQ(1U, turn_servers_.size()); |
1950 EXPECT_EQ("username", turn_configurations_[0].username); | 1949 EXPECT_EQ("username", turn_servers_[0].credentials.username); |
1951 EXPECT_EQ("password", turn_configurations_[0].password); | 1950 EXPECT_EQ("password", turn_servers_[0].credentials.password); |
1952 } | 1951 } |
1953 | 1952 |
1954 // Ensure that if a server has multiple URLs, each one is parsed. | 1953 // Ensure that if a server has multiple URLs, each one is parsed. |
1955 TEST_F(IceServerParsingTest, ParseMultipleUrls) { | 1954 TEST_F(IceServerParsingTest, ParseMultipleUrls) { |
1956 PeerConnectionInterface::IceServers servers; | 1955 PeerConnectionInterface::IceServers servers; |
1957 PeerConnectionInterface::IceServer server; | 1956 PeerConnectionInterface::IceServer server; |
1958 server.urls.push_back("stun:hostname"); | 1957 server.urls.push_back("stun:hostname"); |
1959 server.urls.push_back("turn:hostname"); | 1958 server.urls.push_back("turn:hostname"); |
1960 servers.push_back(server); | 1959 servers.push_back(server); |
1961 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, | 1960 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
1962 &turn_configurations_)); | 1961 EXPECT_EQ(1U, stun_servers_.size()); |
1963 EXPECT_EQ(1U, stun_configurations_.size()); | 1962 EXPECT_EQ(1U, turn_servers_.size()); |
1964 EXPECT_EQ(1U, turn_configurations_.size()); | |
1965 } | 1963 } |
1966 | 1964 |
1967 #endif // if !defined(THREAD_SANITIZER) | 1965 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |