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(
33 QuicStreamId stream_id
,
34 QuicRstStreamErrorCode error_code
);
35 scoped_ptr
<QuicEncryptedPacket
> MakeAckAndRstPacket(
38 QuicStreamId stream_id
,
39 QuicRstStreamErrorCode error_code
,
40 QuicPacketNumber largest_received
,
41 QuicPacketNumber least_unacked
,
43 scoped_ptr
<QuicEncryptedPacket
> MakeConnectionClosePacket(
44 QuicPacketNumber num
);
45 scoped_ptr
<QuicEncryptedPacket
> MakeAckPacket(
46 QuicPacketNumber packet_number
,
47 QuicPacketNumber largest_received
,
48 QuicPacketNumber least_unacked
,
50 scoped_ptr
<QuicEncryptedPacket
> MakeDataPacket(QuicPacketNumber packet_number
,
51 QuicStreamId stream_id
,
52 bool should_include_version
,
54 QuicStreamOffset offset
,
55 base::StringPiece data
);
56 scoped_ptr
<QuicEncryptedPacket
> MakeRequestHeadersPacket(
57 QuicPacketNumber packet_number
,
58 QuicStreamId stream_id
,
59 bool should_include_version
,
61 QuicPriority priority
,
62 const SpdyHeaderBlock
& headers
);
63 scoped_ptr
<QuicEncryptedPacket
> MakeResponseHeadersPacket(
64 QuicPacketNumber packet_number
,
65 QuicStreamId stream_id
,
66 bool should_include_version
,
68 const SpdyHeaderBlock
& headers
);
70 SpdyHeaderBlock
GetRequestHeaders(const std::string
& method
,
71 const std::string
& scheme
,
72 const std::string
& path
);
73 SpdyHeaderBlock
GetResponseHeaders(const std::string
& status
);
76 scoped_ptr
<QuicEncryptedPacket
> MakePacket(
77 const QuicPacketHeader
& header
,
78 const QuicFrame
& frame
);
80 void InitializeHeader(QuicPacketNumber packet_number
,
81 bool should_include_version
);
84 QuicConnectionId connection_id_
;
85 MockClock
* clock_
; // Owned by QuicStreamFactory.
87 SpdyFramer spdy_request_framer_
;
88 SpdyFramer spdy_response_framer_
;
89 MockRandom random_generator_
;
90 QuicPacketHeader header_
;
92 DISALLOW_COPY_AND_ASSIGN(QuicTestPacketMaker
);
98 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_PACKET_MAKER_H_