| 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 <cstdint> | 8 #include <cstdint> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
| 14 #include "net/quic/core/quic_framer.h" | 14 #include "net/quic/core/quic_framer.h" |
| 15 #include "net/quic/core/quic_packet_creator.h" | 15 #include "net/quic/core/quic_packet_creator.h" |
| 16 #include "net/quic/core/quic_packets.h" | 16 #include "net/quic/core/quic_packets.h" |
| 17 #include "net/quic/platform/api/quic_string_piece.h" |
| 17 #include "net/tools/quic/quic_client.h" | 18 #include "net/tools/quic/quic_client.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 | 20 |
| 20 using base::StringPiece; | |
| 21 | |
| 22 namespace net { | 21 namespace net { |
| 23 | 22 |
| 24 class ProofVerifier; | 23 class ProofVerifier; |
| 25 class QuicPacketWriterWrapper; | 24 class QuicPacketWriterWrapper; |
| 26 | 25 |
| 27 namespace test { | 26 namespace test { |
| 28 | 27 |
| 29 // A quic client which allows mocking out reads and writes. | 28 // A quic client which allows mocking out reads and writes. |
| 30 class MockableQuicClient : public QuicClient { | 29 class MockableQuicClient : public QuicClient { |
| 31 public: | 30 public: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Clears any outstanding state and sends a simple GET of 'uri' to the | 109 // Clears any outstanding state and sends a simple GET of 'uri' to the |
| 111 // server. Returns 0 if the request failed and no bytes were written. | 110 // server. Returns 0 if the request failed and no bytes were written. |
| 112 ssize_t SendRequest(const std::string& uri); | 111 ssize_t SendRequest(const std::string& uri); |
| 113 // Sends requests for all the urls and waits for the responses. To process | 112 // Sends requests for all the urls and waits for the responses. To process |
| 114 // the individual responses as they are returned, the caller should use the | 113 // the individual responses as they are returned, the caller should use the |
| 115 // set the response_listener on the client(). | 114 // set the response_listener on the client(). |
| 116 void SendRequestsAndWaitForResponses( | 115 void SendRequestsAndWaitForResponses( |
| 117 const std::vector<std::string>& url_list); | 116 const std::vector<std::string>& url_list); |
| 118 // Sends a request containing |headers| and |body| and returns the number of | 117 // Sends a request containing |headers| and |body| and returns the number of |
| 119 // bytes sent (the size of the serialized request headers and body). | 118 // bytes sent (the size of the serialized request headers and body). |
| 120 ssize_t SendMessage(const SpdyHeaderBlock& headers, base::StringPiece body); | 119 ssize_t SendMessage(const SpdyHeaderBlock& headers, QuicStringPiece body); |
| 121 // Sends a request containing |headers| and |body| with the fin bit set to | 120 // Sends a request containing |headers| and |body| with the fin bit set to |
| 122 // |fin| and returns the number of bytes sent (the size of the serialized | 121 // |fin| and returns the number of bytes sent (the size of the serialized |
| 123 // request headers and body). | 122 // request headers and body). |
| 124 ssize_t SendMessage(const SpdyHeaderBlock& headers, | 123 ssize_t SendMessage(const SpdyHeaderBlock& headers, |
| 125 base::StringPiece body, | 124 QuicStringPiece body, |
| 126 bool fin); | 125 bool fin); |
| 127 // Sends a request containing |headers| and |body|, waits for the response, | 126 // Sends a request containing |headers| and |body|, waits for the response, |
| 128 // and returns the response body. | 127 // and returns the response body. |
| 129 std::string SendCustomSynchronousRequest(const SpdyHeaderBlock& headers, | 128 std::string SendCustomSynchronousRequest(const SpdyHeaderBlock& headers, |
| 130 const std::string& body); | 129 const std::string& body); |
| 131 // Sends a GET request for |uri|, waits for the response, and returns the | 130 // Sends a GET request for |uri|, waits for the response, and returns the |
| 132 // response body. | 131 // response body. |
| 133 std::string SendSynchronousRequest(const std::string& uri); | 132 std::string SendSynchronousRequest(const std::string& uri); |
| 134 void Connect(); | 133 void Connect(); |
| 135 void ResetConnection(); | 134 void ResetConnection(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Update internal stream_ pointer and perform accompanying housekeeping. | 200 // Update internal stream_ pointer and perform accompanying housekeeping. |
| 202 void SetStream(QuicSpdyClientStream* stream); | 201 void SetStream(QuicSpdyClientStream* stream); |
| 203 // Returns nullptr if the maximum number of streams have already been created. | 202 // Returns nullptr if the maximum number of streams have already been created. |
| 204 QuicSpdyClientStream* GetOrCreateStream(); | 203 QuicSpdyClientStream* GetOrCreateStream(); |
| 205 | 204 |
| 206 // Calls GetOrCreateStream(), sends the request on the stream, and | 205 // Calls GetOrCreateStream(), sends the request on the stream, and |
| 207 // stores the request in case it needs to be resent. If |headers| is | 206 // stores the request in case it needs to be resent. If |headers| is |
| 208 // null, only the body will be sent on the stream. | 207 // null, only the body will be sent on the stream. |
| 209 ssize_t GetOrCreateStreamAndSendRequest( | 208 ssize_t GetOrCreateStreamAndSendRequest( |
| 210 const SpdyHeaderBlock* headers, | 209 const SpdyHeaderBlock* headers, |
| 211 base::StringPiece body, | 210 QuicStringPiece body, |
| 212 bool fin, | 211 bool fin, |
| 213 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); | 212 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 214 | 213 |
| 215 QuicRstStreamErrorCode stream_error() { return stream_error_; } | 214 QuicRstStreamErrorCode stream_error() { return stream_error_; } |
| 216 QuicErrorCode connection_error(); | 215 QuicErrorCode connection_error(); |
| 217 | 216 |
| 218 MockableQuicClient* client(); | 217 MockableQuicClient* client(); |
| 219 | 218 |
| 220 // cert_common_name returns the common name value of the server's certificate, | 219 // cert_common_name returns the common name value of the server's certificate, |
| 221 // or the empty string if no certificate was presented. | 220 // or the empty string if no certificate was presented. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 void set_client(MockableQuicClient* client) { client_.reset(client); } | 263 void set_client(MockableQuicClient* client) { client_.reset(client); } |
| 265 | 264 |
| 266 protected: | 265 protected: |
| 267 QuicTestClient(); | 266 QuicTestClient(); |
| 268 | 267 |
| 269 private: | 268 private: |
| 270 class TestClientDataToResend : public QuicClient::QuicDataToResend { | 269 class TestClientDataToResend : public QuicClient::QuicDataToResend { |
| 271 public: | 270 public: |
| 272 TestClientDataToResend( | 271 TestClientDataToResend( |
| 273 std::unique_ptr<SpdyHeaderBlock> headers, | 272 std::unique_ptr<SpdyHeaderBlock> headers, |
| 274 base::StringPiece body, | 273 QuicStringPiece body, |
| 275 bool fin, | 274 bool fin, |
| 276 QuicTestClient* test_client, | 275 QuicTestClient* test_client, |
| 277 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); | 276 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 278 | 277 |
| 279 ~TestClientDataToResend() override; | 278 ~TestClientDataToResend() override; |
| 280 | 279 |
| 281 void Resend() override; | 280 void Resend() override; |
| 282 | 281 |
| 283 protected: | 282 protected: |
| 284 QuicTestClient* test_client_; | 283 QuicTestClient* test_client_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 std::string override_sni_; | 338 std::string override_sni_; |
| 340 | 339 |
| 341 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); | 340 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); |
| 342 }; | 341 }; |
| 343 | 342 |
| 344 } // namespace test | 343 } // namespace test |
| 345 | 344 |
| 346 } // namespace net | 345 } // namespace net |
| 347 | 346 |
| 348 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 347 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
| OLD | NEW |