| 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_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 5 #ifndef NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
| 6 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 6 #define NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "net/base/ip_endpoint.h" |
| 12 #include "net/quic/quic_framer.h" | 13 #include "net/quic/quic_framer.h" |
| 13 #include "net/quic/quic_packet_creator.h" | 14 #include "net/quic/quic_packet_creator.h" |
| 14 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 16 #include "net/tools/balsa/balsa_frame.h" |
| 15 #include "net/tools/quic/quic_client.h" | 17 #include "net/tools/quic/quic_client.h" |
| 18 #include "net/tools/quic/test_tools/simple_client.h" |
| 16 | 19 |
| 17 namespace net { | 20 namespace net { |
| 18 | 21 |
| 19 class ProofVerifier; | 22 class ProofVerifier; |
| 20 class QuicServerId; | 23 class QuicServerId; |
| 21 | 24 |
| 22 namespace tools { | 25 namespace tools { |
| 23 | 26 |
| 24 class QuicPacketWriterWrapper; | 27 class QuicPacketWriterWrapper; |
| 25 | 28 |
| 26 namespace test { | 29 namespace test { |
| 27 | 30 |
| 28 class HTTPMessage; | 31 class HTTPMessage; |
| 29 class MockableQuicClient; | 32 class MockableQuicClient; |
| 30 | 33 |
| 31 // A toy QUIC client used for testing. | 34 // A quic client which allows mocking out writes. |
| 32 class QuicTestClient : public QuicDataStream::Visitor { | 35 class MockableQuicClient : public QuicClient { |
| 36 public: |
| 37 MockableQuicClient(IPEndPoint server_address, |
| 38 const QuicServerId& server_id, |
| 39 const QuicVersionVector& supported_versions, |
| 40 uint32 initial_flow_control_window); |
| 41 |
| 42 MockableQuicClient(IPEndPoint server_address, |
| 43 const QuicServerId& server_id, |
| 44 const QuicConfig& config, |
| 45 const QuicVersionVector& supported_versions, |
| 46 uint32 initial_flow_control_window); |
| 47 |
| 48 virtual ~MockableQuicClient() OVERRIDE; |
| 49 virtual QuicPacketWriter* CreateQuicPacketWriter() OVERRIDE; |
| 50 virtual QuicConnectionId GenerateConnectionId() OVERRIDE; |
| 51 void UseWriter(QuicPacketWriterWrapper* writer); |
| 52 void UseConnectionId(QuicConnectionId connection_id); |
| 53 |
| 54 private: |
| 55 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero |
| 56 QuicPacketWriterWrapper* test_writer_; |
| 57 }; |
| 58 |
| 59 // A toy QUIC client used for testing, mostly following the SimpleClient APIs. |
| 60 class QuicTestClient : public SimpleClient, |
| 61 public QuicDataStream::Visitor { |
| 33 public: | 62 public: |
| 34 QuicTestClient(IPEndPoint server_address, | 63 QuicTestClient(IPEndPoint server_address, |
| 35 const string& server_hostname, | 64 const string& server_hostname, |
| 36 const QuicVersionVector& supported_versions); | 65 const QuicVersionVector& supported_versions); |
| 37 QuicTestClient(IPEndPoint server_address, | 66 QuicTestClient(IPEndPoint server_address, |
| 38 const string& server_hostname, | 67 const string& server_hostname, |
| 39 bool secure, | 68 bool secure, |
| 40 const QuicVersionVector& supported_versions); | 69 const QuicVersionVector& supported_versions); |
| 41 QuicTestClient(IPEndPoint server_address, | 70 QuicTestClient(IPEndPoint server_address, |
| 42 const string& server_hostname, | 71 const string& server_hostname, |
| 43 bool secure, | 72 bool secure, |
| 44 const QuicConfig& config, | 73 const QuicConfig& config, |
| 45 const QuicVersionVector& supported_versions, | 74 const QuicVersionVector& supported_versions, |
| 46 uint32 client_initial_flow_control_receive_window); | 75 uint32 client_initial_flow_control_receive_window); |
| 47 | 76 |
| 48 virtual ~QuicTestClient(); | 77 virtual ~QuicTestClient(); |
| 49 | 78 |
| 50 // ExpectCertificates controls whether the server is expected to provide | 79 // ExpectCertificates controls whether the server is expected to provide |
| 51 // certificates. The certificates, if any, are not verified, but the common | 80 // certificates. The certificates, if any, are not verified, but the common |
| 52 // name is recorded and available with |cert_common_name()|. | 81 // name is recorded and available with |cert_common_name()|. |
| 53 void ExpectCertificates(bool on); | 82 void ExpectCertificates(bool on); |
| 54 | 83 |
| 55 // Clears any outstanding state and sends a simple GET of 'uri' to the | |
| 56 // server. Returns 0 if the request failed and no bytes were written. | |
| 57 ssize_t SendRequest(const string& uri); | |
| 58 ssize_t SendMessage(const HTTPMessage& message); | |
| 59 | |
| 60 string SendCustomSynchronousRequest(const HTTPMessage& message); | |
| 61 string SendSynchronousRequest(const string& uri); | |
| 62 | |
| 63 // Wraps data in a quic packet and sends it. | 84 // Wraps data in a quic packet and sends it. |
| 64 ssize_t SendData(string data, bool last_data); | 85 ssize_t SendData(string data, bool last_data); |
| 65 | 86 |
| 66 QuicPacketCreator::Options* options(); | 87 QuicPacketCreator::Options* options(); |
| 67 | 88 |
| 68 void WaitForResponse(); | 89 // From SimpleClient |
| 69 | 90 // Clears any outstanding state and sends a simple GET of 'uri' to the |
| 70 void Connect(); | 91 // server. Returns 0 if the request failed and no bytes were written. |
| 71 void ResetConnection(); | 92 virtual ssize_t SendRequest(const string& uri) OVERRIDE; |
| 72 void Disconnect(); | 93 virtual ssize_t SendMessage(const HTTPMessage& message) OVERRIDE; |
| 73 IPEndPoint LocalSocketAddress() const; | 94 virtual string SendCustomSynchronousRequest( |
| 74 void ClearPerRequestState(); | 95 const HTTPMessage& message) OVERRIDE; |
| 75 void WaitForResponseForMs(int timeout_ms); | 96 virtual string SendSynchronousRequest(const string& uri) OVERRIDE; |
| 76 void WaitForInitialResponseForMs(int timeout_ms); | 97 virtual void Connect() OVERRIDE; |
| 77 ssize_t Send(const void *buffer, size_t size); | 98 virtual void ResetConnection() OVERRIDE; |
| 78 bool response_complete() const { return response_complete_; } | 99 virtual void Disconnect() OVERRIDE; |
| 79 bool response_headers_complete() const; | 100 virtual IPEndPoint LocalSocketAddress() const OVERRIDE; |
| 80 const BalsaHeaders* response_headers() const; | 101 virtual void ClearPerRequestState() OVERRIDE; |
| 81 int response_size() const; | 102 virtual void WaitForResponseForMs(int timeout_ms) OVERRIDE; |
| 82 int response_header_size() const { return response_header_size_; } | 103 virtual void WaitForInitialResponseForMs(int timeout_ms) OVERRIDE; |
| 83 int response_body_size() const { return response_body_size_; } | 104 virtual ssize_t Send(const void *buffer, size_t size) OVERRIDE; |
| 84 size_t bytes_read() const; | 105 virtual bool response_complete() const OVERRIDE; |
| 85 size_t bytes_written() const; | 106 virtual bool response_headers_complete() const OVERRIDE; |
| 86 bool buffer_body() const { return buffer_body_; } | 107 virtual const BalsaHeaders* response_headers() const OVERRIDE; |
| 87 void set_buffer_body(bool buffer_body) { buffer_body_ = buffer_body; } | 108 virtual int response_size() const OVERRIDE; |
| 109 virtual int response_header_size() const OVERRIDE; |
| 110 virtual int response_body_size() const OVERRIDE; |
| 111 virtual size_t bytes_read() const OVERRIDE; |
| 112 virtual size_t bytes_written() const OVERRIDE; |
| 113 virtual bool buffer_body() const OVERRIDE; |
| 114 virtual void set_buffer_body(bool buffer_body) OVERRIDE; |
| 115 virtual bool ServerInLameDuckMode() const OVERRIDE; |
| 116 virtual const string& response_body() OVERRIDE; |
| 117 virtual bool connected() const OVERRIDE; |
| 118 // These functions are all unimplemented functions from SimpleClient, and log |
| 119 // DFATAL if called by users of SimpleClient. |
| 120 virtual ssize_t SendAndWaitForResponse(const void *buffer, |
| 121 size_t size) OVERRIDE; |
| 122 virtual void Bind(IPEndPoint* local_address) OVERRIDE; |
| 123 virtual string SerializeMessage( |
| 124 const HTTPMessage& message) OVERRIDE; |
| 125 virtual IPAddressNumber bind_to_address() const OVERRIDE; |
| 126 virtual void set_bind_to_address(IPAddressNumber address) OVERRIDE; |
| 127 virtual const IPEndPoint& address() const OVERRIDE; |
| 128 virtual size_t requests_sent() const OVERRIDE; |
| 88 | 129 |
| 89 // From QuicDataStream::Visitor | 130 // From QuicDataStream::Visitor |
| 90 virtual void OnClose(QuicDataStream* stream) OVERRIDE; | 131 virtual void OnClose(QuicDataStream* stream) OVERRIDE; |
| 91 | 132 |
| 92 // Configures client_ to take ownership of and use the writer. | 133 // Configures client_ to take ownership of and use the writer. |
| 93 // Must be called before initial connect. | 134 // Must be called before initial connect. |
| 94 void UseWriter(QuicPacketWriterWrapper* writer); | 135 void UseWriter(QuicPacketWriterWrapper* writer); |
| 95 // If the given ConnectionId is nonzero, configures client_ to use a specific | 136 // If the given ConnectionId is nonzero, configures client_ to use a specific |
| 96 // ConnectionId instead of a random one. | 137 // ConnectionId instead of a random one. |
| 97 void UseConnectionId(QuicConnectionId connection_id); | 138 void UseConnectionId(QuicConnectionId connection_id); |
| 98 | 139 |
| 99 // Returns NULL if the maximum number of streams have already been created. | 140 // Returns NULL if the maximum number of streams have already been created. |
| 100 QuicSpdyClientStream* GetOrCreateStream(); | 141 QuicSpdyClientStream* GetOrCreateStream(); |
| 101 | 142 |
| 102 QuicRstStreamErrorCode stream_error() { return stream_error_; } | 143 QuicRstStreamErrorCode stream_error() { return stream_error_; } |
| 103 QuicErrorCode connection_error(); | 144 QuicErrorCode connection_error(); |
| 104 | 145 |
| 105 QuicClient* client(); | 146 QuicClient* client(); |
| 106 | 147 |
| 107 // cert_common_name returns the common name value of the server's certificate, | 148 // cert_common_name returns the common name value of the server's certificate, |
| 108 // or the empty string if no certificate was presented. | 149 // or the empty string if no certificate was presented. |
| 109 const string& cert_common_name() const; | 150 const string& cert_common_name() const; |
| 110 | 151 |
| 111 // Get the server config map. | 152 // Get the server config map. |
| 112 QuicTagValueMap GetServerConfig() const; | 153 QuicTagValueMap GetServerConfig() const; |
| 113 | 154 |
| 114 const string& response_body() {return response_;} | |
| 115 bool connected() const; | |
| 116 | |
| 117 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } | 155 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } |
| 118 | 156 |
| 119 void set_priority(QuicPriority priority) { priority_ = priority; } | 157 void set_priority(QuicPriority priority) { priority_ = priority; } |
| 120 | 158 |
| 121 void WaitForWriteToFlush(); | 159 void WaitForWriteToFlush(); |
| 122 | 160 |
| 161 protected: |
| 162 QuicTestClient(); |
| 163 |
| 164 void Initialize(bool secure); |
| 165 |
| 166 void set_client(MockableQuicClient* client) { client_.reset(client); } |
| 167 |
| 123 private: | 168 private: |
| 124 void Initialize(IPEndPoint address, const std::string& hostname, bool secure); | |
| 125 | |
| 126 IPEndPoint server_address_; | |
| 127 IPEndPoint client_address_; | |
| 128 scoped_ptr<MockableQuicClient> client_; // The actual client | 169 scoped_ptr<MockableQuicClient> client_; // The actual client |
| 129 QuicSpdyClientStream* stream_; | 170 QuicSpdyClientStream* stream_; |
| 130 | 171 |
| 131 QuicRstStreamErrorCode stream_error_; | 172 QuicRstStreamErrorCode stream_error_; |
| 132 | 173 |
| 133 bool response_complete_; | 174 bool response_complete_; |
| 134 bool response_headers_complete_; | 175 bool response_headers_complete_; |
| 135 BalsaHeaders headers_; | 176 BalsaHeaders headers_; |
| 136 QuicPriority priority_; | 177 QuicPriority priority_; |
| 137 string response_; | 178 string response_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 // proof_verifier_ points to a RecordingProofVerifier that is owned by | 195 // proof_verifier_ points to a RecordingProofVerifier that is owned by |
| 155 // client_. | 196 // client_. |
| 156 ProofVerifier* proof_verifier_; | 197 ProofVerifier* proof_verifier_; |
| 157 }; | 198 }; |
| 158 | 199 |
| 159 } // namespace test | 200 } // namespace test |
| 160 | 201 |
| 161 } // namespace tools | 202 } // namespace tools |
| 162 } // namespace net | 203 } // namespace net |
| 163 | 204 |
| 164 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 205 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
| OLD | NEW |