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 <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> |
6 #include <limits> | 7 #include <limits> |
7 | 8 |
8 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "net/http/http_byte_range.h" | 14 #include "net/http/http_byte_range.h" |
14 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 | 1576 |
1576 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1577 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1577 ContentRangeTest, | 1578 ContentRangeTest, |
1578 testing::ValuesIn(content_range_tests)); | 1579 testing::ValuesIn(content_range_tests)); |
1579 | 1580 |
1580 struct KeepAliveTestData { | 1581 struct KeepAliveTestData { |
1581 const char* headers; | 1582 const char* headers; |
1582 bool expected_keep_alive; | 1583 bool expected_keep_alive; |
1583 }; | 1584 }; |
1584 | 1585 |
| 1586 // Enable GTest to print KeepAliveTestData in an intelligible way if the test |
| 1587 // fails. |
| 1588 void PrintTo(const KeepAliveTestData& keep_alive_test_data, |
| 1589 std::ostream* os) { |
| 1590 *os << "{\"" << keep_alive_test_data.headers << "\", " << std::boolalpha |
| 1591 << keep_alive_test_data.expected_keep_alive << "}"; |
| 1592 } |
| 1593 |
1585 class IsKeepAliveTest | 1594 class IsKeepAliveTest |
1586 : public HttpResponseHeadersTest, | 1595 : public HttpResponseHeadersTest, |
1587 public ::testing::WithParamInterface<KeepAliveTestData> { | 1596 public ::testing::WithParamInterface<KeepAliveTestData> { |
1588 }; | 1597 }; |
1589 | 1598 |
1590 TEST_P(IsKeepAliveTest, IsKeepAlive) { | 1599 TEST_P(IsKeepAliveTest, IsKeepAlive) { |
1591 const KeepAliveTestData test = GetParam(); | 1600 const KeepAliveTestData test = GetParam(); |
1592 | 1601 |
1593 std::string headers(test.headers); | 1602 std::string headers(test.headers); |
1594 HeadersToRaw(&headers); | 1603 HeadersToRaw(&headers); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 true | 1658 true |
1650 }, | 1659 }, |
1651 { "HTTP/1.1 200 OK\n" | 1660 { "HTTP/1.1 200 OK\n" |
1652 "proxy-connection: close\n", | 1661 "proxy-connection: close\n", |
1653 false | 1662 false |
1654 }, | 1663 }, |
1655 { "HTTP/1.1 200 OK\n" | 1664 { "HTTP/1.1 200 OK\n" |
1656 "proxy-connection: keep-alive\n", | 1665 "proxy-connection: keep-alive\n", |
1657 true | 1666 true |
1658 }, | 1667 }, |
| 1668 { "HTTP/1.1 200 OK\n" |
| 1669 "Connection: Upgrade, close\n", |
| 1670 false |
| 1671 }, |
| 1672 { "HTTP/1.1 200 OK\n" |
| 1673 "Connection: Upgrade, keep-alive\n", |
| 1674 true |
| 1675 }, |
| 1676 { "HTTP/1.1 200 OK\n" |
| 1677 "Connection: Upgrade\n" |
| 1678 "Connection: close\n", |
| 1679 false |
| 1680 }, |
| 1681 { "HTTP/1.1 200 OK\n" |
| 1682 "Connection: Upgrade\n" |
| 1683 "Connection: keep-alive\n", |
| 1684 true |
| 1685 }, |
| 1686 { "HTTP/1.1 200 OK\n" |
| 1687 "Connection: close, Upgrade\n", |
| 1688 false |
| 1689 }, |
| 1690 { "HTTP/1.1 200 OK\n" |
| 1691 "Connection: keep-alive, Upgrade\n", |
| 1692 true |
| 1693 }, |
| 1694 { "HTTP/1.1 200 OK\n" |
| 1695 "Connection: Upgrade\n" |
| 1696 "Proxy-Connection: close\n", |
| 1697 false |
| 1698 }, |
| 1699 { "HTTP/1.1 200 OK\n" |
| 1700 "Connection: Upgrade\n" |
| 1701 "Proxy-Connection: keep-alive\n", |
| 1702 true |
| 1703 }, |
| 1704 // In situations where the response headers conflict with themselves, use the |
| 1705 // first one for backwards-compatibility. |
| 1706 { "HTTP/1.1 200 OK\n" |
| 1707 "Connection: close\n" |
| 1708 "Connection: keep-alive\n", |
| 1709 false |
| 1710 }, |
| 1711 { "HTTP/1.1 200 OK\n" |
| 1712 "Connection: keep-alive\n" |
| 1713 "Connection: close\n", |
| 1714 true |
| 1715 }, |
| 1716 { "HTTP/1.0 200 OK\n" |
| 1717 "Connection: close\n" |
| 1718 "Connection: keep-alive\n", |
| 1719 false |
| 1720 }, |
| 1721 { "HTTP/1.0 200 OK\n" |
| 1722 "Connection: keep-alive\n" |
| 1723 "Connection: close\n", |
| 1724 true |
| 1725 }, |
| 1726 // Ignore the Proxy-Connection header if at all possible. |
| 1727 { "HTTP/1.0 200 OK\n" |
| 1728 "Proxy-Connection: keep-alive\n" |
| 1729 "Connection: close\n", |
| 1730 false |
| 1731 }, |
| 1732 { "HTTP/1.1 200 OK\n" |
| 1733 "Proxy-Connection: close\n" |
| 1734 "Connection: keep-alive\n", |
| 1735 true |
| 1736 }, |
| 1737 // Older versions of Chrome would have ignored Proxy-Connection in this case, |
| 1738 // but it doesn't seem safe. |
| 1739 { "HTTP/1.1 200 OK\n" |
| 1740 "Proxy-Connection: close\n" |
| 1741 "Connection: Transfer-Encoding\n", |
| 1742 false |
| 1743 }, |
1659 }; | 1744 }; |
1660 | 1745 |
1661 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1746 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1662 IsKeepAliveTest, | 1747 IsKeepAliveTest, |
1663 testing::ValuesIn(keepalive_tests)); | 1748 testing::ValuesIn(keepalive_tests)); |
1664 | 1749 |
1665 struct HasStrongValidatorsTestData { | 1750 struct HasStrongValidatorsTestData { |
1666 const char* headers; | 1751 const char* headers; |
1667 bool expected_result; | 1752 bool expected_result; |
1668 }; | 1753 }; |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2247 } | 2332 } |
2248 | 2333 |
2249 TEST_F(HttpResponseHeadersCacheControlTest, | 2334 TEST_F(HttpResponseHeadersCacheControlTest, |
2250 FirstStaleWhileRevalidateValueUsed) { | 2335 FirstStaleWhileRevalidateValueUsed) { |
2251 InitializeHeadersWithCacheControl( | 2336 InitializeHeadersWithCacheControl( |
2252 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2337 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
2253 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2338 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
2254 } | 2339 } |
2255 | 2340 |
2256 } // end namespace | 2341 } // end namespace |
OLD | NEW |