| 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" |
| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 stream_->set_visitor(NULL); | 205 stream_->set_visitor(NULL); |
| 202 } | 206 } |
| 203 } | 207 } |
| 204 | 208 |
| 205 void QuicTestClient::Initialize(bool secure) { | 209 void QuicTestClient::Initialize(bool secure) { |
| 206 priority_ = 3; | 210 priority_ = 3; |
| 207 connect_attempted_ = false; | 211 connect_attempted_ = false; |
| 208 secure_ = secure; | 212 secure_ = secure; |
| 209 auto_reconnect_ = false; | 213 auto_reconnect_ = false; |
| 210 buffer_body_ = true; | 214 buffer_body_ = true; |
| 215 fec_policy_ = PROTECT_OPTIONAL; |
| 211 proof_verifier_ = NULL; | 216 proof_verifier_ = NULL; |
| 212 ClearPerRequestState(); | 217 ClearPerRequestState(); |
| 213 ExpectCertificates(secure_); | 218 ExpectCertificates(secure_); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void QuicTestClient::ExpectCertificates(bool on) { | 221 void QuicTestClient::ExpectCertificates(bool on) { |
| 217 if (on) { | 222 if (on) { |
| 218 proof_verifier_ = new RecordingProofVerifier; | 223 proof_verifier_ = new RecordingProofVerifier; |
| 219 client_->SetProofVerifier(proof_verifier_); | 224 client_->SetProofVerifier(proof_verifier_); |
| 220 } else { | 225 } else { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return NULL; | 324 return NULL; |
| 320 } | 325 } |
| 321 } | 326 } |
| 322 if (!stream_) { | 327 if (!stream_) { |
| 323 stream_ = client_->CreateReliableClientStream(); | 328 stream_ = client_->CreateReliableClientStream(); |
| 324 if (stream_ == NULL) { | 329 if (stream_ == NULL) { |
| 325 return NULL; | 330 return NULL; |
| 326 } | 331 } |
| 327 stream_->set_visitor(this); | 332 stream_->set_visitor(this); |
| 328 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_); |
| 329 } | 336 } |
| 330 | 337 |
| 331 return stream_; | 338 return stream_; |
| 332 } | 339 } |
| 333 | 340 |
| 334 QuicErrorCode QuicTestClient::connection_error() { | 341 QuicErrorCode QuicTestClient::connection_error() { |
| 335 return client()->session()->error(); | 342 return client()->session()->error(); |
| 336 } | 343 } |
| 337 | 344 |
| 338 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 Loading... |
| 531 LOG(DFATAL) << "Not implemented"; | 538 LOG(DFATAL) << "Not implemented"; |
| 532 return 0; | 539 return 0; |
| 533 } | 540 } |
| 534 | 541 |
| 535 void QuicTestClient::WaitForWriteToFlush() { | 542 void QuicTestClient::WaitForWriteToFlush() { |
| 536 while (connected() && client()->session()->HasDataToWrite()) { | 543 while (connected() && client()->session()->HasDataToWrite()) { |
| 537 client_->WaitForEvents(); | 544 client_->WaitForEvents(); |
| 538 } | 545 } |
| 539 } | 546 } |
| 540 | 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 |
| 541 } // namespace test | 557 } // namespace test |
| 542 } // namespace tools | 558 } // namespace tools |
| 543 } // namespace net | 559 } // namespace net |
| OLD | NEW |