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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2757893003: Add MakeUnique from chromium and change StunMessage::AddAttribute to take a unique_ptr. (Closed)
Patch Set: Better fix to undefined reference to MIN_SIZE error. Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/api/fakemetricsobserver.h" 14 #include "webrtc/api/fakemetricsobserver.h"
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/dscp.h" 16 #include "webrtc/base/dscp.h"
17 #include "webrtc/base/fakeclock.h" 17 #include "webrtc/base/fakeclock.h"
18 #include "webrtc/base/fakenetwork.h" 18 #include "webrtc/base/fakenetwork.h"
19 #include "webrtc/base/firewallsocketserver.h" 19 #include "webrtc/base/firewallsocketserver.h"
20 #include "webrtc/base/gunit.h" 20 #include "webrtc/base/gunit.h"
21 #include "webrtc/base/helpers.h" 21 #include "webrtc/base/helpers.h"
22 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
23 #include "webrtc/base/natserver.h" 23 #include "webrtc/base/natserver.h"
24 #include "webrtc/base/natsocketfactory.h" 24 #include "webrtc/base/natsocketfactory.h"
25 #include "webrtc/base/physicalsocketserver.h" 25 #include "webrtc/base/physicalsocketserver.h"
26 #include "webrtc/base/ptr_util.h"
26 #include "webrtc/base/socketaddress.h" 27 #include "webrtc/base/socketaddress.h"
27 #include "webrtc/base/ssladapter.h" 28 #include "webrtc/base/ssladapter.h"
28 #include "webrtc/base/thread.h" 29 #include "webrtc/base/thread.h"
29 #include "webrtc/base/virtualsocketserver.h" 30 #include "webrtc/base/virtualsocketserver.h"
31 #include "webrtc/p2p/base/fakeportallocator.h"
30 #include "webrtc/p2p/base/icetransportinternal.h" 32 #include "webrtc/p2p/base/icetransportinternal.h"
31 #include "webrtc/p2p/base/fakeportallocator.h"
32 #include "webrtc/p2p/base/p2ptransportchannel.h" 33 #include "webrtc/p2p/base/p2ptransportchannel.h"
33 #include "webrtc/p2p/base/packettransportinternal.h" 34 #include "webrtc/p2p/base/packettransportinternal.h"
34 #include "webrtc/p2p/base/testrelayserver.h" 35 #include "webrtc/p2p/base/testrelayserver.h"
35 #include "webrtc/p2p/base/teststunserver.h" 36 #include "webrtc/p2p/base/teststunserver.h"
36 #include "webrtc/p2p/base/testturnserver.h" 37 #include "webrtc/p2p/base/testturnserver.h"
37 #include "webrtc/p2p/client/basicportallocator.h" 38 #include "webrtc/p2p/client/basicportallocator.h"
38 39
39 namespace { 40 namespace {
40 41
41 using rtc::SocketAddress; 42 using rtc::SocketAddress;
(...skipping 2928 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 last_sent_packet_id_ = last_sent_packet_id; 2971 last_sent_packet_id_ = last_sent_packet_id;
2971 ++selected_candidate_pair_switches_; 2972 ++selected_candidate_pair_switches_;
2972 } 2973 }
2973 2974
2974 void ReceivePingOnConnection(Connection* conn, 2975 void ReceivePingOnConnection(Connection* conn,
2975 const std::string& remote_ufrag, 2976 const std::string& remote_ufrag,
2976 int priority, 2977 int priority,
2977 uint32_t nomination = 0) { 2978 uint32_t nomination = 0) {
2978 IceMessage msg; 2979 IceMessage msg;
2979 msg.SetType(STUN_BINDING_REQUEST); 2980 msg.SetType(STUN_BINDING_REQUEST);
2980 msg.AddAttribute(new StunByteStringAttribute( 2981 msg.AddAttribute(rtc::MakeUnique<StunByteStringAttribute>(
2981 STUN_ATTR_USERNAME, 2982 STUN_ATTR_USERNAME,
2982 conn->local_candidate().username() + ":" + remote_ufrag)); 2983 conn->local_candidate().username() + ":" + remote_ufrag));
2983 msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority)); 2984 msg.AddAttribute(
2985 rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, priority));
2984 if (nomination != 0) { 2986 if (nomination != 0) {
2985 msg.AddAttribute( 2987 msg.AddAttribute(rtc::MakeUnique<StunUInt32Attribute>(
2986 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); 2988 STUN_ATTR_NOMINATION, nomination));
2987 } 2989 }
2988 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); 2990 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength));
2989 msg.AddMessageIntegrity(conn->local_candidate().password()); 2991 msg.AddMessageIntegrity(conn->local_candidate().password());
2990 msg.AddFingerprint(); 2992 msg.AddFingerprint();
2991 rtc::ByteBufferWriter buf; 2993 rtc::ByteBufferWriter buf;
2992 msg.Write(&buf); 2994 msg.Write(&buf);
2993 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); 2995 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0));
2994 } 2996 }
2995 2997
2996 void OnReadyToSend(rtc::PacketTransportInternal* transport) { 2998 void OnReadyToSend(rtc::PacketTransportInternal* transport) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 ch.SetIceRole(ICEROLE_CONTROLLING); 3175 ch.SetIceRole(ICEROLE_CONTROLLING);
3174 ch.SetIceParameters(kIceParams[0]); 3176 ch.SetIceParameters(kIceParams[0]);
3175 ch.MaybeStartGathering(); 3177 ch.MaybeStartGathering();
3176 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), 3178 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(),
3177 kDefaultTimeout); 3179 kDefaultTimeout);
3178 3180
3179 // Simulate a binding request being received, creating a peer reflexive 3181 // Simulate a binding request being received, creating a peer reflexive
3180 // candidate pair while we still don't have remote ICE parameters. 3182 // candidate pair while we still don't have remote ICE parameters.
3181 IceMessage request; 3183 IceMessage request;
3182 request.SetType(STUN_BINDING_REQUEST); 3184 request.SetType(STUN_BINDING_REQUEST);
3183 request.AddAttribute( 3185 request.AddAttribute(rtc::MakeUnique<StunByteStringAttribute>(
3184 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3186 STUN_ATTR_USERNAME, kIceUfrag[1]));
3185 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3187 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3186 request.AddAttribute( 3188 request.AddAttribute(
3187 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3189 rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, prflx_priority));
3188 Port* port = GetPort(&ch); 3190 Port* port = GetPort(&ch);
3189 ASSERT_NE(nullptr, port); 3191 ASSERT_NE(nullptr, port);
3190 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3192 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3191 &request, kIceUfrag[1], false); 3193 &request, kIceUfrag[1], false);
3192 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); 3194 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
3193 ASSERT_NE(nullptr, conn); 3195 ASSERT_NE(nullptr, conn);
3194 3196
3195 // Simulate waiting for a second (and change) and verify that no pings were 3197 // Simulate waiting for a second (and change) and verify that no pings were
3196 // sent, since we don't yet have remote ICE parameters. 3198 // sent, since we don't yet have remote ICE parameters.
3197 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); 3199 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 // Wait for conn1 to be pruned. 3344 // Wait for conn1 to be pruned.
3343 EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout); 3345 EXPECT_TRUE_WAIT(conn1->pruned(), kMediumTimeout);
3344 // Destroy the connection to test SignalUnknownAddress. 3346 // Destroy the connection to test SignalUnknownAddress.
3345 conn1->Destroy(); 3347 conn1->Destroy();
3346 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3348 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr,
3347 kMediumTimeout); 3349 kMediumTimeout);
3348 3350
3349 // Create a minimal STUN message with prflx priority. 3351 // Create a minimal STUN message with prflx priority.
3350 IceMessage request; 3352 IceMessage request;
3351 request.SetType(STUN_BINDING_REQUEST); 3353 request.SetType(STUN_BINDING_REQUEST);
3352 request.AddAttribute( 3354 request.AddAttribute(rtc::MakeUnique<StunByteStringAttribute>(
3353 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3355 STUN_ATTR_USERNAME, kIceUfrag[1]));
3354 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3356 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3355 request.AddAttribute( 3357 request.AddAttribute(
3356 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3358 rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, prflx_priority));
3357 EXPECT_NE(prflx_priority, remote_priority); 3359 EXPECT_NE(prflx_priority, remote_priority);
3358 3360
3359 Port* port = GetPort(&ch); 3361 Port* port = GetPort(&ch);
3360 // conn1 should be resurrected with original priority. 3362 // conn1 should be resurrected with original priority.
3361 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3363 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3362 &request, kIceUfrag[1], false); 3364 &request, kIceUfrag[1], false);
3363 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3365 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3364 ASSERT_TRUE(conn1 != nullptr); 3366 ASSERT_TRUE(conn1 != nullptr);
3365 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 3367 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
3366 3368
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 // appropriately. 3487 // appropriately.
3486 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { 3488 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
3487 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3489 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3488 P2PTransportChannel ch("receiving state change", 1, &pa); 3490 P2PTransportChannel ch("receiving state change", 1, &pa);
3489 PrepareChannel(&ch); 3491 PrepareChannel(&ch);
3490 ch.SetIceRole(ICEROLE_CONTROLLED); 3492 ch.SetIceRole(ICEROLE_CONTROLLED);
3491 ch.MaybeStartGathering(); 3493 ch.MaybeStartGathering();
3492 // A minimal STUN message with prflx priority. 3494 // A minimal STUN message with prflx priority.
3493 IceMessage request; 3495 IceMessage request;
3494 request.SetType(STUN_BINDING_REQUEST); 3496 request.SetType(STUN_BINDING_REQUEST);
3495 request.AddAttribute( 3497 request.AddAttribute(rtc::MakeUnique<StunByteStringAttribute>(
3496 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3498 STUN_ATTR_USERNAME, kIceUfrag[1]));
3497 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3499 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3498 request.AddAttribute( 3500 request.AddAttribute(
3499 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3501 rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, prflx_priority));
3500 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3502 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch));
3501 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3503 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3502 &request, kIceUfrag[1], false); 3504 &request, kIceUfrag[1], false);
3503 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3505 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3504 ASSERT_TRUE(conn1 != nullptr); 3506 ASSERT_TRUE(conn1 != nullptr);
3505 EXPECT_TRUE(port->sent_binding_response()); 3507 EXPECT_TRUE(port->sent_binding_response());
3506 EXPECT_NE(conn1, ch.selected_connection()); 3508 EXPECT_NE(conn1, ch.selected_connection());
3507 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3509 conn1->ReceivedPingResponse(LOW_RTT, "id");
3508 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); 3510 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3509 port->set_sent_binding_response(false); 3511 port->set_sent_binding_response(false);
(...skipping 17 matching lines...) Expand all
3527 &request, kIceUfrag[1], false); 3529 &request, kIceUfrag[1], false);
3528 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3530 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3529 ASSERT_TRUE(conn3 != nullptr); 3531 ASSERT_TRUE(conn3 != nullptr);
3530 EXPECT_TRUE(port->sent_binding_response()); 3532 EXPECT_TRUE(port->sent_binding_response());
3531 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3533 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3532 EXPECT_EQ(conn2, ch.selected_connection()); 3534 EXPECT_EQ(conn2, ch.selected_connection());
3533 port->set_sent_binding_response(false); 3535 port->set_sent_binding_response(false);
3534 3536
3535 // However if the request contains use_candidate attribute, it will be 3537 // However if the request contains use_candidate attribute, it will be
3536 // selected as the selected connection. 3538 // selected as the selected connection.
3537 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3539 request.AddAttribute(
3540 rtc::MakeUnique<StunByteStringAttribute>(STUN_ATTR_USE_CANDIDATE));
3538 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, 3541 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP,
3539 &request, kIceUfrag[1], false); 3542 &request, kIceUfrag[1], false);
3540 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 3543 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
3541 ASSERT_TRUE(conn4 != nullptr); 3544 ASSERT_TRUE(conn4 != nullptr);
3542 EXPECT_TRUE(port->sent_binding_response()); 3545 EXPECT_TRUE(port->sent_binding_response());
3543 // conn4 is not the selected connection yet because it is not writable. 3546 // conn4 is not the selected connection yet because it is not writable.
3544 EXPECT_EQ(conn2, ch.selected_connection()); 3547 EXPECT_EQ(conn2, ch.selected_connection());
3545 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3548 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3546 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3549 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3547 3550
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 ASSERT_TRUE(conn2 != nullptr); 3585 ASSERT_TRUE(conn2 != nullptr);
3583 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving. 3586 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable and receiving.
3584 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 3587 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
3585 EXPECT_EQ(conn2, ch.selected_connection()); 3588 EXPECT_EQ(conn2, ch.selected_connection());
3586 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3589 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3587 3590
3588 // Now another STUN message with an unknown address and use_candidate will 3591 // Now another STUN message with an unknown address and use_candidate will
3589 // nominate the selected connection. 3592 // nominate the selected connection.
3590 IceMessage request; 3593 IceMessage request;
3591 request.SetType(STUN_BINDING_REQUEST); 3594 request.SetType(STUN_BINDING_REQUEST);
3592 request.AddAttribute( 3595 request.AddAttribute(rtc::MakeUnique<StunByteStringAttribute>(
3593 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3596 STUN_ATTR_USERNAME, kIceUfrag[1]));
3594 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3597 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3595 request.AddAttribute( 3598 request.AddAttribute(
3596 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3599 rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, prflx_priority));
3597 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3600 request.AddAttribute(
3601 rtc::MakeUnique<StunByteStringAttribute>(STUN_ATTR_USE_CANDIDATE));
3598 Port* port = GetPort(&ch); 3602 Port* port = GetPort(&ch);
3599 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3603 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3600 &request, kIceUfrag[1], false); 3604 &request, kIceUfrag[1], false);
3601 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3605 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3602 ASSERT_TRUE(conn3 != nullptr); 3606 ASSERT_TRUE(conn3 != nullptr);
3603 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3607 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3604 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3608 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3605 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3609 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3606 3610
3607 // Now another data packet will not switch the selected connection because the 3611 // Now another data packet will not switch the selected connection because the
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
4325 4329
4326 // TCP Relay/Relay is the next. 4330 // TCP Relay/Relay is the next.
4327 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4331 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4328 TCP_PROTOCOL_NAME); 4332 TCP_PROTOCOL_NAME);
4329 4333
4330 // Finally, Local/Relay will be pinged. 4334 // Finally, Local/Relay will be pinged.
4331 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4335 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4332 } 4336 }
4333 4337
4334 } // namespace cricket { 4338 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698