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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 // Returns the buffer and result code for the next simulated read. | 197 // Returns the buffer and result code for the next simulated read. |
198 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller | 198 // If the |MockRead.result| is ERR_IO_PENDING, it informs the caller |
199 // that it will be called via the AsyncSocket::OnReadComplete() | 199 // that it will be called via the AsyncSocket::OnReadComplete() |
200 // function at a later time. | 200 // function at a later time. |
201 virtual MockRead OnRead() = 0; | 201 virtual MockRead OnRead() = 0; |
202 virtual MockWriteResult OnWrite(const std::string& data) = 0; | 202 virtual MockWriteResult OnWrite(const std::string& data) = 0; |
203 virtual void Reset() = 0; | 203 virtual void Reset() = 0; |
204 virtual bool AllReadDataConsumed() const = 0; | 204 virtual bool AllReadDataConsumed() const = 0; |
205 virtual bool AllWriteDataConsumed() const = 0; | 205 virtual bool AllWriteDataConsumed() const = 0; |
206 | 206 |
207 // Returns true if the request should be considered idle, for the purposes of | |
208 // IsConnectedAndIdle. | |
209 virtual bool IsIdle() const; | |
210 | |
207 // Accessor for the socket which is using the SocketDataProvider. | 211 // Accessor for the socket which is using the SocketDataProvider. |
208 AsyncSocket* socket() { return socket_; } | 212 AsyncSocket* socket() { return socket_; } |
209 void set_socket(AsyncSocket* socket) { socket_ = socket; } | 213 void set_socket(AsyncSocket* socket) { socket_ = socket; } |
210 | 214 |
211 MockConnect connect_data() const { return connect_; } | 215 MockConnect connect_data() const { return connect_; } |
212 void set_connect_data(const MockConnect& connect) { connect_ = connect; } | 216 void set_connect_data(const MockConnect& connect) { connect_ = connect; } |
213 | 217 |
214 private: | 218 private: |
215 MockConnect connect_; | 219 MockConnect connect_; |
216 AsyncSocket* socket_; | 220 AsyncSocket* socket_; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 size_t writes_count); | 361 size_t writes_count); |
358 | 362 |
359 ~SequencedSocketData() override; | 363 ~SequencedSocketData() override; |
360 | 364 |
361 // SocketDataProviderBase implementation. | 365 // SocketDataProviderBase implementation. |
362 MockRead OnRead() override; | 366 MockRead OnRead() override; |
363 MockWriteResult OnWrite(const std::string& data) override; | 367 MockWriteResult OnWrite(const std::string& data) override; |
364 void Reset() override; | 368 void Reset() override; |
365 bool AllReadDataConsumed() const override; | 369 bool AllReadDataConsumed() const override; |
366 bool AllWriteDataConsumed() const override; | 370 bool AllWriteDataConsumed() const override; |
371 bool IsIdle() const override; | |
367 | 372 |
368 bool IsReadPaused(); | 373 bool IsReadPaused(); |
369 void CompleteRead(); | 374 void CompleteRead(); |
370 | 375 |
376 // When true, IsConnectedAndIdle() will return false if the next even in the | |
377 // sequence is a synchronous. Otherwise, the socket claims to be idle as | |
378 // long as it's connected. Defaults to false. | |
379 void set_busy_before_sync_reads(bool busy_before_sync_reads) { | |
asanka
2015/12/03 17:41:57
Perhaps not for this CL, but shouldn't this always
mmenke
2015/12/03 18:24:23
I was worried about breaking all existing synchron
| |
380 busy_before_sync_reads_ = busy_before_sync_reads; | |
381 } | |
382 | |
371 private: | 383 private: |
372 // Defines the state for the read or write path. | 384 // Defines the state for the read or write path. |
373 enum IoState { | 385 enum IoState { |
374 IDLE, // No async operation is in progress. | 386 IDLE, // No async operation is in progress. |
375 PENDING, // An async operation in waiting for another opteration to | 387 PENDING, // An async operation in waiting for another opteration to |
376 // complete. | 388 // complete. |
377 COMPLETING, // A task has been posted to complet an async operation. | 389 COMPLETING, // A task has been posted to complet an async operation. |
378 PAUSED, // IO is paused until CompleteRead() is called. | 390 PAUSED, // IO is paused until CompleteRead() is called. |
379 }; | 391 }; |
380 | 392 |
381 void OnReadComplete(); | 393 void OnReadComplete(); |
382 void OnWriteComplete(); | 394 void OnWriteComplete(); |
383 | 395 |
384 void MaybePostReadCompleteTask(); | 396 void MaybePostReadCompleteTask(); |
385 void MaybePostWriteCompleteTask(); | 397 void MaybePostWriteCompleteTask(); |
386 | 398 |
387 StaticSocketDataHelper helper_; | 399 StaticSocketDataHelper helper_; |
388 int sequence_number_; | 400 int sequence_number_; |
389 IoState read_state_; | 401 IoState read_state_; |
390 IoState write_state_; | 402 IoState write_state_; |
391 | 403 |
404 bool busy_before_sync_reads_; | |
405 | |
392 base::WeakPtrFactory<SequencedSocketData> weak_factory_; | 406 base::WeakPtrFactory<SequencedSocketData> weak_factory_; |
393 | 407 |
394 DISALLOW_COPY_AND_ASSIGN(SequencedSocketData); | 408 DISALLOW_COPY_AND_ASSIGN(SequencedSocketData); |
395 }; | 409 }; |
396 | 410 |
397 class DeterministicMockTCPClientSocket; | 411 class DeterministicMockTCPClientSocket; |
398 | 412 |
399 // This class gives the user full control over the network activity, | 413 // This class gives the user full control over the network activity, |
400 // specifically the timing of the COMPLETION of I/O operations. Regardless of | 414 // specifically the timing of the COMPLETION of I/O operations. Regardless of |
401 // the order in which I/O operations are initiated, this class ensures that they | 415 // the order in which I/O operations are initiated, this class ensures that they |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 int buf_len, | 905 int buf_len, |
892 const CompletionCallback& callback) override; | 906 const CompletionCallback& callback) override; |
893 int Write(IOBuffer* buf, | 907 int Write(IOBuffer* buf, |
894 int buf_len, | 908 int buf_len, |
895 const CompletionCallback& callback) override; | 909 const CompletionCallback& callback) override; |
896 | 910 |
897 // StreamSocket implementation. | 911 // StreamSocket implementation. |
898 int Connect(const CompletionCallback& callback) override; | 912 int Connect(const CompletionCallback& callback) override; |
899 void Disconnect() override; | 913 void Disconnect() override; |
900 bool IsConnected() const override; | 914 bool IsConnected() const override; |
915 bool IsConnectedAndIdle() const override; | |
901 bool WasEverUsed() const override; | 916 bool WasEverUsed() const override; |
902 bool UsingTCPFastOpen() const override; | 917 bool UsingTCPFastOpen() const override; |
903 int GetPeerAddress(IPEndPoint* address) const override; | 918 int GetPeerAddress(IPEndPoint* address) const override; |
904 bool GetSSLInfo(SSLInfo* ssl_info) override; | 919 bool GetSSLInfo(SSLInfo* ssl_info) override; |
905 | 920 |
906 // SSLClientSocket implementation. | 921 // SSLClientSocket implementation. |
907 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; | 922 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; |
908 NextProtoStatus GetNextProto(std::string* proto) const override; | 923 NextProtoStatus GetNextProto(std::string* proto) const override; |
909 | 924 |
910 // This MockSocket does not implement the manual async IO feature. | 925 // This MockSocket does not implement the manual async IO feature. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 | 1263 |
1249 // Helper function to get the total data size of the MockReads in |reads|. | 1264 // Helper function to get the total data size of the MockReads in |reads|. |
1250 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); | 1265 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); |
1251 | 1266 |
1252 // Helper function to get the total data size of the MockWrites in |writes|. | 1267 // Helper function to get the total data size of the MockWrites in |writes|. |
1253 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); | 1268 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); |
1254 | 1269 |
1255 } // namespace net | 1270 } // namespace net |
1256 | 1271 |
1257 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1272 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |