1 // Copyright 2013 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 // Provides a simple interface for QUIC tests to create a variety of packets.
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/request_priority.h"
12 #include "net/quic/quic_protocol.h"
13 #include "net/quic/test_tools/mock_clock.h"
14 #include "net/quic/test_tools/mock_random.h"
15 #include "net/spdy/spdy_framer.h"
16 #include "net/spdy/spdy_protocol.h"
21 class QuicTestPacketMaker
{
23 QuicTestPacketMaker(QuicVersion version
,
24 QuicConnectionId connection_id
,
26 ~QuicTestPacketMaker();
28 scoped_ptr
<QuicEncryptedPacket
> MakeRstPacket(
29 QuicPacketSequenceNumber num
,
31 QuicStreamId stream_id
,
32 QuicRstStreamErrorCode error_code
);
33 scoped_ptr
<QuicEncryptedPacket
> MakeAckAndRstPacket(
34 QuicPacketSequenceNumber num
,
36 QuicStreamId stream_id
,
37 QuicRstStreamErrorCode error_code
,
38 QuicPacketSequenceNumber largest_received
,
39 QuicPacketSequenceNumber least_unacked
,
41 scoped_ptr
<QuicEncryptedPacket
> MakeConnectionClosePacket(
42 QuicPacketSequenceNumber num
);
43 scoped_ptr
<QuicEncryptedPacket
> MakeAckPacket(
44 QuicPacketSequenceNumber sequence_number
,
45 QuicPacketSequenceNumber largest_received
,
46 QuicPacketSequenceNumber least_unacked
,
48 scoped_ptr
<QuicEncryptedPacket
> MakeDataPacket(
49 QuicPacketSequenceNumber sequence_number
,
50 QuicStreamId stream_id
,
51 bool should_include_version
,
53 QuicStreamOffset offset
,
54 base::StringPiece data
);
55 scoped_ptr
<QuicEncryptedPacket
> MakeRequestHeadersPacket(
56 QuicPacketSequenceNumber sequence_number
,
57 QuicStreamId stream_id
,
58 bool should_include_version
,
60 QuicPriority priority
,
61 const SpdyHeaderBlock
& headers
);
62 scoped_ptr
<QuicEncryptedPacket
> MakeResponseHeadersPacket(
63 QuicPacketSequenceNumber sequence_number
,
64 QuicStreamId stream_id
,
65 bool should_include_version
,
67 const SpdyHeaderBlock
& headers
);
69 SpdyHeaderBlock
GetRequestHeaders(const std::string
& method
,
70 const std::string
& scheme
,
71 const std::string
& path
);
72 SpdyHeaderBlock
GetResponseHeaders(const std::string
& status
);
75 scoped_ptr
<QuicEncryptedPacket
> MakePacket(
76 const QuicPacketHeader
& header
,
77 const QuicFrame
& frame
);
79 void InitializeHeader(QuicPacketSequenceNumber sequence_number
,
80 bool should_include_version
);
83 QuicConnectionId connection_id_
;
84 MockClock
* clock_
; // Owned by QuicStreamFactory.
85 SpdyFramer spdy_request_framer_
;
86 SpdyFramer spdy_response_framer_
;
87 MockRandom random_generator_
;
88 QuicPacketHeader header_
;
90 DISALLOW_COPY_AND_ASSIGN(QuicTestPacketMaker
);
96 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_