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

Unified Diff: net/quic/core/spdy_utils_test.cc

Issue 2964583002: Landing Recent QUIC changes until Jun 27 19:50:48 2017 +0000 (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | net/quic/platform/api/quic_logging.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/spdy_utils_test.cc
diff --git a/net/quic/core/spdy_utils_test.cc b/net/quic/core/spdy_utils_test.cc
index 1b19488f4cd84671fedd77cd0d526cbe83276dbc..6acfc83d01b987b2bbcc754e916ac399f2e01046 100644
--- a/net/quic/core/spdy_utils_test.cc
+++ b/net/quic/core/spdy_utils_test.cc
@@ -6,8 +6,9 @@
#include <memory>
#include "base/macros.h"
+#include "net/quic/platform/api/quic_flag_utils.h"
+#include "net/quic/platform/api/quic_flags.h"
#include "net/quic/platform/api/quic_string_piece.h"
-#include "net/quic/platform/api/quic_test.h"
#include "net/quic/platform/api/quic_text_utils.h"
#include "net/test/gtest_util.h"
@@ -29,9 +30,7 @@ static std::unique_ptr<QuicHeaderList> FromList(
return headers;
}
-class SpdyUtilsTest : public QuicTest {};
-
-TEST_F(SpdyUtilsTest, CopyAndValidateHeaders) {
+TEST(CopyAndValidateHeaders, NormalUsage) {
auto headers = FromList({// All cookie crumbs are joined.
{"cookie", " part 1"},
{"cookie", "part 2 "},
@@ -70,7 +69,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeaders) {
EXPECT_EQ(-1, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) {
+TEST(CopyAndValidateHeaders, EmptyName) {
auto headers = FromList({{"foo", "foovalue"}, {"", "barvalue"}, {"baz", ""}});
int64_t content_length = -1;
SpdyHeaderBlock block;
@@ -78,7 +77,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersEmptyName) {
SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) {
+TEST(CopyAndValidateHeaders, UpperCaseName) {
auto headers =
FromList({{"foo", "foovalue"}, {"bar", "barvalue"}, {"bAz", ""}});
int64_t content_length = -1;
@@ -87,7 +86,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersUpperCaseName) {
SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) {
+TEST(CopyAndValidateHeaders, MultipleContentLengths) {
auto headers = FromList({{"content-length", "9"},
{"foo", "foovalue"},
{"content-length", "9"},
@@ -107,7 +106,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleContentLengths) {
EXPECT_EQ(9, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) {
+TEST(CopyAndValidateHeaders, InconsistentContentLengths) {
auto headers = FromList({{"content-length", "9"},
{"foo", "foovalue"},
{"content-length", "8"},
@@ -119,7 +118,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersInconsistentContentLengths) {
SpdyUtils::CopyAndValidateHeaders(*headers, &content_length, &block));
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersLargeContentLength) {
+TEST(CopyAndValidateHeaders, LargeContentLength) {
auto headers = FromList({{"content-length", "9000000000"},
{"foo", "foovalue"},
{"bar", "barvalue"},
@@ -135,7 +134,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersLargeContentLength) {
EXPECT_EQ(9000000000, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) {
+TEST(CopyAndValidateHeaders, MultipleValues) {
auto headers = FromList({{"foo", "foovalue"},
{"bar", "barvalue"},
{"baz", ""},
@@ -152,7 +151,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleValues) {
EXPECT_EQ(-1, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMoreThanTwoValues) {
+TEST(CopyAndValidateHeaders, MoreThanTwoValues) {
auto headers = FromList({{"set-cookie", "value1"},
{"set-cookie", "value2"},
{"set-cookie", "value3"}});
@@ -166,7 +165,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMoreThanTwoValues) {
EXPECT_EQ(-1, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersCookie) {
+TEST(CopyAndValidateHeaders, Cookie) {
auto headers = FromList({{"foo", "foovalue"},
{"bar", "barvalue"},
{"cookie", "value1"},
@@ -181,7 +180,7 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersCookie) {
EXPECT_EQ(-1, content_length);
}
-TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) {
+TEST(CopyAndValidateHeaders, MultipleCookies) {
auto headers = FromList({{"foo", "foovalue"},
{"bar", "barvalue"},
{"cookie", "value1"},
@@ -197,7 +196,108 @@ TEST_F(SpdyUtilsTest, CopyAndValidateHeadersMultipleCookies) {
EXPECT_EQ(-1, content_length);
}
-TEST_F(SpdyUtilsTest, GetUrlFromHeaderBlock) {
+TEST(CopyAndValidateTrailers, SimplestValidList) {
+ // Verify that the simplest trailers are valid: just a final byte offset that
+ // gets parsed successfully.
+ auto trailers = FromList({{kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+ EXPECT_EQ(1234u, final_byte_offset);
+}
+
+TEST(CopyAndValidateTrailers, EmptyTrailerList) {
+ // An empty trailer list will fail as required key kFinalOffsetHeaderKey is
+ // not present.
+ QuicHeaderList trailers;
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(
+ SpdyUtils::CopyAndValidateTrailers(trailers, &final_byte_offset, &block));
+}
+
+TEST(CopyAndValidateTrailers, FinalByteOffsetNotPresent) {
+ // Validation fails if required kFinalOffsetHeaderKey is not present, even if
+ // the rest of the header block is valid.
+ auto trailers = FromList({{"key", "value"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, EmptyName) {
+ // Trailer validation will fail with an empty header key, in an otherwise
+ // valid block of trailers.
+ auto trailers = FromList({{"", "value"}, {kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, PseudoHeaderInTrailers) {
+ // Pseudo headers are illegal in trailers.
+ auto trailers =
+ FromList({{":pseudo_key", "value"}, {kFinalOffsetHeaderKey, "1234"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_FALSE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+}
+
+TEST(CopyAndValidateTrailers, DuplicateTrailers) {
+ // Duplicate trailers are allowed, and their values are concatenated into a
+ // single string delimted with '\0'. Some of the duplicate headers
+ // deliberately have an empty value.
+ FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
+ auto trailers = FromList({{"key", "value0"},
+ {"key", "value1"},
+ {"key", ""},
+ {"key", ""},
+ {"key", "value2"},
+ {"key", ""},
+ {kFinalOffsetHeaderKey, "1234"},
+ {"other_key", "value"},
+ {"key", "non_contiguous_duplicate"}});
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_TRUE(SpdyUtils::CopyAndValidateTrailers(*trailers, &final_byte_offset,
+ &block));
+ EXPECT_THAT(
+ block,
+ UnorderedElementsAre(
+ Pair("key",
+ QuicStringPiece(
+ "value0\0value1\0\0\0value2\0\0non_contiguous_duplicate",
+ 48)),
+ Pair("other_key", "value")));
+}
+
+TEST(CopyAndValidateTrailers, DuplicateCookies) {
+ // Duplicate cookie headers in trailers should be concatenated into a single
+ // "; " delimted string.
+ FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers = true;
+ auto headers = FromList({{"cookie", " part 1"},
+ {"cookie", "part 2 "},
+ {"cookie", "part3"},
+ {"key", "value"},
+ {kFinalOffsetHeaderKey, "1234"},
+ {"cookie", " non_contiguous_cookie!"}});
+
+ size_t final_byte_offset = 0;
+ SpdyHeaderBlock block;
+ EXPECT_TRUE(
+ SpdyUtils::CopyAndValidateTrailers(*headers, &final_byte_offset, &block));
+ EXPECT_THAT(
+ block,
+ UnorderedElementsAre(
+ Pair("cookie", " part 1; part 2 ; part3; non_contiguous_cookie!"),
+ Pair("key", "value")));
+}
+
+TEST(GetUrlFromHeaderBlock, Basic) {
SpdyHeaderBlock headers;
EXPECT_EQ(SpdyUtils::GetUrlFromHeaderBlock(headers), "");
headers[":scheme"] = "https";
@@ -213,7 +313,7 @@ TEST_F(SpdyUtilsTest, GetUrlFromHeaderBlock) {
"https://www.google.com/index.html");
}
-TEST_F(SpdyUtilsTest, GetHostNameFromHeaderBlock) {
+TEST(GetHostNameFromHeaderBlock, NormalUsage) {
SpdyHeaderBlock headers;
EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "");
headers[":scheme"] = "https";
@@ -233,7 +333,7 @@ TEST_F(SpdyUtilsTest, GetHostNameFromHeaderBlock) {
EXPECT_EQ(SpdyUtils::GetHostNameFromHeaderBlock(headers), "192.168.1.1");
}
-TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrl) {
+TEST(PopulateHeaderBlockFromUrl, NormalUsage) {
string url = "https://www.google.com/index.html";
SpdyHeaderBlock headers;
EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
@@ -242,7 +342,7 @@ TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrl) {
EXPECT_EQ("/index.html", headers[":path"].as_string());
}
-TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlWithNoPath) {
+TEST(PopulateHeaderBlockFromUrl, UrlWithNoPath) {
string url = "https://www.google.com";
SpdyHeaderBlock headers;
EXPECT_TRUE(SpdyUtils::PopulateHeaderBlockFromUrl(url, &headers));
@@ -251,7 +351,7 @@ TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlWithNoPath) {
EXPECT_EQ("/", headers[":path"].as_string());
}
-TEST_F(SpdyUtilsTest, PopulateHeaderBlockFromUrlFails) {
+TEST(PopulateHeaderBlockFromUrl, Failure) {
SpdyHeaderBlock headers;
EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/", &headers));
EXPECT_FALSE(SpdyUtils::PopulateHeaderBlockFromUrl("/index.html", &headers));
« no previous file with comments | « net/quic/core/spdy_utils.cc ('k') | net/quic/platform/api/quic_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698