webrtc_m130/webrtc/p2p/base/tcpport_unittest.cc

86 lines
3.0 KiB
C++
Raw Normal View History

Reland of Allow the localhost IP address even if it does not match the tcp port address (patchset #1 id:1 of https://codereview.webrtc.org/1979463003/ ) Reason for revert: Relanding this change since the revert didn't make a difference. Original issue's description: > Revert of Allow the localhost IP address even if it does not match the tcp port address (patchset #4 id:120001 of https://codereview.webrtc.org/1914803002/ ) > > Reason for revert: > Speculatively reverting due to failures on the memcheck bot (and possibly other bots): > > https://build.chromium.org/p/client.webrtc/builders/Linux%20Memcheck/builds/5910/steps/video_engine_tests/logs/EndToEndTest.SendsAndReceivesH264 > > Original issue's description: > > This fixes an issue similar to > > https://bugs.chromium.org/p/webrtc/issues/detail?id=3927 > > where the localhost IP does not match the turn port address. > > The issue here is in the TCP port. > > > > BUG= > > R=pthatcher@webrtc.org > > > > Committed: https://crrev.com/6705012904e6cbbefce6fbce0a3f615b7aeafd8f > > Cr-Commit-Position: refs/heads/master@{#12707} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org,honghaiz@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG= > > Committed: https://crrev.com/1cbf0a73eb4b475e8beb878ea3a4d650191f0c08 > Cr-Commit-Position: refs/heads/master@{#12728} TBR=pthatcher@webrtc.org,deadbeef@webrtc.org,honghaiz@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG= Review-Url: https://codereview.webrtc.org/1979073002 Cr-Commit-Position: refs/heads/master@{#12746}
2016-05-14 03:19:31 -07:00
/*
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/gunit.h"
#include "webrtc/base/physicalsocketserver.h"
#include "webrtc/base/thread.h"
#include "webrtc/base/virtualsocketserver.h"
#include "webrtc/p2p/base/basicpacketsocketfactory.h"
#include "webrtc/p2p/base/tcpport.h"
using rtc::SocketAddress;
using cricket::Connection;
using cricket::Port;
using cricket::TCPPort;
using cricket::ICE_UFRAG_LENGTH;
using cricket::ICE_PWD_LENGTH;
static int kTimeout = 1000;
static const SocketAddress kLocalAddr("11.11.11.11", 1);
static const SocketAddress kRemoteAddr("22.22.22.22", 2);
class TCPPortTest : public testing::Test, public sigslot::has_slots<> {
public:
TCPPortTest()
: main_(rtc::Thread::Current()),
pss_(new rtc::PhysicalSocketServer),
ss_(new rtc::VirtualSocketServer(pss_.get())),
ss_scope_(ss_.get()),
network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
socket_factory_(rtc::Thread::Current()),
username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)),
password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) {
network_.AddIP(rtc::IPAddress(INADDR_ANY));
}
void ConnectSignalSocketCreated() {
ss_->SignalSocketCreated.connect(this, &TCPPortTest::OnSocketCreated);
}
void OnSocketCreated(rtc::VirtualSocket* socket) {
LOG(LS_INFO) << "socket created ";
socket->SignalAddressReady.connect(
this, &TCPPortTest::SetLocalhostAsAlternativeLocalAddress);
}
void SetLocalhostAsAlternativeLocalAddress(rtc::VirtualSocket* socket,
const SocketAddress& address) {
SocketAddress local_address("127.0.0.1", 2000);
socket->SetAlternativeLocalAddress(local_address);
}
TCPPort* CreateTCPPort(const SocketAddress& addr) {
return TCPPort::Create(main_, &socket_factory_, &network_, addr.ipaddr(), 0,
0, username_, password_, true);
}
protected:
rtc::Thread* main_;
rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
rtc::SocketServerScope ss_scope_;
rtc::Network network_;
rtc::BasicPacketSocketFactory socket_factory_;
std::string username_;
std::string password_;
};
TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
rtc::scoped_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr));
rtc::scoped_ptr<TCPPort> rport(CreateTCPPort(kRemoteAddr));
lport->PrepareAddress();
rport->PrepareAddress();
// Start to listen to new socket creation event.
ConnectSignalSocketCreated();
Connection* conn =
lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
}