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 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ | 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ |
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ | 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1022 ClientSocketPoolTest(); | 1022 ClientSocketPoolTest(); |
1023 ~ClientSocketPoolTest(); | 1023 ~ClientSocketPoolTest(); |
1024 | 1024 |
1025 template <typename PoolType> | 1025 template <typename PoolType> |
1026 int StartRequestUsingPool( | 1026 int StartRequestUsingPool( |
1027 PoolType* socket_pool, | 1027 PoolType* socket_pool, |
1028 const std::string& group_name, | 1028 const std::string& group_name, |
1029 RequestPriority priority, | 1029 RequestPriority priority, |
1030 const scoped_refptr<typename PoolType::SocketParams>& socket_params) { | 1030 const scoped_refptr<typename PoolType::SocketParams>& socket_params) { |
1031 DCHECK(socket_pool); | 1031 DCHECK(socket_pool); |
1032 TestSocketRequest* request = | 1032 TestSocketRequest* request( |
1033 new TestSocketRequest(&request_order_, &completion_count_); | 1033 new TestSocketRequest(&request_order_, &completion_count_)); |
1034 requests_.push_back(request); | 1034 requests_.push_back(make_scoped_ptr(request)); |
mmenke
2015/11/19 16:26:12
nit: Think it's cleaner (And safer across refacto
| |
1035 int rv = request->handle()->Init(group_name, | 1035 int rv = request->handle()->Init(group_name, |
1036 socket_params, | 1036 socket_params, |
1037 priority, | 1037 priority, |
1038 request->callback(), | 1038 request->callback(), |
1039 socket_pool, | 1039 socket_pool, |
1040 BoundNetLog()); | 1040 BoundNetLog()); |
1041 if (rv != ERR_IO_PENDING) | 1041 if (rv != ERR_IO_PENDING) |
1042 request_order_.push_back(request); | 1042 request_order_.push_back(request); |
1043 return rv; | 1043 return rv; |
1044 } | 1044 } |
1045 | 1045 |
1046 // Provided there were n requests started, takes |index| in range 1..n | 1046 // Provided there were n requests started, takes |index| in range 1..n |
1047 // and returns order in which that request completed, in range 1..n, | 1047 // and returns order in which that request completed, in range 1..n, |
1048 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound | 1048 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound |
1049 // if that request did not complete (for example was canceled). | 1049 // if that request did not complete (for example was canceled). |
1050 int GetOrderOfRequest(size_t index) const; | 1050 int GetOrderOfRequest(size_t index) const; |
1051 | 1051 |
1052 // Resets first initialized socket handle from |requests_|. If found such | 1052 // Resets first initialized socket handle from |requests_|. If found such |
1053 // a handle, returns true. | 1053 // a handle, returns true. |
1054 bool ReleaseOneConnection(KeepAlive keep_alive); | 1054 bool ReleaseOneConnection(KeepAlive keep_alive); |
1055 | 1055 |
1056 // Releases connections until there is nothing to release. | 1056 // Releases connections until there is nothing to release. |
1057 void ReleaseAllConnections(KeepAlive keep_alive); | 1057 void ReleaseAllConnections(KeepAlive keep_alive); |
1058 | 1058 |
1059 // Note that this uses 0-based indices, while GetOrderOfRequest takes and | 1059 // Note that this uses 0-based indices, while GetOrderOfRequest takes and |
1060 // returns 0-based indices. | 1060 // returns 0-based indices. |
1061 TestSocketRequest* request(int i) { return requests_[i]; } | 1061 TestSocketRequest* request(int i) { return requests_[i].get(); } |
1062 | 1062 |
1063 size_t requests_size() const { return requests_.size(); } | 1063 size_t requests_size() const { return requests_.size(); } |
1064 ScopedVector<TestSocketRequest>* requests() { return &requests_; } | 1064 std::vector<scoped_ptr<TestSocketRequest>>* requests() { return &requests_; } |
1065 size_t completion_count() const { return completion_count_; } | 1065 size_t completion_count() const { return completion_count_; } |
1066 | 1066 |
1067 private: | 1067 private: |
1068 ScopedVector<TestSocketRequest> requests_; | 1068 std::vector<scoped_ptr<TestSocketRequest>> requests_; |
1069 std::vector<TestSocketRequest*> request_order_; | 1069 std::vector<TestSocketRequest*> request_order_; |
1070 size_t completion_count_; | 1070 size_t completion_count_; |
1071 | 1071 |
1072 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolTest); | 1072 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolTest); |
1073 }; | 1073 }; |
1074 | 1074 |
1075 class MockTransportSocketParams | 1075 class MockTransportSocketParams |
1076 : public base::RefCounted<MockTransportSocketParams> { | 1076 : public base::RefCounted<MockTransportSocketParams> { |
1077 private: | 1077 private: |
1078 friend class base::RefCounted<MockTransportSocketParams>; | 1078 friend class base::RefCounted<MockTransportSocketParams>; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 const BoundNetLog& net_log) override; | 1126 const BoundNetLog& net_log) override; |
1127 | 1127 |
1128 void CancelRequest(const std::string& group_name, | 1128 void CancelRequest(const std::string& group_name, |
1129 ClientSocketHandle* handle) override; | 1129 ClientSocketHandle* handle) override; |
1130 void ReleaseSocket(const std::string& group_name, | 1130 void ReleaseSocket(const std::string& group_name, |
1131 scoped_ptr<StreamSocket> socket, | 1131 scoped_ptr<StreamSocket> socket, |
1132 int id) override; | 1132 int id) override; |
1133 | 1133 |
1134 private: | 1134 private: |
1135 ClientSocketFactory* client_socket_factory_; | 1135 ClientSocketFactory* client_socket_factory_; |
1136 ScopedVector<MockConnectJob> job_list_; | 1136 std::vector<scoped_ptr<MockConnectJob>> job_list_; |
1137 RequestPriority last_request_priority_; | 1137 RequestPriority last_request_priority_; |
1138 int release_count_; | 1138 int release_count_; |
1139 int cancel_count_; | 1139 int cancel_count_; |
1140 | 1140 |
1141 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); | 1141 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); |
1142 }; | 1142 }; |
1143 | 1143 |
1144 class DeterministicMockClientSocketFactory : public ClientSocketFactory { | 1144 class DeterministicMockClientSocketFactory : public ClientSocketFactory { |
1145 public: | 1145 public: |
1146 DeterministicMockClientSocketFactory(); | 1146 DeterministicMockClientSocketFactory(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 | 1248 |
1249 // Helper function to get the total data size of the MockReads in |reads|. | 1249 // Helper function to get the total data size of the MockReads in |reads|. |
1250 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); | 1250 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); |
1251 | 1251 |
1252 // Helper function to get the total data size of the MockWrites in |writes|. | 1252 // Helper function to get the total data size of the MockWrites in |writes|. |
1253 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); | 1253 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); |
1254 | 1254 |
1255 } // namespace net | 1255 } // namespace net |
1256 | 1256 |
1257 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1257 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |