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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <limits> 6 #include <limits>
7 7
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "net/http/http_util.h" 9 #include "net/http/http_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 EXPECT_FALSE(HttpUtil::IsLWS('1')); 1315 EXPECT_FALSE(HttpUtil::IsLWS('1'));
1316 EXPECT_FALSE(HttpUtil::IsLWS('a')); 1316 EXPECT_FALSE(HttpUtil::IsLWS('a'));
1317 EXPECT_FALSE(HttpUtil::IsLWS('.')); 1317 EXPECT_FALSE(HttpUtil::IsLWS('.'));
1318 EXPECT_FALSE(HttpUtil::IsLWS('\n')); 1318 EXPECT_FALSE(HttpUtil::IsLWS('\n'));
1319 EXPECT_FALSE(HttpUtil::IsLWS('\r')); 1319 EXPECT_FALSE(HttpUtil::IsLWS('\r'));
1320 1320
1321 EXPECT_TRUE(HttpUtil::IsLWS('\t')); 1321 EXPECT_TRUE(HttpUtil::IsLWS('\t'));
1322 EXPECT_TRUE(HttpUtil::IsLWS(' ')); 1322 EXPECT_TRUE(HttpUtil::IsLWS(' '));
1323 } 1323 }
1324 1324
1325 TEST(HttpUtilTest, ParseAcceptEncoding) {
1326 const struct {
1327 const char* const value;
1328 const char* const expected;
1329 } tests[] = {
1330 {"", "*"},
1331 {"identity;q=1, *;q=0", "identity"},
1332 {"identity", "identity"},
1333 {"FOO, Bar", "bar|foo|identity"},
1334 {"foo; q=1", "foo|identity"},
1335 {"abc, foo; Q=1.0", "abc|foo|identity"},
1336 {"abc, foo;q= 1.00 , bar", "abc|bar|foo|identity"},
1337 {"abc, foo; q=1.000, bar", "abc|bar|foo|identity"},
1338 {"abc, foo ; q = 0 , bar", "abc|bar|identity"},
1339 {"abc, foo; q=0.0, bar", "abc|bar|identity"},
1340 {"abc, foo; q=0.00, bar", "abc|bar|identity"},
1341 {"abc, foo; q=0.000, bar", "abc|bar|identity"},
1342 {"abc, foo; q=0.001, bar", "abc|bar|foo|identity"},
1343 {"gzip", "gzip|identity|x-gzip"},
1344 {"x-gzip", "gzip|identity|x-gzip"},
1345 {"compress", "compress|identity|x-compress"},
1346 {"x-compress", "compress|identity|x-compress"},
1347 {"x-compress", "compress|identity|x-compress"},
1348 {"foo bar", "INVALID"},
1349 {"foo;", "INVALID"},
1350 {"foo;w=1", "INVALID"},
1351 {"foo;q+1", "INVALID"},
1352 {"foo;q=2", "INVALID"},
1353 {"foo;q=1.001", "INVALID"},
1354 {"foo;q=0.", "INVALID"},
1355 {"foo,\"bar\"", "INVALID"},
1356 };
1357
1358 for (size_t i = 0; i < arraysize(tests); ++i) {
1359 std::string value(tests[i].value);
1360 std::string reformatted;
1361 std::set<std::string> allowed_encodings;
1362 if (!HttpUtil::ParseAcceptEncoding(value, &allowed_encodings)) {
1363 reformatted = "INVALID";
1364 } else {
1365 std::vector<std::string> encodings_list;
1366 for (auto const& encoding : allowed_encodings)
1367 encodings_list.push_back(encoding);
1368 reformatted = base::JoinString(encodings_list, "|");
1369 }
1370 EXPECT_STREQ(tests[i].expected, reformatted.c_str())
1371 << "value=\"" << value << "\"";
1372 }
1373 }
1374
1375 TEST(HttpUtilTest, ParseContentEncoding) {
1376 const struct {
1377 const char* const value;
1378 const char* const expected;
1379 } tests[] = {
1380 {"", ""},
1381 {"identity;q=1, *;q=0", "INVALID"},
1382 {"identity", "identity"},
1383 {"FOO, zergli , Bar", "bar|foo|zergli"},
1384 {"foo, *", "INVALID"},
1385 {"foo,\"bar\"", "INVALID"},
1386 };
1387
1388 for (size_t i = 0; i < arraysize(tests); ++i) {
1389 std::string value(tests[i].value);
1390 std::string reformatted;
1391 std::set<std::string> used_encodings;
1392 if (!HttpUtil::ParseContentEncoding(value, &used_encodings)) {
1393 reformatted = "INVALID";
1394 } else {
1395 std::vector<std::string> encodings_list;
1396 for (auto const& encoding : used_encodings)
1397 encodings_list.push_back(encoding);
1398 reformatted = base::JoinString(encodings_list, "|");
1399 }
1400 EXPECT_STREQ(tests[i].expected, reformatted.c_str())
1401 << "value=\"" << value << "\"";
1402 }
1403 }
1404
1325 } // namespace net 1405 } // namespace net
OLDNEW
« 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