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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 std::string& server_hostname, |
67 bool secure, | 67 bool secure, |
68 const QuicVersionVector& supported_versions); | 68 const QuicVersionVector& supported_versions); |
69 QuicTestClient(IPEndPoint server_address, | 69 QuicTestClient(IPEndPoint server_address, |
70 const string& server_hostname, | 70 const std::string& server_hostname, |
71 bool secure, | 71 bool secure, |
72 const QuicConfig& config, | 72 const QuicConfig& config, |
73 const QuicVersionVector& supported_versions); | 73 const QuicVersionVector& supported_versions); |
74 | 74 |
75 ~QuicTestClient() override; | 75 ~QuicTestClient() override; |
76 | 76 |
77 // ExpectCertificates controls whether the server is expected to provide | 77 // ExpectCertificates controls whether the server is expected to provide |
78 // certificates. The certificates, if any, are not verified, but the common | 78 // certificates. The certificates, if any, are not verified, but the common |
79 // name is recorded and available with |cert_common_name()|. | 79 // name is recorded and available with |cert_common_name()|. |
80 void ExpectCertificates(bool on); | 80 void ExpectCertificates(bool on); |
81 | 81 |
82 // Sets the |user_agent_id| of the |client_|. | 82 // Sets the |user_agent_id| of the |client_|. |
83 void SetUserAgentID(const string& user_agent_id); | 83 void SetUserAgentID(const std::string& user_agent_id); |
84 | 84 |
85 // Wraps data in a quic packet and sends it. | 85 // Wraps data in a quic packet and sends it. |
86 ssize_t SendData(string data, bool last_data); | 86 ssize_t SendData(std::string data, bool last_data); |
87 | 87 |
88 // From SimpleClient | 88 // From SimpleClient |
89 // Clears any outstanding state and sends a simple GET of 'uri' to the | 89 // Clears any outstanding state and sends a simple GET of 'uri' to the |
90 // server. Returns 0 if the request failed and no bytes were written. | 90 // server. Returns 0 if the request failed and no bytes were written. |
91 ssize_t SendRequest(const string& uri) override; | 91 ssize_t SendRequest(const std::string& uri) override; |
92 ssize_t SendMessage(const HTTPMessage& message) override; | 92 ssize_t SendMessage(const HTTPMessage& message) override; |
93 string SendCustomSynchronousRequest(const HTTPMessage& message) override; | 93 std::string SendCustomSynchronousRequest( |
94 string SendSynchronousRequest(const string& uri) override; | 94 const HTTPMessage& message) override; |
| 95 std::string SendSynchronousRequest(const std::string& uri) override; |
95 void Connect() override; | 96 void Connect() override; |
96 void ResetConnection() override; | 97 void ResetConnection() override; |
97 void Disconnect() override; | 98 void Disconnect() override; |
98 IPEndPoint LocalSocketAddress() const override; | 99 IPEndPoint LocalSocketAddress() const override; |
99 void ClearPerRequestState() override; | 100 void ClearPerRequestState() override; |
100 void WaitForResponseForMs(int timeout_ms) override; | 101 void WaitForResponseForMs(int timeout_ms) override; |
101 void WaitForInitialResponseForMs(int timeout_ms) override; | 102 void WaitForInitialResponseForMs(int timeout_ms) override; |
102 ssize_t Send(const void* buffer, size_t size) override; | 103 ssize_t Send(const void* buffer, size_t size) override; |
103 bool response_complete() const override; | 104 bool response_complete() const override; |
104 bool response_headers_complete() const override; | 105 bool response_headers_complete() const override; |
105 const BalsaHeaders* response_headers() const override; | 106 const BalsaHeaders* response_headers() const override; |
106 int64 response_size() const override; | 107 int64 response_size() const override; |
107 int response_header_size() const override; | 108 int response_header_size() const override; |
108 int64 response_body_size() const override; | 109 int64 response_body_size() const override; |
109 size_t bytes_read() const override; | 110 size_t bytes_read() const override; |
110 size_t bytes_written() const override; | 111 size_t bytes_written() const override; |
111 bool buffer_body() const override; | 112 bool buffer_body() const override; |
112 void set_buffer_body(bool buffer_body) override; | 113 void set_buffer_body(bool buffer_body) override; |
113 bool ServerInLameDuckMode() const override; | 114 bool ServerInLameDuckMode() const override; |
114 const string& response_body() override; | 115 const std::string& response_body() override; |
115 bool connected() const override; | 116 bool connected() const override; |
116 // These functions are all unimplemented functions from SimpleClient, and log | 117 // These functions are all unimplemented functions from SimpleClient, and log |
117 // DFATAL if called by users of SimpleClient. | 118 // DFATAL if called by users of SimpleClient. |
118 ssize_t SendAndWaitForResponse(const void* buffer, size_t size) override; | 119 ssize_t SendAndWaitForResponse(const void* buffer, size_t size) override; |
119 void Bind(IPEndPoint* local_address) override; | 120 void Bind(IPEndPoint* local_address) override; |
120 string SerializeMessage(const HTTPMessage& message) override; | 121 std::string SerializeMessage(const HTTPMessage& message) override; |
121 IPAddressNumber bind_to_address() const override; | 122 IPAddressNumber bind_to_address() const override; |
122 void set_bind_to_address(IPAddressNumber address) override; | 123 void set_bind_to_address(IPAddressNumber address) override; |
123 const IPEndPoint& address() const override; | 124 const IPEndPoint& address() const override; |
124 size_t requests_sent() const override; | 125 size_t requests_sent() const override; |
125 | 126 |
126 // From QuicDataStream::Visitor | 127 // From QuicDataStream::Visitor |
127 void OnClose(QuicDataStream* stream) override; | 128 void OnClose(QuicDataStream* stream) override; |
128 | 129 |
129 // Configures client_ to take ownership of and use the writer. | 130 // Configures client_ to take ownership of and use the writer. |
130 // Must be called before initial connect. | 131 // Must be called before initial connect. |
131 void UseWriter(QuicPacketWriterWrapper* writer); | 132 void UseWriter(QuicPacketWriterWrapper* writer); |
132 // If the given ConnectionId is nonzero, configures client_ to use a specific | 133 // If the given ConnectionId is nonzero, configures client_ to use a specific |
133 // ConnectionId instead of a random one. | 134 // ConnectionId instead of a random one. |
134 void UseConnectionId(QuicConnectionId connection_id); | 135 void UseConnectionId(QuicConnectionId connection_id); |
135 | 136 |
136 // Returns nullptr if the maximum number of streams have already been created. | 137 // Returns nullptr if the maximum number of streams have already been created. |
137 QuicSpdyClientStream* GetOrCreateStream(); | 138 QuicSpdyClientStream* GetOrCreateStream(); |
138 | 139 |
139 QuicRstStreamErrorCode stream_error() { return stream_error_; } | 140 QuicRstStreamErrorCode stream_error() { return stream_error_; } |
140 QuicErrorCode connection_error(); | 141 QuicErrorCode connection_error(); |
141 | 142 |
142 MockableQuicClient* client(); | 143 MockableQuicClient* client(); |
143 | 144 |
144 // cert_common_name returns the common name value of the server's certificate, | 145 // cert_common_name returns the common name value of the server's certificate, |
145 // or the empty string if no certificate was presented. | 146 // or the empty string if no certificate was presented. |
146 const string& cert_common_name() const; | 147 const std::string& cert_common_name() const; |
147 | 148 |
148 // Get the server config map. | 149 // Get the server config map. |
149 QuicTagValueMap GetServerConfig() const; | 150 QuicTagValueMap GetServerConfig() const; |
150 | 151 |
151 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } | 152 void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; } |
152 | 153 |
153 void set_priority(QuicPriority priority) { priority_ = priority; } | 154 void set_priority(QuicPriority priority) { priority_ = priority; } |
154 | 155 |
155 // Sets client's FEC policy. This policy applies to the data stream(s), and | 156 // Sets client's FEC policy. This policy applies to the data stream(s), and |
156 // also to the headers and crypto streams. | 157 // also to the headers and crypto streams. |
(...skipping 14 matching lines...) Expand all Loading... |
171 EpollServer epoll_server_; | 172 EpollServer epoll_server_; |
172 scoped_ptr<MockableQuicClient> client_; // The actual client | 173 scoped_ptr<MockableQuicClient> client_; // The actual client |
173 QuicSpdyClientStream* stream_; | 174 QuicSpdyClientStream* stream_; |
174 | 175 |
175 QuicRstStreamErrorCode stream_error_; | 176 QuicRstStreamErrorCode stream_error_; |
176 | 177 |
177 bool response_complete_; | 178 bool response_complete_; |
178 bool response_headers_complete_; | 179 bool response_headers_complete_; |
179 BalsaHeaders headers_; | 180 BalsaHeaders headers_; |
180 QuicPriority priority_; | 181 QuicPriority priority_; |
181 string response_; | 182 std::string response_; |
182 uint64 bytes_read_; | 183 uint64 bytes_read_; |
183 uint64 bytes_written_; | 184 uint64 bytes_written_; |
184 // The number of uncompressed HTTP header bytes received. | 185 // The number of uncompressed HTTP header bytes received. |
185 int response_header_size_; | 186 int response_header_size_; |
186 // The number of HTTP body bytes received. | 187 // The number of HTTP body bytes received. |
187 int64 response_body_size_; | 188 int64 response_body_size_; |
188 // True if we tried to connect already since the last call to Disconnect(). | 189 // True if we tried to connect already since the last call to Disconnect(). |
189 bool connect_attempted_; | 190 bool connect_attempted_; |
190 bool secure_; | 191 bool secure_; |
191 // The client will auto-connect exactly once before sending data. If | 192 // The client will auto-connect exactly once before sending data. If |
(...skipping 10 matching lines...) Expand all Loading... |
202 | 203 |
203 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); | 204 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); |
204 }; | 205 }; |
205 | 206 |
206 } // namespace test | 207 } // namespace test |
207 | 208 |
208 } // namespace tools | 209 } // namespace tools |
209 } // namespace net | 210 } // namespace net |
210 | 211 |
211 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ | 212 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ |
OLD | NEW |