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

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

Issue 2989303002: Make Port (and subclasses) fully "Network"-based, instead of IP-based. (Closed)
Patch Set: Add back Port constructor that takes IP for backwards compatibility. Created 3 years, 4 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
« no previous file with comments | « webrtc/p2p/base/turnport.cc ('k') | webrtc/p2p/client/basicportallocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 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 #if defined(WEBRTC_POSIX) 10 #if defined(WEBRTC_POSIX)
11 #include <dirent.h> 11 #include <dirent.h>
12 #endif 12 #endif
13 13
14 #include <list>
14 #include <memory> 15 #include <memory>
15 16
16 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 17 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
17 #include "webrtc/p2p/base/p2pconstants.h" 18 #include "webrtc/p2p/base/p2pconstants.h"
18 #include "webrtc/p2p/base/portallocator.h" 19 #include "webrtc/p2p/base/portallocator.h"
19 #include "webrtc/p2p/base/tcpport.h" 20 #include "webrtc/p2p/base/tcpport.h"
20 #include "webrtc/p2p/base/testturnserver.h" 21 #include "webrtc/p2p/base/testturnserver.h"
21 #include "webrtc/p2p/base/turnport.h" 22 #include "webrtc/p2p/base/turnport.h"
22 #include "webrtc/p2p/base/udpport.h" 23 #include "webrtc/p2p/base/udpport.h"
23 #include "webrtc/rtc_base/asynctcpsocket.h" 24 #include "webrtc/rtc_base/asynctcpsocket.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 // Note: This test uses a fake clock with a simulated network round trip 138 // Note: This test uses a fake clock with a simulated network round trip
138 // (between local port and TURN server) of kSimulatedRtt. 139 // (between local port and TURN server) of kSimulatedRtt.
139 class TurnPortTest : public testing::Test, 140 class TurnPortTest : public testing::Test,
140 public sigslot::has_slots<>, 141 public sigslot::has_slots<>,
141 public rtc::MessageHandler { 142 public rtc::MessageHandler {
142 public: 143 public:
143 TurnPortTest() 144 TurnPortTest()
144 : ss_(new TurnPortTestVirtualSocketServer()), 145 : ss_(new TurnPortTestVirtualSocketServer()),
145 main_(ss_.get()), 146 main_(ss_.get()),
146 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
147 socket_factory_(rtc::Thread::Current()), 147 socket_factory_(rtc::Thread::Current()),
148 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), 148 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
149 turn_ready_(false), 149 turn_ready_(false),
150 turn_error_(false), 150 turn_error_(false),
151 turn_unknown_address_(false), 151 turn_unknown_address_(false),
152 turn_create_permission_success_(false), 152 turn_create_permission_success_(false),
153 udp_ready_(false), 153 udp_ready_(false),
154 test_finish_(false) { 154 test_finish_(false) {
155 // Some code uses "last received time == 0" to represent "nothing received 155 // Some code uses "last received time == 0" to represent "nothing received
156 // so far", so we need to start the fake clock at a nonzero time... 156 // so far", so we need to start the fake clock at a nonzero time...
157 // TODO(deadbeef): Fix this. 157 // TODO(deadbeef): Fix this.
158 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 158 fake_clock_.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
159 network_.AddIP(rtc::IPAddress(INADDR_ANY));
160 } 159 }
161 160
162 virtual void OnMessage(rtc::Message* msg) { 161 virtual void OnMessage(rtc::Message* msg) {
163 RTC_CHECK(msg->message_id == MSG_TESTFINISH); 162 RTC_CHECK(msg->message_id == MSG_TESTFINISH);
164 if (msg->message_id == MSG_TESTFINISH) 163 if (msg->message_id == MSG_TESTFINISH)
165 test_finish_ = true; 164 test_finish_ = true;
166 } 165 }
167 166
168 void ConnectSignalAddressReadyToSetLocalhostAsAltenertativeLocalAddress() {
169 rtc::AsyncPacketSocket* socket = turn_port_->socket();
170 rtc::VirtualSocket* virtual_socket =
171 ss_->LookupBinding(socket->GetLocalAddress());
172 virtual_socket->SignalAddressReady.connect(
173 this, &TurnPortTest::SetLocalhostAsAltenertativeLocalAddress);
174 }
175
176 void SetLocalhostAsAltenertativeLocalAddress(
177 rtc::VirtualSocket* socket,
178 const rtc::SocketAddress& address) {
179 SocketAddress local_address("127.0.0.1", 2000);
180 socket->SetAlternativeLocalAddress(local_address);
181 }
182
183 void OnTurnPortComplete(Port* port) { 167 void OnTurnPortComplete(Port* port) {
184 turn_ready_ = true; 168 turn_ready_ = true;
185 } 169 }
186 void OnTurnPortError(Port* port) { 170 void OnTurnPortError(Port* port) {
187 turn_error_ = true; 171 turn_error_ = true;
188 } 172 }
189 void OnTurnUnknownAddress(PortInterface* port, 173 void OnTurnUnknownAddress(PortInterface* port,
190 const SocketAddress& addr, 174 const SocketAddress& addr,
191 ProtocolType proto, 175 ProtocolType proto,
192 IceMessage* msg, 176 IceMessage* msg,
(...skipping 29 matching lines...) Expand all
222 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr, 206 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr,
223 packet_time); 207 packet_time);
224 } 208 }
225 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) { 209 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) {
226 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM); 210 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM);
227 EXPECT_GE(socket->Bind(addr), 0); 211 EXPECT_GE(socket->Bind(addr), 0);
228 EXPECT_GE(socket->Listen(5), 0); 212 EXPECT_GE(socket->Listen(5), 0);
229 return socket; 213 return socket;
230 } 214 }
231 215
216 rtc::Network* MakeNetwork(const SocketAddress& addr) {
217 networks_.emplace_back("unittest", "unittest", addr.ipaddr(), 32);
218 networks_.back().AddIP(addr.ipaddr());
219 return &networks_.back();
220 }
221
232 void CreateTurnPort(const std::string& username, 222 void CreateTurnPort(const std::string& username,
233 const std::string& password, 223 const std::string& password,
234 const ProtocolAddress& server_address) { 224 const ProtocolAddress& server_address) {
235 CreateTurnPort(kLocalAddr1, username, password, server_address); 225 CreateTurnPortWithAllParams(MakeNetwork(kLocalAddr1), username, password,
226 server_address, std::string());
236 } 227 }
237 void CreateTurnPort(const rtc::SocketAddress& local_address, 228 void CreateTurnPort(const rtc::SocketAddress& local_address,
238 const std::string& username, 229 const std::string& username,
239 const std::string& password, 230 const std::string& password,
240 const ProtocolAddress& server_address) { 231 const ProtocolAddress& server_address) {
241 RelayCredentials credentials(username, password); 232 CreateTurnPortWithAllParams(MakeNetwork(local_address), username, password,
242 turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, &network_, 233 server_address, std::string());
243 local_address.ipaddr(), 0, 0,
244 kIceUfrag1, kIcePwd1,
245 server_address, credentials, 0,
246 std::string()));
247 // This TURN port will be the controlling.
248 turn_port_->SetIceRole(ICEROLE_CONTROLLING);
249 ConnectSignals();
250 } 234 }
251 235
252 // Should be identical to CreateTurnPort but specifies an origin value 236 // Should be identical to CreateTurnPort but specifies an origin value
253 // when creating the instance of TurnPort. 237 // when creating the instance of TurnPort.
254 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address, 238 void CreateTurnPortWithOrigin(const rtc::SocketAddress& local_address,
255 const std::string& username, 239 const std::string& username,
256 const std::string& password, 240 const std::string& password,
257 const ProtocolAddress& server_address, 241 const ProtocolAddress& server_address,
258 const std::string& origin) { 242 const std::string& origin) {
243 CreateTurnPortWithAllParams(MakeNetwork(local_address), username, password,
244 server_address, origin);
245 }
246
247 void CreateTurnPortWithNetwork(rtc::Network* network,
248 const std::string& username,
249 const std::string& password,
250 const ProtocolAddress& server_address) {
251 CreateTurnPortWithAllParams(network, username, password, server_address,
252 std::string());
253 }
254
255 // Version of CreateTurnPort that takes all possible parameters; all other
256 // helper methods call this, such that "SetIceRole" and "ConnectSignals" (and
257 // possibly other things in the future) only happen in one place.
258 void CreateTurnPortWithAllParams(rtc::Network* network,
259 const std::string& username,
260 const std::string& password,
261 const ProtocolAddress& server_address,
262 const std::string& origin) {
259 RelayCredentials credentials(username, password); 263 RelayCredentials credentials(username, password);
260 turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, &network_, 264 turn_port_.reset(TurnPort::Create(&main_, &socket_factory_, network, 0, 0,
261 local_address.ipaddr(), 0, 0, 265 kIceUfrag1, kIcePwd1, server_address,
262 kIceUfrag1, kIcePwd1, 266 credentials, 0, origin));
263 server_address, credentials, 0,
264 origin));
265 // This TURN port will be the controlling. 267 // This TURN port will be the controlling.
266 turn_port_->SetIceRole(ICEROLE_CONTROLLING); 268 turn_port_->SetIceRole(ICEROLE_CONTROLLING);
267 ConnectSignals(); 269 ConnectSignals();
268 } 270 }
269 271
270 void CreateSharedTurnPort(const std::string& username, 272 void CreateSharedTurnPort(const std::string& username,
271 const std::string& password, 273 const std::string& password,
272 const ProtocolAddress& server_address) { 274 const ProtocolAddress& server_address) {
273 RTC_CHECK(server_address.proto == PROTO_UDP); 275 RTC_CHECK(server_address.proto == PROTO_UDP);
274 276
275 if (!socket_) { 277 if (!socket_) {
276 socket_.reset(socket_factory_.CreateUdpSocket( 278 socket_.reset(socket_factory_.CreateUdpSocket(
277 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0)); 279 rtc::SocketAddress(kLocalAddr1.ipaddr(), 0), 0, 0));
278 ASSERT_TRUE(socket_ != NULL); 280 ASSERT_TRUE(socket_ != NULL);
279 socket_->SignalReadPacket.connect( 281 socket_->SignalReadPacket.connect(
280 this, &TurnPortTest::OnSocketReadPacket); 282 this, &TurnPortTest::OnSocketReadPacket);
281 } 283 }
282 284
283 RelayCredentials credentials(username, password); 285 RelayCredentials credentials(username, password);
284 turn_port_.reset(TurnPort::Create( 286 turn_port_.reset(TurnPort::Create(
285 &main_, &socket_factory_, &network_, socket_.get(), kIceUfrag1, 287 &main_, &socket_factory_, MakeNetwork(kLocalAddr1), socket_.get(),
286 kIcePwd1, server_address, credentials, 0, std::string())); 288 kIceUfrag1, kIcePwd1, server_address, credentials, 0, std::string()));
287 // This TURN port will be the controlling. 289 // This TURN port will be the controlling.
288 turn_port_->SetIceRole(ICEROLE_CONTROLLING); 290 turn_port_->SetIceRole(ICEROLE_CONTROLLING);
289 ConnectSignals(); 291 ConnectSignals();
290 } 292 }
291 293
292 void ConnectSignals() { 294 void ConnectSignals() {
293 turn_port_->SignalPortComplete.connect(this, 295 turn_port_->SignalPortComplete.connect(this,
294 &TurnPortTest::OnTurnPortComplete); 296 &TurnPortTest::OnTurnPortComplete);
295 turn_port_->SignalPortError.connect(this, 297 turn_port_->SignalPortError.connect(this,
296 &TurnPortTest::OnTurnPortError); 298 &TurnPortTest::OnTurnPortError);
297 turn_port_->SignalUnknownAddress.connect(this, 299 turn_port_->SignalUnknownAddress.connect(this,
298 &TurnPortTest::OnTurnUnknownAddress); 300 &TurnPortTest::OnTurnUnknownAddress);
299 turn_port_->SignalCreatePermissionResult.connect(this, 301 turn_port_->SignalCreatePermissionResult.connect(this,
300 &TurnPortTest::OnTurnCreatePermissionResult); 302 &TurnPortTest::OnTurnCreatePermissionResult);
301 turn_port_->SignalTurnRefreshResult.connect( 303 turn_port_->SignalTurnRefreshResult.connect(
302 this, &TurnPortTest::OnTurnRefreshResult); 304 this, &TurnPortTest::OnTurnRefreshResult);
303 } 305 }
304 306
305 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } 307 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); }
306 308
307 void CreateUdpPort(const SocketAddress& address) { 309 void CreateUdpPort(const SocketAddress& address) {
308 udp_port_.reset(UDPPort::Create(&main_, &socket_factory_, &network_, 310 udp_port_.reset(UDPPort::Create(&main_, &socket_factory_,
309 address.ipaddr(), 0, 0, kIceUfrag2, 311 MakeNetwork(address), 0, 0, kIceUfrag2,
310 kIcePwd2, std::string(), false)); 312 kIcePwd2, std::string(), false));
311 // UDP port will be controlled. 313 // UDP port will be controlled.
312 udp_port_->SetIceRole(ICEROLE_CONTROLLED); 314 udp_port_->SetIceRole(ICEROLE_CONTROLLED);
313 udp_port_->SignalPortComplete.connect( 315 udp_port_->SignalPortComplete.connect(
314 this, &TurnPortTest::OnUdpPortComplete); 316 this, &TurnPortTest::OnUdpPortComplete);
315 } 317 }
316 318
317 void PrepareTurnAndUdpPorts(ProtocolType protocol_type) { 319 void PrepareTurnAndUdpPorts(ProtocolType protocol_type) {
318 // turn_port_ should have been created. 320 // turn_port_ should have been created.
319 ASSERT_TRUE(turn_port_ != nullptr); 321 ASSERT_TRUE(turn_port_ != nullptr);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 ASSERT_EQ(num_packets, udp_packets_.size()); 611 ASSERT_EQ(num_packets, udp_packets_.size());
610 for (size_t i = 0; i < num_packets; ++i) { 612 for (size_t i = 0; i < num_packets; ++i) {
611 EXPECT_EQ(i + 1, turn_packets_[i].size()); 613 EXPECT_EQ(i + 1, turn_packets_[i].size());
612 EXPECT_EQ(i + 1, udp_packets_[i].size()); 614 EXPECT_EQ(i + 1, udp_packets_[i].size());
613 EXPECT_EQ(turn_packets_[i], udp_packets_[i]); 615 EXPECT_EQ(turn_packets_[i], udp_packets_[i]);
614 } 616 }
615 } 617 }
616 618
617 protected: 619 protected:
618 rtc::ScopedFakeClock fake_clock_; 620 rtc::ScopedFakeClock fake_clock_;
621 // When a "create port" helper method is called with an IP, we create a
622 // Network with that IP and add it to this list. Using a list instead of a
623 // vector so that when it grows, pointers aren't invalidated.
624 std::list<rtc::Network> networks_;
619 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_; 625 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_;
620 rtc::AutoSocketServerThread main_; 626 rtc::AutoSocketServerThread main_;
621 rtc::Network network_;
622 rtc::BasicPacketSocketFactory socket_factory_; 627 rtc::BasicPacketSocketFactory socket_factory_;
623 std::unique_ptr<rtc::AsyncPacketSocket> socket_; 628 std::unique_ptr<rtc::AsyncPacketSocket> socket_;
624 TestTurnServer turn_server_; 629 TestTurnServer turn_server_;
625 std::unique_ptr<TurnPort> turn_port_; 630 std::unique_ptr<TurnPort> turn_port_;
626 std::unique_ptr<UDPPort> udp_port_; 631 std::unique_ptr<UDPPort> udp_port_;
627 bool turn_ready_; 632 bool turn_ready_;
628 bool turn_error_; 633 bool turn_error_;
629 bool turn_unknown_address_; 634 bool turn_unknown_address_;
630 bool turn_create_permission_success_; 635 bool turn_create_permission_success_;
631 bool udp_ready_; 636 bool udp_ready_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 ASSERT_EQ(1U, turn_port_->Candidates().size()); 702 ASSERT_EQ(1U, turn_port_->Candidates().size());
698 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), 703 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
699 turn_port_->Candidates()[0].address().ipaddr()); 704 turn_port_->Candidates()[0].address().ipaddr());
700 EXPECT_NE(0, turn_port_->Candidates()[0].address().port()); 705 EXPECT_NE(0, turn_port_->Candidates()[0].address().port());
701 } 706 }
702 707
703 // Test case for WebRTC issue 3927 where a proxy binds to the local host address 708 // Test case for WebRTC issue 3927 where a proxy binds to the local host address
704 // instead the address that TurnPort originally bound to. The candidate pair 709 // instead the address that TurnPort originally bound to. The candidate pair
705 // impacted by this behavior should still be used. 710 // impacted by this behavior should still be used.
706 TEST_F(TurnPortTest, TestTurnTcpAllocationWhenProxyChangesAddressToLocalHost) { 711 TEST_F(TurnPortTest, TestTurnTcpAllocationWhenProxyChangesAddressToLocalHost) {
712 SocketAddress local_address("127.0.0.1", 0);
713 // After calling this, when TurnPort attempts to get a socket bound to
714 // kLocalAddr, it will end up using localhost instead.
715 ss_->SetAlternativeLocalAddress(kLocalAddr1.ipaddr(), local_address.ipaddr());
716
707 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 717 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
708 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); 718 CreateTurnPort(kLocalAddr1, kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
709 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10 * 1024)); 719 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10 * 1024));
710 turn_port_->PrepareAddress(); 720 turn_port_->PrepareAddress();
711 ConnectSignalAddressReadyToSetLocalhostAsAltenertativeLocalAddress();
712 EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_); 721 EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
713 ASSERT_EQ(1U, turn_port_->Candidates().size()); 722 ASSERT_EQ(1U, turn_port_->Candidates().size());
714 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(), 723 EXPECT_EQ(kTurnUdpExtAddr.ipaddr(),
715 turn_port_->Candidates()[0].address().ipaddr()); 724 turn_port_->Candidates()[0].address().ipaddr());
716 EXPECT_NE(0, turn_port_->Candidates()[0].address().port()); 725 EXPECT_NE(0, turn_port_->Candidates()[0].address().port());
726
727 // Verify that the socket actually used localhost, otherwise this test isn't
728 // doing what it meant to.
729 ASSERT_EQ(local_address.ipaddr(),
730 turn_port_->Candidates()[0].related_address().ipaddr());
731 }
732
733 // If the address the socket ends up bound to does not match any address of the
734 // TurnPort's Network, then the socket should be discarded and no candidates
735 // should be signaled. In the context of ICE, where one TurnPort is created for
736 // each Network, when this happens it's likely that the unexpected address is
737 // associated with some other Network, which another TurnPort is already
738 // covering.
739 TEST_F(TurnPortTest,
740 TurnTcpAllocationDiscardedIfBoundAddressDoesNotMatchNetwork) {
741 // Sockets bound to kLocalAddr1 will actually end up with kLocalAddr2.
742 ss_->SetAlternativeLocalAddress(kLocalAddr1.ipaddr(), kLocalAddr2.ipaddr());
743
744 // Set up TURN server to use TCP (this logic only exists for TCP).
745 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
746
747 // Create TURN port and tell it to start allocation.
748 CreateTurnPort(kLocalAddr1, kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
749 turn_port_->PrepareAddress();
750
751 // Shouldn't take more than 1 RTT to realize the bound address isn't the one
752 // expected.
753 EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_);
754 }
755
756 // A caveat for the above logic: if the socket ends up bound to one of the IPs
757 // associated with the Network, just not the "best" one, this is ok.
758 TEST_F(TurnPortTest, TurnTcpAllocationNotDiscardedIfNotBoundToBestIP) {
759 // Sockets bound to kLocalAddr1 will actually end up with kLocalAddr2.
760 ss_->SetAlternativeLocalAddress(kLocalAddr1.ipaddr(), kLocalAddr2.ipaddr());
761
762 // Set up a network with kLocalAddr1 as the "best" IP, and kLocalAddr2 as an
763 // alternate.
764 rtc::Network* network = MakeNetwork(kLocalAddr1);
765 network->AddIP(kLocalAddr2.ipaddr());
766 ASSERT_EQ(kLocalAddr1.ipaddr(), network->GetBestIP());
767
768 // Set up TURN server to use TCP (this logic only exists for TCP).
769 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
770
771 // Create TURN port using our special Network, and tell it to start
772 // allocation.
773 CreateTurnPortWithNetwork(network, kTurnUsername, kTurnPassword,
774 kTurnTcpProtoAddr);
775 turn_port_->PrepareAddress();
776
777 // Candidate should be gathered as normally.
778 EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kSimulatedRtt * 3, fake_clock_);
779 ASSERT_EQ(1U, turn_port_->Candidates().size());
780
781 // Verify that the socket actually used the alternate address, otherwise this
782 // test isn't doing what it meant to.
783 ASSERT_EQ(kLocalAddr2.ipaddr(),
784 turn_port_->Candidates()[0].related_address().ipaddr());
717 } 785 }
718 786
719 // Testing turn port will attempt to create TCP socket on address resolution 787 // Testing turn port will attempt to create TCP socket on address resolution
720 // failure. 788 // failure.
721 TEST_F(TurnPortTest, TestTurnTcpOnAddressResolveFailure) { 789 TEST_F(TurnPortTest, TestTurnTcpOnAddressResolveFailure) {
722 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 790 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
723 CreateTurnPort(kTurnUsername, kTurnPassword, 791 CreateTurnPort(kTurnUsername, kTurnPassword,
724 ProtocolAddress(rtc::SocketAddress("www.google.invalid", 3478), 792 ProtocolAddress(rtc::SocketAddress("www.google.invalid", 3478),
725 PROTO_TCP)); 793 PROTO_TCP));
726 turn_port_->PrepareAddress(); 794 turn_port_->PrepareAddress();
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 EXPECT_TRUE(turn_port_->Candidates().empty()); 1355 EXPECT_TRUE(turn_port_->Candidates().empty());
1288 turn_port_.reset(); 1356 turn_port_.reset();
1289 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); 1357 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH);
1290 // Waiting for above message to be processed. 1358 // Waiting for above message to be processed.
1291 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); 1359 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_);
1292 EXPECT_EQ(last_fd_count, GetFDCount()); 1360 EXPECT_EQ(last_fd_count, GetFDCount());
1293 } 1361 }
1294 #endif 1362 #endif
1295 1363
1296 } // namespace cricket 1364 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/turnport.cc ('k') | webrtc/p2p/client/basicportallocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698