QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Common utilities for Quic tests |
| 6 | |
| 7 | #ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 8 | #define QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <memory> |
| 12 | #include <string> |
| 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/core/congestion_control/loss_detection_interface.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/congestion_control/send_algorithm_interface.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/http/quic_client_push_promise_index.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/http/quic_server_session_base.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_connection.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 21 | #include "net/third_party/quiche/src/quic/core/quic_framer.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_packet_writer.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/quic_sent_packet_manager.h" |
| 24 | #include "net/third_party/quiche/src/quic/core/quic_simple_buffer_allocator.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_mem_slice_storage.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
| 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
dschinazi | 580d30b | 2019-04-26 15:05:20 -0700 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | #include "net/third_party/quiche/src/quic/test_tools/mock_clock.h" |
| 30 | #include "net/third_party/quiche/src/quic/test_tools/mock_quic_session_visitor.h" |
| 31 | #include "net/third_party/quiche/src/quic/test_tools/mock_random.h" |
| 32 | |
| 33 | namespace quic { |
| 34 | |
| 35 | namespace test { |
| 36 | |
| 37 | // A generic predictable connection ID suited for testing. |
| 38 | QuicConnectionId TestConnectionId(); |
| 39 | |
| 40 | // A generic predictable connection ID suited for testing, generated from a |
| 41 | // given number, such as an index. |
| 42 | QuicConnectionId TestConnectionId(uint64_t connection_number); |
| 43 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 44 | // A generic predictable connection ID suited for testing, generated from a |
| 45 | // given number, such as an index. Guaranteed to be 9 bytes long. |
| 46 | QuicConnectionId TestConnectionIdNineBytesLong(uint64_t connection_number); |
| 47 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | // Extracts the connection number passed to TestConnectionId(). |
| 49 | uint64_t TestConnectionIdToUInt64(QuicConnectionId connection_id); |
| 50 | |
| 51 | static const uint16_t kTestPort = 12345; |
| 52 | static const uint32_t kInitialStreamFlowControlWindowForTest = |
| 53 | 1024 * 1024; // 1 MB |
| 54 | static const uint32_t kInitialSessionFlowControlWindowForTest = |
| 55 | 1536 * 1024; // 1.5 MB |
| 56 | |
| 57 | // Returns the test peer IP address. |
| 58 | QuicIpAddress TestPeerIPAddress(); |
| 59 | |
| 60 | // Upper limit on versions we support. |
| 61 | ParsedQuicVersion QuicVersionMax(); |
| 62 | |
| 63 | // Lower limit on versions we support. |
| 64 | ParsedQuicVersion QuicVersionMin(); |
| 65 | |
| 66 | // Upper limit on versions we support. |
| 67 | // TODO(nharper): Remove this function when it is no longer used. |
| 68 | QuicTransportVersion QuicTransportVersionMax(); |
| 69 | |
| 70 | // Lower limit on versions we support. |
| 71 | // TODO(nharper): Remove this function when it is no longer used. |
| 72 | QuicTransportVersion QuicTransportVersionMin(); |
| 73 | |
| 74 | // Create an encrypted packet for testing. |
| 75 | // If versions == nullptr, uses &AllSupportedVersions(). |
| 76 | // Note that the packet is encrypted with NullEncrypter, so to decrypt the |
| 77 | // constructed packet, the framer must be set to use NullDecrypter. |
| 78 | QuicEncryptedPacket* ConstructEncryptedPacket( |
| 79 | QuicConnectionId destination_connection_id, |
| 80 | QuicConnectionId source_connection_id, |
| 81 | bool version_flag, |
| 82 | bool reset_flag, |
| 83 | uint64_t packet_number, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 84 | const std::string& data, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 85 | QuicConnectionIdIncluded destination_connection_id_included, |
| 86 | QuicConnectionIdIncluded source_connection_id_included, |
| 87 | QuicPacketNumberLength packet_number_length, |
| 88 | ParsedQuicVersionVector* versions, |
| 89 | Perspective perspective); |
| 90 | |
| 91 | // Create an encrypted packet for testing. |
| 92 | // If versions == nullptr, uses &AllSupportedVersions(). |
| 93 | // Note that the packet is encrypted with NullEncrypter, so to decrypt the |
| 94 | // constructed packet, the framer must be set to use NullDecrypter. |
| 95 | QuicEncryptedPacket* ConstructEncryptedPacket( |
| 96 | QuicConnectionId destination_connection_id, |
| 97 | QuicConnectionId source_connection_id, |
| 98 | bool version_flag, |
| 99 | bool reset_flag, |
| 100 | uint64_t packet_number, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 101 | const std::string& data, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | QuicConnectionIdIncluded destination_connection_id_included, |
| 103 | QuicConnectionIdIncluded source_connection_id_included, |
| 104 | QuicPacketNumberLength packet_number_length, |
| 105 | ParsedQuicVersionVector* versions); |
| 106 | |
| 107 | // This form assumes |versions| == nullptr. |
| 108 | QuicEncryptedPacket* ConstructEncryptedPacket( |
| 109 | QuicConnectionId destination_connection_id, |
| 110 | QuicConnectionId source_connection_id, |
| 111 | bool version_flag, |
| 112 | bool reset_flag, |
| 113 | uint64_t packet_number, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 114 | const std::string& data, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 115 | QuicConnectionIdIncluded destination_connection_id_included, |
| 116 | QuicConnectionIdIncluded source_connection_id_included, |
| 117 | QuicPacketNumberLength packet_number_length); |
| 118 | |
| 119 | // This form assumes |connection_id_length| == PACKET_8BYTE_CONNECTION_ID, |
| 120 | // |packet_number_length| == PACKET_4BYTE_PACKET_NUMBER and |
| 121 | // |versions| == nullptr. |
| 122 | QuicEncryptedPacket* ConstructEncryptedPacket( |
| 123 | QuicConnectionId destination_connection_id, |
| 124 | QuicConnectionId source_connection_id, |
| 125 | bool version_flag, |
| 126 | bool reset_flag, |
| 127 | uint64_t packet_number, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 128 | const std::string& data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 129 | |
| 130 | // Constructs a received packet for testing. The caller must take ownership of |
| 131 | // the returned pointer. |
| 132 | QuicReceivedPacket* ConstructReceivedPacket( |
| 133 | const QuicEncryptedPacket& encrypted_packet, |
| 134 | QuicTime receipt_time); |
| 135 | |
| 136 | // Create an encrypted packet for testing whose data portion erroneous. |
| 137 | // The specific way the data portion is erroneous is not specified, but |
| 138 | // it is an error that QuicFramer detects. |
| 139 | // Note that the packet is encrypted with NullEncrypter, so to decrypt the |
| 140 | // constructed packet, the framer must be set to use NullDecrypter. |
| 141 | QuicEncryptedPacket* ConstructMisFramedEncryptedPacket( |
| 142 | QuicConnectionId destination_connection_id, |
| 143 | QuicConnectionId source_connection_id, |
| 144 | bool version_flag, |
| 145 | bool reset_flag, |
| 146 | uint64_t packet_number, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 147 | const std::string& data, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 148 | QuicConnectionIdIncluded destination_connection_id_included, |
| 149 | QuicConnectionIdIncluded source_connection_id_included, |
| 150 | QuicPacketNumberLength packet_number_length, |
| 151 | ParsedQuicVersionVector* versions, |
| 152 | Perspective perspective); |
| 153 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 154 | void CompareCharArraysWithHexError(const std::string& description, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 155 | const char* actual, |
| 156 | const int actual_len, |
| 157 | const char* expected, |
| 158 | const int expected_len); |
| 159 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 160 | // Returns QuicConfig set to default values. |
| 161 | QuicConfig DefaultQuicConfig(); |
| 162 | |
| 163 | // Returns a QuicConfig set to default values that supports stateless rejects. |
| 164 | QuicConfig DefaultQuicConfigStatelessRejects(); |
| 165 | |
| 166 | // Returns a version vector consisting of |version|. |
| 167 | QuicTransportVersionVector SupportedTransportVersions( |
| 168 | QuicTransportVersion version); |
| 169 | |
| 170 | ParsedQuicVersionVector SupportedVersions(ParsedQuicVersion version); |
| 171 | |
| 172 | struct QuicAckBlock { |
| 173 | QuicPacketNumber start; // Included |
| 174 | QuicPacketNumber limit; // Excluded |
| 175 | }; |
| 176 | |
| 177 | // Testing convenience method to construct a QuicAckFrame with arbitrary ack |
| 178 | // blocks. Each block is given by a (closed-open) range of packet numbers. e.g.: |
| 179 | // InitAckFrame({{1, 10}}) |
| 180 | // => 1 ack block acking packet numbers 1 to 9. |
| 181 | // |
| 182 | // InitAckFrame({{1, 2}, {3, 4}}) |
| 183 | // => 2 ack blocks acking packet 1 and 3. Packet 2 is missing. |
| 184 | QuicAckFrame InitAckFrame(const std::vector<QuicAckBlock>& ack_blocks); |
| 185 | |
| 186 | // Testing convenience method to construct a QuicAckFrame with 1 ack block which |
| 187 | // covers packet number range [1, |largest_acked| + 1). |
| 188 | // Equivalent to InitAckFrame({{1, largest_acked + 1}}) |
| 189 | QuicAckFrame InitAckFrame(uint64_t largest_acked); |
| 190 | QuicAckFrame InitAckFrame(QuicPacketNumber largest_acked); |
| 191 | |
| 192 | // Testing convenience method to construct a QuicAckFrame with |num_ack_blocks| |
| 193 | // ack blocks of width 1 packet, starting from |least_unacked| + 2. |
| 194 | QuicAckFrame MakeAckFrameWithAckBlocks(size_t num_ack_blocks, |
| 195 | uint64_t least_unacked); |
| 196 | |
| 197 | // Returns a QuicPacket that is owned by the caller, and |
| 198 | // is populated with the fields in |header| and |frames|, or is nullptr if the |
| 199 | // packet could not be created. |
| 200 | std::unique_ptr<QuicPacket> BuildUnsizedDataPacket( |
| 201 | QuicFramer* framer, |
| 202 | const QuicPacketHeader& header, |
| 203 | const QuicFrames& frames); |
| 204 | // Returns a QuicPacket that is owned by the caller, and of size |packet_size|. |
| 205 | std::unique_ptr<QuicPacket> BuildUnsizedDataPacket( |
| 206 | QuicFramer* framer, |
| 207 | const QuicPacketHeader& header, |
| 208 | const QuicFrames& frames, |
| 209 | size_t packet_size); |
| 210 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 211 | // Compute SHA-1 hash of the supplied std::string. |
| 212 | std::string Sha1Hash(QuicStringPiece data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 213 | |
| 214 | // Simple random number generator used to compute random numbers suitable |
vasilvv | c201848 | 2019-04-26 15:47:55 -0700 | [diff] [blame] | 215 | // for pseudo-randomly dropping packets in tests. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 216 | class SimpleRandom : public QuicRandom { |
| 217 | public: |
vasilvv | c201848 | 2019-04-26 15:47:55 -0700 | [diff] [blame] | 218 | SimpleRandom() { set_seed(0); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 219 | SimpleRandom(const SimpleRandom&) = delete; |
| 220 | SimpleRandom& operator=(const SimpleRandom&) = delete; |
| 221 | ~SimpleRandom() override {} |
| 222 | |
| 223 | // Returns a random number in the range [0, kuint64max]. |
| 224 | uint64_t RandUint64() override; |
| 225 | |
| 226 | void RandBytes(void* data, size_t len) override; |
| 227 | |
vasilvv | c201848 | 2019-04-26 15:47:55 -0700 | [diff] [blame] | 228 | void set_seed(uint64_t seed); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 229 | |
| 230 | private: |
vasilvv | c201848 | 2019-04-26 15:47:55 -0700 | [diff] [blame] | 231 | uint8_t buffer_[4096]; |
| 232 | size_t buffer_offset_; |
| 233 | uint8_t key_[32]; |
| 234 | |
| 235 | void FillBuffer(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | class MockFramerVisitor : public QuicFramerVisitorInterface { |
| 239 | public: |
| 240 | MockFramerVisitor(); |
| 241 | MockFramerVisitor(const MockFramerVisitor&) = delete; |
| 242 | MockFramerVisitor& operator=(const MockFramerVisitor&) = delete; |
| 243 | ~MockFramerVisitor() override; |
| 244 | |
| 245 | MOCK_METHOD1(OnError, void(QuicFramer* framer)); |
| 246 | // The constructor sets this up to return false by default. |
| 247 | MOCK_METHOD2(OnProtocolVersionMismatch, |
| 248 | bool(ParsedQuicVersion version, PacketHeaderFormat form)); |
| 249 | MOCK_METHOD0(OnPacket, void()); |
| 250 | MOCK_METHOD1(OnPublicResetPacket, void(const QuicPublicResetPacket& header)); |
| 251 | MOCK_METHOD1(OnVersionNegotiationPacket, |
| 252 | void(const QuicVersionNegotiationPacket& packet)); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame^] | 253 | MOCK_METHOD3(OnRetryPacket, |
| 254 | void(QuicConnectionId original_connection_id, |
| 255 | QuicConnectionId new_connection_id, |
| 256 | QuicStringPiece retry_token)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 257 | // The constructor sets this up to return true by default. |
| 258 | MOCK_METHOD1(OnUnauthenticatedHeader, bool(const QuicPacketHeader& header)); |
| 259 | // The constructor sets this up to return true by default. |
| 260 | MOCK_METHOD1(OnUnauthenticatedPublicHeader, |
| 261 | bool(const QuicPacketHeader& header)); |
| 262 | MOCK_METHOD1(OnDecryptedPacket, void(EncryptionLevel level)); |
| 263 | MOCK_METHOD1(OnPacketHeader, bool(const QuicPacketHeader& header)); |
| 264 | MOCK_METHOD1(OnCoalescedPacket, void(const QuicEncryptedPacket& packet)); |
| 265 | MOCK_METHOD1(OnStreamFrame, bool(const QuicStreamFrame& frame)); |
| 266 | MOCK_METHOD1(OnCryptoFrame, bool(const QuicCryptoFrame& frame)); |
| 267 | MOCK_METHOD2(OnAckFrameStart, bool(QuicPacketNumber, QuicTime::Delta)); |
| 268 | MOCK_METHOD2(OnAckRange, bool(QuicPacketNumber, QuicPacketNumber)); |
| 269 | MOCK_METHOD2(OnAckTimestamp, bool(QuicPacketNumber, QuicTime)); |
| 270 | MOCK_METHOD1(OnAckFrameEnd, bool(QuicPacketNumber)); |
| 271 | MOCK_METHOD1(OnStopWaitingFrame, bool(const QuicStopWaitingFrame& frame)); |
| 272 | MOCK_METHOD1(OnPaddingFrame, bool(const QuicPaddingFrame& frame)); |
| 273 | MOCK_METHOD1(OnPingFrame, bool(const QuicPingFrame& frame)); |
| 274 | MOCK_METHOD1(OnRstStreamFrame, bool(const QuicRstStreamFrame& frame)); |
| 275 | MOCK_METHOD1(OnConnectionCloseFrame, |
| 276 | bool(const QuicConnectionCloseFrame& frame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 277 | MOCK_METHOD1(OnNewConnectionIdFrame, |
| 278 | bool(const QuicNewConnectionIdFrame& frame)); |
| 279 | MOCK_METHOD1(OnRetireConnectionIdFrame, |
| 280 | bool(const QuicRetireConnectionIdFrame& frame)); |
| 281 | MOCK_METHOD1(OnNewTokenFrame, bool(const QuicNewTokenFrame& frame)); |
| 282 | MOCK_METHOD1(OnStopSendingFrame, bool(const QuicStopSendingFrame& frame)); |
| 283 | MOCK_METHOD1(OnPathChallengeFrame, bool(const QuicPathChallengeFrame& frame)); |
| 284 | MOCK_METHOD1(OnPathResponseFrame, bool(const QuicPathResponseFrame& frame)); |
| 285 | MOCK_METHOD1(OnGoAwayFrame, bool(const QuicGoAwayFrame& frame)); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 286 | MOCK_METHOD1(OnMaxStreamsFrame, bool(const QuicMaxStreamsFrame& frame)); |
| 287 | MOCK_METHOD1(OnStreamsBlockedFrame, |
| 288 | bool(const QuicStreamsBlockedFrame& frame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 289 | MOCK_METHOD1(OnWindowUpdateFrame, bool(const QuicWindowUpdateFrame& frame)); |
| 290 | MOCK_METHOD1(OnBlockedFrame, bool(const QuicBlockedFrame& frame)); |
| 291 | MOCK_METHOD1(OnMessageFrame, bool(const QuicMessageFrame& frame)); |
| 292 | MOCK_METHOD0(OnPacketComplete, void()); |
| 293 | MOCK_CONST_METHOD1(IsValidStatelessResetToken, bool(QuicUint128)); |
| 294 | MOCK_METHOD1(OnAuthenticatedIetfStatelessResetPacket, |
| 295 | void(const QuicIetfStatelessResetPacket&)); |
| 296 | }; |
| 297 | |
| 298 | class NoOpFramerVisitor : public QuicFramerVisitorInterface { |
| 299 | public: |
| 300 | NoOpFramerVisitor() {} |
| 301 | NoOpFramerVisitor(const NoOpFramerVisitor&) = delete; |
| 302 | NoOpFramerVisitor& operator=(const NoOpFramerVisitor&) = delete; |
| 303 | |
| 304 | void OnError(QuicFramer* framer) override {} |
| 305 | void OnPacket() override {} |
| 306 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {} |
| 307 | void OnVersionNegotiationPacket( |
| 308 | const QuicVersionNegotiationPacket& packet) override {} |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame^] | 309 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 310 | QuicConnectionId new_connection_id, |
| 311 | QuicStringPiece retry_token) override {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 312 | bool OnProtocolVersionMismatch(ParsedQuicVersion version, |
| 313 | PacketHeaderFormat form) override; |
| 314 | bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
| 315 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override; |
| 316 | void OnDecryptedPacket(EncryptionLevel level) override {} |
| 317 | bool OnPacketHeader(const QuicPacketHeader& header) override; |
| 318 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override; |
| 319 | bool OnStreamFrame(const QuicStreamFrame& frame) override; |
| 320 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override; |
| 321 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 322 | QuicTime::Delta ack_delay_time) override; |
| 323 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override; |
| 324 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 325 | QuicTime timestamp) override; |
| 326 | bool OnAckFrameEnd(QuicPacketNumber start) override; |
| 327 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
| 328 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override; |
| 329 | bool OnPingFrame(const QuicPingFrame& frame) override; |
| 330 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
| 331 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 332 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override; |
| 333 | bool OnRetireConnectionIdFrame( |
| 334 | const QuicRetireConnectionIdFrame& frame) override; |
| 335 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override; |
| 336 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override; |
| 337 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override; |
| 338 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override; |
| 339 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 340 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override; |
| 341 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 342 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 343 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 344 | bool OnMessageFrame(const QuicMessageFrame& frame) override; |
| 345 | void OnPacketComplete() override {} |
| 346 | bool IsValidStatelessResetToken(QuicUint128 token) const override; |
| 347 | void OnAuthenticatedIetfStatelessResetPacket( |
| 348 | const QuicIetfStatelessResetPacket& packet) override {} |
| 349 | }; |
| 350 | |
| 351 | class MockQuicConnectionVisitor : public QuicConnectionVisitorInterface { |
| 352 | public: |
| 353 | MockQuicConnectionVisitor(); |
| 354 | MockQuicConnectionVisitor(const MockQuicConnectionVisitor&) = delete; |
| 355 | MockQuicConnectionVisitor& operator=(const MockQuicConnectionVisitor&) = |
| 356 | delete; |
| 357 | ~MockQuicConnectionVisitor() override; |
| 358 | |
| 359 | MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame& frame)); |
| 360 | MOCK_METHOD1(OnCryptoFrame, void(const QuicCryptoFrame& frame)); |
| 361 | MOCK_METHOD1(OnWindowUpdateFrame, void(const QuicWindowUpdateFrame& frame)); |
| 362 | MOCK_METHOD1(OnBlockedFrame, void(const QuicBlockedFrame& frame)); |
| 363 | MOCK_METHOD1(OnRstStream, void(const QuicRstStreamFrame& frame)); |
| 364 | MOCK_METHOD1(OnGoAway, void(const QuicGoAwayFrame& frame)); |
| 365 | MOCK_METHOD1(OnMessageReceived, void(QuicStringPiece message)); |
| 366 | MOCK_METHOD3(OnConnectionClosed, |
| 367 | void(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 368 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 369 | ConnectionCloseSource source)); |
| 370 | MOCK_METHOD0(OnWriteBlocked, void()); |
| 371 | MOCK_METHOD0(OnCanWrite, void()); |
QUICHE team | b834325 | 2019-04-29 13:58:01 -0700 | [diff] [blame] | 372 | MOCK_METHOD0(SendProbingData, bool()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 373 | MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now)); |
| 374 | MOCK_METHOD1(OnConnectionMigration, void(AddressChangeType type)); |
| 375 | MOCK_METHOD0(OnPathDegrading, void()); |
| 376 | MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); |
| 377 | MOCK_CONST_METHOD0(HasPendingHandshake, bool()); |
| 378 | MOCK_CONST_METHOD0(ShouldKeepConnectionAlive, bool()); |
| 379 | MOCK_METHOD1(OnSuccessfulVersionNegotiation, |
| 380 | void(const ParsedQuicVersion& version)); |
| 381 | MOCK_METHOD2(OnConnectivityProbeReceived, |
| 382 | void(const QuicSocketAddress& self_address, |
| 383 | const QuicSocketAddress& peer_address)); |
| 384 | MOCK_METHOD0(OnConfigNegotiated, void()); |
| 385 | MOCK_METHOD0(OnAckNeedsRetransmittableFrame, void()); |
| 386 | MOCK_METHOD0(SendPing, void()); |
| 387 | MOCK_CONST_METHOD0(AllowSelfAddressChange, bool()); |
| 388 | MOCK_METHOD0(OnForwardProgressConfirmed, void()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 389 | MOCK_METHOD1(OnMaxStreamsFrame, bool(const QuicMaxStreamsFrame& frame)); |
| 390 | MOCK_METHOD1(OnStreamsBlockedFrame, |
| 391 | bool(const QuicStreamsBlockedFrame& frame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 392 | MOCK_METHOD1(OnStopSendingFrame, bool(const QuicStopSendingFrame& frame)); |
| 393 | }; |
| 394 | |
| 395 | class MockQuicConnectionHelper : public QuicConnectionHelperInterface { |
| 396 | public: |
| 397 | MockQuicConnectionHelper(); |
| 398 | MockQuicConnectionHelper(const MockQuicConnectionHelper&) = delete; |
| 399 | MockQuicConnectionHelper& operator=(const MockQuicConnectionHelper&) = delete; |
| 400 | ~MockQuicConnectionHelper() override; |
| 401 | const QuicClock* GetClock() const override; |
| 402 | QuicRandom* GetRandomGenerator() override; |
| 403 | QuicBufferAllocator* GetStreamSendBufferAllocator() override; |
| 404 | void AdvanceTime(QuicTime::Delta delta); |
| 405 | |
| 406 | private: |
| 407 | MockClock clock_; |
| 408 | MockRandom random_generator_; |
| 409 | SimpleBufferAllocator buffer_allocator_; |
| 410 | }; |
| 411 | |
| 412 | class MockAlarmFactory : public QuicAlarmFactory { |
| 413 | public: |
| 414 | QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; |
| 415 | QuicArenaScopedPtr<QuicAlarm> CreateAlarm( |
| 416 | QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 417 | QuicConnectionArena* arena) override; |
| 418 | |
| 419 | // No-op alarm implementation |
| 420 | class TestAlarm : public QuicAlarm { |
| 421 | public: |
| 422 | explicit TestAlarm(QuicArenaScopedPtr<QuicAlarm::Delegate> delegate) |
| 423 | : QuicAlarm(std::move(delegate)) {} |
| 424 | |
| 425 | void SetImpl() override {} |
| 426 | void CancelImpl() override {} |
| 427 | |
| 428 | using QuicAlarm::Fire; |
| 429 | }; |
| 430 | |
| 431 | void FireAlarm(QuicAlarm* alarm) { |
| 432 | reinterpret_cast<TestAlarm*>(alarm)->Fire(); |
| 433 | } |
| 434 | }; |
| 435 | |
| 436 | class MockQuicConnection : public QuicConnection { |
| 437 | public: |
| 438 | // Uses a ConnectionId of 42 and 127.0.0.1:123. |
| 439 | MockQuicConnection(MockQuicConnectionHelper* helper, |
| 440 | MockAlarmFactory* alarm_factory, |
| 441 | Perspective perspective); |
| 442 | |
| 443 | // Uses a ConnectionId of 42. |
| 444 | MockQuicConnection(QuicSocketAddress address, |
| 445 | MockQuicConnectionHelper* helper, |
| 446 | MockAlarmFactory* alarm_factory, |
| 447 | Perspective perspective); |
| 448 | |
| 449 | // Uses 127.0.0.1:123. |
| 450 | MockQuicConnection(QuicConnectionId connection_id, |
| 451 | MockQuicConnectionHelper* helper, |
| 452 | MockAlarmFactory* alarm_factory, |
| 453 | Perspective perspective); |
| 454 | |
| 455 | // Uses a ConnectionId of 42, and 127.0.0.1:123. |
| 456 | MockQuicConnection(MockQuicConnectionHelper* helper, |
| 457 | MockAlarmFactory* alarm_factory, |
| 458 | Perspective perspective, |
| 459 | const ParsedQuicVersionVector& supported_versions); |
| 460 | |
| 461 | MockQuicConnection(QuicConnectionId connection_id, |
| 462 | QuicSocketAddress address, |
| 463 | MockQuicConnectionHelper* helper, |
| 464 | MockAlarmFactory* alarm_factory, |
| 465 | Perspective perspective, |
| 466 | const ParsedQuicVersionVector& supported_versions); |
| 467 | MockQuicConnection(const MockQuicConnection&) = delete; |
| 468 | MockQuicConnection& operator=(const MockQuicConnection&) = delete; |
| 469 | |
| 470 | ~MockQuicConnection() override; |
| 471 | |
| 472 | // If the constructor that uses a MockQuicConnectionHelper has been used then |
| 473 | // this method |
| 474 | // will advance the time of the MockClock. |
| 475 | void AdvanceTime(QuicTime::Delta delta); |
| 476 | |
| 477 | MOCK_METHOD3(ProcessUdpPacket, |
| 478 | void(const QuicSocketAddress& self_address, |
| 479 | const QuicSocketAddress& peer_address, |
| 480 | const QuicReceivedPacket& packet)); |
| 481 | MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); |
| 482 | MOCK_METHOD3(CloseConnection, |
| 483 | void(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 484 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 485 | ConnectionCloseBehavior connection_close_behavior)); |
ianswett | dc1e7ab | 2019-05-03 16:10:44 -0700 | [diff] [blame] | 486 | MOCK_METHOD2(SendConnectionClosePacket, |
| 487 | void(QuicErrorCode error, const std::string& details)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 488 | MOCK_METHOD3(SendRstStream, |
| 489 | void(QuicStreamId id, |
| 490 | QuicRstStreamErrorCode error, |
| 491 | QuicStreamOffset bytes_written)); |
| 492 | MOCK_METHOD3(SendGoAway, |
| 493 | void(QuicErrorCode error, |
| 494 | QuicStreamId last_good_stream_id, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 495 | const std::string& reason)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 496 | MOCK_METHOD1(SendBlocked, void(QuicStreamId id)); |
| 497 | MOCK_METHOD2(SendWindowUpdate, |
| 498 | void(QuicStreamId id, QuicStreamOffset byte_offset)); |
| 499 | MOCK_METHOD0(OnCanWrite, void()); |
| 500 | MOCK_METHOD1(SendConnectivityProbingResponsePacket, |
| 501 | void(const QuicSocketAddress& peer_address)); |
| 502 | MOCK_METHOD2(SendConnectivityProbingPacket, |
| 503 | bool(QuicPacketWriter* probing_writer, |
| 504 | const QuicSocketAddress& peer_address)); |
| 505 | |
| 506 | MOCK_METHOD1(OnSendConnectionState, void(const CachedNetworkParameters&)); |
| 507 | MOCK_METHOD2(ResumeConnectionState, |
| 508 | void(const CachedNetworkParameters&, bool)); |
| 509 | MOCK_METHOD1(SetMaxPacingRate, void(QuicBandwidth)); |
| 510 | |
| 511 | MOCK_METHOD2(OnStreamReset, void(QuicStreamId, QuicRstStreamErrorCode)); |
| 512 | MOCK_METHOD1(SendControlFrame, bool(const QuicFrame& frame)); |
| 513 | MOCK_METHOD2(SendMessage, MessageStatus(QuicMessageId, QuicMemSliceSpan)); |
| 514 | MOCK_METHOD3(OnConnectionClosed, |
| 515 | void(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 516 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 517 | ConnectionCloseSource source)); |
| 518 | |
| 519 | MOCK_METHOD1(OnError, void(QuicFramer* framer)); |
| 520 | void QuicConnection_OnError(QuicFramer* framer) { |
| 521 | QuicConnection::OnError(framer); |
| 522 | } |
| 523 | |
| 524 | void ReallyCloseConnection( |
| 525 | QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 526 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 527 | ConnectionCloseBehavior connection_close_behavior) { |
| 528 | QuicConnection::CloseConnection(error, details, connection_close_behavior); |
| 529 | } |
| 530 | |
| 531 | void ReallyProcessUdpPacket(const QuicSocketAddress& self_address, |
| 532 | const QuicSocketAddress& peer_address, |
| 533 | const QuicReceivedPacket& packet) { |
| 534 | QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); |
| 535 | } |
| 536 | |
| 537 | bool OnProtocolVersionMismatch(ParsedQuicVersion version, |
| 538 | PacketHeaderFormat form) override; |
| 539 | |
| 540 | bool ReallySendControlFrame(const QuicFrame& frame) { |
| 541 | return QuicConnection::SendControlFrame(frame); |
| 542 | } |
| 543 | |
| 544 | bool ReallySendConnectivityProbingPacket( |
| 545 | QuicPacketWriter* probing_writer, |
| 546 | const QuicSocketAddress& peer_address) { |
| 547 | return QuicConnection::SendConnectivityProbingPacket(probing_writer, |
| 548 | peer_address); |
| 549 | } |
| 550 | |
| 551 | void ReallySendConnectivityProbingResponsePacket( |
| 552 | const QuicSocketAddress& peer_address) { |
| 553 | QuicConnection::SendConnectivityProbingResponsePacket(peer_address); |
| 554 | } |
| 555 | MOCK_METHOD1(OnPathResponseFrame, bool(const QuicPathResponseFrame&)); |
| 556 | MOCK_METHOD1(OnStopSendingFrame, bool(const QuicStopSendingFrame& frame)); |
| 557 | MOCK_METHOD3(SendCryptoData, |
| 558 | size_t(EncryptionLevel, size_t, QuicStreamOffset)); |
| 559 | size_t QuicConnection_SendCryptoData(EncryptionLevel level, |
| 560 | size_t write_length, |
| 561 | QuicStreamOffset offset) { |
| 562 | return QuicConnection::SendCryptoData(level, write_length, offset); |
| 563 | } |
| 564 | }; |
| 565 | |
| 566 | class PacketSavingConnection : public MockQuicConnection { |
| 567 | public: |
| 568 | PacketSavingConnection(MockQuicConnectionHelper* helper, |
| 569 | MockAlarmFactory* alarm_factory, |
| 570 | Perspective perspective); |
| 571 | |
| 572 | PacketSavingConnection(MockQuicConnectionHelper* helper, |
| 573 | MockAlarmFactory* alarm_factory, |
| 574 | Perspective perspective, |
| 575 | const ParsedQuicVersionVector& supported_versions); |
| 576 | PacketSavingConnection(const PacketSavingConnection&) = delete; |
| 577 | PacketSavingConnection& operator=(const PacketSavingConnection&) = delete; |
| 578 | |
| 579 | ~PacketSavingConnection() override; |
| 580 | |
| 581 | void SendOrQueuePacket(SerializedPacket* packet) override; |
| 582 | |
| 583 | std::vector<std::unique_ptr<QuicEncryptedPacket>> encrypted_packets_; |
| 584 | MockClock clock_; |
| 585 | }; |
| 586 | |
| 587 | class MockQuicSession : public QuicSession { |
| 588 | public: |
| 589 | // Takes ownership of |connection|. |
| 590 | MockQuicSession(QuicConnection* connection, bool create_mock_crypto_stream); |
| 591 | |
| 592 | // Takes ownership of |connection|. |
| 593 | explicit MockQuicSession(QuicConnection* connection); |
| 594 | MockQuicSession(const MockQuicSession&) = delete; |
| 595 | MockQuicSession& operator=(const MockQuicSession&) = delete; |
| 596 | ~MockQuicSession() override; |
| 597 | |
| 598 | QuicCryptoStream* GetMutableCryptoStream() override; |
| 599 | const QuicCryptoStream* GetCryptoStream() const override; |
| 600 | void SetCryptoStream(QuicCryptoStream* crypto_stream); |
| 601 | |
| 602 | MOCK_METHOD3(OnConnectionClosed, |
| 603 | void(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 604 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 605 | ConnectionCloseSource source)); |
| 606 | MOCK_METHOD1(CreateIncomingStream, QuicStream*(QuicStreamId id)); |
| 607 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(PendingStream stream)); |
| 608 | MOCK_METHOD1(ShouldCreateIncomingStream2, bool(QuicStreamId id)); |
| 609 | MOCK_METHOD0(ShouldCreateOutgoingBidirectionalStream, bool()); |
| 610 | MOCK_METHOD0(ShouldCreateOutgoingUnidirectionalStream, bool()); |
| 611 | MOCK_METHOD5(WritevData, |
| 612 | QuicConsumedData(QuicStream* stream, |
| 613 | QuicStreamId id, |
| 614 | size_t write_length, |
| 615 | QuicStreamOffset offset, |
| 616 | StreamSendingState state)); |
| 617 | |
| 618 | MOCK_METHOD3(SendRstStream, |
| 619 | void(QuicStreamId stream_id, |
| 620 | QuicRstStreamErrorCode error, |
| 621 | QuicStreamOffset bytes_written)); |
| 622 | |
| 623 | MOCK_METHOD2(OnStreamHeaders, |
| 624 | void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 625 | MOCK_METHOD2(OnStreamHeadersPriority, |
| 626 | void(QuicStreamId stream_id, spdy::SpdyPriority priority)); |
| 627 | MOCK_METHOD3(OnStreamHeadersComplete, |
| 628 | void(QuicStreamId stream_id, bool fin, size_t frame_len)); |
| 629 | MOCK_CONST_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 630 | MOCK_CONST_METHOD0(ShouldKeepConnectionAlive, bool()); |
| 631 | MOCK_METHOD2(SendStopSending, void(uint16_t code, QuicStreamId stream_id)); |
| 632 | |
| 633 | using QuicSession::ActivateStream; |
| 634 | |
| 635 | // Returns a QuicConsumedData that indicates all of |write_length| (and |fin| |
| 636 | // if set) has been consumed. |
| 637 | static QuicConsumedData ConsumeData(QuicStream* stream, |
| 638 | QuicStreamId id, |
| 639 | size_t write_length, |
| 640 | QuicStreamOffset offset, |
| 641 | StreamSendingState state); |
| 642 | |
| 643 | private: |
| 644 | std::unique_ptr<QuicCryptoStream> crypto_stream_; |
| 645 | }; |
| 646 | |
| 647 | class MockQuicCryptoStream : public QuicCryptoStream { |
| 648 | public: |
| 649 | explicit MockQuicCryptoStream(QuicSession* session); |
| 650 | |
| 651 | ~MockQuicCryptoStream() override; |
| 652 | |
| 653 | bool encryption_established() const override; |
| 654 | bool handshake_confirmed() const override; |
| 655 | const QuicCryptoNegotiatedParameters& crypto_negotiated_params() |
| 656 | const override; |
| 657 | CryptoMessageParser* crypto_message_parser() override; |
| 658 | |
| 659 | private: |
| 660 | QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; |
| 661 | CryptoFramer crypto_framer_; |
| 662 | }; |
| 663 | |
| 664 | class MockQuicSpdySession : public QuicSpdySession { |
| 665 | public: |
| 666 | // Takes ownership of |connection|. |
| 667 | explicit MockQuicSpdySession(QuicConnection* connection); |
| 668 | // Takes ownership of |connection|. |
| 669 | MockQuicSpdySession(QuicConnection* connection, |
| 670 | bool create_mock_crypto_stream); |
| 671 | MockQuicSpdySession(const MockQuicSpdySession&) = delete; |
| 672 | MockQuicSpdySession& operator=(const MockQuicSpdySession&) = delete; |
| 673 | ~MockQuicSpdySession() override; |
| 674 | |
| 675 | QuicCryptoStream* GetMutableCryptoStream() override; |
| 676 | const QuicCryptoStream* GetCryptoStream() const override; |
| 677 | void SetCryptoStream(QuicCryptoStream* crypto_stream); |
| 678 | |
QUICHE team | 396d109 | 2019-03-20 10:21:07 -0700 | [diff] [blame] | 679 | void ReallyOnConnectionClosed(QuicErrorCode error, |
| 680 | const std::string& error_details, |
| 681 | ConnectionCloseSource source) { |
| 682 | QuicSession::OnConnectionClosed(error, error_details, source); |
| 683 | } |
| 684 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 685 | // From QuicSession. |
| 686 | MOCK_METHOD3(OnConnectionClosed, |
| 687 | void(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 688 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 689 | ConnectionCloseSource source)); |
| 690 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(QuicStreamId id)); |
| 691 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(PendingStream stream)); |
| 692 | MOCK_METHOD0(CreateOutgoingBidirectionalStream, QuicSpdyStream*()); |
| 693 | MOCK_METHOD0(CreateOutgoingUnidirectionalStream, QuicSpdyStream*()); |
| 694 | MOCK_METHOD1(ShouldCreateIncomingStream, bool(QuicStreamId id)); |
| 695 | MOCK_METHOD0(ShouldCreateOutgoingBidirectionalStream, bool()); |
| 696 | MOCK_METHOD0(ShouldCreateOutgoingUnidirectionalStream, bool()); |
| 697 | MOCK_METHOD5(WritevData, |
| 698 | QuicConsumedData(QuicStream* stream, |
| 699 | QuicStreamId id, |
| 700 | size_t write_length, |
| 701 | QuicStreamOffset offset, |
| 702 | StreamSendingState state)); |
| 703 | |
| 704 | MOCK_METHOD3(SendRstStream, |
| 705 | void(QuicStreamId stream_id, |
| 706 | QuicRstStreamErrorCode error, |
| 707 | QuicStreamOffset bytes_written)); |
| 708 | |
| 709 | MOCK_METHOD2(OnStreamHeaders, |
| 710 | void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 711 | MOCK_METHOD2(OnStreamHeadersPriority, |
| 712 | void(QuicStreamId stream_id, spdy::SpdyPriority priority)); |
| 713 | MOCK_METHOD3(OnStreamHeadersComplete, |
| 714 | void(QuicStreamId stream_id, bool fin, size_t frame_len)); |
| 715 | MOCK_METHOD4(OnStreamHeaderList, |
| 716 | void(QuicStreamId stream_id, |
| 717 | bool fin, |
| 718 | size_t frame_len, |
| 719 | const QuicHeaderList& header_list)); |
| 720 | MOCK_CONST_METHOD0(IsCryptoHandshakeConfirmed, bool()); |
| 721 | MOCK_METHOD2(OnPromiseHeaders, |
| 722 | void(QuicStreamId stream_id, QuicStringPiece headers_data)); |
| 723 | MOCK_METHOD3(OnPromiseHeadersComplete, |
| 724 | void(QuicStreamId stream_id, |
| 725 | QuicStreamId promised_stream_id, |
| 726 | size_t frame_len)); |
| 727 | MOCK_METHOD4(OnPromiseHeaderList, |
| 728 | void(QuicStreamId stream_id, |
| 729 | QuicStreamId promised_stream_id, |
| 730 | size_t frame_len, |
| 731 | const QuicHeaderList& header_list)); |
| 732 | MOCK_METHOD2(OnPriorityFrame, |
| 733 | void(QuicStreamId id, spdy::SpdyPriority priority)); |
| 734 | |
| 735 | MOCK_METHOD1(OnHeadersHeadOfLineBlocking, void(QuicTime::Delta delta)); |
| 736 | MOCK_METHOD4( |
| 737 | OnStreamFrameData, |
| 738 | void(QuicStreamId stream_id, const char* data, size_t len, bool fin)); |
| 739 | |
| 740 | using QuicSession::ActivateStream; |
| 741 | |
| 742 | private: |
| 743 | std::unique_ptr<QuicCryptoStream> crypto_stream_; |
| 744 | }; |
| 745 | |
| 746 | class TestQuicSpdyServerSession : public QuicServerSessionBase { |
| 747 | public: |
| 748 | // Takes ownership of |connection|. |
| 749 | TestQuicSpdyServerSession(QuicConnection* connection, |
| 750 | const QuicConfig& config, |
| 751 | const ParsedQuicVersionVector& supported_versions, |
| 752 | const QuicCryptoServerConfig* crypto_config, |
| 753 | QuicCompressedCertsCache* compressed_certs_cache); |
| 754 | TestQuicSpdyServerSession(const TestQuicSpdyServerSession&) = delete; |
| 755 | TestQuicSpdyServerSession& operator=(const TestQuicSpdyServerSession&) = |
| 756 | delete; |
| 757 | ~TestQuicSpdyServerSession() override; |
| 758 | |
| 759 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(QuicStreamId id)); |
| 760 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(PendingStream stream)); |
| 761 | MOCK_METHOD0(CreateOutgoingBidirectionalStream, QuicSpdyStream*()); |
| 762 | MOCK_METHOD0(CreateOutgoingUnidirectionalStream, QuicSpdyStream*()); |
| 763 | QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
| 764 | const QuicCryptoServerConfig* crypto_config, |
| 765 | QuicCompressedCertsCache* compressed_certs_cache) override; |
| 766 | |
| 767 | // Override to not send max header list size. |
| 768 | void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; |
| 769 | |
| 770 | QuicCryptoServerStream* GetMutableCryptoStream() override; |
| 771 | |
| 772 | const QuicCryptoServerStream* GetCryptoStream() const override; |
| 773 | |
| 774 | MockQuicCryptoServerStreamHelper* helper() { return &helper_; } |
| 775 | |
| 776 | private: |
| 777 | MockQuicSessionVisitor visitor_; |
| 778 | MockQuicCryptoServerStreamHelper helper_; |
| 779 | }; |
| 780 | |
| 781 | // A test implementation of QuicClientPushPromiseIndex::Delegate. |
| 782 | class TestPushPromiseDelegate : public QuicClientPushPromiseIndex::Delegate { |
| 783 | public: |
| 784 | // |match| sets the validation result for checking whether designated header |
| 785 | // fields match for promise request and client request. |
| 786 | explicit TestPushPromiseDelegate(bool match); |
| 787 | |
| 788 | bool CheckVary(const spdy::SpdyHeaderBlock& client_request, |
| 789 | const spdy::SpdyHeaderBlock& promise_request, |
| 790 | const spdy::SpdyHeaderBlock& promise_response) override; |
| 791 | |
| 792 | void OnRendezvousResult(QuicSpdyStream* stream) override; |
| 793 | |
| 794 | QuicSpdyStream* rendezvous_stream() { return rendezvous_stream_; } |
| 795 | bool rendezvous_fired() { return rendezvous_fired_; } |
| 796 | |
| 797 | private: |
| 798 | bool match_; |
| 799 | bool rendezvous_fired_; |
| 800 | QuicSpdyStream* rendezvous_stream_; |
| 801 | }; |
| 802 | |
| 803 | class TestQuicSpdyClientSession : public QuicSpdyClientSessionBase { |
| 804 | public: |
| 805 | TestQuicSpdyClientSession(QuicConnection* connection, |
| 806 | const QuicConfig& config, |
| 807 | const ParsedQuicVersionVector& supported_versions, |
| 808 | const QuicServerId& server_id, |
| 809 | QuicCryptoClientConfig* crypto_config); |
| 810 | TestQuicSpdyClientSession(const TestQuicSpdyClientSession&) = delete; |
| 811 | TestQuicSpdyClientSession& operator=(const TestQuicSpdyClientSession&) = |
| 812 | delete; |
| 813 | ~TestQuicSpdyClientSession() override; |
| 814 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 815 | bool IsAuthorized(const std::string& authority) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 816 | |
| 817 | // QuicSpdyClientSessionBase |
| 818 | MOCK_METHOD1(OnProofValid, |
| 819 | void(const QuicCryptoClientConfig::CachedState& cached)); |
| 820 | MOCK_METHOD1(OnProofVerifyDetailsAvailable, |
| 821 | void(const ProofVerifyDetails& verify_details)); |
| 822 | |
| 823 | // TestQuicSpdyClientSession |
| 824 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(QuicStreamId id)); |
| 825 | MOCK_METHOD1(CreateIncomingStream, QuicSpdyStream*(PendingStream stream)); |
| 826 | MOCK_METHOD0(CreateOutgoingBidirectionalStream, QuicSpdyStream*()); |
| 827 | MOCK_METHOD0(CreateOutgoingUnidirectionalStream, QuicSpdyStream*()); |
| 828 | MOCK_METHOD1(ShouldCreateIncomingStream, bool(QuicStreamId id)); |
| 829 | MOCK_METHOD0(ShouldCreateOutgoingBidirectionalStream, bool()); |
| 830 | MOCK_METHOD0(ShouldCreateOutgoingUnidirectionalStream, bool()); |
| 831 | |
| 832 | // Override to not send max header list size. |
| 833 | void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; |
| 834 | QuicCryptoClientStream* GetMutableCryptoStream() override; |
| 835 | const QuicCryptoClientStream* GetCryptoStream() const override; |
| 836 | |
| 837 | // Override to save sent crypto handshake messages. |
| 838 | void OnCryptoHandshakeMessageSent( |
| 839 | const CryptoHandshakeMessage& message) override { |
| 840 | sent_crypto_handshake_messages_.push_back(message); |
| 841 | } |
| 842 | |
| 843 | const std::vector<CryptoHandshakeMessage>& sent_crypto_handshake_messages() |
| 844 | const { |
| 845 | return sent_crypto_handshake_messages_; |
| 846 | } |
| 847 | |
| 848 | private: |
| 849 | std::unique_ptr<QuicCryptoClientStream> crypto_stream_; |
| 850 | QuicClientPushPromiseIndex push_promise_index_; |
| 851 | std::vector<CryptoHandshakeMessage> sent_crypto_handshake_messages_; |
| 852 | }; |
| 853 | |
| 854 | class MockPacketWriter : public QuicPacketWriter { |
| 855 | public: |
| 856 | MockPacketWriter(); |
| 857 | MockPacketWriter(const MockPacketWriter&) = delete; |
| 858 | MockPacketWriter& operator=(const MockPacketWriter&) = delete; |
| 859 | ~MockPacketWriter() override; |
| 860 | |
| 861 | MOCK_METHOD5(WritePacket, |
| 862 | WriteResult(const char* buffer, |
| 863 | size_t buf_len, |
| 864 | const QuicIpAddress& self_address, |
| 865 | const QuicSocketAddress& peer_address, |
| 866 | PerPacketOptions* options)); |
| 867 | MOCK_CONST_METHOD0(IsWriteBlocked, bool()); |
| 868 | MOCK_METHOD0(SetWritable, void()); |
| 869 | MOCK_CONST_METHOD1(GetMaxPacketSize, |
| 870 | QuicByteCount(const QuicSocketAddress& peer_address)); |
| 871 | MOCK_CONST_METHOD0(SupportsReleaseTime, bool()); |
| 872 | MOCK_CONST_METHOD0(IsBatchMode, bool()); |
| 873 | MOCK_METHOD2(GetNextWriteLocation, |
| 874 | char*(const QuicIpAddress& self_address, |
| 875 | const QuicSocketAddress& peer_address)); |
| 876 | MOCK_METHOD0(Flush, WriteResult()); |
| 877 | }; |
| 878 | |
| 879 | class MockSendAlgorithm : public SendAlgorithmInterface { |
| 880 | public: |
| 881 | MockSendAlgorithm(); |
| 882 | MockSendAlgorithm(const MockSendAlgorithm&) = delete; |
| 883 | MockSendAlgorithm& operator=(const MockSendAlgorithm&) = delete; |
| 884 | ~MockSendAlgorithm() override; |
| 885 | |
| 886 | MOCK_METHOD2(SetFromConfig, |
| 887 | void(const QuicConfig& config, Perspective perspective)); |
| 888 | MOCK_METHOD1(SetNumEmulatedConnections, void(int num_connections)); |
| 889 | MOCK_METHOD1(SetInitialCongestionWindowInPackets, |
| 890 | void(QuicPacketCount packets)); |
| 891 | MOCK_METHOD1(SetMaxCongestionWindow, |
| 892 | void(QuicByteCount max_congestion_window)); |
| 893 | MOCK_METHOD5(OnCongestionEvent, |
| 894 | void(bool rtt_updated, |
| 895 | QuicByteCount bytes_in_flight, |
| 896 | QuicTime event_time, |
| 897 | const AckedPacketVector& acked_packets, |
| 898 | const LostPacketVector& lost_packets)); |
| 899 | MOCK_METHOD5(OnPacketSent, |
| 900 | void(QuicTime, |
| 901 | QuicByteCount, |
| 902 | QuicPacketNumber, |
| 903 | QuicByteCount, |
| 904 | HasRetransmittableData)); |
| 905 | MOCK_METHOD1(OnRetransmissionTimeout, void(bool)); |
| 906 | MOCK_METHOD0(OnConnectionMigration, void()); |
| 907 | MOCK_METHOD0(RevertRetransmissionTimeout, void()); |
| 908 | MOCK_METHOD1(CanSend, bool(QuicByteCount)); |
| 909 | MOCK_CONST_METHOD1(PacingRate, QuicBandwidth(QuicByteCount)); |
| 910 | MOCK_CONST_METHOD0(BandwidthEstimate, QuicBandwidth(void)); |
| 911 | MOCK_CONST_METHOD0(HasReliableBandwidthEstimate, bool()); |
| 912 | MOCK_METHOD1(OnRttUpdated, void(QuicPacketNumber)); |
| 913 | MOCK_CONST_METHOD0(GetCongestionWindow, QuicByteCount()); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 914 | MOCK_CONST_METHOD0(GetDebugState, std::string()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 915 | MOCK_CONST_METHOD0(InSlowStart, bool()); |
| 916 | MOCK_CONST_METHOD0(InRecovery, bool()); |
| 917 | MOCK_CONST_METHOD0(ShouldSendProbingPacket, bool()); |
| 918 | MOCK_CONST_METHOD0(GetSlowStartThreshold, QuicByteCount()); |
| 919 | MOCK_CONST_METHOD0(GetCongestionControlType, CongestionControlType()); |
| 920 | MOCK_METHOD2(AdjustNetworkParameters, void(QuicBandwidth, QuicTime::Delta)); |
| 921 | MOCK_METHOD1(OnApplicationLimited, void(QuicByteCount)); |
| 922 | }; |
| 923 | |
| 924 | class MockLossAlgorithm : public LossDetectionInterface { |
| 925 | public: |
| 926 | MockLossAlgorithm(); |
| 927 | MockLossAlgorithm(const MockLossAlgorithm&) = delete; |
| 928 | MockLossAlgorithm& operator=(const MockLossAlgorithm&) = delete; |
| 929 | ~MockLossAlgorithm() override; |
| 930 | |
| 931 | MOCK_CONST_METHOD0(GetLossDetectionType, LossDetectionType()); |
| 932 | MOCK_METHOD6(DetectLosses, |
| 933 | void(const QuicUnackedPacketMap& unacked_packets, |
| 934 | QuicTime time, |
| 935 | const RttStats& rtt_stats, |
| 936 | QuicPacketNumber largest_recently_acked, |
| 937 | const AckedPacketVector& packets_acked, |
| 938 | LostPacketVector* packets_lost)); |
| 939 | MOCK_CONST_METHOD0(GetLossTimeout, QuicTime()); |
| 940 | MOCK_METHOD4(SpuriousRetransmitDetected, |
| 941 | void(const QuicUnackedPacketMap&, |
| 942 | QuicTime, |
| 943 | const RttStats&, |
| 944 | QuicPacketNumber)); |
| 945 | }; |
| 946 | |
| 947 | class MockAckListener : public QuicAckListenerInterface { |
| 948 | public: |
| 949 | MockAckListener(); |
| 950 | MockAckListener(const MockAckListener&) = delete; |
| 951 | MockAckListener& operator=(const MockAckListener&) = delete; |
| 952 | |
| 953 | MOCK_METHOD2(OnPacketAcked, |
| 954 | void(int acked_bytes, QuicTime::Delta ack_delay_time)); |
| 955 | |
| 956 | MOCK_METHOD1(OnPacketRetransmitted, void(int retransmitted_bytes)); |
| 957 | |
| 958 | protected: |
| 959 | // Object is ref counted. |
| 960 | ~MockAckListener() override; |
| 961 | }; |
| 962 | |
| 963 | class MockNetworkChangeVisitor |
| 964 | : public QuicSentPacketManager::NetworkChangeVisitor { |
| 965 | public: |
| 966 | MockNetworkChangeVisitor(); |
| 967 | MockNetworkChangeVisitor(const MockNetworkChangeVisitor&) = delete; |
| 968 | MockNetworkChangeVisitor& operator=(const MockNetworkChangeVisitor&) = delete; |
| 969 | ~MockNetworkChangeVisitor() override; |
| 970 | |
| 971 | MOCK_METHOD0(OnCongestionChange, void()); |
| 972 | MOCK_METHOD1(OnPathMtuIncreased, void(QuicPacketLength)); |
| 973 | }; |
| 974 | |
| 975 | class MockQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor { |
| 976 | public: |
| 977 | MockQuicConnectionDebugVisitor(); |
| 978 | ~MockQuicConnectionDebugVisitor() override; |
| 979 | |
| 980 | MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&)); |
| 981 | |
| 982 | MOCK_METHOD4(OnPacketSent, |
| 983 | void(const SerializedPacket&, |
| 984 | QuicPacketNumber, |
| 985 | TransmissionType, |
| 986 | QuicTime)); |
| 987 | |
| 988 | MOCK_METHOD0(OnPingSent, void()); |
| 989 | |
| 990 | MOCK_METHOD3(OnPacketReceived, |
| 991 | void(const QuicSocketAddress&, |
| 992 | const QuicSocketAddress&, |
| 993 | const QuicEncryptedPacket&)); |
| 994 | |
| 995 | MOCK_METHOD1(OnIncorrectConnectionId, void(QuicConnectionId)); |
| 996 | |
| 997 | MOCK_METHOD1(OnProtocolVersionMismatch, void(ParsedQuicVersion)); |
| 998 | |
| 999 | MOCK_METHOD1(OnPacketHeader, void(const QuicPacketHeader& header)); |
| 1000 | |
| 1001 | MOCK_METHOD1(OnSuccessfulVersionNegotiation, void(const ParsedQuicVersion&)); |
| 1002 | |
| 1003 | MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame&)); |
| 1004 | |
| 1005 | MOCK_METHOD1(OnStopWaitingFrame, void(const QuicStopWaitingFrame&)); |
| 1006 | |
| 1007 | MOCK_METHOD1(OnRstStreamFrame, void(const QuicRstStreamFrame&)); |
| 1008 | |
| 1009 | MOCK_METHOD1(OnConnectionCloseFrame, void(const QuicConnectionCloseFrame&)); |
| 1010 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1011 | MOCK_METHOD1(OnStopSendingFrame, void(const QuicStopSendingFrame&)); |
| 1012 | |
| 1013 | MOCK_METHOD1(OnPathChallengeFrame, void(const QuicPathChallengeFrame&)); |
| 1014 | |
| 1015 | MOCK_METHOD1(OnPathResponseFrame, void(const QuicPathResponseFrame&)); |
| 1016 | |
| 1017 | MOCK_METHOD1(OnPublicResetPacket, void(const QuicPublicResetPacket&)); |
| 1018 | |
| 1019 | MOCK_METHOD1(OnVersionNegotiationPacket, |
| 1020 | void(const QuicVersionNegotiationPacket&)); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame^] | 1021 | |
| 1022 | MOCK_METHOD3(OnRetryPacket, |
| 1023 | void(QuicConnectionId, QuicConnectionId, QuicStringPiece)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | class MockReceivedPacketManager : public QuicReceivedPacketManager { |
| 1027 | public: |
| 1028 | explicit MockReceivedPacketManager(QuicConnectionStats* stats); |
| 1029 | ~MockReceivedPacketManager() override; |
| 1030 | |
| 1031 | MOCK_METHOD2(RecordPacketReceived, |
| 1032 | void(const QuicPacketHeader& header, QuicTime receipt_time)); |
| 1033 | MOCK_METHOD1(IsMissing, bool(QuicPacketNumber packet_number)); |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 1034 | MOCK_CONST_METHOD1(IsAwaitingPacket, bool(QuicPacketNumber packet_number)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1035 | MOCK_METHOD1(UpdatePacketInformationSentByPeer, |
| 1036 | void(const QuicStopWaitingFrame& stop_waiting)); |
| 1037 | MOCK_CONST_METHOD0(HasNewMissingPackets, bool(void)); |
| 1038 | MOCK_CONST_METHOD0(ack_frame_updated, bool(void)); |
| 1039 | }; |
| 1040 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1041 | class MockPacketCreatorDelegate : public QuicPacketCreator::DelegateInterface { |
| 1042 | public: |
| 1043 | MockPacketCreatorDelegate(); |
| 1044 | MockPacketCreatorDelegate(const MockPacketCreatorDelegate&) = delete; |
| 1045 | MockPacketCreatorDelegate& operator=(const MockPacketCreatorDelegate&) = |
| 1046 | delete; |
| 1047 | ~MockPacketCreatorDelegate() override; |
| 1048 | |
| 1049 | MOCK_METHOD0(GetPacketBuffer, char*()); |
| 1050 | MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); |
| 1051 | MOCK_METHOD3(OnUnrecoverableError, |
| 1052 | void(QuicErrorCode, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1053 | const std::string&, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1054 | ConnectionCloseSource source)); |
| 1055 | }; |
| 1056 | |
| 1057 | class MockSessionNotifier : public SessionNotifierInterface { |
| 1058 | public: |
| 1059 | MockSessionNotifier(); |
| 1060 | ~MockSessionNotifier() override; |
| 1061 | |
| 1062 | MOCK_METHOD2(OnFrameAcked, bool(const QuicFrame&, QuicTime::Delta)); |
| 1063 | MOCK_METHOD1(OnStreamFrameRetransmitted, void(const QuicStreamFrame&)); |
| 1064 | MOCK_METHOD1(OnFrameLost, void(const QuicFrame&)); |
| 1065 | MOCK_METHOD2(RetransmitFrames, |
| 1066 | void(const QuicFrames&, TransmissionType type)); |
| 1067 | MOCK_CONST_METHOD1(IsFrameOutstanding, bool(const QuicFrame&)); |
| 1068 | MOCK_CONST_METHOD0(HasUnackedCryptoData, bool()); |
| 1069 | }; |
| 1070 | |
| 1071 | // Creates a client session for testing. |
| 1072 | // |
| 1073 | // server_id: The server id associated with this stream. |
| 1074 | // supports_stateless_rejects: Does this client support stateless rejects. |
| 1075 | // connection_start_time: The time to set for the connection clock. |
| 1076 | // Needed for strike-register nonce verification. The client |
| 1077 | // connection_start_time should be synchronized witht the server |
| 1078 | // start time, otherwise nonce verification will fail. |
| 1079 | // supported_versions: Set of QUIC versions this client supports. |
| 1080 | // helper: Pointer to the MockQuicConnectionHelper to use for the session. |
| 1081 | // crypto_client_config: Pointer to the crypto client config. |
| 1082 | // client_connection: Pointer reference for newly created |
| 1083 | // connection. This object will be owned by the |
| 1084 | // client_session. |
| 1085 | // client_session: Pointer reference for the newly created client |
| 1086 | // session. The new object will be owned by the caller. |
| 1087 | void CreateClientSessionForTest( |
| 1088 | QuicServerId server_id, |
| 1089 | bool supports_stateless_rejects, |
| 1090 | QuicTime::Delta connection_start_time, |
| 1091 | const ParsedQuicVersionVector& supported_versions, |
| 1092 | MockQuicConnectionHelper* helper, |
| 1093 | MockAlarmFactory* alarm_factory, |
| 1094 | QuicCryptoClientConfig* crypto_client_config, |
| 1095 | PacketSavingConnection** client_connection, |
| 1096 | TestQuicSpdyClientSession** client_session); |
| 1097 | |
| 1098 | // Creates a server session for testing. |
| 1099 | // |
| 1100 | // server_id: The server id associated with this stream. |
| 1101 | // connection_start_time: The time to set for the connection clock. |
| 1102 | // Needed for strike-register nonce verification. The server |
| 1103 | // connection_start_time should be synchronized witht the client |
| 1104 | // start time, otherwise nonce verification will fail. |
| 1105 | // supported_versions: Set of QUIC versions this server supports. |
| 1106 | // helper: Pointer to the MockQuicConnectionHelper to use for the session. |
| 1107 | // crypto_server_config: Pointer to the crypto server config. |
| 1108 | // server_connection: Pointer reference for newly created |
| 1109 | // connection. This object will be owned by the |
| 1110 | // server_session. |
| 1111 | // server_session: Pointer reference for the newly created server |
| 1112 | // session. The new object will be owned by the caller. |
| 1113 | void CreateServerSessionForTest( |
| 1114 | QuicServerId server_id, |
| 1115 | QuicTime::Delta connection_start_time, |
| 1116 | ParsedQuicVersionVector supported_versions, |
| 1117 | MockQuicConnectionHelper* helper, |
| 1118 | MockAlarmFactory* alarm_factory, |
| 1119 | QuicCryptoServerConfig* crypto_server_config, |
| 1120 | QuicCompressedCertsCache* compressed_certs_cache, |
| 1121 | PacketSavingConnection** server_connection, |
| 1122 | TestQuicSpdyServerSession** server_session); |
| 1123 | |
| 1124 | // Verifies that the relative error of |actual| with respect to |expected| is |
| 1125 | // no more than |margin|. |
wub | 9343d70 | 2019-05-02 17:12:56 -0700 | [diff] [blame] | 1126 | // Please use EXPECT_APPROX_EQ, a wrapper around this function, for better error |
| 1127 | // report. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1128 | template <typename T> |
| 1129 | void ExpectApproxEq(T expected, T actual, float relative_margin) { |
| 1130 | // If |relative_margin| > 1 and T is an unsigned type, the comparison will |
| 1131 | // underflow. |
| 1132 | ASSERT_LE(relative_margin, 1); |
| 1133 | ASSERT_GE(relative_margin, 0); |
| 1134 | |
| 1135 | T absolute_margin = expected * relative_margin; |
| 1136 | |
wub | 9343d70 | 2019-05-02 17:12:56 -0700 | [diff] [blame] | 1137 | EXPECT_GE(expected + absolute_margin, actual) << "actual value too big"; |
| 1138 | EXPECT_LE(expected - absolute_margin, actual) << "actual value too small"; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1139 | } |
| 1140 | |
wub | 9343d70 | 2019-05-02 17:12:56 -0700 | [diff] [blame] | 1141 | #define EXPECT_APPROX_EQ(expected, actual, relative_margin) \ |
| 1142 | do { \ |
| 1143 | SCOPED_TRACE(testing::Message() << "relative_margin:" << relative_margin); \ |
| 1144 | quic::test::ExpectApproxEq(expected, actual, relative_margin); \ |
| 1145 | } while (0) |
| 1146 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1147 | template <typename T> |
| 1148 | QuicHeaderList AsHeaderList(const T& container) { |
| 1149 | QuicHeaderList l; |
| 1150 | // No need to enforce header list size limits again in this handler. |
| 1151 | l.set_max_header_list_size(UINT_MAX); |
| 1152 | l.OnHeaderBlockStart(); |
| 1153 | size_t total_size = 0; |
| 1154 | for (auto p : container) { |
| 1155 | total_size += p.first.size() + p.second.size(); |
| 1156 | l.OnHeader(p.first, p.second); |
| 1157 | } |
| 1158 | l.OnHeaderBlockEnd(total_size, total_size); |
| 1159 | return l; |
| 1160 | } |
| 1161 | |
| 1162 | // Utility function that stores |str|'s data in |iov|. |
| 1163 | inline void MakeIOVector(QuicStringPiece str, struct iovec* iov) { |
| 1164 | iov->iov_base = const_cast<char*>(str.data()); |
| 1165 | iov->iov_len = static_cast<size_t>(str.size()); |
| 1166 | } |
| 1167 | |
| 1168 | // Helper functions for stream ids, to allow test logic to abstract over the |
| 1169 | // HTTP stream numbering scheme (i.e. whether one or two QUIC streams are used |
| 1170 | // per HTTP transaction). |
| 1171 | QuicStreamId GetNthClientInitiatedBidirectionalStreamId( |
| 1172 | QuicTransportVersion version, |
| 1173 | int n); |
| 1174 | QuicStreamId GetNthServerInitiatedBidirectionalStreamId( |
| 1175 | QuicTransportVersion version, |
| 1176 | int n); |
| 1177 | QuicStreamId GetNthServerInitiatedUnidirectionalStreamId( |
| 1178 | QuicTransportVersion version, |
| 1179 | int n); |
| 1180 | |
| 1181 | StreamType DetermineStreamType(QuicStreamId id, |
| 1182 | QuicTransportVersion version, |
| 1183 | Perspective perspective, |
| 1184 | bool is_incoming, |
| 1185 | StreamType default_type); |
| 1186 | |
| 1187 | // Utility function that stores message_data in |storage| and returns a |
| 1188 | // QuicMemSliceSpan. |
| 1189 | QuicMemSliceSpan MakeSpan(QuicBufferAllocator* allocator, |
| 1190 | QuicStringPiece message_data, |
| 1191 | QuicMemSliceStorage* storage); |
| 1192 | |
| 1193 | } // namespace test |
| 1194 | } // namespace quic |
| 1195 | |
| 1196 | #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ |