| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return headers; | 95 return headers; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // A quic client which allows mocking out writes. | 98 // A quic client which allows mocking out writes. |
| 99 class MockableQuicClient : public QuicClient { | 99 class MockableQuicClient : public QuicClient { |
| 100 public: | 100 public: |
| 101 MockableQuicClient(IPEndPoint server_address, | 101 MockableQuicClient(IPEndPoint server_address, |
| 102 const string& server_hostname, | 102 const string& server_hostname, |
| 103 const QuicVersionVector& supported_versions) | 103 const QuicVersionVector& supported_versions) |
| 104 : QuicClient(server_address, server_hostname, supported_versions, false), | 104 : QuicClient(server_address, server_hostname, supported_versions, false), |
| 105 override_guid_(0), | 105 override_connection_id_(0), |
| 106 test_writer_(NULL) {} | 106 test_writer_(NULL) {} |
| 107 | 107 |
| 108 MockableQuicClient(IPEndPoint server_address, | 108 MockableQuicClient(IPEndPoint server_address, |
| 109 const string& server_hostname, | 109 const string& server_hostname, |
| 110 const QuicConfig& config, | 110 const QuicConfig& config, |
| 111 const QuicVersionVector& supported_versions) | 111 const QuicVersionVector& supported_versions) |
| 112 : QuicClient(server_address, server_hostname, config, supported_versions), | 112 : QuicClient(server_address, server_hostname, config, supported_versions), |
| 113 override_guid_(0), | 113 override_connection_id_(0), |
| 114 test_writer_(NULL) {} | 114 test_writer_(NULL) {} |
| 115 | 115 |
| 116 virtual ~MockableQuicClient() { | 116 virtual ~MockableQuicClient() { |
| 117 if (connected()) { | 117 if (connected()) { |
| 118 Disconnect(); | 118 Disconnect(); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 virtual QuicPacketWriter* CreateQuicPacketWriter() OVERRIDE { | 122 virtual QuicPacketWriter* CreateQuicPacketWriter() OVERRIDE { |
| 123 QuicPacketWriter* writer = QuicClient::CreateQuicPacketWriter(); | 123 QuicPacketWriter* writer = QuicClient::CreateQuicPacketWriter(); |
| 124 if (!test_writer_) { | 124 if (!test_writer_) { |
| 125 return writer; | 125 return writer; |
| 126 } | 126 } |
| 127 test_writer_->set_writer(writer); | 127 test_writer_->set_writer(writer); |
| 128 return test_writer_; | 128 return test_writer_; |
| 129 } | 129 } |
| 130 | 130 |
| 131 virtual QuicGuid GenerateGuid() OVERRIDE { | 131 virtual QuicConnectionId GenerateConnectionId() OVERRIDE { |
| 132 return override_guid_ ? override_guid_ : QuicClient::GenerateGuid(); | 132 return override_connection_id_ ? override_connection_id_ |
| 133 : QuicClient::GenerateConnectionId(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Takes ownership of writer. | 136 // Takes ownership of writer. |
| 136 void UseWriter(QuicPacketWriterWrapper* writer) { test_writer_ = writer; } | 137 void UseWriter(QuicPacketWriterWrapper* writer) { test_writer_ = writer; } |
| 137 | 138 |
| 138 void UseGuid(QuicGuid guid) { override_guid_ = guid; } | 139 void UseConnectionId(QuicConnectionId connection_id) { |
| 140 override_connection_id_ = connection_id; |
| 141 } |
| 139 | 142 |
| 140 private: | 143 private: |
| 141 QuicGuid override_guid_; // GUID to use, if nonzero | 144 QuicConnectionId override_connection_id_; // ConnectionId to use, if nonzero |
| 142 QuicPacketWriterWrapper* test_writer_; | 145 QuicPacketWriterWrapper* test_writer_; |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 QuicTestClient::QuicTestClient(IPEndPoint address, const string& hostname, | 148 QuicTestClient::QuicTestClient(IPEndPoint address, const string& hostname, |
| 146 const QuicVersionVector& supported_versions) | 149 const QuicVersionVector& supported_versions) |
| 147 : client_(new MockableQuicClient(address, hostname, supported_versions)) { | 150 : client_(new MockableQuicClient(address, hostname, supported_versions)) { |
| 148 Initialize(address, hostname, true); | 151 Initialize(address, hostname, true); |
| 149 } | 152 } |
| 150 | 153 |
| 151 QuicTestClient::QuicTestClient(IPEndPoint address, | 154 QuicTestClient::QuicTestClient(IPEndPoint address, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 stream_->stream_bytes_written() + stream_->header_bytes_written(); | 441 stream_->stream_bytes_written() + stream_->header_bytes_written(); |
| 439 response_header_size_ = headers_.GetSizeForWriteBuffer(); | 442 response_header_size_ = headers_.GetSizeForWriteBuffer(); |
| 440 response_body_size_ = stream_->data().size(); | 443 response_body_size_ = stream_->data().size(); |
| 441 stream_ = NULL; | 444 stream_ = NULL; |
| 442 } | 445 } |
| 443 | 446 |
| 444 void QuicTestClient::UseWriter(QuicPacketWriterWrapper* writer) { | 447 void QuicTestClient::UseWriter(QuicPacketWriterWrapper* writer) { |
| 445 client_->UseWriter(writer); | 448 client_->UseWriter(writer); |
| 446 } | 449 } |
| 447 | 450 |
| 448 void QuicTestClient::UseGuid(QuicGuid guid) { | 451 void QuicTestClient::UseConnectionId(QuicConnectionId connection_id) { |
| 449 DCHECK(!connected()); | 452 DCHECK(!connected()); |
| 450 client_->UseGuid(guid); | 453 client_->UseConnectionId(connection_id); |
| 451 } | 454 } |
| 452 | 455 |
| 453 void QuicTestClient::WaitForWriteToFlush() { | 456 void QuicTestClient::WaitForWriteToFlush() { |
| 454 while (connected() && client()->session()->HasDataToWrite()) { | 457 while (connected() && client()->session()->HasDataToWrite()) { |
| 455 client_->WaitForEvents(); | 458 client_->WaitForEvents(); |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 | 461 |
| 459 } // namespace test | 462 } // namespace test |
| 460 } // namespace tools | 463 } // namespace tools |
| 461 } // namespace net | 464 } // namespace net |
| OLD | NEW |