| OLD | NEW |
| 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> |
| 12 |
| 11 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
| 12 #include "webrtc/p2p/base/stunport.h" | 14 #include "webrtc/p2p/base/stunport.h" |
| 13 #include "webrtc/p2p/base/teststunserver.h" | 15 #include "webrtc/p2p/base/teststunserver.h" |
| 14 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/helpers.h" | 17 #include "webrtc/base/helpers.h" |
| 16 #include "webrtc/base/physicalsocketserver.h" | 18 #include "webrtc/base/physicalsocketserver.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | |
| 18 #include "webrtc/base/socketaddress.h" | 19 #include "webrtc/base/socketaddress.h" |
| 19 #include "webrtc/base/ssladapter.h" | 20 #include "webrtc/base/ssladapter.h" |
| 20 #include "webrtc/base/virtualsocketserver.h" | 21 #include "webrtc/base/virtualsocketserver.h" |
| 21 | 22 |
| 22 using cricket::ServerAddresses; | 23 using cricket::ServerAddresses; |
| 23 using rtc::SocketAddress; | 24 using rtc::SocketAddress; |
| 24 | 25 |
| 25 static const SocketAddress kLocalAddr("127.0.0.1", 0); | 26 static const SocketAddress kLocalAddr("127.0.0.1", 0); |
| 26 static const SocketAddress kStunAddr1("127.0.0.1", 5000); | 27 static const SocketAddress kStunAddr1("127.0.0.1", 5000); |
| 27 static const SocketAddress kStunAddr2("127.0.0.1", 4000); | 28 static const SocketAddress kStunAddr2("127.0.0.1", 4000); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 149 } |
| 149 | 150 |
| 150 cricket::TestStunServer* stun_server_1() { | 151 cricket::TestStunServer* stun_server_1() { |
| 151 return stun_server_1_.get(); | 152 return stun_server_1_.get(); |
| 152 } | 153 } |
| 153 cricket::TestStunServer* stun_server_2() { | 154 cricket::TestStunServer* stun_server_2() { |
| 154 return stun_server_2_.get(); | 155 return stun_server_2_.get(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 private: | 158 private: |
| 158 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 159 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 159 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 160 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
| 160 rtc::SocketServerScope ss_scope_; | 161 rtc::SocketServerScope ss_scope_; |
| 161 rtc::Network network_; | 162 rtc::Network network_; |
| 162 rtc::BasicPacketSocketFactory socket_factory_; | 163 rtc::BasicPacketSocketFactory socket_factory_; |
| 163 rtc::scoped_ptr<cricket::UDPPort> stun_port_; | 164 std::unique_ptr<cricket::UDPPort> stun_port_; |
| 164 rtc::scoped_ptr<cricket::TestStunServer> stun_server_1_; | 165 std::unique_ptr<cricket::TestStunServer> stun_server_1_; |
| 165 rtc::scoped_ptr<cricket::TestStunServer> stun_server_2_; | 166 std::unique_ptr<cricket::TestStunServer> stun_server_2_; |
| 166 rtc::scoped_ptr<rtc::AsyncPacketSocket> socket_; | 167 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
| 167 bool done_; | 168 bool done_; |
| 168 bool error_; | 169 bool error_; |
| 169 int stun_keepalive_delay_; | 170 int stun_keepalive_delay_; |
| 170 int stun_keepalive_lifetime_; | 171 int stun_keepalive_lifetime_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 // Test that we can create a STUN port | 174 // Test that we can create a STUN port |
| 174 TEST_F(StunPortTest, TestBasic) { | 175 TEST_F(StunPortTest, TestBasic) { |
| 175 CreateStunPort(kStunAddr1); | 176 CreateStunPort(kStunAddr1); |
| 176 EXPECT_EQ("stun", port()->Type()); | 177 EXPECT_EQ("stun", port()->Type()); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 347 |
| 347 // Test that by default, the STUN binding requests will last for a long time. | 348 // Test that by default, the STUN binding requests will last for a long time. |
| 348 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { | 349 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { |
| 349 SetKeepaliveDelay(101); | 350 SetKeepaliveDelay(101); |
| 350 CreateStunPort(kStunAddr1); | 351 CreateStunPort(kStunAddr1); |
| 351 PrepareAddress(); | 352 PrepareAddress(); |
| 352 EXPECT_TRUE_WAIT(done(), kTimeoutMs); | 353 EXPECT_TRUE_WAIT(done(), kTimeoutMs); |
| 353 rtc::Thread::Current()->ProcessMessages(1000); | 354 rtc::Thread::Current()->ProcessMessages(1000); |
| 354 EXPECT_TRUE(port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST)); | 355 EXPECT_TRUE(port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST)); |
| 355 } | 356 } |
| OLD | NEW |