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 <cstdint> | 10 #include <cstdint> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/quic/core/quic_connection_close_delegate_interface.h" | 21 #include "net/quic/core/quic_connection_close_delegate_interface.h" |
22 #include "net/quic/core/quic_framer.h" | 22 #include "net/quic/core/quic_framer.h" |
23 #include "net/quic/core/quic_iovector.h" | 23 #include "net/quic/core/quic_iovector.h" |
24 #include "net/quic/core/quic_sent_packet_manager.h" | 24 #include "net/quic/core/quic_sent_packet_manager.h" |
25 #include "net/quic/core/quic_server_session_base.h" | 25 #include "net/quic/core/quic_server_session_base.h" |
26 #include "net/quic/core/quic_simple_buffer_allocator.h" | 26 #include "net/quic/core/quic_simple_buffer_allocator.h" |
27 #include "net/quic/platform/api/quic_ptr_util.h" | 27 #include "net/quic/platform/api/quic_ptr_util.h" |
28 #include "net/quic/platform/api/quic_string_piece.h" | 28 #include "net/quic/platform/api/quic_string_piece.h" |
29 #include "net/quic/test_tools/mock_clock.h" | 29 #include "net/quic/test_tools/mock_clock.h" |
30 #include "net/quic/test_tools/mock_random.h" | 30 #include "net/quic/test_tools/mock_random.h" |
| 31 #include "net/quic/test_tools/simple_data_producer.h" |
31 #include "net/test/gtest_util.h" | 32 #include "net/test/gtest_util.h" |
32 #include "net/tools/quic/quic_per_connection_packet_writer.h" | 33 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
33 #include "net/tools/quic/test_tools/mock_quic_session_visitor.h" | 34 #include "net/tools/quic/test_tools/mock_quic_session_visitor.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
35 | 36 |
36 // EXPECT_QUIC_BUG is like EXPECT_DFATAL, except it ensures that no DFATAL | 37 // EXPECT_QUIC_BUG is like EXPECT_DFATAL, except it ensures that no DFATAL |
37 // logging is skipped due to exponential backoff. | 38 // logging is skipped due to exponential backoff. |
38 // | 39 // |
39 // For external QUIC, EXPECT_QUIC_BUG should be #defined to EXPECT_DFATAL. | 40 // For external QUIC, EXPECT_QUIC_BUG should be #defined to EXPECT_DFATAL. |
40 #define EXPECT_QUIC_BUG EXPECT_DFATAL | 41 #define EXPECT_QUIC_BUG EXPECT_DFATAL |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 MOCK_METHOD1(OnConnectionMigration, void(PeerAddressChangeType type)); | 289 MOCK_METHOD1(OnConnectionMigration, void(PeerAddressChangeType type)); |
289 MOCK_METHOD0(OnPathDegrading, void()); | 290 MOCK_METHOD0(OnPathDegrading, void()); |
290 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); | 291 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); |
291 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); | 292 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); |
292 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); | 293 MOCK_CONST_METHOD0(HasOpenDynamicStreams, bool()); |
293 MOCK_METHOD1(OnSuccessfulVersionNegotiation, | 294 MOCK_METHOD1(OnSuccessfulVersionNegotiation, |
294 void(const QuicVersion& version)); | 295 void(const QuicVersion& version)); |
295 MOCK_METHOD0(OnConfigNegotiated, void()); | 296 MOCK_METHOD0(OnConfigNegotiated, void()); |
296 MOCK_METHOD0(PostProcessAfterData, void()); | 297 MOCK_METHOD0(PostProcessAfterData, void()); |
297 MOCK_METHOD0(OnAckNeedsRetransmittableFrame, void()); | 298 MOCK_METHOD0(OnAckNeedsRetransmittableFrame, void()); |
| 299 void SaveStreamData(QuicStreamId id, |
| 300 QuicIOVector iov, |
| 301 size_t iov_offset, |
| 302 QuicStreamOffset offset, |
| 303 QuicByteCount data_length) override; |
| 304 bool WriteStreamData(QuicStreamId id, |
| 305 QuicStreamOffset offset, |
| 306 QuicByteCount data_length, |
| 307 QuicDataWriter* writer) override; |
298 | 308 |
299 private: | 309 private: |
| 310 SimpleDataProducer producer_; |
| 311 |
300 DISALLOW_COPY_AND_ASSIGN(MockQuicConnectionVisitor); | 312 DISALLOW_COPY_AND_ASSIGN(MockQuicConnectionVisitor); |
301 }; | 313 }; |
302 | 314 |
303 class MockQuicConnectionHelper : public QuicConnectionHelperInterface { | 315 class MockQuicConnectionHelper : public QuicConnectionHelperInterface { |
304 public: | 316 public: |
305 MockQuicConnectionHelper(); | 317 MockQuicConnectionHelper(); |
306 ~MockQuicConnectionHelper() override; | 318 ~MockQuicConnectionHelper() override; |
307 const QuicClock* GetClock() const override; | 319 const QuicClock* GetClock() const override; |
308 QuicRandom* GetRandomGenerator() override; | 320 QuicRandom* GetRandomGenerator() override; |
309 QuicBufferAllocator* GetBufferAllocator() override; | 321 QuicBufferAllocator* GetBufferAllocator() override; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // has been consumed. | 516 // has been consumed. |
505 static QuicConsumedData ConsumeAllData( | 517 static QuicConsumedData ConsumeAllData( |
506 QuicStream* stream, | 518 QuicStream* stream, |
507 QuicStreamId id, | 519 QuicStreamId id, |
508 const QuicIOVector& data, | 520 const QuicIOVector& data, |
509 QuicStreamOffset offset, | 521 QuicStreamOffset offset, |
510 StreamSendingState state, | 522 StreamSendingState state, |
511 const QuicReferenceCountedPointer<QuicAckListenerInterface>& | 523 const QuicReferenceCountedPointer<QuicAckListenerInterface>& |
512 ack_listener); | 524 ack_listener); |
513 | 525 |
| 526 QuicConsumedData ConsumeAndSaveAllData( |
| 527 QuicStream* stream, |
| 528 QuicStreamId id, |
| 529 const QuicIOVector& data, |
| 530 QuicStreamOffset offset, |
| 531 StreamSendingState state, |
| 532 const QuicReferenceCountedPointer<QuicAckListenerInterface>& |
| 533 ack_listener); |
| 534 |
514 private: | 535 private: |
515 std::unique_ptr<QuicCryptoStream> crypto_stream_; | 536 std::unique_ptr<QuicCryptoStream> crypto_stream_; |
516 | 537 |
517 DISALLOW_COPY_AND_ASSIGN(MockQuicSession); | 538 DISALLOW_COPY_AND_ASSIGN(MockQuicSession); |
518 }; | 539 }; |
519 | 540 |
520 class MockQuicSpdySession : public QuicSpdySession { | 541 class MockQuicSpdySession : public QuicSpdySession { |
521 public: | 542 public: |
522 // Takes ownership of |connection|. | 543 // Takes ownership of |connection|. |
523 explicit MockQuicSpdySession(QuicConnection* connection); | 544 explicit MockQuicSpdySession(QuicConnection* connection); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 629 |
609 QuicSpdyStream* QuicSpdySessionMaybeCreateOutgoingDynamicStream( | 630 QuicSpdyStream* QuicSpdySessionMaybeCreateOutgoingDynamicStream( |
610 SpdyPriority priority) { | 631 SpdyPriority priority) { |
611 return QuicSpdySession::MaybeCreateOutgoingDynamicStream(priority); | 632 return QuicSpdySession::MaybeCreateOutgoingDynamicStream(priority); |
612 } | 633 } |
613 | 634 |
614 bool QuicSpdySessionShouldCreateOutgoingDynamicStream2() { | 635 bool QuicSpdySessionShouldCreateOutgoingDynamicStream2() { |
615 return QuicSpdySession::ShouldCreateOutgoingDynamicStream2(); | 636 return QuicSpdySession::ShouldCreateOutgoingDynamicStream2(); |
616 } | 637 } |
617 | 638 |
| 639 QuicConsumedData ConsumeAndSaveAllData( |
| 640 QuicStream* stream, |
| 641 QuicStreamId id, |
| 642 const QuicIOVector& data, |
| 643 QuicStreamOffset offset, |
| 644 StreamSendingState state, |
| 645 const QuicReferenceCountedPointer<QuicAckListenerInterface>& |
| 646 ack_listener); |
| 647 |
618 using QuicSession::ActivateStream; | 648 using QuicSession::ActivateStream; |
619 | 649 |
620 private: | 650 private: |
621 std::unique_ptr<QuicCryptoStream> crypto_stream_; | 651 std::unique_ptr<QuicCryptoStream> crypto_stream_; |
622 SpdyHeaderBlock write_headers_; | 652 SpdyHeaderBlock write_headers_; |
623 | 653 |
624 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); | 654 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); |
625 }; | 655 }; |
626 | 656 |
627 class TestQuicSpdyServerSession : public QuicServerSessionBase { | 657 class TestQuicSpdyServerSession : public QuicServerSessionBase { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 public: | 925 public: |
896 MockConnectionCloseDelegate(); | 926 MockConnectionCloseDelegate(); |
897 ~MockConnectionCloseDelegate() override; | 927 ~MockConnectionCloseDelegate() override; |
898 | 928 |
899 MOCK_METHOD3(OnUnrecoverableError, | 929 MOCK_METHOD3(OnUnrecoverableError, |
900 void(QuicErrorCode, | 930 void(QuicErrorCode, |
901 const std::string&, | 931 const std::string&, |
902 ConnectionCloseSource source)); | 932 ConnectionCloseSource source)); |
903 }; | 933 }; |
904 | 934 |
| 935 class MockPacketCreatorDelegate : public QuicPacketCreator::DelegateInterface { |
| 936 public: |
| 937 MockPacketCreatorDelegate(); |
| 938 ~MockPacketCreatorDelegate() override; |
| 939 |
| 940 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); |
| 941 MOCK_METHOD3(OnUnrecoverableError, |
| 942 void(QuicErrorCode, |
| 943 const std::string&, |
| 944 ConnectionCloseSource source)); |
| 945 |
| 946 void SaveStreamData(QuicStreamId id, |
| 947 QuicIOVector iov, |
| 948 size_t iov_offset, |
| 949 QuicStreamOffset offset, |
| 950 QuicByteCount data_length) override; |
| 951 bool WriteStreamData(QuicStreamId id, |
| 952 QuicStreamOffset offset, |
| 953 QuicByteCount data_length, |
| 954 QuicDataWriter* writer) override; |
| 955 |
| 956 private: |
| 957 SimpleDataProducer producer_; |
| 958 |
| 959 DISALLOW_COPY_AND_ASSIGN(MockPacketCreatorDelegate); |
| 960 }; |
| 961 |
905 // Creates a client session for testing. | 962 // Creates a client session for testing. |
906 // | 963 // |
907 // server_id: The server id associated with this stream. | 964 // server_id: The server id associated with this stream. |
908 // supports_stateless_rejects: Does this client support stateless rejects. | 965 // supports_stateless_rejects: Does this client support stateless rejects. |
909 // connection_start_time: The time to set for the connection clock. | 966 // connection_start_time: The time to set for the connection clock. |
910 // Needed for strike-register nonce verification. The client | 967 // Needed for strike-register nonce verification. The client |
911 // connection_start_time should be synchronized witht the server | 968 // connection_start_time should be synchronized witht the server |
912 // start time, otherwise nonce verification will fail. | 969 // start time, otherwise nonce verification will fail. |
913 // supported_versions: Set of QUIC versions this client supports. | 970 // supported_versions: Set of QUIC versions this client supports. |
914 // helper: Pointer to the MockQuicConnectionHelper to use for the session. | 971 // helper: Pointer to the MockQuicConnectionHelper to use for the session. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 // Utilities that will adapt stream ids when http stream pairs are | 1052 // Utilities that will adapt stream ids when http stream pairs are |
996 // enabled. | 1053 // enabled. |
997 QuicStreamId NextStreamId(QuicVersion version); | 1054 QuicStreamId NextStreamId(QuicVersion version); |
998 QuicStreamId GetNthClientInitiatedStreamId(QuicVersion version, int n); | 1055 QuicStreamId GetNthClientInitiatedStreamId(QuicVersion version, int n); |
999 QuicStreamId GetNthServerInitiatedStreamId(QuicVersion version, int n); | 1056 QuicStreamId GetNthServerInitiatedStreamId(QuicVersion version, int n); |
1000 | 1057 |
1001 } // namespace test | 1058 } // namespace test |
1002 } // namespace net | 1059 } // namespace net |
1003 | 1060 |
1004 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 1061 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |