| 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/quic/test_tools/quic_test_utils.h" | 5 #include "net/quic/test_tools/quic_test_utils.h" |
| 6 | 6 |
| 7 #include "base/sha1.h" | 7 #include "base/sha1.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "net/quic/crypto/crypto_framer.h" | 10 #include "net/quic/crypto/crypto_framer.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 MockConnectionHelper::~MockConnectionHelper() {} | 192 MockConnectionHelper::~MockConnectionHelper() {} |
| 193 | 193 |
| 194 const QuicClock* MockConnectionHelper::GetClock() const { | 194 const QuicClock* MockConnectionHelper::GetClock() const { |
| 195 return &clock_; | 195 return &clock_; |
| 196 } | 196 } |
| 197 | 197 |
| 198 QuicRandom* MockConnectionHelper::GetRandomGenerator() { | 198 QuicRandom* MockConnectionHelper::GetRandomGenerator() { |
| 199 return &random_generator_; | 199 return &random_generator_; |
| 200 } | 200 } |
| 201 | 201 |
| 202 QuicAlarm* MockConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { | 202 QuicAlarm* MockAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) { |
| 203 return new MockConnectionHelper::TestAlarm( | 203 return new MockAlarmFactory::TestAlarm( |
| 204 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); | 204 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 QuicArenaScopedPtr<QuicAlarm> MockConnectionHelper::CreateAlarm( | 207 QuicArenaScopedPtr<QuicAlarm> MockAlarmFactory::CreateAlarm( |
| 208 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, | 208 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 209 QuicConnectionArena* arena) { | 209 QuicConnectionArena* arena) { |
| 210 if (arena != nullptr) { | 210 if (arena != nullptr) { |
| 211 return arena->New<MockConnectionHelper::TestAlarm>(std::move(delegate)); | 211 return arena->New<MockAlarmFactory::TestAlarm>(std::move(delegate)); |
| 212 } else { | 212 } else { |
| 213 return QuicArenaScopedPtr<MockConnectionHelper::TestAlarm>( | 213 return QuicArenaScopedPtr<MockAlarmFactory::TestAlarm>( |
| 214 new TestAlarm(std::move(delegate))); | 214 new TestAlarm(std::move(delegate))); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() { | 218 QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() { |
| 219 return &buffer_allocator_; | 219 return &buffer_allocator_; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) { | 222 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) { |
| 223 clock_.AdvanceTime(delta); | 223 clock_.AdvanceTime(delta); |
| 224 } | 224 } |
| 225 | 225 |
| 226 MockConnection::MockConnection(MockConnectionHelper* helper, | 226 MockConnection::MockConnection(MockConnectionHelper* helper, |
| 227 MockAlarmFactory* alarm_factory, |
| 227 Perspective perspective) | 228 Perspective perspective) |
| 228 : MockConnection(kTestConnectionId, | 229 : MockConnection(kTestConnectionId, |
| 229 IPEndPoint(TestPeerIPAddress(), kTestPort), | 230 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 230 helper, | 231 helper, |
| 232 alarm_factory, |
| 231 perspective, | 233 perspective, |
| 232 QuicSupportedVersions()) {} | 234 QuicSupportedVersions()) {} |
| 233 | 235 |
| 234 MockConnection::MockConnection(IPEndPoint address, | 236 MockConnection::MockConnection(IPEndPoint address, |
| 235 MockConnectionHelper* helper, | 237 MockConnectionHelper* helper, |
| 238 MockAlarmFactory* alarm_factory, |
| 236 Perspective perspective) | 239 Perspective perspective) |
| 237 : MockConnection(kTestConnectionId, | 240 : MockConnection(kTestConnectionId, |
| 238 address, | 241 address, |
| 239 helper, | 242 helper, |
| 243 alarm_factory, |
| 240 perspective, | 244 perspective, |
| 241 QuicSupportedVersions()) {} | 245 QuicSupportedVersions()) {} |
| 242 | 246 |
| 243 MockConnection::MockConnection(QuicConnectionId connection_id, | 247 MockConnection::MockConnection(QuicConnectionId connection_id, |
| 244 MockConnectionHelper* helper, | 248 MockConnectionHelper* helper, |
| 249 MockAlarmFactory* alarm_factory, |
| 245 Perspective perspective) | 250 Perspective perspective) |
| 246 : MockConnection(connection_id, | 251 : MockConnection(connection_id, |
| 247 IPEndPoint(TestPeerIPAddress(), kTestPort), | 252 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 248 helper, | 253 helper, |
| 254 alarm_factory, |
| 249 perspective, | 255 perspective, |
| 250 QuicSupportedVersions()) {} | 256 QuicSupportedVersions()) {} |
| 251 | 257 |
| 252 MockConnection::MockConnection(MockConnectionHelper* helper, | 258 MockConnection::MockConnection(MockConnectionHelper* helper, |
| 259 MockAlarmFactory* alarm_factory, |
| 253 Perspective perspective, | 260 Perspective perspective, |
| 254 const QuicVersionVector& supported_versions) | 261 const QuicVersionVector& supported_versions) |
| 255 : MockConnection(kTestConnectionId, | 262 : MockConnection(kTestConnectionId, |
| 256 IPEndPoint(TestPeerIPAddress(), kTestPort), | 263 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 257 helper, | 264 helper, |
| 265 alarm_factory, |
| 258 perspective, | 266 perspective, |
| 259 supported_versions) {} | 267 supported_versions) {} |
| 260 | 268 |
| 261 MockConnection::MockConnection(QuicConnectionId connection_id, | 269 MockConnection::MockConnection(QuicConnectionId connection_id, |
| 262 IPEndPoint address, | 270 IPEndPoint address, |
| 263 MockConnectionHelper* helper, | 271 MockConnectionHelper* helper, |
| 272 MockAlarmFactory* alarm_factory, |
| 264 Perspective perspective, | 273 Perspective perspective, |
| 265 const QuicVersionVector& supported_versions) | 274 const QuicVersionVector& supported_versions) |
| 266 : QuicConnection(connection_id, | 275 : QuicConnection(connection_id, |
| 267 address, | 276 address, |
| 268 helper, | 277 helper, |
| 278 alarm_factory, |
| 269 new testing::NiceMock<MockPacketWriter>(), | 279 new testing::NiceMock<MockPacketWriter>(), |
| 270 /* owns_writer= */ true, | 280 /* owns_writer= */ true, |
| 271 perspective, | 281 perspective, |
| 272 supported_versions) { | 282 supported_versions) { |
| 273 ON_CALL(*this, OnError(_)) | 283 ON_CALL(*this, OnError(_)) |
| 274 .WillByDefault( | 284 .WillByDefault( |
| 275 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); | 285 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); |
| 276 } | 286 } |
| 277 | 287 |
| 278 MockConnection::~MockConnection() {} | 288 MockConnection::~MockConnection() {} |
| 279 | 289 |
| 280 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 290 void MockConnection::AdvanceTime(QuicTime::Delta delta) { |
| 281 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta); | 291 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta); |
| 282 } | 292 } |
| 283 | 293 |
| 284 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper, | 294 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper, |
| 295 MockAlarmFactory* alarm_factory, |
| 285 Perspective perspective) | 296 Perspective perspective) |
| 286 : MockConnection(helper, perspective) {} | 297 : MockConnection(helper, alarm_factory, perspective) {} |
| 287 | 298 |
| 288 PacketSavingConnection::PacketSavingConnection( | 299 PacketSavingConnection::PacketSavingConnection( |
| 289 MockConnectionHelper* helper, | 300 MockConnectionHelper* helper, |
| 301 MockAlarmFactory* alarm_factory, |
| 290 Perspective perspective, | 302 Perspective perspective, |
| 291 const QuicVersionVector& supported_versions) | 303 const QuicVersionVector& supported_versions) |
| 292 : MockConnection(helper, perspective, supported_versions) {} | 304 : MockConnection(helper, alarm_factory, perspective, supported_versions) {} |
| 293 | 305 |
| 294 PacketSavingConnection::~PacketSavingConnection() { | 306 PacketSavingConnection::~PacketSavingConnection() { |
| 295 STLDeleteElements(&encrypted_packets_); | 307 STLDeleteElements(&encrypted_packets_); |
| 296 } | 308 } |
| 297 | 309 |
| 298 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { | 310 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { |
| 299 encrypted_packets_.push_back(new QuicEncryptedPacket( | 311 encrypted_packets_.push_back(new QuicEncryptedPacket( |
| 300 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); | 312 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); |
| 301 // Transfer ownership of the packet to the SentPacketManager and the | 313 // Transfer ownership of the packet to the SentPacketManager and the |
| 302 // ack notifier to the AckNotifierManager. | 314 // ack notifier to the AckNotifierManager. |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) | 764 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) |
| 753 : QuicReceivedPacketManager(stats) {} | 765 : QuicReceivedPacketManager(stats) {} |
| 754 | 766 |
| 755 MockReceivedPacketManager::~MockReceivedPacketManager() {} | 767 MockReceivedPacketManager::~MockReceivedPacketManager() {} |
| 756 | 768 |
| 757 void CreateClientSessionForTest(QuicServerId server_id, | 769 void CreateClientSessionForTest(QuicServerId server_id, |
| 758 bool supports_stateless_rejects, | 770 bool supports_stateless_rejects, |
| 759 QuicTime::Delta connection_start_time, | 771 QuicTime::Delta connection_start_time, |
| 760 QuicVersionVector supported_versions, | 772 QuicVersionVector supported_versions, |
| 761 MockConnectionHelper* helper, | 773 MockConnectionHelper* helper, |
| 774 MockAlarmFactory* alarm_factory, |
| 762 QuicCryptoClientConfig* crypto_client_config, | 775 QuicCryptoClientConfig* crypto_client_config, |
| 763 PacketSavingConnection** client_connection, | 776 PacketSavingConnection** client_connection, |
| 764 TestQuicSpdyClientSession** client_session) { | 777 TestQuicSpdyClientSession** client_session) { |
| 765 CHECK(crypto_client_config); | 778 CHECK(crypto_client_config); |
| 766 CHECK(client_connection); | 779 CHECK(client_connection); |
| 767 CHECK(client_session); | 780 CHECK(client_session); |
| 768 CHECK(!connection_start_time.IsZero()) | 781 CHECK(!connection_start_time.IsZero()) |
| 769 << "Connections must start at non-zero times, otherwise the " | 782 << "Connections must start at non-zero times, otherwise the " |
| 770 << "strike-register will be unhappy."; | 783 << "strike-register will be unhappy."; |
| 771 | 784 |
| 772 QuicConfig config = supports_stateless_rejects | 785 QuicConfig config = supports_stateless_rejects |
| 773 ? DefaultQuicConfigStatelessRejects() | 786 ? DefaultQuicConfigStatelessRejects() |
| 774 : DefaultQuicConfig(); | 787 : DefaultQuicConfig(); |
| 775 *client_connection = new PacketSavingConnection( | 788 *client_connection = new PacketSavingConnection( |
| 776 helper, Perspective::IS_CLIENT, supported_versions); | 789 helper, alarm_factory, Perspective::IS_CLIENT, supported_versions); |
| 777 *client_session = new TestQuicSpdyClientSession( | 790 *client_session = new TestQuicSpdyClientSession( |
| 778 *client_connection, config, server_id, crypto_client_config); | 791 *client_connection, config, server_id, crypto_client_config); |
| 779 (*client_connection)->AdvanceTime(connection_start_time); | 792 (*client_connection)->AdvanceTime(connection_start_time); |
| 780 } | 793 } |
| 781 | 794 |
| 782 void CreateServerSessionForTest( | 795 void CreateServerSessionForTest( |
| 783 QuicServerId server_id, | 796 QuicServerId server_id, |
| 784 QuicTime::Delta connection_start_time, | 797 QuicTime::Delta connection_start_time, |
| 785 QuicVersionVector supported_versions, | 798 QuicVersionVector supported_versions, |
| 786 MockConnectionHelper* helper, | 799 MockConnectionHelper* helper, |
| 800 MockAlarmFactory* alarm_factory, |
| 787 QuicCryptoServerConfig* server_crypto_config, | 801 QuicCryptoServerConfig* server_crypto_config, |
| 788 QuicCompressedCertsCache* compressed_certs_cache, | 802 QuicCompressedCertsCache* compressed_certs_cache, |
| 789 PacketSavingConnection** server_connection, | 803 PacketSavingConnection** server_connection, |
| 790 TestQuicSpdyServerSession** server_session) { | 804 TestQuicSpdyServerSession** server_session) { |
| 791 CHECK(server_crypto_config); | 805 CHECK(server_crypto_config); |
| 792 CHECK(server_connection); | 806 CHECK(server_connection); |
| 793 CHECK(server_session); | 807 CHECK(server_session); |
| 794 CHECK(!connection_start_time.IsZero()) | 808 CHECK(!connection_start_time.IsZero()) |
| 795 << "Connections must start at non-zero times, otherwise the " | 809 << "Connections must start at non-zero times, otherwise the " |
| 796 << "strike-register will be unhappy."; | 810 << "strike-register will be unhappy."; |
| 797 | 811 |
| 798 *server_connection = new PacketSavingConnection( | 812 *server_connection = new PacketSavingConnection( |
| 799 helper, Perspective::IS_SERVER, supported_versions); | 813 helper, alarm_factory, Perspective::IS_SERVER, supported_versions); |
| 800 *server_session = new TestQuicSpdyServerSession( | 814 *server_session = new TestQuicSpdyServerSession( |
| 801 *server_connection, DefaultQuicConfig(), server_crypto_config, | 815 *server_connection, DefaultQuicConfig(), server_crypto_config, |
| 802 compressed_certs_cache); | 816 compressed_certs_cache); |
| 803 | 817 |
| 804 // We advance the clock initially because the default time is zero and the | 818 // We advance the clock initially because the default time is zero and the |
| 805 // strike register worries that we've just overflowed a uint32_t time. | 819 // strike register worries that we've just overflowed a uint32_t time. |
| 806 (*server_connection)->AdvanceTime(connection_start_time); | 820 (*server_connection)->AdvanceTime(connection_start_time); |
| 807 } | 821 } |
| 808 | 822 |
| 809 QuicStreamId QuicClientDataStreamId(int i) { | 823 QuicStreamId QuicClientDataStreamId(int i) { |
| 810 return kClientDataStreamId1 + 2 * i; | 824 return kClientDataStreamId1 + 2 * i; |
| 811 } | 825 } |
| 812 | 826 |
| 813 } // namespace test | 827 } // namespace test |
| 814 } // namespace net | 828 } // namespace net |
| OLD | NEW |