| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 CHECK(address.AssignFromIPLiteral(ip)); | 33 CHECK(address.AssignFromIPLiteral(ip)); |
| 34 return address; | 34 return address; |
| 35 } | 35 } |
| 36 | 36 |
| 37 // A StreamSocket which connects synchronously and successfully. | 37 // A StreamSocket which connects synchronously and successfully. |
| 38 class MockConnectClientSocket : public StreamSocket { | 38 class MockConnectClientSocket : public StreamSocket { |
| 39 public: | 39 public: |
| 40 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 40 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
| 41 : connected_(false), | 41 : connected_(false), |
| 42 addrlist_(addrlist), | 42 addrlist_(addrlist), |
| 43 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 43 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} |
| 44 use_tcp_fastopen_(false) {} | |
| 45 | 44 |
| 46 // StreamSocket implementation. | 45 // StreamSocket implementation. |
| 47 int Connect(const CompletionCallback& callback) override { | 46 int Connect(const CompletionCallback& callback) override { |
| 48 connected_ = true; | 47 connected_ = true; |
| 49 return OK; | 48 return OK; |
| 50 } | 49 } |
| 51 void Disconnect() override { connected_ = false; } | 50 void Disconnect() override { connected_ = false; } |
| 52 bool IsConnected() const override { return connected_; } | 51 bool IsConnected() const override { return connected_; } |
| 53 bool IsConnectedAndIdle() const override { return connected_; } | 52 bool IsConnectedAndIdle() const override { return connected_; } |
| 54 | 53 |
| 55 int GetPeerAddress(IPEndPoint* address) const override { | 54 int GetPeerAddress(IPEndPoint* address) const override { |
| 56 *address = addrlist_.front(); | 55 *address = addrlist_.front(); |
| 57 return OK; | 56 return OK; |
| 58 } | 57 } |
| 59 int GetLocalAddress(IPEndPoint* address) const override { | 58 int GetLocalAddress(IPEndPoint* address) const override { |
| 60 if (!connected_) | 59 if (!connected_) |
| 61 return ERR_SOCKET_NOT_CONNECTED; | 60 return ERR_SOCKET_NOT_CONNECTED; |
| 62 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) | 61 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) |
| 63 SetIPv4Address(address); | 62 SetIPv4Address(address); |
| 64 else | 63 else |
| 65 SetIPv6Address(address); | 64 SetIPv6Address(address); |
| 66 return OK; | 65 return OK; |
| 67 } | 66 } |
| 68 const BoundNetLog& NetLog() const override { return net_log_; } | 67 const BoundNetLog& NetLog() const override { return net_log_; } |
| 69 | 68 |
| 70 void SetSubresourceSpeculation() override {} | 69 void SetSubresourceSpeculation() override {} |
| 71 void SetOmniboxSpeculation() override {} | 70 void SetOmniboxSpeculation() override {} |
| 72 bool WasEverUsed() const override { return false; } | 71 bool WasEverUsed() const override { return false; } |
| 73 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 72 void EnableTCPFastOpenIfSupported() override {} |
| 74 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | |
| 75 bool WasNpnNegotiated() const override { return false; } | 73 bool WasNpnNegotiated() const override { return false; } |
| 76 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 74 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 77 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 75 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 78 void GetConnectionAttempts(ConnectionAttempts* out) const override { | 76 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 79 out->clear(); | 77 out->clear(); |
| 80 } | 78 } |
| 81 void ClearConnectionAttempts() override {} | 79 void ClearConnectionAttempts() override {} |
| 82 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} | 80 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
| 83 int64_t GetTotalReceivedBytes() const override { | 81 int64_t GetTotalReceivedBytes() const override { |
| 84 NOTIMPLEMENTED(); | 82 NOTIMPLEMENTED(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 const CompletionCallback& callback) override { | 94 const CompletionCallback& callback) override { |
| 97 return ERR_FAILED; | 95 return ERR_FAILED; |
| 98 } | 96 } |
| 99 int SetReceiveBufferSize(int32_t size) override { return OK; } | 97 int SetReceiveBufferSize(int32_t size) override { return OK; } |
| 100 int SetSendBufferSize(int32_t size) override { return OK; } | 98 int SetSendBufferSize(int32_t size) override { return OK; } |
| 101 | 99 |
| 102 private: | 100 private: |
| 103 bool connected_; | 101 bool connected_; |
| 104 const AddressList addrlist_; | 102 const AddressList addrlist_; |
| 105 BoundNetLog net_log_; | 103 BoundNetLog net_log_; |
| 106 bool use_tcp_fastopen_; | |
| 107 | 104 |
| 108 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); | 105 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); |
| 109 }; | 106 }; |
| 110 | 107 |
| 111 class MockFailingClientSocket : public StreamSocket { | 108 class MockFailingClientSocket : public StreamSocket { |
| 112 public: | 109 public: |
| 113 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 110 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
| 114 : addrlist_(addrlist), | 111 : addrlist_(addrlist), |
| 115 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 112 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} |
| 116 use_tcp_fastopen_(false) {} | |
| 117 | 113 |
| 118 // StreamSocket implementation. | 114 // StreamSocket implementation. |
| 119 int Connect(const CompletionCallback& callback) override { | 115 int Connect(const CompletionCallback& callback) override { |
| 120 return ERR_CONNECTION_FAILED; | 116 return ERR_CONNECTION_FAILED; |
| 121 } | 117 } |
| 122 | 118 |
| 123 void Disconnect() override {} | 119 void Disconnect() override {} |
| 124 | 120 |
| 125 bool IsConnected() const override { return false; } | 121 bool IsConnected() const override { return false; } |
| 126 bool IsConnectedAndIdle() const override { return false; } | 122 bool IsConnectedAndIdle() const override { return false; } |
| 127 int GetPeerAddress(IPEndPoint* address) const override { | 123 int GetPeerAddress(IPEndPoint* address) const override { |
| 128 return ERR_UNEXPECTED; | 124 return ERR_UNEXPECTED; |
| 129 } | 125 } |
| 130 int GetLocalAddress(IPEndPoint* address) const override { | 126 int GetLocalAddress(IPEndPoint* address) const override { |
| 131 return ERR_UNEXPECTED; | 127 return ERR_UNEXPECTED; |
| 132 } | 128 } |
| 133 const BoundNetLog& NetLog() const override { return net_log_; } | 129 const BoundNetLog& NetLog() const override { return net_log_; } |
| 134 | 130 |
| 135 void SetSubresourceSpeculation() override {} | 131 void SetSubresourceSpeculation() override {} |
| 136 void SetOmniboxSpeculation() override {} | 132 void SetOmniboxSpeculation() override {} |
| 137 bool WasEverUsed() const override { return false; } | 133 bool WasEverUsed() const override { return false; } |
| 138 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 134 void EnableTCPFastOpenIfSupported() override {} |
| 139 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | |
| 140 bool WasNpnNegotiated() const override { return false; } | 135 bool WasNpnNegotiated() const override { return false; } |
| 141 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 136 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 142 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 137 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 143 void GetConnectionAttempts(ConnectionAttempts* out) const override { | 138 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 144 out->clear(); | 139 out->clear(); |
| 145 for (const auto& addr : addrlist_) | 140 for (const auto& addr : addrlist_) |
| 146 out->push_back(ConnectionAttempt(addr, ERR_CONNECTION_FAILED)); | 141 out->push_back(ConnectionAttempt(addr, ERR_CONNECTION_FAILED)); |
| 147 } | 142 } |
| 148 void ClearConnectionAttempts() override {} | 143 void ClearConnectionAttempts() override {} |
| 149 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} | 144 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 163 int buf_len, | 158 int buf_len, |
| 164 const CompletionCallback& callback) override { | 159 const CompletionCallback& callback) override { |
| 165 return ERR_FAILED; | 160 return ERR_FAILED; |
| 166 } | 161 } |
| 167 int SetReceiveBufferSize(int32_t size) override { return OK; } | 162 int SetReceiveBufferSize(int32_t size) override { return OK; } |
| 168 int SetSendBufferSize(int32_t size) override { return OK; } | 163 int SetSendBufferSize(int32_t size) override { return OK; } |
| 169 | 164 |
| 170 private: | 165 private: |
| 171 const AddressList addrlist_; | 166 const AddressList addrlist_; |
| 172 BoundNetLog net_log_; | 167 BoundNetLog net_log_; |
| 173 bool use_tcp_fastopen_; | |
| 174 | 168 |
| 175 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); | 169 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); |
| 176 }; | 170 }; |
| 177 | 171 |
| 178 class MockTriggerableClientSocket : public StreamSocket { | 172 class MockTriggerableClientSocket : public StreamSocket { |
| 179 public: | 173 public: |
| 180 // |should_connect| indicates whether the socket should successfully complete | 174 // |should_connect| indicates whether the socket should successfully complete |
| 181 // or fail. | 175 // or fail. |
| 182 MockTriggerableClientSocket(const AddressList& addrlist, | 176 MockTriggerableClientSocket(const AddressList& addrlist, |
| 183 bool should_connect, | 177 bool should_connect, |
| 184 net::NetLog* net_log) | 178 net::NetLog* net_log) |
| 185 : should_connect_(should_connect), | 179 : should_connect_(should_connect), |
| 186 is_connected_(false), | 180 is_connected_(false), |
| 187 addrlist_(addrlist), | 181 addrlist_(addrlist), |
| 188 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 182 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), |
| 189 use_tcp_fastopen_(false), | |
| 190 weak_factory_(this) {} | 183 weak_factory_(this) {} |
| 191 | 184 |
| 192 // Call this method to get a closure which will trigger the connect callback | 185 // Call this method to get a closure which will trigger the connect callback |
| 193 // when called. The closure can be called even after the socket is deleted; it | 186 // when called. The closure can be called even after the socket is deleted; it |
| 194 // will safely do nothing. | 187 // will safely do nothing. |
| 195 base::Closure GetConnectCallback() { | 188 base::Closure GetConnectCallback() { |
| 196 return base::Bind(&MockTriggerableClientSocket::DoCallback, | 189 return base::Bind(&MockTriggerableClientSocket::DoCallback, |
| 197 weak_factory_.GetWeakPtr()); | 190 weak_factory_.GetWeakPtr()); |
| 198 } | 191 } |
| 199 | 192 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 SetIPv4Address(address); | 250 SetIPv4Address(address); |
| 258 else | 251 else |
| 259 SetIPv6Address(address); | 252 SetIPv6Address(address); |
| 260 return OK; | 253 return OK; |
| 261 } | 254 } |
| 262 const BoundNetLog& NetLog() const override { return net_log_; } | 255 const BoundNetLog& NetLog() const override { return net_log_; } |
| 263 | 256 |
| 264 void SetSubresourceSpeculation() override {} | 257 void SetSubresourceSpeculation() override {} |
| 265 void SetOmniboxSpeculation() override {} | 258 void SetOmniboxSpeculation() override {} |
| 266 bool WasEverUsed() const override { return false; } | 259 bool WasEverUsed() const override { return false; } |
| 267 void EnableTCPFastOpenIfSupported() override { use_tcp_fastopen_ = true; } | 260 void EnableTCPFastOpenIfSupported() override {} |
| 268 bool UsingTCPFastOpen() const override { return use_tcp_fastopen_; } | |
| 269 bool WasNpnNegotiated() const override { return false; } | 261 bool WasNpnNegotiated() const override { return false; } |
| 270 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } | 262 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; } |
| 271 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } | 263 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; } |
| 272 void GetConnectionAttempts(ConnectionAttempts* out) const override { | 264 void GetConnectionAttempts(ConnectionAttempts* out) const override { |
| 273 *out = connection_attempts_; | 265 *out = connection_attempts_; |
| 274 } | 266 } |
| 275 void ClearConnectionAttempts() override { connection_attempts_.clear(); } | 267 void ClearConnectionAttempts() override { connection_attempts_.clear(); } |
| 276 void AddConnectionAttempts(const ConnectionAttempts& attempts) override { | 268 void AddConnectionAttempts(const ConnectionAttempts& attempts) override { |
| 277 connection_attempts_.insert(connection_attempts_.begin(), attempts.begin(), | 269 connection_attempts_.insert(connection_attempts_.begin(), attempts.begin(), |
| 278 attempts.end()); | 270 attempts.end()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 301 void DoCallback() { | 293 void DoCallback() { |
| 302 is_connected_ = should_connect_; | 294 is_connected_ = should_connect_; |
| 303 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); | 295 callback_.Run(is_connected_ ? OK : ERR_CONNECTION_FAILED); |
| 304 } | 296 } |
| 305 | 297 |
| 306 bool should_connect_; | 298 bool should_connect_; |
| 307 bool is_connected_; | 299 bool is_connected_; |
| 308 const AddressList addrlist_; | 300 const AddressList addrlist_; |
| 309 BoundNetLog net_log_; | 301 BoundNetLog net_log_; |
| 310 CompletionCallback callback_; | 302 CompletionCallback callback_; |
| 311 bool use_tcp_fastopen_; | |
| 312 ConnectionAttempts connection_attempts_; | 303 ConnectionAttempts connection_attempts_; |
| 313 | 304 |
| 314 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; | 305 base::WeakPtrFactory<MockTriggerableClientSocket> weak_factory_; |
| 315 | 306 |
| 316 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); | 307 DISALLOW_COPY_AND_ASSIGN(MockTriggerableClientSocket); |
| 317 }; | 308 }; |
| 318 | 309 |
| 319 } // namespace | 310 } // namespace |
| 320 | 311 |
| 321 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | 312 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 run_loop_quit_closure_ = run_loop.QuitClosure(); | 455 run_loop_quit_closure_ = run_loop.QuitClosure(); |
| 465 run_loop.Run(); | 456 run_loop.Run(); |
| 466 run_loop_quit_closure_.Reset(); | 457 run_loop_quit_closure_.Reset(); |
| 467 } | 458 } |
| 468 base::Closure trigger = triggerable_sockets_.front(); | 459 base::Closure trigger = triggerable_sockets_.front(); |
| 469 triggerable_sockets_.pop(); | 460 triggerable_sockets_.pop(); |
| 470 return trigger; | 461 return trigger; |
| 471 } | 462 } |
| 472 | 463 |
| 473 } // namespace net | 464 } // namespace net |
| OLD | NEW |