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

Unified Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1350523003: TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Mac test. Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/portallocator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index d0277f481461015f67320fc6f1eadc4166a59813..485449fa88d6aa7b821f129de11290c66cdf5bd4 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -297,10 +297,8 @@ class P2PTransportChannelTestBase : public testing::Test,
const std::string& remote_ice_pwd) {
cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel(
"test content name", component, NULL, GetAllocator(endpoint));
- channel->SignalRequestSignaling.connect(
- this, &P2PTransportChannelTestBase::OnChannelRequestSignaling);
- channel->SignalCandidateReady.connect(this,
- &P2PTransportChannelTestBase::OnCandidate);
+ channel->SignalCandidateGathered.connect(
+ this, &P2PTransportChannelTestBase::OnCandidate);
channel->SignalReadPacket.connect(
this, &P2PTransportChannelTestBase::OnReadPacket);
channel->SignalRoleConflict.connect(
@@ -314,6 +312,7 @@ class P2PTransportChannelTestBase : public testing::Test,
channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
channel->Connect();
+ channel->MaybeStartGathering();
return channel;
}
void DestroyChannels() {
@@ -389,10 +388,9 @@ class P2PTransportChannelTestBase : public testing::Test,
}
bool IsLocalToPrflxOrTheReverse(const Result& expected) {
- return ((expected.local_type == "local" &&
- expected.remote_type == "prflx") ||
- (expected.local_type == "prflx" &&
- expected.remote_type == "local"));
+ return (
+ (expected.local_type == "local" && expected.remote_type == "prflx") ||
+ (expected.local_type == "prflx" && expected.remote_type == "local"));
}
// Return true if the approprite parts of the expected Result, based
@@ -512,8 +510,8 @@ class P2PTransportChannelTestBase : public testing::Test,
ep2_ch1()->best_connection()) {
int32 converge_start = rtc::Time(), converge_time;
int converge_wait = 2000;
- EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected),
- converge_wait, converge_wait);
+ EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), converge_wait,
+ converge_wait);
// Also do EXPECT_EQ on each part so that failures are more verbose.
ExpectCandidate1(expected);
@@ -562,7 +560,7 @@ class P2PTransportChannelTestBase : public testing::Test,
}
// This test waits for the transport to become receiving and writable on both
- // end points. Once they are, the end points set new local ice credentials to
+ // end points. Once they are, the end points set new local ice credentials and
// restart the ice gathering. Finally it waits for the transport to select a
// new connection using the newly generated ice candidates.
// Before calling this function the end points must be configured.
@@ -582,8 +580,10 @@ class P2PTransportChannelTestBase : public testing::Test,
ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
+ ep1_ch1()->MaybeStartGathering();
ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]);
ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
+ ep2_ch1()->MaybeStartGathering();
EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
old_local_candidate1->generation(),
@@ -626,9 +626,6 @@ class P2PTransportChannelTestBase : public testing::Test,
TestSendRecv(1);
}
- void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) {
- channel->OnSignalingReady();
- }
// We pass the candidates directly to the other side.
void OnCandidate(cricket::TransportChannelImpl* ch,
const cricket::Candidate& c) {
@@ -669,7 +666,7 @@ class P2PTransportChannelTestBase : public testing::Test,
}
LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->"
<< rch->component() << "): " << c.ToString();
- rch->OnCandidate(c);
+ rch->AddRemoteCandidate(c);
break;
}
}
@@ -804,8 +801,10 @@ class P2PTransportChannelTest : public P2PTransportChannelTestBase {
static const Result* kMatrixSharedUfrag[NUM_CONFIGS][NUM_CONFIGS];
static const Result* kMatrixSharedSocketAsGice[NUM_CONFIGS][NUM_CONFIGS];
static const Result* kMatrixSharedSocketAsIce[NUM_CONFIGS][NUM_CONFIGS];
- void ConfigureEndpoints(Config config1, Config config2,
- int allocator_flags1, int allocator_flags2) {
+ void ConfigureEndpoints(Config config1,
+ Config config2,
+ int allocator_flags1,
+ int allocator_flags2) {
ServerAddresses stun_servers;
stun_servers.insert(kStunAddr);
GetEndpoint(0)->allocator_.reset(
@@ -821,8 +820,8 @@ class P2PTransportChannelTest : public P2PTransportChannelTestBase {
cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
relay_server.credentials = kRelayCredentials;
- relay_server.ports.push_back(cricket::ProtocolAddress(
- kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ relay_server.ports.push_back(
+ cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
GetEndpoint(0)->allocator_->AddRelay(relay_server);
GetEndpoint(1)->allocator_->AddRelay(relay_server);
@@ -1026,15 +1025,14 @@ const P2PTransportChannelTest::Result*
// The actual tests that exercise all the various configurations.
// Test names are of the form P2PTransportChannelTest_TestOPENToNAT_FULL_CONE
-#define P2P_TEST_DECLARATION(x, y, z) \
- TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \
- ConfigureEndpoints(x, y, \
- PORTALLOCATOR_ENABLE_SHARED_SOCKET, \
- PORTALLOCATOR_ENABLE_SHARED_SOCKET); \
- if (kMatrixSharedSocketAsIce[x][y] != NULL) \
- Test(*kMatrixSharedSocketAsIce[x][y]); \
- else \
- LOG(LS_WARNING) << "Not yet implemented"; \
+#define P2P_TEST_DECLARATION(x, y, z) \
+ TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \
+ ConfigureEndpoints(x, y, PORTALLOCATOR_ENABLE_SHARED_SOCKET, \
+ PORTALLOCATOR_ENABLE_SHARED_SOCKET); \
+ if (kMatrixSharedSocketAsIce[x][y] != NULL) \
+ Test(*kMatrixSharedSocketAsIce[x][y]); \
+ else \
+ LOG(LS_WARNING) << "Not yet implemented"; \
}
#define P2P_TEST(x, y) \
@@ -1089,8 +1087,7 @@ P2P_TEST_SET(PROXY_SOCKS)
// Test that we restart candidate allocation when local ufrag&pwd changed.
// Standard Ice protocol is used.
TEST_F(P2PTransportChannelTest, HandleUfragPwdChange) {
- ConfigureEndpoints(OPEN, OPEN,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
CreateChannels(1);
TestHandleIceUfragPasswordChanged();
@@ -1099,8 +1096,7 @@ TEST_F(P2PTransportChannelTest, HandleUfragPwdChange) {
// Test the operation of GetStats.
TEST_F(P2PTransportChannelTest, GetStats) {
- ConfigureEndpoints(OPEN, OPEN,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
CreateChannels(1);
EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
@@ -1126,8 +1122,7 @@ TEST_F(P2PTransportChannelTest, GetStats) {
// Test that we properly create a connection on a STUN ping from unknown address
// when the signaling is slow.
TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
- ConfigureEndpoints(OPEN, OPEN,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
// Emulate no remote credentials coming in.
set_clear_remote_candidates_ufrag_pwd(false);
@@ -1171,8 +1166,7 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
// Test that we properly create a connection on a STUN ping from unknown address
// when the signaling is slow and the end points are behind NAT.
TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
- ConfigureEndpoints(OPEN, NAT_SYMMETRIC,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
// Emulate no remote credentials coming in.
set_clear_remote_candidates_ufrag_pwd(false);
@@ -1214,8 +1208,7 @@ TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
// Test that if remote candidates don't have ufrag and pwd, we still work.
TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
set_clear_remote_candidates_ufrag_pwd(true);
- ConfigureEndpoints(OPEN, OPEN,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
CreateChannels(1);
const cricket::Connection* best_connection = NULL;
@@ -1230,8 +1223,7 @@ TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
// Test that a host behind NAT cannot be reached when incoming_only
// is set to true.
TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) {
- ConfigureEndpoints(NAT_FULL_CONE, OPEN,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
SetAllocatorFlags(0, kOnlyLocalPorts);
@@ -1252,8 +1244,7 @@ TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) {
// Test that a peer behind NAT can connect to a peer that has
// incoming_only flag set.
TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) {
- ConfigureEndpoints(OPEN, NAT_FULL_CONE,
- kDefaultPortAllocatorFlags,
+ ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags,
kDefaultPortAllocatorFlags);
SetAllocatorFlags(0, kOnlyLocalPorts);
@@ -1414,11 +1405,10 @@ TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
// Testing forceful TURN connections.
TEST_F(P2PTransportChannelTest, TestForceTurn) {
- ConfigureEndpoints(NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
- kDefaultPortAllocatorFlags |
- cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET,
- kDefaultPortAllocatorFlags |
- cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
+ ConfigureEndpoints(
+ NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
+ kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET,
+ kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
set_force_relay(true);
SetAllocationStepDelay(0, kMinimumStepDelay);
@@ -1473,8 +1463,7 @@ class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase {
TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) {
ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE);
Test(P2PTransportChannelTestBase::Result(
- "prflx", "udp", "stun", "udp",
- "stun", "udp", "prflx", "udp", 1000));
+ "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000));
}
// Test what happens when we have multiple available pathways.
@@ -1560,11 +1549,12 @@ TEST_F(P2PTransportChannelMultihomedTest, TestDrain) {
// Remove the public interface, add the alternate interface, and allocate
- // a new generation of candidates for the new interface (via Connect()).
+ // a new generation of candidates for the new interface (via
+ // MaybeStartGathering()).
LOG(LS_INFO) << "Draining...";
AddAddress(1, kAlternateAddrs[1]);
RemoveAddress(1, kPublicAddrs[1]);
- ep2_ch1()->Connect();
+ ep2_ch1()->MaybeStartGathering();
// We should switch over to use the alternate address after
// an exchange of pings.
@@ -1591,17 +1581,11 @@ class P2PTransportChannelPingTest : public testing::Test,
protected:
void PrepareChannel(cricket::P2PTransportChannel* ch) {
- ch->SignalRequestSignaling.connect(
- this, &P2PTransportChannelPingTest::OnChannelRequestSignaling);
ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
}
- void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) {
- channel->OnSignalingReady();
- }
-
cricket::Candidate CreateCandidate(const std::string& ip,
int port,
int priority) {
@@ -1648,8 +1632,9 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa);
PrepareChannel(&ch);
ch.Connect();
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@@ -1672,8 +1657,9 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa);
PrepareChannel(&ch);
ch.Connect();
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@@ -1696,16 +1682,17 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa);
PrepareChannel(&ch);
ch.Connect();
+ ch.MaybeStartGathering();
// Create conn1 and keep track of original candidate priority.
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
uint32 remote_priority = conn1->remote_candidate().priority();
// Create a higher priority candidate and make the connection
// receiving/writable. This will prune conn1.
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
@@ -1752,7 +1739,8 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
EXPECT_EQ(500, ch.receiving_timeout());
EXPECT_EQ(50, ch.check_receiving_delay());
ch.Connect();
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@@ -1773,14 +1761,15 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
PrepareChannel(&ch);
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
// When a higher priority candidate comes in, the new connection is chosen
// as the best connection.
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 10));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn2, ch.best_connection());
@@ -1788,7 +1777,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// If a stun request with use-candidate attribute arrives, the receiving
// connection will be set as the best connection, even though
// its priority is lower.
- ch.OnCandidate(CreateCandidate("3.3.3.3", 3, 1));
+ ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the best connection is still conn2.
@@ -1803,7 +1792,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// Even if another higher priority candidate arrives,
// it will not be set as the best connection because the best connection
// is nominated by the controlling side.
- ch.OnCandidate(CreateCandidate("4.4.4.4", 4, 100));
+ ch.AddRemoteCandidate(CreateCandidate("4.4.4.4", 4, 100));
cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_EQ(conn3, ch.best_connection());
@@ -1828,6 +1817,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
PrepareChannel(&ch);
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
+ ch.MaybeStartGathering();
// A minimal STUN message with prflx priority.
cricket::IceMessage request;
request.SetType(cricket::STUN_BINDING_REQUEST);
@@ -1846,7 +1836,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
EXPECT_EQ(conn1, ch.best_connection());
// Another connection is nominated via use_candidate.
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
// Because it has a lower priority, the best connection is still conn1.
@@ -1892,7 +1882,8 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
PrepareChannel(&ch);
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
- ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 10));
+ ch.MaybeStartGathering();
+ ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
@@ -1900,7 +1891,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// If a data packet is received on conn2, the best connection should
// switch to conn2 because the controlled side must mirror the media path
// chosen by the controlling side.
- ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Start receiving.
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/portallocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698