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

Side by Side Diff: talk/app/webrtc/peerconnection_unittest.cc

Issue 1520963002: Removing webrtc::PortAllocatorFactoryInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing patch conflicts Created 5 years 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 * 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
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
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
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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 1826
1830 bool ParseUrl(const std::string& url, 1827 bool ParseUrl(const std::string& url,
1831 const std::string& username, 1828 const std::string& username,
1832 const std::string& password) { 1829 const std::string& password) {
1833 PeerConnectionInterface::IceServers servers; 1830 PeerConnectionInterface::IceServers servers;
1834 PeerConnectionInterface::IceServer server; 1831 PeerConnectionInterface::IceServer server;
1835 server.urls.push_back(url); 1832 server.urls.push_back(url);
1836 server.username = username; 1833 server.username = username;
1837 server.password = password; 1834 server.password = password;
1838 servers.push_back(server); 1835 servers.push_back(server);
1839 return webrtc::ParseIceServers(servers, &stun_configurations_, 1836 return webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_);
1840 &turn_configurations_);
1841 } 1837 }
1842 1838
1843 protected: 1839 protected:
1844 webrtc::StunConfigurations stun_configurations_; 1840 cricket::ServerAddresses stun_servers_;
1845 webrtc::TurnConfigurations turn_configurations_; 1841 std::vector<cricket::RelayServerConfig> turn_servers_;
1846 }; 1842 };
1847 1843
1848 // Make sure all STUN/TURN prefixes are parsed correctly. 1844 // Make sure all STUN/TURN prefixes are parsed correctly.
1849 TEST_F(IceServerParsingTest, ParseStunPrefixes) { 1845 TEST_F(IceServerParsingTest, ParseStunPrefixes) {
1850 EXPECT_TRUE(ParseUrl("stun:hostname")); 1846 EXPECT_TRUE(ParseUrl("stun:hostname"));
1851 EXPECT_EQ(1U, stun_configurations_.size()); 1847 EXPECT_EQ(1U, stun_servers_.size());
1852 EXPECT_EQ(0U, turn_configurations_.size()); 1848 EXPECT_EQ(0U, turn_servers_.size());
1853 stun_configurations_.clear(); 1849 stun_servers_.clear();
1854 1850
1855 EXPECT_TRUE(ParseUrl("stuns:hostname")); 1851 EXPECT_TRUE(ParseUrl("stuns:hostname"));
1856 EXPECT_EQ(1U, stun_configurations_.size()); 1852 EXPECT_EQ(1U, stun_servers_.size());
1857 EXPECT_EQ(0U, turn_configurations_.size()); 1853 EXPECT_EQ(0U, turn_servers_.size());
1858 stun_configurations_.clear(); 1854 stun_servers_.clear();
1859 1855
1860 EXPECT_TRUE(ParseUrl("turn:hostname")); 1856 EXPECT_TRUE(ParseUrl("turn:hostname"));
1861 EXPECT_EQ(0U, stun_configurations_.size()); 1857 EXPECT_EQ(0U, stun_servers_.size());
1862 EXPECT_EQ(1U, turn_configurations_.size()); 1858 EXPECT_EQ(1U, turn_servers_.size());
1863 EXPECT_FALSE(turn_configurations_[0].secure); 1859 EXPECT_FALSE(turn_servers_[0].ports[0].secure);
1864 turn_configurations_.clear(); 1860 turn_servers_.clear();
1865 1861
1866 EXPECT_TRUE(ParseUrl("turns:hostname")); 1862 EXPECT_TRUE(ParseUrl("turns:hostname"));
1867 EXPECT_EQ(0U, stun_configurations_.size()); 1863 EXPECT_EQ(0U, stun_servers_.size());
1868 EXPECT_EQ(1U, turn_configurations_.size()); 1864 EXPECT_EQ(1U, turn_servers_.size());
1869 EXPECT_TRUE(turn_configurations_[0].secure); 1865 EXPECT_TRUE(turn_servers_[0].ports[0].secure);
1870 turn_configurations_.clear(); 1866 turn_servers_.clear();
1871 1867
1872 // invalid prefixes 1868 // invalid prefixes
1873 EXPECT_FALSE(ParseUrl("stunn:hostname")); 1869 EXPECT_FALSE(ParseUrl("stunn:hostname"));
1874 EXPECT_FALSE(ParseUrl(":hostname")); 1870 EXPECT_FALSE(ParseUrl(":hostname"));
1875 EXPECT_FALSE(ParseUrl(":")); 1871 EXPECT_FALSE(ParseUrl(":"));
1876 EXPECT_FALSE(ParseUrl("")); 1872 EXPECT_FALSE(ParseUrl(""));
1877 } 1873 }
1878 1874
1879 TEST_F(IceServerParsingTest, VerifyDefaults) { 1875 TEST_F(IceServerParsingTest, VerifyDefaults) {
1880 // TURNS defaults 1876 // TURNS defaults
1881 EXPECT_TRUE(ParseUrl("turns:hostname")); 1877 EXPECT_TRUE(ParseUrl("turns:hostname"));
1882 EXPECT_EQ(1U, turn_configurations_.size()); 1878 EXPECT_EQ(1U, turn_servers_.size());
1883 EXPECT_EQ(5349, turn_configurations_[0].server.port()); 1879 EXPECT_EQ(5349, turn_servers_[0].ports[0].address.port());
1884 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); 1880 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
1885 turn_configurations_.clear(); 1881 turn_servers_.clear();
1886 1882
1887 // TURN defaults 1883 // TURN defaults
1888 EXPECT_TRUE(ParseUrl("turn:hostname")); 1884 EXPECT_TRUE(ParseUrl("turn:hostname"));
1889 EXPECT_EQ(1U, turn_configurations_.size()); 1885 EXPECT_EQ(1U, turn_servers_.size());
1890 EXPECT_EQ(3478, turn_configurations_[0].server.port()); 1886 EXPECT_EQ(3478, turn_servers_[0].ports[0].address.port());
1891 EXPECT_EQ("udp", turn_configurations_[0].transport_type); 1887 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
1892 turn_configurations_.clear(); 1888 turn_servers_.clear();
1893 1889
1894 // STUN defaults 1890 // STUN defaults
1895 EXPECT_TRUE(ParseUrl("stun:hostname")); 1891 EXPECT_TRUE(ParseUrl("stun:hostname"));
1896 EXPECT_EQ(1U, stun_configurations_.size()); 1892 EXPECT_EQ(1U, stun_servers_.size());
1897 EXPECT_EQ(3478, stun_configurations_[0].server.port()); 1893 EXPECT_EQ(3478, stun_servers_.begin()->port());
1898 stun_configurations_.clear(); 1894 stun_servers_.clear();
1899 } 1895 }
1900 1896
1901 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port 1897 // Check that the 6 combinations of IPv4/IPv6/hostname and with/without port
1902 // can be parsed correctly. 1898 // can be parsed correctly.
1903 TEST_F(IceServerParsingTest, ParseHostnameAndPort) { 1899 TEST_F(IceServerParsingTest, ParseHostnameAndPort) {
1904 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234")); 1900 EXPECT_TRUE(ParseUrl("stun:1.2.3.4:1234"));
1905 EXPECT_EQ(1U, stun_configurations_.size()); 1901 EXPECT_EQ(1U, stun_servers_.size());
1906 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); 1902 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
1907 EXPECT_EQ(1234, stun_configurations_[0].server.port()); 1903 EXPECT_EQ(1234, stun_servers_.begin()->port());
1908 stun_configurations_.clear(); 1904 stun_servers_.clear();
1909 1905
1910 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321")); 1906 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]:4321"));
1911 EXPECT_EQ(1U, stun_configurations_.size()); 1907 EXPECT_EQ(1U, stun_servers_.size());
1912 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); 1908 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
1913 EXPECT_EQ(4321, stun_configurations_[0].server.port()); 1909 EXPECT_EQ(4321, stun_servers_.begin()->port());
1914 stun_configurations_.clear(); 1910 stun_servers_.clear();
1915 1911
1916 EXPECT_TRUE(ParseUrl("stun:hostname:9999")); 1912 EXPECT_TRUE(ParseUrl("stun:hostname:9999"));
1917 EXPECT_EQ(1U, stun_configurations_.size()); 1913 EXPECT_EQ(1U, stun_servers_.size());
1918 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); 1914 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
1919 EXPECT_EQ(9999, stun_configurations_[0].server.port()); 1915 EXPECT_EQ(9999, stun_servers_.begin()->port());
1920 stun_configurations_.clear(); 1916 stun_servers_.clear();
1921 1917
1922 EXPECT_TRUE(ParseUrl("stun:1.2.3.4")); 1918 EXPECT_TRUE(ParseUrl("stun:1.2.3.4"));
1923 EXPECT_EQ(1U, stun_configurations_.size()); 1919 EXPECT_EQ(1U, stun_servers_.size());
1924 EXPECT_EQ("1.2.3.4", stun_configurations_[0].server.hostname()); 1920 EXPECT_EQ("1.2.3.4", stun_servers_.begin()->hostname());
1925 EXPECT_EQ(3478, stun_configurations_[0].server.port()); 1921 EXPECT_EQ(3478, stun_servers_.begin()->port());
1926 stun_configurations_.clear(); 1922 stun_servers_.clear();
1927 1923
1928 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]")); 1924 EXPECT_TRUE(ParseUrl("stun:[1:2:3:4:5:6:7:8]"));
1929 EXPECT_EQ(1U, stun_configurations_.size()); 1925 EXPECT_EQ(1U, stun_servers_.size());
1930 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_configurations_[0].server.hostname()); 1926 EXPECT_EQ("1:2:3:4:5:6:7:8", stun_servers_.begin()->hostname());
1931 EXPECT_EQ(3478, stun_configurations_[0].server.port()); 1927 EXPECT_EQ(3478, stun_servers_.begin()->port());
1932 stun_configurations_.clear(); 1928 stun_servers_.clear();
1933 1929
1934 EXPECT_TRUE(ParseUrl("stun:hostname")); 1930 EXPECT_TRUE(ParseUrl("stun:hostname"));
1935 EXPECT_EQ(1U, stun_configurations_.size()); 1931 EXPECT_EQ(1U, stun_servers_.size());
1936 EXPECT_EQ("hostname", stun_configurations_[0].server.hostname()); 1932 EXPECT_EQ("hostname", stun_servers_.begin()->hostname());
1937 EXPECT_EQ(3478, stun_configurations_[0].server.port()); 1933 EXPECT_EQ(3478, stun_servers_.begin()->port());
1938 stun_configurations_.clear(); 1934 stun_servers_.clear();
1939 1935
1940 // Try some invalid hostname:port strings. 1936 // Try some invalid hostname:port strings.
1941 EXPECT_FALSE(ParseUrl("stun:hostname:99a99")); 1937 EXPECT_FALSE(ParseUrl("stun:hostname:99a99"));
1942 EXPECT_FALSE(ParseUrl("stun:hostname:-1")); 1938 EXPECT_FALSE(ParseUrl("stun:hostname:-1"));
1939 EXPECT_FALSE(ParseUrl("stun:hostname:port:more"));
1940 EXPECT_FALSE(ParseUrl("stun:hostname:port more"));
1943 EXPECT_FALSE(ParseUrl("stun:hostname:")); 1941 EXPECT_FALSE(ParseUrl("stun:hostname:"));
1944 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000")); 1942 EXPECT_FALSE(ParseUrl("stun:[1:2:3:4:5:6:7:8]junk:1000"));
1945 EXPECT_FALSE(ParseUrl("stun::5555")); 1943 EXPECT_FALSE(ParseUrl("stun::5555"));
1946 EXPECT_FALSE(ParseUrl("stun:")); 1944 EXPECT_FALSE(ParseUrl("stun:"));
1947 } 1945 }
1948 1946
1949 // Test parsing the "?transport=xxx" part of the URL. 1947 // Test parsing the "?transport=xxx" part of the URL.
1950 TEST_F(IceServerParsingTest, ParseTransport) { 1948 TEST_F(IceServerParsingTest, ParseTransport) {
1951 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp")); 1949 EXPECT_TRUE(ParseUrl("turn:hostname:1234?transport=tcp"));
1952 EXPECT_EQ(1U, turn_configurations_.size()); 1950 EXPECT_EQ(1U, turn_servers_.size());
1953 EXPECT_EQ("tcp", turn_configurations_[0].transport_type); 1951 EXPECT_EQ(cricket::PROTO_TCP, turn_servers_[0].ports[0].proto);
1954 turn_configurations_.clear(); 1952 turn_servers_.clear();
1955 1953
1956 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp")); 1954 EXPECT_TRUE(ParseUrl("turn:hostname?transport=udp"));
1957 EXPECT_EQ(1U, turn_configurations_.size()); 1955 EXPECT_EQ(1U, turn_servers_.size());
1958 EXPECT_EQ("udp", turn_configurations_[0].transport_type); 1956 EXPECT_EQ(cricket::PROTO_UDP, turn_servers_[0].ports[0].proto);
1959 turn_configurations_.clear(); 1957 turn_servers_.clear();
1960 1958
1961 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid")); 1959 EXPECT_FALSE(ParseUrl("turn:hostname?transport=invalid"));
1962 } 1960 }
1963 1961
1964 // Test parsing ICE username contained in URL. 1962 // Test parsing ICE username contained in URL.
1965 TEST_F(IceServerParsingTest, ParseUsername) { 1963 TEST_F(IceServerParsingTest, ParseUsername) {
1966 EXPECT_TRUE(ParseUrl("turn:user@hostname")); 1964 EXPECT_TRUE(ParseUrl("turn:user@hostname"));
1967 EXPECT_EQ(1U, turn_configurations_.size()); 1965 EXPECT_EQ(1U, turn_servers_.size());
1968 EXPECT_EQ("user", turn_configurations_[0].username); 1966 EXPECT_EQ("user", turn_servers_[0].credentials.username);
1969 turn_configurations_.clear(); 1967 turn_servers_.clear();
1970 1968
1971 EXPECT_FALSE(ParseUrl("turn:@hostname")); 1969 EXPECT_FALSE(ParseUrl("turn:@hostname"));
1972 EXPECT_FALSE(ParseUrl("turn:username@")); 1970 EXPECT_FALSE(ParseUrl("turn:username@"));
1973 EXPECT_FALSE(ParseUrl("turn:@")); 1971 EXPECT_FALSE(ParseUrl("turn:@"));
1974 EXPECT_FALSE(ParseUrl("turn:user@name@hostname")); 1972 EXPECT_FALSE(ParseUrl("turn:user@name@hostname"));
1975 } 1973 }
1976 1974
1977 // Test that username and password from IceServer is copied into the resulting 1975 // Test that username and password from IceServer is copied into the resulting
1978 // TurnConfiguration. 1976 // RelayServerConfig.
1979 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) { 1977 TEST_F(IceServerParsingTest, CopyUsernameAndPasswordFromIceServer) {
1980 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password")); 1978 EXPECT_TRUE(ParseUrl("turn:hostname", "username", "password"));
1981 EXPECT_EQ(1U, turn_configurations_.size()); 1979 EXPECT_EQ(1U, turn_servers_.size());
1982 EXPECT_EQ("username", turn_configurations_[0].username); 1980 EXPECT_EQ("username", turn_servers_[0].credentials.username);
1983 EXPECT_EQ("password", turn_configurations_[0].password); 1981 EXPECT_EQ("password", turn_servers_[0].credentials.password);
1984 } 1982 }
1985 1983
1986 // Ensure that if a server has multiple URLs, each one is parsed. 1984 // Ensure that if a server has multiple URLs, each one is parsed.
1987 TEST_F(IceServerParsingTest, ParseMultipleUrls) { 1985 TEST_F(IceServerParsingTest, ParseMultipleUrls) {
1988 PeerConnectionInterface::IceServers servers; 1986 PeerConnectionInterface::IceServers servers;
1989 PeerConnectionInterface::IceServer server; 1987 PeerConnectionInterface::IceServer server;
1990 server.urls.push_back("stun:hostname"); 1988 server.urls.push_back("stun:hostname");
1991 server.urls.push_back("turn:hostname"); 1989 server.urls.push_back("turn:hostname");
1992 servers.push_back(server); 1990 servers.push_back(server);
1993 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, 1991 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
1994 &turn_configurations_)); 1992 EXPECT_EQ(1U, stun_servers_.size());
1995 EXPECT_EQ(1U, stun_configurations_.size()); 1993 EXPECT_EQ(1U, turn_servers_.size());
1996 EXPECT_EQ(1U, turn_configurations_.size());
1997 } 1994 }
1998 1995
1999 #endif // if !defined(THREAD_SANITIZER) 1996 #endif // if !defined(THREAD_SANITIZER)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698