Index: talk/app/webrtc/peerconnectionfactory_unittest.cc |
diff --git a/talk/app/webrtc/peerconnectionfactory_unittest.cc b/talk/app/webrtc/peerconnectionfactory_unittest.cc |
index f1d5353abd008a72b650a416cdf303ce3339dbce..c73ce97ad5dce1b683b98a9ff3eba1fbab5b9bf7 100644 |
--- a/talk/app/webrtc/peerconnectionfactory_unittest.cc |
+++ b/talk/app/webrtc/peerconnectionfactory_unittest.cc |
@@ -27,7 +27,6 @@ |
#include <string> |
-#include "talk/app/webrtc/fakeportallocatorfactory.h" |
#include "talk/app/webrtc/mediastreaminterface.h" |
#include "talk/app/webrtc/peerconnectionfactory.h" |
#include "talk/app/webrtc/test/fakedtlsidentitystore.h" |
@@ -39,6 +38,7 @@ |
#include "webrtc/base/gunit.h" |
#include "webrtc/base/scoped_ptr.h" |
#include "webrtc/base/thread.h" |
+#include "webrtc/p2p/client/fakeportallocator.h" |
using webrtc::DataChannelInterface; |
using webrtc::DtlsIdentityStoreInterface; |
@@ -47,17 +47,11 @@ using webrtc::MediaStreamInterface; |
using webrtc::PeerConnectionFactoryInterface; |
using webrtc::PeerConnectionInterface; |
using webrtc::PeerConnectionObserver; |
-using webrtc::PortAllocatorFactoryInterface; |
using webrtc::VideoSourceInterface; |
using webrtc::VideoTrackInterface; |
namespace { |
-typedef std::vector<PortAllocatorFactoryInterface::StunConfiguration> |
- StunConfigurations; |
-typedef std::vector<PortAllocatorFactoryInterface::TurnConfiguration> |
- TurnConfigurations; |
- |
static const char kStunIceServer[] = "stun:stun.l.google.com:19302"; |
static const char kTurnIceServer[] = "turn:test%40hello.com@test.com:1234"; |
static const char kTurnIceServerWithTransport[] = |
@@ -110,41 +104,39 @@ class PeerConnectionFactoryTest : public testing::Test { |
NULL); |
ASSERT_TRUE(factory_.get() != NULL); |
- allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); |
+ port_allocator_.reset( |
+ new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
+ raw_port_allocator_ = port_allocator_.get(); |
pthatcher1
2015/12/15 07:58:44
Why not just have a getter of port_allocator() tha
Taylor Brandstetter
2015/12/15 21:31:54
I tried this route, but at the point where I was w
|
} |
protected: |
- void VerifyStunConfigurations(StunConfigurations stun_config) { |
- webrtc::FakePortAllocatorFactory* allocator = |
- static_cast<webrtc::FakePortAllocatorFactory*>( |
- allocator_factory_.get()); |
- ASSERT_TRUE(allocator != NULL); |
- EXPECT_EQ(stun_config.size(), allocator->stun_configs().size()); |
- for (size_t i = 0; i < stun_config.size(); ++i) { |
- EXPECT_EQ(stun_config[i].server.ToString(), |
- allocator->stun_configs()[i].server.ToString()); |
- } |
+ void VerifyStunServers(cricket::ServerAddresses stun_servers) { |
+ EXPECT_EQ(stun_servers, raw_port_allocator_->stun_servers()); |
} |
- void VerifyTurnConfigurations(TurnConfigurations turn_config) { |
- webrtc::FakePortAllocatorFactory* allocator = |
- static_cast<webrtc::FakePortAllocatorFactory*>( |
- allocator_factory_.get()); |
- ASSERT_TRUE(allocator != NULL); |
- EXPECT_EQ(turn_config.size(), allocator->turn_configs().size()); |
- for (size_t i = 0; i < turn_config.size(); ++i) { |
- EXPECT_EQ(turn_config[i].server.ToString(), |
- allocator->turn_configs()[i].server.ToString()); |
- EXPECT_EQ(turn_config[i].username, allocator->turn_configs()[i].username); |
- EXPECT_EQ(turn_config[i].password, allocator->turn_configs()[i].password); |
- EXPECT_EQ(turn_config[i].transport_type, |
- allocator->turn_configs()[i].transport_type); |
+ void VerifyTurnServers(std::vector<cricket::RelayServerConfig> turn_servers) { |
+ EXPECT_EQ(turn_servers.size(), raw_port_allocator_->turn_servers().size()); |
+ for (size_t i = 0; i < turn_servers.size(); ++i) { |
+ ASSERT_EQ(1u, turn_servers[i].ports.size()); |
+ EXPECT_EQ(1u, raw_port_allocator_->turn_servers()[i].ports.size()); |
+ EXPECT_EQ( |
+ turn_servers[i].ports[0].address.ToString(), |
+ raw_port_allocator_->turn_servers()[i].ports[0].address.ToString()); |
+ EXPECT_EQ(turn_servers[i].ports[0].proto, |
+ raw_port_allocator_->turn_servers()[i].ports[0].proto); |
+ EXPECT_EQ(turn_servers[i].credentials.username, |
+ raw_port_allocator_->turn_servers()[i].credentials.username); |
+ EXPECT_EQ(turn_servers[i].credentials.password, |
+ raw_port_allocator_->turn_servers()[i].credentials.password); |
} |
} |
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_; |
NullPeerConnectionObserver observer_; |
- rtc::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_; |
+ rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator_; |
+ // Since the PC owns the port allocator after it's been initialized, |
+ // this should only be used when known to be safe. |
+ cricket::FakePortAllocator* raw_port_allocator_; |
}; |
// Verify creation of PeerConnection using internal ADM, video factory and |
@@ -154,13 +146,12 @@ TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) { |
webrtc::CreatePeerConnectionFactory()); |
NullPeerConnectionObserver observer; |
- webrtc::PeerConnectionInterface::IceServers servers; |
+ webrtc::PeerConnectionInterface::RTCConfiguration config; |
rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory->CreatePeerConnection( |
- servers, nullptr, nullptr, dtls_identity_store.Pass(), &observer)); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory->CreatePeerConnection( |
+ config, nullptr, nullptr, std::move(dtls_identity_store), &observer)); |
EXPECT_TRUE(pc.get() != nullptr); |
} |
@@ -180,25 +171,22 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- StunConfigurations stun_configs; |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
- "stun.l.google.com", 19302); |
- stun_configs.push_back(stun1); |
- VerifyStunConfigurations(stun_configs); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
- "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
- turn_configs.push_back(turn1); |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
- "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
- turn_configs.push_back(turn2); |
- VerifyTurnConfigurations(turn_configs); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ cricket::ServerAddresses stun_servers; |
+ rtc::SocketAddress stun1("stun.l.google.com", 19302); |
+ stun_servers.insert(stun1); |
+ VerifyStunServers(stun_servers); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
+ kTurnPassword, cricket::PROTO_UDP, false); |
+ turn_servers.push_back(turn1); |
+ cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
+ kTurnPassword, cricket::PROTO_TCP, false); |
+ turn_servers.push_back(turn2); |
+ VerifyTurnServers(turn_servers); |
} |
// This test verifies creation of PeerConnection with valid STUN and TURN |
@@ -213,63 +201,22 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- StunConfigurations stun_configs; |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
- "stun.l.google.com", 19302); |
- stun_configs.push_back(stun1); |
- VerifyStunConfigurations(stun_configs); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
- "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
- turn_configs.push_back(turn1); |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
- "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
- turn_configs.push_back(turn2); |
- VerifyTurnConfigurations(turn_configs); |
-} |
- |
-// This test verifies creation of PeerConnection with valid STUN and TURN |
-// configuration. Also verifies the URL's parsed correctly as expected. |
-// This version doesn't use RTCConfiguration. |
-// TODO(mallinath) - Remove this method after clients start using RTCConfig. |
-TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersOldSignature) { |
- webrtc::PeerConnectionInterface::IceServers ice_servers; |
- webrtc::PeerConnectionInterface::IceServer ice_server; |
- ice_server.uri = kStunIceServer; |
- ice_servers.push_back(ice_server); |
- ice_server.uri = kTurnIceServer; |
- ice_server.password = kTurnPassword; |
- ice_servers.push_back(ice_server); |
- ice_server.uri = kTurnIceServerWithTransport; |
- ice_server.password = kTurnPassword; |
- ice_servers.push_back(ice_server); |
- rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
- new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(ice_servers, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- StunConfigurations stun_configs; |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
- "stun.l.google.com", 19302); |
- stun_configs.push_back(stun1); |
- VerifyStunConfigurations(stun_configs); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
- "test.com", 1234, "test@hello.com", kTurnPassword, "udp", false); |
- turn_configs.push_back(turn1); |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
- "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
- turn_configs.push_back(turn2); |
- VerifyTurnConfigurations(turn_configs); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ cricket::ServerAddresses stun_servers; |
+ rtc::SocketAddress stun1("stun.l.google.com", 19302); |
+ stun_servers.insert(stun1); |
+ VerifyStunServers(stun_servers); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn1("test.com", 1234, "test@hello.com", |
+ kTurnPassword, cricket::PROTO_UDP, false); |
+ turn_servers.push_back(turn1); |
+ cricket::RelayServerConfig turn2("hello.com", kDefaultStunPort, "test", |
+ kTurnPassword, cricket::PROTO_TCP, false); |
+ turn_servers.push_back(turn2); |
+ VerifyTurnServers(turn_servers); |
} |
TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
@@ -283,17 +230,15 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
- "test.com", 1234, kTurnUsername, kTurnPassword, "udp", false); |
- turn_configs.push_back(turn); |
- VerifyTurnConfigurations(turn_configs); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn("test.com", 1234, kTurnUsername, |
+ kTurnPassword, cricket::PROTO_UDP, false); |
+ turn_servers.push_back(turn); |
+ VerifyTurnServers(turn_servers); |
} |
// This test verifies the PeerConnection created properly with TURN url which |
@@ -306,17 +251,15 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn( |
- "hello.com", kDefaultStunPort, "test", kTurnPassword, "tcp", false); |
- turn_configs.push_back(turn); |
- VerifyTurnConfigurations(turn_configs); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn("hello.com", kDefaultStunPort, "test", |
+ kTurnPassword, cricket::PROTO_TCP, false); |
+ turn_servers.push_back(turn); |
+ VerifyTurnServers(turn_servers); |
} |
TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
@@ -333,25 +276,23 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
- "hello.com", kDefaultStunTlsPort, "test", kTurnPassword, "tcp", true); |
- turn_configs.push_back(turn1); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn1("hello.com", kDefaultStunTlsPort, "test", |
+ kTurnPassword, cricket::PROTO_TCP, true); |
+ turn_servers.push_back(turn1); |
// TURNS with transport param should be default to tcp. |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn2( |
- "hello.com", 443, "test_no_transport", kTurnPassword, "tcp", true); |
- turn_configs.push_back(turn2); |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn3( |
- "hello.com", kDefaultStunTlsPort, "test_no_transport", |
- kTurnPassword, "tcp", true); |
- turn_configs.push_back(turn3); |
- VerifyTurnConfigurations(turn_configs); |
+ cricket::RelayServerConfig turn2("hello.com", 443, "test_no_transport", |
+ kTurnPassword, cricket::PROTO_TCP, true); |
+ turn_servers.push_back(turn2); |
+ cricket::RelayServerConfig turn3("hello.com", kDefaultStunTlsPort, |
+ "test_no_transport", kTurnPassword, |
+ cricket::PROTO_TCP, true); |
+ turn_servers.push_back(turn3); |
+ VerifyTurnServers(turn_servers); |
} |
TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
@@ -370,32 +311,26 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { |
config.servers.push_back(ice_server); |
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store( |
new FakeDtlsIdentityStore()); |
- rtc::scoped_refptr<PeerConnectionInterface> pc( |
- factory_->CreatePeerConnection(config, nullptr, |
- allocator_factory_.get(), |
- dtls_identity_store.Pass(), |
- &observer_)); |
- EXPECT_TRUE(pc.get() != NULL); |
- StunConfigurations stun_configs; |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun1( |
- "1.2.3.4", 1234); |
- stun_configs.push_back(stun1); |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun2( |
- "1.2.3.4", 3478); |
- stun_configs.push_back(stun2); // Default port |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun3( |
- "2401:fa00:4::", 1234); |
- stun_configs.push_back(stun3); |
- webrtc::PortAllocatorFactoryInterface::StunConfiguration stun4( |
- "2401:fa00:4::", 3478); |
- stun_configs.push_back(stun4); // Default port |
- VerifyStunConfigurations(stun_configs); |
+ rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection( |
+ config, nullptr, std::move(port_allocator_), |
+ std::move(dtls_identity_store), &observer_)); |
+ ASSERT_TRUE(pc.get() != NULL); |
+ cricket::ServerAddresses stun_servers; |
+ rtc::SocketAddress stun1("1.2.3.4", 1234); |
+ stun_servers.insert(stun1); |
+ rtc::SocketAddress stun2("1.2.3.4", 3478); |
+ stun_servers.insert(stun2); // Default port |
+ rtc::SocketAddress stun3("2401:fa00:4::", 1234); |
+ stun_servers.insert(stun3); |
+ rtc::SocketAddress stun4("2401:fa00:4::", 3478); |
+ stun_servers.insert(stun4); // Default port |
+ VerifyStunServers(stun_servers); |
- TurnConfigurations turn_configs; |
- webrtc::PortAllocatorFactoryInterface::TurnConfiguration turn1( |
- "2401:fa00:4::", 1234, "test", kTurnPassword, "udp", false); |
- turn_configs.push_back(turn1); |
- VerifyTurnConfigurations(turn_configs); |
+ std::vector<cricket::RelayServerConfig> turn_servers; |
+ cricket::RelayServerConfig turn1("2401:fa00:4::", 1234, "test", kTurnPassword, |
+ cricket::PROTO_UDP, false); |
+ turn_servers.push_back(turn1); |
+ VerifyTurnServers(turn_servers); |
} |
// This test verifies the captured stream is rendered locally using a |