OLD | NEW |
---|---|
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 <stdint.h> | |
6 | |
5 #include <algorithm> | 7 #include <algorithm> |
6 #include <iostream> | 8 #include <iostream> |
7 #include <limits> | 9 #include <limits> |
8 | 10 |
9 #include "base/basictypes.h" | |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/pickle.h" | 12 #include "base/pickle.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
15 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 true | 1193 true |
1193 }, | 1194 }, |
1194 }; | 1195 }; |
1195 | 1196 |
1196 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1197 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1197 IsRedirectTest, | 1198 IsRedirectTest, |
1198 testing::ValuesIn(is_redirect_tests)); | 1199 testing::ValuesIn(is_redirect_tests)); |
1199 | 1200 |
1200 struct ContentLengthTestData { | 1201 struct ContentLengthTestData { |
1201 const char* headers; | 1202 const char* headers; |
1202 int64 expected_len; | 1203 int64_t expected_len; |
1203 }; | 1204 }; |
1204 | 1205 |
1205 class GetContentLengthTest | 1206 class GetContentLengthTest |
1206 : public HttpResponseHeadersTest, | 1207 : public HttpResponseHeadersTest, |
1207 public ::testing::WithParamInterface<ContentLengthTestData> { | 1208 public ::testing::WithParamInterface<ContentLengthTestData> { |
1208 }; | 1209 }; |
1209 | 1210 |
1210 TEST_P(GetContentLengthTest, GetContentLength) { | 1211 TEST_P(GetContentLengthTest, GetContentLength) { |
1211 const ContentLengthTestData test = GetParam(); | 1212 const ContentLengthTestData test = GetParam(); |
1212 | 1213 |
1213 std::string headers(test.headers); | 1214 std::string headers(test.headers); |
1214 HeadersToRaw(&headers); | 1215 HeadersToRaw(&headers); |
1215 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | 1216 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
1216 | 1217 |
1217 EXPECT_EQ(test.expected_len, parsed->GetContentLength()); | 1218 EXPECT_EQ(test.expected_len, parsed->GetContentLength()); |
1218 } | 1219 } |
1219 | 1220 |
1220 const ContentLengthTestData content_length_tests[] = { | 1221 const ContentLengthTestData content_length_tests[] = { |
1221 { "HTTP/1.1 200 OK\n", | 1222 {"HTTP/1.1 200 OK\n", -1}, |
1222 -1 | 1223 {"HTTP/1.1 200 OK\n" |
1223 }, | 1224 "Content-Length: 10\n", |
1224 { "HTTP/1.1 200 OK\n" | 1225 10}, |
1225 "Content-Length: 10\n", | 1226 {"HTTP/1.1 200 OK\n" |
1226 10 | 1227 "Content-Length: \n", |
1227 }, | 1228 -1}, |
1228 { "HTTP/1.1 200 OK\n" | 1229 {"HTTP/1.1 200 OK\n" |
1229 "Content-Length: \n", | 1230 "Content-Length: abc\n", |
1230 -1 | 1231 -1}, |
1231 }, | 1232 {"HTTP/1.1 200 OK\n" |
1232 { "HTTP/1.1 200 OK\n" | 1233 "Content-Length: -10\n", |
1233 "Content-Length: abc\n", | 1234 -1}, |
1234 -1 | 1235 {"HTTP/1.1 200 OK\n" |
1235 }, | 1236 "Content-Length: +10\n", |
1236 { "HTTP/1.1 200 OK\n" | 1237 -1}, |
1237 "Content-Length: -10\n", | 1238 {"HTTP/1.1 200 OK\n" |
1238 -1 | 1239 "Content-Length: 23xb5\n", |
1239 }, | 1240 -1}, |
1240 { "HTTP/1.1 200 OK\n" | 1241 {"HTTP/1.1 200 OK\n" |
1241 "Content-Length: +10\n", | 1242 "Content-Length: 0xA\n", |
1242 -1 | 1243 -1}, |
1243 }, | 1244 {"HTTP/1.1 200 OK\n" |
1244 { "HTTP/1.1 200 OK\n" | 1245 "Content-Length: 010\n", |
1245 "Content-Length: 23xb5\n", | 1246 10}, |
1246 -1 | 1247 // Content-Length too big, will overflow an int64_t. |
1247 }, | 1248 {"HTTP/1.1 200 OK\n" |
1248 { "HTTP/1.1 200 OK\n" | 1249 "Content-Length: 40000000000000000000\n", |
1249 "Content-Length: 0xA\n", | 1250 -1}, |
1250 -1 | 1251 {"HTTP/1.1 200 OK\n" |
1251 }, | 1252 "Content-Length: 10\n", |
1252 { "HTTP/1.1 200 OK\n" | 1253 10}, |
1253 "Content-Length: 010\n", | 1254 {"HTTP/1.1 200 OK\n" |
1254 10 | 1255 "Content-Length: 10 \n", |
1255 }, | 1256 10}, |
1256 // Content-Length too big, will overflow an int64. | 1257 {"HTTP/1.1 200 OK\n" |
1257 { "HTTP/1.1 200 OK\n" | 1258 "Content-Length: \t10\n", |
1258 "Content-Length: 40000000000000000000\n", | 1259 10}, |
1259 -1 | 1260 {"HTTP/1.1 200 OK\n" |
1260 }, | 1261 "Content-Length: \v10\n", |
1261 { "HTTP/1.1 200 OK\n" | 1262 -1}, |
1262 "Content-Length: 10\n", | 1263 {"HTTP/1.1 200 OK\n" |
1263 10 | 1264 "Content-Length: \f10\n", |
1264 }, | 1265 -1}, |
1265 { "HTTP/1.1 200 OK\n" | 1266 {"HTTP/1.1 200 OK\n" |
1266 "Content-Length: 10 \n", | 1267 "cOnTeNt-LENgth: 33\n", |
1267 10 | 1268 33}, |
1268 }, | 1269 {"HTTP/1.1 200 OK\n" |
1269 { "HTTP/1.1 200 OK\n" | 1270 "Content-Length: 34\r\n", |
1270 "Content-Length: \t10\n", | 1271 -1}, |
mmenke
2015/11/25 18:33:46
I assume this is just reformatting done by git cl
Avi (use Gerrit)
2015/11/25 18:39:13
I touched the comment "int64_t" so clang format we
| |
1271 10 | |
1272 }, | |
1273 { "HTTP/1.1 200 OK\n" | |
1274 "Content-Length: \v10\n", | |
1275 -1 | |
1276 }, | |
1277 { "HTTP/1.1 200 OK\n" | |
1278 "Content-Length: \f10\n", | |
1279 -1 | |
1280 }, | |
1281 { "HTTP/1.1 200 OK\n" | |
1282 "cOnTeNt-LENgth: 33\n", | |
1283 33 | |
1284 }, | |
1285 { "HTTP/1.1 200 OK\n" | |
1286 "Content-Length: 34\r\n", | |
1287 -1 | |
1288 }, | |
1289 }; | 1272 }; |
1290 | 1273 |
1291 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1274 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1292 GetContentLengthTest, | 1275 GetContentLengthTest, |
1293 testing::ValuesIn(content_length_tests)); | 1276 testing::ValuesIn(content_length_tests)); |
1294 | 1277 |
1295 struct ContentRangeTestData { | 1278 struct ContentRangeTestData { |
1296 const char* headers; | 1279 const char* headers; |
1297 bool expected_return_value; | 1280 bool expected_return_value; |
1298 int64 expected_first_byte_position; | 1281 int64_t expected_first_byte_position; |
1299 int64 expected_last_byte_position; | 1282 int64_t expected_last_byte_position; |
1300 int64 expected_instance_size; | 1283 int64_t expected_instance_size; |
1301 }; | 1284 }; |
1302 | 1285 |
1303 class ContentRangeTest | 1286 class ContentRangeTest |
1304 : public HttpResponseHeadersTest, | 1287 : public HttpResponseHeadersTest, |
1305 public ::testing::WithParamInterface<ContentRangeTestData> { | 1288 public ::testing::WithParamInterface<ContentRangeTestData> { |
1306 }; | 1289 }; |
1307 | 1290 |
1308 TEST_P(ContentRangeTest, GetContentRange) { | 1291 TEST_P(ContentRangeTest, GetContentRange) { |
1309 const ContentRangeTestData test = GetParam(); | 1292 const ContentRangeTestData test = GetParam(); |
1310 | 1293 |
1311 std::string headers(test.headers); | 1294 std::string headers(test.headers); |
1312 HeadersToRaw(&headers); | 1295 HeadersToRaw(&headers); |
1313 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | 1296 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
1314 | 1297 |
1315 int64 first_byte_position; | 1298 int64_t first_byte_position; |
1316 int64 last_byte_position; | 1299 int64_t last_byte_position; |
1317 int64 instance_size; | 1300 int64_t instance_size; |
1318 bool return_value = parsed->GetContentRange(&first_byte_position, | 1301 bool return_value = parsed->GetContentRange(&first_byte_position, |
1319 &last_byte_position, | 1302 &last_byte_position, |
1320 &instance_size); | 1303 &instance_size); |
1321 EXPECT_EQ(test.expected_return_value, return_value); | 1304 EXPECT_EQ(test.expected_return_value, return_value); |
1322 EXPECT_EQ(test.expected_first_byte_position, first_byte_position); | 1305 EXPECT_EQ(test.expected_first_byte_position, first_byte_position); |
1323 EXPECT_EQ(test.expected_last_byte_position, last_byte_position); | 1306 EXPECT_EQ(test.expected_last_byte_position, last_byte_position); |
1324 EXPECT_EQ(test.expected_instance_size, instance_size); | 1307 EXPECT_EQ(test.expected_instance_size, instance_size); |
1325 } | 1308 } |
1326 | 1309 |
1327 const ContentRangeTestData content_range_tests[] = { | 1310 const ContentRangeTestData content_range_tests[] = { |
1328 { "HTTP/1.1 206 Partial Content", | 1311 {"HTTP/1.1 206 Partial Content", false, -1, -1, -1}, |
1329 false, | 1312 {"HTTP/1.1 206 Partial Content\n" |
1330 -1, | 1313 "Content-Range:", |
1331 -1, | 1314 false, -1, -1, -1}, |
1332 -1 | 1315 {"HTTP/1.1 206 Partial Content\n" |
1333 }, | 1316 "Content-Range: megabytes 0-10/50", |
1334 { "HTTP/1.1 206 Partial Content\n" | 1317 false, -1, -1, -1}, |
1335 "Content-Range:", | 1318 {"HTTP/1.1 206 Partial Content\n" |
1336 false, | 1319 "Content-Range: 0-10/50", |
1337 -1, | 1320 false, -1, -1, -1}, |
1338 -1, | 1321 {"HTTP/1.1 206 Partial Content\n" |
1339 -1 | 1322 "Content-Range: Bytes 0-50/51", |
1340 }, | 1323 true, 0, 50, 51}, |
1341 { "HTTP/1.1 206 Partial Content\n" | 1324 {"HTTP/1.1 206 Partial Content\n" |
1342 "Content-Range: megabytes 0-10/50", | 1325 "Content-Range: bytes 0-50/51", |
1343 false, | 1326 true, 0, 50, 51}, |
1344 -1, | 1327 {"HTTP/1.1 206 Partial Content\n" |
1345 -1, | 1328 "Content-Range: bytes\t0-50/51", |
1346 -1 | 1329 false, -1, -1, -1}, |
1347 }, | 1330 {"HTTP/1.1 206 Partial Content\n" |
1348 { "HTTP/1.1 206 Partial Content\n" | 1331 "Content-Range: bytes 0-50/51", |
1349 "Content-Range: 0-10/50", | 1332 true, 0, 50, 51}, |
1350 false, | 1333 {"HTTP/1.1 206 Partial Content\n" |
1351 -1, | 1334 "Content-Range: bytes 0 - 50 \t / \t51", |
1352 -1, | 1335 true, 0, 50, 51}, |
1353 -1 | 1336 {"HTTP/1.1 206 Partial Content\n" |
1354 }, | 1337 "Content-Range: bytes 0\t-\t50\t/\t51\t", |
1355 { "HTTP/1.1 206 Partial Content\n" | 1338 true, 0, 50, 51}, |
1356 "Content-Range: Bytes 0-50/51", | 1339 {"HTTP/1.1 206 Partial Content\n" |
1357 true, | 1340 "Content-Range: \tbytes\t\t\t 0\t-\t50\t/\t51\t", |
1358 0, | 1341 true, 0, 50, 51}, |
1359 50, | 1342 {"HTTP/1.1 206 Partial Content\n" |
1360 51 | 1343 "Content-Range: \t bytes \t 0 - 50 / 5 1", |
1361 }, | 1344 false, 0, 50, -1}, |
1362 { "HTTP/1.1 206 Partial Content\n" | 1345 {"HTTP/1.1 206 Partial Content\n" |
1363 "Content-Range: bytes 0-50/51", | 1346 "Content-Range: \t bytes \t 0 - 5 0 / 51", |
1364 true, | 1347 false, -1, -1, -1}, |
1365 0, | 1348 {"HTTP/1.1 206 Partial Content\n" |
1366 50, | 1349 "Content-Range: bytes 50-0/51", |
1367 51 | 1350 false, 50, 0, -1}, |
1368 }, | 1351 {"HTTP/1.1 416 Requested range not satisfiable\n" |
1369 { "HTTP/1.1 206 Partial Content\n" | 1352 "Content-Range: bytes * /*", |
1370 "Content-Range: bytes\t0-50/51", | 1353 false, -1, -1, -1}, |
1371 false, | 1354 {"HTTP/1.1 416 Requested range not satisfiable\n" |
1372 -1, | 1355 "Content-Range: bytes * / * ", |
1373 -1, | 1356 false, -1, -1, -1}, |
1374 -1 | 1357 {"HTTP/1.1 206 Partial Content\n" |
1375 }, | 1358 "Content-Range: bytes 0-50/*", |
1376 { "HTTP/1.1 206 Partial Content\n" | 1359 false, 0, 50, -1}, |
1377 "Content-Range: bytes 0-50/51", | 1360 {"HTTP/1.1 206 Partial Content\n" |
1378 true, | 1361 "Content-Range: bytes 0-50 / * ", |
1379 0, | 1362 false, 0, 50, -1}, |
1380 50, | 1363 {"HTTP/1.1 206 Partial Content\n" |
1381 51 | 1364 "Content-Range: bytes 0-10000000000/10000000001", |
1382 }, | 1365 true, 0, 10000000000ll, 10000000001ll}, |
1383 { "HTTP/1.1 206 Partial Content\n" | 1366 {"HTTP/1.1 206 Partial Content\n" |
1384 "Content-Range: bytes 0 - 50 \t / \t51", | 1367 "Content-Range: bytes 0-10000000000/10000000000", |
1385 true, | 1368 false, 0, 10000000000ll, 10000000000ll}, |
1386 0, | 1369 // 64 bit wraparound. |
1387 50, | 1370 {"HTTP/1.1 206 Partial Content\n" |
1388 51 | 1371 "Content-Range: bytes 0 - 9223372036854775807 / 100", |
1389 }, | 1372 false, 0, std::numeric_limits<int64_t>::max(), 100}, |
1390 { "HTTP/1.1 206 Partial Content\n" | 1373 // 64 bit wraparound. |
1391 "Content-Range: bytes 0\t-\t50\t/\t51\t", | 1374 {"HTTP/1.1 206 Partial Content\n" |
1392 true, | 1375 "Content-Range: bytes 0 - 100 / -9223372036854775808", |
1393 0, | 1376 false, 0, 100, std::numeric_limits<int64_t>::min()}, |
mmenke
2015/11/25 18:33:46
Other than the two numeric_limits line, I assume t
Avi (use Gerrit)
2015/11/25 18:39:13
Indeed it is.
| |
1394 50, | 1377 {"HTTP/1.1 206 Partial Content\n" |
1395 51 | 1378 "Content-Range: bytes */50", |
1396 }, | 1379 false, -1, -1, 50}, |
1397 { "HTTP/1.1 206 Partial Content\n" | 1380 {"HTTP/1.1 206 Partial Content\n" |
1398 "Content-Range: \tbytes\t\t\t 0\t-\t50\t/\t51\t", | 1381 "Content-Range: bytes 0-50/10", |
1399 true, | 1382 false, 0, 50, 10}, |
1400 0, | 1383 {"HTTP/1.1 206 Partial Content\n" |
1401 50, | 1384 "Content-Range: bytes 40-50/45", |
1402 51 | 1385 false, 40, 50, 45}, |
1403 }, | 1386 {"HTTP/1.1 206 Partial Content\n" |
1404 { "HTTP/1.1 206 Partial Content\n" | 1387 "Content-Range: bytes 0-50/-10", |
1405 "Content-Range: \t bytes \t 0 - 50 / 5 1", | 1388 false, 0, 50, -10}, |
1406 false, | 1389 {"HTTP/1.1 206 Partial Content\n" |
1407 0, | 1390 "Content-Range: bytes 0-0/1", |
1408 50, | 1391 true, 0, 0, 1}, |
1409 -1 | 1392 {"HTTP/1.1 206 Partial Content\n" |
1410 }, | 1393 "Content-Range: bytes 0-40000000000000000000/40000000000000000001", |
1411 { "HTTP/1.1 206 Partial Content\n" | 1394 false, -1, -1, -1}, |
1412 "Content-Range: \t bytes \t 0 - 5 0 / 51", | 1395 {"HTTP/1.1 206 Partial Content\n" |
1413 false, | 1396 "Content-Range: bytes 1-/100", |
1414 -1, | 1397 false, -1, -1, -1}, |
1415 -1, | 1398 {"HTTP/1.1 206 Partial Content\n" |
1416 -1 | 1399 "Content-Range: bytes -/100", |
1417 }, | 1400 false, -1, -1, -1}, |
1418 { "HTTP/1.1 206 Partial Content\n" | 1401 {"HTTP/1.1 206 Partial Content\n" |
1419 "Content-Range: bytes 50-0/51", | 1402 "Content-Range: bytes -1/100", |
1420 false, | 1403 false, -1, -1, -1}, |
1421 50, | 1404 {"HTTP/1.1 206 Partial Content\n" |
1422 0, | 1405 "Content-Range: bytes 0-1233/*", |
1423 -1 | 1406 false, 0, 1233, -1}, |
1424 }, | 1407 {"HTTP/1.1 206 Partial Content\n" |
1425 { "HTTP/1.1 416 Requested range not satisfiable\n" | 1408 "Content-Range: bytes -123 - -1/100", |
1426 "Content-Range: bytes * /*", | 1409 false, -1, -1, -1}, |
1427 false, | |
1428 -1, | |
1429 -1, | |
1430 -1 | |
1431 }, | |
1432 { "HTTP/1.1 416 Requested range not satisfiable\n" | |
1433 "Content-Range: bytes * / * ", | |
1434 false, | |
1435 -1, | |
1436 -1, | |
1437 -1 | |
1438 }, | |
1439 { "HTTP/1.1 206 Partial Content\n" | |
1440 "Content-Range: bytes 0-50/*", | |
1441 false, | |
1442 0, | |
1443 50, | |
1444 -1 | |
1445 }, | |
1446 { "HTTP/1.1 206 Partial Content\n" | |
1447 "Content-Range: bytes 0-50 / * ", | |
1448 false, | |
1449 0, | |
1450 50, | |
1451 -1 | |
1452 }, | |
1453 { "HTTP/1.1 206 Partial Content\n" | |
1454 "Content-Range: bytes 0-10000000000/10000000001", | |
1455 true, | |
1456 0, | |
1457 10000000000ll, | |
1458 10000000001ll | |
1459 }, | |
1460 { "HTTP/1.1 206 Partial Content\n" | |
1461 "Content-Range: bytes 0-10000000000/10000000000", | |
1462 false, | |
1463 0, | |
1464 10000000000ll, | |
1465 10000000000ll | |
1466 }, | |
1467 // 64 bit wraparound. | |
1468 { "HTTP/1.1 206 Partial Content\n" | |
1469 "Content-Range: bytes 0 - 9223372036854775807 / 100", | |
1470 false, | |
1471 0, | |
1472 kint64max, | |
1473 100 | |
1474 }, | |
1475 // 64 bit wraparound. | |
1476 { "HTTP/1.1 206 Partial Content\n" | |
1477 "Content-Range: bytes 0 - 100 / -9223372036854775808", | |
1478 false, | |
1479 0, | |
1480 100, | |
1481 kint64min | |
1482 }, | |
1483 { "HTTP/1.1 206 Partial Content\n" | |
1484 "Content-Range: bytes */50", | |
1485 false, | |
1486 -1, | |
1487 -1, | |
1488 50 | |
1489 }, | |
1490 { "HTTP/1.1 206 Partial Content\n" | |
1491 "Content-Range: bytes 0-50/10", | |
1492 false, | |
1493 0, | |
1494 50, | |
1495 10 | |
1496 }, | |
1497 { "HTTP/1.1 206 Partial Content\n" | |
1498 "Content-Range: bytes 40-50/45", | |
1499 false, | |
1500 40, | |
1501 50, | |
1502 45 | |
1503 }, | |
1504 { "HTTP/1.1 206 Partial Content\n" | |
1505 "Content-Range: bytes 0-50/-10", | |
1506 false, | |
1507 0, | |
1508 50, | |
1509 -10 | |
1510 }, | |
1511 { "HTTP/1.1 206 Partial Content\n" | |
1512 "Content-Range: bytes 0-0/1", | |
1513 true, | |
1514 0, | |
1515 0, | |
1516 1 | |
1517 }, | |
1518 { "HTTP/1.1 206 Partial Content\n" | |
1519 "Content-Range: bytes 0-40000000000000000000/40000000000000000001", | |
1520 false, | |
1521 -1, | |
1522 -1, | |
1523 -1 | |
1524 }, | |
1525 { "HTTP/1.1 206 Partial Content\n" | |
1526 "Content-Range: bytes 1-/100", | |
1527 false, | |
1528 -1, | |
1529 -1, | |
1530 -1 | |
1531 }, | |
1532 { "HTTP/1.1 206 Partial Content\n" | |
1533 "Content-Range: bytes -/100", | |
1534 false, | |
1535 -1, | |
1536 -1, | |
1537 -1 | |
1538 }, | |
1539 { "HTTP/1.1 206 Partial Content\n" | |
1540 "Content-Range: bytes -1/100", | |
1541 false, | |
1542 -1, | |
1543 -1, | |
1544 -1 | |
1545 }, | |
1546 { "HTTP/1.1 206 Partial Content\n" | |
1547 "Content-Range: bytes 0-1233/*", | |
1548 false, | |
1549 0, | |
1550 1233, | |
1551 -1 | |
1552 }, | |
1553 { "HTTP/1.1 206 Partial Content\n" | |
1554 "Content-Range: bytes -123 - -1/100", | |
1555 false, | |
1556 -1, | |
1557 -1, | |
1558 -1 | |
1559 }, | |
1560 }; | 1410 }; |
1561 | 1411 |
1562 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1412 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1563 ContentRangeTest, | 1413 ContentRangeTest, |
1564 testing::ValuesIn(content_range_tests)); | 1414 testing::ValuesIn(content_range_tests)); |
1565 | 1415 |
1566 struct KeepAliveTestData { | 1416 struct KeepAliveTestData { |
1567 const char* headers; | 1417 const char* headers; |
1568 bool expected_keep_alive; | 1418 bool expected_keep_alive; |
1569 }; | 1419 }; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2128 | 1978 |
2129 TEST_P(UpdateWithNewRangeTest, UpdateWithNewRange) { | 1979 TEST_P(UpdateWithNewRangeTest, UpdateWithNewRange) { |
2130 const UpdateWithNewRangeTestData test = GetParam(); | 1980 const UpdateWithNewRangeTestData test = GetParam(); |
2131 | 1981 |
2132 const HttpByteRange range = HttpByteRange::Bounded(3, 5); | 1982 const HttpByteRange range = HttpByteRange::Bounded(3, 5); |
2133 | 1983 |
2134 std::string orig_headers(test.orig_headers); | 1984 std::string orig_headers(test.orig_headers); |
2135 std::replace(orig_headers.begin(), orig_headers.end(), '\n', '\0'); | 1985 std::replace(orig_headers.begin(), orig_headers.end(), '\n', '\0'); |
2136 scoped_refptr<HttpResponseHeaders> parsed( | 1986 scoped_refptr<HttpResponseHeaders> parsed( |
2137 new HttpResponseHeaders(orig_headers + '\0')); | 1987 new HttpResponseHeaders(orig_headers + '\0')); |
2138 int64 content_size = parsed->GetContentLength(); | 1988 int64_t content_size = parsed->GetContentLength(); |
2139 std::string resulting_headers; | 1989 std::string resulting_headers; |
2140 | 1990 |
2141 // Update headers without replacing status line. | 1991 // Update headers without replacing status line. |
2142 parsed->UpdateWithNewRange(range, content_size, false); | 1992 parsed->UpdateWithNewRange(range, content_size, false); |
2143 parsed->GetNormalizedHeaders(&resulting_headers); | 1993 parsed->GetNormalizedHeaders(&resulting_headers); |
2144 EXPECT_EQ(std::string(test.expected_headers), resulting_headers); | 1994 EXPECT_EQ(std::string(test.expected_headers), resulting_headers); |
2145 | 1995 |
2146 // Replace status line too. | 1996 // Replace status line too. |
2147 parsed->UpdateWithNewRange(range, content_size, true); | 1997 parsed->UpdateWithNewRange(range, content_size, true); |
2148 parsed->GetNormalizedHeaders(&resulting_headers); | 1998 parsed->GetNormalizedHeaders(&resulting_headers); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2238 EXPECT_EQ(TimeDelta::FromSeconds(0), GetMaxAgeValue()); | 2088 EXPECT_EQ(TimeDelta::FromSeconds(0), GetMaxAgeValue()); |
2239 } | 2089 } |
2240 | 2090 |
2241 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeCaseInsensitive) { | 2091 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeCaseInsensitive) { |
2242 InitializeHeadersWithCacheControl("Max-aGe=15"); | 2092 InitializeHeadersWithCacheControl("Max-aGe=15"); |
2243 EXPECT_EQ(TimeDelta::FromSeconds(15), GetMaxAgeValue()); | 2093 EXPECT_EQ(TimeDelta::FromSeconds(15), GetMaxAgeValue()); |
2244 } | 2094 } |
2245 | 2095 |
2246 struct MaxAgeTestData { | 2096 struct MaxAgeTestData { |
2247 const char* max_age_string; | 2097 const char* max_age_string; |
2248 const int64 expected_seconds; | 2098 const int64_t expected_seconds; |
2249 }; | 2099 }; |
2250 | 2100 |
2251 class MaxAgeEdgeCasesTest | 2101 class MaxAgeEdgeCasesTest |
2252 : public HttpResponseHeadersCacheControlTest, | 2102 : public HttpResponseHeadersCacheControlTest, |
2253 public ::testing::WithParamInterface<MaxAgeTestData> { | 2103 public ::testing::WithParamInterface<MaxAgeTestData> { |
2254 }; | 2104 }; |
2255 | 2105 |
2256 TEST_P(MaxAgeEdgeCasesTest, MaxAgeEdgeCases) { | 2106 TEST_P(MaxAgeEdgeCasesTest, MaxAgeEdgeCases) { |
2257 const MaxAgeTestData test = GetParam(); | 2107 const MaxAgeTestData test = GetParam(); |
2258 | 2108 |
2259 std::string max_age = "max-age="; | 2109 std::string max_age = "max-age="; |
2260 InitializeHeadersWithCacheControl( | 2110 InitializeHeadersWithCacheControl( |
2261 (max_age + test.max_age_string).c_str()); | 2111 (max_age + test.max_age_string).c_str()); |
2262 EXPECT_EQ(test.expected_seconds, GetMaxAgeValue().InSeconds()) | 2112 EXPECT_EQ(test.expected_seconds, GetMaxAgeValue().InSeconds()) |
2263 << " for max-age=" << test.max_age_string; | 2113 << " for max-age=" << test.max_age_string; |
2264 } | 2114 } |
2265 | 2115 |
2266 const MaxAgeTestData max_age_tests[] = { | 2116 const MaxAgeTestData max_age_tests[] = { |
2267 {" 1 ", 1}, // Spaces are ignored. | 2117 {" 1 ", 1}, // Spaces are ignored. |
2268 {"-1", -1}, // Negative numbers are passed through. | 2118 {"-1", -1}, // Negative numbers are passed through. |
2269 {"--1", 0}, // Leading junk gives 0. | 2119 {"--1", 0}, // Leading junk gives 0. |
2270 {"2s", 2}, // Trailing junk is ignored. | 2120 {"2s", 2}, // Trailing junk is ignored. |
2271 {"3 days", 3}, | 2121 {"3 days", 3}, |
2272 {"'4'", 0}, // Single quotes don't work. | 2122 {"'4'", 0}, // Single quotes don't work. |
2273 {"\"5\"", 0}, // Double quotes don't work. | 2123 {"\"5\"", 0}, // Double quotes don't work. |
2274 {"0x6", 0}, // Hex not parsed as hex. | 2124 {"0x6", 0}, // Hex not parsed as hex. |
2275 {"7F", 7}, // Hex without 0x still not parsed as hex. | 2125 {"7F", 7}, // Hex without 0x still not parsed as hex. |
2276 {"010", 10}, // Octal not parsed as octal. | 2126 {"010", 10}, // Octal not parsed as octal. |
2277 {"9223372036854", 9223372036854}, | 2127 {"9223372036854", 9223372036854}, |
2278 // {"9223372036855", -9223372036854}, // Undefined behaviour. | 2128 // {"9223372036855", -9223372036854}, // Undefined behaviour. |
2279 // {"9223372036854775806", -2}, // Undefined behaviour. | 2129 // {"9223372036854775806", -2}, // Undefined behaviour. |
2280 {"9223372036854775807", 9223372036854775807}, | 2130 {"9223372036854775807", 9223372036854775807}, |
2281 {"20000000000000000000", | 2131 {"20000000000000000000", |
2282 std::numeric_limits<int64>::max()}, // Overflow int64. | 2132 std::numeric_limits<int64_t>::max()}, // Overflow int64_t. |
2283 }; | 2133 }; |
2284 | 2134 |
2285 INSTANTIATE_TEST_CASE_P(HttpResponseHeadersCacheControl, | 2135 INSTANTIATE_TEST_CASE_P(HttpResponseHeadersCacheControl, |
2286 MaxAgeEdgeCasesTest, | 2136 MaxAgeEdgeCasesTest, |
2287 testing::ValuesIn(max_age_tests)); | 2137 testing::ValuesIn(max_age_tests)); |
2288 | 2138 |
2289 TEST_F(HttpResponseHeadersCacheControlTest, | 2139 TEST_F(HttpResponseHeadersCacheControlTest, |
2290 AbsentStaleWhileRevalidateReturnsFalse) { | 2140 AbsentStaleWhileRevalidateReturnsFalse) { |
2291 InitializeHeadersWithCacheControl("max-age=3600"); | 2141 InitializeHeadersWithCacheControl("max-age=3600"); |
2292 EXPECT_FALSE(headers()->GetStaleWhileRevalidateValue(TimeDeltaPointer())); | 2142 EXPECT_FALSE(headers()->GetStaleWhileRevalidateValue(TimeDeltaPointer())); |
(...skipping 19 matching lines...) Expand all Loading... | |
2312 TEST_F(HttpResponseHeadersCacheControlTest, | 2162 TEST_F(HttpResponseHeadersCacheControlTest, |
2313 FirstStaleWhileRevalidateValueUsed) { | 2163 FirstStaleWhileRevalidateValueUsed) { |
2314 InitializeHeadersWithCacheControl( | 2164 InitializeHeadersWithCacheControl( |
2315 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2165 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
2316 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2166 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
2317 } | 2167 } |
2318 | 2168 |
2319 } // namespace | 2169 } // namespace |
2320 | 2170 |
2321 } // namespace net | 2171 } // namespace net |
OLD | NEW |