Chromium Code Reviews| 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 void PrintTo(const KeepAliveTestData& keep_alive_test_data, | |
|
rvargas (doing something else)
2014/10/15 22:55:21
nit: add a comment about this being gtest related.
Adam Rice
2014/10/16 11:29:38
Done.
| |
| 1587 std::ostream* os) { | |
| 1588 *os << "{\"" << keep_alive_test_data.headers << "\", " << std::boolalpha | |
| 1589 << keep_alive_test_data.expected_keep_alive << "}"; | |
| 1590 } | |
| 1591 | |
| 1585 class IsKeepAliveTest | 1592 class IsKeepAliveTest |
| 1586 : public HttpResponseHeadersTest, | 1593 : public HttpResponseHeadersTest, |
| 1587 public ::testing::WithParamInterface<KeepAliveTestData> { | 1594 public ::testing::WithParamInterface<KeepAliveTestData> { |
| 1588 }; | 1595 }; |
| 1589 | 1596 |
| 1590 TEST_P(IsKeepAliveTest, IsKeepAlive) { | 1597 TEST_P(IsKeepAliveTest, IsKeepAlive) { |
| 1591 const KeepAliveTestData test = GetParam(); | 1598 const KeepAliveTestData test = GetParam(); |
| 1592 | 1599 |
| 1593 std::string headers(test.headers); | 1600 std::string headers(test.headers); |
| 1594 HeadersToRaw(&headers); | 1601 HeadersToRaw(&headers); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 true | 1656 true |
| 1650 }, | 1657 }, |
| 1651 { "HTTP/1.1 200 OK\n" | 1658 { "HTTP/1.1 200 OK\n" |
| 1652 "proxy-connection: close\n", | 1659 "proxy-connection: close\n", |
| 1653 false | 1660 false |
| 1654 }, | 1661 }, |
| 1655 { "HTTP/1.1 200 OK\n" | 1662 { "HTTP/1.1 200 OK\n" |
| 1656 "proxy-connection: keep-alive\n", | 1663 "proxy-connection: keep-alive\n", |
| 1657 true | 1664 true |
| 1658 }, | 1665 }, |
| 1666 { "HTTP/1.1 200 OK\n" | |
| 1667 "Connection: Upgrade, close\n", | |
| 1668 false | |
| 1669 }, | |
| 1670 { "HTTP/1.1 200 OK\n" | |
| 1671 "Connection: Upgrade, keep-alive\n", | |
| 1672 true | |
| 1673 }, | |
| 1674 { "HTTP/1.1 200 OK\n" | |
| 1675 "Connection: Upgrade\n" | |
| 1676 "Connection: close\n", | |
| 1677 false | |
| 1678 }, | |
| 1679 { "HTTP/1.1 200 OK\n" | |
| 1680 "Connection: Upgrade\n" | |
| 1681 "Connection: keep-alive\n", | |
| 1682 true | |
| 1683 }, | |
| 1684 { "HTTP/1.1 200 OK\n" | |
| 1685 "Connection: close, Upgrade\n", | |
| 1686 false | |
| 1687 }, | |
| 1688 { "HTTP/1.1 200 OK\n" | |
| 1689 "Connection: keep-alive, Upgrade\n", | |
| 1690 true | |
| 1691 }, | |
| 1692 { "HTTP/1.1 200 OK\n" | |
| 1693 "Connection: Upgrade\n" | |
| 1694 "Proxy-Connection: close\n", | |
| 1695 false | |
| 1696 }, | |
| 1697 { "HTTP/1.1 200 OK\n" | |
| 1698 "Connection: Upgrade\n" | |
| 1699 "Proxy-Connection: keep-alive\n", | |
| 1700 true | |
| 1701 }, | |
| 1702 // In situations where the response headers conflict with themselves, use the | |
| 1703 // first one for backwards-compatibility. | |
| 1704 { "HTTP/1.1 200 OK\n" | |
| 1705 "Connection: close\n" | |
| 1706 "Connection: keep-alive\n", | |
| 1707 false | |
| 1708 }, | |
| 1709 { "HTTP/1.1 200 OK\n" | |
| 1710 "Connection: keep-alive\n" | |
| 1711 "Connection: close\n", | |
| 1712 true | |
| 1713 }, | |
| 1714 { "HTTP/1.0 200 OK\n" | |
| 1715 "Connection: close\n" | |
| 1716 "Connection: keep-alive\n", | |
| 1717 false | |
| 1718 }, | |
| 1719 { "HTTP/1.0 200 OK\n" | |
| 1720 "Connection: keep-alive\n" | |
| 1721 "Connection: close\n", | |
| 1722 true | |
| 1723 }, | |
| 1659 }; | 1724 }; |
| 1660 | 1725 |
| 1661 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 1726 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
| 1662 IsKeepAliveTest, | 1727 IsKeepAliveTest, |
| 1663 testing::ValuesIn(keepalive_tests)); | 1728 testing::ValuesIn(keepalive_tests)); |
| 1664 | 1729 |
| 1665 struct HasStrongValidatorsTestData { | 1730 struct HasStrongValidatorsTestData { |
| 1666 const char* headers; | 1731 const char* headers; |
| 1667 bool expected_result; | 1732 bool expected_result; |
| 1668 }; | 1733 }; |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2247 } | 2312 } |
| 2248 | 2313 |
| 2249 TEST_F(HttpResponseHeadersCacheControlTest, | 2314 TEST_F(HttpResponseHeadersCacheControlTest, |
| 2250 FirstStaleWhileRevalidateValueUsed) { | 2315 FirstStaleWhileRevalidateValueUsed) { |
| 2251 InitializeHeadersWithCacheControl( | 2316 InitializeHeadersWithCacheControl( |
| 2252 "stale-while-revalidate=1,stale-while-revalidate=7200"); | 2317 "stale-while-revalidate=1,stale-while-revalidate=7200"); |
| 2253 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | 2318 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); |
| 2254 } | 2319 } |
| 2255 | 2320 |
| 2256 } // end namespace | 2321 } // end namespace |
| OLD | NEW |