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

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

Issue 1414313003: Reland of Adding the ability to change ICE servers through SetConfiguration. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding "override" to applicable methods to fix compile warning. Created 5 years, 1 month 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
« no previous file with comments | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 // Endpoint is on the public network, with TURN specified. 142 // Endpoint is on the public network, with TURN specified.
143 void ResetWithTurnServersNoNat(const rtc::SocketAddress& udp_turn, 143 void ResetWithTurnServersNoNat(const rtc::SocketAddress& udp_turn,
144 const rtc::SocketAddress& tcp_turn) { 144 const rtc::SocketAddress& tcp_turn) {
145 ResetWithNoServersOrNat(); 145 ResetWithNoServersOrNat();
146 AddTurnServers(udp_turn, tcp_turn); 146 AddTurnServers(udp_turn, tcp_turn);
147 } 147 }
148 148
149 void AddTurnServers(const rtc::SocketAddress& udp_turn, 149 void AddTurnServers(const rtc::SocketAddress& udp_turn,
150 const rtc::SocketAddress& tcp_turn) { 150 const rtc::SocketAddress& tcp_turn) {
151 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 151 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
152 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); 152 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
153 relay_server.credentials = credentials; 153 turn_server.credentials = credentials;
154 154
155 if (!udp_turn.IsNil()) { 155 if (!udp_turn.IsNil()) {
156 relay_server.ports.push_back(cricket::ProtocolAddress( 156 turn_server.ports.push_back(
157 kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 157 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
158 } 158 }
159 if (!tcp_turn.IsNil()) { 159 if (!tcp_turn.IsNil()) {
160 relay_server.ports.push_back(cricket::ProtocolAddress( 160 turn_server.ports.push_back(
161 kTurnTcpIntAddr, cricket::PROTO_TCP, false)); 161 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false));
162 } 162 }
163 allocator_->AddRelay(relay_server); 163 allocator_->AddTurnServer(turn_server);
164 } 164 }
165 165
166 bool CreateSession(int component) { 166 bool CreateSession(int component) {
167 session_.reset(CreateSession("session", component)); 167 session_.reset(CreateSession("session", component));
168 if (!session_) 168 if (!session_)
169 return false; 169 return false;
170 return true; 170 return true;
171 } 171 }
172 172
173 bool CreateSession(int component, const std::string& content_name) { 173 bool CreateSession(int component, const std::string& content_name) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 313 }
314 void OnCandidatesReady(cricket::PortAllocatorSession* ses, 314 void OnCandidatesReady(cricket::PortAllocatorSession* ses,
315 const std::vector<cricket::Candidate>& candidates) { 315 const std::vector<cricket::Candidate>& candidates) {
316 for (size_t i = 0; i < candidates.size(); ++i) { 316 for (size_t i = 0; i < candidates.size(); ++i) {
317 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); 317 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString();
318 candidates_.push_back(candidates[i]); 318 candidates_.push_back(candidates[i]);
319 } 319 }
320 } 320 }
321 321
322 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { 322 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) {
323 for (size_t i = 0; i < allocator_->relays().size(); ++i) { 323 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) {
324 cricket::RelayServerConfig server_config = allocator_->relays()[i]; 324 cricket::RelayServerConfig server_config = allocator_->turn_servers()[i];
325 cricket::PortList::const_iterator relay_port; 325 cricket::PortList::const_iterator relay_port;
326 for (relay_port = server_config.ports.begin(); 326 for (relay_port = server_config.ports.begin();
327 relay_port != server_config.ports.end(); ++relay_port) { 327 relay_port != server_config.ports.end(); ++relay_port) {
328 if (proto_addr.address == relay_port->address && 328 if (proto_addr.address == relay_port->address &&
329 proto_addr.proto == relay_port->proto) 329 proto_addr.proto == relay_port->proto)
330 return true; 330 return true;
331 } 331 }
332 } 332 }
333 return false; 333 return false;
334 } 334 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 rtc::scoped_ptr<cricket::PortAllocatorSession> session_; 367 rtc::scoped_ptr<cricket::PortAllocatorSession> session_;
368 std::vector<cricket::PortInterface*> ports_; 368 std::vector<cricket::PortInterface*> ports_;
369 std::vector<cricket::Candidate> candidates_; 369 std::vector<cricket::Candidate> candidates_;
370 bool candidate_allocation_done_; 370 bool candidate_allocation_done_;
371 }; 371 };
372 372
373 // Tests that we can init the port allocator and create a session. 373 // Tests that we can init the port allocator and create a session.
374 TEST_F(PortAllocatorTest, TestBasic) { 374 TEST_F(PortAllocatorTest, TestBasic) {
375 EXPECT_EQ(&network_manager_, allocator().network_manager()); 375 EXPECT_EQ(&network_manager_, allocator().network_manager());
376 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); 376 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin());
377 ASSERT_EQ(1u, allocator().relays().size()); 377 ASSERT_EQ(1u, allocator().turn_servers().size());
378 EXPECT_EQ(cricket::RELAY_GTURN, allocator().relays()[0].type); 378 EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type);
379 // Empty relay credentials are used for GTURN. 379 // Empty relay credentials are used for GTURN.
380 EXPECT_TRUE(allocator().relays()[0].credentials.username.empty()); 380 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty());
381 EXPECT_TRUE(allocator().relays()[0].credentials.password.empty()); 381 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty());
382 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 382 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
383 kRelayUdpIntAddr, cricket::PROTO_UDP))); 383 kRelayUdpIntAddr, cricket::PROTO_UDP)));
384 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 384 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
385 kRelayTcpIntAddr, cricket::PROTO_TCP))); 385 kRelayTcpIntAddr, cricket::PROTO_TCP)));
386 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( 386 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress(
387 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); 387 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP)));
388 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 388 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
389 } 389 }
390 390
391 // Tests that we allocator session not trying to allocate ports for every 250ms. 391 // Tests that we allocator session not trying to allocate ports for every 250ms.
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 EXPECT_EQ(3U, candidates_.size()); 1019 EXPECT_EQ(3U, candidates_.size());
1020 } 1020 }
1021 1021
1022 // Testing DNS resolve for the TURN server, this will test AllocationSequence 1022 // Testing DNS resolve for the TURN server, this will test AllocationSequence
1023 // handling the unresolved address signal from TurnPort. 1023 // handling the unresolved address signal from TurnPort.
1024 TEST_F(PortAllocatorTest, TestSharedSocketWithServerAddressResolve) { 1024 TEST_F(PortAllocatorTest, TestSharedSocketWithServerAddressResolve) {
1025 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), 1025 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478),
1026 cricket::PROTO_UDP); 1026 cricket::PROTO_UDP);
1027 AddInterface(kClientAddr); 1027 AddInterface(kClientAddr);
1028 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 1028 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
1029 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1029 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
1030 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); 1030 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1031 relay_server.credentials = credentials; 1031 turn_server.credentials = credentials;
1032 relay_server.ports.push_back(cricket::ProtocolAddress( 1032 turn_server.ports.push_back(cricket::ProtocolAddress(
1033 rtc::SocketAddress("localhost", 3478), 1033 rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false));
1034 cricket::PROTO_UDP, false)); 1034 allocator_->AddTurnServer(turn_server);
1035 allocator_->AddRelay(relay_server);
1036 1035
1037 allocator_->set_step_delay(cricket::kMinimumStepDelay); 1036 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1038 allocator_->set_flags(allocator().flags() | 1037 allocator_->set_flags(allocator().flags() |
1039 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1038 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1040 cricket::PORTALLOCATOR_DISABLE_TCP); 1039 cricket::PORTALLOCATOR_DISABLE_TCP);
1041 1040
1042 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1041 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1043 session_->StartGettingPorts(); 1042 session_->StartGettingPorts();
1044 1043
1045 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); 1044 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout);
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 1325
1327 // After clearing getting ports, adding a new interface will start getting 1326 // After clearing getting ports, adding a new interface will start getting
1328 // ports again. 1327 // ports again.
1329 candidates_.clear(); 1328 candidates_.clear();
1330 ports_.clear(); 1329 ports_.clear();
1331 candidate_allocation_done_ = false; 1330 candidate_allocation_done_ = false;
1332 network_manager_.AddInterface(kClientAddr2); 1331 network_manager_.AddInterface(kClientAddr2);
1333 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1332 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1334 EXPECT_EQ(2U, ports_.size()); 1333 EXPECT_EQ(2U, ports_.size());
1335 } 1334 }
OLDNEW
« no previous file with comments | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698