| OLD | NEW |
| (Empty) |
| 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 NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | |
| 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/strings/string_piece.h" | |
| 15 #include "net/quic/congestion_control/loss_detection_interface.h" | |
| 16 #include "net/quic/congestion_control/send_algorithm_interface.h" | |
| 17 #include "net/quic/quic_ack_notifier.h" | |
| 18 #include "net/quic/quic_client_session_base.h" | |
| 19 #include "net/quic/quic_connection.h" | |
| 20 #include "net/quic/quic_dispatcher.h" | |
| 21 #include "net/quic/quic_framer.h" | |
| 22 #include "net/quic/quic_per_connection_packet_writer.h" | |
| 23 #include "net/quic/quic_sent_packet_manager.h" | |
| 24 #include "net/quic/quic_session.h" | |
| 25 #include "net/quic/test_tools/mock_clock.h" | |
| 26 #include "net/quic/test_tools/mock_random.h" | |
| 27 #include "net/spdy/spdy_framer.h" | |
| 28 #include "testing/gmock/include/gmock/gmock.h" | |
| 29 | |
| 30 namespace net { | |
| 31 | |
| 32 namespace test { | |
| 33 | |
| 34 static const QuicConnectionId kTestConnectionId = 42; | |
| 35 static const uint16 kTestPort = 123; | |
| 36 static const uint32 kInitialStreamFlowControlWindowForTest = | |
| 37 32 * 1024; // 32 KB | |
| 38 static const uint32 kInitialSessionFlowControlWindowForTest = | |
| 39 64 * 1024; // 64 KB | |
| 40 | |
| 41 // Data stream IDs start at 5: the crypto stream is 1, headers stream is 3. | |
| 42 static const QuicStreamId kClientDataStreamId1 = 5; | |
| 43 static const QuicStreamId kClientDataStreamId2 = 7; | |
| 44 static const QuicStreamId kClientDataStreamId3 = 9; | |
| 45 static const QuicStreamId kClientDataStreamId4 = 11; | |
| 46 | |
| 47 // Returns the test peer IP address. | |
| 48 IPAddressNumber TestPeerIPAddress(); | |
| 49 | |
| 50 // Upper limit on versions we support. | |
| 51 QuicVersion QuicVersionMax(); | |
| 52 | |
| 53 // Lower limit on versions we support. | |
| 54 QuicVersion QuicVersionMin(); | |
| 55 | |
| 56 // Returns an address for 127.0.0.1. | |
| 57 IPAddressNumber Loopback4(); | |
| 58 | |
| 59 // Returns an address for ::1. | |
| 60 IPAddressNumber Loopback6(); | |
| 61 | |
| 62 void GenerateBody(std::string* body, int length); | |
| 63 | |
| 64 // Create an encrypted packet for testing. | |
| 65 QuicEncryptedPacket* ConstructEncryptedPacket( | |
| 66 QuicConnectionId connection_id, | |
| 67 bool version_flag, | |
| 68 bool reset_flag, | |
| 69 QuicPacketSequenceNumber sequence_number, | |
| 70 const std::string& data); | |
| 71 | |
| 72 void CompareCharArraysWithHexError(const std::string& description, | |
| 73 const char* actual, | |
| 74 const int actual_len, | |
| 75 const char* expected, | |
| 76 const int expected_len); | |
| 77 | |
| 78 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes); | |
| 79 | |
| 80 // Returns the length of a QuicPacket that is capable of holding either a | |
| 81 // stream frame or a minimal ack frame. Sets |*payload_length| to the number | |
| 82 // of bytes of stream data that will fit in such a packet. | |
| 83 size_t GetPacketLengthForOneStream( | |
| 84 QuicVersion version, | |
| 85 bool include_version, | |
| 86 QuicConnectionIdLength connection_id_length, | |
| 87 QuicSequenceNumberLength sequence_number_length, | |
| 88 InFecGroup is_in_fec_group, | |
| 89 size_t* payload_length); | |
| 90 | |
| 91 // Returns QuicConfig set to default values. | |
| 92 QuicConfig DefaultQuicConfig(); | |
| 93 | |
| 94 // Returns a version vector consisting of |version|. | |
| 95 QuicVersionVector SupportedVersions(QuicVersion version); | |
| 96 | |
| 97 // Testing convenience method to construct a QuicAckFrame with entropy_hash set | |
| 98 // to 0 and largest_observed from peer set to |largest_observed|. | |
| 99 QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed); | |
| 100 | |
| 101 // Testing convenience method to construct a QuicAckFrame with |num_nack_ranges| | |
| 102 // nack ranges of width 1 packet, starting from |least_unacked|. | |
| 103 QuicAckFrame MakeAckFrameWithNackRanges(size_t num_nack_ranges, | |
| 104 QuicPacketSequenceNumber least_unacked); | |
| 105 | |
| 106 // Returns a QuicPacket that is owned by the caller, and | |
| 107 // is populated with the fields in |header| and |frames|, or is nullptr if the | |
| 108 // packet could not be created. | |
| 109 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | |
| 110 const QuicPacketHeader& header, | |
| 111 const QuicFrames& frames); | |
| 112 // Returns a QuicPacket that is owned by the caller, and of size |packet_size|. | |
| 113 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | |
| 114 const QuicPacketHeader& header, | |
| 115 const QuicFrames& frames, | |
| 116 size_t packet_size); | |
| 117 | |
| 118 template<typename SaveType> | |
| 119 class ValueRestore { | |
| 120 public: | |
| 121 ValueRestore(SaveType* name, SaveType value) | |
| 122 : name_(name), | |
| 123 value_(*name) { | |
| 124 *name_ = value; | |
| 125 } | |
| 126 ~ValueRestore() { | |
| 127 *name_ = value_; | |
| 128 } | |
| 129 | |
| 130 private: | |
| 131 SaveType* name_; | |
| 132 SaveType value_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(ValueRestore); | |
| 135 }; | |
| 136 | |
| 137 // Simple random number generator used to compute random numbers suitable | |
| 138 // for pseudo-randomly dropping packets in tests. It works by computing | |
| 139 // the sha1 hash of the current seed, and using the first 64 bits as | |
| 140 // the next random number, and the next seed. | |
| 141 class SimpleRandom { | |
| 142 public: | |
| 143 SimpleRandom() : seed_(0) {} | |
| 144 | |
| 145 // Returns a random number in the range [0, kuint64max]. | |
| 146 uint64 RandUint64(); | |
| 147 | |
| 148 void set_seed(uint64 seed) { seed_ = seed; } | |
| 149 | |
| 150 private: | |
| 151 uint64 seed_; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(SimpleRandom); | |
| 154 }; | |
| 155 | |
| 156 class MockFramerVisitor : public QuicFramerVisitorInterface { | |
| 157 public: | |
| 158 MockFramerVisitor(); | |
| 159 ~MockFramerVisitor() override; | |
| 160 | |
| 161 MOCK_METHOD1(OnError, void(QuicFramer* framer)); | |
| 162 // The constructor sets this up to return false by default. | |
| 163 MOCK_METHOD1(OnProtocolVersionMismatch, bool(QuicVersion version)); | |
| 164 MOCK_METHOD0(OnPacket, void()); | |
| 165 MOCK_METHOD1(OnPublicResetPacket, void(const QuicPublicResetPacket& header)); | |
| 166 MOCK_METHOD1(OnVersionNegotiationPacket, | |
| 167 void(const QuicVersionNegotiationPacket& packet)); | |
| 168 MOCK_METHOD0(OnRevivedPacket, void()); | |
| 169 // The constructor sets this up to return true by default. | |
| 170 MOCK_METHOD1(OnUnauthenticatedHeader, bool(const QuicPacketHeader& header)); | |
| 171 // The constructor sets this up to return true by default. | |
| 172 MOCK_METHOD1(OnUnauthenticatedPublicHeader, bool( | |
| 173 const QuicPacketPublicHeader& header)); | |
| 174 MOCK_METHOD1(OnDecryptedPacket, void(EncryptionLevel level)); | |
| 175 MOCK_METHOD1(OnPacketHeader, bool(const QuicPacketHeader& header)); | |
| 176 MOCK_METHOD1(OnFecProtectedPayload, void(base::StringPiece payload)); | |
| 177 MOCK_METHOD1(OnStreamFrame, bool(const QuicStreamFrame& frame)); | |
| 178 MOCK_METHOD1(OnAckFrame, bool(const QuicAckFrame& frame)); | |
| 179 MOCK_METHOD1(OnStopWaitingFrame, bool(const QuicStopWaitingFrame& frame)); | |
| 180 MOCK_METHOD1(OnPingFrame, bool(const QuicPingFrame& frame)); | |
| 181 MOCK_METHOD1(OnFecData, void(const QuicFecData& fec)); | |
| 182 MOCK_METHOD1(OnRstStreamFrame, bool(const QuicRstStreamFrame& frame)); | |
| 183 MOCK_METHOD1(OnConnectionCloseFrame, | |
| 184 bool(const QuicConnectionCloseFrame& frame)); | |
| 185 MOCK_METHOD1(OnGoAwayFrame, bool(const QuicGoAwayFrame& frame)); | |
| 186 MOCK_METHOD1(OnWindowUpdateFrame, bool(const QuicWindowUpdateFrame& frame)); | |
| 187 MOCK_METHOD1(OnBlockedFrame, bool(const QuicBlockedFrame& frame)); | |
| 188 MOCK_METHOD0(OnPacketComplete, void()); | |
| 189 | |
| 190 private: | |
| 191 DISALLOW_COPY_AND_ASSIGN(MockFramerVisitor); | |
| 192 }; | |
| 193 | |
| 194 class NoOpFramerVisitor : public QuicFramerVisitorInterface { | |
| 195 public: | |
| 196 NoOpFramerVisitor() {} | |
| 197 | |
| 198 void OnError(QuicFramer* framer) override {} | |
| 199 void OnPacket() override {} | |
| 200 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {} | |
| 201 void OnVersionNegotiationPacket( | |
| 202 const QuicVersionNegotiationPacket& packet) override {} | |
| 203 void OnRevivedPacket() override {} | |
| 204 bool OnProtocolVersionMismatch(QuicVersion version) override; | |
| 205 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; | |
| 206 bool OnUnauthenticatedPublicHeader( | |
| 207 const QuicPacketPublicHeader& header) override; | |
| 208 void OnDecryptedPacket(EncryptionLevel level) override {} | |
| 209 bool OnPacketHeader(const QuicPacketHeader& header) override; | |
| 210 void OnFecProtectedPayload(base::StringPiece payload) override {} | |
| 211 bool OnStreamFrame(const QuicStreamFrame& frame) override; | |
| 212 bool OnAckFrame(const QuicAckFrame& frame) override; | |
| 213 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; | |
| 214 bool OnPingFrame(const QuicPingFrame& frame) override; | |
| 215 void OnFecData(const QuicFecData& fec) override {} | |
| 216 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; | |
| 217 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; | |
| 218 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; | |
| 219 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | |
| 220 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; | |
| 221 void OnPacketComplete() override {} | |
| 222 | |
| 223 private: | |
| 224 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor); | |
| 225 }; | |
| 226 | |
| 227 class MockConnectionVisitor : public QuicConnectionVisitorInterface { | |
| 228 public: | |
| 229 MockConnectionVisitor(); | |
| 230 ~MockConnectionVisitor() override; | |
| 231 | |
| 232 MOCK_METHOD1(OnStreamFrames, void(const std::vector<QuicStreamFrame>& frame)); | |
| 233 MOCK_METHOD1(OnWindowUpdateFrames, | |
| 234 void(const std::vector<QuicWindowUpdateFrame>& frame)); | |
| 235 MOCK_METHOD1(OnBlockedFrames, | |
| 236 void(const std::vector<QuicBlockedFrame>& frame)); | |
| 237 MOCK_METHOD1(OnRstStream, void(const QuicRstStreamFrame& frame)); | |
| 238 MOCK_METHOD1(OnGoAway, void(const QuicGoAwayFrame& frame)); | |
| 239 MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer)); | |
| 240 MOCK_METHOD0(OnWriteBlocked, void()); | |
| 241 MOCK_METHOD0(OnCanWrite, void()); | |
| 242 MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now)); | |
| 243 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool()); | |
| 244 MOCK_CONST_METHOD0(HasPendingHandshake, bool()); | |
| 245 MOCK_CONST_METHOD0(HasOpenDataStreams, bool()); | |
| 246 MOCK_METHOD1(OnSuccessfulVersionNegotiation, | |
| 247 void(const QuicVersion& version)); | |
| 248 MOCK_METHOD0(OnConfigNegotiated, void()); | |
| 249 | |
| 250 private: | |
| 251 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor); | |
| 252 }; | |
| 253 | |
| 254 class MockHelper : public QuicConnectionHelperInterface { | |
| 255 public: | |
| 256 MockHelper(); | |
| 257 ~MockHelper() override; | |
| 258 const QuicClock* GetClock() const override; | |
| 259 QuicRandom* GetRandomGenerator() override; | |
| 260 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; | |
| 261 void AdvanceTime(QuicTime::Delta delta); | |
| 262 | |
| 263 private: | |
| 264 MockClock clock_; | |
| 265 MockRandom random_generator_; | |
| 266 | |
| 267 DISALLOW_COPY_AND_ASSIGN(MockHelper); | |
| 268 }; | |
| 269 | |
| 270 class NiceMockPacketWriterFactory : public QuicConnection::PacketWriterFactory { | |
| 271 public: | |
| 272 NiceMockPacketWriterFactory() {} | |
| 273 ~NiceMockPacketWriterFactory() override {} | |
| 274 | |
| 275 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override; | |
| 276 | |
| 277 private: | |
| 278 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory); | |
| 279 }; | |
| 280 | |
| 281 class MockConnection : public QuicConnection { | |
| 282 public: | |
| 283 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123. | |
| 284 explicit MockConnection(bool is_server); | |
| 285 | |
| 286 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123. | |
| 287 MockConnection(bool is_server, bool is_secure); | |
| 288 | |
| 289 // Uses a MockHelper, ConnectionId of 42. | |
| 290 MockConnection(IPEndPoint address, bool is_server); | |
| 291 | |
| 292 // Uses a MockHelper, and 127.0.0.1:123 | |
| 293 MockConnection(QuicConnectionId connection_id, bool is_server); | |
| 294 | |
| 295 // Uses a Mock helper, ConnectionId of 42, and 127.0.0.1:123. | |
| 296 MockConnection(bool is_server, const QuicVersionVector& supported_versions); | |
| 297 | |
| 298 ~MockConnection() override; | |
| 299 | |
| 300 // If the constructor that uses a MockHelper has been used then this method | |
| 301 // will advance the time of the MockClock. | |
| 302 void AdvanceTime(QuicTime::Delta delta); | |
| 303 | |
| 304 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address, | |
| 305 const IPEndPoint& peer_address, | |
| 306 const QuicEncryptedPacket& packet)); | |
| 307 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error)); | |
| 308 MOCK_METHOD2(SendConnectionCloseWithDetails, | |
| 309 void(QuicErrorCode error, const std::string& details)); | |
| 310 MOCK_METHOD2(SendConnectionClosePacket, | |
| 311 void(QuicErrorCode error, const std::string& details)); | |
| 312 MOCK_METHOD3(SendRstStream, void(QuicStreamId id, | |
| 313 QuicRstStreamErrorCode error, | |
| 314 QuicStreamOffset bytes_written)); | |
| 315 MOCK_METHOD3(SendGoAway, | |
| 316 void(QuicErrorCode error, | |
| 317 QuicStreamId last_good_stream_id, | |
| 318 const std::string& reason)); | |
| 319 MOCK_METHOD1(SendBlocked, void(QuicStreamId id)); | |
| 320 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id, | |
| 321 QuicStreamOffset byte_offset)); | |
| 322 MOCK_METHOD0(OnCanWrite, void()); | |
| 323 | |
| 324 MOCK_METHOD1(ResumeConnectionState, bool(const CachedNetworkParameters&)); | |
| 325 | |
| 326 void ProcessUdpPacketInternal(const IPEndPoint& self_address, | |
| 327 const IPEndPoint& peer_address, | |
| 328 const QuicEncryptedPacket& packet) { | |
| 329 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet); | |
| 330 } | |
| 331 | |
| 332 bool OnProtocolVersionMismatch(QuicVersion version) override { | |
| 333 return false; | |
| 334 } | |
| 335 | |
| 336 private: | |
| 337 scoped_ptr<QuicConnectionHelperInterface> helper_; | |
| 338 | |
| 339 DISALLOW_COPY_AND_ASSIGN(MockConnection); | |
| 340 }; | |
| 341 | |
| 342 class PacketSavingConnection : public MockConnection { | |
| 343 public: | |
| 344 explicit PacketSavingConnection(bool is_server); | |
| 345 | |
| 346 PacketSavingConnection(bool is_server, | |
| 347 const QuicVersionVector& supported_versions); | |
| 348 | |
| 349 ~PacketSavingConnection() override; | |
| 350 | |
| 351 void SendOrQueuePacket(QueuedPacket packet) override; | |
| 352 | |
| 353 std::vector<QuicEncryptedPacket*> encrypted_packets_; | |
| 354 | |
| 355 private: | |
| 356 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection); | |
| 357 }; | |
| 358 | |
| 359 class MockSession : public QuicSession { | |
| 360 public: | |
| 361 explicit MockSession(QuicConnection* connection); | |
| 362 ~MockSession() override; | |
| 363 MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer)); | |
| 364 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); | |
| 365 MOCK_METHOD0(GetCryptoStream, QuicCryptoStream*()); | |
| 366 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); | |
| 367 MOCK_METHOD6(WritevData, | |
| 368 QuicConsumedData(QuicStreamId id, | |
| 369 const IOVector& data, | |
| 370 QuicStreamOffset offset, | |
| 371 bool fin, | |
| 372 FecProtection fec_protection, | |
| 373 QuicAckNotifier::DelegateInterface*)); | |
| 374 MOCK_METHOD2(OnStreamHeaders, void(QuicStreamId stream_id, | |
| 375 base::StringPiece headers_data)); | |
| 376 MOCK_METHOD2(OnStreamHeadersPriority, void(QuicStreamId stream_id, | |
| 377 QuicPriority priority)); | |
| 378 MOCK_METHOD3(OnStreamHeadersComplete, void(QuicStreamId stream_id, | |
| 379 bool fin, | |
| 380 size_t frame_len)); | |
| 381 MOCK_METHOD3(SendRstStream, void(QuicStreamId stream_id, | |
| 382 QuicRstStreamErrorCode error, | |
| 383 QuicStreamOffset bytes_written)); | |
| 384 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); | |
| 385 | |
| 386 using QuicSession::ActivateStream; | |
| 387 | |
| 388 private: | |
| 389 DISALLOW_COPY_AND_ASSIGN(MockSession); | |
| 390 }; | |
| 391 | |
| 392 class TestSession : public QuicSession { | |
| 393 public: | |
| 394 TestSession(QuicConnection* connection, const QuicConfig& config); | |
| 395 ~TestSession() override; | |
| 396 | |
| 397 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); | |
| 398 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); | |
| 399 | |
| 400 void SetCryptoStream(QuicCryptoStream* stream); | |
| 401 | |
| 402 QuicCryptoStream* GetCryptoStream() override; | |
| 403 | |
| 404 private: | |
| 405 QuicCryptoStream* crypto_stream_; | |
| 406 | |
| 407 DISALLOW_COPY_AND_ASSIGN(TestSession); | |
| 408 }; | |
| 409 | |
| 410 class TestClientSession : public QuicClientSessionBase { | |
| 411 public: | |
| 412 TestClientSession(QuicConnection* connection, const QuicConfig& config); | |
| 413 ~TestClientSession() override; | |
| 414 | |
| 415 // QuicClientSessionBase | |
| 416 MOCK_METHOD1(OnProofValid, | |
| 417 void(const QuicCryptoClientConfig::CachedState& cached)); | |
| 418 MOCK_METHOD1(OnProofVerifyDetailsAvailable, | |
| 419 void(const ProofVerifyDetails& verify_details)); | |
| 420 | |
| 421 // TestClientSession | |
| 422 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id)); | |
| 423 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*()); | |
| 424 | |
| 425 void SetCryptoStream(QuicCryptoStream* stream); | |
| 426 | |
| 427 QuicCryptoStream* GetCryptoStream() override; | |
| 428 | |
| 429 private: | |
| 430 QuicCryptoStream* crypto_stream_; | |
| 431 | |
| 432 DISALLOW_COPY_AND_ASSIGN(TestClientSession); | |
| 433 }; | |
| 434 | |
| 435 class MockPacketWriter : public QuicPacketWriter { | |
| 436 public: | |
| 437 MockPacketWriter(); | |
| 438 ~MockPacketWriter() override; | |
| 439 | |
| 440 MOCK_METHOD4(WritePacket, | |
| 441 WriteResult(const char* buffer, | |
| 442 size_t buf_len, | |
| 443 const IPAddressNumber& self_address, | |
| 444 const IPEndPoint& peer_address)); | |
| 445 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool()); | |
| 446 MOCK_CONST_METHOD0(IsWriteBlocked, bool()); | |
| 447 MOCK_METHOD0(SetWritable, void()); | |
| 448 | |
| 449 private: | |
| 450 DISALLOW_COPY_AND_ASSIGN(MockPacketWriter); | |
| 451 }; | |
| 452 | |
| 453 class MockSendAlgorithm : public SendAlgorithmInterface { | |
| 454 public: | |
| 455 MockSendAlgorithm(); | |
| 456 ~MockSendAlgorithm() override; | |
| 457 | |
| 458 MOCK_METHOD3(SetFromConfig, void(const QuicConfig& config, | |
| 459 bool is_server, | |
| 460 bool using_pacing)); | |
| 461 MOCK_METHOD1(SetNumEmulatedConnections, void(int num_connections)); | |
| 462 MOCK_METHOD1(SetMaxPacketSize, void(QuicByteCount max_packet_size)); | |
| 463 MOCK_METHOD4(OnCongestionEvent, void(bool rtt_updated, | |
| 464 QuicByteCount bytes_in_flight, | |
| 465 const CongestionVector& acked_packets, | |
| 466 const CongestionVector& lost_packets)); | |
| 467 MOCK_METHOD5(OnPacketSent, | |
| 468 bool(QuicTime, QuicByteCount, QuicPacketSequenceNumber, | |
| 469 QuicByteCount, HasRetransmittableData)); | |
| 470 MOCK_METHOD1(OnRetransmissionTimeout, void(bool)); | |
| 471 MOCK_METHOD0(RevertRetransmissionTimeout, void()); | |
| 472 MOCK_CONST_METHOD3(TimeUntilSend, | |
| 473 QuicTime::Delta(QuicTime now, | |
| 474 QuicByteCount bytes_in_flight, | |
| 475 HasRetransmittableData)); | |
| 476 MOCK_CONST_METHOD0(PacingRate, QuicBandwidth(void)); | |
| 477 MOCK_CONST_METHOD0(BandwidthEstimate, QuicBandwidth(void)); | |
| 478 MOCK_CONST_METHOD0(HasReliableBandwidthEstimate, bool()); | |
| 479 MOCK_METHOD1(OnRttUpdated, void(QuicPacketSequenceNumber)); | |
| 480 MOCK_CONST_METHOD0(RetransmissionDelay, QuicTime::Delta(void)); | |
| 481 MOCK_CONST_METHOD0(GetCongestionWindow, QuicByteCount()); | |
| 482 MOCK_CONST_METHOD0(InSlowStart, bool()); | |
| 483 MOCK_CONST_METHOD0(InRecovery, bool()); | |
| 484 MOCK_CONST_METHOD0(GetSlowStartThreshold, QuicByteCount()); | |
| 485 MOCK_CONST_METHOD0(GetCongestionControlType, CongestionControlType()); | |
| 486 MOCK_METHOD1(ResumeConnectionState, bool(const CachedNetworkParameters&)); | |
| 487 | |
| 488 private: | |
| 489 DISALLOW_COPY_AND_ASSIGN(MockSendAlgorithm); | |
| 490 }; | |
| 491 | |
| 492 class MockLossAlgorithm : public LossDetectionInterface { | |
| 493 public: | |
| 494 MockLossAlgorithm(); | |
| 495 ~MockLossAlgorithm() override; | |
| 496 | |
| 497 MOCK_CONST_METHOD0(GetLossDetectionType, LossDetectionType()); | |
| 498 MOCK_METHOD4(DetectLostPackets, | |
| 499 SequenceNumberSet(const QuicUnackedPacketMap& unacked_packets, | |
| 500 const QuicTime& time, | |
| 501 QuicPacketSequenceNumber largest_observed, | |
| 502 const RttStats& rtt_stats)); | |
| 503 MOCK_CONST_METHOD0(GetLossTimeout, QuicTime()); | |
| 504 | |
| 505 private: | |
| 506 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm); | |
| 507 }; | |
| 508 | |
| 509 class TestEntropyCalculator : | |
| 510 public QuicReceivedEntropyHashCalculatorInterface { | |
| 511 public: | |
| 512 TestEntropyCalculator(); | |
| 513 ~TestEntropyCalculator() override; | |
| 514 | |
| 515 QuicPacketEntropyHash EntropyHash( | |
| 516 QuicPacketSequenceNumber sequence_number) const override; | |
| 517 | |
| 518 private: | |
| 519 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator); | |
| 520 }; | |
| 521 | |
| 522 class MockEntropyCalculator : public TestEntropyCalculator { | |
| 523 public: | |
| 524 MockEntropyCalculator(); | |
| 525 ~MockEntropyCalculator() override; | |
| 526 | |
| 527 MOCK_CONST_METHOD1( | |
| 528 EntropyHash, | |
| 529 QuicPacketEntropyHash(QuicPacketSequenceNumber sequence_number)); | |
| 530 | |
| 531 private: | |
| 532 DISALLOW_COPY_AND_ASSIGN(MockEntropyCalculator); | |
| 533 }; | |
| 534 | |
| 535 class MockAckNotifierDelegate : public QuicAckNotifier::DelegateInterface { | |
| 536 public: | |
| 537 MockAckNotifierDelegate(); | |
| 538 | |
| 539 MOCK_METHOD3(OnAckNotification, | |
| 540 void(int num_retransmitted_packets, | |
| 541 int num_retransmitted_bytes, | |
| 542 QuicTime::Delta delta_largest_observed)); | |
| 543 | |
| 544 protected: | |
| 545 // Object is ref counted. | |
| 546 ~MockAckNotifierDelegate() override; | |
| 547 | |
| 548 private: | |
| 549 DISALLOW_COPY_AND_ASSIGN(MockAckNotifierDelegate); | |
| 550 }; | |
| 551 | |
| 552 class MockNetworkChangeVisitor : | |
| 553 public QuicSentPacketManager::NetworkChangeVisitor { | |
| 554 public: | |
| 555 MockNetworkChangeVisitor(); | |
| 556 ~MockNetworkChangeVisitor() override; | |
| 557 | |
| 558 MOCK_METHOD0(OnCongestionWindowChange, void()); | |
| 559 MOCK_METHOD0(OnRttChange, void()); | |
| 560 | |
| 561 private: | |
| 562 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); | |
| 563 }; | |
| 564 | |
| 565 // Creates per-connection packet writers that register themselves with the | |
| 566 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can | |
| 567 // be routed to the appropriate QuicConnection. | |
| 568 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory { | |
| 569 public: | |
| 570 TestWriterFactory(); | |
| 571 ~TestWriterFactory() override; | |
| 572 | |
| 573 QuicPacketWriter* Create(QuicServerPacketWriter* writer, | |
| 574 QuicConnection* connection) override; | |
| 575 | |
| 576 // Calls OnPacketSent on the last QuicConnection to write through one of the | |
| 577 // packet writers created by this factory. | |
| 578 void OnPacketSent(WriteResult result); | |
| 579 | |
| 580 private: | |
| 581 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter { | |
| 582 public: | |
| 583 PerConnectionPacketWriter(TestWriterFactory* factory, | |
| 584 QuicServerPacketWriter* writer, | |
| 585 QuicConnection* connection); | |
| 586 ~PerConnectionPacketWriter() override; | |
| 587 | |
| 588 WriteResult WritePacket(const char* buffer, | |
| 589 size_t buf_len, | |
| 590 const IPAddressNumber& self_address, | |
| 591 const IPEndPoint& peer_address) override; | |
| 592 | |
| 593 private: | |
| 594 TestWriterFactory* factory_; | |
| 595 }; | |
| 596 | |
| 597 // If an asynchronous write is happening and |writer| gets deleted, this | |
| 598 // clears the pointer to it to prevent use-after-free. | |
| 599 void Unregister(PerConnectionPacketWriter* writer); | |
| 600 | |
| 601 PerConnectionPacketWriter* current_writer_; | |
| 602 }; | |
| 603 | |
| 604 } // namespace test | |
| 605 } // namespace net | |
| 606 | |
| 607 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ | |
| OLD | NEW |