Index: webrtc/api/peerconnectioninterface_unittest.cc |
diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc |
index 2594b6c10637996c3a554757a188da633d5b12cb..ac017a02c57720f7663ec432aa61e9a09bccf117 100644 |
--- a/webrtc/api/peerconnectioninterface_unittest.cc |
+++ b/webrtc/api/peerconnectioninterface_unittest.cc |
@@ -39,7 +39,7 @@ |
#include "webrtc/base/thread.h" |
#include "webrtc/media/base/fakevideocapturer.h" |
#include "webrtc/media/sctp/sctpdataengine.h" |
-#include "webrtc/p2p/client/fakeportallocator.h" |
+#include "webrtc/p2p/base/fakeportallocator.h" |
#include "webrtc/pc/mediasession.h" |
static const char kStreamLabel1[] = "local_stream_1"; |
@@ -532,24 +532,33 @@ |
} |
void CreatePeerConnection() { |
- CreatePeerConnection("", "", NULL); |
+ CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); |
} |
void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
- CreatePeerConnection("", "", constraints); |
- } |
- |
- void CreatePeerConnection(const std::string& uri, |
- const std::string& password, |
- webrtc::MediaConstraintsInterface* constraints) { |
+ CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), |
+ constraints); |
+ } |
+ |
+ void CreatePeerConnectionWithIceTransportsType( |
+ PeerConnectionInterface::IceTransportsType type) { |
+ PeerConnectionInterface::RTCConfiguration config; |
+ config.type = type; |
+ return CreatePeerConnection(config, nullptr); |
+ } |
+ |
+ void CreatePeerConnectionWithIceServer(const std::string& uri, |
+ const std::string& password) { |
PeerConnectionInterface::RTCConfiguration config; |
PeerConnectionInterface::IceServer server; |
- if (!uri.empty()) { |
- server.uri = uri; |
- server.password = password; |
- config.servers.push_back(server); |
- } |
- |
+ server.uri = uri; |
+ server.password = password; |
+ config.servers.push_back(server); |
+ CreatePeerConnection(config, nullptr); |
+ } |
+ |
+ void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, |
+ webrtc::MediaConstraintsInterface* constraints) { |
std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
port_allocator_ = port_allocator.get(); |
@@ -594,7 +603,7 @@ |
} |
void CreatePeerConnectionWithDifferentConfigurations() { |
- CreatePeerConnection(kStunAddressOnly, "", NULL); |
+ CreatePeerConnectionWithIceServer(kStunAddressOnly, ""); |
EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
@@ -605,7 +614,7 @@ |
CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
- CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); |
+ CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword); |
EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
EXPECT_EQ(kTurnUsername, |
@@ -993,6 +1002,44 @@ |
TEST_F(PeerConnectionInterfaceTest, |
CreatePeerConnectionWithDifferentConfigurations) { |
CreatePeerConnectionWithDifferentConfigurations(); |
+} |
+ |
+TEST_F(PeerConnectionInterfaceTest, |
+ CreatePeerConnectionWithDifferentIceTransportsTypes) { |
+ CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); |
+ EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); |
+ CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); |
+ EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
+ CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); |
+ EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, |
+ port_allocator_->candidate_filter()); |
+ CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); |
+ EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); |
+} |
+ |
+// Test that when a PeerConnection is created with a nonzero candidate pool |
+// size, the pooled PortAllocatorSession is created with all the attributes |
+// in the RTCConfiguration. |
+TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { |
+ PeerConnectionInterface::RTCConfiguration config; |
+ PeerConnectionInterface::IceServer server; |
+ server.uri = kStunAddressOnly; |
+ config.servers.push_back(server); |
+ config.type = PeerConnectionInterface::kRelay; |
+ config.disable_ipv6 = true; |
+ config.tcp_candidate_policy = |
+ PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
+ config.ice_candidate_pool_size = 1; |
+ CreatePeerConnection(config, nullptr); |
+ |
+ const cricket::FakePortAllocatorSession* session = |
+ static_cast<const cricket::FakePortAllocatorSession*>( |
+ port_allocator_->GetPooledSession()); |
+ ASSERT_NE(nullptr, session); |
+ EXPECT_EQ(1UL, session->stun_servers().size()); |
+ EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); |
+ EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
+ EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
} |
TEST_F(PeerConnectionInterfaceTest, AddStreams) { |
@@ -1888,6 +1935,35 @@ |
port_allocator_->stun_servers().begin()->hostname()); |
} |
+TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { |
+ CreatePeerConnection(); |
+ PeerConnectionInterface::RTCConfiguration config; |
+ config.type = PeerConnectionInterface::kRelay; |
+ EXPECT_TRUE(pc_->SetConfiguration(config)); |
+ EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
+} |
+ |
+// Test that when SetConfiguration changes both the pool size and other |
+// attributes, the pooled session is created with the updated attributes. |
+TEST_F(PeerConnectionInterfaceTest, |
+ SetConfigurationCreatesPooledSessionCorrectly) { |
+ CreatePeerConnection(); |
+ PeerConnectionInterface::RTCConfiguration config; |
+ config.ice_candidate_pool_size = 1; |
+ PeerConnectionInterface::IceServer server; |
+ server.uri = kStunAddressOnly; |
+ config.servers.push_back(server); |
+ config.type = PeerConnectionInterface::kRelay; |
+ CreatePeerConnection(config, nullptr); |
+ |
+ const cricket::FakePortAllocatorSession* session = |
+ static_cast<const cricket::FakePortAllocatorSession*>( |
+ port_allocator_->GetPooledSession()); |
+ ASSERT_NE(nullptr, session); |
+ EXPECT_EQ(1UL, session->stun_servers().size()); |
+ EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
+} |
+ |
// Test that PeerConnection::Close changes the states to closed and all remote |
// tracks change state to ended. |
TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |