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

Side by Side Diff: net/http/http_response_headers_unittest.cc

Issue 2549143003: Cleaned up the API of HttpUtil::ParseContentRangeHeader(). (Closed)
Patch Set: Fixed unittest Created 4 years 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_response_headers.cc ('k') | net/http/http_util.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 (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 "net/http/http_response_headers.h" 5 #include "net/http/http_response_headers.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iostream> 10 #include <iostream>
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 int64_t expected_first_byte_position; 1331 int64_t expected_first_byte_position;
1332 int64_t expected_last_byte_position; 1332 int64_t expected_last_byte_position;
1333 int64_t expected_instance_size; 1333 int64_t expected_instance_size;
1334 }; 1334 };
1335 1335
1336 class ContentRangeTest 1336 class ContentRangeTest
1337 : public HttpResponseHeadersTest, 1337 : public HttpResponseHeadersTest,
1338 public ::testing::WithParamInterface<ContentRangeTestData> { 1338 public ::testing::WithParamInterface<ContentRangeTestData> {
1339 }; 1339 };
1340 1340
1341 TEST_P(ContentRangeTest, GetContentRange) { 1341 TEST_P(ContentRangeTest, GetContentRangeFor206) {
1342 const ContentRangeTestData test = GetParam(); 1342 const ContentRangeTestData test = GetParam();
1343 1343
1344 std::string headers(test.headers); 1344 std::string headers(test.headers);
1345 HeadersToRaw(&headers); 1345 HeadersToRaw(&headers);
1346 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); 1346 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
1347 1347
1348 int64_t first_byte_position; 1348 int64_t first_byte_position;
1349 int64_t last_byte_position; 1349 int64_t last_byte_position;
1350 int64_t instance_size; 1350 int64_t instance_size;
1351 bool return_value = parsed->GetContentRange(&first_byte_position, 1351 bool return_value = parsed->GetContentRangeFor206(
1352 &last_byte_position, 1352 &first_byte_position, &last_byte_position, &instance_size);
1353 &instance_size);
1354 EXPECT_EQ(test.expected_return_value, return_value); 1353 EXPECT_EQ(test.expected_return_value, return_value);
1355 EXPECT_EQ(test.expected_first_byte_position, first_byte_position); 1354 EXPECT_EQ(test.expected_first_byte_position, first_byte_position);
1356 EXPECT_EQ(test.expected_last_byte_position, last_byte_position); 1355 EXPECT_EQ(test.expected_last_byte_position, last_byte_position);
1357 EXPECT_EQ(test.expected_instance_size, instance_size); 1356 EXPECT_EQ(test.expected_instance_size, instance_size);
1358 } 1357 }
1359 1358
1360 const ContentRangeTestData content_range_tests[] = { 1359 const ContentRangeTestData content_range_tests[] = {
1361 {"HTTP/1.1 206 Partial Content", false, -1, -1, -1}, 1360 {"HTTP/1.1 206 Partial Content", false, -1, -1, -1},
1362 {"HTTP/1.1 206 Partial Content\n" 1361 {"HTTP/1.1 206 Partial Content\n"
1363 "Content-Range:", 1362 "Content-Range:",
1364 false, -1, -1, -1}, 1363 false, -1, -1, -1},
1365 {"HTTP/1.1 206 Partial Content\n" 1364 {"HTTP/1.1 206 Partial Content\n"
1366 "Content-Range: megabytes 0-10/50",
1367 false, -1, -1, -1},
1368 {"HTTP/1.1 206 Partial Content\n"
1369 "Content-Range: 0-10/50",
1370 false, -1, -1, -1},
1371 {"HTTP/1.1 206 Partial Content\n"
1372 "Content-Range: Bytes 0-50/51",
1373 true, 0, 50, 51},
1374 {"HTTP/1.1 206 Partial Content\n"
1375 "Content-Range: bytes 0-50/51", 1365 "Content-Range: bytes 0-50/51",
1376 true, 0, 50, 51}, 1366 true, 0, 50, 51},
1377 {"HTTP/1.1 206 Partial Content\n" 1367 {"HTTP/1.1 206 Partial Content\n"
1378 "Content-Range: bytes\t0-50/51",
1379 false, -1, -1, -1},
1380 {"HTTP/1.1 206 Partial Content\n"
1381 "Content-Range: bytes 0-50/51",
1382 true, 0, 50, 51},
1383 {"HTTP/1.1 206 Partial Content\n"
1384 "Content-Range: bytes 0 - 50 \t / \t51",
1385 true, 0, 50, 51},
1386 {"HTTP/1.1 206 Partial Content\n"
1387 "Content-Range: bytes 0\t-\t50\t/\t51\t",
1388 true, 0, 50, 51},
1389 {"HTTP/1.1 206 Partial Content\n"
1390 "Content-Range: \tbytes\t\t\t 0\t-\t50\t/\t51\t",
1391 true, 0, 50, 51},
1392 {"HTTP/1.1 206 Partial Content\n"
1393 "Content-Range: \t bytes \t 0 - 50 / 5 1",
1394 false, 0, 50, -1},
1395 {"HTTP/1.1 206 Partial Content\n"
1396 "Content-Range: \t bytes \t 0 - 5 0 / 51",
1397 false, -1, -1, -1},
1398 {"HTTP/1.1 206 Partial Content\n"
1399 "Content-Range: bytes 50-0/51", 1368 "Content-Range: bytes 50-0/51",
1400 false, 50, 0, -1},
1401 {"HTTP/1.1 416 Requested range not satisfiable\n"
1402 "Content-Range: bytes * /*",
1403 false, -1, -1, -1}, 1369 false, -1, -1, -1},
1404 {"HTTP/1.1 416 Requested range not satisfiable\n" 1370 {"HTTP/1.1 416 Requested range not satisfiable\n"
1405 "Content-Range: bytes * / * ", 1371 "Content-Range: bytes */*",
1406 false, -1, -1, -1}, 1372 false, -1, -1, -1},
1407 {"HTTP/1.1 206 Partial Content\n" 1373 {"HTTP/1.1 206 Partial Content\n"
1408 "Content-Range: bytes 0-50/*", 1374 "Content-Range: bytes 0-50/*",
1409 false, 0, 50, -1},
1410 {"HTTP/1.1 206 Partial Content\n"
1411 "Content-Range: bytes 0-50 / * ",
1412 false, 0, 50, -1},
1413 {"HTTP/1.1 206 Partial Content\n"
1414 "Content-Range: bytes 0-10000000000/10000000001",
1415 true, 0, 10000000000ll, 10000000001ll},
1416 {"HTTP/1.1 206 Partial Content\n"
1417 "Content-Range: bytes 0-10000000000/10000000000",
1418 false, 0, 10000000000ll, 10000000000ll},
1419 // 64 bit wraparound.
1420 {"HTTP/1.1 206 Partial Content\n"
1421 "Content-Range: bytes 0 - 9223372036854775807 / 100",
1422 false, 0, std::numeric_limits<int64_t>::max(), 100},
1423 // 64 bit wraparound.
1424 {"HTTP/1.1 206 Partial Content\n"
1425 "Content-Range: bytes 0 - 100 / -9223372036854775808",
1426 false, 0, 100, std::numeric_limits<int64_t>::min()},
1427 {"HTTP/1.1 206 Partial Content\n"
1428 "Content-Range: bytes */50",
1429 false, -1, -1, 50},
1430 {"HTTP/1.1 206 Partial Content\n"
1431 "Content-Range: bytes 0-50/10",
1432 false, 0, 50, 10},
1433 {"HTTP/1.1 206 Partial Content\n"
1434 "Content-Range: bytes 40-50/45",
1435 false, 40, 50, 45},
1436 {"HTTP/1.1 206 Partial Content\n"
1437 "Content-Range: bytes 0-50/-10",
1438 false, 0, 50, -10},
1439 {"HTTP/1.1 206 Partial Content\n"
1440 "Content-Range: bytes 0-0/1",
1441 true, 0, 0, 1},
1442 {"HTTP/1.1 206 Partial Content\n"
1443 "Content-Range: bytes 0-40000000000000000000/40000000000000000001",
1444 false, -1, -1, -1},
1445 {"HTTP/1.1 206 Partial Content\n"
1446 "Content-Range: bytes 1-/100",
1447 false, -1, -1, -1},
1448 {"HTTP/1.1 206 Partial Content\n"
1449 "Content-Range: bytes -/100",
1450 false, -1, -1, -1},
1451 {"HTTP/1.1 206 Partial Content\n"
1452 "Content-Range: bytes -1/100",
1453 false, -1, -1, -1},
1454 {"HTTP/1.1 206 Partial Content\n"
1455 "Content-Range: bytes 0-1233/*",
1456 false, 0, 1233, -1},
1457 {"HTTP/1.1 206 Partial Content\n"
1458 "Content-Range: bytes -123 - -1/100",
1459 false, -1, -1, -1}, 1375 false, -1, -1, -1},
1460 }; 1376 };
1461 1377
1462 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, 1378 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
1463 ContentRangeTest, 1379 ContentRangeTest,
1464 testing::ValuesIn(content_range_tests)); 1380 testing::ValuesIn(content_range_tests));
1465 1381
1466 struct KeepAliveTestData { 1382 struct KeepAliveTestData {
1467 const char* headers; 1383 const char* headers;
1468 bool expected_keep_alive; 1384 bool expected_keep_alive;
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 TEST_F(HttpResponseHeadersCacheControlTest, 2131 TEST_F(HttpResponseHeadersCacheControlTest,
2216 FirstStaleWhileRevalidateValueUsed) { 2132 FirstStaleWhileRevalidateValueUsed) {
2217 InitializeHeadersWithCacheControl( 2133 InitializeHeadersWithCacheControl(
2218 "stale-while-revalidate=1,stale-while-revalidate=7200"); 2134 "stale-while-revalidate=1,stale-while-revalidate=7200");
2219 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); 2135 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue());
2220 } 2136 }
2221 2137
2222 } // namespace 2138 } // namespace
2223 2139
2224 } // namespace net 2140 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_response_headers.cc ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698