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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
14 #include "net/dns/dns_protocol.h" | 14 #include "net/dns/dns_protocol.h" |
15 #include "net/dns/dns_socket_pool.h" | 15 #include "net/dns/dns_socket_pool.h" |
16 #include "net/socket/socket_test_util.h" | 16 #include "net/socket/socket_test_util.h" |
17 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
18 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 class TestClientSocketFactory : public ClientSocketFactory { | 25 class TestClientSocketFactory : public ClientSocketFactory { |
26 public: | 26 public: |
27 virtual ~TestClientSocketFactory(); | 27 ~TestClientSocketFactory() override; |
28 | 28 |
29 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 29 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
30 DatagramSocket::BindType bind_type, | 30 DatagramSocket::BindType bind_type, |
31 const RandIntCallback& rand_int_cb, | 31 const RandIntCallback& rand_int_cb, |
32 net::NetLog* net_log, | 32 net::NetLog* net_log, |
33 const net::NetLog::Source& source) override; | 33 const net::NetLog::Source& source) override; |
34 | 34 |
35 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 35 scoped_ptr<StreamSocket> CreateTransportClientSocket( |
36 const AddressList& addresses, | 36 const AddressList& addresses, |
37 NetLog*, const NetLog::Source&) override { | 37 NetLog*, |
| 38 const NetLog::Source&) override { |
38 NOTIMPLEMENTED(); | 39 NOTIMPLEMENTED(); |
39 return scoped_ptr<StreamSocket>(); | 40 return scoped_ptr<StreamSocket>(); |
40 } | 41 } |
41 | 42 |
42 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 43 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
43 scoped_ptr<ClientSocketHandle> transport_socket, | 44 scoped_ptr<ClientSocketHandle> transport_socket, |
44 const HostPortPair& host_and_port, | 45 const HostPortPair& host_and_port, |
45 const SSLConfig& ssl_config, | 46 const SSLConfig& ssl_config, |
46 const SSLClientSocketContext& context) override { | 47 const SSLClientSocketContext& context) override { |
47 NOTIMPLEMENTED(); | 48 NOTIMPLEMENTED(); |
48 return scoped_ptr<SSLClientSocket>(); | 49 return scoped_ptr<SSLClientSocket>(); |
49 } | 50 } |
50 | 51 |
51 virtual void ClearSSLSessionCache() override { | 52 void ClearSSLSessionCache() override { NOTIMPLEMENTED(); } |
52 NOTIMPLEMENTED(); | |
53 } | |
54 | 53 |
55 private: | 54 private: |
56 std::list<SocketDataProvider*> data_providers_; | 55 std::list<SocketDataProvider*> data_providers_; |
57 }; | 56 }; |
58 | 57 |
59 struct PoolEvent { | 58 struct PoolEvent { |
60 enum { ALLOCATE, FREE } action; | 59 enum { ALLOCATE, FREE } action; |
61 unsigned server_index; | 60 unsigned server_index; |
62 }; | 61 }; |
63 | 62 |
(...skipping 17 matching lines...) Expand all Loading... |
81 private: | 80 private: |
82 bool ExpectEvent(const PoolEvent& event); | 81 bool ExpectEvent(const PoolEvent& event); |
83 std::list<PoolEvent> events_; | 82 std::list<PoolEvent> events_; |
84 }; | 83 }; |
85 | 84 |
86 class MockDnsSocketPool : public DnsSocketPool { | 85 class MockDnsSocketPool : public DnsSocketPool { |
87 public: | 86 public: |
88 MockDnsSocketPool(ClientSocketFactory* factory, DnsSessionTest* test) | 87 MockDnsSocketPool(ClientSocketFactory* factory, DnsSessionTest* test) |
89 : DnsSocketPool(factory), test_(test) { } | 88 : DnsSocketPool(factory), test_(test) { } |
90 | 89 |
91 virtual ~MockDnsSocketPool() { } | 90 ~MockDnsSocketPool() override {} |
92 | 91 |
93 virtual void Initialize( | 92 void Initialize(const std::vector<IPEndPoint>* nameservers, |
94 const std::vector<IPEndPoint>* nameservers, | 93 NetLog* net_log) override { |
95 NetLog* net_log) override { | |
96 InitializeInternal(nameservers, net_log); | 94 InitializeInternal(nameservers, net_log); |
97 } | 95 } |
98 | 96 |
99 virtual scoped_ptr<DatagramClientSocket> AllocateSocket( | 97 scoped_ptr<DatagramClientSocket> AllocateSocket( |
100 unsigned server_index) override { | 98 unsigned server_index) override { |
101 test_->OnSocketAllocated(server_index); | 99 test_->OnSocketAllocated(server_index); |
102 return CreateConnectedSocket(server_index); | 100 return CreateConnectedSocket(server_index); |
103 } | 101 } |
104 | 102 |
105 virtual void FreeSocket( | 103 void FreeSocket(unsigned server_index, |
106 unsigned server_index, | 104 scoped_ptr<DatagramClientSocket> socket) override { |
107 scoped_ptr<DatagramClientSocket> socket) override { | |
108 test_->OnSocketFreed(server_index); | 105 test_->OnSocketFreed(server_index); |
109 } | 106 } |
110 | 107 |
111 private: | 108 private: |
112 DnsSessionTest* test_; | 109 DnsSessionTest* test_; |
113 }; | 110 }; |
114 | 111 |
115 void DnsSessionTest::Initialize(unsigned num_servers) { | 112 void DnsSessionTest::Initialize(unsigned num_servers) { |
116 CHECK(num_servers < 256u); | 113 CHECK(num_servers < 256u); |
117 config_.nameservers.clear(); | 114 config_.nameservers.clear(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 TEST_F(DnsSessionTest, HistogramTimeoutLong) { | 240 TEST_F(DnsSessionTest, HistogramTimeoutLong) { |
244 config_.timeout = base::TimeDelta::FromSeconds(15); | 241 config_.timeout = base::TimeDelta::FromSeconds(15); |
245 Initialize(2); | 242 Initialize(2); |
246 base::TimeDelta timeout = session_->NextTimeout(0, 0); | 243 base::TimeDelta timeout = session_->NextTimeout(0, 0); |
247 EXPECT_EQ(config_.timeout.InMilliseconds(), timeout.InMilliseconds()); | 244 EXPECT_EQ(config_.timeout.InMilliseconds(), timeout.InMilliseconds()); |
248 } | 245 } |
249 | 246 |
250 } // namespace | 247 } // namespace |
251 | 248 |
252 } // namespace net | 249 } // namespace net |
OLD | NEW |