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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const BoundNetLog& NetLog() const override { return net_log_; } | 62 const BoundNetLog& NetLog() const override { return net_log_; } |
63 | 63 |
64 void SetSubresourceSpeculation() override {} | 64 void SetSubresourceSpeculation() override {} |
65 void SetOmniboxSpeculation() override {} | 65 void SetOmniboxSpeculation() override {} |
66 bool WasEverUsed() const override { return false; } | 66 bool WasEverUsed() const override { return false; } |
67 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 67 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } |
68 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | 68 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
69 bool WasNpnNegotiated() const override { return false; } | 69 bool WasNpnNegotiated() const override { return false; } |
70 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 70 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
71 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 71 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 72 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 73 out->clear(); |
| 74 } |
| 75 void ClearConnectionAttempts() override {} |
| 76 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
72 | 77 |
73 // Socket implementation. | 78 // Socket implementation. |
74 int Read(IOBuffer* buf, | 79 int Read(IOBuffer* buf, |
75 int buf_len, | 80 int buf_len, |
76 const CompletionCallback& callback) override { | 81 const CompletionCallback& callback) override { |
77 return ERR_FAILED; | 82 return ERR_FAILED; |
78 } | 83 } |
79 int Write(IOBuffer* buf, | 84 int Write(IOBuffer* buf, |
80 int buf_len, | 85 int buf_len, |
81 const CompletionCallback& callback) override { | 86 const CompletionCallback& callback) override { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 const BoundNetLog& NetLog() const override { return net_log_; } | 123 const BoundNetLog& NetLog() const override { return net_log_; } |
119 | 124 |
120 void SetSubresourceSpeculation() override {} | 125 void SetSubresourceSpeculation() override {} |
121 void SetOmniboxSpeculation() override {} | 126 void SetOmniboxSpeculation() override {} |
122 bool WasEverUsed() const override { return false; } | 127 bool WasEverUsed() const override { return false; } |
123 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 128 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } |
124 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | 129 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
125 bool WasNpnNegotiated() const override { return false; } | 130 bool WasNpnNegotiated() const override { return false; } |
126 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 131 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
127 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 132 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 133 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 134 out->clear(); |
| 135 for (const auto& addr : addrlist_) |
| 136 out->push_back(ConnectionAttempt(addr, ERR_CONNECTION_FAILED)); |
| 137 } |
| 138 void ClearConnectionAttempts() override {} |
| 139 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
128 | 140 |
129 // Socket implementation. | 141 // Socket implementation. |
130 int Read(IOBuffer* buf, | 142 int Read(IOBuffer* buf, |
131 int buf_len, | 143 int buf_len, |
132 const CompletionCallback& callback) override { | 144 const CompletionCallback& callback) override { |
133 return ERR_FAILED; | 145 return ERR_FAILED; |
134 } | 146 } |
135 | 147 |
136 int Write(IOBuffer* buf, | 148 int Write(IOBuffer* buf, |
137 int buf_len, | 149 int buf_len, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 net::NetLog* net_log) { | 201 net::NetLog* net_log) { |
190 scoped_ptr<MockTriggerableClientSocket> socket( | 202 scoped_ptr<MockTriggerableClientSocket> socket( |
191 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); | 203 new MockTriggerableClientSocket(addrlist, should_connect, net_log)); |
192 base::MessageLoop::current()->PostDelayedTask( | 204 base::MessageLoop::current()->PostDelayedTask( |
193 FROM_HERE, socket->GetConnectCallback(), delay); | 205 FROM_HERE, socket->GetConnectCallback(), delay); |
194 return socket.Pass(); | 206 return socket.Pass(); |
195 } | 207 } |
196 | 208 |
197 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( | 209 static scoped_ptr<StreamSocket> MakeMockStalledClientSocket( |
198 const AddressList& addrlist, | 210 const AddressList& addrlist, |
199 net::NetLog* net_log) { | 211 net::NetLog* net_log, |
| 212 bool failing) { |
200 scoped_ptr<MockTriggerableClientSocket> socket( | 213 scoped_ptr<MockTriggerableClientSocket> socket( |
201 new MockTriggerableClientSocket(addrlist, true, net_log)); | 214 new MockTriggerableClientSocket(addrlist, true, net_log)); |
| 215 if (failing) { |
| 216 DCHECK_LE(1u, addrlist.size()); |
| 217 ConnectionAttempts attempts; |
| 218 attempts.push_back(ConnectionAttempt(addrlist[0], ERR_CONNECTION_FAILED)); |
| 219 socket->AddConnectionAttempts(attempts); |
| 220 } |
202 return socket.Pass(); | 221 return socket.Pass(); |
203 } | 222 } |
204 | 223 |
205 // StreamSocket implementation. | 224 // StreamSocket implementation. |
206 int Connect(const CompletionCallback& callback) override { | 225 int Connect(const CompletionCallback& callback) override { |
207 DCHECK(callback_.is_null()); | 226 DCHECK(callback_.is_null()); |
208 callback_ = callback; | 227 callback_ = callback; |
209 return ERR_IO_PENDING; | 228 return ERR_IO_PENDING; |
210 } | 229 } |
211 | 230 |
(...skipping 17 matching lines...) Expand all Loading... |
229 const BoundNetLog& NetLog() const override { return net_log_; } | 248 const BoundNetLog& NetLog() const override { return net_log_; } |
230 | 249 |
231 void SetSubresourceSpeculation() override {} | 250 void SetSubresourceSpeculation() override {} |
232 void SetOmniboxSpeculation() override {} | 251 void SetOmniboxSpeculation() override {} |
233 bool WasEverUsed() const override { return false; } | 252 bool WasEverUsed() const override { return false; } |
234 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 253 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } |
235 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | 254 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } |
236 bool WasNpnNegotiated() const override { return false; } | 255 bool WasNpnNegotiated() const override { return false; } |
237 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 256 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
238 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 257 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 258 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 259 *out = connection_attempts_; |
| 260 } |
| 261 void ClearConnectionAttempts() override { connection_attempts_.clear(); } |
| 262 void AddConnectionAttempts(const ConnectionAttempts& attempts) override { |
| 263 connection_attempts_.insert(connection_attempts_.begin(), attempts.begin(), |
| 264 attempts.end()); |
| 265 } |
239 | 266 |
240 // Socket implementation. | 267 // Socket implementation. |
241 int Read(IOBuffer* buf, | 268 int Read(IOBuffer* buf, |
242 int buf_len, | 269 int buf_len, |
243 const CompletionCallback& callback) override { | 270 const CompletionCallback& callback) override { |
244 return ERR_FAILED; | 271 return ERR_FAILED; |
245 } | 272 } |
246 | 273 |
247 int Write(IOBuffer* buf, | 274 int Write(IOBuffer* buf, |
248 int buf_len, | 275 int buf_len, |
249 const CompletionCallback& callback) override { | 276 const CompletionCallback& callback) override { |
250 return ERR_FAILED; | 277 return ERR_FAILED; |
251 } | 278 } |
252 int SetReceiveBufferSize(int32 size) override { return OK; } | 279 int SetReceiveBufferSize(int32 size) override { return OK; } |
253 int SetSendBufferSize(int32 size) override { return OK; } | 280 int SetSendBufferSize(int32 size) override { return OK; } |
254 | 281 |
255 private: | 282 private: |
256 void DoCallback() { | 283 void DoCallback() { |
257 is_connected_ = should_connect_; | 284 is_connected_ = should_connect_; |
258 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); | 285 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); |
259 } | 286 } |
260 | 287 |
261 bool should_connect_; | 288 bool should_connect_; |
262 bool is_connected_; | 289 bool is_connected_; |
263 const AddressList addrlist_; | 290 const AddressList addrlist_; |
264 BoundNetLog net_log_; | 291 BoundNetLog net_log_; |
265 CompletionCallback callback_; | 292 CompletionCallback callback_; |
266 bool use_tcp_fastopen_; | 293 bool use_tcp_fastopen_; |
| 294 ConnectionAttempts connection_attempts_; |
267 | 295 |
268 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; | 296 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; |
269 | 297 |
270 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); | 298 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); |
271 }; | 299 }; |
272 | 300 |
273 } // namespace | 301 } // namespace |
274 | 302 |
275 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | 303 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { |
276 LoadTimingInfo load_timing_info; | 304 LoadTimingInfo load_timing_info; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 case MOCK_PENDING_FAILING_CLIENT_SOCKET: | 385 case MOCK_PENDING_FAILING_CLIENT_SOCKET: |
358 return MockTriggerableClientSocket::MakeMockPendingClientSocket( | 386 return MockTriggerableClientSocket::MakeMockPendingClientSocket( |
359 addresses, false, net_log_); | 387 addresses, false, net_log_); |
360 case MOCK_DELAYED_CLIENT_SOCKET: | 388 case MOCK_DELAYED_CLIENT_SOCKET: |
361 return MockTriggerableClientSocket::MakeMockDelayedClientSocket( | 389 return MockTriggerableClientSocket::MakeMockDelayedClientSocket( |
362 addresses, true, delay_, net_log_); | 390 addresses, true, delay_, net_log_); |
363 case MOCK_DELAYED_FAILING_CLIENT_SOCKET: | 391 case MOCK_DELAYED_FAILING_CLIENT_SOCKET: |
364 return MockTriggerableClientSocket::MakeMockDelayedClientSocket( | 392 return MockTriggerableClientSocket::MakeMockDelayedClientSocket( |
365 addresses, false, delay_, net_log_); | 393 addresses, false, delay_, net_log_); |
366 case MOCK_STALLED_CLIENT_SOCKET: | 394 case MOCK_STALLED_CLIENT_SOCKET: |
367 return MockTriggerableClientSocket::MakeMockStalledClientSocket(addresses, | 395 return MockTriggerableClientSocket::MakeMockStalledClientSocket( |
368 net_log_); | 396 addresses, net_log_, false); |
| 397 case MOCK_STALLED_FAILING_CLIENT_SOCKET: |
| 398 return MockTriggerableClientSocket::MakeMockStalledClientSocket( |
| 399 addresses, net_log_, true); |
369 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { | 400 case MOCK_TRIGGERABLE_CLIENT_SOCKET: { |
370 scoped_ptr<MockTriggerableClientSocket> rv( | 401 scoped_ptr<MockTriggerableClientSocket> rv( |
371 new MockTriggerableClientSocket(addresses, true, net_log_)); | 402 new MockTriggerableClientSocket(addresses, true, net_log_)); |
372 triggerable_sockets_.push(rv->GetConnectCallback()); | 403 triggerable_sockets_.push(rv->GetConnectCallback()); |
373 // run_loop_quit_closure_ behaves like a condition variable. It will | 404 // run_loop_quit_closure_ behaves like a condition variable. It will |
374 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We | 405 // wake up WaitForTriggerableSocketCreation() if it is sleeping. We |
375 // don't need to worry about atomicity because this code is | 406 // don't need to worry about atomicity because this code is |
376 // single-threaded. | 407 // single-threaded. |
377 if (!run_loop_quit_closure_.is_null()) | 408 if (!run_loop_quit_closure_.is_null()) |
378 run_loop_quit_closure_.Run(); | 409 run_loop_quit_closure_.Run(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 run_loop_quit_closure_ = run_loop.QuitClosure(); | 446 run_loop_quit_closure_ = run_loop.QuitClosure(); |
416 run_loop.Run(); | 447 run_loop.Run(); |
417 run_loop_quit_closure_.Reset(); | 448 run_loop_quit_closure_.Reset(); |
418 } | 449 } |
419 base::Closure trigger = triggerable_sockets_.front(); | 450 base::Closure trigger = triggerable_sockets_.front(); |
420 triggerable_sockets_.pop(); | 451 triggerable_sockets_.pop(); |
421 return trigger; | 452 return trigger; |
422 } | 453 } |
423 | 454 |
424 } // namespace net | 455 } // namespace net |
OLD | NEW |