Revert of Add support for escaped target names in isolate driver. (patchset #6 id...
[chromium-blink-merge.git] / net / quic / test_tools / quic_test_utils.h
blob900bb150f454907707888a0c7ced3058497f529c
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
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
10 #include <string>
11 #include <vector>
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"
30 namespace net {
32 namespace test {
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
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,
66 bool version_flag,
67 bool reset_flag,
68 QuicPacketSequenceNumber sequence_number,
69 const std::string& data);
71 void CompareCharArraysWithHexError(const std::string& description,
72 const char* actual,
73 const int actual_len,
74 const char* expected,
75 const int expected_len);
77 bool DecodeHexString(const base::StringPiece& hex, std::string* bytes);
79 // Returns the length of a QuicPacket that is capable of holding either a
80 // stream frame or a minimal ack frame. Sets |*payload_length| to the number
81 // of bytes of stream data that will fit in such a packet.
82 size_t GetPacketLengthForOneStream(
83 QuicVersion version,
84 bool include_version,
85 QuicConnectionIdLength connection_id_length,
86 QuicSequenceNumberLength sequence_number_length,
87 InFecGroup is_in_fec_group,
88 size_t* payload_length);
90 // Returns QuicConfig set to default values.
91 QuicConfig DefaultQuicConfig();
93 // Returns a version vector consisting of |version|.
94 QuicVersionVector SupportedVersions(QuicVersion version);
96 // Testing convenience method to construct a QuicAckFrame with entropy_hash set
97 // to 0 and largest_observed from peer set to |largest_observed|.
98 QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed);
100 // Testing convenience method to construct a QuicAckFrame with |num_nack_ranges|
101 // nack ranges of width 1 packet, starting from |least_unacked|.
102 QuicAckFrame MakeAckFrameWithNackRanges(size_t num_nack_ranges,
103 QuicPacketSequenceNumber least_unacked);
105 // Returns a QuicPacket that is owned by the caller, and
106 // is populated with the fields in |header| and |frames|, or is nullptr if the
107 // packet could not be created.
108 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer,
109 const QuicPacketHeader& header,
110 const QuicFrames& frames);
111 // Returns a QuicPacket that is owned by the caller, and of size |packet_size|.
112 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer,
113 const QuicPacketHeader& header,
114 const QuicFrames& frames,
115 size_t packet_size);
117 template<typename SaveType>
118 class ValueRestore {
119 public:
120 ValueRestore(SaveType* name, SaveType value)
121 : name_(name),
122 value_(*name) {
123 *name_ = value;
125 ~ValueRestore() {
126 *name_ = value_;
129 private:
130 SaveType* name_;
131 SaveType value_;
133 DISALLOW_COPY_AND_ASSIGN(ValueRestore);
136 // Simple random number generator used to compute random numbers suitable
137 // for pseudo-randomly dropping packets in tests. It works by computing
138 // the sha1 hash of the current seed, and using the first 64 bits as
139 // the next random number, and the next seed.
140 class SimpleRandom {
141 public:
142 SimpleRandom() : seed_(0) {}
144 // Returns a random number in the range [0, kuint64max].
145 uint64 RandUint64();
147 void set_seed(uint64 seed) { seed_ = seed; }
149 private:
150 uint64 seed_;
152 DISALLOW_COPY_AND_ASSIGN(SimpleRandom);
155 class MockFramerVisitor : public QuicFramerVisitorInterface {
156 public:
157 MockFramerVisitor();
158 ~MockFramerVisitor() override;
160 MOCK_METHOD1(OnError, void(QuicFramer* framer));
161 // The constructor sets this up to return false by default.
162 MOCK_METHOD1(OnProtocolVersionMismatch, bool(QuicVersion version));
163 MOCK_METHOD0(OnPacket, void());
164 MOCK_METHOD1(OnPublicResetPacket, void(const QuicPublicResetPacket& header));
165 MOCK_METHOD1(OnVersionNegotiationPacket,
166 void(const QuicVersionNegotiationPacket& packet));
167 MOCK_METHOD0(OnRevivedPacket, void());
168 // The constructor sets this up to return true by default.
169 MOCK_METHOD1(OnUnauthenticatedHeader, bool(const QuicPacketHeader& header));
170 // The constructor sets this up to return true by default.
171 MOCK_METHOD1(OnUnauthenticatedPublicHeader, bool(
172 const QuicPacketPublicHeader& header));
173 MOCK_METHOD1(OnDecryptedPacket, void(EncryptionLevel level));
174 MOCK_METHOD1(OnPacketHeader, bool(const QuicPacketHeader& header));
175 MOCK_METHOD1(OnFecProtectedPayload, void(base::StringPiece payload));
176 MOCK_METHOD1(OnStreamFrame, bool(const QuicStreamFrame& frame));
177 MOCK_METHOD1(OnAckFrame, bool(const QuicAckFrame& frame));
178 MOCK_METHOD1(OnStopWaitingFrame, bool(const QuicStopWaitingFrame& frame));
179 MOCK_METHOD1(OnPingFrame, bool(const QuicPingFrame& frame));
180 MOCK_METHOD1(OnFecData, void(const QuicFecData& fec));
181 MOCK_METHOD1(OnRstStreamFrame, bool(const QuicRstStreamFrame& frame));
182 MOCK_METHOD1(OnConnectionCloseFrame,
183 bool(const QuicConnectionCloseFrame& frame));
184 MOCK_METHOD1(OnGoAwayFrame, bool(const QuicGoAwayFrame& frame));
185 MOCK_METHOD1(OnWindowUpdateFrame, bool(const QuicWindowUpdateFrame& frame));
186 MOCK_METHOD1(OnBlockedFrame, bool(const QuicBlockedFrame& frame));
187 MOCK_METHOD0(OnPacketComplete, void());
189 private:
190 DISALLOW_COPY_AND_ASSIGN(MockFramerVisitor);
193 class NoOpFramerVisitor : public QuicFramerVisitorInterface {
194 public:
195 NoOpFramerVisitor() {}
197 void OnError(QuicFramer* framer) override {}
198 void OnPacket() override {}
199 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {}
200 void OnVersionNegotiationPacket(
201 const QuicVersionNegotiationPacket& packet) override {}
202 void OnRevivedPacket() override {}
203 bool OnProtocolVersionMismatch(QuicVersion version) override;
204 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override;
205 bool OnUnauthenticatedPublicHeader(
206 const QuicPacketPublicHeader& header) override;
207 void OnDecryptedPacket(EncryptionLevel level) override {}
208 bool OnPacketHeader(const QuicPacketHeader& header) override;
209 void OnFecProtectedPayload(base::StringPiece payload) override {}
210 bool OnStreamFrame(const QuicStreamFrame& frame) override;
211 bool OnAckFrame(const QuicAckFrame& frame) override;
212 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override;
213 bool OnPingFrame(const QuicPingFrame& frame) override;
214 void OnFecData(const QuicFecData& fec) override {}
215 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override;
216 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override;
217 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override;
218 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override;
219 bool OnBlockedFrame(const QuicBlockedFrame& frame) override;
220 void OnPacketComplete() override {}
222 private:
223 DISALLOW_COPY_AND_ASSIGN(NoOpFramerVisitor);
226 class MockConnectionVisitor : public QuicConnectionVisitorInterface {
227 public:
228 MockConnectionVisitor();
229 ~MockConnectionVisitor() override;
231 MOCK_METHOD1(OnStreamFrames, void(const std::vector<QuicStreamFrame>& frame));
232 MOCK_METHOD1(OnWindowUpdateFrames,
233 void(const std::vector<QuicWindowUpdateFrame>& frame));
234 MOCK_METHOD1(OnBlockedFrames,
235 void(const std::vector<QuicBlockedFrame>& frame));
236 MOCK_METHOD1(OnRstStream, void(const QuicRstStreamFrame& frame));
237 MOCK_METHOD1(OnGoAway, void(const QuicGoAwayFrame& frame));
238 MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer));
239 MOCK_METHOD0(OnWriteBlocked, void());
240 MOCK_METHOD0(OnCanWrite, void());
241 MOCK_METHOD1(OnCongestionWindowChange, void(QuicTime now));
242 MOCK_CONST_METHOD0(WillingAndAbleToWrite, bool());
243 MOCK_CONST_METHOD0(HasPendingHandshake, bool());
244 MOCK_CONST_METHOD0(HasOpenDataStreams, bool());
245 MOCK_METHOD1(OnSuccessfulVersionNegotiation,
246 void(const QuicVersion& version));
247 MOCK_METHOD0(OnConfigNegotiated, void());
249 private:
250 DISALLOW_COPY_AND_ASSIGN(MockConnectionVisitor);
253 class MockHelper : public QuicConnectionHelperInterface {
254 public:
255 MockHelper();
256 ~MockHelper() override;
257 const QuicClock* GetClock() const override;
258 QuicRandom* GetRandomGenerator() override;
259 QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override;
260 void AdvanceTime(QuicTime::Delta delta);
262 private:
263 MockClock clock_;
264 MockRandom random_generator_;
266 DISALLOW_COPY_AND_ASSIGN(MockHelper);
269 class NiceMockPacketWriterFactory : public QuicConnection::PacketWriterFactory {
270 public:
271 NiceMockPacketWriterFactory() {}
272 ~NiceMockPacketWriterFactory() override {}
274 QuicPacketWriter* Create(QuicConnection* /*connection*/) const override;
276 private:
277 DISALLOW_COPY_AND_ASSIGN(NiceMockPacketWriterFactory);
280 class MockConnection : public QuicConnection {
281 public:
282 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123.
283 explicit MockConnection(bool is_server);
285 // Uses a MockHelper, ConnectionId of 42, and 127.0.0.1:123.
286 MockConnection(bool is_server, bool is_secure);
288 // Uses a MockHelper, ConnectionId of 42.
289 MockConnection(IPEndPoint address, bool is_server);
291 // Uses a MockHelper, and 127.0.0.1:123
292 MockConnection(QuicConnectionId connection_id, bool is_server);
294 // Uses a Mock helper, ConnectionId of 42, and 127.0.0.1:123.
295 MockConnection(bool is_server, const QuicVersionVector& supported_versions);
297 ~MockConnection() override;
299 // If the constructor that uses a MockHelper has been used then this method
300 // will advance the time of the MockClock.
301 void AdvanceTime(QuicTime::Delta delta);
303 MOCK_METHOD3(ProcessUdpPacket, void(const IPEndPoint& self_address,
304 const IPEndPoint& peer_address,
305 const QuicEncryptedPacket& packet));
306 MOCK_METHOD1(SendConnectionClose, void(QuicErrorCode error));
307 MOCK_METHOD2(SendConnectionCloseWithDetails,
308 void(QuicErrorCode error, const std::string& details));
309 MOCK_METHOD2(SendConnectionClosePacket,
310 void(QuicErrorCode error, const std::string& details));
311 MOCK_METHOD3(SendRstStream, void(QuicStreamId id,
312 QuicRstStreamErrorCode error,
313 QuicStreamOffset bytes_written));
314 MOCK_METHOD3(SendGoAway,
315 void(QuicErrorCode error,
316 QuicStreamId last_good_stream_id,
317 const std::string& reason));
318 MOCK_METHOD1(SendBlocked, void(QuicStreamId id));
319 MOCK_METHOD2(SendWindowUpdate, void(QuicStreamId id,
320 QuicStreamOffset byte_offset));
321 MOCK_METHOD0(OnCanWrite, void());
323 MOCK_METHOD1(ResumeConnectionState, bool(const CachedNetworkParameters&));
325 void ProcessUdpPacketInternal(const IPEndPoint& self_address,
326 const IPEndPoint& peer_address,
327 const QuicEncryptedPacket& packet) {
328 QuicConnection::ProcessUdpPacket(self_address, peer_address, packet);
331 bool OnProtocolVersionMismatch(QuicVersion version) override {
332 return false;
335 private:
336 scoped_ptr<QuicConnectionHelperInterface> helper_;
338 DISALLOW_COPY_AND_ASSIGN(MockConnection);
341 class PacketSavingConnection : public MockConnection {
342 public:
343 explicit PacketSavingConnection(bool is_server);
345 PacketSavingConnection(bool is_server,
346 const QuicVersionVector& supported_versions);
348 ~PacketSavingConnection() override;
350 void SendOrQueuePacket(QueuedPacket packet) override;
352 std::vector<QuicEncryptedPacket*> encrypted_packets_;
354 private:
355 DISALLOW_COPY_AND_ASSIGN(PacketSavingConnection);
358 class MockSession : public QuicSession {
359 public:
360 explicit MockSession(QuicConnection* connection);
361 ~MockSession() override;
362 MOCK_METHOD2(OnConnectionClosed, void(QuicErrorCode error, bool from_peer));
363 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id));
364 MOCK_METHOD0(GetCryptoStream, QuicCryptoStream*());
365 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*());
366 MOCK_METHOD6(WritevData,
367 QuicConsumedData(QuicStreamId id,
368 const IOVector& data,
369 QuicStreamOffset offset,
370 bool fin,
371 FecProtection fec_protection,
372 QuicAckNotifier::DelegateInterface*));
373 MOCK_METHOD2(OnStreamHeaders, void(QuicStreamId stream_id,
374 base::StringPiece headers_data));
375 MOCK_METHOD2(OnStreamHeadersPriority, void(QuicStreamId stream_id,
376 QuicPriority priority));
377 MOCK_METHOD3(OnStreamHeadersComplete, void(QuicStreamId stream_id,
378 bool fin,
379 size_t frame_len));
380 MOCK_METHOD3(SendRstStream, void(QuicStreamId stream_id,
381 QuicRstStreamErrorCode error,
382 QuicStreamOffset bytes_written));
383 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool());
385 using QuicSession::ActivateStream;
387 private:
388 DISALLOW_COPY_AND_ASSIGN(MockSession);
391 class TestSession : public QuicSession {
392 public:
393 TestSession(QuicConnection* connection, const QuicConfig& config);
394 ~TestSession() override;
396 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id));
397 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*());
399 void SetCryptoStream(QuicCryptoStream* stream);
401 QuicCryptoStream* GetCryptoStream() override;
403 private:
404 QuicCryptoStream* crypto_stream_;
406 DISALLOW_COPY_AND_ASSIGN(TestSession);
409 class TestClientSession : public QuicClientSessionBase {
410 public:
411 TestClientSession(QuicConnection* connection, const QuicConfig& config);
412 ~TestClientSession() override;
414 // QuicClientSessionBase
415 MOCK_METHOD1(OnProofValid,
416 void(const QuicCryptoClientConfig::CachedState& cached));
417 MOCK_METHOD1(OnProofVerifyDetailsAvailable,
418 void(const ProofVerifyDetails& verify_details));
420 // TestClientSession
421 MOCK_METHOD1(CreateIncomingDataStream, QuicDataStream*(QuicStreamId id));
422 MOCK_METHOD0(CreateOutgoingDataStream, QuicDataStream*());
424 void SetCryptoStream(QuicCryptoStream* stream);
426 QuicCryptoStream* GetCryptoStream() override;
428 private:
429 QuicCryptoStream* crypto_stream_;
431 DISALLOW_COPY_AND_ASSIGN(TestClientSession);
434 class MockPacketWriter : public QuicPacketWriter {
435 public:
436 MockPacketWriter();
437 ~MockPacketWriter() override;
439 MOCK_METHOD4(WritePacket,
440 WriteResult(const char* buffer,
441 size_t buf_len,
442 const IPAddressNumber& self_address,
443 const IPEndPoint& peer_address));
444 MOCK_CONST_METHOD0(IsWriteBlockedDataBuffered, bool());
445 MOCK_CONST_METHOD0(IsWriteBlocked, bool());
446 MOCK_METHOD0(SetWritable, void());
448 private:
449 DISALLOW_COPY_AND_ASSIGN(MockPacketWriter);
452 class MockSendAlgorithm : public SendAlgorithmInterface {
453 public:
454 MockSendAlgorithm();
455 ~MockSendAlgorithm() override;
457 MOCK_METHOD3(SetFromConfig, void(const QuicConfig& config,
458 bool is_server,
459 bool using_pacing));
460 MOCK_METHOD1(SetNumEmulatedConnections, void(int num_connections));
461 MOCK_METHOD1(SetMaxPacketSize, void(QuicByteCount max_packet_size));
462 MOCK_METHOD4(OnCongestionEvent, void(bool rtt_updated,
463 QuicByteCount bytes_in_flight,
464 const CongestionVector& acked_packets,
465 const CongestionVector& lost_packets));
466 MOCK_METHOD5(OnPacketSent,
467 bool(QuicTime, QuicByteCount, QuicPacketSequenceNumber,
468 QuicByteCount, HasRetransmittableData));
469 MOCK_METHOD1(OnRetransmissionTimeout, void(bool));
470 MOCK_METHOD0(RevertRetransmissionTimeout, void());
471 MOCK_CONST_METHOD3(TimeUntilSend,
472 QuicTime::Delta(QuicTime now,
473 QuicByteCount bytes_in_flight,
474 HasRetransmittableData));
475 MOCK_CONST_METHOD0(PacingRate, QuicBandwidth(void));
476 MOCK_CONST_METHOD0(BandwidthEstimate, QuicBandwidth(void));
477 MOCK_CONST_METHOD0(HasReliableBandwidthEstimate, bool());
478 MOCK_METHOD1(OnRttUpdated, void(QuicPacketSequenceNumber));
479 MOCK_CONST_METHOD0(RetransmissionDelay, QuicTime::Delta(void));
480 MOCK_CONST_METHOD0(GetCongestionWindow, QuicByteCount());
481 MOCK_CONST_METHOD0(InSlowStart, bool());
482 MOCK_CONST_METHOD0(InRecovery, bool());
483 MOCK_CONST_METHOD0(GetSlowStartThreshold, QuicByteCount());
484 MOCK_CONST_METHOD0(GetCongestionControlType, CongestionControlType());
485 MOCK_METHOD1(ResumeConnectionState, bool(const CachedNetworkParameters&));
487 private:
488 DISALLOW_COPY_AND_ASSIGN(MockSendAlgorithm);
491 class MockLossAlgorithm : public LossDetectionInterface {
492 public:
493 MockLossAlgorithm();
494 ~MockLossAlgorithm() override;
496 MOCK_CONST_METHOD0(GetLossDetectionType, LossDetectionType());
497 MOCK_METHOD4(DetectLostPackets,
498 SequenceNumberSet(const QuicUnackedPacketMap& unacked_packets,
499 const QuicTime& time,
500 QuicPacketSequenceNumber largest_observed,
501 const RttStats& rtt_stats));
502 MOCK_CONST_METHOD0(GetLossTimeout, QuicTime());
504 private:
505 DISALLOW_COPY_AND_ASSIGN(MockLossAlgorithm);
508 class TestEntropyCalculator :
509 public QuicReceivedEntropyHashCalculatorInterface {
510 public:
511 TestEntropyCalculator();
512 ~TestEntropyCalculator() override;
514 QuicPacketEntropyHash EntropyHash(
515 QuicPacketSequenceNumber sequence_number) const override;
517 private:
518 DISALLOW_COPY_AND_ASSIGN(TestEntropyCalculator);
521 class MockEntropyCalculator : public TestEntropyCalculator {
522 public:
523 MockEntropyCalculator();
524 ~MockEntropyCalculator() override;
526 MOCK_CONST_METHOD1(
527 EntropyHash,
528 QuicPacketEntropyHash(QuicPacketSequenceNumber sequence_number));
530 private:
531 DISALLOW_COPY_AND_ASSIGN(MockEntropyCalculator);
534 class MockAckNotifierDelegate : public QuicAckNotifier::DelegateInterface {
535 public:
536 MockAckNotifierDelegate();
538 MOCK_METHOD3(OnAckNotification,
539 void(int num_retransmitted_packets,
540 int num_retransmitted_bytes,
541 QuicTime::Delta delta_largest_observed));
543 protected:
544 // Object is ref counted.
545 ~MockAckNotifierDelegate() override;
547 private:
548 DISALLOW_COPY_AND_ASSIGN(MockAckNotifierDelegate);
551 class MockNetworkChangeVisitor :
552 public QuicSentPacketManager::NetworkChangeVisitor {
553 public:
554 MockNetworkChangeVisitor();
555 ~MockNetworkChangeVisitor() override;
557 MOCK_METHOD0(OnCongestionWindowChange, void());
558 MOCK_METHOD0(OnRttChange, void());
560 private:
561 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor);
564 // Creates per-connection packet writers that register themselves with the
565 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
566 // be routed to the appropriate QuicConnection.
567 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory {
568 public:
569 TestWriterFactory();
570 ~TestWriterFactory() override;
572 QuicPacketWriter* Create(QuicServerPacketWriter* writer,
573 QuicConnection* connection) override;
575 // Calls OnPacketSent on the last QuicConnection to write through one of the
576 // packet writers created by this factory.
577 void OnPacketSent(WriteResult result);
579 private:
580 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter {
581 public:
582 PerConnectionPacketWriter(TestWriterFactory* factory,
583 QuicServerPacketWriter* writer,
584 QuicConnection* connection);
585 ~PerConnectionPacketWriter() override;
587 WriteResult WritePacket(const char* buffer,
588 size_t buf_len,
589 const IPAddressNumber& self_address,
590 const IPEndPoint& peer_address) override;
592 private:
593 TestWriterFactory* factory_;
596 // If an asynchronous write is happening and |writer| gets deleted, this
597 // clears the pointer to it to prevent use-after-free.
598 void Unregister(PerConnectionPacketWriter* writer);
600 PerConnectionPacketWriter* current_writer_;
603 } // namespace test
604 } // namespace net
606 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_