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

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

Issue 2883313003: Remove VirtualSocketServer's dependency on PhysicalSocketServer. (Closed)
Patch Set: Created 3 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/relayserver_unittest.cc ('k') | webrtc/p2p/base/stunserver_unittest.cc » ('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
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"
19 #include "webrtc/base/socketaddress.h" 18 #include "webrtc/base/socketaddress.h"
20 #include "webrtc/base/ssladapter.h" 19 #include "webrtc/base/ssladapter.h"
21 #include "webrtc/base/virtualsocketserver.h" 20 #include "webrtc/base/virtualsocketserver.h"
22 21
23 using cricket::ServerAddresses; 22 using cricket::ServerAddresses;
24 using rtc::SocketAddress; 23 using rtc::SocketAddress;
25 24
26 static const SocketAddress kLocalAddr("127.0.0.1", 0); 25 static const SocketAddress kLocalAddr("127.0.0.1", 0);
27 static const SocketAddress kStunAddr1("127.0.0.1", 5000); 26 static const SocketAddress kStunAddr1("127.0.0.1", 5000);
28 static const SocketAddress kStunAddr2("127.0.0.1", 4000); 27 static const SocketAddress kStunAddr2("127.0.0.1", 4000);
29 static const SocketAddress kStunAddr3("127.0.0.1", 3000); 28 static const SocketAddress kStunAddr3("127.0.0.1", 3000);
30 static const SocketAddress kBadAddr("0.0.0.1", 5000); 29 static const SocketAddress kBadAddr("0.0.0.1", 5000);
31 static const SocketAddress kStunHostnameAddr("localhost", 5000); 30 static const SocketAddress kStunHostnameAddr("localhost", 5000);
32 static const SocketAddress kBadHostnameAddr("not-a-real-hostname", 5000); 31 static const SocketAddress kBadHostnameAddr("not-a-real-hostname", 5000);
33 // STUN timeout (with all retries) is cricket::STUN_TOTAL_TIMEOUT. 32 // STUN timeout (with all retries) is cricket::STUN_TOTAL_TIMEOUT.
34 // Add some margin of error for slow bots. 33 // Add some margin of error for slow bots.
35 static const int kTimeoutMs = cricket::STUN_TOTAL_TIMEOUT; 34 static const int kTimeoutMs = cricket::STUN_TOTAL_TIMEOUT;
36 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0 35 // stun prio = 100 << 24 | 30 (IPV4) << 8 | 256 - 0
37 static const uint32_t kStunCandidatePriority = 1677729535; 36 static const uint32_t kStunCandidatePriority = 1677729535;
38 static const int kInfiniteLifetime = -1; 37 static const int kInfiniteLifetime = -1;
39 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000; 38 static const int kHighCostPortKeepaliveLifetimeMs = 2 * 60 * 1000;
40 39
41 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer) 40 // Tests connecting a StunPort to a fake STUN server (cricket::StunServer)
42 // TODO: Use a VirtualSocketServer here. We have to use a
43 // PhysicalSocketServer right now since DNS is not part of SocketServer yet.
44 class StunPortTestBase : public testing::Test, public sigslot::has_slots<> { 41 class StunPortTestBase : public testing::Test, public sigslot::has_slots<> {
45 public: 42 public:
46 StunPortTestBase() 43 StunPortTestBase()
47 : pss_(new rtc::PhysicalSocketServer), 44 : ss_(new rtc::VirtualSocketServer()),
48 ss_(new rtc::VirtualSocketServer(pss_.get())),
49 thread_(ss_.get()), 45 thread_(ss_.get()),
50 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), 46 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
51 socket_factory_(rtc::Thread::Current()), 47 socket_factory_(rtc::Thread::Current()),
52 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(), 48 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(),
53 kStunAddr1)), 49 kStunAddr1)),
54 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(), 50 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(),
55 kStunAddr2)), 51 kStunAddr2)),
56 done_(false), 52 done_(false),
57 error_(false), 53 error_(false),
58 stun_keepalive_delay_(1), 54 stun_keepalive_delay_(1),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 145 }
150 146
151 cricket::TestStunServer* stun_server_1() { 147 cricket::TestStunServer* stun_server_1() {
152 return stun_server_1_.get(); 148 return stun_server_1_.get();
153 } 149 }
154 cricket::TestStunServer* stun_server_2() { 150 cricket::TestStunServer* stun_server_2() {
155 return stun_server_2_.get(); 151 return stun_server_2_.get();
156 } 152 }
157 153
158 private: 154 private:
159 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
160 std::unique_ptr<rtc::VirtualSocketServer> ss_; 155 std::unique_ptr<rtc::VirtualSocketServer> ss_;
161 rtc::AutoSocketServerThread thread_; 156 rtc::AutoSocketServerThread thread_;
162 rtc::Network network_; 157 rtc::Network network_;
163 rtc::BasicPacketSocketFactory socket_factory_; 158 rtc::BasicPacketSocketFactory socket_factory_;
164 std::unique_ptr<cricket::UDPPort> stun_port_; 159 std::unique_ptr<cricket::UDPPort> stun_port_;
165 std::unique_ptr<cricket::TestStunServer> stun_server_1_; 160 std::unique_ptr<cricket::TestStunServer> stun_server_1_;
166 std::unique_ptr<cricket::TestStunServer> stun_server_2_; 161 std::unique_ptr<cricket::TestStunServer> stun_server_2_;
167 std::unique_ptr<rtc::AsyncPacketSocket> socket_; 162 std::unique_ptr<rtc::AsyncPacketSocket> socket_;
168 bool done_; 163 bool done_;
169 bool error_; 164 bool error_;
(...skipping 27 matching lines...) Expand all
197 // Test that we can get an address from a STUN server. 192 // Test that we can get an address from a STUN server.
198 TEST_F(StunPortTest, TestPrepareAddress) { 193 TEST_F(StunPortTest, TestPrepareAddress) {
199 CreateStunPort(kStunAddr1); 194 CreateStunPort(kStunAddr1);
200 PrepareAddress(); 195 PrepareAddress();
201 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); 196 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
202 ASSERT_EQ(1U, port()->Candidates().size()); 197 ASSERT_EQ(1U, port()->Candidates().size());
203 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address())); 198 EXPECT_TRUE(kLocalAddr.EqualIPs(port()->Candidates()[0].address()));
204 std::string expected_server_url = "stun:127.0.0.1:5000"; 199 std::string expected_server_url = "stun:127.0.0.1:5000";
205 EXPECT_EQ(port()->Candidates()[0].url(), expected_server_url); 200 EXPECT_EQ(port()->Candidates()[0].url(), expected_server_url);
206 201
207 // TODO: Add IPv6 tests here, once either physicalsocketserver supports 202 // TODO(deadbeef): Add IPv6 tests here.
208 // IPv6, or this test is changed to use VirtualSocketServer.
209 } 203 }
210 204
211 // Test that we fail properly if we can't get an address. 205 // Test that we fail properly if we can't get an address.
212 TEST_F(StunPortTest, TestPrepareAddressFail) { 206 TEST_F(StunPortTest, TestPrepareAddressFail) {
213 CreateStunPort(kBadAddr); 207 CreateStunPort(kBadAddr);
214 PrepareAddress(); 208 PrepareAddress();
215 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); 209 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
216 EXPECT_TRUE(error()); 210 EXPECT_TRUE(error());
217 EXPECT_EQ(0U, port()->Candidates().size()); 211 EXPECT_EQ(0U, port()->Candidates().size());
218 } 212 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // Test that by default, the STUN binding requests will last for a long time. 374 // Test that by default, the STUN binding requests will last for a long time.
381 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { 375 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) {
382 SetKeepaliveDelay(101); 376 SetKeepaliveDelay(101);
383 CreateStunPort(kStunAddr1); 377 CreateStunPort(kStunAddr1);
384 PrepareAddress(); 378 PrepareAddress();
385 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); 379 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock);
386 EXPECT_TRUE_SIMULATED_WAIT( 380 EXPECT_TRUE_SIMULATED_WAIT(
387 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000, 381 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000,
388 fake_clock); 382 fake_clock);
389 } 383 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/relayserver_unittest.cc ('k') | webrtc/p2p/base/stunserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698