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

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

Issue 2989303002: Make Port (and subclasses) fully "Network"-based, instead of IP-based. (Closed)
Patch Set: Add back Port constructor that takes IP for backwards compatibility. Created 3 years, 4 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') | webrtc/p2p/base/tcpport.h » ('j') | 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 25 matching lines...) Expand all
36 static const uint32_t kStunCandidatePriority = 1677729535; 36 static const uint32_t kStunCandidatePriority = 1677729535;
37 static const int kInfiniteLifetime = -1; 37 static const int kInfiniteLifetime = -1;
38 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000; 38 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000;
39 39
40 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer) 40 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer)
41 class StunPortTestBase : public testing::Test, public sigslot::has_slots<> { 41 class StunPortTestBase : public testing::Test, public sigslot::has_slots<> {
42 public: 42 public:
43 StunPortTestBase() 43 StunPortTestBase()
44 : ss_(new rtc::VirtualSocketServer()), 44 : ss_(new rtc::VirtualSocketServer()),
45 thread_(ss_.get()), 45 thread_(ss_.get()),
46 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), 46 network_("unittest", "unittest", kLocalAddr.ipaddr(), 32),
47 socket_factory_(rtc::Thread::Current()), 47 socket_factory_(rtc::Thread::Current()),
48 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(), 48 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(),
49 kStunAddr1)), 49 kStunAddr1)),
50 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(), 50 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(),
51 kStunAddr2)), 51 kStunAddr2)),
52 done_(false), 52 done_(false),
53 error_(false), 53 error_(false),
54 stun_keepalive_delay_(1), 54 stun_keepalive_delay_(1),
55 stun_keepalive_lifetime_(-1) {} 55 stun_keepalive_lifetime_(-1) {
56 network_.AddIP(kLocalAddr.ipaddr());
57 }
56 58
57 cricket::UDPPort* port() const { return stun_port_.get(); } 59 cricket::UDPPort* port() const { return stun_port_.get(); }
58 bool done() const { return done_; } 60 bool done() const { return done_; }
59 bool error() const { return error_; } 61 bool error() const { return error_; }
60 62
61 void SetNetworkType(rtc::AdapterType adapter_type) { 63 void SetNetworkType(rtc::AdapterType adapter_type) {
62 network_.set_type(adapter_type); 64 network_.set_type(adapter_type);
63 } 65 }
64 66
65 void CreateStunPort(const rtc::SocketAddress& server_addr) { 67 void CreateStunPort(const rtc::SocketAddress& server_addr) {
66 ServerAddresses stun_servers; 68 ServerAddresses stun_servers;
67 stun_servers.insert(server_addr); 69 stun_servers.insert(server_addr);
68 CreateStunPort(stun_servers); 70 CreateStunPort(stun_servers);
69 } 71 }
70 72
71 void CreateStunPort(const ServerAddresses& stun_servers) { 73 void CreateStunPort(const ServerAddresses& stun_servers) {
72 stun_port_.reset(cricket::StunPort::Create( 74 stun_port_.reset(cricket::StunPort::Create(
73 rtc::Thread::Current(), &socket_factory_, &network_, 75 rtc::Thread::Current(), &socket_factory_, &network_, 0, 0,
74 kLocalAddr.ipaddr(), 0, 0, rtc::CreateRandomString(16), 76 rtc::CreateRandomString(16), rtc::CreateRandomString(22), stun_servers,
75 rtc::CreateRandomString(22), stun_servers, std::string())); 77 std::string()));
76 stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_); 78 stun_port_->set_stun_keepalive_delay(stun_keepalive_delay_);
77 // If |stun_keepalive_lifetime_| is negative, let the stun port 79 // If |stun_keepalive_lifetime_| is negative, let the stun port
78 // choose its lifetime from the network type. 80 // choose its lifetime from the network type.
79 if (stun_keepalive_lifetime_ >= 0) { 81 if (stun_keepalive_lifetime_ >= 0) {
80 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_); 82 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_);
81 } 83 }
82 stun_port_->SignalPortComplete.connect(this, 84 stun_port_->SignalPortComplete.connect(this,
83 &StunPortTestBase::OnPortComplete); 85 &StunPortTestBase::OnPortComplete);
84 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError); 86 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError);
85 } 87 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Test that by default, the STUN binding requests will last for a long time. 376 // Test that by default, the STUN binding requests will last for a long time.
375 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { 377 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
376 SetKeepaliveDelay(101); 378 SetKeepaliveDelay(101);
377 CreateStunPort(kStunAddr1); 379 CreateStunPort(kStunAddr1);
378 PrepareAddress(); 380 PrepareAddress();
379 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); 381 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
380 EXPECT_TRUE_SIMULATED_WAIT( 382 EXPECT_TRUE_SIMULATED_WAIT(
381 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000, 383 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000,
382 fake_clock); 384 fake_clock);
383 } 385 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stunport.cc ('k') | webrtc/p2p/base/tcpport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698