| 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 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_); | 84 stun_port_->set_stun_keepalive_lifetime(stun_keepalive_lifetime_); |
| 85 } | 85 } |
| 86 stun_port_->SignalPortComplete.connect(this, | 86 stun_port_->SignalPortComplete.connect(this, |
| 87 &StunPortTestBase::OnPortComplete); | 87 &StunPortTestBase::OnPortComplete); |
| 88 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError); | 88 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) { | 91 void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) { |
| 92 socket_.reset(socket_factory_.CreateUdpSocket( | 92 socket_.reset(socket_factory_.CreateUdpSocket( |
| 93 rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0)); | 93 rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0)); |
| 94 ASSERT_TRUE(socket_ != NULL); | 94 ASSERT_TRUE(socket_ != nullptr); |
| 95 socket_->SignalReadPacket.connect(this, &StunPortTestBase::OnReadPacket); | 95 socket_->SignalReadPacket.connect(this, &StunPortTestBase::OnReadPacket); |
| 96 stun_port_.reset(cricket::UDPPort::Create( | 96 stun_port_.reset(cricket::UDPPort::Create( |
| 97 rtc::Thread::Current(), &socket_factory_, | 97 rtc::Thread::Current(), &socket_factory_, |
| 98 &network_, socket_.get(), | 98 &network_, socket_.get(), |
| 99 rtc::CreateRandomString(16), rtc::CreateRandomString(22), | 99 rtc::CreateRandomString(16), rtc::CreateRandomString(22), |
| 100 std::string(), false)); | 100 std::string(), false)); |
| 101 ASSERT_TRUE(stun_port_ != NULL); | 101 ASSERT_TRUE(stun_port_ != nullptr); |
| 102 ServerAddresses stun_servers; | 102 ServerAddresses stun_servers; |
| 103 stun_servers.insert(server_addr); | 103 stun_servers.insert(server_addr); |
| 104 stun_port_->set_server_addresses(stun_servers); | 104 stun_port_->set_server_addresses(stun_servers); |
| 105 stun_port_->SignalPortComplete.connect(this, | 105 stun_port_->SignalPortComplete.connect(this, |
| 106 &StunPortTestBase::OnPortComplete); | 106 &StunPortTestBase::OnPortComplete); |
| 107 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError); | 107 stun_port_->SignalPortError.connect(this, &StunPortTestBase::OnPortError); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void PrepareAddress() { | 110 void PrepareAddress() { |
| 111 stun_port_->PrepareAddress(); | 111 stun_port_->PrepareAddress(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data, | 114 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data, |
| 115 size_t size, const rtc::SocketAddress& remote_addr, | 115 size_t size, const rtc::SocketAddress& remote_addr, |
| 116 const rtc::PacketTime& packet_time) { | 116 const rtc::PacketTime& packet_time) { |
| 117 stun_port_->HandleIncomingPacket( | 117 stun_port_->HandleIncomingPacket( |
| 118 socket, data, size, remote_addr, rtc::PacketTime()); | 118 socket, data, size, remote_addr, rtc::PacketTime()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void SendData(const char* data, size_t len) { | 121 void SendData(const char* data, size_t len) { |
| 122 stun_port_->HandleIncomingPacket( | 122 stun_port_->HandleIncomingPacket( |
| 123 socket_.get(), data, len, rtc::SocketAddress("22.22.22.22", 0), | 123 socket_.get(), data, len, rtc::SocketAddress("22.22.22.22", 0), |
| 124 rtc::PacketTime()); | 124 rtc::PacketTime()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 protected: | 127 protected: |
| 128 static void SetUpTestCase() { | 128 static void SetUpTestCase() { |
| 129 // Ensure the RNG is inited. | 129 // Ensure the RNG is inited. |
| 130 rtc::InitRandom(NULL, 0); | 130 rtc::InitRandom(nullptr, 0); |
| 131 | |
| 132 } | 131 } |
| 133 | 132 |
| 134 void OnPortComplete(cricket::Port* port) { | 133 void OnPortComplete(cricket::Port* port) { |
| 135 ASSERT_FALSE(done_); | 134 ASSERT_FALSE(done_); |
| 136 done_ = true; | 135 done_ = true; |
| 137 error_ = false; | 136 error_ = false; |
| 138 } | 137 } |
| 139 void OnPortError(cricket::Port* port) { | 138 void OnPortError(cricket::Port* port) { |
| 140 done_ = true; | 139 done_ = true; |
| 141 error_ = true; | 140 error_ = true; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // Test that by default, the STUN binding requests will last for a long time. | 371 // Test that by default, the STUN binding requests will last for a long time. |
| 373 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { | 372 TEST_F(StunPortTest, TestStunBindingRequestLongLifetime) { |
| 374 SetKeepaliveDelay(101); | 373 SetKeepaliveDelay(101); |
| 375 CreateStunPort(kStunAddr1); | 374 CreateStunPort(kStunAddr1); |
| 376 PrepareAddress(); | 375 PrepareAddress(); |
| 377 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); | 376 EXPECT_TRUE_SIMULATED_WAIT(done(), kTimeoutMs, fake_clock); |
| 378 EXPECT_TRUE_SIMULATED_WAIT( | 377 EXPECT_TRUE_SIMULATED_WAIT( |
| 379 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000, | 378 port()->HasPendingRequest(cricket::STUN_BINDING_REQUEST), 1000, |
| 380 fake_clock); | 379 fake_clock); |
| 381 } | 380 } |
| OLD | NEW |