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 #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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/tools/quic/quic_spdy_client_stream.h" | 21 #include "net/tools/quic/quic_spdy_client_stream.h" |
22 #include "net/tools/quic/test_tools/http_message.h" | 22 #include "net/tools/quic/test_tools/http_message.h" |
23 #include "net/tools/quic/test_tools/quic_client_peer.h" | 23 #include "net/tools/quic/test_tools/quic_client_peer.h" |
24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
25 | 25 |
26 using base::StringPiece; | 26 using base::StringPiece; |
27 using net::QuicServerId; | 27 using net::QuicServerId; |
28 using net::test::QuicConnectionPeer; | 28 using net::test::QuicConnectionPeer; |
29 using net::test::QuicSessionPeer; | 29 using net::test::QuicSessionPeer; |
30 using net::test::ReliableQuicStreamPeer; | 30 using net::test::ReliableQuicStreamPeer; |
31 using net::test::kInitialFlowControlWindowForTest; | |
32 using std::string; | 31 using std::string; |
33 using std::vector; | 32 using std::vector; |
34 | 33 |
35 namespace net { | 34 namespace net { |
36 namespace tools { | 35 namespace tools { |
37 namespace test { | 36 namespace test { |
38 namespace { | 37 namespace { |
39 | 38 |
40 // RecordingProofVerifier accepts any certificate chain and records the common | 39 // RecordingProofVerifier accepts any certificate chain and records the common |
41 // name of the leaf. | 40 // name of the leaf. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 "http://www.google.com"; | 96 "http://www.google.com"; |
98 full_uri.append(uri.as_string()); | 97 full_uri.append(uri.as_string()); |
99 headers->SetRequestUri(full_uri); | 98 headers->SetRequestUri(full_uri); |
100 } | 99 } |
101 return headers; | 100 return headers; |
102 } | 101 } |
103 | 102 |
104 MockableQuicClient::MockableQuicClient( | 103 MockableQuicClient::MockableQuicClient( |
105 IPEndPoint server_address, | 104 IPEndPoint server_address, |
106 const QuicServerId& server_id, | 105 const QuicServerId& server_id, |
107 const QuicVersionVector& supported_versions) | 106 const QuicVersionVector& supported_versions, |
| 107 EpollServer* epoll_server) |
108 : QuicClient(server_address, | 108 : QuicClient(server_address, |
109 server_id, | 109 server_id, |
110 supported_versions, | 110 supported_versions, |
111 false), | 111 false, |
| 112 epoll_server), |
112 override_connection_id_(0), | 113 override_connection_id_(0), |
113 test_writer_(NULL) {} | 114 test_writer_(NULL) {} |
114 | 115 |
115 MockableQuicClient::MockableQuicClient( | 116 MockableQuicClient::MockableQuicClient( |
116 IPEndPoint server_address, | 117 IPEndPoint server_address, |
117 const QuicServerId& server_id, | 118 const QuicServerId& server_id, |
118 const QuicConfig& config, | 119 const QuicConfig& config, |
119 const QuicVersionVector& supported_versions) | 120 const QuicVersionVector& supported_versions, |
| 121 EpollServer* epoll_server) |
120 : QuicClient(server_address, | 122 : QuicClient(server_address, |
121 server_id, | 123 server_id, |
122 supported_versions, | 124 supported_versions, |
123 false, | 125 false, |
124 config), | 126 config, |
| 127 epoll_server), |
125 override_connection_id_(0), | 128 override_connection_id_(0), |
126 test_writer_(NULL) {} | 129 test_writer_(NULL) {} |
127 | 130 |
128 MockableQuicClient::~MockableQuicClient() { | 131 MockableQuicClient::~MockableQuicClient() { |
129 if (connected()) { | 132 if (connected()) { |
130 Disconnect(); | 133 Disconnect(); |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
134 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { | 137 QuicPacketWriter* MockableQuicClient::CreateQuicPacketWriter() { |
(...skipping 21 matching lines...) Expand all Loading... |
156 } | 159 } |
157 | 160 |
158 QuicTestClient::QuicTestClient(IPEndPoint server_address, | 161 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
159 const string& server_hostname, | 162 const string& server_hostname, |
160 const QuicVersionVector& supported_versions) | 163 const QuicVersionVector& supported_versions) |
161 : client_(new MockableQuicClient(server_address, | 164 : client_(new MockableQuicClient(server_address, |
162 QuicServerId(server_hostname, | 165 QuicServerId(server_hostname, |
163 server_address.port(), | 166 server_address.port(), |
164 false, | 167 false, |
165 PRIVACY_MODE_DISABLED), | 168 PRIVACY_MODE_DISABLED), |
166 supported_versions)) { | 169 supported_versions, |
| 170 &epoll_server_)) { |
167 Initialize(true); | 171 Initialize(true); |
168 } | 172 } |
169 | 173 |
170 QuicTestClient::QuicTestClient(IPEndPoint server_address, | 174 QuicTestClient::QuicTestClient(IPEndPoint server_address, |
171 const string& server_hostname, | 175 const string& server_hostname, |
172 bool secure, | 176 bool secure, |
173 const QuicVersionVector& supported_versions) | 177 const QuicVersionVector& supported_versions) |
174 : client_(new MockableQuicClient(server_address, | 178 : client_(new MockableQuicClient(server_address, |
175 QuicServerId(server_hostname, | 179 QuicServerId(server_hostname, |
176 server_address.port(), | 180 server_address.port(), |
177 secure, | 181 secure, |
178 PRIVACY_MODE_DISABLED), | 182 PRIVACY_MODE_DISABLED), |
179 supported_versions)) { | 183 supported_versions, |
| 184 &epoll_server_)) { |
180 Initialize(secure); | 185 Initialize(secure); |
181 } | 186 } |
182 | 187 |
183 QuicTestClient::QuicTestClient( | 188 QuicTestClient::QuicTestClient( |
184 IPEndPoint server_address, | 189 IPEndPoint server_address, |
185 const string& server_hostname, | 190 const string& server_hostname, |
186 bool secure, | 191 bool secure, |
187 const QuicConfig& config, | 192 const QuicConfig& config, |
188 const QuicVersionVector& supported_versions) | 193 const QuicVersionVector& supported_versions) |
189 : client_( | 194 : client_( |
190 new MockableQuicClient(server_address, | 195 new MockableQuicClient(server_address, |
191 QuicServerId(server_hostname, | 196 QuicServerId(server_hostname, |
192 server_address.port(), | 197 server_address.port(), |
193 secure, | 198 secure, |
194 PRIVACY_MODE_DISABLED), | 199 PRIVACY_MODE_DISABLED), |
195 config, | 200 config, |
196 supported_versions)) { | 201 supported_versions, |
| 202 &epoll_server_)) { |
197 Initialize(secure); | 203 Initialize(secure); |
198 } | 204 } |
199 | 205 |
200 QuicTestClient::QuicTestClient() { | 206 QuicTestClient::QuicTestClient() { |
201 } | 207 } |
202 | 208 |
203 QuicTestClient::~QuicTestClient() { | 209 QuicTestClient::~QuicTestClient() { |
204 if (stream_) { | 210 if (stream_) { |
205 stream_->set_visitor(NULL); | 211 stream_->set_visitor(NULL); |
206 } | 212 } |
(...skipping 14 matching lines...) Expand all Loading... |
221 void QuicTestClient::ExpectCertificates(bool on) { | 227 void QuicTestClient::ExpectCertificates(bool on) { |
222 if (on) { | 228 if (on) { |
223 proof_verifier_ = new RecordingProofVerifier; | 229 proof_verifier_ = new RecordingProofVerifier; |
224 client_->SetProofVerifier(proof_verifier_); | 230 client_->SetProofVerifier(proof_verifier_); |
225 } else { | 231 } else { |
226 proof_verifier_ = NULL; | 232 proof_verifier_ = NULL; |
227 client_->SetProofVerifier(NULL); | 233 client_->SetProofVerifier(NULL); |
228 } | 234 } |
229 } | 235 } |
230 | 236 |
| 237 void QuicTestClient::SetUserAgentID(const string& user_agent_id) { |
| 238 client_->SetUserAgentID(user_agent_id); |
| 239 } |
| 240 |
231 ssize_t QuicTestClient::SendRequest(const string& uri) { | 241 ssize_t QuicTestClient::SendRequest(const string& uri) { |
232 HTTPMessage message(HttpConstants::HTTP_1_1, | 242 HTTPMessage message(HttpConstants::HTTP_1_1, |
233 HttpConstants::GET, | 243 HttpConstants::GET, |
234 uri); | 244 uri); |
235 return SendMessage(message); | 245 return SendMessage(message); |
236 } | 246 } |
237 | 247 |
238 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { | 248 ssize_t QuicTestClient::SendMessage(const HTTPMessage& message) { |
239 stream_ = NULL; // Always force creation of a stream for SendMessage. | 249 stream_ = NULL; // Always force creation of a stream for SendMessage. |
240 | 250 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 response_headers_complete_ = false; | 407 response_headers_complete_ = false; |
398 headers_.Clear(); | 408 headers_.Clear(); |
399 bytes_read_ = 0; | 409 bytes_read_ = 0; |
400 bytes_written_ = 0; | 410 bytes_written_ = 0; |
401 response_header_size_ = 0; | 411 response_header_size_ = 0; |
402 response_body_size_ = 0; | 412 response_body_size_ = 0; |
403 } | 413 } |
404 | 414 |
405 void QuicTestClient::WaitForResponseForMs(int timeout_ms) { | 415 void QuicTestClient::WaitForResponseForMs(int timeout_ms) { |
406 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; | 416 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; |
407 int64 old_timeout_us = client()->epoll_server()->timeout_in_us(); | 417 int64 old_timeout_us = epoll_server()->timeout_in_us(); |
408 if (timeout_us > 0) { | 418 if (timeout_us > 0) { |
409 client()->epoll_server()->set_timeout_in_us(timeout_us); | 419 epoll_server()->set_timeout_in_us(timeout_us); |
410 } | 420 } |
411 const QuicClock* clock = | 421 const QuicClock* clock = |
412 QuicConnectionPeer::GetHelper(client()->session()->connection())-> | 422 QuicConnectionPeer::GetHelper(client()->session()->connection())-> |
413 GetClock(); | 423 GetClock(); |
414 QuicTime end_waiting_time = clock->Now().Add( | 424 QuicTime end_waiting_time = clock->Now().Add( |
415 QuicTime::Delta::FromMicroseconds(timeout_us)); | 425 QuicTime::Delta::FromMicroseconds(timeout_us)); |
416 while (stream_ != NULL && | 426 while (stream_ != NULL && |
417 !client_->session()->IsClosedStream(stream_->id()) && | 427 !client_->session()->IsClosedStream(stream_->id()) && |
418 (timeout_us < 0 || clock->Now() < end_waiting_time)) { | 428 (timeout_us < 0 || clock->Now() < end_waiting_time)) { |
419 client_->WaitForEvents(); | 429 client_->WaitForEvents(); |
420 } | 430 } |
421 if (timeout_us > 0) { | 431 if (timeout_us > 0) { |
422 client()->epoll_server()->set_timeout_in_us(old_timeout_us); | 432 epoll_server()->set_timeout_in_us(old_timeout_us); |
423 } | 433 } |
424 } | 434 } |
425 | 435 |
426 void QuicTestClient::WaitForInitialResponseForMs(int timeout_ms) { | 436 void QuicTestClient::WaitForInitialResponseForMs(int timeout_ms) { |
427 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; | 437 int64 timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; |
428 int64 old_timeout_us = client()->epoll_server()->timeout_in_us(); | 438 int64 old_timeout_us = epoll_server()->timeout_in_us(); |
429 if (timeout_us > 0) { | 439 if (timeout_us > 0) { |
430 client()->epoll_server()->set_timeout_in_us(timeout_us); | 440 epoll_server()->set_timeout_in_us(timeout_us); |
431 } | 441 } |
432 const QuicClock* clock = | 442 const QuicClock* clock = |
433 QuicConnectionPeer::GetHelper(client()->session()->connection())-> | 443 QuicConnectionPeer::GetHelper(client()->session()->connection())-> |
434 GetClock(); | 444 GetClock(); |
435 QuicTime end_waiting_time = clock->Now().Add( | 445 QuicTime end_waiting_time = clock->Now().Add( |
436 QuicTime::Delta::FromMicroseconds(timeout_us)); | 446 QuicTime::Delta::FromMicroseconds(timeout_us)); |
437 while (stream_ != NULL && | 447 while (stream_ != NULL && |
438 !client_->session()->IsClosedStream(stream_->id()) && | 448 !client_->session()->IsClosedStream(stream_->id()) && |
439 stream_->stream_bytes_read() == 0 && | 449 stream_->stream_bytes_read() == 0 && |
440 (timeout_us < 0 || clock->Now() < end_waiting_time)) { | 450 (timeout_us < 0 || clock->Now() < end_waiting_time)) { |
441 client_->WaitForEvents(); | 451 client_->WaitForEvents(); |
442 } | 452 } |
443 if (timeout_us > 0) { | 453 if (timeout_us > 0) { |
444 client()->epoll_server()->set_timeout_in_us(old_timeout_us); | 454 epoll_server()->set_timeout_in_us(old_timeout_us); |
445 } | 455 } |
446 } | 456 } |
447 | 457 |
448 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { | 458 ssize_t QuicTestClient::Send(const void *buffer, size_t size) { |
449 return SendData(string(static_cast<const char*>(buffer), size), false); | 459 return SendData(string(static_cast<const char*>(buffer), size), false); |
450 } | 460 } |
451 | 461 |
452 bool QuicTestClient::response_headers_complete() const { | 462 bool QuicTestClient::response_headers_complete() const { |
453 if (stream_ != NULL) { | 463 if (stream_ != NULL) { |
454 return stream_->headers_decompressed(); | 464 return stream_->headers_decompressed(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // Set policy for headers and crypto streams. | 560 // Set policy for headers and crypto streams. |
551 ReliableQuicStreamPeer::SetFecPolicy( | 561 ReliableQuicStreamPeer::SetFecPolicy( |
552 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); | 562 QuicSessionPeer::GetHeadersStream(client()->session()), fec_policy); |
553 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), | 563 ReliableQuicStreamPeer::SetFecPolicy(client()->session()->GetCryptoStream(), |
554 fec_policy); | 564 fec_policy); |
555 } | 565 } |
556 | 566 |
557 } // namespace test | 567 } // namespace test |
558 } // namespace tools | 568 } // namespace tools |
559 } // namespace net | 569 } // namespace net |
OLD | NEW |