| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const QuicServerId& server_id, | 38 const QuicServerId& server_id, |
| 39 const QuicVersionVector& supported_versions, | 39 const QuicVersionVector& supported_versions, |
| 40 EpollServer* epoll_server); | 40 EpollServer* epoll_server); |
| 41 | 41 |
| 42 MockableQuicClient(IPEndPoint server_address, | 42 MockableQuicClient(IPEndPoint server_address, |
| 43 const QuicServerId& server_id, | 43 const QuicServerId& server_id, |
| 44 const QuicConfig& config, | 44 const QuicConfig& config, |
| 45 const QuicVersionVector& supported_versions, | 45 const QuicVersionVector& supported_versions, |
| 46 EpollServer* epoll_server); | 46 EpollServer* epoll_server); |
| 47 | 47 |
| 48 virtual ~MockableQuicClient() override; | 48 ~MockableQuicClient() override; |
| 49 virtual QuicPacketWriter* CreateQuicPacketWriter() override; | 49 QuicPacketWriter* CreateQuicPacketWriter() override; |
| 50 virtual QuicConnectionId GenerateConnectionId() override; | 50 QuicConnectionId GenerateConnectionId() override; |
| 51 void UseWriter(QuicPacketWriterWrapper* writer); | 51 void UseWriter(QuicPacketWriterWrapper* writer); |
| 52 void UseConnectionId(QuicConnectionId connection_id); | 52 void UseConnectionId(QuicConnectionId connection_id); |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero | 55 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero |
| 56 QuicPacketWriterWrapper* test_writer_; | 56 QuicPacketWriterWrapper* test_writer_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(MockableQuicClient); | 58 DISALLOW_COPY_AND_ASSIGN(MockableQuicClient); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // A toy QUIC client used for testing, mostly following the SimpleClient APIs. | 61 // A toy QUIC client used for testing, mostly following the SimpleClient APIs. |
| 62 class QuicTestClient : public SimpleClient, | 62 class QuicTestClient : public SimpleClient, |
| 63 public QuicDataStream::Visitor { | 63 public QuicDataStream::Visitor { |
| 64 public: | 64 public: |
| 65 QuicTestClient(IPEndPoint server_address, | 65 QuicTestClient(IPEndPoint server_address, |
| 66 const string& server_hostname, | 66 const string& server_hostname, |
| 67 const QuicVersionVector& supported_versions); | 67 const QuicVersionVector& supported_versions); |
| 68 QuicTestClient(IPEndPoint server_address, | 68 QuicTestClient(IPEndPoint server_address, |
| 69 const string& server_hostname, | 69 const string& server_hostname, |
| 70 bool secure, | 70 bool secure, |
| 71 const QuicVersionVector& supported_versions); | 71 const QuicVersionVector& supported_versions); |
| 72 QuicTestClient(IPEndPoint server_address, | 72 QuicTestClient(IPEndPoint server_address, |
| 73 const string& server_hostname, | 73 const string& server_hostname, |
| 74 bool secure, | 74 bool secure, |
| 75 const QuicConfig& config, | 75 const QuicConfig& config, |
| 76 const QuicVersionVector& supported_versions); | 76 const QuicVersionVector& supported_versions); |
| 77 | 77 |
| 78 virtual ~QuicTestClient(); | 78 ~QuicTestClient() override; |
| 79 | 79 |
| 80 // ExpectCertificates controls whether the server is expected to provide | 80 // ExpectCertificates controls whether the server is expected to provide |
| 81 // certificates. The certificates, if any, are not verified, but the common | 81 // certificates. The certificates, if any, are not verified, but the common |
| 82 // name is recorded and available with |cert_common_name()|. | 82 // name is recorded and available with |cert_common_name()|. |
| 83 void ExpectCertificates(bool on); | 83 void ExpectCertificates(bool on); |
| 84 | 84 |
| 85 // Sets the |user_agent_id| of the |client_|. | 85 // Sets the |user_agent_id| of the |client_|. |
| 86 void SetUserAgentID(const string& user_agent_id); | 86 void SetUserAgentID(const string& user_agent_id); |
| 87 | 87 |
| 88 // Wraps data in a quic packet and sends it. | 88 // Wraps data in a quic packet and sends it. |
| 89 ssize_t SendData(string data, bool last_data); | 89 ssize_t SendData(string data, bool last_data); |
| 90 | 90 |
| 91 // From SimpleClient | 91 // From SimpleClient |
| 92 // Clears any outstanding state and sends a simple GET of 'uri' to the | 92 // Clears any outstanding state and sends a simple GET of 'uri' to the |
| 93 // server. Returns 0 if the request failed and no bytes were written. | 93 // server. Returns 0 if the request failed and no bytes were written. |
| 94 virtual ssize_t SendRequest(const string& uri) override; | 94 ssize_t SendRequest(const string& uri) override; |
| 95 virtual ssize_t SendMessage(const HTTPMessage& message) override; | 95 ssize_t SendMessage(const HTTPMessage& message) override; |
| 96 virtual string SendCustomSynchronousRequest( | 96 string SendCustomSynchronousRequest(const HTTPMessage& message) override; |
| 97 const HTTPMessage& message) override; | 97 string SendSynchronousRequest(const string& uri) override; |
| 98 virtual string SendSynchronousRequest(const string& uri) override; | 98 void Connect() override; |
| 99 virtual void Connect() override; | 99 void ResetConnection() override; |
| 100 virtual void ResetConnection() override; | 100 void Disconnect() override; |
| 101 virtual void Disconnect() override; | 101 IPEndPoint LocalSocketAddress() const override; |
| 102 virtual IPEndPoint LocalSocketAddress() const override; | 102 void ClearPerRequestState() override; |
| 103 virtual void ClearPerRequestState() override; | 103 void WaitForResponseForMs(int timeout_ms) override; |
| 104 virtual void WaitForResponseForMs(int timeout_ms) override; | 104 void WaitForInitialResponseForMs(int timeout_ms) override; |
| 105 virtual void WaitForInitialResponseForMs(int timeout_ms) override; | 105 ssize_t Send(const void* buffer, size_t size) override; |
| 106 virtual ssize_t Send(const void *buffer, size_t size) override; | 106 bool response_complete() const override; |
| 107 virtual bool response_complete() const override; | 107 bool response_headers_complete() const override; |
| 108 virtual bool response_headers_complete() const override; | 108 const BalsaHeaders* response_headers() const override; |
| 109 virtual const BalsaHeaders* response_headers() const override; | 109 int64 response_size() const override; |
| 110 virtual int64 response_size() const override; | 110 int response_header_size() const override; |
| 111 virtual int response_header_size() const override; | 111 int64 response_body_size() const override; |
| 112 virtual int64 response_body_size() const override; | 112 size_t bytes_read() const override; |
| 113 virtual size_t bytes_read() const override; | 113 size_t bytes_written() const override; |
| 114 virtual size_t bytes_written() const override; | 114 bool buffer_body() const override; |
| 115 virtual bool buffer_body() const override; | 115 void set_buffer_body(bool buffer_body) override; |
| 116 virtual void set_buffer_body(bool buffer_body) override; | 116 bool ServerInLameDuckMode() const override; |
| 117 virtual bool ServerInLameDuckMode() const override; | 117 const string& response_body() override; |
| 118 virtual const string& response_body() override; | 118 bool connected() const override; |
| 119 virtual bool connected() const override; | |
| 120 // These functions are all unimplemented functions from SimpleClient, and log | 119 // These functions are all unimplemented functions from SimpleClient, and log |
| 121 // DFATAL if called by users of SimpleClient. | 120 // DFATAL if called by users of SimpleClient. |
| 122 virtual ssize_t SendAndWaitForResponse(const void *buffer, | 121 ssize_t SendAndWaitForResponse(const void* buffer, size_t size) override; |
| 123 size_t size) override; | 122 void Bind(IPEndPoint* local_address) override; |
| 124 virtual void Bind(IPEndPoint* local_address) override; | 123 string SerializeMessage(const HTTPMessage& message) override; |
| 125 virtual string SerializeMessage(const HTTPMessage& message) override; | 124 IPAddressNumber bind_to_address() const override; |
| 126 virtual IPAddressNumber bind_to_address() const override; | 125 void set_bind_to_address(IPAddressNumber address) override; |
| 127 virtual void set_bind_to_address(IPAddressNumber address) override; | 126 const IPEndPoint& address() const override; |
| 128 virtual const IPEndPoint& address() const override; | 127 size_t requests_sent() const override; |
| 129 virtual size_t requests_sent() const override; | |
| 130 | 128 |
| 131 // From QuicDataStream::Visitor | 129 // From QuicDataStream::Visitor |
| 132 virtual void OnClose(QuicDataStream* stream) override; | 130 void OnClose(QuicDataStream* stream) override; |
| 133 | 131 |
| 134 // Configures client_ to take ownership of and use the writer. | 132 // Configures client_ to take ownership of and use the writer. |
| 135 // Must be called before initial connect. | 133 // Must be called before initial connect. |
| 136 void UseWriter(QuicPacketWriterWrapper* writer); | 134 void UseWriter(QuicPacketWriterWrapper* writer); |
| 137 // If the given ConnectionId is nonzero, configures client_ to use a specific | 135 // If the given ConnectionId is nonzero, configures client_ to use a specific |
| 138 // ConnectionId instead of a random one. | 136 // ConnectionId instead of a random one. |
| 139 void UseConnectionId(QuicConnectionId connection_id); | 137 void UseConnectionId(QuicConnectionId connection_id); |
| 140 | 138 |
| 141 // Returns nullptr if the maximum number of streams have already been created. | 139 // Returns nullptr if the maximum number of streams have already been created. |
| 142 QuicSpdyClientStream* GetOrCreateStream(); | 140 QuicSpdyClientStream* GetOrCreateStream(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 205 |
| 208 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); | 206 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); |
| 209 }; | 207 }; |
| 210 | 208 |
| 211 } // namespace test | 209 } // namespace test |
| 212 | 210 |
| 213 } // namespace tools | 211 } // namespace tools |
| 214 } // namespace net | 212 } // namespace net |
| 215 | 213 |
| 216 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 214 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
| OLD | NEW |