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

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

Issue 1359363003: Make it possible to keep the port allocator session running (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 24 matching lines...) Expand all
35 using rtc::SocketAddress; 35 using rtc::SocketAddress;
36 using rtc::Thread; 36 using rtc::Thread;
37 37
38 static const SocketAddress kClientAddr("11.11.11.11", 0); 38 static const SocketAddress kClientAddr("11.11.11.11", 0);
39 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); 39 static const SocketAddress kLoopbackAddr("127.0.0.1", 0);
40 static const SocketAddress kPrivateAddr("192.168.1.11", 0); 40 static const SocketAddress kPrivateAddr("192.168.1.11", 0);
41 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); 41 static const SocketAddress kPrivateAddr2("192.168.1.12", 0);
42 static const SocketAddress kClientIPv6Addr( 42 static const SocketAddress kClientIPv6Addr(
43 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); 43 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0);
44 static const SocketAddress kClientAddr2("22.22.22.22", 0); 44 static const SocketAddress kClientAddr2("22.22.22.22", 0);
45 static const SocketAddress kClientAddr3("33.33.33.33", 0);
45 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); 46 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT);
46 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); 47 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT);
47 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); 48 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0);
48 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); 49 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
49 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); 50 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000);
50 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); 51 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001);
51 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); 52 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002);
52 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); 53 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003);
53 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); 54 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004);
54 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 55 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 EXPECT_PRED5(CheckCandidate, candidates_[5], 453 EXPECT_PRED5(CheckCandidate, candidates_[5],
453 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); 454 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr);
454 EXPECT_EQ(4U, ports_.size()); 455 EXPECT_EQ(4U, ports_.size());
455 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); 456 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000);
456 EXPECT_PRED5(CheckCandidate, candidates_[6], 457 EXPECT_PRED5(CheckCandidate, candidates_[6],
457 cricket::ICE_CANDIDATE_COMPONENT_RTP, 458 cricket::ICE_CANDIDATE_COMPONENT_RTP,
458 "relay", "ssltcp", kRelaySslTcpIntAddr); 459 "relay", "ssltcp", kRelaySslTcpIntAddr);
459 EXPECT_EQ(4U, ports_.size()); 460 EXPECT_EQ(4U, ports_.size());
460 EXPECT_TRUE(candidate_allocation_done_); 461 EXPECT_TRUE(candidate_allocation_done_);
461 // If we Stop gathering now, we shouldn't get a second "done" callback. 462 // If we Stop gathering now, we shouldn't get a second "done" callback.
462 session_->StopGettingPorts(); 463 session_->StopGettingPorts(false);
463 } 464 }
464 465
465 TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { 466 TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) {
466 AddInterface(kClientAddr); 467 AddInterface(kClientAddr);
467 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, 468 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP,
468 cricket::CN_VIDEO)); 469 cricket::CN_VIDEO));
469 session_->StartGettingPorts(); 470 session_->StartGettingPorts();
470 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 471 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
471 EXPECT_TRUE(candidate_allocation_done_); 472 EXPECT_TRUE(candidate_allocation_done_);
472 // If we Stop gathering now, we shouldn't get a second "done" callback. 473 // If we Stop gathering now, we shouldn't get a second "done" callback.
473 session_->StopGettingPorts(); 474 session_->StopGettingPorts(false);
474 475
475 // All ports should have unset send-buffer sizes. 476 // All ports should have unset send-buffer sizes.
476 CheckSendBufferSizesOfAllPorts(-1); 477 CheckSendBufferSizesOfAllPorts(-1);
477 } 478 }
478 479
479 // Tests that we can get callback after StopGetAllPorts. 480 // Tests that we can get callback after StopGetAllPorts.
480 TEST_F(PortAllocatorTest, TestStopGetAllPorts) { 481 TEST_F(PortAllocatorTest, TestStopGetAllPorts) {
481 AddInterface(kClientAddr); 482 AddInterface(kClientAddr);
482 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 483 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
483 session_->StartGettingPorts(); 484 session_->StartGettingPorts();
484 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 485 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
485 EXPECT_EQ(2U, ports_.size()); 486 EXPECT_EQ(2U, ports_.size());
486 session_->StopGettingPorts(); 487 session_->StopGettingPorts(false);
487 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 488 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
488 } 489 }
489 490
490 // Test that we restrict client ports appropriately when a port range is set. 491 // Test that we restrict client ports appropriately when a port range is set.
491 // We check the candidates for udp/stun/tcp ports, and the from address 492 // We check the candidates for udp/stun/tcp ports, and the from address
492 // for relay ports. 493 // for relay ports.
493 TEST_F(PortAllocatorTest, TestGetAllPortsPortRange) { 494 TEST_F(PortAllocatorTest, TestGetAllPortsPortRange) {
494 AddInterface(kClientAddr); 495 AddInterface(kClientAddr);
495 // Check that an invalid port range fails. 496 // Check that an invalid port range fails.
496 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); 497 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort));
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 1212 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
1212 kClientAddr); 1213 kClientAddr);
1213 EXPECT_PRED5(CheckCandidate, candidates_[2], 1214 EXPECT_PRED5(CheckCandidate, candidates_[2],
1214 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", 1215 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp",
1215 kClientIPv6Addr); 1216 kClientIPv6Addr);
1216 EXPECT_PRED5(CheckCandidate, candidates_[3], 1217 EXPECT_PRED5(CheckCandidate, candidates_[3],
1217 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", 1218 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp",
1218 kClientAddr); 1219 kClientAddr);
1219 EXPECT_EQ(4U, candidates_.size()); 1220 EXPECT_EQ(4U, candidates_.size());
1220 } 1221 }
1222
1223 // Tests that when stopping getting ports, it can choose whether to stop
1224 // the port allocator session (i.e., gather continually).
1225 TEST_F(PortAllocatorTest, TestStopGettingPorts) {
1226 AddInterface(kClientAddr);
1227 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1228 session_->StartGettingPorts();
1229 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1230 EXPECT_EQ(4U, ports_.size());
1231 EXPECT_TRUE(candidate_allocation_done_);
1232
1233 // Stop getting ports but keep the session running
1234 candidates_.clear();
1235 ports_.clear();
1236 candidate_allocation_done_ = false;
1237 session_->StopGettingPorts(true);
1238 network_manager_.AddInterface(kClientAddr2);
1239 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1240 EXPECT_EQ(4U, ports_.size());
1241 EXPECT_TRUE(candidate_allocation_done_);
1242
1243 // Stop getting ports and also stop the session.
1244 candidates_.clear();
1245 ports_.clear();
1246 candidate_allocation_done_ = false;
1247 session_->StopGettingPorts(false);
1248 network_manager_.AddInterface(kClientAddr3);
1249 rtc::Thread::Current()->ProcessMessages(1000);
1250 EXPECT_TRUE(candidate_allocation_done_);
1251 EXPECT_EQ(0U, candidates_.size());
1252 EXPECT_EQ(0U, ports_.size());
1253 }
OLDNEW
« webrtc/p2p/base/portallocator.h ('K') | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698