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

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

Issue 2680233002: Use fake clock in some more networks tests. (Closed)
Patch Set: Created 3 years, 10 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/p2p/base/basicpacketsocketfactory.h" 14 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
15 #include "webrtc/p2p/base/p2pconstants.h" 15 #include "webrtc/p2p/base/p2pconstants.h"
16 #include "webrtc/p2p/base/p2ptransportchannel.h" 16 #include "webrtc/p2p/base/p2ptransportchannel.h"
17 #include "webrtc/p2p/base/testrelayserver.h" 17 #include "webrtc/p2p/base/testrelayserver.h"
18 #include "webrtc/p2p/base/teststunserver.h" 18 #include "webrtc/p2p/base/teststunserver.h"
19 #include "webrtc/p2p/base/testturnserver.h" 19 #include "webrtc/p2p/base/testturnserver.h"
20 #include "webrtc/p2p/client/basicportallocator.h" 20 #include "webrtc/p2p/client/basicportallocator.h"
21 #include "webrtc/base/fakeclock.h"
21 #include "webrtc/base/fakenetwork.h" 22 #include "webrtc/base/fakenetwork.h"
22 #include "webrtc/base/firewallsocketserver.h" 23 #include "webrtc/base/firewallsocketserver.h"
23 #include "webrtc/base/gunit.h" 24 #include "webrtc/base/gunit.h"
24 #include "webrtc/base/helpers.h" 25 #include "webrtc/base/helpers.h"
25 #include "webrtc/base/ipaddress.h" 26 #include "webrtc/base/ipaddress.h"
26 #include "webrtc/base/logging.h" 27 #include "webrtc/base/logging.h"
27 #include "webrtc/base/natserver.h" 28 #include "webrtc/base/natserver.h"
28 #include "webrtc/base/natsocketfactory.h" 29 #include "webrtc/base/natsocketfactory.h"
29 #include "webrtc/base/network.h" 30 #include "webrtc/base/network.h"
30 #include "webrtc/base/physicalsocketserver.h" 31 #include "webrtc/base/physicalsocketserver.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), 382 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(),
382 rtc::IPAddress()); 383 rtc::IPAddress());
383 if (!session_) { 384 if (!session_) {
384 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 385 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
385 } 386 }
386 session_->set_flags(session_->flags() | 387 session_->set_flags(session_->flags() |
387 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | 388 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
388 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 389 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
389 allocator().set_allow_tcp_listen(false); 390 allocator().set_allow_tcp_listen(false);
390 session_->StartGettingPorts(); 391 session_->StartGettingPorts();
391 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 392 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
393 kDefaultAllocationTimeout, fake_clock);
392 394
393 uint32_t total_candidates = 0; 395 uint32_t total_candidates = 0;
394 if (!host_candidate_addr.IsNil()) { 396 if (!host_candidate_addr.IsNil()) {
395 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", 397 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp",
396 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); 398 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0));
397 ++total_candidates; 399 ++total_candidates;
398 } 400 }
399 if (!stun_candidate_addr.IsNil()) { 401 if (!stun_candidate_addr.IsNil()) {
400 rtc::SocketAddress related_address(host_candidate_addr, 0); 402 rtc::SocketAddress related_address(host_candidate_addr, 0);
401 if (host_candidate_addr.IsNil()) { 403 if (host_candidate_addr.IsNil()) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 allocator_->SetConfiguration(allocator_->stun_servers(), 523 allocator_->SetConfiguration(allocator_->stun_servers(),
522 allocator_->turn_servers(), 0, true); 524 allocator_->turn_servers(), 0, true);
523 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 525 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
524 allocator_->set_step_delay(kMinimumStepDelay); 526 allocator_->set_step_delay(kMinimumStepDelay);
525 allocator_->set_flags(allocator().flags() | 527 allocator_->set_flags(allocator().flags() |
526 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 528 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
527 PORTALLOCATOR_DISABLE_TCP); 529 PORTALLOCATOR_DISABLE_TCP);
528 530
529 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 531 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
530 session_->StartGettingPorts(); 532 session_->StartGettingPorts();
531 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 533 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
534 kDefaultAllocationTimeout, fake_clock);
532 // Only 2 ports (one STUN and one TURN) are actually being used. 535 // Only 2 ports (one STUN and one TURN) are actually being used.
533 EXPECT_EQ(2U, session_->ReadyPorts().size()); 536 EXPECT_EQ(2U, session_->ReadyPorts().size());
534 // We have verified that each port, when it is added to |ports_|, it is 537 // We have verified that each port, when it is added to |ports_|, it is
535 // found in |ready_ports|, and when it is pruned, it is not found in 538 // found in |ready_ports|, and when it is pruned, it is not found in
536 // |ready_ports|, so we only need to verify the content in one of them. 539 // |ready_ports|, so we only need to verify the content in one of them.
537 EXPECT_EQ(2U, ports_.size()); 540 EXPECT_EQ(2U, ports_.size());
538 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); 541 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
539 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); 542 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
540 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); 543 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr));
541 544
(...skipping 22 matching lines...) Expand all
564 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); 567 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress());
565 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 568 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
566 569
567 allocator_->set_step_delay(kMinimumStepDelay); 570 allocator_->set_step_delay(kMinimumStepDelay);
568 allocator_->set_flags( 571 allocator_->set_flags(
569 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | 572 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET |
570 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); 573 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP);
571 574
572 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 575 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
573 session_->StartGettingPorts(); 576 session_->StartGettingPorts();
574 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 577 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
578 kDefaultAllocationTimeout, fake_clock);
575 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. 579 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready.
576 EXPECT_EQ(3U, session_->ReadyPorts().size()); 580 EXPECT_EQ(3U, session_->ReadyPorts().size());
577 EXPECT_EQ(3U, ports_.size()); 581 EXPECT_EQ(3U, ports_.size());
578 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); 582 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
579 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); 583 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
580 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); 584 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
581 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); 585 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
582 586
583 // Now that we remove candidates when a TURN port is pruned, there will be 587 // Now that we remove candidates when a TURN port is pruned, there will be
584 // exactly 3 candidates in both |candidates_| and |ready_candidates|. 588 // exactly 3 candidates in both |candidates_| and |ready_candidates|.
(...skipping 21 matching lines...) Expand all
606 // Have both UDP/TCP and IPv4/IPv6 TURN ports. 610 // Have both UDP/TCP and IPv4/IPv6 TURN ports.
607 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 611 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
608 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); 612 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr);
609 613
610 allocator_->set_step_delay(kMinimumStepDelay); 614 allocator_->set_step_delay(kMinimumStepDelay);
611 allocator_->set_flags(allocator().flags() | 615 allocator_->set_flags(allocator().flags() |
612 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 616 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
613 PORTALLOCATOR_ENABLE_IPV6); 617 PORTALLOCATOR_ENABLE_IPV6);
614 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 618 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
615 session_->StartGettingPorts(); 619 session_->StartGettingPorts();
616 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 620 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
621 kDefaultAllocationTimeout, fake_clock);
617 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to 622 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to
618 // use. 623 // use.
619 EXPECT_EQ(10U, session_->ReadyPorts().size()); 624 EXPECT_EQ(10U, session_->ReadyPorts().size());
620 EXPECT_EQ(10U, ports_.size()); 625 EXPECT_EQ(10U, ports_.size());
621 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); 626 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
622 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); 627 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2));
623 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); 628 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
624 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); 629 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2));
625 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); 630 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr));
626 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); 631 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2));
(...skipping 17 matching lines...) Expand all
644 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); 649 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr);
645 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); 650 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2);
646 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", 651 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp",
647 kClientIPv6Addr); 652 kClientIPv6Addr);
648 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", 653 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp",
649 kClientIPv6Addr2); 654 kClientIPv6Addr2);
650 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", 655 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
651 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 656 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
652 } 657 }
653 658
659 rtc::ScopedFakeClock fake_clock;
654 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 660 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
655 std::unique_ptr<rtc::VirtualSocketServer> vss_; 661 std::unique_ptr<rtc::VirtualSocketServer> vss_;
656 std::unique_ptr<rtc::FirewallSocketServer> fss_; 662 std::unique_ptr<rtc::FirewallSocketServer> fss_;
657 rtc::SocketServerScope ss_scope_; 663 rtc::SocketServerScope ss_scope_;
658 std::unique_ptr<rtc::NATServer> nat_server_; 664 std::unique_ptr<rtc::NATServer> nat_server_;
659 rtc::NATSocketFactory nat_factory_; 665 rtc::NATSocketFactory nat_factory_;
660 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; 666 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_;
661 std::unique_ptr<TestStunServer> stun_server_; 667 std::unique_ptr<TestStunServer> stun_server_;
662 TestRelayServer relay_server_; 668 TestRelayServer relay_server_;
663 TestTurnServer turn_server_; 669 TestTurnServer turn_server_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", 701 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
696 rtc::ADAPTER_TYPE_CELLULAR); 702 rtc::ADAPTER_TYPE_CELLULAR);
697 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", 703 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0",
698 rtc::ADAPTER_TYPE_VPN); 704 rtc::ADAPTER_TYPE_VPN);
699 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", 705 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo",
700 rtc::ADAPTER_TYPE_LOOPBACK); 706 rtc::ADAPTER_TYPE_LOOPBACK);
701 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 707 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
702 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | 708 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY |
703 PORTALLOCATOR_DISABLE_TCP); 709 PORTALLOCATOR_DISABLE_TCP);
704 session_->StartGettingPorts(); 710 session_->StartGettingPorts();
705 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 711 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
712 kDefaultAllocationTimeout, fake_clock);
706 EXPECT_EQ(4U, candidates_.size()); 713 EXPECT_EQ(4U, candidates_.size());
707 for (Candidate candidate : candidates_) { 714 for (Candidate candidate : candidates_) {
708 EXPECT_LT(candidate.address().ip(), 0x12345604U); 715 EXPECT_LT(candidate.address().ip(), 0x12345604U);
709 } 716 }
710 } 717 }
711 718
712 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { 719 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) {
713 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", 720 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0",
714 rtc::ADAPTER_TYPE_ETHERNET); 721 rtc::ADAPTER_TYPE_ETHERNET);
715 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", 722 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0",
716 rtc::ADAPTER_TYPE_WIFI); 723 rtc::ADAPTER_TYPE_WIFI);
717 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", 724 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
718 rtc::ADAPTER_TYPE_CELLULAR); 725 rtc::ADAPTER_TYPE_CELLULAR);
719 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | 726 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET |
720 rtc::ADAPTER_TYPE_LOOPBACK | 727 rtc::ADAPTER_TYPE_LOOPBACK |
721 rtc::ADAPTER_TYPE_WIFI); 728 rtc::ADAPTER_TYPE_WIFI);
722 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 729 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
723 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | 730 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY |
724 PORTALLOCATOR_DISABLE_TCP); 731 PORTALLOCATOR_DISABLE_TCP);
725 session_->StartGettingPorts(); 732 session_->StartGettingPorts();
726 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 733 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
734 kDefaultAllocationTimeout, fake_clock);
727 EXPECT_EQ(1U, candidates_.size()); 735 EXPECT_EQ(1U, candidates_.size());
728 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); 736 EXPECT_EQ(0x12345602U, candidates_[0].address().ip());
729 } 737 }
730 738
731 // Test that high cost networks are filtered if the flag 739 // Test that high cost networks are filtered if the flag
732 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. 740 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set.
733 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { 741 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) {
734 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); 742 SocketAddress addr_wifi(IPAddress(0x12345600U), 0);
735 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); 743 SocketAddress addr_cellular(IPAddress(0x12345601U), 0);
736 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); 744 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0);
737 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); 745 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0);
738 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi 746 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi
739 // interface. 747 // interface.
740 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); 748 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI);
741 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); 749 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
742 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | 750 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
743 cricket::PORTALLOCATOR_DISABLE_RELAY | 751 cricket::PORTALLOCATOR_DISABLE_RELAY |
744 cricket::PORTALLOCATOR_DISABLE_TCP | 752 cricket::PORTALLOCATOR_DISABLE_TCP |
745 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); 753 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
746 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 754 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
747 session_->StartGettingPorts(); 755 session_->StartGettingPorts();
748 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 756 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
757 kDefaultAllocationTimeout, fake_clock);
749 EXPECT_EQ(1U, candidates_.size()); 758 EXPECT_EQ(1U, candidates_.size());
750 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); 759 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address()));
751 760
752 // If both cellular and unknown interfaces are present, only gather on the 761 // If both cellular and unknown interfaces are present, only gather on the
753 // unknown interfaces. 762 // unknown interfaces.
754 candidates_.clear(); 763 candidates_.clear();
755 candidate_allocation_done_ = false; 764 candidate_allocation_done_ = false;
756 RemoveInterface(addr_wifi); 765 RemoveInterface(addr_wifi);
757 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); 766 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN);
758 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); 767 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN);
759 session_->StartGettingPorts(); 768 session_->StartGettingPorts();
760 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 769 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
770 kDefaultAllocationTimeout, fake_clock);
761 EXPECT_EQ(2U, candidates_.size()); 771 EXPECT_EQ(2U, candidates_.size());
762 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && 772 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) &&
763 addr_unknown2.EqualIPs(candidates_[1].address())) || 773 addr_unknown2.EqualIPs(candidates_[1].address())) ||
764 (addr_unknown1.EqualIPs(candidates_[1].address()) && 774 (addr_unknown1.EqualIPs(candidates_[1].address()) &&
765 addr_unknown2.EqualIPs(candidates_[0].address()))); 775 addr_unknown2.EqualIPs(candidates_[0].address())));
766 776
767 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the 777 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the
768 // Wi-Fi interface. 778 // Wi-Fi interface.
769 candidates_.clear(); 779 candidates_.clear();
770 candidate_allocation_done_ = false; 780 candidate_allocation_done_ = false;
771 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); 781 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI);
772 session_->StartGettingPorts(); 782 session_->StartGettingPorts();
773 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 783 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
784 kDefaultAllocationTimeout, fake_clock);
774 EXPECT_EQ(1U, candidates_.size()); 785 EXPECT_EQ(1U, candidates_.size());
775 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); 786 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address()));
776 } 787 }
777 788
778 // Test that we could use loopback interface as host candidate. 789 // Test that we could use loopback interface as host candidate.
779 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { 790 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) {
780 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); 791 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK);
781 allocator_->SetNetworkIgnoreMask(0); 792 allocator_->SetNetworkIgnoreMask(0);
782 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 793 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
783 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | 794 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY |
784 PORTALLOCATOR_DISABLE_TCP); 795 PORTALLOCATOR_DISABLE_TCP);
785 session_->StartGettingPorts(); 796 session_->StartGettingPorts();
786 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 797 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
798 kDefaultAllocationTimeout, fake_clock);
787 EXPECT_EQ(1U, candidates_.size()); 799 EXPECT_EQ(1U, candidates_.size());
788 } 800 }
789 801
790 // Tests that we can get all the desired addresses successfully. 802 // Tests that we can get all the desired addresses successfully.
791 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { 803 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) {
792 AddInterface(kClientAddr); 804 AddInterface(kClientAddr);
793 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 805 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
794 session_->StartGettingPorts(); 806 session_->StartGettingPorts();
795 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 807 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
808 fake_clock);
796 EXPECT_EQ(4U, ports_.size()); 809 EXPECT_EQ(4U, ports_.size());
797 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 810 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
798 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); 811 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr);
799 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 812 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
800 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 813 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
801 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 814 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
802 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 815 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
803 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 816 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
804 kRelaySslTcpIntAddr); 817 kRelaySslTcpIntAddr);
805 EXPECT_TRUE(candidate_allocation_done_); 818 EXPECT_TRUE(candidate_allocation_done_);
806 } 819 }
807 820
808 // Test that when the same network interface is brought down and up, the 821 // Test that when the same network interface is brought down and up, the
809 // port allocator session will restart a new allocation sequence if 822 // port allocator session will restart a new allocation sequence if
810 // it is not stopped. 823 // it is not stopped.
811 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { 824 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) {
812 std::string if_name("test_net0"); 825 std::string if_name("test_net0");
813 AddInterface(kClientAddr, if_name); 826 AddInterface(kClientAddr, if_name);
814 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 827 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
815 session_->StartGettingPorts(); 828 session_->StartGettingPorts();
816 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 829 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
830 fake_clock);
817 EXPECT_EQ(4U, ports_.size()); 831 EXPECT_EQ(4U, ports_.size());
818 EXPECT_TRUE(candidate_allocation_done_); 832 EXPECT_TRUE(candidate_allocation_done_);
819 candidate_allocation_done_ = false; 833 candidate_allocation_done_ = false;
820 candidates_.clear(); 834 candidates_.clear();
821 ports_.clear(); 835 ports_.clear();
822 836
823 RemoveInterface(kClientAddr); 837 RemoveInterface(kClientAddr);
824 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); 838 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout,
839 fake_clock);
825 EXPECT_EQ(0U, ports_.size()); 840 EXPECT_EQ(0U, ports_.size());
826 EXPECT_FALSE(candidate_allocation_done_); 841 EXPECT_FALSE(candidate_allocation_done_);
827 842
828 // When the same interfaces are added again, new candidates/ports should be 843 // When the same interfaces are added again, new candidates/ports should be
829 // generated. 844 // generated.
830 AddInterface(kClientAddr, if_name); 845 AddInterface(kClientAddr, if_name);
831 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 846 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
847 fake_clock);
832 EXPECT_EQ(4U, ports_.size()); 848 EXPECT_EQ(4U, ports_.size());
833 EXPECT_TRUE(candidate_allocation_done_); 849 EXPECT_TRUE(candidate_allocation_done_);
834 } 850 }
835 851
836 // Test that when the same network interface is brought down and up, the 852 // Test that when the same network interface is brought down and up, the
837 // port allocator session will not restart a new allocation sequence if 853 // port allocator session will not restart a new allocation sequence if
838 // it is stopped. 854 // it is stopped.
839 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { 855 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) {
840 std::string if_name("test_net0"); 856 std::string if_name("test_net0");
841 AddInterface(kClientAddr, if_name); 857 AddInterface(kClientAddr, if_name);
842 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 858 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
843 session_->StartGettingPorts(); 859 session_->StartGettingPorts();
844 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 860 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
861 fake_clock);
845 EXPECT_EQ(4U, ports_.size()); 862 EXPECT_EQ(4U, ports_.size());
846 EXPECT_TRUE(candidate_allocation_done_); 863 EXPECT_TRUE(candidate_allocation_done_);
847 session_->StopGettingPorts(); 864 session_->StopGettingPorts();
848 candidates_.clear(); 865 candidates_.clear();
849 ports_.clear(); 866 ports_.clear();
850 867
851 RemoveInterface(kClientAddr); 868 RemoveInterface(kClientAddr);
852 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); 869 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout,
870 fake_clock);
853 EXPECT_EQ(0U, ports_.size()); 871 EXPECT_EQ(0U, ports_.size());
854 872
855 // When the same interfaces are added again, new candidates/ports should not 873 // When the same interfaces are added again, new candidates/ports should not
856 // be generated because the session has stopped. 874 // be generated because the session has stopped.
857 AddInterface(kClientAddr, if_name); 875 AddInterface(kClientAddr, if_name);
858 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); 876 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout,
877 fake_clock);
859 EXPECT_EQ(0U, ports_.size()); 878 EXPECT_EQ(0U, ports_.size());
860 EXPECT_TRUE(candidate_allocation_done_); 879 EXPECT_TRUE(candidate_allocation_done_);
861 } 880 }
862 881
863 // Verify candidates with default step delay of 1sec. 882 // Verify candidates with default step delay of 1sec.
864 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { 883 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) {
865 AddInterface(kClientAddr); 884 AddInterface(kClientAddr);
866 allocator_->set_step_delay(kDefaultStepDelay); 885 allocator_->set_step_delay(kDefaultStepDelay);
867 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 886 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
868 session_->StartGettingPorts(); 887 session_->StartGettingPorts();
869 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 888 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
870 EXPECT_EQ(2U, ports_.size()); 889 EXPECT_EQ(2U, ports_.size());
871 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); 890 ASSERT_EQ_SIMULATED_WAIT(4U, candidates_.size(), 2000, fake_clock);
872 EXPECT_EQ(3U, ports_.size()); 891 EXPECT_EQ(3U, ports_.size());
873 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 892 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
874 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 893 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
875 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); 894 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 1500, fake_clock);
876 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 895 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
877 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 896 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
878 EXPECT_EQ(4U, ports_.size()); 897 EXPECT_EQ(4U, ports_.size());
879 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); 898 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), 2000, fake_clock);
880 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 899 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
881 kRelaySslTcpIntAddr); 900 kRelaySslTcpIntAddr);
882 EXPECT_EQ(4U, ports_.size()); 901 EXPECT_EQ(4U, ports_.size());
883 EXPECT_TRUE(candidate_allocation_done_); 902 EXPECT_TRUE(candidate_allocation_done_);
884 // If we Stop gathering now, we shouldn't get a second "done" callback. 903 // If we Stop gathering now, we shouldn't get a second "done" callback.
885 session_->StopGettingPorts(); 904 session_->StopGettingPorts();
886 } 905 }
887 906
888 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { 907 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) {
889 AddInterface(kClientAddr); 908 AddInterface(kClientAddr);
890 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); 909 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO));
891 session_->StartGettingPorts(); 910 session_->StartGettingPorts();
892 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 911 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
912 fake_clock);
893 EXPECT_TRUE(candidate_allocation_done_); 913 EXPECT_TRUE(candidate_allocation_done_);
894 // If we Stop gathering now, we shouldn't get a second "done" callback. 914 // If we Stop gathering now, we shouldn't get a second "done" callback.
895 session_->StopGettingPorts(); 915 session_->StopGettingPorts();
896 916
897 // All ports should have unset send-buffer sizes. 917 // All ports should have unset send-buffer sizes.
898 CheckSendBufferSizesOfAllPorts(-1); 918 CheckSendBufferSizesOfAllPorts(-1);
899 } 919 }
900 920
901 // Tests that we can get callback after StopGetAllPorts. 921 // Tests that we can get callback after StopGetAllPorts.
902 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { 922 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) {
(...skipping 12 matching lines...) Expand all
915 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { 935 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) {
916 AddInterface(kClientAddr); 936 AddInterface(kClientAddr);
917 // Check that an invalid port range fails. 937 // Check that an invalid port range fails.
918 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); 938 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort));
919 // Check that a null port range succeeds. 939 // Check that a null port range succeeds.
920 EXPECT_TRUE(SetPortRange(0, 0)); 940 EXPECT_TRUE(SetPortRange(0, 0));
921 // Check that a valid port range succeeds. 941 // Check that a valid port range succeeds.
922 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); 942 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort));
923 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 943 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
924 session_->StartGettingPorts(); 944 session_->StartGettingPorts();
925 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 945 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
946 fake_clock);
926 EXPECT_EQ(4U, ports_.size()); 947 EXPECT_EQ(4U, ports_.size());
927 948
928 int num_nonrelay_candidates = 0; 949 int num_nonrelay_candidates = 0;
929 for (const Candidate& candidate : candidates_) { 950 for (const Candidate& candidate : candidates_) {
930 // Check the port number for the UDP/STUN/TCP port objects. 951 // Check the port number for the UDP/STUN/TCP port objects.
931 if (candidate.type() != RELAY_PORT_TYPE) { 952 if (candidate.type() != RELAY_PORT_TYPE) {
932 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); 953 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort);
933 ++num_nonrelay_candidates; 954 ++num_nonrelay_candidates;
934 } 955 }
935 } 956 }
(...skipping 12 matching lines...) Expand all
948 ResetWithStunServerAndNat(kStunAddr); 969 ResetWithStunServerAndNat(kStunAddr);
949 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 970 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
950 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 971 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
951 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); 972 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr);
952 // Disable IPv6, because our test infrastructure doesn't support having IPv4 973 // Disable IPv6, because our test infrastructure doesn't support having IPv4
953 // behind a NAT but IPv6 not, or having an IPv6 NAT. 974 // behind a NAT but IPv6 not, or having an IPv6 NAT.
954 // TODO(deadbeef): Fix this. 975 // TODO(deadbeef): Fix this.
955 network_manager_.set_ipv6_enabled(false); 976 network_manager_.set_ipv6_enabled(false);
956 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 977 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
957 session_->StartGettingPorts(); 978 session_->StartGettingPorts();
958 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 979 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
980 kDefaultAllocationTimeout, fake_clock);
959 EXPECT_EQ(4U, ports_.size()); 981 EXPECT_EQ(4U, ports_.size());
960 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr)); 982 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr));
961 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr)); 983 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr));
962 // Two TURN ports, using UDP/TCP for the first hop to the TURN server. 984 // Two TURN ports, using UDP/TCP for the first hop to the TURN server.
963 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr)); 985 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr));
964 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr)); 986 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr));
965 // The "any" address port should be in the signaled ready ports, but the host 987 // The "any" address port should be in the signaled ready ports, but the host
966 // candidate for it is useless and shouldn't be signaled. So we only have 988 // candidate for it is useless and shouldn't be signaled. So we only have
967 // STUN/TURN candidates. 989 // STUN/TURN candidates.
968 EXPECT_EQ(3U, candidates_.size()); 990 EXPECT_EQ(3U, candidates_.size());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1107 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1086 AddInterface(kClientAddr); 1108 AddInterface(kClientAddr);
1087 ResetWithStunServerAndNat(kStunAddr); 1109 ResetWithStunServerAndNat(kStunAddr);
1088 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 1110 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1089 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1111 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1090 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | 1112 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY |
1091 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | 1113 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN |
1092 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1114 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1093 1115
1094 session_->StartGettingPorts(); 1116 session_->StartGettingPorts();
1095 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1117 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1118 kDefaultAllocationTimeout, fake_clock);
1096 1119
1097 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and 1120 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and
1098 // TURN/TCP candidates. 1121 // TURN/TCP candidates.
1099 EXPECT_EQ(2U, ports_.size()); 1122 EXPECT_EQ(2U, ports_.size());
1100 EXPECT_EQ(2U, candidates_.size()); 1123 EXPECT_EQ(2U, candidates_.size());
1101 Candidate turn_candidate; 1124 Candidate turn_candidate;
1102 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr, 1125 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr,
1103 &turn_candidate); 1126 &turn_candidate);
1104 // The TURN candidate should use TCP to contact the TURN server. 1127 // The TURN candidate should use TCP to contact the TURN server.
1105 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol()); 1128 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol());
1106 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1129 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1107 } 1130 }
1108 1131
1109 // Disable for asan, see 1132 // Disable for asan, see
1110 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 1133 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
1111 #if !defined(ADDRESS_SANITIZER) 1134 #if !defined(ADDRESS_SANITIZER)
1112 1135
1113 // Test that we can get OnCandidatesAllocationDone callback when all the ports 1136 // Test that we can get OnCandidatesAllocationDone callback when all the ports
1114 // are disabled. 1137 // are disabled.
1115 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { 1138 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) {
1116 AddInterface(kClientAddr); 1139 AddInterface(kClientAddr);
1117 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1140 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1118 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | 1141 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN |
1119 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); 1142 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP);
1120 session_->StartGettingPorts(); 1143 session_->StartGettingPorts();
1121 rtc::Thread::Current()->ProcessMessages(100); 1144 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock);
1122 EXPECT_EQ(0U, candidates_.size()); 1145 EXPECT_EQ(0U, candidates_.size());
1123 EXPECT_TRUE(candidate_allocation_done_); 1146 EXPECT_TRUE(candidate_allocation_done_);
Taylor Brandstetter 2017/02/08 01:23:59 Don't need this additional EXPECT_TRUE
1124 } 1147 }
1125 1148
1126 // Test that we don't crash or malfunction if we can't create UDP sockets. 1149 // Test that we don't crash or malfunction if we can't create UDP sockets.
1127 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { 1150 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) {
1128 AddInterface(kClientAddr); 1151 AddInterface(kClientAddr);
1129 fss_->set_udp_sockets_enabled(false); 1152 fss_->set_udp_sockets_enabled(false);
1130 EXPECT_TRUE(CreateSession(1)); 1153 EXPECT_TRUE(CreateSession(1));
1131 session_->StartGettingPorts(); 1154 session_->StartGettingPorts();
1132 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); 1155 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout,
1156 fake_clock);
1133 EXPECT_EQ(2U, ports_.size()); 1157 EXPECT_EQ(2U, ports_.size());
1134 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 1158 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
1135 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 1159 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
1136 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 1160 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
1137 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1161 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1138 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 1162 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
1139 kRelaySslTcpIntAddr); 1163 kRelaySslTcpIntAddr);
1140 EXPECT_TRUE(candidate_allocation_done_); 1164 EXPECT_TRUE(candidate_allocation_done_);
1141 } 1165 }
1142 1166
1143 #endif // if !defined(ADDRESS_SANITIZER) 1167 #endif // if !defined(ADDRESS_SANITIZER)
1144 1168
1145 // Test that we don't crash or malfunction if we can't create UDP sockets or 1169 // Test that we don't crash or malfunction if we can't create UDP sockets or
1146 // listen on TCP sockets. We still give out a local TCP address, since 1170 // listen on TCP sockets. We still give out a local TCP address, since
1147 // apparently this is needed for the remote side to accept our connection. 1171 // apparently this is needed for the remote side to accept our connection.
1148 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { 1172 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) {
1149 AddInterface(kClientAddr); 1173 AddInterface(kClientAddr);
1150 fss_->set_udp_sockets_enabled(false); 1174 fss_->set_udp_sockets_enabled(false);
1151 fss_->set_tcp_listen_enabled(false); 1175 fss_->set_tcp_listen_enabled(false);
1152 EXPECT_TRUE(CreateSession(1)); 1176 EXPECT_TRUE(CreateSession(1));
1153 session_->StartGettingPorts(); 1177 session_->StartGettingPorts();
1154 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); 1178 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout,
1179 fake_clock);
1155 EXPECT_EQ(2U, ports_.size()); 1180 EXPECT_EQ(2U, ports_.size());
1156 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 1181 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
1157 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 1182 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
1158 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 1183 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
1159 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1184 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1160 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 1185 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
1161 kRelaySslTcpIntAddr); 1186 kRelaySslTcpIntAddr);
1162 EXPECT_TRUE(candidate_allocation_done_); 1187 EXPECT_TRUE(candidate_allocation_done_);
1163 } 1188 }
1164 1189
(...skipping 10 matching lines...) Expand all
1175 // In case of Relay, ports creation will succeed but sockets will fail. 1200 // In case of Relay, ports creation will succeed but sockets will fail.
1176 // There is no error reporting from RelayEntry to handle this failure. 1201 // There is no error reporting from RelayEntry to handle this failure.
1177 } 1202 }
1178 1203
1179 // Testing STUN timeout. 1204 // Testing STUN timeout.
1180 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { 1205 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) {
1181 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1206 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1182 AddInterface(kClientAddr); 1207 AddInterface(kClientAddr);
1183 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1208 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1184 session_->StartGettingPorts(); 1209 session_->StartGettingPorts();
1185 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 1210 EXPECT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout,
1211 fake_clock);
1186 EXPECT_EQ(2U, ports_.size()); 1212 EXPECT_EQ(2U, ports_.size());
1187 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1213 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1188 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1214 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1189 // RelayPort connection timeout is 3sec. TCP connection with RelayServer 1215 // RelayPort connection timeout is 3sec. TCP connection with RelayServer
1190 // will be tried after 3 seconds. 1216 // will be tried after about 3 seconds.
1191 // TODO(deadbeef): Use simulated clock here, waiting for exactly 3 seconds. 1217 EXPECT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 3500, fake_clock);
1192 EXPECT_EQ_WAIT(6U, candidates_.size(), kStunTimeoutMs);
1193 EXPECT_EQ(3U, ports_.size()); 1218 EXPECT_EQ(3U, ports_.size());
1194 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 1219 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
1195 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 1220 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
1196 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 1221 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
1197 kRelaySslTcpIntAddr); 1222 kRelaySslTcpIntAddr);
1198 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 1223 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
1199 // Stun Timeout is 9.5sec. 1224 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 6500, fake_clock);
Taylor Brandstetter 2017/02/08 01:23:59 Does this pass? I think my comment about 6.5 secon
pthatcher1 2017/02/08 08:52:24 Yes, it passes. I added a comment explaining why
1200 // TODO(deadbeef): Use simulated clock here, waiting exactly 6.5 seconds.
1201 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs);
1202 } 1225 }
1203 1226
1204 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { 1227 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) {
1205 AddInterface(kClientAddr); 1228 AddInterface(kClientAddr);
1206 AddInterface(kClientAddr2); 1229 AddInterface(kClientAddr2);
1207 // Allocating only host UDP ports. This is done purely for testing 1230 // Allocating only host UDP ports. This is done purely for testing
1208 // convenience. 1231 // convenience.
1209 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | 1232 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN |
1210 PORTALLOCATOR_DISABLE_RELAY); 1233 PORTALLOCATOR_DISABLE_RELAY);
1211 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1234 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1212 session_->StartGettingPorts(); 1235 session_->StartGettingPorts();
1213 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1236 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1237 kDefaultAllocationTimeout, fake_clock);
1214 ASSERT_EQ(2U, candidates_.size()); 1238 ASSERT_EQ(2U, candidates_.size());
1215 EXPECT_EQ(2U, ports_.size()); 1239 EXPECT_EQ(2U, ports_.size());
1216 // Candidates priorities should be different. 1240 // Candidates priorities should be different.
1217 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); 1241 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority());
1218 } 1242 }
1219 1243
1220 // Test to verify ICE restart process. 1244 // Test to verify ICE restart process.
1221 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { 1245 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) {
1222 AddInterface(kClientAddr); 1246 AddInterface(kClientAddr);
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1247 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1224 session_->StartGettingPorts(); 1248 session_->StartGettingPorts();
1225 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1249 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
1250 fake_clock);
1226 EXPECT_EQ(4U, ports_.size()); 1251 EXPECT_EQ(4U, ports_.size());
1227 EXPECT_TRUE(candidate_allocation_done_); 1252 EXPECT_TRUE(candidate_allocation_done_);
1228 // TODO(deadbeef): Extend this to verify ICE restart. 1253 // TODO(deadbeef): Extend this to verify ICE restart.
1229 } 1254 }
1230 1255
1231 // Test that the allocator session uses the candidate filter it's created with, 1256 // Test that the allocator session uses the candidate filter it's created with,
1232 // rather than the filter of its parent allocator. 1257 // rather than the filter of its parent allocator.
1233 // The filter of the allocator should only affect the next gathering phase, 1258 // The filter of the allocator should only affect the next gathering phase,
1234 // according to JSEP, which means the *next* allocator session returned. 1259 // according to JSEP, which means the *next* allocator session returned.
1235 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { 1260 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) {
1236 AddInterface(kClientAddr); 1261 AddInterface(kClientAddr);
1237 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1262 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1238 // Set candidate filter *after* creating the session. Should have no effect. 1263 // Set candidate filter *after* creating the session. Should have no effect.
1239 allocator().set_candidate_filter(CF_RELAY); 1264 allocator().set_candidate_filter(CF_RELAY);
1240 session_->StartGettingPorts(); 1265 session_->StartGettingPorts();
1241 // 7 candidates and 4 ports is what we would normally get (see the 1266 // 7 candidates and 4 ports is what we would normally get (see the
1242 // TestGetAllPorts* tests). 1267 // TestGetAllPorts* tests).
1243 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1268 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
1269 fake_clock);
1244 EXPECT_EQ(4U, ports_.size()); 1270 EXPECT_EQ(4U, ports_.size());
1245 EXPECT_TRUE(candidate_allocation_done_); 1271 EXPECT_TRUE(candidate_allocation_done_);
1246 } 1272 }
1247 1273
1248 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. 1274 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive.
1249 // This test also verifies that when the allocator is only allowed to use 1275 // This test also verifies that when the allocator is only allowed to use
1250 // relay (i.e. IceTransportsType is relay), the raddr is an empty 1276 // relay (i.e. IceTransportsType is relay), the raddr is an empty
1251 // address with the correct family. This is to prevent any local 1277 // address with the correct family. This is to prevent any local
1252 // reflective address leakage in the sdp line. 1278 // reflective address leakage in the sdp line.
1253 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { 1279 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) {
1254 AddInterface(kClientAddr); 1280 AddInterface(kClientAddr);
1255 // GTURN is not configured here. 1281 // GTURN is not configured here.
1256 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); 1282 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress());
1257 allocator().set_candidate_filter(CF_RELAY); 1283 allocator().set_candidate_filter(CF_RELAY);
1258 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1284 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1259 session_->StartGettingPorts(); 1285 session_->StartGettingPorts();
1260 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1286 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1287 kDefaultAllocationTimeout, fake_clock);
1261 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1288 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1262 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1289 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1263 1290
1264 EXPECT_EQ(1U, candidates_.size()); 1291 EXPECT_EQ(1U, candidates_.size());
1265 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. 1292 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state.
1266 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); 1293 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type());
1267 EXPECT_EQ( 1294 EXPECT_EQ(
1268 candidates_[0].related_address(), 1295 candidates_[0].related_address(),
1269 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 1296 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
1270 } 1297 }
1271 1298
1272 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { 1299 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) {
1273 AddInterface(kClientAddr); 1300 AddInterface(kClientAddr);
1274 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1301 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1275 allocator().set_candidate_filter(CF_HOST); 1302 allocator().set_candidate_filter(CF_HOST);
1276 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1303 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1277 session_->StartGettingPorts(); 1304 session_->StartGettingPorts();
1278 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1305 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1306 kDefaultAllocationTimeout, fake_clock);
1279 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. 1307 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
1280 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. 1308 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
1281 for (const Candidate& candidate : candidates_) { 1309 for (const Candidate& candidate : candidates_) {
1282 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); 1310 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type());
1283 } 1311 }
1284 } 1312 }
1285 1313
1286 // Host is behind the NAT. 1314 // Host is behind the NAT.
1287 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { 1315 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
1288 AddInterface(kPrivateAddr); 1316 AddInterface(kPrivateAddr);
1289 ResetWithStunServerAndNat(kStunAddr); 1317 ResetWithStunServerAndNat(kStunAddr);
1290 1318
1291 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1319 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1292 allocator().set_candidate_filter(CF_REFLEXIVE); 1320 allocator().set_candidate_filter(CF_REFLEXIVE);
1293 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1321 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1294 session_->StartGettingPorts(); 1322 session_->StartGettingPorts();
1295 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1323 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1324 kDefaultAllocationTimeout, fake_clock);
1296 // Host is behind NAT, no private address will be exposed. Hence only UDP 1325 // Host is behind NAT, no private address will be exposed. Hence only UDP
1297 // port with STUN candidate will be sent outside. 1326 // port with STUN candidate will be sent outside.
1298 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. 1327 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
1299 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. 1328 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state.
1300 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); 1329 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type());
1301 EXPECT_EQ( 1330 EXPECT_EQ(
1302 candidates_[0].related_address(), 1331 candidates_[0].related_address(),
1303 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 1332 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
1304 } 1333 }
1305 1334
1306 // Host is not behind the NAT. 1335 // Host is not behind the NAT.
1307 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { 1336 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) {
1308 AddInterface(kClientAddr); 1337 AddInterface(kClientAddr);
1309 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1338 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1310 allocator().set_candidate_filter(CF_REFLEXIVE); 1339 allocator().set_candidate_filter(CF_REFLEXIVE);
1311 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1340 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1312 session_->StartGettingPorts(); 1341 session_->StartGettingPorts();
1313 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1342 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1343 kDefaultAllocationTimeout, fake_clock);
1314 // Host has a public address, both UDP and TCP candidates will be exposed. 1344 // Host has a public address, both UDP and TCP candidates will be exposed.
1315 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. 1345 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate.
1316 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. 1346 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state.
1317 for (const Candidate& candidate : candidates_) { 1347 for (const Candidate& candidate : candidates_) {
1318 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); 1348 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type());
1319 } 1349 }
1320 } 1350 }
1321 1351
1322 // Test that we get the same ufrag and pwd for all candidates. 1352 // Test that we get the same ufrag and pwd for all candidates.
1323 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { 1353 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) {
1324 AddInterface(kClientAddr); 1354 AddInterface(kClientAddr);
1325 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1355 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1326 session_->StartGettingPorts(); 1356 session_->StartGettingPorts();
1327 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1357 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout,
1358 fake_clock);
1328 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1359 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1329 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); 1360 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr);
1330 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1361 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1331 EXPECT_EQ(4U, ports_.size()); 1362 EXPECT_EQ(4U, ports_.size());
1332 for (const Candidate& candidate : candidates_) { 1363 for (const Candidate& candidate : candidates_) {
1333 EXPECT_EQ(kIceUfrag0, candidate.username()); 1364 EXPECT_EQ(kIceUfrag0, candidate.username());
1334 EXPECT_EQ(kIcePwd0, candidate.password()); 1365 EXPECT_EQ(kIcePwd0, candidate.password());
1335 } 1366 }
1336 EXPECT_TRUE(candidate_allocation_done_); 1367 EXPECT_TRUE(candidate_allocation_done_);
1337 } 1368 }
1338 1369
1339 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1370 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1340 // is allocated for udp and stun. Also verify there is only one candidate 1371 // is allocated for udp and stun. Also verify there is only one candidate
1341 // (local) if stun candidate is same as local candidate, which will be the case 1372 // (local) if stun candidate is same as local candidate, which will be the case
1342 // in a public network like the below test. 1373 // in a public network like the below test.
1343 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { 1374 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) {
1344 AddInterface(kClientAddr); 1375 AddInterface(kClientAddr);
1345 allocator_->set_flags(allocator().flags() | 1376 allocator_->set_flags(allocator().flags() |
1346 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1377 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1347 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1378 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1348 session_->StartGettingPorts(); 1379 session_->StartGettingPorts();
1349 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); 1380 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout,
1381 fake_clock);
1350 EXPECT_EQ(3U, ports_.size()); 1382 EXPECT_EQ(3U, ports_.size());
1351 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1383 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1352 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1384 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1385 kDefaultAllocationTimeout, fake_clock);
1353 } 1386 }
1354 1387
1355 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1388 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1356 // is allocated for udp and stun. In this test we should expect both stun and 1389 // is allocated for udp and stun. In this test we should expect both stun and
1357 // local candidates as client behind a nat. 1390 // local candidates as client behind a nat.
1358 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { 1391 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) {
1359 AddInterface(kClientAddr); 1392 AddInterface(kClientAddr);
1360 ResetWithStunServerAndNat(kStunAddr); 1393 ResetWithStunServerAndNat(kStunAddr);
1361 1394
1362 allocator_->set_flags(allocator().flags() | 1395 allocator_->set_flags(allocator().flags() |
1363 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1396 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1364 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1397 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1365 session_->StartGettingPorts(); 1398 session_->StartGettingPorts();
1366 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1399 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1400 fake_clock);
1367 ASSERT_EQ(2U, ports_.size()); 1401 ASSERT_EQ(2U, ports_.size());
1368 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1402 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1369 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", 1403 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp",
1370 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1404 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1371 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1405 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1406 kDefaultAllocationTimeout, fake_clock);
1372 EXPECT_EQ(3U, candidates_.size()); 1407 EXPECT_EQ(3U, candidates_.size());
1373 } 1408 }
1374 1409
1375 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. 1410 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
1376 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 1411 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
1377 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1412 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1378 AddInterface(kClientAddr); 1413 AddInterface(kClientAddr);
1379 allocator_.reset(new BasicPortAllocator(&network_manager_)); 1414 allocator_.reset(new BasicPortAllocator(&network_manager_));
1380 1415
1381 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 1416 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1382 1417
1383 allocator_->set_step_delay(kMinimumStepDelay); 1418 allocator_->set_step_delay(kMinimumStepDelay);
1384 allocator_->set_flags(allocator().flags() | 1419 allocator_->set_flags(allocator().flags() |
1385 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1420 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1386 PORTALLOCATOR_DISABLE_TCP); 1421 PORTALLOCATOR_DISABLE_TCP);
1387 1422
1388 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1423 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1389 session_->StartGettingPorts(); 1424 session_->StartGettingPorts();
1390 1425
1391 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1426 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1427 fake_clock);
1392 ASSERT_EQ(3U, ports_.size()); 1428 ASSERT_EQ(3U, ports_.size());
1393 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1429 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1394 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1430 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1395 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1431 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1396 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1432 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1397 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1433 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1398 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1434 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1435 kDefaultAllocationTimeout, fake_clock);
1399 EXPECT_EQ(3U, candidates_.size()); 1436 EXPECT_EQ(3U, candidates_.size());
1400 } 1437 }
1401 1438
1402 // Test that if prune_turn_ports is set, TCP TURN port will not be used 1439 // Test that if prune_turn_ports is set, TCP TURN port will not be used
1403 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. 1440 // if UDP TurnPort is used, given that TCP TURN port becomes ready first.
1404 TEST_F(BasicPortAllocatorTest, 1441 TEST_F(BasicPortAllocatorTest,
1405 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { 1442 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) {
1406 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. 1443 // UDP has longer delay than TCP so that TCP TURN port becomes ready first.
1407 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); 1444 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200);
1408 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); 1445 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 allocator_->AddTurnServer(turn_server); 1519 allocator_->AddTurnServer(turn_server);
1483 1520
1484 allocator_->set_step_delay(kMinimumStepDelay); 1521 allocator_->set_step_delay(kMinimumStepDelay);
1485 allocator_->set_flags(allocator().flags() | 1522 allocator_->set_flags(allocator().flags() |
1486 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1523 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1487 PORTALLOCATOR_DISABLE_TCP); 1524 PORTALLOCATOR_DISABLE_TCP);
1488 1525
1489 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1526 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1490 session_->StartGettingPorts(); 1527 session_->StartGettingPorts();
1491 1528
1492 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); 1529 EXPECT_EQ_SIMULATED_WAIT(2U, ports_.size(), kDefaultAllocationTimeout,
1530 fake_clock);
1493 } 1531 }
1494 1532
1495 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1533 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1496 // is allocated for udp/stun/turn. In this test we should expect all local, 1534 // is allocated for udp/stun/turn. In this test we should expect all local,
1497 // stun and turn candidates. 1535 // stun and turn candidates.
1498 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { 1536 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) {
1499 AddInterface(kClientAddr); 1537 AddInterface(kClientAddr);
1500 ResetWithStunServerAndNat(kStunAddr); 1538 ResetWithStunServerAndNat(kStunAddr);
1501 1539
1502 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1540 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1503 1541
1504 allocator_->set_flags(allocator().flags() | 1542 allocator_->set_flags(allocator().flags() |
1505 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1543 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1506 PORTALLOCATOR_DISABLE_TCP); 1544 PORTALLOCATOR_DISABLE_TCP);
1507 1545
1508 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1546 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1509 session_->StartGettingPorts(); 1547 session_->StartGettingPorts();
1510 1548
1511 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1549 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1550 fake_clock);
1512 ASSERT_EQ(2U, ports_.size()); 1551 ASSERT_EQ(2U, ports_.size());
1513 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1552 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1514 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", 1553 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp",
1515 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1554 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1516 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1555 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1517 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1556 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1518 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1557 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1558 kDefaultAllocationTimeout, fake_clock);
1519 EXPECT_EQ(3U, candidates_.size()); 1559 EXPECT_EQ(3U, candidates_.size());
1520 // Local port will be created first and then TURN port. 1560 // Local port will be created first and then TURN port.
1521 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1561 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1522 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1562 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1523 } 1563 }
1524 1564
1525 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN 1565 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN
1526 // server is also used as the STUN server, we should get 'local', 'stun', and 1566 // server is also used as the STUN server, we should get 'local', 'stun', and
1527 // 'relay' candidates. 1567 // 'relay' candidates.
1528 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { 1568 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) {
1529 AddInterface(kClientAddr); 1569 AddInterface(kClientAddr);
1530 // Use an empty SocketAddress to add a NAT without STUN server. 1570 // Use an empty SocketAddress to add a NAT without STUN server.
1531 ResetWithStunServerAndNat(SocketAddress()); 1571 ResetWithStunServerAndNat(SocketAddress());
1532 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1572 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1533 1573
1534 // Must set the step delay to 0 to make sure the relay allocation phase is 1574 // Must set the step delay to 0 to make sure the relay allocation phase is
1535 // started before the STUN candidates are obtained, so that the STUN binding 1575 // started before the STUN candidates are obtained, so that the STUN binding
1536 // response is processed when both StunPort and TurnPort exist to reproduce 1576 // response is processed when both StunPort and TurnPort exist to reproduce
1537 // webrtc issue 3537. 1577 // webrtc issue 3537.
1538 allocator_->set_step_delay(0); 1578 allocator_->set_step_delay(0);
1539 allocator_->set_flags(allocator().flags() | 1579 allocator_->set_flags(allocator().flags() |
1540 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1580 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1541 PORTALLOCATOR_DISABLE_TCP); 1581 PORTALLOCATOR_DISABLE_TCP);
1542 1582
1543 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1583 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1544 session_->StartGettingPorts(); 1584 session_->StartGettingPorts();
1545 1585
1546 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1586 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1587 fake_clock);
1547 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1588 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1548 Candidate stun_candidate; 1589 Candidate stun_candidate;
1549 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", 1590 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp",
1550 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); 1591 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1551 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", 1592 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp",
1552 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), 1593 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1553 stun_candidate.address()); 1594 stun_candidate.address());
1554 1595
1555 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1596 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1597 kDefaultAllocationTimeout, fake_clock);
1556 EXPECT_EQ(3U, candidates_.size()); 1598 EXPECT_EQ(3U, candidates_.size());
1557 // Local port will be created first and then TURN port. 1599 // Local port will be created first and then TURN port.
1558 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1600 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1559 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1601 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1560 } 1602 }
1561 1603
1562 // Test that when only a TCP TURN server is available, we do NOT use it as 1604 // Test that when only a TCP TURN server is available, we do NOT use it as
1563 // a UDP STUN server, as this could leak our IP address. Thus we should only 1605 // a UDP STUN server, as this could leak our IP address. Thus we should only
1564 // expect two ports, a UDPPort and TurnPort. 1606 // expect two ports, a UDPPort and TurnPort.
1565 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 1607 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
1566 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1608 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1567 AddInterface(kClientAddr); 1609 AddInterface(kClientAddr);
1568 ResetWithStunServerAndNat(rtc::SocketAddress()); 1610 ResetWithStunServerAndNat(rtc::SocketAddress());
1569 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 1611 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
1570 1612
1571 allocator_->set_flags(allocator().flags() | 1613 allocator_->set_flags(allocator().flags() |
1572 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1614 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1573 PORTALLOCATOR_DISABLE_TCP); 1615 PORTALLOCATOR_DISABLE_TCP);
1574 1616
1575 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1617 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1576 session_->StartGettingPorts(); 1618 session_->StartGettingPorts();
1577 1619
1578 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 1620 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout,
1621 fake_clock);
1579 ASSERT_EQ(2U, ports_.size()); 1622 ASSERT_EQ(2U, ports_.size());
1580 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1623 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1581 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1624 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1582 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1625 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1583 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1626 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1627 kDefaultAllocationTimeout, fake_clock);
1584 EXPECT_EQ(2U, candidates_.size()); 1628 EXPECT_EQ(2U, candidates_.size());
1585 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1629 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1586 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1630 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1587 } 1631 }
1588 1632
1589 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the 1633 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
1590 // TURN server is used as the STUN server and we get 'local', 'stun', and 1634 // TURN server is used as the STUN server and we get 'local', 'stun', and
1591 // 'relay' candidates. 1635 // 'relay' candidates.
1592 // TODO(deadbeef): Remove this test when support for non-shared socket mode 1636 // TODO(deadbeef): Remove this test when support for non-shared socket mode
1593 // is removed. 1637 // is removed.
1594 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 1638 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
1595 AddInterface(kClientAddr); 1639 AddInterface(kClientAddr);
1596 // Use an empty SocketAddress to add a NAT without STUN server. 1640 // Use an empty SocketAddress to add a NAT without STUN server.
1597 ResetWithStunServerAndNat(SocketAddress()); 1641 ResetWithStunServerAndNat(SocketAddress());
1598 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1642 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1599 1643
1600 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); 1644 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP);
1601 1645
1602 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1646 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1603 session_->StartGettingPorts(); 1647 session_->StartGettingPorts();
1604 1648
1605 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1649 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1650 fake_clock);
1606 ASSERT_EQ(3U, ports_.size()); 1651 ASSERT_EQ(3U, ports_.size());
1607 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1652 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1608 Candidate stun_candidate; 1653 Candidate stun_candidate;
1609 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", 1654 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp",
1610 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); 1655 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1611 Candidate turn_candidate; 1656 Candidate turn_candidate;
1612 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", 1657 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp",
1613 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), 1658 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1614 &turn_candidate); 1659 &turn_candidate);
1615 // Not using shared socket, so the STUN request's server reflexive address 1660 // Not using shared socket, so the STUN request's server reflexive address
1616 // should be different than the TURN request's server reflexive address. 1661 // should be different than the TURN request's server reflexive address.
1617 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); 1662 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address());
1618 1663
1619 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1664 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1665 kDefaultAllocationTimeout, fake_clock);
1620 EXPECT_EQ(3U, candidates_.size()); 1666 EXPECT_EQ(3U, candidates_.size());
1621 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1667 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1622 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1668 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1623 EXPECT_EQ(1U, ports_[2]->Candidates().size()); 1669 EXPECT_EQ(1U, ports_[2]->Candidates().size());
1624 } 1670 }
1625 1671
1626 // Test that even when both a STUN and TURN server are configured, the TURN 1672 // Test that even when both a STUN and TURN server are configured, the TURN
1627 // server is used as a STUN server and we get a 'stun' candidate. 1673 // server is used as a STUN server and we get a 'stun' candidate.
1628 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 1674 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
1629 AddInterface(kClientAddr); 1675 AddInterface(kClientAddr);
1630 // Configure with STUN server but destroy it, so we can ensure that it's 1676 // Configure with STUN server but destroy it, so we can ensure that it's
1631 // the TURN server actually being used as a STUN server. 1677 // the TURN server actually being used as a STUN server.
1632 ResetWithStunServerAndNat(kStunAddr); 1678 ResetWithStunServerAndNat(kStunAddr);
1633 stun_server_.reset(); 1679 stun_server_.reset();
1634 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1680 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1635 1681
1636 allocator_->set_flags(allocator().flags() | 1682 allocator_->set_flags(allocator().flags() |
1637 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1683 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1638 PORTALLOCATOR_DISABLE_TCP); 1684 PORTALLOCATOR_DISABLE_TCP);
1639 1685
1640 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1686 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1641 session_->StartGettingPorts(); 1687 session_->StartGettingPorts();
1642 1688
1643 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1689 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout,
1690 fake_clock);
1644 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1691 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1645 Candidate stun_candidate; 1692 Candidate stun_candidate;
1646 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", 1693 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp",
1647 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); 1694 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1648 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", 1695 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp",
1649 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), 1696 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1650 stun_candidate.address()); 1697 stun_candidate.address());
1651 1698
1652 // Don't bother waiting for STUN timeout, since we already verified 1699 // Don't bother waiting for STUN timeout, since we already verified
1653 // that we got a STUN candidate from the TURN server. 1700 // that we got a STUN candidate from the TURN server.
1654 } 1701 }
1655 1702
1656 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1703 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
1657 // and fail to generate STUN candidate, local UDP candidate is generated 1704 // and fail to generate STUN candidate, local UDP candidate is generated
1658 // properly. 1705 // properly.
1659 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1706 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) {
1660 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1707 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1661 PORTALLOCATOR_DISABLE_TCP | 1708 PORTALLOCATOR_DISABLE_TCP |
1662 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1709 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1663 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1710 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1664 AddInterface(kClientAddr); 1711 AddInterface(kClientAddr);
1665 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1712 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1666 session_->StartGettingPorts(); 1713 session_->StartGettingPorts();
1667 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1714 ASSERT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout,
1715 fake_clock);
1668 EXPECT_EQ(1U, candidates_.size()); 1716 EXPECT_EQ(1U, candidates_.size());
1669 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1717 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1670 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. 1718 // STUN timeout is 9.5sec. We need to wait to get candidate done signal.
1671 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); 1719 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, kStunTimeoutMs,
1720 fake_clock);
1672 EXPECT_EQ(1U, candidates_.size()); 1721 EXPECT_EQ(1U, candidates_.size());
1673 } 1722 }
1674 1723
1675 // Test that when the NetworkManager doesn't have permission to enumerate 1724 // Test that when the NetworkManager doesn't have permission to enumerate
1676 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified 1725 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified
1677 // automatically. 1726 // automatically.
1678 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { 1727 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) {
1679 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), 1728 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(),
1680 rtc::IPAddress()); 1729 rtc::IPAddress());
1681 network_manager_.set_enumeration_permission( 1730 network_manager_.set_enumeration_permission(
1682 rtc::NetworkManager::ENUMERATION_BLOCKED); 1731 rtc::NetworkManager::ENUMERATION_BLOCKED);
1683 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1732 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1684 PORTALLOCATOR_DISABLE_TCP | 1733 PORTALLOCATOR_DISABLE_TCP |
1685 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1734 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1686 EXPECT_EQ(0U, 1735 EXPECT_EQ(0U,
1687 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1736 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1688 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1737 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1689 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1738 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1690 session_->StartGettingPorts(); 1739 session_->StartGettingPorts();
1691 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1740 EXPECT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout,
1741 fake_clock);
1692 EXPECT_EQ(1U, candidates_.size()); 1742 EXPECT_EQ(1U, candidates_.size());
1693 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr); 1743 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr);
1694 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1744 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1695 } 1745 }
1696 1746
1697 // This test verifies allocator can use IPv6 addresses along with IPv4. 1747 // This test verifies allocator can use IPv6 addresses along with IPv4.
1698 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { 1748 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) {
1699 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1749 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1700 PORTALLOCATOR_ENABLE_IPV6 | 1750 PORTALLOCATOR_ENABLE_IPV6 |
1701 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1751 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1702 AddInterface(kClientIPv6Addr); 1752 AddInterface(kClientIPv6Addr);
1703 AddInterface(kClientAddr); 1753 AddInterface(kClientAddr);
1704 allocator_->set_step_delay(kMinimumStepDelay); 1754 allocator_->set_step_delay(kMinimumStepDelay);
1705 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1755 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1706 session_->StartGettingPorts(); 1756 session_->StartGettingPorts();
1707 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); 1757 ASSERT_EQ_SIMULATED_WAIT(4U, ports_.size(), kDefaultAllocationTimeout,
1758 fake_clock);
1708 EXPECT_EQ(4U, candidates_.size()); 1759 EXPECT_EQ(4U, candidates_.size());
1709 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1760 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1761 kDefaultAllocationTimeout, fake_clock);
1710 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); 1762 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr);
1711 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1763 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1712 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); 1764 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr);
1713 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1765 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1714 EXPECT_EQ(4U, candidates_.size()); 1766 EXPECT_EQ(4U, candidates_.size());
1715 } 1767 }
1716 1768
1717 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { 1769 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) {
1718 AddInterface(kClientAddr); 1770 AddInterface(kClientAddr);
1719 allocator_->set_step_delay(kDefaultStepDelay); 1771 allocator_->set_step_delay(kDefaultStepDelay);
1720 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1772 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1721 session_->StartGettingPorts(); 1773 session_->StartGettingPorts();
1722 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1774 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
1723 EXPECT_EQ(2U, ports_.size()); 1775 EXPECT_EQ(2U, ports_.size());
1724 session_->StopGettingPorts(); 1776 session_->StopGettingPorts();
1725 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); 1777 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock);
1726 1778
1727 // After stopping getting ports, adding a new interface will not start 1779 // After stopping getting ports, adding a new interface will not start
1728 // getting ports again. 1780 // getting ports again.
1729 allocator_->set_step_delay(kMinimumStepDelay); 1781 allocator_->set_step_delay(kMinimumStepDelay);
1730 candidates_.clear(); 1782 candidates_.clear();
1731 ports_.clear(); 1783 ports_.clear();
1732 candidate_allocation_done_ = false; 1784 candidate_allocation_done_ = false;
1733 network_manager_.AddInterface(kClientAddr2); 1785 network_manager_.AddInterface(kClientAddr2);
1734 rtc::Thread::Current()->ProcessMessages(1000); 1786 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1000));
Taylor Brandstetter 2017/02/08 01:23:59 To be safe I'd prefer SIMULATED_WAIT(false, 1000,
pthatcher1 2017/02/08 08:52:24 Done.
1735 EXPECT_EQ(0U, candidates_.size()); 1787 EXPECT_EQ(0U, candidates_.size());
1736 EXPECT_EQ(0U, ports_.size()); 1788 EXPECT_EQ(0U, ports_.size());
1737 } 1789 }
1738 1790
1739 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { 1791 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) {
1740 AddInterface(kClientAddr); 1792 AddInterface(kClientAddr);
1741 allocator_->set_step_delay(kDefaultStepDelay); 1793 allocator_->set_step_delay(kDefaultStepDelay);
1742 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1794 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1743 session_->StartGettingPorts(); 1795 session_->StartGettingPorts();
1744 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1796 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
1745 EXPECT_EQ(2U, ports_.size()); 1797 EXPECT_EQ(2U, ports_.size());
1746 session_->ClearGettingPorts(); 1798 session_->ClearGettingPorts();
1747 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); 1799 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock);
1748 1800
1749 // After clearing getting ports, adding a new interface will start getting 1801 // After clearing getting ports, adding a new interface will start getting
1750 // ports again. 1802 // ports again.
1751 allocator_->set_step_delay(kMinimumStepDelay); 1803 allocator_->set_step_delay(kMinimumStepDelay);
1752 candidates_.clear(); 1804 candidates_.clear();
1753 ports_.clear(); 1805 ports_.clear();
1754 candidate_allocation_done_ = false; 1806 candidate_allocation_done_ = false;
1755 network_manager_.AddInterface(kClientAddr2); 1807 network_manager_.AddInterface(kClientAddr2);
1756 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1808 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
1757 EXPECT_EQ(2U, ports_.size()); 1809 EXPECT_EQ(2U, ports_.size());
1758 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1810 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1811 kDefaultAllocationTimeout, fake_clock);
1759 } 1812 }
1760 1813
1761 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when 1814 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when
1762 // a pooled session is taken out of the pool. 1815 // a pooled session is taken out of the pool.
1763 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { 1816 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) {
1764 AddInterface(kClientAddr); 1817 AddInterface(kClientAddr);
1765 int pool_size = 1; 1818 int pool_size = 1;
1766 allocator_->SetConfiguration(allocator_->stun_servers(), 1819 allocator_->SetConfiguration(allocator_->stun_servers(),
1767 allocator_->turn_servers(), pool_size, false); 1820 allocator_->turn_servers(), pool_size, false);
1768 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1821 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1769 ASSERT_NE(nullptr, peeked_session); 1822 ASSERT_NE(nullptr, peeked_session);
1770 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1823 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(),
1771 kDefaultAllocationTimeout); 1824 kDefaultAllocationTimeout, fake_clock);
1772 // Expect that when TakePooledSession is called, 1825 // Expect that when TakePooledSession is called,
1773 // UpdateTransportInformationInternal will be called and the 1826 // UpdateTransportInformationInternal will be called and the
1774 // BasicPortAllocatorSession will update the ufrag/pwd of ports and 1827 // BasicPortAllocatorSession will update the ufrag/pwd of ports and
1775 // candidates. 1828 // candidates.
1776 session_ = 1829 session_ =
1777 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); 1830 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0);
1778 ASSERT_NE(nullptr, session_.get()); 1831 ASSERT_NE(nullptr, session_.get());
1779 auto ready_ports = session_->ReadyPorts(); 1832 auto ready_ports = session_->ReadyPorts();
1780 auto candidates = session_->ReadyCandidates(); 1833 auto candidates = session_->ReadyCandidates();
1781 EXPECT_FALSE(ready_ports.empty()); 1834 EXPECT_FALSE(ready_ports.empty());
(...skipping 14 matching lines...) Expand all
1796 1849
1797 // Test that a new candidate filter takes effect even on already-gathered 1850 // Test that a new candidate filter takes effect even on already-gathered
1798 // candidates. 1851 // candidates.
1799 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { 1852 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) {
1800 AddInterface(kClientAddr); 1853 AddInterface(kClientAddr);
1801 int pool_size = 1; 1854 int pool_size = 1;
1802 allocator_->SetConfiguration(allocator_->stun_servers(), 1855 allocator_->SetConfiguration(allocator_->stun_servers(),
1803 allocator_->turn_servers(), pool_size, false); 1856 allocator_->turn_servers(), pool_size, false);
1804 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1857 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1805 ASSERT_NE(nullptr, peeked_session); 1858 ASSERT_NE(nullptr, peeked_session);
1806 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1859 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(),
1807 kDefaultAllocationTimeout); 1860 kDefaultAllocationTimeout, fake_clock);
1808 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); 1861 size_t initial_candidates_size = peeked_session->ReadyCandidates().size();
1809 size_t initial_ports_size = peeked_session->ReadyPorts().size(); 1862 size_t initial_ports_size = peeked_session->ReadyPorts().size();
1810 allocator_->set_candidate_filter(CF_RELAY); 1863 allocator_->set_candidate_filter(CF_RELAY);
1811 // Assume that when TakePooledSession is called, the candidate filter will be 1864 // Assume that when TakePooledSession is called, the candidate filter will be
1812 // applied to the pooled session. This is tested by PortAllocatorTest. 1865 // applied to the pooled session. This is tested by PortAllocatorTest.
1813 session_ = 1866 session_ =
1814 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); 1867 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0);
1815 ASSERT_NE(nullptr, session_.get()); 1868 ASSERT_NE(nullptr, session_.get());
1816 auto candidates = session_->ReadyCandidates(); 1869 auto candidates = session_->ReadyCandidates();
1817 auto ports = session_->ReadyPorts(); 1870 auto ports = session_->ReadyPorts();
1818 // Sanity check that the number of candidates and ports decreased. 1871 // Sanity check that the number of candidates and ports decreased.
1819 EXPECT_GT(initial_candidates_size, candidates.size()); 1872 EXPECT_GT(initial_candidates_size, candidates.size());
1820 EXPECT_GT(initial_ports_size, ports.size()); 1873 EXPECT_GT(initial_ports_size, ports.size());
1821 for (const PortInterface* port : ports) { 1874 for (const PortInterface* port : ports) {
1822 // Expect only relay ports. 1875 // Expect only relay ports.
1823 EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); 1876 EXPECT_EQ(RELAY_PORT_TYPE, port->Type());
1824 } 1877 }
1825 for (const Candidate& candidate : candidates) { 1878 for (const Candidate& candidate : candidates) {
1826 // Expect only relay candidates now that the filter is applied. 1879 // Expect only relay candidates now that the filter is applied.
1827 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1880 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1828 // Expect that the raddr is emptied due to the CF_RELAY filter. 1881 // Expect that the raddr is emptied due to the CF_RELAY filter.
1829 EXPECT_EQ(candidate.related_address(), 1882 EXPECT_EQ(candidate.related_address(),
1830 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1883 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1831 } 1884 }
1832 } 1885 }
1833 1886
1834 } // namespace cricket 1887 } // namespace cricket
OLDNEW
« webrtc/p2p/base/stunport_unittest.cc ('K') | « webrtc/p2p/base/stunport_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698