| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/dns_session.h" | 5 #include "net/dns/dns_session.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 13 #include "base/stl_util.h" | |
| 14 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
| 15 #include "net/dns/dns_protocol.h" | 15 #include "net/dns/dns_protocol.h" |
| 16 #include "net/dns/dns_socket_pool.h" | 16 #include "net/dns/dns_socket_pool.h" |
| 17 #include "net/log/net_log_source.h" | 17 #include "net/log/net_log_source.h" |
| 18 #include "net/socket/socket_performance_watcher.h" | 18 #include "net/socket/socket_performance_watcher.h" |
| 19 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 20 #include "net/socket/ssl_client_socket.h" | 20 #include "net/socket/ssl_client_socket.h" |
| 21 #include "net/socket/stream_socket.h" | 21 #include "net/socket/stream_socket.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 const HostPortPair& host_and_port, | 49 const HostPortPair& host_and_port, |
| 50 const SSLConfig& ssl_config, | 50 const SSLConfig& ssl_config, |
| 51 const SSLClientSocketContext& context) override { | 51 const SSLClientSocketContext& context) override { |
| 52 NOTIMPLEMENTED(); | 52 NOTIMPLEMENTED(); |
| 53 return std::unique_ptr<SSLClientSocket>(); | 53 return std::unique_ptr<SSLClientSocket>(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); } | 56 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 std::list<SocketDataProvider*> data_providers_; | 59 std::list<std::unique_ptr<SocketDataProvider>> data_providers_; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 struct PoolEvent { | 62 struct PoolEvent { |
| 63 enum { ALLOCATE, FREE } action; | 63 enum { ALLOCATE, FREE } action; |
| 64 unsigned server_index; | 64 unsigned server_index; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class DnsSessionTest : public testing::Test { | 67 class DnsSessionTest : public testing::Test { |
| 68 public: | 68 public: |
| 69 void OnSocketAllocated(unsigned server_index); | 69 void OnSocketAllocated(unsigned server_index); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 std::unique_ptr<DatagramClientSocket> | 181 std::unique_ptr<DatagramClientSocket> |
| 182 TestClientSocketFactory::CreateDatagramClientSocket( | 182 TestClientSocketFactory::CreateDatagramClientSocket( |
| 183 DatagramSocket::BindType bind_type, | 183 DatagramSocket::BindType bind_type, |
| 184 const RandIntCallback& rand_int_cb, | 184 const RandIntCallback& rand_int_cb, |
| 185 NetLog* net_log, | 185 NetLog* net_log, |
| 186 const NetLogSource& source) { | 186 const NetLogSource& source) { |
| 187 // We're not actually expecting to send or receive any data, so use the | 187 // We're not actually expecting to send or receive any data, so use the |
| 188 // simplest SocketDataProvider with no data supplied. | 188 // simplest SocketDataProvider with no data supplied. |
| 189 SocketDataProvider* data_provider = new StaticSocketDataProvider(); | 189 SocketDataProvider* data_provider = new StaticSocketDataProvider(); |
| 190 data_providers_.push_back(data_provider); | 190 data_providers_.push_back(base::WrapUnique(data_provider)); |
| 191 std::unique_ptr<MockUDPClientSocket> socket( | 191 std::unique_ptr<MockUDPClientSocket> socket( |
| 192 new MockUDPClientSocket(data_provider, net_log)); | 192 new MockUDPClientSocket(data_provider, net_log)); |
| 193 return std::move(socket); | 193 return std::move(socket); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TestClientSocketFactory::~TestClientSocketFactory() { | 196 TestClientSocketFactory::~TestClientSocketFactory() { |
| 197 base::STLDeleteElements(&data_providers_); | |
| 198 } | 197 } |
| 199 | 198 |
| 200 TEST_F(DnsSessionTest, AllocateFree) { | 199 TEST_F(DnsSessionTest, AllocateFree) { |
| 201 std::unique_ptr<DnsSession::SocketLease> lease1, lease2; | 200 std::unique_ptr<DnsSession::SocketLease> lease1, lease2; |
| 202 | 201 |
| 203 Initialize(2); | 202 Initialize(2); |
| 204 EXPECT_TRUE(NoMoreEvents()); | 203 EXPECT_TRUE(NoMoreEvents()); |
| 205 | 204 |
| 206 lease1 = Allocate(0); | 205 lease1 = Allocate(0); |
| 207 EXPECT_TRUE(DidAllocate(0)); | 206 EXPECT_TRUE(DidAllocate(0)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 TEST_F(DnsSessionTest, HistogramTimeoutLong) { | 240 TEST_F(DnsSessionTest, HistogramTimeoutLong) { |
| 242 config_.timeout = base::TimeDelta::FromSeconds(15); | 241 config_.timeout = base::TimeDelta::FromSeconds(15); |
| 243 Initialize(2); | 242 Initialize(2); |
| 244 base::TimeDelta timeout = session_->NextTimeout(0, 0); | 243 base::TimeDelta timeout = session_->NextTimeout(0, 0); |
| 245 EXPECT_EQ(timeout.InMilliseconds(), config_.timeout.InMilliseconds()); | 244 EXPECT_EQ(timeout.InMilliseconds(), config_.timeout.InMilliseconds()); |
| 246 } | 245 } |
| 247 | 246 |
| 248 } // namespace | 247 } // namespace |
| 249 | 248 |
| 250 } // namespace net | 249 } // namespace net |
| OLD | NEW |