Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: net/tools/quic/test_tools/quic_test_client.h

Issue 2430973004: Landing Recent QUIC changes until 10:38 AM, Oct 17, 2016 UTC-4 (Closed)
Patch Set: Improving flagsaver logging Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/stateless_rejector.cc ('k') | net/tools/quic/test_tools/quic_test_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 22 #include "net/tools/balsa/balsa_frame.h"
23 #include "net/tools/epoll_server/epoll_server.h" 23 #include "net/tools/epoll_server/epoll_server.h"
24 #include "net/tools/quic/quic_client.h" 24 #include "net/tools/quic/quic_client.h"
25 #include "net/tools/quic/test_tools/simple_client.h"
26 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
27 26
28 using base::StringPiece; 27 using base::StringPiece;
29 28
30 namespace net { 29 namespace net {
31 30
32 class ProofVerifier; 31 class ProofVerifier;
33 32
34 class ProofVerifier; 33 class ProofVerifier;
35 class QuicPacketWriterWrapper; 34 class QuicPacketWriterWrapper;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 QuicPacketWriterWrapper* test_writer_; 85 QuicPacketWriterWrapper* test_writer_;
87 CachedNetworkParameters cached_network_paramaters_; 86 CachedNetworkParameters cached_network_paramaters_;
88 // The last incoming packet, iff |track_last_incoming_packet_| is true. 87 // The last incoming packet, iff |track_last_incoming_packet_| is true.
89 std::unique_ptr<QuicReceivedPacket> last_incoming_packet_; 88 std::unique_ptr<QuicReceivedPacket> last_incoming_packet_;
90 // If true, copy each packet from ProcessPacket into |last_incoming_packet_| 89 // If true, copy each packet from ProcessPacket into |last_incoming_packet_|
91 bool track_last_incoming_packet_; 90 bool track_last_incoming_packet_;
92 91
93 DISALLOW_COPY_AND_ASSIGN(MockableQuicClient); 92 DISALLOW_COPY_AND_ASSIGN(MockableQuicClient);
94 }; 93 };
95 94
96 // A toy QUIC client used for testing, mostly following the SimpleClient APIs. 95 // A toy QUIC client used for testing.
97 class QuicTestClient : public test::SimpleClient, 96 class QuicTestClient : public QuicSpdyStream::Visitor,
98 public QuicSpdyStream::Visitor,
99 public QuicClientPushPromiseIndex::Delegate { 97 public QuicClientPushPromiseIndex::Delegate {
100 public: 98 public:
101 QuicTestClient(IPEndPoint server_address, 99 QuicTestClient(IPEndPoint server_address,
102 const std::string& server_hostname, 100 const std::string& server_hostname,
103 const QuicVersionVector& supported_versions); 101 const QuicVersionVector& supported_versions);
104 QuicTestClient(IPEndPoint server_address, 102 QuicTestClient(IPEndPoint server_address,
105 const std::string& server_hostname, 103 const std::string& server_hostname,
106 const QuicConfig& config, 104 const QuicConfig& config,
107 const QuicVersionVector& supported_versions); 105 const QuicVersionVector& supported_versions);
108 QuicTestClient(IPEndPoint server_address, 106 QuicTestClient(IPEndPoint server_address,
109 const std::string& server_hostname, 107 const std::string& server_hostname,
110 const QuicConfig& config, 108 const QuicConfig& config,
111 const QuicVersionVector& supported_versions, 109 const QuicVersionVector& supported_versions,
112 std::unique_ptr<ProofVerifier> proof_verifier); 110 std::unique_ptr<ProofVerifier> proof_verifier);
113 111
114 ~QuicTestClient() override; 112 ~QuicTestClient() override;
115 113
116 // Sets the |user_agent_id| of the |client_|. 114 // Sets the |user_agent_id| of the |client_|.
117 void SetUserAgentID(const std::string& user_agent_id); 115 void SetUserAgentID(const std::string& user_agent_id);
118 116
119 // Wraps data in a quic packet and sends it. 117 // Wraps data in a quic packet and sends it.
120 ssize_t SendData(const std::string& data, bool last_data); 118 ssize_t SendData(const std::string& data, bool last_data);
121 // As above, but |delegate| will be notified when |data| is ACKed. 119 // As above, but |delegate| will be notified when |data| is ACKed.
122 ssize_t SendData(const std::string& data, 120 ssize_t SendData(const std::string& data,
123 bool last_data, 121 bool last_data,
124 QuicAckListenerInterface* delegate); 122 QuicAckListenerInterface* delegate);
125 123
126 // From SimpleClient
127 // Clears any outstanding state and sends a simple GET of 'uri' to the 124 // Clears any outstanding state and sends a simple GET of 'uri' to the
128 // server. Returns 0 if the request failed and no bytes were written. 125 // server. Returns 0 if the request failed and no bytes were written.
129 ssize_t SendRequest(const std::string& uri) override; 126 ssize_t SendRequest(const std::string& uri);
130 // Sends requests for all the urls and waits for the responses. To process 127 // Sends requests for all the urls and waits for the responses. To process
131 // the individual responses as they are returned, the caller should use the 128 // the individual responses as they are returned, the caller should use the
132 // set the response_listener on the client(). 129 // set the response_listener on the client().
133 void SendRequestsAndWaitForResponses( 130 void SendRequestsAndWaitForResponses(
134 const std::vector<std::string>& url_list); 131 const std::vector<std::string>& url_list);
135 ssize_t SendMessage(const HTTPMessage& message) override; 132 ssize_t SendMessage(const HTTPMessage& message);
136 std::string SendCustomSynchronousRequest(const HTTPMessage& message) override; 133 std::string SendCustomSynchronousRequest(const HTTPMessage& message);
137 std::string SendSynchronousRequest(const std::string& uri) override; 134 std::string SendSynchronousRequest(const std::string& uri);
138 void Connect() override; 135 void Connect();
139 void ResetConnection() override; 136 void ResetConnection();
140 void Disconnect() override; 137 void Disconnect();
141 IPEndPoint local_address() const override; 138 IPEndPoint local_address() const;
142 void ClearPerRequestState() override; 139 void ClearPerRequestState();
143 bool WaitUntil(int timeout_ms, std::function<bool()> trigger) override; 140 bool WaitUntil(int timeout_ms, std::function<bool()> trigger);
144 ssize_t Send(const void* buffer, size_t size) override; 141 ssize_t Send(const void* buffer, size_t size);
145 bool response_complete() const override; 142 bool response_complete() const;
146 bool response_headers_complete() const override; 143 bool response_headers_complete() const;
147 const BalsaHeaders* response_headers() const override; 144 const BalsaHeaders* response_headers() const;
148 int64_t response_size() const override; 145 int64_t response_size() const;
149 int response_header_size() const override; 146 int response_header_size() const;
150 int64_t response_body_size() const override; 147 int64_t response_body_size() const;
151 size_t bytes_read() const override; 148 size_t bytes_read() const;
152 size_t bytes_written() const override; 149 size_t bytes_written() const;
153 bool buffer_body() const override; 150 bool buffer_body() const;
154 void set_buffer_body(bool buffer_body) override; 151 void set_buffer_body(bool buffer_body);
155 bool ServerInLameDuckMode() const override; 152 const std::string& response_body();
156 const std::string& response_body() override; 153 bool connected() const;
157 bool connected() const override; 154
158 // These functions are all unimplemented functions from SimpleClient, and log 155 // Returns once a complete response or a connection close has been received
159 // DFATAL if called by users of SimpleClient. 156 // from the server.
160 ssize_t SendAndWaitForResponse(const void* buffer, size_t size) override; 157 void WaitForResponse() { WaitForResponseForMs(-1); }
161 void Bind(IPEndPoint* local_address) override; 158
162 void MigrateSocket(const IPAddress& new_host) override; 159 // Waits for some data or response from the server.
163 std::string SerializeMessage(const HTTPMessage& message) override; 160 void WaitForInitialResponse() { WaitForInitialResponseForMs(-1); }
164 IPAddress bind_to_address() const override; 161
165 void set_bind_to_address(const IPAddress& address) override; 162 // Returns once a complete response or a connection close has been received
166 const IPEndPoint& address() const override; 163 // from the server, or once the timeout expires. -1 for no timeout.
167 size_t requests_sent() const override; 164 void WaitForResponseForMs(int timeout_ms) {
165 WaitUntil(timeout_ms, [this]() { return response_complete(); });
166 if (response_complete()) {
167 VLOG(1) << "Client received response:"
168 << response_headers()->DebugString() << response_body();
169 }
170 }
171
172 // Waits for some data or response from the server, or once the timeout
173 // expires. -1 for no timeout.
174 void WaitForInitialResponseForMs(int timeout_ms) {
175 WaitUntil(timeout_ms, [this]() { return response_size() != 0; });
176 }
177
178 void MigrateSocket(const IPAddress& new_host);
179 IPAddress bind_to_address() const;
180 void set_bind_to_address(IPAddress address);
181 const IPEndPoint& address() const;
168 182
169 // Returns the response trailers as received by the |stream_|. 183 // Returns the response trailers as received by the |stream_|.
170 const SpdyHeaderBlock& response_trailers() const; 184 const SpdyHeaderBlock& response_trailers() const;
171 185
172 // From QuicSpdyStream::Visitor 186 // From QuicSpdyStream::Visitor
173 void OnClose(QuicSpdyStream* stream) override; 187 void OnClose(QuicSpdyStream* stream) override;
174 188
175 // From QuicClientPushPromiseIndex::Delegate 189 // From QuicClientPushPromiseIndex::Delegate
176 bool CheckVary(const SpdyHeaderBlock& client_request, 190 bool CheckVary(const SpdyHeaderBlock& client_request,
177 const SpdyHeaderBlock& promise_request, 191 const SpdyHeaderBlock& promise_request,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 client_->set_server_address(server_address); 250 client_->set_server_address(server_address);
237 } 251 }
238 252
239 // Explicitly set the SNI value for this client, overriding the default 253 // Explicitly set the SNI value for this client, overriding the default
240 // behavior which extracts the SNI value from the request URL. 254 // behavior which extracts the SNI value from the request URL.
241 void OverrideSni(const std::string& sni) { 255 void OverrideSni(const std::string& sni) {
242 override_sni_set_ = true; 256 override_sni_set_ = true;
243 override_sni_ = sni; 257 override_sni_ = sni;
244 } 258 }
245 259
246 protected:
247 QuicTestClient();
248
249 void Initialize(); 260 void Initialize();
250 261
251 void set_client(MockableQuicClient* client) { client_.reset(client); } 262 void set_client(MockableQuicClient* client) { client_.reset(client); }
252 263
264 protected:
265 QuicTestClient();
266
253 private: 267 private:
254 class TestClientDataToResend : public QuicClient::QuicDataToResend { 268 class TestClientDataToResend : public QuicClient::QuicDataToResend {
255 public: 269 public:
256 TestClientDataToResend(std::unique_ptr<SpdyHeaderBlock> headers, 270 TestClientDataToResend(std::unique_ptr<SpdyHeaderBlock> headers,
257 base::StringPiece body, 271 base::StringPiece body,
258 bool fin, 272 bool fin,
259 QuicTestClient* test_client, 273 QuicTestClient* test_client,
260 QuicAckListenerInterface* delegate) 274 QuicAckListenerInterface* delegate)
261 : QuicClient::QuicDataToResend(std::move(headers), body, fin), 275 : QuicClient::QuicDataToResend(std::move(headers), body, fin),
262 test_client_(test_client), 276 test_client_(test_client),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 std::string override_sni_; 337 std::string override_sni_;
324 338
325 DISALLOW_COPY_AND_ASSIGN(QuicTestClient); 339 DISALLOW_COPY_AND_ASSIGN(QuicTestClient);
326 }; 340 };
327 341
328 } // namespace test 342 } // namespace test
329 343
330 } // namespace net 344 } // namespace net
331 345
332 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_ 346 #endif // NET_TOOLS_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_
OLDNEW
« no previous file with comments | « net/tools/quic/stateless_rejector.cc ('k') | net/tools/quic/test_tools/quic_test_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698