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> | 13 #include <cstdint> |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
| 16 #include <utility> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
20 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" |
21 #include "net/quic/congestion_control/loss_detection_interface.h" | 22 #include "net/quic/congestion_control/loss_detection_interface.h" |
22 #include "net/quic/congestion_control/send_algorithm_interface.h" | 23 #include "net/quic/congestion_control/send_algorithm_interface.h" |
23 #include "net/quic/quic_client_push_promise_index.h" | 24 #include "net/quic/quic_client_push_promise_index.h" |
24 #include "net/quic/quic_connection.h" | 25 #include "net/quic/quic_connection.h" |
25 #include "net/quic/quic_framer.h" | 26 #include "net/quic/quic_framer.h" |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 551 |
551 DISALLOW_COPY_AND_ASSIGN(MockQuicSession); | 552 DISALLOW_COPY_AND_ASSIGN(MockQuicSession); |
552 }; | 553 }; |
553 | 554 |
554 class MockQuicSpdySession : public QuicSpdySession { | 555 class MockQuicSpdySession : public QuicSpdySession { |
555 public: | 556 public: |
556 explicit MockQuicSpdySession(QuicConnection* connection); | 557 explicit MockQuicSpdySession(QuicConnection* connection); |
557 ~MockQuicSpdySession() override; | 558 ~MockQuicSpdySession() override; |
558 | 559 |
559 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); } | 560 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); } |
| 561 const SpdyHeaderBlock& GetWriteHeaders() { return write_headers_; } |
560 | 562 |
561 // From QuicSession. | 563 // From QuicSession. |
562 MOCK_METHOD3(OnConnectionClosed, | 564 MOCK_METHOD3(OnConnectionClosed, |
563 void(QuicErrorCode error, | 565 void(QuicErrorCode error, |
564 const std::string& error_details, | 566 const std::string& error_details, |
565 ConnectionCloseSource source)); | 567 ConnectionCloseSource source)); |
566 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); | 568 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); |
567 MOCK_METHOD1(CreateOutgoingDynamicStream, | 569 MOCK_METHOD1(CreateOutgoingDynamicStream, |
568 QuicSpdyStream*(SpdyPriority priority)); | 570 QuicSpdyStream*(SpdyPriority priority)); |
569 MOCK_METHOD1(ShouldCreateIncomingDynamicStream, bool(QuicStreamId id)); | 571 MOCK_METHOD1(ShouldCreateIncomingDynamicStream, bool(QuicStreamId id)); |
(...skipping 27 matching lines...) Expand all Loading... |
597 void(QuicStreamId stream_id, StringPiece headers_data)); | 599 void(QuicStreamId stream_id, StringPiece headers_data)); |
598 MOCK_METHOD3(OnPromiseHeadersComplete, | 600 MOCK_METHOD3(OnPromiseHeadersComplete, |
599 void(QuicStreamId stream_id, | 601 void(QuicStreamId stream_id, |
600 QuicStreamId promised_stream_id, | 602 QuicStreamId promised_stream_id, |
601 size_t frame_len)); | 603 size_t frame_len)); |
602 MOCK_METHOD4(OnPromiseHeaderList, | 604 MOCK_METHOD4(OnPromiseHeaderList, |
603 void(QuicStreamId stream_id, | 605 void(QuicStreamId stream_id, |
604 QuicStreamId promised_stream_id, | 606 QuicStreamId promised_stream_id, |
605 size_t frame_len, | 607 size_t frame_len, |
606 const QuicHeaderList& header_list)); | 608 const QuicHeaderList& header_list)); |
607 MOCK_METHOD5(WriteHeaders, | 609 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be |
| 610 // mocked directly. |
| 611 size_t WriteHeaders( |
| 612 QuicStreamId id, |
| 613 SpdyHeaderBlock headers, |
| 614 bool fin, |
| 615 SpdyPriority priority, |
| 616 QuicAckListenerInterface* ack_notifier_delegate) override { |
| 617 write_headers_ = std::move(headers); |
| 618 return WriteHeadersMock(id, write_headers_, fin, priority, |
| 619 ack_notifier_delegate); |
| 620 } |
| 621 MOCK_METHOD5(WriteHeadersMock, |
608 size_t(QuicStreamId id, | 622 size_t(QuicStreamId id, |
609 SpdyHeaderBlock headers, | 623 const SpdyHeaderBlock& headers, |
610 bool fin, | 624 bool fin, |
611 SpdyPriority priority, | 625 SpdyPriority priority, |
612 QuicAckListenerInterface* ack_notifier_delegate)); | 626 QuicAckListenerInterface* ack_notifier_delegate)); |
613 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); | 627 MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); |
614 | 628 |
615 using QuicSession::ActivateStream; | 629 using QuicSession::ActivateStream; |
616 | 630 |
617 private: | 631 private: |
618 std::unique_ptr<QuicCryptoStream> crypto_stream_; | 632 std::unique_ptr<QuicCryptoStream> crypto_stream_; |
| 633 SpdyHeaderBlock write_headers_; |
619 | 634 |
620 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); | 635 DISALLOW_COPY_AND_ASSIGN(MockQuicSpdySession); |
621 }; | 636 }; |
622 | 637 |
623 class TestQuicSpdyServerSession : public QuicServerSessionBase { | 638 class TestQuicSpdyServerSession : public QuicServerSessionBase { |
624 public: | 639 public: |
625 TestQuicSpdyServerSession(QuicConnection* connection, | 640 TestQuicSpdyServerSession(QuicConnection* connection, |
626 const QuicConfig& config, | 641 const QuicConfig& config, |
627 const QuicCryptoServerConfig* crypto_config, | 642 const QuicCryptoServerConfig* crypto_config, |
628 QuicCompressedCertsCache* compressed_certs_cache); | 643 QuicCompressedCertsCache* compressed_certs_cache); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 TestQuicSpdyServerSession** server_session); | 950 TestQuicSpdyServerSession** server_session); |
936 | 951 |
937 // Helper to generate client side stream ids, generalizes | 952 // Helper to generate client side stream ids, generalizes |
938 // kClientDataStreamId1 etc. above. | 953 // kClientDataStreamId1 etc. above. |
939 QuicStreamId QuicClientDataStreamId(int i); | 954 QuicStreamId QuicClientDataStreamId(int i); |
940 | 955 |
941 } // namespace test | 956 } // namespace test |
942 } // namespace net | 957 } // namespace net |
943 | 958 |
944 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 959 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |