1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_TEST_UTIL_H_ 6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_TEST_UTIL_H_ 7 8 #include <stdint.h> 9 #include <string> 10 11 #include "net/base/test_completion_callback.h" 12 #include "net/socket/stream_socket.h" 13 14 namespace net { 15 16 class IOBuffer; 17 18 // Sends a request from `socket` to `connected_socket`. Makes `connected_socket` 19 // read the request and send a response. 20 void SendRequestAndResponse(StreamSocket* socket, 21 StreamSocket* connected_socket); 22 23 // Reads `expected_bytes_read` bytes from `socket`. Returns the data 24 // read as a string. 25 std::string ReadDataOfExpectedLength(StreamSocket* socket, 26 int expected_bytes_read); 27 28 // Sends response from `socket`. 29 void SendServerResponse(StreamSocket* socket); 30 31 // `socket` reads `bytes_to_read` number of bytes into `buf`. Returns number of 32 // bytes read. 33 int DrainStreamSocket(StreamSocket* socket, 34 IOBuffer* buf, 35 uint32_t buf_len, 36 uint32_t bytes_to_read, 37 TestCompletionCallback* callback); 38 39 } // namespace net 40 41 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_TEST_UTIL_H_ 42