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 <utility> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
21 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" |
22 #include "net/quic/core/congestion_control/loss_detection_interface.h" | 22 #include "net/quic/core/congestion_control/loss_detection_interface.h" |
23 #include "net/quic/core/congestion_control/send_algorithm_interface.h" | 23 #include "net/quic/core/congestion_control/send_algorithm_interface.h" |
24 #include "net/quic/core/quic_client_push_promise_index.h" | 24 #include "net/quic/core/quic_client_push_promise_index.h" |
25 #include "net/quic/core/quic_connection.h" | 25 #include "net/quic/core/quic_connection.h" |
26 #include "net/quic/core/quic_framer.h" | 26 #include "net/quic/core/quic_framer.h" |
| 27 #include "net/quic/core/quic_iovector.h" |
27 #include "net/quic/core/quic_protocol.h" | 28 #include "net/quic/core/quic_protocol.h" |
28 #include "net/quic/core/quic_sent_packet_manager_interface.h" | 29 #include "net/quic/core/quic_sent_packet_manager_interface.h" |
29 #include "net/quic/core/quic_server_session_base.h" | 30 #include "net/quic/core/quic_server_session_base.h" |
30 #include "net/quic/core/quic_session.h" | 31 #include "net/quic/core/quic_session.h" |
31 #include "net/quic/core/quic_simple_buffer_allocator.h" | 32 #include "net/quic/core/quic_simple_buffer_allocator.h" |
32 #include "net/quic/test_tools/mock_clock.h" | 33 #include "net/quic/test_tools/mock_clock.h" |
33 #include "net/quic/test_tools/mock_random.h" | 34 #include "net/quic/test_tools/mock_random.h" |
34 #include "net/spdy/spdy_framer.h" | 35 #include "net/spdy/spdy_framer.h" |
35 #include "net/tools/quic/quic_dispatcher.h" | 36 #include "net/tools/quic/quic_dispatcher.h" |
36 #include "net/tools/quic/quic_per_connection_packet_writer.h" | 37 #include "net/tools/quic/quic_per_connection_packet_writer.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 // Returns QuicConfig set to default values. | 184 // Returns QuicConfig set to default values. |
184 QuicConfig DefaultQuicConfig(); | 185 QuicConfig DefaultQuicConfig(); |
185 | 186 |
186 // Returns a QuicConfig set to default values that supports stateless rejects. | 187 // Returns a QuicConfig set to default values that supports stateless rejects. |
187 QuicConfig DefaultQuicConfigStatelessRejects(); | 188 QuicConfig DefaultQuicConfigStatelessRejects(); |
188 | 189 |
189 // Returns a version vector consisting of |version|. | 190 // Returns a version vector consisting of |version|. |
190 QuicVersionVector SupportedVersions(QuicVersion version); | 191 QuicVersionVector SupportedVersions(QuicVersion version); |
191 | 192 |
192 // Testing convenience method to construct a QuicAckFrame with entropy_hash set | 193 // Testing convenience method to construct a QuicAckFrame with largest_observed |
193 // to 0 and largest_observed from peer set to |largest_observed|. | 194 // from peer set to |largest_observed|. |
194 QuicAckFrame MakeAckFrame(QuicPacketNumber largest_observed); | 195 QuicAckFrame MakeAckFrame(QuicPacketNumber largest_observed); |
195 | 196 |
196 // Testing convenience method to construct a QuicAckFrame with |num_nack_ranges| | |
197 // nack ranges of width 1 packet, starting from |least_unacked|. | |
198 QuicAckFrame MakeAckFrameWithNackRanges(size_t num_nack_ranges, | |
199 QuicPacketNumber least_unacked); | |
200 | |
201 // Testing convenience method to construct a QuicAckFrame with |num_ack_blocks| | 197 // Testing convenience method to construct a QuicAckFrame with |num_ack_blocks| |
202 // ack blocks of width 1 packet, starting from |least_unacked| + 2. | 198 // ack blocks of width 1 packet, starting from |least_unacked| + 2. |
203 QuicAckFrame MakeAckFrameWithAckBlocks(size_t num_ack_blocks, | 199 QuicAckFrame MakeAckFrameWithAckBlocks(size_t num_ack_blocks, |
204 QuicPacketNumber least_unacked); | 200 QuicPacketNumber least_unacked); |
205 | 201 |
206 // Returns a QuicPacket that is owned by the caller, and | 202 // Returns a QuicPacket that is owned by the caller, and |
207 // is populated with the fields in |header| and |frames|, or is nullptr if the | 203 // is populated with the fields in |header| and |frames|, or is nullptr if the |
208 // packet could not be created. | 204 // packet could not be created. |
209 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | 205 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, |
210 const QuicPacketHeader& header, | 206 const QuicPacketHeader& header, |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 MOCK_METHOD4(SpuriousRetransmitDetected, | 800 MOCK_METHOD4(SpuriousRetransmitDetected, |
805 void(const QuicUnackedPacketMap&, | 801 void(const QuicUnackedPacketMap&, |
806 QuicTime, | 802 QuicTime, |
807 const RttStats&, | 803 const RttStats&, |
808 QuicPacketNumber)); | 804 QuicPacketNumber)); |
809 | 805 |
810 private: | 806 private: |
811 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); | 807 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); |
812 }; | 808 }; |
813 | 809 |
814 class TestEntropyCalculator | |
815 : public QuicReceivedEntropyHashCalculatorInterface { | |
816 public: | |
817 TestEntropyCalculator(); | |
818 ~TestEntropyCalculator() override; | |
819 | |
820 QuicPacketEntropyHash EntropyHash( | |
821 QuicPacketNumber packet_number) const override; | |
822 | |
823 private: | |
824 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); | |
825 }; | |
826 | |
827 class MockEntropyCalculator : public TestEntropyCalculator { | |
828 public: | |
829 MockEntropyCalculator(); | |
830 ~MockEntropyCalculator() override; | |
831 | |
832 MOCK_CONST_METHOD1(EntropyHash, | |
833 QuicPacketEntropyHash(QuicPacketNumber packet_number)); | |
834 | |
835 private: | |
836 DISALLOW_COPY_AND_ASSIGN(MockEntropyCalculator); | |
837 }; | |
838 | |
839 class MockAckListener : public QuicAckListenerInterface { | 810 class MockAckListener : public QuicAckListenerInterface { |
840 public: | 811 public: |
841 MockAckListener(); | 812 MockAckListener(); |
842 | 813 |
843 MOCK_METHOD2(OnPacketAcked, | 814 MOCK_METHOD2(OnPacketAcked, |
844 void(int acked_bytes, QuicTime::Delta ack_delay_time)); | 815 void(int acked_bytes, QuicTime::Delta ack_delay_time)); |
845 | 816 |
846 MOCK_METHOD1(OnPacketRetransmitted, void(int retransmitted_bytes)); | 817 MOCK_METHOD1(OnPacketRetransmitted, void(int retransmitted_bytes)); |
847 | 818 |
848 protected: | 819 protected: |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 l.OnHeaderBlockStart(); | 1041 l.OnHeaderBlockStart(); |
1071 size_t total_size = 0; | 1042 size_t total_size = 0; |
1072 for (auto p : container) { | 1043 for (auto p : container) { |
1073 total_size += p.first.size() + p.second.size(); | 1044 total_size += p.first.size() + p.second.size(); |
1074 l.OnHeader(p.first, p.second); | 1045 l.OnHeader(p.first, p.second); |
1075 } | 1046 } |
1076 l.OnHeaderBlockEnd(total_size); | 1047 l.OnHeaderBlockEnd(total_size); |
1077 return l; | 1048 return l; |
1078 } | 1049 } |
1079 | 1050 |
| 1051 // Utility function that returns an QuicIOVector object wrapped around |str|. |
| 1052 // // |str|'s data is stored in |iov|. |
| 1053 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { |
| 1054 iov->iov_base = const_cast<char*>(str.data()); |
| 1055 iov->iov_len = static_cast<size_t>(str.size()); |
| 1056 QuicIOVector quic_iov(iov, 1, str.size()); |
| 1057 return quic_iov; |
| 1058 } |
| 1059 |
1080 } // namespace test | 1060 } // namespace test |
1081 } // namespace net | 1061 } // namespace net |
1082 | 1062 |
1083 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | 1063 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
OLD | NEW |