| 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 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "net/base/ip_address.h" | 18 #include "net/base/ip_address.h" |
| 19 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
| 20 #include "net/base/load_timing_info.h" | 20 #include "net/base/load_timing_info.h" |
| 21 #include "net/base/load_timing_info_test_util.h" | 21 #include "net/base/load_timing_info_test_util.h" |
| 22 #include "net/log/net_log_source_type.h" |
| 22 #include "net/socket/client_socket_handle.h" | 23 #include "net/socket/client_socket_handle.h" |
| 23 #include "net/socket/ssl_client_socket.h" | 24 #include "net/socket/ssl_client_socket.h" |
| 24 #include "net/udp/datagram_client_socket.h" | 25 #include "net/udp/datagram_client_socket.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 IPAddress ParseIP(const std::string& ip) { | 32 IPAddress ParseIP(const std::string& ip) { |
| 32 IPAddress address; | 33 IPAddress address; |
| 33 CHECK(address.AssignFromIPLiteral(ip)); | 34 CHECK(address.AssignFromIPLiteral(ip)); |
| 34 return address; | 35 return address; |
| 35 } | 36 } |
| 36 | 37 |
| 37 // A StreamSocket which connects synchronously and successfully. | 38 // A StreamSocket which connects synchronously and successfully. |
| 38 class MockConnectClientSocket : public StreamSocket { | 39 class MockConnectClientSocket : public StreamSocket { |
| 39 public: | 40 public: |
| 40 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 41 MockConnectClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
| 41 : connected_(false), | 42 : connected_(false), |
| 42 addrlist_(addrlist), | 43 addrlist_(addrlist), |
| 43 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} | 44 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)) {} |
| 44 | 45 |
| 45 // StreamSocket implementation. | 46 // StreamSocket implementation. |
| 46 int Connect(const CompletionCallback& callback) override { | 47 int Connect(const CompletionCallback& callback) override { |
| 47 connected_ = true; | 48 connected_ = true; |
| 48 return OK; | 49 return OK; |
| 49 } | 50 } |
| 50 void Disconnect() override { connected_ = false; } | 51 void Disconnect() override { connected_ = false; } |
| 51 bool IsConnected() const override { return connected_; } | 52 bool IsConnected() const override { return connected_; } |
| 52 bool IsConnectedAndIdle() const override { return connected_; } | 53 bool IsConnectedAndIdle() const override { return connected_; } |
| 53 | 54 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 const AddressList addrlist_; | 103 const AddressList addrlist_; |
| 103 BoundNetLog net_log_; | 104 BoundNetLog net_log_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); | 106 DISALLOW_COPY_AND_ASSIGN(MockConnectClientSocket); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 class MockFailingClientSocket : public StreamSocket { | 109 class MockFailingClientSocket : public StreamSocket { |
| 109 public: | 110 public: |
| 110 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) | 111 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
| 111 : addrlist_(addrlist), | 112 : addrlist_(addrlist), |
| 112 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) {} | 113 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)) {} |
| 113 | 114 |
| 114 // StreamSocket implementation. | 115 // StreamSocket implementation. |
| 115 int Connect(const CompletionCallback& callback) override { | 116 int Connect(const CompletionCallback& callback) override { |
| 116 return ERR_CONNECTION_FAILED; | 117 return ERR_CONNECTION_FAILED; |
| 117 } | 118 } |
| 118 | 119 |
| 119 void Disconnect() override {} | 120 void Disconnect() override {} |
| 120 | 121 |
| 121 bool IsConnected() const override { return false; } | 122 bool IsConnected() const override { return false; } |
| 122 bool IsConnectedAndIdle() const override { return false; } | 123 bool IsConnectedAndIdle() const override { return false; } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 class MockTriggerableClientSocket : public StreamSocket { | 173 class MockTriggerableClientSocket : public StreamSocket { |
| 173 public: | 174 public: |
| 174 // |should_connect| indicates whether the socket should successfully complete | 175 // |should_connect| indicates whether the socket should successfully complete |
| 175 // or fail. | 176 // or fail. |
| 176 MockTriggerableClientSocket(const AddressList& addrlist, | 177 MockTriggerableClientSocket(const AddressList& addrlist, |
| 177 bool should_connect, | 178 bool should_connect, |
| 178 net::NetLog* net_log) | 179 net::NetLog* net_log) |
| 179 : should_connect_(should_connect), | 180 : should_connect_(should_connect), |
| 180 is_connected_(false), | 181 is_connected_(false), |
| 181 addrlist_(addrlist), | 182 addrlist_(addrlist), |
| 182 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | 183 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::SOCKET)), |
| 183 weak_factory_(this) {} | 184 weak_factory_(this) {} |
| 184 | 185 |
| 185 // Call this method to get a closure which will trigger the connect callback | 186 // Call this method to get a closure which will trigger the connect callback |
| 186 // when called. The closure can be called even after the socket is deleted; it | 187 // when called. The closure can be called even after the socket is deleted; it |
| 187 // will safely do nothing. | 188 // will safely do nothing. |
| 188 base::Closure GetConnectCallback() { | 189 base::Closure GetConnectCallback() { |
| 189 return base::Bind(&MockTriggerableClientSocket::DoCallback, | 190 return base::Bind(&MockTriggerableClientSocket::DoCallback, |
| 190 weak_factory_.GetWeakPtr()); | 191 weak_factory_.GetWeakPtr()); |
| 191 } | 192 } |
| 192 | 193 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 run_loop_quit_closure_ = run_loop.QuitClosure(); | 457 run_loop_quit_closure_ = run_loop.QuitClosure(); |
| 457 run_loop.Run(); | 458 run_loop.Run(); |
| 458 run_loop_quit_closure_.Reset(); | 459 run_loop_quit_closure_.Reset(); |
| 459 } | 460 } |
| 460 base::Closure trigger = triggerable_sockets_.front(); | 461 base::Closure trigger = triggerable_sockets_.front(); |
| 461 triggerable_sockets_.pop(); | 462 triggerable_sockets_.pop(); |
| 462 return trigger; | 463 return trigger; |
| 463 } | 464 } |
| 464 | 465 |
| 465 } // namespace net | 466 } // namespace net |
| OLD | NEW |