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

Unified Diff: net/http/http_util_unittest.cc

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Fix histo value comments Created 3 years, 8 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/http/http_util.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_util_unittest.cc
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
index 3560e2f477600b721df0fd2b93ebe75cc81a3e35..f56f48ebdae0ae3254ad2cc1b4c558399265c802 100644
--- a/net/http/http_util_unittest.cc
+++ b/net/http/http_util_unittest.cc
@@ -1322,4 +1322,84 @@ TEST(HttpUtilTest, IsLWS) {
EXPECT_TRUE(HttpUtil::IsLWS(' '));
}
+TEST(HttpUtilTest, ParseAcceptEncoding) {
+ const struct {
+ const char* const value;
+ const char* const expected;
+ } tests[] = {
+ {"", "*"},
+ {"identity;q=1, *;q=0", "identity"},
+ {"identity", "identity"},
+ {"FOO, Bar", "bar|foo|identity"},
+ {"foo; q=1", "foo|identity"},
+ {"abc, foo; Q=1.0", "abc|foo|identity"},
+ {"abc, foo;q= 1.00 , bar", "abc|bar|foo|identity"},
+ {"abc, foo; q=1.000, bar", "abc|bar|foo|identity"},
+ {"abc, foo ; q = 0 , bar", "abc|bar|identity"},
+ {"abc, foo; q=0.0, bar", "abc|bar|identity"},
+ {"abc, foo; q=0.00, bar", "abc|bar|identity"},
+ {"abc, foo; q=0.000, bar", "abc|bar|identity"},
+ {"abc, foo; q=0.001, bar", "abc|bar|foo|identity"},
+ {"gzip", "gzip|identity|x-gzip"},
+ {"x-gzip", "gzip|identity|x-gzip"},
+ {"compress", "compress|identity|x-compress"},
+ {"x-compress", "compress|identity|x-compress"},
+ {"x-compress", "compress|identity|x-compress"},
+ {"foo bar", "INVALID"},
+ {"foo;", "INVALID"},
+ {"foo;w=1", "INVALID"},
+ {"foo;q+1", "INVALID"},
+ {"foo;q=2", "INVALID"},
+ {"foo;q=1.001", "INVALID"},
+ {"foo;q=0.", "INVALID"},
+ {"foo,\"bar\"", "INVALID"},
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ std::string value(tests[i].value);
+ std::string reformatted;
+ std::set<std::string> allowed_encodings;
+ if (!HttpUtil::ParseAcceptEncoding(value, &allowed_encodings)) {
+ reformatted = "INVALID";
+ } else {
+ std::vector<std::string> encodings_list;
+ for (auto const& encoding : allowed_encodings)
+ encodings_list.push_back(encoding);
+ reformatted = base::JoinString(encodings_list, "|");
+ }
+ EXPECT_STREQ(tests[i].expected, reformatted.c_str())
+ << "value=\"" << value << "\"";
+ }
+}
+
+TEST(HttpUtilTest, ParseContentEncoding) {
+ const struct {
+ const char* const value;
+ const char* const expected;
+ } tests[] = {
+ {"", ""},
+ {"identity;q=1, *;q=0", "INVALID"},
+ {"identity", "identity"},
+ {"FOO, zergli , Bar", "bar|foo|zergli"},
+ {"foo, *", "INVALID"},
+ {"foo,\"bar\"", "INVALID"},
+ };
+
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ std::string value(tests[i].value);
+ std::string reformatted;
+ std::set<std::string> used_encodings;
+ if (!HttpUtil::ParseContentEncoding(value, &used_encodings)) {
+ reformatted = "INVALID";
+ } else {
+ std::vector<std::string> encodings_list;
+ for (auto const& encoding : used_encodings)
+ encodings_list.push_back(encoding);
+ reformatted = base::JoinString(encodings_list, "|");
+ }
+ EXPECT_STREQ(tests[i].expected, reformatted.c_str())
+ << "value=\"" << value << "\"";
+ }
+}
+
} // namespace net
« no previous file with comments | « net/http/http_util.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698