| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) { | 198 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) { |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool NoOpFramerVisitor::OnPathCloseFrame(const QuicPathCloseFrame& frame) { | 202 bool NoOpFramerVisitor::OnPathCloseFrame(const QuicPathCloseFrame& frame) { |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 MockConnectionVisitor::MockConnectionVisitor() {} | 206 MockQuicConnectionVisitor::MockQuicConnectionVisitor() {} |
| 207 | 207 |
| 208 MockConnectionVisitor::~MockConnectionVisitor() {} | 208 MockQuicConnectionVisitor::~MockQuicConnectionVisitor() {} |
| 209 | 209 |
| 210 MockConnectionHelper::MockConnectionHelper() {} | 210 MockQuicConnectionHelper::MockQuicConnectionHelper() {} |
| 211 | 211 |
| 212 MockConnectionHelper::~MockConnectionHelper() {} | 212 MockQuicConnectionHelper::~MockQuicConnectionHelper() {} |
| 213 | 213 |
| 214 const QuicClock* MockConnectionHelper::GetClock() const { | 214 const QuicClock* MockQuicConnectionHelper::GetClock() const { |
| 215 return &clock_; | 215 return &clock_; |
| 216 } | 216 } |
| 217 | 217 |
| 218 QuicRandom* MockConnectionHelper::GetRandomGenerator() { | 218 QuicRandom* MockQuicConnectionHelper::GetRandomGenerator() { |
| 219 return &random_generator_; | 219 return &random_generator_; |
| 220 } | 220 } |
| 221 | 221 |
| 222 QuicAlarm* MockAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) { | 222 QuicAlarm* MockAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) { |
| 223 return new MockAlarmFactory::TestAlarm( | 223 return new MockAlarmFactory::TestAlarm( |
| 224 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); | 224 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 QuicArenaScopedPtr<QuicAlarm> MockAlarmFactory::CreateAlarm( | 227 QuicArenaScopedPtr<QuicAlarm> MockAlarmFactory::CreateAlarm( |
| 228 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, | 228 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 229 QuicConnectionArena* arena) { | 229 QuicConnectionArena* arena) { |
| 230 if (arena != nullptr) { | 230 if (arena != nullptr) { |
| 231 return arena->New<MockAlarmFactory::TestAlarm>(std::move(delegate)); | 231 return arena->New<MockAlarmFactory::TestAlarm>(std::move(delegate)); |
| 232 } else { | 232 } else { |
| 233 return QuicArenaScopedPtr<MockAlarmFactory::TestAlarm>( | 233 return QuicArenaScopedPtr<MockAlarmFactory::TestAlarm>( |
| 234 new TestAlarm(std::move(delegate))); | 234 new TestAlarm(std::move(delegate))); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 QuicBufferAllocator* MockConnectionHelper::GetBufferAllocator() { | 238 QuicBufferAllocator* MockQuicConnectionHelper::GetBufferAllocator() { |
| 239 return &buffer_allocator_; | 239 return &buffer_allocator_; |
| 240 } | 240 } |
| 241 | 241 |
| 242 void MockConnectionHelper::AdvanceTime(QuicTime::Delta delta) { | 242 void MockQuicConnectionHelper::AdvanceTime(QuicTime::Delta delta) { |
| 243 clock_.AdvanceTime(delta); | 243 clock_.AdvanceTime(delta); |
| 244 } | 244 } |
| 245 | 245 |
| 246 MockConnection::MockConnection(MockConnectionHelper* helper, | 246 MockQuicConnection::MockQuicConnection(MockQuicConnectionHelper* helper, |
| 247 MockAlarmFactory* alarm_factory, | 247 MockAlarmFactory* alarm_factory, |
| 248 Perspective perspective) | 248 Perspective perspective) |
| 249 : MockConnection(kTestConnectionId, | 249 : MockQuicConnection(kTestConnectionId, |
| 250 IPEndPoint(TestPeerIPAddress(), kTestPort), | 250 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 251 helper, | 251 helper, |
| 252 alarm_factory, | 252 alarm_factory, |
| 253 perspective, | 253 perspective, |
| 254 QuicSupportedVersions()) {} | 254 QuicSupportedVersions()) {} |
| 255 | 255 |
| 256 MockConnection::MockConnection(IPEndPoint address, | 256 MockQuicConnection::MockQuicConnection(IPEndPoint address, |
| 257 MockConnectionHelper* helper, | 257 MockQuicConnectionHelper* helper, |
| 258 MockAlarmFactory* alarm_factory, | 258 MockAlarmFactory* alarm_factory, |
| 259 Perspective perspective) | 259 Perspective perspective) |
| 260 : MockConnection(kTestConnectionId, | 260 : MockQuicConnection(kTestConnectionId, |
| 261 address, | 261 address, |
| 262 helper, | 262 helper, |
| 263 alarm_factory, | 263 alarm_factory, |
| 264 perspective, | 264 perspective, |
| 265 QuicSupportedVersions()) {} | 265 QuicSupportedVersions()) {} |
| 266 | 266 |
| 267 MockConnection::MockConnection(QuicConnectionId connection_id, | 267 MockQuicConnection::MockQuicConnection(QuicConnectionId connection_id, |
| 268 MockConnectionHelper* helper, | 268 MockQuicConnectionHelper* helper, |
| 269 MockAlarmFactory* alarm_factory, | 269 MockAlarmFactory* alarm_factory, |
| 270 Perspective perspective) | 270 Perspective perspective) |
| 271 : MockConnection(connection_id, | 271 : MockQuicConnection(connection_id, |
| 272 IPEndPoint(TestPeerIPAddress(), kTestPort), | 272 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 273 helper, | 273 helper, |
| 274 alarm_factory, | 274 alarm_factory, |
| 275 perspective, | 275 perspective, |
| 276 QuicSupportedVersions()) {} | 276 QuicSupportedVersions()) {} |
| 277 | 277 |
| 278 MockConnection::MockConnection(MockConnectionHelper* helper, | 278 MockQuicConnection::MockQuicConnection( |
| 279 MockAlarmFactory* alarm_factory, | 279 MockQuicConnectionHelper* helper, |
| 280 Perspective perspective, | 280 MockAlarmFactory* alarm_factory, |
| 281 const QuicVersionVector& supported_versions) | 281 Perspective perspective, |
| 282 : MockConnection(kTestConnectionId, | 282 const QuicVersionVector& supported_versions) |
| 283 IPEndPoint(TestPeerIPAddress(), kTestPort), | 283 : MockQuicConnection(kTestConnectionId, |
| 284 helper, | 284 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 285 alarm_factory, | 285 helper, |
| 286 perspective, | 286 alarm_factory, |
| 287 supported_versions) {} | 287 perspective, |
| 288 supported_versions) {} |
| 288 | 289 |
| 289 MockConnection::MockConnection(QuicConnectionId connection_id, | 290 MockQuicConnection::MockQuicConnection( |
| 290 IPEndPoint address, | 291 QuicConnectionId connection_id, |
| 291 MockConnectionHelper* helper, | 292 IPEndPoint address, |
| 292 MockAlarmFactory* alarm_factory, | 293 MockQuicConnectionHelper* helper, |
| 293 Perspective perspective, | 294 MockAlarmFactory* alarm_factory, |
| 294 const QuicVersionVector& supported_versions) | 295 Perspective perspective, |
| 296 const QuicVersionVector& supported_versions) |
| 295 : QuicConnection(connection_id, | 297 : QuicConnection(connection_id, |
| 296 address, | 298 address, |
| 297 helper, | 299 helper, |
| 298 alarm_factory, | 300 alarm_factory, |
| 299 new testing::NiceMock<MockPacketWriter>(), | 301 new testing::NiceMock<MockPacketWriter>(), |
| 300 /* owns_writer= */ true, | 302 /* owns_writer= */ true, |
| 301 perspective, | 303 perspective, |
| 302 supported_versions) { | 304 supported_versions) { |
| 303 ON_CALL(*this, OnError(_)) | 305 ON_CALL(*this, OnError(_)) |
| 304 .WillByDefault( | 306 .WillByDefault( |
| 305 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); | 307 Invoke(this, &PacketSavingConnection::QuicConnection_OnError)); |
| 306 } | 308 } |
| 307 | 309 |
| 308 MockConnection::~MockConnection() {} | 310 MockQuicConnection::~MockQuicConnection() {} |
| 309 | 311 |
| 310 void MockConnection::AdvanceTime(QuicTime::Delta delta) { | 312 void MockQuicConnection::AdvanceTime(QuicTime::Delta delta) { |
| 311 static_cast<MockConnectionHelper*>(helper())->AdvanceTime(delta); | 313 static_cast<MockQuicConnectionHelper*>(helper())->AdvanceTime(delta); |
| 312 } | 314 } |
| 313 | 315 |
| 314 PacketSavingConnection::PacketSavingConnection(MockConnectionHelper* helper, | 316 PacketSavingConnection::PacketSavingConnection(MockQuicConnectionHelper* helper, |
| 315 MockAlarmFactory* alarm_factory, | 317 MockAlarmFactory* alarm_factory, |
| 316 Perspective perspective) | 318 Perspective perspective) |
| 317 : MockConnection(helper, alarm_factory, perspective) {} | 319 : MockQuicConnection(helper, alarm_factory, perspective) {} |
| 318 | 320 |
| 319 PacketSavingConnection::PacketSavingConnection( | 321 PacketSavingConnection::PacketSavingConnection( |
| 320 MockConnectionHelper* helper, | 322 MockQuicConnectionHelper* helper, |
| 321 MockAlarmFactory* alarm_factory, | 323 MockAlarmFactory* alarm_factory, |
| 322 Perspective perspective, | 324 Perspective perspective, |
| 323 const QuicVersionVector& supported_versions) | 325 const QuicVersionVector& supported_versions) |
| 324 : MockConnection(helper, alarm_factory, perspective, supported_versions) {} | 326 : MockQuicConnection(helper, |
| 327 alarm_factory, |
| 328 perspective, |
| 329 supported_versions) {} |
| 325 | 330 |
| 326 PacketSavingConnection::~PacketSavingConnection() { | 331 PacketSavingConnection::~PacketSavingConnection() { |
| 327 STLDeleteElements(&encrypted_packets_); | 332 STLDeleteElements(&encrypted_packets_); |
| 328 } | 333 } |
| 329 | 334 |
| 330 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { | 335 void PacketSavingConnection::SendOrQueuePacket(SerializedPacket* packet) { |
| 331 encrypted_packets_.push_back(new QuicEncryptedPacket( | 336 encrypted_packets_.push_back(new QuicEncryptedPacket( |
| 332 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); | 337 QuicUtils::CopyBuffer(*packet), packet->encrypted_length, true)); |
| 333 // Transfer ownership of the packet to the SentPacketManager and the | 338 // Transfer ownership of the packet to the SentPacketManager and the |
| 334 // ack notifier to the AckNotifierManager. | 339 // ack notifier to the AckNotifierManager. |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 827 |
| 823 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) | 828 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) |
| 824 : QuicReceivedPacketManager(stats) {} | 829 : QuicReceivedPacketManager(stats) {} |
| 825 | 830 |
| 826 MockReceivedPacketManager::~MockReceivedPacketManager() {} | 831 MockReceivedPacketManager::~MockReceivedPacketManager() {} |
| 827 | 832 |
| 828 void CreateClientSessionForTest(QuicServerId server_id, | 833 void CreateClientSessionForTest(QuicServerId server_id, |
| 829 bool supports_stateless_rejects, | 834 bool supports_stateless_rejects, |
| 830 QuicTime::Delta connection_start_time, | 835 QuicTime::Delta connection_start_time, |
| 831 QuicVersionVector supported_versions, | 836 QuicVersionVector supported_versions, |
| 832 MockConnectionHelper* helper, | 837 MockQuicConnectionHelper* helper, |
| 833 MockAlarmFactory* alarm_factory, | 838 MockAlarmFactory* alarm_factory, |
| 834 QuicCryptoClientConfig* crypto_client_config, | 839 QuicCryptoClientConfig* crypto_client_config, |
| 835 PacketSavingConnection** client_connection, | 840 PacketSavingConnection** client_connection, |
| 836 TestQuicSpdyClientSession** client_session) { | 841 TestQuicSpdyClientSession** client_session) { |
| 837 CHECK(crypto_client_config); | 842 CHECK(crypto_client_config); |
| 838 CHECK(client_connection); | 843 CHECK(client_connection); |
| 839 CHECK(client_session); | 844 CHECK(client_session); |
| 840 CHECK(!connection_start_time.IsZero()) | 845 CHECK(!connection_start_time.IsZero()) |
| 841 << "Connections must start at non-zero times, otherwise the " | 846 << "Connections must start at non-zero times, otherwise the " |
| 842 << "strike-register will be unhappy."; | 847 << "strike-register will be unhappy."; |
| 843 | 848 |
| 844 QuicConfig config = supports_stateless_rejects | 849 QuicConfig config = supports_stateless_rejects |
| 845 ? DefaultQuicConfigStatelessRejects() | 850 ? DefaultQuicConfigStatelessRejects() |
| 846 : DefaultQuicConfig(); | 851 : DefaultQuicConfig(); |
| 847 *client_connection = new PacketSavingConnection( | 852 *client_connection = new PacketSavingConnection( |
| 848 helper, alarm_factory, Perspective::IS_CLIENT, supported_versions); | 853 helper, alarm_factory, Perspective::IS_CLIENT, supported_versions); |
| 849 *client_session = new TestQuicSpdyClientSession( | 854 *client_session = new TestQuicSpdyClientSession( |
| 850 *client_connection, config, server_id, crypto_client_config); | 855 *client_connection, config, server_id, crypto_client_config); |
| 851 (*client_connection)->AdvanceTime(connection_start_time); | 856 (*client_connection)->AdvanceTime(connection_start_time); |
| 852 } | 857 } |
| 853 | 858 |
| 854 void CreateServerSessionForTest( | 859 void CreateServerSessionForTest( |
| 855 QuicServerId server_id, | 860 QuicServerId server_id, |
| 856 QuicTime::Delta connection_start_time, | 861 QuicTime::Delta connection_start_time, |
| 857 QuicVersionVector supported_versions, | 862 QuicVersionVector supported_versions, |
| 858 MockConnectionHelper* helper, | 863 MockQuicConnectionHelper* helper, |
| 859 MockAlarmFactory* alarm_factory, | 864 MockAlarmFactory* alarm_factory, |
| 860 QuicCryptoServerConfig* server_crypto_config, | 865 QuicCryptoServerConfig* server_crypto_config, |
| 861 QuicCompressedCertsCache* compressed_certs_cache, | 866 QuicCompressedCertsCache* compressed_certs_cache, |
| 862 PacketSavingConnection** server_connection, | 867 PacketSavingConnection** server_connection, |
| 863 TestQuicSpdyServerSession** server_session) { | 868 TestQuicSpdyServerSession** server_session) { |
| 864 CHECK(server_crypto_config); | 869 CHECK(server_crypto_config); |
| 865 CHECK(server_connection); | 870 CHECK(server_connection); |
| 866 CHECK(server_session); | 871 CHECK(server_session); |
| 867 CHECK(!connection_start_time.IsZero()) | 872 CHECK(!connection_start_time.IsZero()) |
| 868 << "Connections must start at non-zero times, otherwise the " | 873 << "Connections must start at non-zero times, otherwise the " |
| 869 << "strike-register will be unhappy."; | 874 << "strike-register will be unhappy."; |
| 870 | 875 |
| 871 *server_connection = new PacketSavingConnection( | 876 *server_connection = new PacketSavingConnection( |
| 872 helper, alarm_factory, Perspective::IS_SERVER, supported_versions); | 877 helper, alarm_factory, Perspective::IS_SERVER, supported_versions); |
| 873 *server_session = new TestQuicSpdyServerSession( | 878 *server_session = new TestQuicSpdyServerSession( |
| 874 *server_connection, DefaultQuicConfig(), server_crypto_config, | 879 *server_connection, DefaultQuicConfig(), server_crypto_config, |
| 875 compressed_certs_cache); | 880 compressed_certs_cache); |
| 876 | 881 |
| 877 // We advance the clock initially because the default time is zero and the | 882 // We advance the clock initially because the default time is zero and the |
| 878 // strike register worries that we've just overflowed a uint32_t time. | 883 // strike register worries that we've just overflowed a uint32_t time. |
| 879 (*server_connection)->AdvanceTime(connection_start_time); | 884 (*server_connection)->AdvanceTime(connection_start_time); |
| 880 } | 885 } |
| 881 | 886 |
| 882 QuicStreamId QuicClientDataStreamId(int i) { | 887 QuicStreamId QuicClientDataStreamId(int i) { |
| 883 return kClientDataStreamId1 + 2 * i; | 888 return kClientDataStreamId1 + 2 * i; |
| 884 } | 889 } |
| 885 | 890 |
| 886 } // namespace test | 891 } // namespace test |
| 887 } // namespace net | 892 } // namespace net |
| OLD | NEW |