| Index: talk/app/webrtc/peerconnectionfactory_unittest.cc
|
| diff --git a/talk/app/webrtc/peerconnectionfactory_unittest.cc b/talk/app/webrtc/peerconnectionfactory_unittest.cc
|
| index d0018d9897c1b96010aa2e8a676d119cae209e99..050d5dbb12a05caf06bbb5928324ec989b2edf9e 100644
|
| --- a/talk/app/webrtc/peerconnectionfactory_unittest.cc
|
| +++ b/talk/app/webrtc/peerconnectionfactory_unittest.cc
|
| @@ -28,7 +28,6 @@
|
| #include <string>
|
| #include <utility>
|
|
|
| -#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"
|
| @@ -40,6 +39,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;
|
| @@ -48,17 +48,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[] =
|
| @@ -111,41 +105,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();
|
| }
|
|
|
| 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
|
| @@ -155,12 +147,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, std::move(dtls_identity_store), &observer));
|
| + config, nullptr, nullptr, std::move(dtls_identity_store), &observer));
|
|
|
| EXPECT_TRUE(pc.get() != nullptr);
|
| }
|
| @@ -181,22 +173,21 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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);
|
| + 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
|
| @@ -212,58 +203,21 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServersUrls) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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(),
|
| + config, nullptr, std::move(port_allocator_),
|
| std::move(dtls_identity_store), &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);
|
| + 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) {
|
| @@ -278,14 +232,14 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingNoUsernameInUri) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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);
|
| + 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
|
| @@ -299,14 +253,14 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingTurnUrlWithTransportParam) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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);
|
| + 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) {
|
| @@ -324,22 +278,22 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingSecureTurnUrl) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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);
|
| + 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) {
|
| @@ -359,29 +313,25 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) {
|
| rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store(
|
| new FakeDtlsIdentityStore());
|
| rtc::scoped_refptr<PeerConnectionInterface> pc(factory_->CreatePeerConnection(
|
| - config, nullptr, allocator_factory_.get(), std::move(dtls_identity_store),
|
| - &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);
|
| + 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
|
|
|