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

Side by Side Diff: webrtc/p2p/base/stunport_unittest.cc

Issue 1976683003: Update the type and cost of existing networks if its type is found later by network monitor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Minor changes Created 4 years, 7 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
« no previous file with comments | « webrtc/p2p/base/stunport.cc ('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
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 13 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
14 #include "webrtc/p2p/base/stunport.h" 14 #include "webrtc/p2p/base/stunport.h"
15 #include "webrtc/p2p/base/teststunserver.h" 15 #include "webrtc/p2p/base/teststunserver.h"
16 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
17 #include "webrtc/base/helpers.h" 17 #include "webrtc/base/helpers.h"
18 #include "webrtc/base/physicalsocketserver.h" 18 #include "webrtc/base/physicalsocketserver.h"
19 #include "webrtc/base/socketaddress.h" 19 #include "webrtc/base/socketaddress.h"
20 #include "webrtc/base/ssladapter.h" 20 #include "webrtc/base/ssladapter.h"
21 #include "webrtc/base/virtualsocketserver.h" 21 #include "webrtc/base/virtualsocketserver.h"
22 22
23 using cricket::ServerAddresses; 23 using cricket::ServerAddresses;
24 using rtc::SocketAddress; 24 using rtc::SocketAddress;
25 25
26 static const SocketAddress kLocalAddr("127.0.0.1", 0); 26 static const SocketAddress kLocalAddr("127.0.0.1", 0);
27 static const SocketAddress kStunAddr1("127.0.0.1", 5000); 27 static const SocketAddress kStunAddr1("127.0.0.1", 5000);
28 static const SocketAddress kStunAddr2("127.0.0.1", 4000); 28 static const SocketAddress kStunAddr2("127.0.0.1", 4000);
29 static const SocketAddress kStunAddr3("127.0.0.1", 3000);
29 static const SocketAddress kBadAddr("0.0.0.1", 5000); 30 static const SocketAddress kBadAddr("0.0.0.1", 5000);
30 static const SocketAddress kStunHostnameAddr("localhost", 5000); 31 static const SocketAddress kStunHostnameAddr("localhost", 5000);
31 static const SocketAddress kBadHostnameAddr("not-a-real-hostname", 5000); 32 static const SocketAddress kBadHostnameAddr("not-a-real-hostname", 5000);
32 static const int kTimeoutMs = 10000; 33 static const int kTimeoutMs = 10000;
33 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0 34 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0
34 static const uint32_t kStunCandidatePriority = 1677729535; 35 static const uint32_t kStunCandidatePriority = 1677729535;
35 static const int kInfiniteLifetime = -1; 36 static const int kInfiniteLifetime = -1;
36 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000; 37 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000;
37 38
38 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer) 39 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer)
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 CreateStunPort(stun_servers); 300 CreateStunPort(stun_servers);
300 EXPECT_EQ("stun", port()->Type()); 301 EXPECT_EQ("stun", port()->Type());
301 PrepareAddress(); 302 PrepareAddress();
302 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 303 EXPECT_TRUE_WAIT(done(), kTimeoutMs);
303 EXPECT_EQ(2U, port()->Candidates().size()); 304 EXPECT_EQ(2U, port()->Candidates().size());
304 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), ""); 305 EXPECT_EQ(port()->Candidates()[0].relay_protocol(), "");
305 EXPECT_EQ(port()->Candidates()[1].relay_protocol(), ""); 306 EXPECT_EQ(port()->Candidates()[1].relay_protocol(), "");
306 } 307 }
307 308
308 // Test that the stun_keepalive_lifetime is set correctly based on the network 309 // Test that the stun_keepalive_lifetime is set correctly based on the network
309 // type on a STUN port. 310 // type on a STUN port. Also test that it will be updated if the network type
311 // changes.
310 TEST_F(StunPortTest, TestStunPortGetStunKeepaliveLifetime) { 312 TEST_F(StunPortTest, TestStunPortGetStunKeepaliveLifetime) {
311 // Lifetime for the default network type is |kInfiniteLifetime|. 313 // Lifetime for the default (unknown) network type is |kInfiniteLifetime|.
312 CreateStunPort(kStunAddr1); 314 CreateStunPort(kStunAddr1);
313 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime()); 315 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
314
315 // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs| 316 // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs|
316 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); 317 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
317 CreateStunPort(kStunAddr2);
318 EXPECT_EQ(kHighCostPortKeepaliveLifetimeMs, 318 EXPECT_EQ(kHighCostPortKeepaliveLifetimeMs,
319 port()->stun_keepalive_lifetime()); 319 port()->stun_keepalive_lifetime());
320
321 // Lifetime for the wifi network is |kInfiniteLifetime|.
322 SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
323 CreateStunPort(kStunAddr2);
324 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
320 } 325 }
321 326
322 // Test that the stun_keepalive_lifetime is set correctly based on the network 327 // Test that the stun_keepalive_lifetime is set correctly based on the network
323 // type on a shared STUN port (UDPPort). 328 // type on a shared STUN port (UDPPort). Also test that it will be updated
329 // if the network type changes.
324 TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) { 330 TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) {
325 // Lifetime for the default network type is |kInfiniteLifetime|. 331 // Lifetime for the default (unknown) network type is |kInfiniteLifetime|.
326 CreateSharedStunPort(kStunAddr1); 332 CreateSharedStunPort(kStunAddr1);
327 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime()); 333 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
328 334 // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs|.
329 // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs|
330 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); 335 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
331 CreateSharedStunPort(kStunAddr2);
332 EXPECT_EQ(kHighCostPortKeepaliveLifetimeMs, 336 EXPECT_EQ(kHighCostPortKeepaliveLifetimeMs,
333 port()->stun_keepalive_lifetime()); 337 port()->stun_keepalive_lifetime());
338
339 // Lifetime for the wifi network type is |kInfiniteLifetime|.
340 SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
341 CreateSharedStunPort(kStunAddr2);
342 EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
334 } 343 }
335 344
336 // Test that STUN binding requests will be stopped shortly if the keep-alive 345 // Test that STUN binding requests will be stopped shortly if the keep-alive
337 // lifetime is short. 346 // lifetime is short.
338 TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) { 347 TEST_F(StunPortTest, TestStunBindingRequestShortLifetime) {
339 SetKeepaliveDelay(101); 348 SetKeepaliveDelay(101);
340 SetKeepaliveLifetime(100); 349 SetKeepaliveLifetime(100);
341 CreateStunPort(kStunAddr1); 350 CreateStunPort(kStunAddr1);
342 PrepareAddress(); 351 PrepareAddress();
343 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 352 EXPECT_TRUE_WAIT(done(), kTimeoutMs);
344 EXPECT_TRUE_WAIT(!port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 353 EXPECT_TRUE_WAIT(!port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST),
345 2000); 354 2000);
346 } 355 }
347 356
348 // Test that by default, the STUN binding requests will last for a long time. 357 // Test that by default, the STUN binding requests will last for a long time.
349 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { 358 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
350 SetKeepaliveDelay(101); 359 SetKeepaliveDelay(101);
351 CreateStunPort(kStunAddr1); 360 CreateStunPort(kStunAddr1);
352 PrepareAddress(); 361 PrepareAddress();
353 EXPECT_TRUE_WAIT(done(), kTimeoutMs); 362 EXPECT_TRUE_WAIT(done(), kTimeoutMs);
354 rtc::Thread::Current()->ProcessMessages(1000); 363 rtc::Thread::Current()->ProcessMessages(1000);
355 EXPECT_TRUE(port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST)); 364 EXPECT_TRUE(port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST));
356 } 365 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stunport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698