Chromium Code Reviews| Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc |
| diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
| index 1395038bed48df757a0d71eae923b3a29aa883ad..81fb037fc1061397a819c232fd38b595578287e7 100644 |
| --- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
| +++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
| @@ -1728,12 +1728,14 @@ class P2PTransportChannelPingTest : public testing::Test, |
| cricket::Candidate CreateCandidate(const std::string& ip, |
| int port, |
| - int priority) { |
| + int priority, |
| + const std::string& ufrag = "") { |
| cricket::Candidate c; |
| c.set_address(rtc::SocketAddress(ip, port)); |
| c.set_component(1); |
| c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| c.set_priority(priority); |
| + c.set_username(ufrag); |
| return c; |
| } |
| @@ -1817,6 +1819,39 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
| EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| } |
| +// Test that if a remote candidate is added with an old ufrag, it will be |
| +// discarded, and if it is added with a ufrag that was not seen before, it will |
| +// be used to create connections where the ICE pwd will be set when the ICE |
| +// credentials arrive. |
| +TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
| + cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| + cricket::P2PTransportChannel ch("add candidate", 1, nullptr, &pa); |
| + PrepareChannel(&ch); |
| + ch.Connect(); |
| + ch.MaybeStartGathering(); |
| + // Add a candidate with a future ufrag. |
| + ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
| + cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| + ASSERT_TRUE(conn1 != nullptr); |
| + const cricket::Candidate& candidate = conn1->remote_candidate(); |
| + EXPECT_EQ(kIceUfrag[2], candidate.username()); |
| + EXPECT_TRUE(candidate.password().empty()); |
| + EXPECT_TRUE(ch.FindNextPingableConnection() == nullptr); |
| + |
| + // Set the remote credentials with the "future" ufrag. |
| + // This should set the ICE pwd in the remote candidate of |conn1|, making |
| + // it pingable. |
| + ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| + EXPECT_EQ(kIceUfrag[2], candidate.username()); |
| + EXPECT_EQ(kIcePwd[2], candidate.password()); |
| + EXPECT_TRUE(ch.FindNextPingableConnection() != nullptr); |
| + |
| + // Now add a candidate with an old ufrag. No connection will be created. |
| + ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); |
| + rtc::Thread::Current()->ProcessMessages(500); |
| + EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); |
|
pthatcher1
2015/12/04 20:43:50
Do we also need a test to make sure that if genera
honghaiz3
2015/12/09 23:57:54
Done.
|
| +} |
| + |
| TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
| cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); |