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

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

Issue 2961123002: Add tests for gfe/quic/spdy_utils::CopyAndValidateTrailers. (Closed)
Patch Set: Rebase Created 3 years, 5 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 | « no previous file | no next file » | 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/core/spdy_utils.h" 4 #include "net/quic/core/spdy_utils.h"
5 5
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "net/quic/platform/api/quic_string_piece.h" 9 #include "net/quic/platform/api/quic_string_piece.h"
10 #include "net/quic/platform/api/quic_text_utils.h" 10 #include "net/quic/platform/api/quic_text_utils.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int64_t content_length = -1; 187 int64_t content_length = -1;
188 SpdyHeaderBlock block; 188 SpdyHeaderBlock block;
189 ASSERT_TRUE( 189 ASSERT_TRUE(
190 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block)); 190 SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
191 EXPECT_THAT(block, UnorderedElementsAre( 191 EXPECT_THAT(block, UnorderedElementsAre(
192 Pair("foo", "foovalue"), Pair("bar", "barvalue"), 192 Pair("foo", "foovalue"), Pair("bar", "barvalue"),
193 Pair("cookie", "value1; value2"), Pair("baz", ""))); 193 Pair("cookie", "value1; value2"), Pair("baz", "")));
194 EXPECT_EQ(-1, content_length); 194 EXPECT_EQ(-1, content_length);
195 } 195 }
196 196
197 TEST(CopyAndValidateTrailers, SimplestValidList) {
198 // Verify that the simplest trailers are valid: just a final byte offset that
199 // gets parsed successfully.
200 auto trailers = FromList({{kFinalOffsetHeaderKey, "1234"}});
201 size_t final_byte_offset = 0;
202 SpdyHeaderBlock block;
203 EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
204 &block));
205 EXPECT_EQ(1234u, final_byte_offset);
206 }
207
208 TEST(CopyAndValidateTrailers, EmptyTrailerList) {
209 // An empty trailer list will fail as required key kFinalOffsetHeaderKey is
210 // not present.
211 QuicHeaderList trailers;
212 size_t final_byte_offset = 0;
213 SpdyHeaderBlock block;
214 EXPECT_FALSE(
215 SpdyUtils::CopyAndValidateTrailers(trailers, &final_byte_offset, &block));
216 }
217
218 TEST(CopyAndValidateTrailers, FinalByteOffsetNotPresent) {
219 // Validation fails if required kFinalOffsetHeaderKey is not present, even if
220 // the rest of the header block is valid.
221 auto trailers = FromList({{"key", "value"}});
222 size_t final_byte_offset = 0;
223 SpdyHeaderBlock block;
224 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
225 &block));
226 }
227
228 TEST(CopyAndValidateTrailers, EmptyName) {
229 // Trailer validation will fail with an empty header key, in an otherwise
230 // valid block of trailers.
231 auto trailers = FromList({{"", "value"}, {kFinalOffsetHeaderKey, "1234"}});
232 size_t final_byte_offset = 0;
233 SpdyHeaderBlock block;
234 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
235 &block));
236 }
237
238 TEST(CopyAndValidateTrailers, PseudoHeaderInTrailers) {
239 // Pseudo headers are illegal in trailers.
240 auto trailers =
241 FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}});
242 size_t final_byte_offset = 0;
243 SpdyHeaderBlock block;
244 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
245 &block));
246 }
247
248 TEST(CopyAndValidateTrailers, DuplicateTrailers) {
249 // Duplicate trailers are not allowed.
250 auto trailers = FromList({{"key", "value0"},
251 {"key", "value1"},
252 {"key", ""},
253 {"key", ""},
254 {"key", "value2"},
255 {"key", ""},
256 {kFinalOffsetHeaderKey, "1234"},
257 {"other_key", "value"},
258 {"key", "non_contiguous_duplicate"}});
259 size_t final_byte_offset = 0;
260 SpdyHeaderBlock block;
261 EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
262 &block));
263 }
264
197 TEST(GetUrlFromHeaderBlock, Basic) { 265 TEST(GetUrlFromHeaderBlock, Basic) {
198 SpdyHeaderBlock headers; 266 SpdyHeaderBlock headers;
199 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 267 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
200 headers[":scheme"] = "https"; 268 headers[":scheme"] = "https";
201 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 269 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
202 headers[":authority"] = "www.google.com"; 270 headers[":authority"] = "www.google.com";
203 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), ""); 271 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
204 headers[":path"] = "/index.html"; 272 headers[":path"] = "/index.html";
205 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), 273 EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers),
206 "https://www.google.com/index.html"); 274 "https://www.google.com/index.html");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 TEST(PopulateHeaderBlockFromUrl, Failure) { 319 TEST(PopulateHeaderBlockFromUrl, Failure) {
252 SpdyHeaderBlock headers; 320 SpdyHeaderBlock headers;
253 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers)); 321 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers));
254 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers)); 322 EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers));
255 EXPECT_FALSE( 323 EXPECT_FALSE(
256 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers)); 324 SpdyUtils::PopulateHeaderBlockFromUrl("www.google.com/", &headers));
257 } 325 }
258 326
259 } // namespace test 327 } // namespace test
260 } // namespace net 328 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698