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 const std::string
& host
);
27 ~QuicTestPacketMaker();
29 void set_hostname(const std::string
& host
);
30 scoped_ptr
<QuicEncryptedPacket
> MakeRstPacket(
31 QuicPacketSequenceNumber num
,
33 QuicStreamId stream_id
,
34 QuicRstStreamErrorCode error_code
);
35 scoped_ptr
<QuicEncryptedPacket
> MakeAckAndRstPacket(
36 QuicPacketSequenceNumber num
,
38 QuicStreamId stream_id
,
39 QuicRstStreamErrorCode error_code
,
40 QuicPacketSequenceNumber largest_received
,
41 QuicPacketSequenceNumber least_unacked
,
43 scoped_ptr
<QuicEncryptedPacket
> MakeConnectionClosePacket(
44 QuicPacketSequenceNumber num
);
45 scoped_ptr
<QuicEncryptedPacket
> MakeAckPacket(
46 QuicPacketSequenceNumber sequence_number
,
47 QuicPacketSequenceNumber largest_received
,
48 QuicPacketSequenceNumber least_unacked
,
50 scoped_ptr
<QuicEncryptedPacket
> MakeDataPacket(
51 QuicPacketSequenceNumber sequence_number
,
52 QuicStreamId stream_id
,
53 bool should_include_version
,
55 QuicStreamOffset offset
,
56 base::StringPiece data
);
57 scoped_ptr
<QuicEncryptedPacket
> MakeRequestHeadersPacket(
58 QuicPacketSequenceNumber sequence_number
,
59 QuicStreamId stream_id
,
60 bool should_include_version
,
62 QuicPriority priority
,
63 const SpdyHeaderBlock
& headers
);
64 scoped_ptr
<QuicEncryptedPacket
> MakeResponseHeadersPacket(
65 QuicPacketSequenceNumber sequence_number
,
66 QuicStreamId stream_id
,
67 bool should_include_version
,
69 const SpdyHeaderBlock
& headers
);
71 SpdyHeaderBlock
GetRequestHeaders(const std::string
& method
,
72 const std::string
& scheme
,
73 const std::string
& path
);
74 SpdyHeaderBlock
GetResponseHeaders(const std::string
& status
);
77 scoped_ptr
<QuicEncryptedPacket
> MakePacket(
78 const QuicPacketHeader
& header
,
79 const QuicFrame
& frame
);
81 void InitializeHeader(QuicPacketSequenceNumber sequence_number
,
82 bool should_include_version
);
85 QuicConnectionId connection_id_
;
86 MockClock
* clock_
; // Owned by QuicStreamFactory.
88 SpdyFramer spdy_request_framer_
;
89 SpdyFramer spdy_response_framer_
;
90 MockRandom random_generator_
;
91 QuicPacketHeader header_
;
93 DISALLOW_COPY_AND_ASSIGN(QuicTestPacketMaker
);
99 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_