Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: net/quic/spdy_utils_test.cc

Issue 1979763002: Landing Recent QUIC changes until Sun May 8 00:39:29 2016 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/spdy_utils.cc ('k') | net/quic/test_tools/crypto_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "net/quic/spdy_utils.h" 4 #include "net/quic/spdy_utils.h"
5 5
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h"
8 #include "net/test/gtest_util.h" 9 #include "net/test/gtest_util.h"
9 10
11 using base::StringPiece;
10 using std::string; 12 using std::string;
13 using testing::UnorderedElementsAre;
14 using testing::Pair;
11 15
12 namespace net { 16 namespace net {
13 namespace test { 17 namespace test {
14 18
15 TEST(SpdyUtilsTest, SerializeAndParseHeaders) { 19 TEST(SpdyUtilsTest, SerializeAndParseHeaders) {
16 // Creates a SpdyHeaderBlock with some key->value pairs, serializes it, then 20 // Creates a SpdyHeaderBlock with some key->value pairs, serializes it, then
17 // parses the serialized output and verifies that the end result is the same 21 // parses the serialized output and verifies that the end result is the same
18 // as the headers that the test started with. 22 // as the headers that the test started with.
19 23
20 SpdyHeaderBlock input_headers; 24 SpdyHeaderBlock input_headers;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 string serialized_trailers = 105 string serialized_trailers =
102 SpdyUtils::SerializeUncompressedHeaders(input_trailers); 106 SpdyUtils::SerializeUncompressedHeaders(input_trailers);
103 107
104 // Parsing the serialized trailers fails because of the extra pseudo header. 108 // Parsing the serialized trailers fails because of the extra pseudo header.
105 SpdyHeaderBlock output_trailers; 109 SpdyHeaderBlock output_trailers;
106 size_t final_byte_offset = 0; 110 size_t final_byte_offset = 0;
107 EXPECT_FALSE(SpdyUtils::ParseTrailers(serialized_trailers.data(), 111 EXPECT_FALSE(SpdyUtils::ParseTrailers(serialized_trailers.data(),
108 serialized_trailers.size(), 112 serialized_trailers.size(),
109 &final_byte_offset, &output_trailers)); 113 &final_byte_offset, &output_trailers));
110 } 114 }
115 static std::unique_ptr<QuicHeaderList> FromList(
116 const QuicHeaderList::ListType& src) {
117 std::unique_ptr<QuicHeaderList> headers(new QuicHeaderList);
118 headers->OnHeaderBlockStart();
119 for (const auto& p : src) {
120 headers->OnHeader(p.first, p.second);
121 }
122 headers->OnHeaderBlockEnd(0);
123 return headers;
124 }
125
126 TEST(SpdyUtilsTest, CopyAndValidateHeaders) {
127 auto headers =
128 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"baz", ""}});
129 int64_t content_length = -1;
130 SpdyHeaderBlock block;
131 ASSERT_TRUE(
132 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
133 EXPECT_THAT(block,
134 UnorderedElementsAre(Pair("foo", "foovalue"),
135 Pair("bar", "barvalue"), Pair("baz", "")));
136 EXPECT_EQ(-1, content_length);
137 }
138
139 TEST(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) {
140 auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}});
141 int64_t content_length = -1;
142 SpdyHeaderBlock block;
143 ASSERT_FALSE(
144 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
145 }
146
147 TEST(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) {
148 auto headers =
149 FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}});
150 int64_t content_length = -1;
151 SpdyHeaderBlock block;
152 ASSERT_FALSE(
153 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
154 }
155
156 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) {
157 auto headers = FromList({{"content-length", "9"},
158 {"foo", "foovalue"},
159 {"content-length", "9"},
160 {"bar", "barvalue"},
161 {"baz", ""}});
162 int64_t content_length = -1;
163 SpdyHeaderBlock block;
164 ASSERT_TRUE(
165 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
166 EXPECT_THAT(block, UnorderedElementsAre(
167 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
168 Pair("content-length", StringPiece("9"
169 "\0"
170 "9",
171 3)),
172 Pair("baz", "")));
173 EXPECT_EQ(9, content_length);
174 }
175
176 TEST(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) {
177 auto headers = FromList({{"content-length", "9"},
178 {"foo", "foovalue"},
179 {"content-length", "8"},
180 {"bar", "barvalue"},
181 {"baz", ""}});
182 int64_t content_length = -1;
183 SpdyHeaderBlock block;
184 ASSERT_FALSE(
185 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
186 }
187
188 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) {
189 auto headers = FromList({{"foo", "foovalue"},
190 {"bar", "barvalue"},
191 {"baz", ""},
192 {"foo", "boo"},
193 {"baz", "buzz"}});
194 int64_t content_length = -1;
195 SpdyHeaderBlock block;
196 ASSERT_TRUE(
197 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
198 EXPECT_THAT(
199 block, UnorderedElementsAre(Pair("foo", StringPiece("foovalue\0boo", 12)),
200 Pair("bar", "barvalue"),
201 Pair("baz", StringPiece("\0buzz", 5))));
202 EXPECT_EQ(-1, content_length);
203 }
204
205 TEST(SpdyUtilsTest, CopyAndValidateHeadersCookie) {
206 auto headers = FromList({{"foo", "foovalue"},
207 {"bar", "barvalue"},
208 {"cookie", "value1"},
209 {"baz", ""}});
210 int64_t content_length = -1;
211 SpdyHeaderBlock block;
212 ASSERT_TRUE(
213 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
214 EXPECT_THAT(block, UnorderedElementsAre(
215 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
216 Pair("cookie", "value1"), Pair("baz", "")));
217 EXPECT_EQ(-1, content_length);
218 }
219
220 TEST(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) {
221 auto headers = FromList({{"foo", "foovalue"},
222 {"bar", "barvalue"},
223 {"cookie", "value1"},
224 {"baz", ""},
225 {"cookie", "value2"}});
226 int64_t content_length = -1;
227 SpdyHeaderBlock block;
228 ASSERT_TRUE(
229 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
230 EXPECT_THAT(block, UnorderedElementsAre(
231 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
232 Pair("cookie", "value1; value2"), Pair("baz", "")));
233 EXPECT_EQ(-1, content_length);
234 }
111 235
112 TEST(SpdyUtilsTest, GetUrlFromHeaderBlock) { 236 TEST(SpdyUtilsTest, GetUrlFromHeaderBlock) {
113 SpdyHeaderBlock headers; 237 SpdyHeaderBlock headers;
114 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 238 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
115 headers[":scheme"] = "https"; 239 headers[":scheme"] = "https";
116 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 240 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
117 headers[":authority"] = "www.google.com"; 241 headers[":authority"] = "www.google.com";
118 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 242 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
119 headers[":path"] = "/index.html"; 243 headers[":path"] = "/index.html";
120 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 244 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
(...skipping 30 matching lines...) Expand all
151 headers[":scheme"] = "https"; 275 headers[":scheme"] = "https";
152 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); 276 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers));
153 headers[":authority"] = "www.google.com"; 277 headers[":authority"] = "www.google.com";
154 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers)); 278 EXPECT_FALSE(SpdyUtils::UrlIsValid(headers));
155 headers[":path"] = "/index.html"; 279 headers[":path"] = "/index.html";
156 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers)); 280 EXPECT_TRUE(SpdyUtils::UrlIsValid(headers));
157 } 281 }
158 282
159 } // namespace test 283 } // namespace test
160 } // namespace net 284 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/spdy_utils.cc ('k') | net/quic/test_tools/crypto_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698