| 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/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stl_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.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 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class TestClientSocketFactory : public ClientSocketFactory { | 28 class TestClientSocketFactory : public ClientSocketFactory { |
| 29 public: | 29 public: |
| 30 ~TestClientSocketFactory() override; | 30 ~TestClientSocketFactory() override; |
| 31 | 31 |
| 32 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 32 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 33 DatagramSocket::BindType bind_type, | 33 DatagramSocket::BindType bind_type, |
| 34 const RandIntCallback& rand_int_cb, | 34 const RandIntCallback& rand_int_cb, |
| 35 NetLog* net_log, | 35 NetLog* net_log, |
| 36 const NetLog::Source& source) override; | 36 const NetLogSource& source) override; |
| 37 | 37 |
| 38 std::unique_ptr<StreamSocket> CreateTransportClientSocket( | 38 std::unique_ptr<StreamSocket> CreateTransportClientSocket( |
| 39 const AddressList& addresses, | 39 const AddressList& addresses, |
| 40 std::unique_ptr<SocketPerformanceWatcher>, | 40 std::unique_ptr<SocketPerformanceWatcher>, |
| 41 NetLog*, | 41 NetLog*, |
| 42 const NetLog::Source&) override { | 42 const NetLogSource&) override { |
| 43 NOTIMPLEMENTED(); | 43 NOTIMPLEMENTED(); |
| 44 return std::unique_ptr<StreamSocket>(); | 44 return std::unique_ptr<StreamSocket>(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( | 47 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 48 std::unique_ptr<ClientSocketHandle> transport_socket, | 48 std::unique_ptr<ClientSocketHandle> transport_socket, |
| 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(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 protected: | 72 protected: |
| 73 void Initialize(unsigned num_servers); | 73 void Initialize(unsigned num_servers); |
| 74 std::unique_ptr<DnsSession::SocketLease> Allocate(unsigned server_index); | 74 std::unique_ptr<DnsSession::SocketLease> Allocate(unsigned server_index); |
| 75 bool DidAllocate(unsigned server_index); | 75 bool DidAllocate(unsigned server_index); |
| 76 bool DidFree(unsigned server_index); | 76 bool DidFree(unsigned server_index); |
| 77 bool NoMoreEvents(); | 77 bool NoMoreEvents(); |
| 78 | 78 |
| 79 DnsConfig config_; | 79 DnsConfig config_; |
| 80 std::unique_ptr<TestClientSocketFactory> test_client_socket_factory_; | 80 std::unique_ptr<TestClientSocketFactory> test_client_socket_factory_; |
| 81 scoped_refptr<DnsSession> session_; | 81 scoped_refptr<DnsSession> session_; |
| 82 NetLog::Source source_; | 82 NetLogSource source_; |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 bool ExpectEvent(const PoolEvent& event); | 85 bool ExpectEvent(const PoolEvent& event); |
| 86 std::list<PoolEvent> events_; | 86 std::list<PoolEvent> events_; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class MockDnsSocketPool : public DnsSocketPool { | 89 class MockDnsSocketPool : public DnsSocketPool { |
| 90 public: | 90 public: |
| 91 MockDnsSocketPool(ClientSocketFactory* factory, DnsSessionTest* test) | 91 MockDnsSocketPool(ClientSocketFactory* factory, DnsSessionTest* test) |
| 92 : DnsSocketPool(factory, base::Bind(&base::RandInt)), test_(test) {} | 92 : DnsSocketPool(factory, base::Bind(&base::RandInt)), test_(test) {} |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 events_.pop_front(); | 176 events_.pop_front(); |
| 177 | 177 |
| 178 return true; | 178 return true; |
| 179 } | 179 } |
| 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 NetLog::Source& 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(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() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 TEST_F(DnsSessionTest, HistogramTimeoutLong) { | 241 TEST_F(DnsSessionTest, HistogramTimeoutLong) { |
| 242 config_.timeout = base::TimeDelta::FromSeconds(15); | 242 config_.timeout = base::TimeDelta::FromSeconds(15); |
| 243 Initialize(2); | 243 Initialize(2); |
| 244 base::TimeDelta timeout = session_->NextTimeout(0, 0); | 244 base::TimeDelta timeout = session_->NextTimeout(0, 0); |
| 245 EXPECT_EQ(timeout.InMilliseconds(), config_.timeout.InMilliseconds()); | 245 EXPECT_EQ(timeout.InMilliseconds(), config_.timeout.InMilliseconds()); |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace | 248 } // namespace |
| 249 | 249 |
| 250 } // namespace net | 250 } // namespace net |
| OLD | NEW |