| 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 // Common utilities for Quic tests | 5 // Common utilities for Quic tests |
| 6 | 6 |
| 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <cstdint> |
| 14 #include <memory> |
| 13 #include <string> | 15 #include <string> |
| 14 #include <vector> | 16 #include <vector> |
| 15 | 17 |
| 16 #include "base/macros.h" | 18 #include "base/macros.h" |
| 17 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 18 #include "net/base/ip_address.h" | 20 #include "net/base/ip_address.h" |
| 19 #include "net/quic/congestion_control/loss_detection_interface.h" | 21 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 20 #include "net/quic/congestion_control/send_algorithm_interface.h" | 22 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 21 #include "net/quic/quic_client_push_promise_index.h" | 23 #include "net/quic/quic_client_push_promise_index.h" |
| 22 #include "net/quic/quic_connection.h" | 24 #include "net/quic/quic_connection.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 private: | 313 private: |
| 312 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | 314 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); |
| 313 }; | 315 }; |
| 314 | 316 |
| 315 class MockConnectionHelper : public QuicConnectionHelperInterface { | 317 class MockConnectionHelper : public QuicConnectionHelperInterface { |
| 316 public: | 318 public: |
| 317 MockConnectionHelper(); | 319 MockConnectionHelper(); |
| 318 ~MockConnectionHelper() override; | 320 ~MockConnectionHelper() override; |
| 319 const QuicClock* GetClock() const override; | 321 const QuicClock* GetClock() const override; |
| 320 QuicRandom* GetRandomGenerator() override; | 322 QuicRandom* GetRandomGenerator() override; |
| 323 QuicBufferAllocator* GetBufferAllocator() override; |
| 324 void AdvanceTime(QuicTime::Delta delta); |
| 325 |
| 326 private: |
| 327 MockClock clock_; |
| 328 MockRandom random_generator_; |
| 329 SimpleBufferAllocator buffer_allocator_; |
| 330 |
| 331 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); |
| 332 }; |
| 333 |
| 334 class MockAlarmFactory : public QuicAlarmFactory { |
| 335 public: |
| 321 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; | 336 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
| 322 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( | 337 QuicArenaScopedPtr<QuicAlarm> CreateAlarm( |
| 323 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, | 338 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 324 QuicConnectionArena* arena) override; | 339 QuicConnectionArena* arena) override; |
| 325 QuicBufferAllocator* GetBufferAllocator() override; | |
| 326 void AdvanceTime(QuicTime::Delta delta); | |
| 327 | 340 |
| 328 // No-op alarm implementation | 341 // No-op alarm implementation |
| 329 class TestAlarm : public QuicAlarm { | 342 class TestAlarm : public QuicAlarm { |
| 330 public: | 343 public: |
| 331 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) | 344 explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) |
| 332 : QuicAlarm(std::move(delegate)) {} | 345 : QuicAlarm(std::move(delegate)) {} |
| 333 | 346 |
| 334 void SetImpl() override {} | 347 void SetImpl() override {} |
| 335 void CancelImpl() override {} | 348 void CancelImpl() override {} |
| 336 | 349 |
| 337 using QuicAlarm::Fire; | 350 using QuicAlarm::Fire; |
| 338 }; | 351 }; |
| 339 | 352 |
| 340 void FireAlarm(QuicAlarm* alarm) { | 353 void FireAlarm(QuicAlarm* alarm) { |
| 341 reinterpret_cast<TestAlarm*>(alarm)->Fire(); | 354 reinterpret_cast<TestAlarm*>(alarm)->Fire(); |
| 342 } | 355 } |
| 343 | |
| 344 private: | |
| 345 MockClock clock_; | |
| 346 MockRandom random_generator_; | |
| 347 SimpleBufferAllocator buffer_allocator_; | |
| 348 | |
| 349 DISALLOW_COPY_AND_ASSIGN(MockConnectionHelper); | |
| 350 }; | 356 }; |
| 351 | 357 |
| 352 class MockConnection : public QuicConnection { | 358 class MockConnection : public QuicConnection { |
| 353 public: | 359 public: |
| 354 // Uses a ConnectionId of 42 and 127.0.0.1:123. | 360 // Uses a ConnectionId of 42 and 127.0.0.1:123. |
| 355 MockConnection(MockConnectionHelper* helper, Perspective perspective); | 361 MockConnection(MockConnectionHelper* helper, |
| 362 MockAlarmFactory* alarm_factory, |
| 363 Perspective perspective); |
| 356 | 364 |
| 357 // Uses a ConnectionId of 42. | 365 // Uses a ConnectionId of 42. |
| 358 MockConnection(IPEndPoint address, | 366 MockConnection(IPEndPoint address, |
| 359 MockConnectionHelper* helper, | 367 MockConnectionHelper* helper, |
| 368 MockAlarmFactory* alarm_factory, |
| 360 Perspective perspective); | 369 Perspective perspective); |
| 361 | 370 |
| 362 // Uses 127.0.0.1:123. | 371 // Uses 127.0.0.1:123. |
| 363 MockConnection(QuicConnectionId connection_id, | 372 MockConnection(QuicConnectionId connection_id, |
| 364 MockConnectionHelper* helper, | 373 MockConnectionHelper* helper, |
| 374 MockAlarmFactory* alarm_factory, |
| 365 Perspective perspective); | 375 Perspective perspective); |
| 366 | 376 |
| 367 // Uses a ConnectionId of 42, and 127.0.0.1:123. | 377 // Uses a ConnectionId of 42, and 127.0.0.1:123. |
| 368 MockConnection(MockConnectionHelper* helper, | 378 MockConnection(MockConnectionHelper* helper, |
| 379 MockAlarmFactory* alarm_factory, |
| 369 Perspective perspective, | 380 Perspective perspective, |
| 370 const QuicVersionVector& supported_versions); | 381 const QuicVersionVector& supported_versions); |
| 371 | 382 |
| 372 MockConnection(QuicConnectionId connection_id, | 383 MockConnection(QuicConnectionId connection_id, |
| 373 IPEndPoint address, | 384 IPEndPoint address, |
| 374 MockConnectionHelper* helper, | 385 MockConnectionHelper* helper, |
| 386 MockAlarmFactory* alarm_factory, |
| 375 Perspective perspective, | 387 Perspective perspective, |
| 376 const QuicVersionVector& supported_versions); | 388 const QuicVersionVector& supported_versions); |
| 377 | 389 |
| 378 ~MockConnection() override; | 390 ~MockConnection() override; |
| 379 | 391 |
| 380 // If the constructor that uses a MockConnectionHelper has been used then | 392 // If the constructor that uses a MockConnectionHelper has been used then |
| 381 // this method | 393 // this method |
| 382 // will advance the time of the MockClock. | 394 // will advance the time of the MockClock. |
| 383 void AdvanceTime(QuicTime::Delta delta); | 395 void AdvanceTime(QuicTime::Delta delta); |
| 384 | 396 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 const std::string& reason) { | 440 const std::string& reason) { |
| 429 QuicConnection::SendGoAway(error, last_good_stream_id, reason); | 441 QuicConnection::SendGoAway(error, last_good_stream_id, reason); |
| 430 } | 442 } |
| 431 | 443 |
| 432 private: | 444 private: |
| 433 DISALLOW_COPY_AND_ASSIGN(MockConnection); | 445 DISALLOW_COPY_AND_ASSIGN(MockConnection); |
| 434 }; | 446 }; |
| 435 | 447 |
| 436 class PacketSavingConnection : public MockConnection { | 448 class PacketSavingConnection : public MockConnection { |
| 437 public: | 449 public: |
| 438 PacketSavingConnection(MockConnectionHelper* helper, Perspective perspective); | 450 PacketSavingConnection(MockConnectionHelper* helper, |
| 451 MockAlarmFactory* alarm_factory, |
| 452 Perspective perspective); |
| 439 | 453 |
| 440 PacketSavingConnection(MockConnectionHelper* helper, | 454 PacketSavingConnection(MockConnectionHelper* helper, |
| 455 MockAlarmFactory* alarm_factory, |
| 441 Perspective perspective, | 456 Perspective perspective, |
| 442 const QuicVersionVector& supported_versions); | 457 const QuicVersionVector& supported_versions); |
| 443 | 458 |
| 444 ~PacketSavingConnection() override; | 459 ~PacketSavingConnection() override; |
| 445 | 460 |
| 446 void SendOrQueuePacket(SerializedPacket* packet) override; | 461 void SendOrQueuePacket(SerializedPacket* packet) override; |
| 447 | 462 |
| 448 std::vector<QuicEncryptedPacket*> encrypted_packets_; | 463 std::vector<QuicEncryptedPacket*> encrypted_packets_; |
| 449 | 464 |
| 450 private: | 465 private: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 479 void(QuicStreamId stream_id, | 494 void(QuicStreamId stream_id, |
| 480 QuicRstStreamErrorCode error, | 495 QuicRstStreamErrorCode error, |
| 481 QuicStreamOffset bytes_written)); | 496 QuicStreamOffset bytes_written)); |
| 482 | 497 |
| 483 MOCK_METHOD2(OnStreamHeaders, | 498 MOCK_METHOD2(OnStreamHeaders, |
| 484 void(QuicStreamId stream_id, base::StringPiece headers_data)); | 499 void(QuicStreamId stream_id, base::StringPiece headers_data)); |
| 485 MOCK_METHOD2(OnStreamHeadersPriority, | 500 MOCK_METHOD2(OnStreamHeadersPriority, |
| 486 void(QuicStreamId stream_id, SpdyPriority priority)); | 501 void(QuicStreamId stream_id, SpdyPriority priority)); |
| 487 MOCK_METHOD3(OnStreamHeadersComplete, | 502 MOCK_METHOD3(OnStreamHeadersComplete, |
| 488 void(QuicStreamId stream_id, bool fin, size_t frame_len)); | 503 void(QuicStreamId stream_id, bool fin, size_t frame_len)); |
| 504 MOCK_METHOD4(OnStreamHeaderList, |
| 505 void(QuicStreamId stream_id, |
| 506 bool fin, |
| 507 size_t frame_len, |
| 508 const QuicHeaderList& header_list)); |
| 509 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 489 MOCK_METHOD2(OnPromiseHeaders, | 510 MOCK_METHOD2(OnPromiseHeaders, |
| 490 void(QuicStreamId stream_id, StringPiece headers_data)); | 511 void(QuicStreamId stream_id, StringPiece headers_data)); |
| 491 MOCK_METHOD3(OnPromiseHeadersComplete, | 512 MOCK_METHOD3(OnPromiseHeadersComplete, |
| 492 void(QuicStreamId stream_id, | 513 void(QuicStreamId stream_id, |
| 493 QuicStreamId promised_stream_id, | 514 QuicStreamId promised_stream_id, |
| 494 size_t frame_len)); | 515 size_t frame_len)); |
| 495 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); | 516 MOCK_METHOD4(OnPromiseHeaderList, |
| 517 void(QuicStreamId stream_id, |
| 518 QuicStreamId promised_stream_id, |
| 519 size_t frame_len, |
| 520 const QuicHeaderList& header_list)); |
| 496 MOCK_METHOD5(WriteHeaders, | 521 MOCK_METHOD5(WriteHeaders, |
| 497 size_t(QuicStreamId id, | 522 size_t(QuicStreamId id, |
| 498 const SpdyHeaderBlock& headers, | 523 const SpdyHeaderBlock& headers, |
| 499 bool fin, | 524 bool fin, |
| 500 SpdyPriority priority, | 525 SpdyPriority priority, |
| 501 QuicAckListenerInterface* ack_notifier_delegate)); | 526 QuicAckListenerInterface* ack_notifier_delegate)); |
| 502 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); | 527 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); |
| 503 | 528 |
| 504 using QuicSession::ActivateStream; | 529 using QuicSession::ActivateStream; |
| 505 | 530 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 // client_connection: Pointer reference for newly created | 809 // client_connection: Pointer reference for newly created |
| 785 // connection. This object will be owned by the | 810 // connection. This object will be owned by the |
| 786 // client_session. | 811 // client_session. |
| 787 // client_session: Pointer reference for the newly created client | 812 // client_session: Pointer reference for the newly created client |
| 788 // session. The new object will be owned by the caller. | 813 // session. The new object will be owned by the caller. |
| 789 void CreateClientSessionForTest(QuicServerId server_id, | 814 void CreateClientSessionForTest(QuicServerId server_id, |
| 790 bool supports_stateless_rejects, | 815 bool supports_stateless_rejects, |
| 791 QuicTime::Delta connection_start_time, | 816 QuicTime::Delta connection_start_time, |
| 792 QuicVersionVector supported_versions, | 817 QuicVersionVector supported_versions, |
| 793 MockConnectionHelper* helper, | 818 MockConnectionHelper* helper, |
| 819 MockAlarmFactory* alarm_factory, |
| 794 QuicCryptoClientConfig* crypto_client_config, | 820 QuicCryptoClientConfig* crypto_client_config, |
| 795 PacketSavingConnection** client_connection, | 821 PacketSavingConnection** client_connection, |
| 796 TestQuicSpdyClientSession** client_session); | 822 TestQuicSpdyClientSession** client_session); |
| 797 | 823 |
| 798 // Creates a server session for testing. | 824 // Creates a server session for testing. |
| 799 // | 825 // |
| 800 // server_id: The server id associated with this stream. | 826 // server_id: The server id associated with this stream. |
| 801 // connection_start_time: The time to set for the connection clock. | 827 // connection_start_time: The time to set for the connection clock. |
| 802 // Needed for strike-register nonce verification. The server | 828 // Needed for strike-register nonce verification. The server |
| 803 // connection_start_time should be synchronized witht the client | 829 // connection_start_time should be synchronized witht the client |
| 804 // start time, otherwise nonce verification will fail. | 830 // start time, otherwise nonce verification will fail. |
| 805 // supported_versions: Set of QUIC versions this server supports. | 831 // supported_versions: Set of QUIC versions this server supports. |
| 806 // helper: Pointer to the MockConnectionHelper to use for the session. | 832 // helper: Pointer to the MockConnectionHelper to use for the session. |
| 807 // crypto_server_config: Pointer to the crypto server config. | 833 // crypto_server_config: Pointer to the crypto server config. |
| 808 // server_connection: Pointer reference for newly created | 834 // server_connection: Pointer reference for newly created |
| 809 // connection. This object will be owned by the | 835 // connection. This object will be owned by the |
| 810 // server_session. | 836 // server_session. |
| 811 // server_session: Pointer reference for the newly created server | 837 // server_session: Pointer reference for the newly created server |
| 812 // session. The new object will be owned by the caller. | 838 // session. The new object will be owned by the caller. |
| 813 void CreateServerSessionForTest( | 839 void CreateServerSessionForTest( |
| 814 QuicServerId server_id, | 840 QuicServerId server_id, |
| 815 QuicTime::Delta connection_start_time, | 841 QuicTime::Delta connection_start_time, |
| 816 QuicVersionVector supported_versions, | 842 QuicVersionVector supported_versions, |
| 817 MockConnectionHelper* helper, | 843 MockConnectionHelper* helper, |
| 844 MockAlarmFactory* alarm_factory, |
| 818 QuicCryptoServerConfig* crypto_server_config, | 845 QuicCryptoServerConfig* crypto_server_config, |
| 819 QuicCompressedCertsCache* compressed_certs_cache, | 846 QuicCompressedCertsCache* compressed_certs_cache, |
| 820 PacketSavingConnection** server_connection, | 847 PacketSavingConnection** server_connection, |
| 821 TestQuicSpdyServerSession** server_session); | 848 TestQuicSpdyServerSession** server_session); |
| 822 | 849 |
| 823 // Helper to generate client side stream ids, generalizes | 850 // Helper to generate client side stream ids, generalizes |
| 824 // kClientDataStreamId1 etc. above. | 851 // kClientDataStreamId1 etc. above. |
| 825 QuicStreamId QuicClientDataStreamId(int i); | 852 QuicStreamId QuicClientDataStreamId(int i); |
| 826 | 853 |
| 827 } // namespace test | 854 } // namespace test |
| 828 } // namespace net | 855 } // namespace net |
| 829 | 856 |
| 830 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 857 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| OLD | NEW |