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

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

Issue 1520963002: Removing webrtc::PortAllocatorFactoryInterface. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing patch conflicts Created 5 years 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 14 matching lines...) Expand all
25 #include "webrtc/base/natserver.h" 25 #include "webrtc/base/natserver.h"
26 #include "webrtc/base/natsocketfactory.h" 26 #include "webrtc/base/natsocketfactory.h"
27 #include "webrtc/base/network.h" 27 #include "webrtc/base/network.h"
28 #include "webrtc/base/physicalsocketserver.h" 28 #include "webrtc/base/physicalsocketserver.h"
29 #include "webrtc/base/socketaddress.h" 29 #include "webrtc/base/socketaddress.h"
30 #include "webrtc/base/ssladapter.h" 30 #include "webrtc/base/ssladapter.h"
31 #include "webrtc/base/thread.h" 31 #include "webrtc/base/thread.h"
32 #include "webrtc/base/virtualsocketserver.h" 32 #include "webrtc/base/virtualsocketserver.h"
33 33
34 using cricket::ServerAddresses; 34 using cricket::ServerAddresses;
35 using rtc::IPAddress;
35 using rtc::SocketAddress; 36 using rtc::SocketAddress;
36 using rtc::Thread; 37 using rtc::Thread;
37 38
38 static const SocketAddress kClientAddr("11.11.11.11", 0); 39 static const SocketAddress kClientAddr("11.11.11.11", 0);
39 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); 40 static const SocketAddress kLoopbackAddr("127.0.0.1", 0);
40 static const SocketAddress kPrivateAddr("192.168.1.11", 0); 41 static const SocketAddress kPrivateAddr("192.168.1.11", 0);
41 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); 42 static const SocketAddress kPrivateAddr2("192.168.1.12", 0);
42 static const SocketAddress kClientIPv6Addr( 43 static const SocketAddress kClientIPv6Addr(
43 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); 44 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0);
44 static const SocketAddress kClientAddr2("22.22.22.22", 0); 45 static const SocketAddress kClientAddr2("22.22.22.22", 0);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 108 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
108 allocator_->set_step_delay(cricket::kMinimumStepDelay); 109 allocator_->set_step_delay(cricket::kMinimumStepDelay);
109 } 110 }
110 111
111 void AddInterface(const SocketAddress& addr) { 112 void AddInterface(const SocketAddress& addr) {
112 network_manager_.AddInterface(addr); 113 network_manager_.AddInterface(addr);
113 } 114 }
114 void AddInterface(const SocketAddress& addr, const std::string& if_name) { 115 void AddInterface(const SocketAddress& addr, const std::string& if_name) {
115 network_manager_.AddInterface(addr, if_name); 116 network_manager_.AddInterface(addr, if_name);
116 } 117 }
118 void AddInterface(const SocketAddress& addr,
119 const std::string& if_name,
120 rtc::AdapterType type) {
121 network_manager_.AddInterface(addr, if_name, type);
122 }
117 // The default route is the public address that STUN server will observe when 123 // The default route is the public address that STUN server will observe when
118 // the endpoint is sitting on the public internet and the local port is bound 124 // the endpoint is sitting on the public internet and the local port is bound
119 // to the "any" address. This may be different from the default local address 125 // to the "any" address. This may be different from the default local address
120 // which the endpoint observes. This can occur if the route to the public 126 // which the endpoint observes. This can occur if the route to the public
121 // endpoint like 8.8.8.8 (specified as the default local address) is 127 // endpoint like 8.8.8.8 (specified as the default local address) is
122 // different from the route to the STUN server (the default route). 128 // different from the route to the STUN server (the default route).
123 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) { 129 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) {
124 AddInterface(addr); 130 AddInterface(addr);
125 // When a binding comes from the any address, the |addr| will be used as the 131 // When a binding comes from the any address, the |addr| will be used as the
126 // srflx address. 132 // srflx address.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); 399 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty());
394 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 400 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
395 kRelayUdpIntAddr, cricket::PROTO_UDP))); 401 kRelayUdpIntAddr, cricket::PROTO_UDP)));
396 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 402 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
397 kRelayTcpIntAddr, cricket::PROTO_TCP))); 403 kRelayTcpIntAddr, cricket::PROTO_TCP)));
398 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 404 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
399 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); 405 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP)));
400 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 406 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
401 } 407 }
402 408
409 // Tests that our network filtering works properly.
410 TEST_F(PortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) {
411 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0",
412 rtc::ADAPTER_TYPE_ETHERNET);
413 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0",
414 rtc::ADAPTER_TYPE_WIFI);
415 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
416 rtc::ADAPTER_TYPE_CELLULAR);
417 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0",
418 rtc::ADAPTER_TYPE_VPN);
419 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo",
420 rtc::ADAPTER_TYPE_LOOPBACK);
421 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
422 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
423 cricket::PORTALLOCATOR_DISABLE_RELAY |
424 cricket::PORTALLOCATOR_DISABLE_TCP);
425 session_->StartGettingPorts();
426 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
427 EXPECT_EQ(4U, candidates_.size());
428 for (cricket::Candidate candidate : candidates_) {
429 EXPECT_LT(candidate.address().ip(), 0x12345604U);
430 }
431 }
432
433 TEST_F(PortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) {
434 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0",
435 rtc::ADAPTER_TYPE_ETHERNET);
436 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0",
437 rtc::ADAPTER_TYPE_WIFI);
438 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0",
439 rtc::ADAPTER_TYPE_CELLULAR);
440 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET |
441 rtc::ADAPTER_TYPE_LOOPBACK |
442 rtc::ADAPTER_TYPE_WIFI);
443 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
444 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
445 cricket::PORTALLOCATOR_DISABLE_RELAY |
446 cricket::PORTALLOCATOR_DISABLE_TCP);
447 session_->StartGettingPorts();
448 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
449 EXPECT_EQ(1U, candidates_.size());
450 EXPECT_EQ(0x12345602U, candidates_[0].address().ip());
451 }
452
403 // Tests that we allocator session not trying to allocate ports for every 250ms. 453 // Tests that we allocator session not trying to allocate ports for every 250ms.
404 TEST_F(PortAllocatorTest, TestNoNetworkInterface) { 454 TEST_F(PortAllocatorTest, TestNoNetworkInterface) {
405 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 455 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
406 session_->StartGettingPorts(); 456 session_->StartGettingPorts();
407 // Waiting for one second to make sure BasicPortAllocatorSession has not 457 // Waiting for one second to make sure BasicPortAllocatorSession has not
408 // called OnAllocate multiple times. In old behavior it's called every 250ms. 458 // called OnAllocate multiple times. In old behavior it's called every 250ms.
409 // When there are no network interfaces, each execution of OnAllocate will 459 // When there are no network interfaces, each execution of OnAllocate will
410 // result in SignalCandidatesAllocationDone signal. 460 // result in SignalCandidatesAllocationDone signal.
411 rtc::Thread::Current()->ProcessMessages(1000); 461 rtc::Thread::Current()->ProcessMessages(1000);
412 EXPECT_TRUE(candidate_allocation_done_); 462 EXPECT_TRUE(candidate_allocation_done_);
413 EXPECT_EQ(0U, candidates_.size()); 463 EXPECT_EQ(0U, candidates_.size());
414 } 464 }
415 465
416 // Test that we could use loopback interface as host candidate. 466 // Test that we could use loopback interface as host candidate.
417 TEST_F(PortAllocatorTest, TestLoopbackNetworkInterface) { 467 TEST_F(PortAllocatorTest, TestLoopbackNetworkInterface) {
418 AddInterface(kLoopbackAddr); 468 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK);
469 allocator_->SetNetworkIgnoreMask(0);
419 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 470 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
420 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | 471 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN |
421 cricket::PORTALLOCATOR_DISABLE_RELAY | 472 cricket::PORTALLOCATOR_DISABLE_RELAY |
422 cricket::PORTALLOCATOR_DISABLE_TCP); 473 cricket::PORTALLOCATOR_DISABLE_TCP);
423 session_->StartGettingPorts(); 474 session_->StartGettingPorts();
424 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 475 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
425 EXPECT_EQ(1U, candidates_.size()); 476 EXPECT_EQ(1U, candidates_.size());
426 } 477 }
427 478
428 // Tests that we can get all the desired addresses successfully. 479 // Tests that we can get all the desired addresses successfully.
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 1401
1351 // After clearing getting ports, adding a new interface will start getting 1402 // After clearing getting ports, adding a new interface will start getting
1352 // ports again. 1403 // ports again.
1353 candidates_.clear(); 1404 candidates_.clear();
1354 ports_.clear(); 1405 ports_.clear();
1355 candidate_allocation_done_ = false; 1406 candidate_allocation_done_ = false;
1356 network_manager_.AddInterface(kClientAddr2); 1407 network_manager_.AddInterface(kClientAddr2);
1357 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1408 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1358 EXPECT_EQ(2U, ports_.size()); 1409 EXPECT_EQ(2U, ports_.size());
1359 } 1410 }
OLDNEW
« webrtc/p2p/client/basicportallocator.cc ('K') | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698