OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/socket/transport_client_socket_pool_test_util.h" | 5 #include "net/socket/transport_client_socket_pool_test_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // A StreamSocket which connects synchronously and successfully. | 31 // A StreamSocket which connects synchronously and successfully. |
32 class MockConnectClientSocket : public StreamSocket { | 32 class MockConnectClientSocket : public StreamSocket { |
33 public: | 33 public: |
34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 34 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
35 : connected_(false), | 35 : connected_(false), |
36 addrlist_(addrlist), | 36 addrlist_(addrlist), |
37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 37 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), |
38 use_tcp_fastopen_(false) {} | 38 use_tcp_fastopen_(false) {} |
39 | 39 |
40 // StreamSocket implementation. | 40 // StreamSocket implementation. |
41 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | 41 virtual int Connect(const CompletionCallback& callback) override { |
42 connected_ = true; | 42 connected_ = true; |
43 return OK; | 43 return OK; |
44 } | 44 } |
45 virtual void Disconnect() OVERRIDE { connected_ = false; } | 45 virtual void Disconnect() override { connected_ = false; } |
46 virtual bool IsConnected() const OVERRIDE { return connected_; } | 46 virtual bool IsConnected() const override { return connected_; } |
47 virtual bool IsConnectedAndIdle() const OVERRIDE { return connected_; } | 47 virtual bool IsConnectedAndIdle() const override { return connected_; } |
48 | 48 |
49 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | 49 virtual int GetPeerAddress(IPEndPoint* address) const override { |
50 *address = addrlist_.front(); | 50 *address = addrlist_.front(); |
51 return OK; | 51 return OK; |
52 } | 52 } |
53 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | 53 virtual int GetLocalAddress(IPEndPoint* address) const override { |
54 if (!connected_) | 54 if (!connected_) |
55 return ERR_SOCKET_NOT_CONNECTED; | 55 return ERR_SOCKET_NOT_CONNECTED; |
56 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) | 56 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) |
57 SetIPv4Address(address); | 57 SetIPv4Address(address); |
58 else | 58 else |
59 SetIPv6Address(address); | 59 SetIPv6Address(address); |
60 return OK; | 60 return OK; |
61 } | 61 } |
62 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } | 62 virtual const BoundNetLog& NetLog() const override { return net_log_; } |
63 | 63 |
64 virtual void SetSubresourceSpeculation() OVERRIDE {} | 64 virtual void SetSubresourceSpeculation() override {} |
65 virtual void SetOmniboxSpeculation() OVERRIDE {} | 65 virtual void SetOmniboxSpeculation() override {} |
66 virtual bool WasEverUsed() const OVERRIDE { return false; } | 66 virtual bool WasEverUsed() const override { return false; } |
67 virtual void EnableTCPFastOpenIfSupported() OVERRIDE { | 67 virtual void EnableTCPFastOpenIfSupported() override { |
68 use_tcp_fastopen_ = true; | 68 use_tcp_fastopen_ = true; |
69 } | 69 } |
70 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; } | 70 virtual bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
71 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } | 71 virtual bool WasNpnNegotiated() const override { return false; } |
72 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | 72 virtual NextProto GetNegotiatedProtocol() const override { |
73 return kProtoUnknown; | 73 return kProtoUnknown; |
74 } | 74 } |
75 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } | 75 virtual bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
76 | 76 |
77 // Socket implementation. | 77 // Socket implementation. |
78 virtual int Read(IOBuffer* buf, | 78 virtual int Read(IOBuffer* buf, |
79 int buf_len, | 79 int buf_len, |
80 const CompletionCallback& callback) OVERRIDE { | 80 const CompletionCallback& callback) override { |
81 return ERR_FAILED; | 81 return ERR_FAILED; |
82 } | 82 } |
83 virtual int Write(IOBuffer* buf, | 83 virtual int Write(IOBuffer* buf, |
84 int buf_len, | 84 int buf_len, |
85 const CompletionCallback& callback) OVERRIDE { | 85 const CompletionCallback& callback) override { |
86 return ERR_FAILED; | 86 return ERR_FAILED; |
87 } | 87 } |
88 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | 88 virtual int SetReceiveBufferSize(int32 size) override { return OK; } |
89 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | 89 virtual int SetSendBufferSize(int32 size) override { return OK; } |
90 | 90 |
91 private: | 91 private: |
92 bool connected_; | 92 bool connected_; |
93 const AddressList addrlist_; | 93 const AddressList addrlist_; |
94 BoundNetLog net_log_; | 94 BoundNetLog net_log_; |
95 bool use_tcp_fastopen_; | 95 bool use_tcp_fastopen_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); | 97 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); |
98 }; | 98 }; |
99 | 99 |
100 class MockFailingClientSocket : public StreamSocket { | 100 class MockFailingClientSocket : public StreamSocket { |
101 public: | 101 public: |
102 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 102 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
103 : addrlist_(addrlist), | 103 : addrlist_(addrlist), |
104 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 104 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), |
105 use_tcp_fastopen_(false) {} | 105 use_tcp_fastopen_(false) {} |
106 | 106 |
107 // StreamSocket implementation. | 107 // StreamSocket implementation. |
108 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | 108 virtual int Connect(const CompletionCallback& callback) override { |
109 return ERR_CONNECTION_FAILED; | 109 return ERR_CONNECTION_FAILED; |
110 } | 110 } |
111 | 111 |
112 virtual void Disconnect() OVERRIDE {} | 112 virtual void Disconnect() override {} |
113 | 113 |
114 virtual bool IsConnected() const OVERRIDE { return false; } | 114 virtual bool IsConnected() const override { return false; } |
115 virtual bool IsConnectedAndIdle() const OVERRIDE { return false; } | 115 virtual bool IsConnectedAndIdle() const override { return false; } |
116 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | 116 virtual int GetPeerAddress(IPEndPoint* address) const override { |
117 return ERR_UNEXPECTED; | 117 return ERR_UNEXPECTED; |
118 } | 118 } |
119 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | 119 virtual int GetLocalAddress(IPEndPoint* address) const override { |
120 return ERR_UNEXPECTED; | 120 return ERR_UNEXPECTED; |
121 } | 121 } |
122 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } | 122 virtual const BoundNetLog& NetLog() const override { return net_log_; } |
123 | 123 |
124 virtual void SetSubresourceSpeculation() OVERRIDE {} | 124 virtual void SetSubresourceSpeculation() override {} |
125 virtual void SetOmniboxSpeculation() OVERRIDE {} | 125 virtual void SetOmniboxSpeculation() override {} |
126 virtual bool WasEverUsed() const OVERRIDE { return false; } | 126 virtual bool WasEverUsed() const override { return false; } |
127 virtual void EnableTCPFastOpenIfSupported() OVERRIDE { | 127 virtual void EnableTCPFastOpenIfSupported() override { |
128 use_tcp_fastopen_ = true; | 128 use_tcp_fastopen_ = true; |
129 } | 129 } |
130 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; } | 130 virtual bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
131 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } | 131 virtual bool WasNpnNegotiated() const override { return false; } |
132 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | 132 virtual NextProto GetNegotiatedProtocol() const override { |
133 return kProtoUnknown; | 133 return kProtoUnknown; |
134 } | 134 } |
135 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } | 135 virtual bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
136 | 136 |
137 // Socket implementation. | 137 // Socket implementation. |
138 virtual int Read(IOBuffer* buf, | 138 virtual int Read(IOBuffer* buf, |
139 int buf_len, | 139 int buf_len, |
140 const CompletionCallback& callback) OVERRIDE { | 140 const CompletionCallback& callback) override { |
141 return ERR_FAILED; | 141 return ERR_FAILED; |
142 } | 142 } |
143 | 143 |
144 virtual int Write(IOBuffer* buf, | 144 virtual int Write(IOBuffer* buf, |
145 int buf_len, | 145 int buf_len, |
146 const CompletionCallback& callback) OVERRIDE { | 146 const CompletionCallback& callback) override { |
147 return ERR_FAILED; | 147 return ERR_FAILED; |
148 } | 148 } |
149 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | 149 virtual int SetReceiveBufferSize(int32 size) override { return OK; } |
150 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | 150 virtual int SetSendBufferSize(int32 size) override { return OK; } |
151 | 151 |
152 private: | 152 private: |
153 const AddressList addrlist_; | 153 const AddressList addrlist_; |
154 BoundNetLog net_log_; | 154 BoundNetLog net_log_; |
155 bool use_tcp_fastopen_; | 155 bool use_tcp_fastopen_; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); | 157 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); |
158 }; | 158 }; |
159 | 159 |
160 class MockTriggerableClientSocket : public StreamSocket { | 160 class MockTriggerableClientSocket : public StreamSocket { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( | 205 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( |
206 const AddressList& addrlist, | 206 const AddressList& addrlist, |
207 net::NetLog* net_log) { | 207 net::NetLog* net_log) { |
208 scoped_ptr<MockTriggerableClientSocket> socket( | 208 scoped_ptr<MockTriggerableClientSocket> socket( |
209 new MockTriggerableClientSocket(addrlist, true, net_log)); | 209 new MockTriggerableClientSocket(addrlist, true, net_log)); |
210 return socket.PassAs<StreamSocket>(); | 210 return socket.PassAs<StreamSocket>(); |
211 } | 211 } |
212 | 212 |
213 // StreamSocket implementation. | 213 // StreamSocket implementation. |
214 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | 214 virtual int Connect(const CompletionCallback& callback) override { |
215 DCHECK(callback_.is_null()); | 215 DCHECK(callback_.is_null()); |
216 callback_ = callback; | 216 callback_ = callback; |
217 return ERR_IO_PENDING; | 217 return ERR_IO_PENDING; |
218 } | 218 } |
219 | 219 |
220 virtual void Disconnect() OVERRIDE {} | 220 virtual void Disconnect() override {} |
221 | 221 |
222 virtual bool IsConnected() const OVERRIDE { return is_connected_; } | 222 virtual bool IsConnected() const override { return is_connected_; } |
223 virtual bool IsConnectedAndIdle() const OVERRIDE { return is_connected_; } | 223 virtual bool IsConnectedAndIdle() const override { return is_connected_; } |
224 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | 224 virtual int GetPeerAddress(IPEndPoint* address) const override { |
225 *address = addrlist_.front(); | 225 *address = addrlist_.front(); |
226 return OK; | 226 return OK; |
227 } | 227 } |
228 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | 228 virtual int GetLocalAddress(IPEndPoint* address) const override { |
229 if (!is_connected_) | 229 if (!is_connected_) |
230 return ERR_SOCKET_NOT_CONNECTED; | 230 return ERR_SOCKET_NOT_CONNECTED; |
231 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) | 231 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) |
232 SetIPv4Address(address); | 232 SetIPv4Address(address); |
233 else | 233 else |
234 SetIPv6Address(address); | 234 SetIPv6Address(address); |
235 return OK; | 235 return OK; |
236 } | 236 } |
237 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } | 237 virtual const BoundNetLog& NetLog() const override { return net_log_; } |
238 | 238 |
239 virtual void SetSubresourceSpeculation() OVERRIDE {} | 239 virtual void SetSubresourceSpeculation() override {} |
240 virtual void SetOmniboxSpeculation() OVERRIDE {} | 240 virtual void SetOmniboxSpeculation() override {} |
241 virtual bool WasEverUsed() const OVERRIDE { return false; } | 241 virtual bool WasEverUsed() const override { return false; } |
242 virtual void EnableTCPFastOpenIfSupported() OVERRIDE { | 242 virtual void EnableTCPFastOpenIfSupported() override { |
243 use_tcp_fastopen_ = true; | 243 use_tcp_fastopen_ = true; |
244 } | 244 } |
245 virtual bool UsingTCPFastOpen() const OVERRIDE { return use_tcp_fastopen_; } | 245 virtual bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
246 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } | 246 virtual bool WasNpnNegotiated() const override { return false; } |
247 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | 247 virtual NextProto GetNegotiatedProtocol() const override { |
248 return kProtoUnknown; | 248 return kProtoUnknown; |
249 } | 249 } |
250 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } | 250 virtual bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
251 | 251 |
252 // Socket implementation. | 252 // Socket implementation. |
253 virtual int Read(IOBuffer* buf, | 253 virtual int Read(IOBuffer* buf, |
254 int buf_len, | 254 int buf_len, |
255 const CompletionCallback& callback) OVERRIDE { | 255 const CompletionCallback& callback) override { |
256 return ERR_FAILED; | 256 return ERR_FAILED; |
257 } | 257 } |
258 | 258 |
259 virtual int Write(IOBuffer* buf, | 259 virtual int Write(IOBuffer* buf, |
260 int buf_len, | 260 int buf_len, |
261 const CompletionCallback& callback) OVERRIDE { | 261 const CompletionCallback& callback) override { |
262 return ERR_FAILED; | 262 return ERR_FAILED; |
263 } | 263 } |
264 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | 264 virtual int SetReceiveBufferSize(int32 size) override { return OK; } |
265 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | 265 virtual int SetSendBufferSize(int32 size) override { return OK; } |
266 | 266 |
267 private: | 267 private: |
268 void DoCallback() { | 268 void DoCallback() { |
269 is_connected_ = should_connect_; | 269 is_connected_ = should_connect_; |
270 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); | 270 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); |
271 } | 271 } |
272 | 272 |
273 bool should_connect_; | 273 bool should_connect_; |
274 bool is_connected_; | 274 bool is_connected_; |
275 const AddressList addrlist_; | 275 const AddressList addrlist_; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 run_loop_quit_closure_ = run_loop.QuitClosure(); | 427 run_loop_quit_closure_ = run_loop.QuitClosure(); |
428 run_loop.Run(); | 428 run_loop.Run(); |
429 run_loop_quit_closure_.Reset(); | 429 run_loop_quit_closure_.Reset(); |
430 } | 430 } |
431 base::Closure trigger = triggerable_sockets_.front(); | 431 base::Closure trigger = triggerable_sockets_.front(); |
432 triggerable_sockets_.pop(); | 432 triggerable_sockets_.pop(); |
433 return trigger; | 433 return trigger; |
434 } | 434 } |
435 | 435 |
436 } // namespace net | 436 } // namespace net |
OLD | NEW |