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

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

Issue 330333006: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linus_tsan error - reverted the change to ConnectionMigrationClientPortChanged unitttest Created 6 years, 6 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 | Annotate | Revision Log
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 #include "net/tools/quic/test_tools/quic_test_client.h" 5 #include "net/tools/quic/test_tools/quic_test_client.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/cert/cert_verify_result.h" 10 #include "net/cert/cert_verify_result.h"
11 #include "net/cert/x509_certificate.h" 11 #include "net/cert/x509_certificate.h"
12 #include "net/quic/crypto/proof_verifier.h" 12 #include "net/quic/crypto/proof_verifier.h"
13 #include "net/quic/quic_server_id.h" 13 #include "net/quic/quic_server_id.h"
14 #include "net/quic/test_tools/quic_connection_peer.h" 14 #include "net/quic/test_tools/quic_connection_peer.h"
15 #include "net/quic/test_tools/quic_session_peer.h"
15 #include "net/quic/test_tools/quic_test_utils.h" 16 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
16 #include "net/tools/balsa/balsa_headers.h" 18 #include "net/tools/balsa/balsa_headers.h"
17 #include "net/tools/quic/quic_epoll_connection_helper.h" 19 #include "net/tools/quic/quic_epoll_connection_helper.h"
18 #include "net/tools/quic/quic_packet_writer_wrapper.h" 20 #include "net/tools/quic/quic_packet_writer_wrapper.h"
19 #include "net/tools/quic/quic_spdy_client_stream.h" 21 #include "net/tools/quic/quic_spdy_client_stream.h"
20 #include "net/tools/quic/test_tools/http_message.h" 22 #include "net/tools/quic/test_tools/http_message.h"
21 #include "net/tools/quic/test_tools/quic_client_peer.h" 23 #include "net/tools/quic/test_tools/quic_client_peer.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
23 25
24 using base::StringPiece; 26 using base::StringPiece;
25 using net::QuicServerId; 27 using net::QuicServerId;
28 using net::test::QuicConnectionPeer;
29 using net::test::QuicSessionPeer;
30 using net::test::ReliableQuicStreamPeer;
26 using net::test::kInitialFlowControlWindowForTest; 31 using net::test::kInitialFlowControlWindowForTest;
27 using net::test::QuicConnectionPeer;
28 using std::string; 32 using std::string;
29 using std::vector; 33 using std::vector;
30 34
31 namespace net { 35 namespace net {
32 namespace tools { 36 namespace tools {
33 namespace test { 37 namespace test {
34 namespace { 38 namespace {
35 39
36 // RecordingProofVerifier accepts any certificate chain and records the common 40 // RecordingProofVerifier accepts any certificate chain and records the common
37 // name of the leaf. 41 // name of the leaf.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 "http://www.google.com"; 97 "http://www.google.com";
94 full_uri.append(uri.as_string()); 98 full_uri.append(uri.as_string());
95 headers->SetRequestUri(full_uri); 99 headers->SetRequestUri(full_uri);
96 } 100 }
97 return headers; 101 return headers;
98 } 102 }
99 103
100 MockableQuicClient::MockableQuicClient( 104 MockableQuicClient::MockableQuicClient(
101 IPEndPoint server_address, 105 IPEndPoint server_address,
102 const QuicServerId& server_id, 106 const QuicServerId& server_id,
103 const QuicVersionVector& supported_versions, 107 const QuicVersionVector& supported_versions)
104 uint32 initial_flow_control_window)
105 : QuicClient(server_address, 108 : QuicClient(server_address,
106 server_id, 109 server_id,
107 supported_versions, 110 supported_versions,
108 false, 111 false),
109 initial_flow_control_window),
110 override_connection_id_(0), 112 override_connection_id_(0),
111 test_writer_(NULL) {} 113 test_writer_(NULL) {}
112 114
113 MockableQuicClient::MockableQuicClient( 115 MockableQuicClient::MockableQuicClient(
114 IPEndPoint server_address, 116 IPEndPoint server_address,
115 const QuicServerId& server_id, 117 const QuicServerId& server_id,
116 const QuicConfig& config, 118 const QuicConfig& config,
117 const QuicVersionVector& supported_versions, 119 const QuicVersionVector& supported_versions)
118 uint32 initial_flow_control_window)
119 : QuicClient(server_address, 120 : QuicClient(server_address,
120 server_id, 121 server_id,
121 config,
122 supported_versions, 122 supported_versions,
123 initial_flow_control_window), 123 false,
124 config),
124 override_connection_id_(0), 125 override_connection_id_(0),
125 test_writer_(NULL) {} 126 test_writer_(NULL) {}
126 127
127 MockableQuicClient::~MockableQuicClient() { 128 MockableQuicClient::~MockableQuicClient() {
128 if (connected()) { 129 if (connected()) {
129 Disconnect(); 130 Disconnect();
130 } 131 }
131 } 132 }
132 133
133 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { 134 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() {
(...skipping 21 matching lines...) Expand all
155 } 156 }
156 157
157 QuicTestClient::QuicTestClient(IPEndPoint server_address, 158 QuicTestClient::QuicTestClient(IPEndPoint server_address,
158 const string& server_hostname, 159 const string& server_hostname,
159 const QuicVersionVector& supported_versions) 160 const QuicVersionVector& supported_versions)
160 : client_(new MockableQuicClient(server_address, 161 : client_(new MockableQuicClient(server_address,
161 QuicServerId(server_hostname, 162 QuicServerId(server_hostname,
162 server_address.port(), 163 server_address.port(),
163 false, 164 false,
164 PRIVACY_MODE_DISABLED), 165 PRIVACY_MODE_DISABLED),
165 supported_versions, 166 supported_versions)) {
166 kInitialFlowControlWindowForTest)) {
167 Initialize(true); 167 Initialize(true);
168 } 168 }
169 169
170 QuicTestClient::QuicTestClient(IPEndPoint server_address, 170 QuicTestClient::QuicTestClient(IPEndPoint server_address,
171 const string& server_hostname, 171 const string& server_hostname,
172 bool secure, 172 bool secure,
173 const QuicVersionVector& supported_versions) 173 const QuicVersionVector& supported_versions)
174 : client_(new MockableQuicClient(server_address, 174 : client_(new MockableQuicClient(server_address,
175 QuicServerId(server_hostname, 175 QuicServerId(server_hostname,
176 server_address.port(), 176 server_address.port(),
177 secure, 177 secure,
178 PRIVACY_MODE_DISABLED), 178 PRIVACY_MODE_DISABLED),
179 supported_versions, 179 supported_versions)) {
180 kInitialFlowControlWindowForTest)) {
181 Initialize(secure); 180 Initialize(secure);
182 } 181 }
183 182
184 QuicTestClient::QuicTestClient( 183 QuicTestClient::QuicTestClient(
185 IPEndPoint server_address, 184 IPEndPoint server_address,
186 const string& server_hostname, 185 const string& server_hostname,
187 bool secure, 186 bool secure,
188 const QuicConfig& config, 187 const QuicConfig& config,
189 const QuicVersionVector& supported_versions, 188 const QuicVersionVector& supported_versions)
190 uint32 client_initial_flow_control_receive_window)
191 : client_( 189 : client_(
192 new MockableQuicClient(server_address, 190 new MockableQuicClient(server_address,
193 QuicServerId(server_hostname, 191 QuicServerId(server_hostname,
194 server_address.port(), 192 server_address.port(),
195 secure, 193 secure,
196 PRIVACY_MODE_DISABLED), 194 PRIVACY_MODE_DISABLED),
197 config, 195 config,
198 supported_versions, 196 supported_versions)) {
199 client_initial_flow_control_receive_window)) {
200 Initialize(secure); 197 Initialize(secure);
201 } 198 }
202 199
203 QuicTestClient::QuicTestClient() { 200 QuicTestClient::QuicTestClient() {
204 } 201 }
205 202
206 QuicTestClient::~QuicTestClient() { 203 QuicTestClient::~QuicTestClient() {
207 if (stream_) { 204 if (stream_) {
208 stream_->set_visitor(NULL); 205 stream_->set_visitor(NULL);
209 } 206 }
210 } 207 }
211 208
212 void QuicTestClient::Initialize(bool secure) { 209 void QuicTestClient::Initialize(bool secure) {
213 priority_ = 3; 210 priority_ = 3;
214 connect_attempted_ = false; 211 connect_attempted_ = false;
215 secure_ = secure; 212 secure_ = secure;
216 auto_reconnect_ = false; 213 auto_reconnect_ = false;
217 buffer_body_ = true; 214 buffer_body_ = true;
215 fec_policy_ = FEC_PROTECT_OPTIONAL;
218 proof_verifier_ = NULL; 216 proof_verifier_ = NULL;
219 ClearPerRequestState(); 217 ClearPerRequestState();
220 ExpectCertificates(secure_); 218 ExpectCertificates(secure_);
221 } 219 }
222 220
223 void QuicTestClient::ExpectCertificates(bool on) { 221 void QuicTestClient::ExpectCertificates(bool on) {
224 if (on) { 222 if (on) {
225 proof_verifier_ = new RecordingProofVerifier; 223 proof_verifier_ = new RecordingProofVerifier;
226 client_->SetProofVerifier(proof_verifier_); 224 client_->SetProofVerifier(proof_verifier_);
227 } else { 225 } else {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return NULL; 324 return NULL;
327 } 325 }
328 } 326 }
329 if (!stream_) { 327 if (!stream_) {
330 stream_ = client_->CreateReliableClientStream(); 328 stream_ = client_->CreateReliableClientStream();
331 if (stream_ == NULL) { 329 if (stream_ == NULL) {
332 return NULL; 330 return NULL;
333 } 331 }
334 stream_->set_visitor(this); 332 stream_->set_visitor(this);
335 reinterpret_cast<QuicSpdyClientStream*>(stream_)->set_priority(priority_); 333 reinterpret_cast<QuicSpdyClientStream*>(stream_)->set_priority(priority_);
334 // Set FEC policy on stream.
335 ReliableQuicStreamPeer::SetFecPolicy(stream_, fec_policy_);
336 } 336 }
337 337
338 return stream_; 338 return stream_;
339 } 339 }
340 340
341 QuicErrorCode QuicTestClient::connection_error() { 341 QuicErrorCode QuicTestClient::connection_error() {
342 return client()->session()->error(); 342 return client()->session()->error();
343 } 343 }
344 344
345 MockableQuicClient* QuicTestClient::client() { return client_.get(); } 345 MockableQuicClient* QuicTestClient::client() { return client_.get(); }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 LOG(DFATAL) << "Not implemented"; 538 LOG(DFATAL) << "Not implemented";
539 return 0; 539 return 0;
540 } 540 }
541 541
542 void QuicTestClient::WaitForWriteToFlush() { 542 void QuicTestClient::WaitForWriteToFlush() {
543 while (connected() && client()->session()->HasDataToWrite()) { 543 while (connected() && client()->session()->HasDataToWrite()) {
544 client_->WaitForEvents(); 544 client_->WaitForEvents();
545 } 545 }
546 } 546 }
547 547
548 void QuicTestClient::SetFecPolicy(FecPolicy fec_policy) {
549 fec_policy_ = fec_policy;
550 // Set policy for headers and crypto streams.
551 ReliableQuicStreamPeer::SetFecPolicy(
552 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy);
553 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(),
554 fec_policy);
555 }
556
548 } // namespace test 557 } // namespace test
549 } // namespace tools 558 } // namespace tools
550 } // namespace net 559 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/test_tools/quic_test_client.h ('k') | net/tools/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698