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

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

Issue 2018693002: Create a new connection if a candidate reuses an address (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: address comments Created 4 years, 7 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/port.cc ('k') | webrtc/p2p/base/relayport.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/port_unittest.cc
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index 43ef084b02e1aa49a970c9d9a10accce7a414236..099567f4314652f4f707008516f0860e6d63ea7d 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -169,7 +169,7 @@ class TestPort : public Port {
virtual Connection* CreateConnection(const Candidate& remote_candidate,
CandidateOrigin origin) {
Connection* conn = new ProxyConnection(this, 0, remote_candidate);
- AddConnection(conn);
+ AddOrReplaceConnection(conn);
// Set use-candidate attribute flag as this will add USE-CANDIDATE attribute
// in STUN binding requests.
conn->set_use_candidate_attr(true);
@@ -2665,3 +2665,31 @@ TEST_F(PortTest, TestSetIceParameters) {
EXPECT_EQ("ufrag2", candidate.username());
EXPECT_EQ("password2", candidate.password());
}
+
+TEST_F(PortTest, TestAddConnectionWithSameAddress) {
+ std::unique_ptr<TestPort> port(
+ CreateTestPort(kLocalAddr1, "ufrag1", "password1"));
+ port->PrepareAddress();
+ EXPECT_EQ(1u, port->Candidates().size());
+ rtc::SocketAddress address("1.1.1.1", 5000);
+ cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, "");
+ cricket::Connection* conn1 =
+ port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
+ cricket::Connection* conn_in_use = port->GetConnection(address);
+ EXPECT_EQ(conn1, conn_in_use);
+ EXPECT_EQ(0u, conn_in_use->remote_candidate().generation());
+
+ // Creating with a candidate with the same address again will get us a
+ // different connection with the new candidate.
+ candidate.set_generation(2);
+ cricket::Connection* conn2 =
+ port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
+ EXPECT_NE(conn1, conn2);
+ conn_in_use = port->GetConnection(address);
+ EXPECT_EQ(conn2, conn_in_use);
+ EXPECT_EQ(2u, conn_in_use->remote_candidate().generation());
+
+ // Make sure the new connection was not deleted.
+ rtc::Thread::Current()->ProcessMessages(300);
+ EXPECT_TRUE(port->GetConnection(address) != nullptr);
+}
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | webrtc/p2p/base/relayport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698