Index: webrtc/p2p/client/portallocator_unittest.cc |
diff --git a/webrtc/p2p/client/portallocator_unittest.cc b/webrtc/p2p/client/portallocator_unittest.cc |
index 9ea22dd189487192cb56152c5117f102939454b0..dd93fbb1688572535fdfb8ffadea25df4fba16a8 100644 |
--- a/webrtc/p2p/client/portallocator_unittest.cc |
+++ b/webrtc/p2p/client/portallocator_unittest.cc |
@@ -42,6 +42,7 @@ static const SocketAddress kPrivateAddr2("192.168.1.12", 0); |
static const SocketAddress kClientIPv6Addr( |
"2401:fa00:4:1000:be30:5bff:fee5:c3", 0); |
static const SocketAddress kClientAddr2("22.22.22.22", 0); |
+static const SocketAddress kClientAddr3("33.33.33.33", 0); |
static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); |
static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); |
@@ -459,7 +460,7 @@ TEST_F(PortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
EXPECT_EQ(4U, ports_.size()); |
EXPECT_TRUE(candidate_allocation_done_); |
// If we Stop gathering now, we shouldn't get a second "done" callback. |
- session_->StopGettingPorts(); |
+ session_->StopGettingPorts(false); |
} |
TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
@@ -470,7 +471,7 @@ TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
EXPECT_TRUE(candidate_allocation_done_); |
// If we Stop gathering now, we shouldn't get a second "done" callback. |
- session_->StopGettingPorts(); |
+ session_->StopGettingPorts(false); |
// All ports should have unset send-buffer sizes. |
CheckSendBufferSizesOfAllPorts(-1); |
@@ -483,7 +484,7 @@ TEST_F(PortAllocatorTest, TestStopGetAllPorts) { |
session_->StartGettingPorts(); |
ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
EXPECT_EQ(2U, ports_.size()); |
- session_->StopGettingPorts(); |
+ session_->StopGettingPorts(false); |
EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
} |
@@ -1218,3 +1219,35 @@ TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { |
kClientAddr); |
EXPECT_EQ(4U, candidates_.size()); |
} |
+ |
+// Tests that when stopping getting ports, it can choose whether to stop |
+// the port allocator session (i.e., gather continually). |
+TEST_F(PortAllocatorTest, TestStopGettingPorts) { |
+ AddInterface(kClientAddr); |
+ EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
+ session_->StartGettingPorts(); |
+ ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
+ EXPECT_EQ(4U, ports_.size()); |
+ EXPECT_TRUE(candidate_allocation_done_); |
+ |
+ // Stop getting ports but keep the session running |
+ candidates_.clear(); |
+ ports_.clear(); |
+ candidate_allocation_done_ = false; |
+ session_->StopGettingPorts(true); |
+ network_manager_.AddInterface(kClientAddr2); |
+ ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
+ EXPECT_EQ(4U, ports_.size()); |
+ EXPECT_TRUE(candidate_allocation_done_); |
+ |
+ // Stop getting ports and also stop the session. |
+ candidates_.clear(); |
+ ports_.clear(); |
+ candidate_allocation_done_ = false; |
+ session_->StopGettingPorts(false); |
+ network_manager_.AddInterface(kClientAddr3); |
+ rtc::Thread::Current()->ProcessMessages(1000); |
+ EXPECT_TRUE(candidate_allocation_done_); |
+ EXPECT_EQ(0U, candidates_.size()); |
+ EXPECT_EQ(0U, ports_.size()); |
+} |