OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 1409 matching lines...) Loading... |
1420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1421 string headers(tests[i].headers); | 1421 string headers(tests[i].headers); |
1422 HeadersToRaw(&headers); | 1422 HeadersToRaw(&headers); |
1423 scoped_refptr<HttpResponseHeaders> parsed = | 1423 scoped_refptr<HttpResponseHeaders> parsed = |
1424 new HttpResponseHeaders(headers); | 1424 new HttpResponseHeaders(headers); |
1425 | 1425 |
1426 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); | 1426 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); |
1427 } | 1427 } |
1428 } | 1428 } |
1429 | 1429 |
| 1430 TEST(HttpResponseHeadersTest, HasStrongValidators) { |
| 1431 const struct { |
| 1432 const char* headers; |
| 1433 bool expected_result; |
| 1434 } tests[] = { |
| 1435 { "HTTP/0.9 200 OK", |
| 1436 false |
| 1437 }, |
| 1438 { "HTTP/0.9 200 OK\n" |
| 1439 "Date: Wed, 28 Nov 2007 01:40:10 GMT\n" |
| 1440 "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n" |
| 1441 "ETag: \"foo\"\n", |
| 1442 true |
| 1443 }, |
| 1444 { "HTTP/1.1 200 OK\n" |
| 1445 "Date: Wed, 28 Nov 2007 00:41:10 GMT\n" |
| 1446 "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n", |
| 1447 true |
| 1448 }, |
| 1449 { "HTTP/1.1 200 OK\n" |
| 1450 "Date: Wed, 28 Nov 2007 00:41:09 GMT\n" |
| 1451 "Last-Modified: Wed, 28 Nov 2007 00:40:10 GMT\n", |
| 1452 false |
| 1453 }, |
| 1454 { "HTTP/1.1 200 OK\n" |
| 1455 "ETag: \"foo\"\n", |
| 1456 true |
| 1457 }, |
| 1458 // This is not really a weak etag: |
| 1459 { "HTTP/1.1 200 OK\n" |
| 1460 "etag: \"w/foo\"\n", |
| 1461 true |
| 1462 }, |
| 1463 // This is a weak etag: |
| 1464 { "HTTP/1.1 200 OK\n" |
| 1465 "etag: w/\"foo\"\n", |
| 1466 false |
| 1467 }, |
| 1468 { "HTTP/1.1 200 OK\n" |
| 1469 "etag: W / \"foo\"\n", |
| 1470 false |
| 1471 } |
| 1472 }; |
| 1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1474 string headers(tests[i].headers); |
| 1475 HeadersToRaw(&headers); |
| 1476 scoped_refptr<HttpResponseHeaders> parsed = |
| 1477 new HttpResponseHeaders(headers); |
| 1478 |
| 1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) << |
| 1480 "Failed test case " << i; |
| 1481 } |
| 1482 } |
| 1483 |
1430 TEST(HttpResponseHeadersTest, GetStatusText) { | 1484 TEST(HttpResponseHeadersTest, GetStatusText) { |
1431 std::string headers("HTTP/1.1 404 Not Found"); | 1485 std::string headers("HTTP/1.1 404 Not Found"); |
1432 HeadersToRaw(&headers); | 1486 HeadersToRaw(&headers); |
1433 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1487 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); |
1434 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); | 1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); |
1435 } | 1489 } |
1436 | 1490 |
1437 TEST(HttpResponseHeadersTest, GetStatusTextMissing) { | 1491 TEST(HttpResponseHeadersTest, GetStatusTextMissing) { |
1438 std::string headers("HTTP/1.1 404"); | 1492 std::string headers("HTTP/1.1 404"); |
1439 HeadersToRaw(&headers); | 1493 HeadersToRaw(&headers); |
(...skipping 155 matching lines...) Loading... |
1595 new HttpResponseHeaders(orig_headers); | 1649 new HttpResponseHeaders(orig_headers); |
1596 | 1650 |
1597 string name(tests[i].new_status); | 1651 string name(tests[i].new_status); |
1598 parsed->ReplaceStatusLine(name); | 1652 parsed->ReplaceStatusLine(name); |
1599 | 1653 |
1600 string resulting_headers; | 1654 string resulting_headers; |
1601 parsed->GetNormalizedHeaders(&resulting_headers); | 1655 parsed->GetNormalizedHeaders(&resulting_headers); |
1602 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); | 1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); |
1603 } | 1657 } |
1604 } | 1658 } |
OLD | NEW |