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.
5 // Common utilities for Quic tests
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
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_framer.h"
21 #include "net/quic/quic_protocol.h"
22 #include "net/quic/quic_sent_packet_manager.h"
23 #include "net/quic/quic_session.h"
24 #include "net/quic/test_tools/mock_clock.h"
25 #include "net/quic/test_tools/mock_random.h"
26 #include "net/spdy/spdy_framer.h"
27 #include "net/tools/quic/quic_dispatcher.h"
28 #include "net/tools/quic/quic_per_connection_packet_writer.h"
29 #include "testing/gmock/include/gmock/gmock.h"
35 static const QuicConnectionId kTestConnectionId
= 42;
36 static const uint16 kTestPort
= 123;
37 static const uint32 kInitialStreamFlowControlWindowForTest
=
39 static const uint32 kInitialSessionFlowControlWindowForTest
=
40 1536 * 1024; // 1.5 MB
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;
46 // Returns the test peer IP address.
47 IPAddressNumber
TestPeerIPAddress();
49 // Upper limit on versions we support.
50 QuicVersion
QuicVersionMax();
52 // Lower limit on versions we support.
53 QuicVersion
QuicVersionMin();
55 // Returns an address for 127.0.0.1.
56 IPAddressNumber
Loopback4();
58 // Returns an address for ::1.
59 IPAddressNumber
Loopback6();
61 void GenerateBody(std::string
* body
, int length
);
63 // Create an encrypted packet for testing.
64 QuicEncryptedPacket
* ConstructEncryptedPacket(
65 QuicConnectionId connection_id
,
68 QuicPacketSequenceNumber sequence_number
,
69 const std::string
& data
,
70 QuicConnectionIdLength connection_id_length
,
71 QuicSequenceNumberLength sequence_number_length
);
73 // This form assumes |connection_id_length| == PACKET_8BYTE_CONNECTION_ID and
74 // |sequence_number_length| == PACKET_6BYTE_SEQUENCE_NUMBER.
75 QuicEncryptedPacket
* ConstructEncryptedPacket(
76 QuicConnectionId connection_id
,
79 QuicPacketSequenceNumber sequence_number
,
80 const std::string
& data
);
82 void CompareCharArraysWithHexError(const std::string
& description
,
86 const int expected_len
);
88 bool DecodeHexString(const base::StringPiece
& hex
, std::string
* bytes
);
90 // Returns the length of a QuicPacket that is capable of holding either a
91 // stream frame or a minimal ack frame. Sets |*payload_length| to the number
92 // of bytes of stream data that will fit in such a packet.
93 size_t GetPacketLengthForOneStream(
96 QuicConnectionIdLength connection_id_length
,
97 QuicSequenceNumberLength sequence_number_length
,
98 InFecGroup is_in_fec_group
,
99 size_t* payload_length
);
101 // Returns QuicConfig set to default values.
102 QuicConfig
DefaultQuicConfig();
104 // Returns a version vector consisting of |version|.
105 QuicVersionVector
SupportedVersions(QuicVersion version
);
107 // Testing convenience method to construct a QuicAckFrame with entropy_hash set
108 // to 0 and largest_observed from peer set to |largest_observed|.
109 QuicAckFrame
MakeAckFrame(QuicPacketSequenceNumber largest_observed
);
111 // Testing convenience method to construct a QuicAckFrame with |num_nack_ranges|
112 // nack ranges of width 1 packet, starting from |least_unacked|.
113 QuicAckFrame
MakeAckFrameWithNackRanges(size_t num_nack_ranges
,
114 QuicPacketSequenceNumber least_unacked
);
116 // Returns a QuicPacket that is owned by the caller, and
117 // is populated with the fields in |header| and |frames|, or is nullptr if the
118 // packet could not be created.
119 QuicPacket
* BuildUnsizedDataPacket(QuicFramer
* framer
,
120 const QuicPacketHeader
& header
,
121 const QuicFrames
& frames
);
122 // Returns a QuicPacket that is owned by the caller, and of size |packet_size|.
123 QuicPacket
* BuildUnsizedDataPacket(QuicFramer
* framer
,
124 const QuicPacketHeader
& header
,
125 const QuicFrames
& frames
,
128 template<typename SaveType
>
131 ValueRestore(SaveType
* name
, SaveType value
)
144 DISALLOW_COPY_AND_ASSIGN(ValueRestore
);
147 // Simple random number generator used to compute random numbers suitable
148 // for pseudo-randomly dropping packets in tests. It works by computing
149 // the sha1 hash of the current seed, and using the first 64 bits as
150 // the next random number, and the next seed.
153 SimpleRandom() : seed_(0) {}
155 // Returns a random number in the range [0, kuint64max].
158 void set_seed(uint64 seed
) { seed_
= seed
; }
163 DISALLOW_COPY_AND_ASSIGN(SimpleRandom
);
166 class MockFramerVisitor
: public QuicFramerVisitorInterface
{
169 ~MockFramerVisitor() override
;
171 MOCK_METHOD1(OnError
, void(QuicFramer
* framer
));
172 // The constructor sets this up to return false by default.
173 MOCK_METHOD1(OnProtocolVersionMismatch
, bool(QuicVersion version
));
174 MOCK_METHOD0(OnPacket
, void());
175 MOCK_METHOD1(OnPublicResetPacket
, void(const QuicPublicResetPacket
& header
));
176 MOCK_METHOD1(OnVersionNegotiationPacket
,
177 void(const QuicVersionNegotiationPacket
& packet
));
178 MOCK_METHOD0(OnRevivedPacket
, void());
179 // The constructor sets this up to return true by default.
180 MOCK_METHOD1(OnUnauthenticatedHeader
, bool(const QuicPacketHeader
& header
));
181 // The constructor sets this up to return true by default.
182 MOCK_METHOD1(OnUnauthenticatedPublicHeader
, bool(
183 const QuicPacketPublicHeader
& header
));
184 MOCK_METHOD1(OnDecryptedPacket
, void(EncryptionLevel level
));
185 MOCK_METHOD1(OnPacketHeader
, bool(const QuicPacketHeader
& header
));
186 MOCK_METHOD1(OnFecProtectedPayload
, void(base::StringPiece payload
));
187 MOCK_METHOD1(OnStreamFrame
, bool(const QuicStreamFrame
& frame
));
188 MOCK_METHOD1(OnAckFrame
, bool(const QuicAckFrame
& frame
));
189 MOCK_METHOD1(OnStopWaitingFrame
, bool(const QuicStopWaitingFrame
& frame
));
190 MOCK_METHOD1(OnPingFrame
, bool(const QuicPingFrame
& frame
));
191 MOCK_METHOD1(OnFecData
, void(const QuicFecData
& fec
));
192 MOCK_METHOD1(OnRstStreamFrame
, bool(const QuicRstStreamFrame
& frame
));
193 MOCK_METHOD1(OnConnectionCloseFrame
,
194 bool(const QuicConnectionCloseFrame
& frame
));
195 MOCK_METHOD1(OnGoAwayFrame
, bool(const QuicGoAwayFrame
& frame
));
196 MOCK_METHOD1(OnWindowUpdateFrame
, bool(const QuicWindowUpdateFrame
& frame
));
197 MOCK_METHOD1(OnBlockedFrame
, bool(const QuicBlockedFrame
& frame
));
198 MOCK_METHOD0(OnPacketComplete
, void());
201 DISALLOW_COPY_AND_ASSIGN(MockFramerVisitor
);
204 class NoOpFramerVisitor
: public QuicFramerVisitorInterface
{
206 NoOpFramerVisitor() {}
208 void OnError(QuicFramer
* framer
) override
{}
209 void OnPacket() override
{}
210 void OnPublicResetPacket(const QuicPublicResetPacket
& packet
) override
{}
211 void OnVersionNegotiationPacket(
212 const QuicVersionNegotiationPacket
& packet
) override
{}
213 void OnRevivedPacket() override
{}
214 bool OnProtocolVersionMismatch(QuicVersion version
) override
;
215 bool OnUnauthenticatedHeader(const QuicPacketHeader
& header
) override
;
216 bool OnUnauthenticatedPublicHeader(
217 const QuicPacketPublicHeader
& header
) override
;
218 void OnDecryptedPacket(EncryptionLevel level
) override
{}
219 bool OnPacketHeader(const QuicPacketHeader
& header
) override
;
220 void OnFecProtectedPayload(base::StringPiece payload
) override
{}
221 bool OnStreamFrame(const QuicStreamFrame
& frame
) override
;
222 bool OnAckFrame(const QuicAckFrame
& frame
) override
;
223 bool OnStopWaitingFrame(const QuicStopWaitingFrame
& frame
) override
;
224 bool OnPingFrame(const QuicPingFrame
& frame
) override
;
225 void OnFecData(const QuicFecData
& fec
) override
{}
226 bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) override
;
227 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame
& frame
) override
;
228 bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) override
;
229 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame
& frame
) override
;
230 bool OnBlockedFrame(const QuicBlockedFrame
& frame
) override
;
231 void OnPacketComplete() override
{}
234 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor
);
237 class MockConnectionVisitor
: public QuicConnectionVisitorInterface
{
239 MockConnectionVisitor();
240 ~MockConnectionVisitor() override
;
242 MOCK_METHOD1(OnStreamFrames
, void(const std::vector
<QuicStreamFrame
>& frame
));
243 MOCK_METHOD1(OnWindowUpdateFrames
,
244 void(const std::vector
<QuicWindowUpdateFrame
>& frame
));
245 MOCK_METHOD1(OnBlockedFrames
,
246 void(const std::vector
<QuicBlockedFrame
>& frame
));
247 MOCK_METHOD1(OnRstStream
, void(const QuicRstStreamFrame
& frame
));
248 MOCK_METHOD1(OnGoAway
, void(const QuicGoAwayFrame
& frame
));
249 MOCK_METHOD2(OnConnectionClosed
, void(QuicErrorCode error
, bool from_peer
));
250 MOCK_METHOD0(OnWriteBlocked
, void());
251 MOCK_METHOD0(OnCanWrite
, void());
252 MOCK_METHOD1(OnCongestionWindowChange
, void(QuicTime now
));
253 MOCK_CONST_METHOD0(WillingAndAbleToWrite
, bool());
254 MOCK_CONST_METHOD0(HasPendingHandshake
, bool());
255 MOCK_CONST_METHOD0(HasOpenDataStreams
, bool());
256 MOCK_METHOD1(OnSuccessfulVersionNegotiation
,
257 void(const QuicVersion
& version
));
258 MOCK_METHOD0(OnConfigNegotiated
, void());
261 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor
);
264 class MockHelper
: public QuicConnectionHelperInterface
{
267 ~MockHelper() override
;
268 const QuicClock
* GetClock() const override
;
269 QuicRandom
* GetRandomGenerator() override
;
270 QuicAlarm
* CreateAlarm(QuicAlarm::Delegate
* delegate
) override
;
271 void AdvanceTime(QuicTime::Delta delta
);
275 MockRandom random_generator_
;
277 DISALLOW_COPY_AND_ASSIGN(MockHelper
);
280 class NiceMockPacketWriterFactory
: public QuicConnection::PacketWriterFactory
{
282 NiceMockPacketWriterFactory() {}
283 ~NiceMockPacketWriterFactory() override
{}
285 QuicPacketWriter
* Create(QuicConnection
* /*connection*/) const override
;
288 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory
);
291 class MockConnection
: public QuicConnection
{
293 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123.
294 explicit MockConnection(Perspective perspective
);
296 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123.
297 MockConnection(Perspective perspective
, bool is_secure
);
299 // Uses a MockHelper, ConnectionId of 42.
300 MockConnection(IPEndPoint address
, Perspective perspective
);
302 // Uses a MockHelper, and 127.0.0.1:123.
303 MockConnection(QuicConnectionId connection_id
, Perspective perspective
);
305 // Uses a MockHelper, and 127.0.0.1:123.
306 MockConnection(QuicConnectionId connection_id
,
307 Perspective perspective
,
310 // Uses a Mock helper, ConnectionId of 42, and 127.0.0.1:123.
311 MockConnection(Perspective perspective
,
312 const QuicVersionVector
& supported_versions
);
314 ~MockConnection() override
;
316 // If the constructor that uses a MockHelper has been used then this method
317 // will advance the time of the MockClock.
318 void AdvanceTime(QuicTime::Delta delta
);
320 MOCK_METHOD3(ProcessUdpPacket
, void(const IPEndPoint
& self_address
,
321 const IPEndPoint
& peer_address
,
322 const QuicEncryptedPacket
& packet
));
323 MOCK_METHOD1(SendConnectionClose
, void(QuicErrorCode error
));
324 MOCK_METHOD2(SendConnectionCloseWithDetails
,
325 void(QuicErrorCode error
, const std::string
& details
));
326 MOCK_METHOD2(SendConnectionClosePacket
,
327 void(QuicErrorCode error
, const std::string
& details
));
328 MOCK_METHOD3(SendRstStream
, void(QuicStreamId id
,
329 QuicRstStreamErrorCode error
,
330 QuicStreamOffset bytes_written
));
331 MOCK_METHOD3(SendGoAway
,
332 void(QuicErrorCode error
,
333 QuicStreamId last_good_stream_id
,
334 const std::string
& reason
));
335 MOCK_METHOD1(SendBlocked
, void(QuicStreamId id
));
336 MOCK_METHOD2(SendWindowUpdate
, void(QuicStreamId id
,
337 QuicStreamOffset byte_offset
));
338 MOCK_METHOD0(OnCanWrite
, void());
340 MOCK_METHOD1(OnSendConnectionState
, void(const CachedNetworkParameters
&));
341 MOCK_METHOD2(ResumeConnectionState
,
342 bool(const CachedNetworkParameters
&, bool));
344 void ReallyProcessUdpPacket(const IPEndPoint
& self_address
,
345 const IPEndPoint
& peer_address
,
346 const QuicEncryptedPacket
& packet
) {
347 QuicConnection::ProcessUdpPacket(self_address
, peer_address
, packet
);
350 bool OnProtocolVersionMismatch(QuicVersion version
) override
{
355 scoped_ptr
<QuicConnectionHelperInterface
> helper_
;
357 DISALLOW_COPY_AND_ASSIGN(MockConnection
);
360 class PacketSavingConnection
: public MockConnection
{
362 explicit PacketSavingConnection(Perspective perspective
);
364 PacketSavingConnection(Perspective perspective
,
365 const QuicVersionVector
& supported_versions
);
367 ~PacketSavingConnection() override
;
369 void SendOrQueuePacket(QueuedPacket packet
) override
;
371 std::vector
<QuicEncryptedPacket
*> encrypted_packets_
;
374 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection
);
377 class MockSession
: public QuicSession
{
379 explicit MockSession(QuicConnection
* connection
);
380 ~MockSession() override
;
381 MOCK_METHOD2(OnConnectionClosed
, void(QuicErrorCode error
, bool from_peer
));
382 MOCK_METHOD1(CreateIncomingDataStream
, QuicDataStream
*(QuicStreamId id
));
383 MOCK_METHOD0(GetCryptoStream
, QuicCryptoStream
*());
384 MOCK_METHOD0(CreateOutgoingDataStream
, QuicDataStream
*());
385 MOCK_METHOD6(WritevData
,
386 QuicConsumedData(QuicStreamId id
,
387 const IOVector
& data
,
388 QuicStreamOffset offset
,
390 FecProtection fec_protection
,
391 QuicAckNotifier::DelegateInterface
*));
392 MOCK_METHOD2(OnStreamHeaders
, void(QuicStreamId stream_id
,
393 base::StringPiece headers_data
));
394 MOCK_METHOD2(OnStreamHeadersPriority
, void(QuicStreamId stream_id
,
395 QuicPriority priority
));
396 MOCK_METHOD3(OnStreamHeadersComplete
, void(QuicStreamId stream_id
,
399 MOCK_METHOD3(SendRstStream
, void(QuicStreamId stream_id
,
400 QuicRstStreamErrorCode error
,
401 QuicStreamOffset bytes_written
));
402 MOCK_METHOD0(IsCryptoHandshakeConfirmed
, bool());
404 using QuicSession::ActivateStream
;
407 DISALLOW_COPY_AND_ASSIGN(MockSession
);
410 class TestSession
: public QuicSession
{
412 TestSession(QuicConnection
* connection
, const QuicConfig
& config
);
413 ~TestSession() override
;
415 MOCK_METHOD1(CreateIncomingDataStream
, QuicDataStream
*(QuicStreamId id
));
416 MOCK_METHOD0(CreateOutgoingDataStream
, QuicDataStream
*());
418 void SetCryptoStream(QuicCryptoStream
* stream
);
420 QuicCryptoStream
* GetCryptoStream() override
;
423 QuicCryptoStream
* crypto_stream_
;
425 DISALLOW_COPY_AND_ASSIGN(TestSession
);
428 class TestClientSession
: public QuicClientSessionBase
{
430 TestClientSession(QuicConnection
* connection
, const QuicConfig
& config
);
431 ~TestClientSession() override
;
433 // QuicClientSessionBase
434 MOCK_METHOD1(OnProofValid
,
435 void(const QuicCryptoClientConfig::CachedState
& cached
));
436 MOCK_METHOD1(OnProofVerifyDetailsAvailable
,
437 void(const ProofVerifyDetails
& verify_details
));
440 MOCK_METHOD1(CreateIncomingDataStream
, QuicDataStream
*(QuicStreamId id
));
441 MOCK_METHOD0(CreateOutgoingDataStream
, QuicDataStream
*());
443 void SetCryptoStream(QuicCryptoStream
* stream
);
445 QuicCryptoStream
* GetCryptoStream() override
;
448 QuicCryptoStream
* crypto_stream_
;
450 DISALLOW_COPY_AND_ASSIGN(TestClientSession
);
453 class MockPacketWriter
: public QuicPacketWriter
{
456 ~MockPacketWriter() override
;
458 MOCK_METHOD4(WritePacket
,
459 WriteResult(const char* buffer
,
461 const IPAddressNumber
& self_address
,
462 const IPEndPoint
& peer_address
));
463 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered
, bool());
464 MOCK_CONST_METHOD0(IsWriteBlocked
, bool());
465 MOCK_METHOD0(SetWritable
, void());
468 DISALLOW_COPY_AND_ASSIGN(MockPacketWriter
);
471 class MockSendAlgorithm
: public SendAlgorithmInterface
{
474 ~MockSendAlgorithm() override
;
476 MOCK_METHOD2(SetFromConfig
,
477 void(const QuicConfig
& config
,
478 Perspective perspective
));
479 MOCK_METHOD1(SetNumEmulatedConnections
, void(int num_connections
));
480 MOCK_METHOD1(SetMaxCongestionWindow
,
481 void(QuicByteCount max_congestion_window
));
482 MOCK_METHOD4(OnCongestionEvent
, void(bool rtt_updated
,
483 QuicByteCount bytes_in_flight
,
484 const CongestionVector
& acked_packets
,
485 const CongestionVector
& lost_packets
));
486 MOCK_METHOD5(OnPacketSent
,
487 bool(QuicTime
, QuicByteCount
, QuicPacketSequenceNumber
,
488 QuicByteCount
, HasRetransmittableData
));
489 MOCK_METHOD1(OnRetransmissionTimeout
, void(bool));
490 MOCK_METHOD0(RevertRetransmissionTimeout
, void());
491 MOCK_CONST_METHOD3(TimeUntilSend
,
492 QuicTime::Delta(QuicTime now
,
493 QuicByteCount bytes_in_flight
,
494 HasRetransmittableData
));
495 MOCK_CONST_METHOD0(PacingRate
, QuicBandwidth(void));
496 MOCK_CONST_METHOD0(BandwidthEstimate
, QuicBandwidth(void));
497 MOCK_CONST_METHOD0(HasReliableBandwidthEstimate
, bool());
498 MOCK_METHOD1(OnRttUpdated
, void(QuicPacketSequenceNumber
));
499 MOCK_CONST_METHOD0(RetransmissionDelay
, QuicTime::Delta(void));
500 MOCK_CONST_METHOD0(GetCongestionWindow
, QuicByteCount());
501 MOCK_CONST_METHOD0(InSlowStart
, bool());
502 MOCK_CONST_METHOD0(InRecovery
, bool());
503 MOCK_CONST_METHOD0(GetSlowStartThreshold
, QuicByteCount());
504 MOCK_CONST_METHOD0(GetCongestionControlType
, CongestionControlType());
505 MOCK_METHOD2(ResumeConnectionState
,
506 bool(const CachedNetworkParameters
&, bool));
509 DISALLOW_COPY_AND_ASSIGN(MockSendAlgorithm
);
512 class MockLossAlgorithm
: public LossDetectionInterface
{
515 ~MockLossAlgorithm() override
;
517 MOCK_CONST_METHOD0(GetLossDetectionType
, LossDetectionType());
518 MOCK_METHOD4(DetectLostPackets
,
519 SequenceNumberSet(const QuicUnackedPacketMap
& unacked_packets
,
520 const QuicTime
& time
,
521 QuicPacketSequenceNumber largest_observed
,
522 const RttStats
& rtt_stats
));
523 MOCK_CONST_METHOD0(GetLossTimeout
, QuicTime());
526 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm
);
529 class TestEntropyCalculator
:
530 public QuicReceivedEntropyHashCalculatorInterface
{
532 TestEntropyCalculator();
533 ~TestEntropyCalculator() override
;
535 QuicPacketEntropyHash
EntropyHash(
536 QuicPacketSequenceNumber sequence_number
) const override
;
539 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator
);
542 class MockEntropyCalculator
: public TestEntropyCalculator
{
544 MockEntropyCalculator();
545 ~MockEntropyCalculator() override
;
549 QuicPacketEntropyHash(QuicPacketSequenceNumber sequence_number
));
552 DISALLOW_COPY_AND_ASSIGN(MockEntropyCalculator
);
555 class MockAckNotifierDelegate
: public QuicAckNotifier::DelegateInterface
{
557 MockAckNotifierDelegate();
559 MOCK_METHOD3(OnAckNotification
,
560 void(int num_retransmitted_packets
,
561 int num_retransmitted_bytes
,
562 QuicTime::Delta delta_largest_observed
));
565 // Object is ref counted.
566 ~MockAckNotifierDelegate() override
;
569 DISALLOW_COPY_AND_ASSIGN(MockAckNotifierDelegate
);
572 class MockNetworkChangeVisitor
:
573 public QuicSentPacketManager::NetworkChangeVisitor
{
575 MockNetworkChangeVisitor();
576 ~MockNetworkChangeVisitor() override
;
578 MOCK_METHOD0(OnCongestionWindowChange
, void());
579 MOCK_METHOD0(OnRttChange
, void());
582 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor
);
585 // Creates per-connection packet writers that register themselves with the
586 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
587 // be routed to the appropriate QuicConnection.
588 class TestWriterFactory
: public tools::QuicDispatcher::PacketWriterFactory
{
591 ~TestWriterFactory() override
;
593 QuicPacketWriter
* Create(QuicPacketWriter
* writer
,
594 QuicConnection
* connection
) override
;
596 // Calls OnPacketSent on the last QuicConnection to write through one of the
597 // packet writers created by this factory.
598 void OnPacketSent(WriteResult result
);
601 class PerConnectionPacketWriter
602 : public tools::QuicPerConnectionPacketWriter
{
604 PerConnectionPacketWriter(TestWriterFactory
* factory
,
605 QuicPacketWriter
* writer
,
606 QuicConnection
* connection
);
607 ~PerConnectionPacketWriter() override
;
609 WriteResult
WritePacket(const char* buffer
,
611 const IPAddressNumber
& self_address
,
612 const IPEndPoint
& peer_address
) override
;
615 TestWriterFactory
* factory_
;
618 // If an asynchronous write is happening and |writer| gets deleted, this
619 // clears the pointer to it to prevent use-after-free.
620 void Unregister(PerConnectionPacketWriter
* writer
);
622 PerConnectionPacketWriter
* current_writer_
;
625 class MockQuicConnectionDebugVisitor
: public QuicConnectionDebugVisitor
{
627 MockQuicConnectionDebugVisitor();
628 ~MockQuicConnectionDebugVisitor();
630 MOCK_METHOD1(OnFrameAddedToPacket
, void(const QuicFrame
&));
632 MOCK_METHOD6(OnPacketSent
,
633 void(const SerializedPacket
&,
634 QuicPacketSequenceNumber
,
637 const QuicEncryptedPacket
&,
640 MOCK_METHOD3(OnPacketReceived
,
641 void(const IPEndPoint
&,
643 const QuicEncryptedPacket
&));
645 MOCK_METHOD1(OnIncorrectConnectionId
, void(QuicConnectionId
));
647 MOCK_METHOD1(OnProtocolVersionMismatch
, void(QuicVersion
));
649 MOCK_METHOD1(OnPacketHeader
, void(const QuicPacketHeader
& header
));
651 MOCK_METHOD1(OnStreamFrame
, void(const QuicStreamFrame
&));
653 MOCK_METHOD1(OnAckFrame
, void(const QuicAckFrame
& frame
));
655 MOCK_METHOD1(OnStopWaitingFrame
, void(const QuicStopWaitingFrame
&));
657 MOCK_METHOD1(OnRstStreamFrame
, void(const QuicRstStreamFrame
&));
659 MOCK_METHOD1(OnConnectionCloseFrame
, void(const QuicConnectionCloseFrame
&));
661 MOCK_METHOD1(OnPublicResetPacket
, void(const QuicPublicResetPacket
&));
663 MOCK_METHOD1(OnVersionNegotiationPacket
,
664 void(const QuicVersionNegotiationPacket
&));
666 MOCK_METHOD2(OnRevivedPacket
,
667 void(const QuicPacketHeader
&, StringPiece payload
));
673 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_