blob: 35530d01771d7647bd402ce362cd97ad397a89f0 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2018 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
vasilvv872e7a32019-03-12 16:42:44 -07005#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -05006#include <tuple>
7
vasilvv7cac7b02020-10-08 12:32:10 -07008#include "absl/strings/string_view.h"
QUICHE team5be974e2020-12-29 18:35:24 -05009#include "quic/platform/api/quic_test.h"
10#include "quic/test_tools/qpack/qpack_decoder_test_utils.h"
11#include "quic/test_tools/qpack/qpack_encoder_test_utils.h"
12#include "quic/test_tools/qpack/qpack_test_utils.h"
13#include "spdy/core/spdy_header_block.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050014
QUICHE teama6ef0a62019-03-07 20:34:33 -050015using ::testing::Values;
16
17namespace quic {
18namespace test {
19namespace {
20
bncf21c1ad2019-06-20 20:09:50 -070021class QpackRoundTripTest : public QuicTestWithParam<FragmentMode> {
QUICHE teama6ef0a62019-03-07 20:34:33 -050022 public:
bncf21c1ad2019-06-20 20:09:50 -070023 QpackRoundTripTest() = default;
QUICHE teama6ef0a62019-03-07 20:34:33 -050024 ~QpackRoundTripTest() override = default;
25
QUICHE team232cf492020-10-27 08:21:26 -070026 spdy::Http2HeaderBlock EncodeThenDecode(
27 const spdy::Http2HeaderBlock& header_list) {
QUICHE teama6ef0a62019-03-07 20:34:33 -050028 NoopDecoderStreamErrorDelegate decoder_stream_error_delegate;
renjietangc2aa5cb2019-06-20 12:22:53 -070029 NoopQpackStreamSenderDelegate encoder_stream_sender_delegate;
renjietang8a2df8f2019-08-07 10:43:52 -070030 QpackEncoder encoder(&decoder_stream_error_delegate);
31 encoder.set_qpack_stream_sender_delegate(&encoder_stream_sender_delegate);
bncf21c1ad2019-06-20 20:09:50 -070032 std::string encoded_header_block =
bnc609c24e2019-09-10 05:24:32 -070033 encoder.EncodeHeaderList(/* stream_id = */ 1, header_list, nullptr);
QUICHE teama6ef0a62019-03-07 20:34:33 -050034
35 TestHeadersHandler handler;
36 NoopEncoderStreamErrorDelegate encoder_stream_error_delegate;
renjietangc2aa5cb2019-06-20 12:22:53 -070037 NoopQpackStreamSenderDelegate decoder_stream_sender_delegate;
bnc4c664c52019-08-04 18:14:12 -070038 // TODO(b/112770235): Test dynamic table and blocked streams.
39 QpackDecode(
40 /* maximum_dynamic_table_capacity = */ 0,
41 /* maximum_blocked_streams = */ 0, &encoder_stream_error_delegate,
42 &decoder_stream_sender_delegate, &handler,
43 FragmentModeToFragmentSizeGenerator(GetParam()), encoded_header_block);
QUICHE teama6ef0a62019-03-07 20:34:33 -050044
45 EXPECT_TRUE(handler.decoding_completed());
46 EXPECT_FALSE(handler.decoding_error_detected());
47
48 return handler.ReleaseHeaderList();
49 }
QUICHE teama6ef0a62019-03-07 20:34:33 -050050};
51
QUICHE team1bfe0d72019-09-23 04:50:47 -070052INSTANTIATE_TEST_SUITE_P(All,
bncf21c1ad2019-06-20 20:09:50 -070053 QpackRoundTripTest,
54 Values(FragmentMode::kSingleChunk,
55 FragmentMode::kOctetByOctet));
QUICHE teama6ef0a62019-03-07 20:34:33 -050056
57TEST_P(QpackRoundTripTest, Empty) {
QUICHE team232cf492020-10-27 08:21:26 -070058 spdy::Http2HeaderBlock header_list;
59 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -050060 EXPECT_EQ(header_list, output);
61}
62
63TEST_P(QpackRoundTripTest, EmptyName) {
QUICHE team232cf492020-10-27 08:21:26 -070064 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -050065 header_list["foo"] = "bar";
66 header_list[""] = "bar";
67
QUICHE team232cf492020-10-27 08:21:26 -070068 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -050069 EXPECT_EQ(header_list, output);
70}
71
72TEST_P(QpackRoundTripTest, EmptyValue) {
QUICHE team232cf492020-10-27 08:21:26 -070073 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -050074 header_list["foo"] = "";
75 header_list[""] = "";
76
QUICHE team232cf492020-10-27 08:21:26 -070077 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -050078 EXPECT_EQ(header_list, output);
79}
80
81TEST_P(QpackRoundTripTest, MultipleWithLongEntries) {
QUICHE team232cf492020-10-27 08:21:26 -070082 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -050083 header_list["foo"] = "bar";
84 header_list[":path"] = "/";
vasilvvc48c8712019-03-11 13:38:16 -070085 header_list["foobaar"] = std::string(127, 'Z');
86 header_list[std::string(1000, 'b')] = std::string(1000, 'c');
QUICHE teama6ef0a62019-03-07 20:34:33 -050087
QUICHE team232cf492020-10-27 08:21:26 -070088 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -050089 EXPECT_EQ(header_list, output);
90}
91
92TEST_P(QpackRoundTripTest, StaticTable) {
93 {
QUICHE team232cf492020-10-27 08:21:26 -070094 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -050095 header_list[":method"] = "GET";
96 header_list["accept-encoding"] = "gzip, deflate";
97 header_list["cache-control"] = "";
98 header_list["foo"] = "bar";
99 header_list[":path"] = "/";
100
QUICHE team232cf492020-10-27 08:21:26 -0700101 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102 EXPECT_EQ(header_list, output);
103 }
104 {
QUICHE team232cf492020-10-27 08:21:26 -0700105 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500106 header_list[":method"] = "POST";
107 header_list["accept-encoding"] = "brotli";
108 header_list["cache-control"] = "foo";
109 header_list["foo"] = "bar";
110 header_list[":path"] = "/";
111
QUICHE team232cf492020-10-27 08:21:26 -0700112 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500113 EXPECT_EQ(header_list, output);
114 }
115 {
QUICHE team232cf492020-10-27 08:21:26 -0700116 spdy::Http2HeaderBlock header_list;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500117 header_list[":method"] = "CONNECT";
118 header_list["accept-encoding"] = "";
119 header_list["foo"] = "bar";
120 header_list[":path"] = "/";
121
QUICHE team232cf492020-10-27 08:21:26 -0700122 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500123 EXPECT_EQ(header_list, output);
124 }
125}
126
bnc78053612019-04-25 20:08:12 -0700127TEST_P(QpackRoundTripTest, ValueHasNullCharacter) {
QUICHE team232cf492020-10-27 08:21:26 -0700128 spdy::Http2HeaderBlock header_list;
vasilvv7cac7b02020-10-08 12:32:10 -0700129 header_list["foo"] = absl::string_view("bar\0bar\0baz", 11);
bnc78053612019-04-25 20:08:12 -0700130
QUICHE team232cf492020-10-27 08:21:26 -0700131 spdy::Http2HeaderBlock output = EncodeThenDecode(header_list);
bnc78053612019-04-25 20:08:12 -0700132 EXPECT_EQ(header_list, output);
133}
134
QUICHE teama6ef0a62019-03-07 20:34:33 -0500135} // namespace
136} // namespace test
137} // namespace quic