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