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_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
6 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 6 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <cstdint> | 11 #include <cstdint> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "net/base/ip_address.h" | 16 #include "net/base/ip_address.h" |
17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
18 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 18 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
19 #include "net/quic/core/quic_framer.h" | 19 #include "net/quic/core/quic_framer.h" |
20 #include "net/quic/core/quic_packet_creator.h" | 20 #include "net/quic/core/quic_packet_creator.h" |
21 #include "net/quic/core/quic_protocol.h" | 21 #include "net/quic/core/quic_protocol.h" |
22 #include "net/tools/balsa/balsa_frame.h" | |
23 #include "net/tools/epoll_server/epoll_server.h" | 22 #include "net/tools/epoll_server/epoll_server.h" |
24 #include "net/tools/quic/quic_client.h" | 23 #include "net/tools/quic/quic_client.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
26 | 25 |
27 using base::StringPiece; | 26 using base::StringPiece; |
28 | 27 |
29 namespace net { | 28 namespace net { |
30 | 29 |
31 class ProofVerifier; | 30 class ProofVerifier; |
32 | 31 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 QuicAckListenerInterface* delegate); | 121 QuicAckListenerInterface* delegate); |
123 | 122 |
124 // Clears any outstanding state and sends a simple GET of 'uri' to the | 123 // Clears any outstanding state and sends a simple GET of 'uri' to the |
125 // server. Returns 0 if the request failed and no bytes were written. | 124 // server. Returns 0 if the request failed and no bytes were written. |
126 ssize_t SendRequest(const std::string& uri); | 125 ssize_t SendRequest(const std::string& uri); |
127 // Sends requests for all the urls and waits for the responses. To process | 126 // Sends requests for all the urls and waits for the responses. To process |
128 // the individual responses as they are returned, the caller should use the | 127 // the individual responses as they are returned, the caller should use the |
129 // set the response_listener on the client(). | 128 // set the response_listener on the client(). |
130 void SendRequestsAndWaitForResponses( | 129 void SendRequestsAndWaitForResponses( |
131 const std::vector<std::string>& url_list); | 130 const std::vector<std::string>& url_list); |
132 ssize_t SendMessage(const HTTPMessage& message); | 131 // Sends a request containing |headers| and |body| and returns the number of |
133 std::string SendCustomSynchronousRequest(const HTTPMessage& message); | 132 // bytes sent (the size of the serialized request headers and body). |
| 133 ssize_t SendMessage(const SpdyHeaderBlock& headers, base::StringPiece body); |
| 134 // Sends a request containing |headers| and |body| with the fin bit set to |
| 135 // |fin| and returns the number of bytes sent (the size of the serialized |
| 136 // request headers and body). |
| 137 ssize_t SendMessage(const SpdyHeaderBlock& headers, |
| 138 base::StringPiece body, |
| 139 bool fin); |
| 140 // Sends a request containing |headers| and |body|, waits for the response, |
| 141 // and returns the response body. |
| 142 std::string SendCustomSynchronousRequest(const SpdyHeaderBlock& headers, |
| 143 const std::string& body); |
| 144 // Sends a GET request for |uri|, waits for the response, and returns the |
| 145 // response body. |
134 std::string SendSynchronousRequest(const std::string& uri); | 146 std::string SendSynchronousRequest(const std::string& uri); |
135 void Connect(); | 147 void Connect(); |
136 void ResetConnection(); | 148 void ResetConnection(); |
137 void Disconnect(); | 149 void Disconnect(); |
138 IPEndPoint local_address() const; | 150 IPEndPoint local_address() const; |
139 void ClearPerRequestState(); | 151 void ClearPerRequestState(); |
140 bool WaitUntil(int timeout_ms, std::function<bool()> trigger); | 152 bool WaitUntil(int timeout_ms, std::function<bool()> trigger); |
141 ssize_t Send(const void* buffer, size_t size); | 153 ssize_t Send(const void* buffer, size_t size); |
142 bool response_complete() const; | 154 bool response_complete() const; |
143 bool response_headers_complete() const; | 155 bool response_headers_complete() const; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 void UseConnectionId(QuicConnectionId connection_id); | 211 void UseConnectionId(QuicConnectionId connection_id); |
200 | 212 |
201 // Update internal stream_ pointer and perform accompanying housekeeping. | 213 // Update internal stream_ pointer and perform accompanying housekeeping. |
202 void SetStream(QuicSpdyClientStream* stream); | 214 void SetStream(QuicSpdyClientStream* stream); |
203 // Returns nullptr if the maximum number of streams have already been created. | 215 // Returns nullptr if the maximum number of streams have already been created. |
204 QuicSpdyClientStream* GetOrCreateStream(); | 216 QuicSpdyClientStream* GetOrCreateStream(); |
205 | 217 |
206 // Calls GetOrCreateStream(), sends the request on the stream, and | 218 // Calls GetOrCreateStream(), sends the request on the stream, and |
207 // stores the request in case it needs to be resent. If |headers| is | 219 // stores the request in case it needs to be resent. If |headers| is |
208 // null, only the body will be sent on the stream. | 220 // null, only the body will be sent on the stream. |
209 ssize_t GetOrCreateStreamAndSendRequest(const BalsaHeaders* headers, | 221 ssize_t GetOrCreateStreamAndSendRequest(const SpdyHeaderBlock* headers, |
210 StringPiece body, | 222 base::StringPiece body, |
211 bool fin, | 223 bool fin, |
212 QuicAckListenerInterface* delegate); | 224 QuicAckListenerInterface* delegate); |
213 | 225 |
214 QuicRstStreamErrorCode stream_error() { return stream_error_; } | 226 QuicRstStreamErrorCode stream_error() { return stream_error_; } |
215 QuicErrorCode connection_error(); | 227 QuicErrorCode connection_error(); |
216 | 228 |
217 MockableQuicClient* client(); | 229 MockableQuicClient* client(); |
218 | 230 |
219 // cert_common_name returns the common name value of the server's certificate, | 231 // cert_common_name returns the common name value of the server's certificate, |
220 // or the empty string if no certificate was presented. | 232 // or the empty string if no certificate was presented. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 289 |
278 ~TestClientDataToResend() override {} | 290 ~TestClientDataToResend() override {} |
279 | 291 |
280 void Resend() override; | 292 void Resend() override; |
281 | 293 |
282 protected: | 294 protected: |
283 QuicTestClient* test_client_; | 295 QuicTestClient* test_client_; |
284 QuicAckListenerInterface* delegate_; | 296 QuicAckListenerInterface* delegate_; |
285 }; | 297 }; |
286 | 298 |
287 // Given a uri, creates a simple HTTPMessage request message for testing. | 299 // Given |uri|, populates the fields in |headers| for a simple GET |
288 static void FillInRequest(const std::string& uri, HTTPMessage* message); | 300 // request. If |uri| is a relative URL, the QuicServerId will be |
| 301 // use to specify the authority. |
| 302 bool PopulateHeaderBlockFromUrl(const std::string& uri, |
| 303 SpdyHeaderBlock* headers); |
289 | 304 |
290 bool HaveActiveStream(); | 305 bool HaveActiveStream(); |
291 | 306 |
292 EpollServer epoll_server_; | 307 EpollServer epoll_server_; |
293 std::unique_ptr<MockableQuicClient> client_; // The actual client | 308 std::unique_ptr<MockableQuicClient> client_; // The actual client |
294 QuicSpdyClientStream* stream_; | 309 QuicSpdyClientStream* stream_; |
295 | 310 |
296 QuicRstStreamErrorCode stream_error_; | 311 QuicRstStreamErrorCode stream_error_; |
297 | 312 |
298 bool response_complete_; | 313 bool response_complete_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 std::string override_sni_; | 349 std::string override_sni_; |
335 | 350 |
336 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); | 351 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); |
337 }; | 352 }; |
338 | 353 |
339 } // namespace test | 354 } // namespace test |
340 | 355 |
341 } // namespace net | 356 } // namespace net |
342 | 357 |
343 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 358 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
OLD | NEW |