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

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1275703006: Bug 4517: Enable connectivity for demo page when no STUN/TURN specifiefd. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: merge from master Created 5 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
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
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 } 256 }
257 257
258 // This function starts the port/address gathering and check the existence of 258 // This function starts the port/address gathering and check the existence of
259 // candidates as specified. When |expect_stun_candidate| is true, 259 // candidates as specified. When |expect_stun_candidate| is true,
260 // |stun_candidate_addr| carries the expected reflective address, which is 260 // |stun_candidate_addr| carries the expected reflective address, which is
261 // also the related address for TURN candidate if it is expected. Otherwise, 261 // also the related address for TURN candidate if it is expected. Otherwise,
262 // it should be ignore. 262 // it should be ignore.
263 void CheckDisableAdapterEnumeration( 263 void CheckDisableAdapterEnumeration(
264 uint32 total_ports, 264 uint32 total_ports,
265 const rtc::IPAddress& host_candidate_addr,
265 const rtc::IPAddress& stun_candidate_addr, 266 const rtc::IPAddress& stun_candidate_addr,
266 const rtc::IPAddress& relay_candidate_udp_transport_addr, 267 const rtc::IPAddress& relay_candidate_udp_transport_addr,
267 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { 268 const rtc::IPAddress& relay_candidate_tcp_transport_addr) {
268 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 269 if (!session_) {
269 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | 270 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
271 }
272 session_->set_flags(session_->flags() |
273 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
270 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 274 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
271 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 275 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
272 allocator().set_allow_tcp_listen(false); 276 allocator().set_allow_tcp_listen(false);
273 session_->StartGettingPorts(); 277 session_->StartGettingPorts();
274 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 278 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
275 279
276 uint32 total_candidates = 0; 280 uint32 total_candidates = 0;
281 if (!IPIsUnspec(host_candidate_addr)) {
282 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
283 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
284 rtc::SocketAddress(host_candidate_addr, 0));
285 ++total_candidates;
286 }
277 if (!IPIsUnspec(stun_candidate_addr)) { 287 if (!IPIsUnspec(stun_candidate_addr)) {
278 ++total_candidates; 288 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
279 EXPECT_PRED5(CheckCandidate, candidates_[0],
280 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 289 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
281 rtc::SocketAddress(stun_candidate_addr, 0)); 290 rtc::SocketAddress(stun_candidate_addr, 0));
282 EXPECT_EQ( 291 EXPECT_EQ(rtc::EmptySocketAddressWithFamily(
283 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()), 292 candidates_[total_candidates].address().family()),
284 candidates_[0].related_address()); 293 candidates_[total_candidates].related_address());
294 ++total_candidates;
285 } 295 }
286 if (!IPIsUnspec(relay_candidate_udp_transport_addr)) { 296 if (!IPIsUnspec(relay_candidate_udp_transport_addr)) {
287 ++total_candidates; 297 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
288 EXPECT_PRED5(CheckCandidate, candidates_[1],
289 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 298 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
290 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); 299 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0));
291 EXPECT_EQ(stun_candidate_addr, candidates_[1].related_address().ipaddr()); 300 EXPECT_EQ(stun_candidate_addr,
301 candidates_[total_candidates].related_address().ipaddr());
302 ++total_candidates;
292 } 303 }
293 if (!IPIsUnspec(relay_candidate_tcp_transport_addr)) { 304 if (!IPIsUnspec(relay_candidate_tcp_transport_addr)) {
294 ++total_candidates; 305 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
295 EXPECT_PRED5(CheckCandidate, candidates_[2],
296 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 306 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
297 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); 307 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0));
298 EXPECT_EQ(stun_candidate_addr, candidates_[2].related_address().ipaddr()); 308 EXPECT_EQ(stun_candidate_addr,
309 candidates_[total_candidates].related_address().ipaddr());
310 ++total_candidates;
299 } 311 }
300 312
301 EXPECT_EQ(total_candidates, candidates_.size()); 313 EXPECT_EQ(total_candidates, candidates_.size());
302 EXPECT_EQ(total_ports, ports_.size()); 314 EXPECT_EQ(total_ports, ports_.size());
303 } 315 }
304 316
305 protected: 317 protected:
306 cricket::BasicPortAllocator& allocator() { 318 cricket::BasicPortAllocator& allocator() {
307 return *allocator_; 319 return *allocator_;
308 } 320 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 514
503 // Test that we should only get STUN and TURN candidates when adapter 515 // Test that we should only get STUN and TURN candidates when adapter
504 // enumeration is disabled. 516 // enumeration is disabled.
505 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) { 517 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) {
506 AddInterface(kClientAddr); 518 AddInterface(kClientAddr);
507 // GTURN is not configured here. 519 // GTURN is not configured here.
508 ResetWithNatServer(kStunAddr); 520 ResetWithNatServer(kStunAddr);
509 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 521 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
510 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 522 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
511 // TURN/UDP candidates. 523 // TURN/UDP candidates.
512 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), 524 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(),
513 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 525 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
514 } 526 }
515 527
516 // Test that even with multiple interfaces, the result should still be one STUN 528 // Test that even with multiple interfaces, the result should still be one STUN
517 // and one TURN candidate since we bind to any address (i.e. all 0s). 529 // and one TURN candidate since we bind to any address (i.e. all 0s).
518 TEST_F(PortAllocatorTest, 530 TEST_F(PortAllocatorTest,
519 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { 531 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) {
520 AddInterface(kPrivateAddr); 532 AddInterface(kPrivateAddr);
521 AddInterface(kPrivateAddr2); 533 AddInterface(kPrivateAddr2);
522 ResetWithNatServer(kStunAddr); 534 ResetWithNatServer(kStunAddr);
523 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 535 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
524 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 536 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
525 // TURN/UDP candidates. 537 // TURN/UDP candidates.
526 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), 538 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(),
527 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 539 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
528 } 540 }
529 541
530 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a 542 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a
531 // TURN/TCP server is specified. 543 // TURN/TCP server is specified.
532 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { 544 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) {
533 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 545 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
534 AddInterface(kClientAddr); 546 AddInterface(kClientAddr);
535 // GTURN is not configured here. 547 // GTURN is not configured here.
536 ResetWithNatServer(kStunAddr); 548 ResetWithNatServer(kStunAddr);
537 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 549 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
538 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN, 550 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN,
539 // TURN/UDP, and TURN/TCP candidates. 551 // TURN/UDP, and TURN/TCP candidates.
540 CheckDisableAdapterEnumeration(4U, kNatUdpAddr.ipaddr(), 552 CheckDisableAdapterEnumeration(4U, rtc::IPAddress(), kNatUdpAddr.ipaddr(),
541 kTurnUdpExtAddr.ipaddr(), 553 kTurnUdpExtAddr.ipaddr(),
542 kTurnUdpExtAddr.ipaddr()); 554 kTurnUdpExtAddr.ipaddr());
543 } 555 }
544 556
545 // Test that we should only get STUN and TURN candidates when adapter 557 // Test that we should only get STUN and TURN candidates when adapter
546 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx 558 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx
547 // address should be the public client interface. 559 // address should be the public client interface.
548 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) { 560 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) {
549 AddInterfaceAsDefaultRoute(kClientAddr); 561 AddInterfaceAsDefaultRoute(kClientAddr);
550 ResetWithStunServer(kStunAddr); 562 ResetWithStunServer(kStunAddr);
551 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 563 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
552 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and 564 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and
553 // TURN candidates. The STUN candidate should have kClientAddr as srflx 565 // TURN candidates. The STUN candidate should have kClientAddr as srflx
554 // address, and TURN candidate with kClientAddr as the related address. 566 // address, and TURN candidate with kClientAddr as the related address.
555 CheckDisableAdapterEnumeration(3U, kClientAddr.ipaddr(), 567 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kClientAddr.ipaddr(),
556 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 568 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
557 } 569 }
558 570
559 // Test that when adapter enumeration is disabled, for endpoints without 571 // Test that when adapter enumeration is disabled, for endpoints without
560 // STUN/TURN specified, no candidate is generated. 572 // STUN/TURN specified, no candidate is generated.
561 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { 573 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) {
562 AddInterfaceAsDefaultRoute(kClientAddr); 574 AddInterfaceAsDefaultRoute(kClientAddr);
563 ResetWithNoServers(); 575 ResetWithNoServers();
564 // Expect to see 2 ports: STUN and TCP ports, but no candidate. 576 // Expect to see 2 ports: STUN and TCP ports, but no candidate.
565 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), 577 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(),
578 rtc::IPAddress(), rtc::IPAddress());
579 }
580
581 // Test that when adapter enumeration is disabled, with
582 // PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind
583 // a NAT, there are a localhost candidate in addition to a STUN candidate.
584 TEST_F(PortAllocatorTest,
585 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateRequested) {
586 AddInterfaceAsDefaultRoute(kClientAddr);
587 ResetWithStunServer(kStunAddr);
588 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
589 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE);
590 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN
591 // candidate.
592 CheckDisableAdapterEnumeration(2U, rtc::GetLoopbackIP(AF_INET),
593 kClientAddr.ipaddr(), rtc::IPAddress(),
566 rtc::IPAddress()); 594 rtc::IPAddress());
567 } 595 }
568 596
569 // Disable for asan, see 597 // Disable for asan, see
570 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 598 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
571 #if !defined(ADDRESS_SANITIZER) 599 #if !defined(ADDRESS_SANITIZER)
572 600
573 // Test that we can get OnCandidatesAllocationDone callback when all the ports 601 // Test that we can get OnCandidatesAllocationDone callback when all the ports
574 // are disabled. 602 // are disabled.
575 TEST_F(PortAllocatorTest, TestDisableAllPorts) { 603 TEST_F(PortAllocatorTest, TestDisableAllPorts) {
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 AllocationSequenceForTest alloc_sequence( 1303 AllocationSequenceForTest alloc_sequence(
1276 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), 1304 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()),
1277 &network1, &config, flag); 1305 &network1, &config, flag);
1278 // This simply tests it will not crash if udp_socket_ in the 1306 // This simply tests it will not crash if udp_socket_ in the
1279 // AllocationSequence is null, which is chosen in the constructor. 1307 // AllocationSequence is null, which is chosen in the constructor.
1280 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1308 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1281 relay_server.ports.push_back( 1309 relay_server.ports.push_back(
1282 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 1310 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1283 alloc_sequence.CreateTurnPort(relay_server); 1311 alloc_sequence.CreateTurnPort(relay_server);
1284 } 1312 }
OLDNEW
« webrtc/p2p/base/portallocator.h ('K') | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698