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

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

Issue 1914803002: Allow the localhost IP address even if it does not match the tcp port address (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Merge with head 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/tcpport.cc ('k') | webrtc/p2p/p2p.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/tcpport_unittest.cc
diff --git a/webrtc/p2p/base/tcpport_unittest.cc b/webrtc/p2p/base/tcpport_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..77fb790c537bda82c6ec55171851c966f050c807
--- /dev/null
+++ b/webrtc/p2p/base/tcpport_unittest.cc
@@ -0,0 +1,85 @@
+/*
+ * 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);
+}
« no previous file with comments | « webrtc/p2p/base/tcpport.cc ('k') | webrtc/p2p/p2p.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698