| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/cache_type.h" | 11 #include "net/base/cache_type.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/base/net_log_unittest.h" | 14 #include "net/base/net_log_unittest.h" |
| 15 #include "net/base/ssl_cert_request_info.h" | 15 #include "net/base/ssl_cert_request_info.h" |
| 16 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 17 #include "net/http/http_byte_range.h" | 17 #include "net/http/http_byte_range.h" |
| 18 #include "net/http/http_request_headers.h" |
| 18 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "net/http/http_response_info.h" | 21 #include "net/http/http_response_info.h" |
| 21 #include "net/http/http_transaction.h" | 22 #include "net/http/http_transaction.h" |
| 22 #include "net/http/http_transaction_unittest.h" | 23 #include "net/http/http_transaction_unittest.h" |
| 23 #include "net/http/http_util.h" | 24 #include "net/http/http_util.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 using base::Time; | 27 using base::Time; |
| 27 | 28 |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 static bool not_modified_; | 718 static bool not_modified_; |
| 718 static bool modified_; | 719 static bool modified_; |
| 719 static bool bad_200_; | 720 static bool bad_200_; |
| 720 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); | 721 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); |
| 721 }; | 722 }; |
| 722 bool RangeTransactionServer::not_modified_ = false; | 723 bool RangeTransactionServer::not_modified_ = false; |
| 723 bool RangeTransactionServer::modified_ = false; | 724 bool RangeTransactionServer::modified_ = false; |
| 724 bool RangeTransactionServer::bad_200_ = false; | 725 bool RangeTransactionServer::bad_200_ = false; |
| 725 | 726 |
| 726 // A dummy extra header that must be preserved on a given request. | 727 // A dummy extra header that must be preserved on a given request. |
| 727 #define EXTRA_HEADER "Extra: header\r\n" | 728 #define EXTRA_HEADER "Extra: header" |
| 729 static const char kExtraHeaderKey[] = "Extra"; |
| 728 | 730 |
| 729 // Static. | 731 // Static. |
| 730 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, | 732 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, |
| 731 std::string* response_status, | 733 std::string* response_status, |
| 732 std::string* response_headers, | 734 std::string* response_headers, |
| 733 std::string* response_data) { | 735 std::string* response_data) { |
| 734 if (request->extra_headers.empty()) { | 736 if (request->extra_headers.IsEmpty()) { |
| 735 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); | 737 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
| 736 return; | 738 return; |
| 737 } | 739 } |
| 738 | 740 |
| 739 // We want to make sure we don't delete extra headers. | 741 // We want to make sure we don't delete extra headers. |
| 740 EXPECT_TRUE(request->extra_headers.find(EXTRA_HEADER) != std::string::npos); | 742 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); |
| 741 | 743 |
| 742 if (not_modified_) { | 744 if (not_modified_) { |
| 743 response_status->assign("HTTP/1.1 304 Not Modified"); | 745 response_status->assign("HTTP/1.1 304 Not Modified"); |
| 744 return; | 746 return; |
| 745 } | 747 } |
| 746 | 748 |
| 747 std::vector<net::HttpByteRange> ranges; | 749 std::vector<net::HttpByteRange> ranges; |
| 748 if (!net::HttpUtil::ParseRanges(request->extra_headers, &ranges) || | 750 std::string range_header; |
| 751 if (!request->extra_headers.GetHeader( |
| 752 net::HttpRequestHeaders::kRange, &range_header) || |
| 753 !net::HttpUtil::ParseRangeHeader(range_header, &ranges) || |
| 749 ranges.size() != 1) | 754 ranges.size() != 1) |
| 750 return; | 755 return; |
| 751 // We can handle this range request. | 756 // We can handle this range request. |
| 752 net::HttpByteRange byte_range = ranges[0]; | 757 net::HttpByteRange byte_range = ranges[0]; |
| 753 if (byte_range.first_byte_position() > 79) { | 758 if (byte_range.first_byte_position() > 79) { |
| 754 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); | 759 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
| 755 return; | 760 return; |
| 756 } | 761 } |
| 757 | 762 |
| 758 EXPECT_TRUE(byte_range.ComputeBounds(80)); | 763 EXPECT_TRUE(byte_range.ComputeBounds(80)); |
| 759 int start = static_cast<int>(byte_range.first_byte_position()); | 764 int start = static_cast<int>(byte_range.first_byte_position()); |
| 760 int end = static_cast<int>(byte_range.last_byte_position()); | 765 int end = static_cast<int>(byte_range.last_byte_position()); |
| 761 | 766 |
| 762 EXPECT_LT(end, 80); | 767 EXPECT_LT(end, 80); |
| 763 | 768 |
| 764 size_t if_range_header = request->extra_headers.find("If-Range"); | |
| 765 if (std::string::npos != if_range_header) { | |
| 766 // Check that If-Range isn't specified twice. | |
| 767 EXPECT_EQ(std::string::npos, | |
| 768 request->extra_headers.find("If-Range", if_range_header + 1)); | |
| 769 } | |
| 770 | |
| 771 std::string content_range = StringPrintf("Content-Range: bytes %d-%d/80\n", | 769 std::string content_range = StringPrintf("Content-Range: bytes %d-%d/80\n", |
| 772 start, end); | 770 start, end); |
| 773 response_headers->append(content_range); | 771 response_headers->append(content_range); |
| 774 | 772 |
| 775 if (request->extra_headers.find("If-None-Match") == std::string::npos || | 773 if (!request->extra_headers.HasHeader("If-None-Match") || modified_) { |
| 776 modified_) { | |
| 777 EXPECT_EQ(9, (end - start) % 10); | 774 EXPECT_EQ(9, (end - start) % 10); |
| 778 std::string data; | 775 std::string data; |
| 779 for (int block_start = start; block_start < end; block_start += 10) | 776 for (int block_start = start; block_start < end; block_start += 10) |
| 780 StringAppendF(&data, "rg: %02d-%02d ", block_start, block_start + 9); | 777 StringAppendF(&data, "rg: %02d-%02d ", block_start, block_start + 9); |
| 781 *response_data = data; | 778 *response_data = data; |
| 782 | 779 |
| 783 if (end - start != 9) { | 780 if (end - start != 9) { |
| 784 // We also have to fix content-length. | 781 // We also have to fix content-length. |
| 785 int len = end - start + 1; | 782 int len = end - start + 1; |
| 786 EXPECT_EQ(0, len % 10); | 783 EXPECT_EQ(0, len % 10); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 810 "ETag: \"foo\"\n" | 807 "ETag: \"foo\"\n" |
| 811 "Accept-Ranges: bytes\n" | 808 "Accept-Ranges: bytes\n" |
| 812 "Content-Length: 10\n", | 809 "Content-Length: 10\n", |
| 813 base::Time(), | 810 base::Time(), |
| 814 "rg: 40-49 ", | 811 "rg: 40-49 ", |
| 815 TEST_MODE_NORMAL, | 812 TEST_MODE_NORMAL, |
| 816 &RangeTransactionServer::RangeHandler, | 813 &RangeTransactionServer::RangeHandler, |
| 817 0 | 814 0 |
| 818 }; | 815 }; |
| 819 | 816 |
| 820 // Returns true if the response headers (|response|) match a partial content | 817 // Verifies the response headers (|response|) match a partial content |
| 821 // response for the range starting at |start| and ending at |end|. | 818 // response for the range starting at |start| and ending at |end|. |
| 822 bool Verify206Response(std::string response, int start, int end) { | 819 void Verify206Response(std::string response, int start, int end) { |
| 823 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), | 820 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), |
| 824 response.size())); | 821 response.size())); |
| 825 scoped_refptr<net::HttpResponseHeaders> headers = | 822 scoped_refptr<net::HttpResponseHeaders> headers = |
| 826 new net::HttpResponseHeaders(raw_headers); | 823 new net::HttpResponseHeaders(raw_headers); |
| 827 | 824 |
| 828 if (206 != headers->response_code()) | 825 ASSERT_EQ(206, headers->response_code()); |
| 829 return false; | |
| 830 | 826 |
| 831 int64 range_start, range_end, object_size; | 827 int64 range_start, range_end, object_size; |
| 832 if (!headers->GetContentRange(&range_start, &range_end, &object_size)) | 828 ASSERT_TRUE( |
| 833 return false; | 829 headers->GetContentRange(&range_start, &range_end, &object_size)); |
| 834 int64 content_length = headers->GetContentLength(); | 830 int64 content_length = headers->GetContentLength(); |
| 835 | 831 |
| 836 int length = end - start + 1; | 832 int length = end - start + 1; |
| 837 if (content_length != length) | 833 ASSERT_EQ(length, content_length); |
| 838 return false; | 834 ASSERT_EQ(start, range_start); |
| 839 | 835 ASSERT_EQ(end, range_end); |
| 840 if (range_start != start) | |
| 841 return false; | |
| 842 | |
| 843 if (range_end != end) | |
| 844 return false; | |
| 845 | |
| 846 return true; | |
| 847 } | 836 } |
| 848 | 837 |
| 849 // Helper to represent a network HTTP response. | 838 // Helper to represent a network HTTP response. |
| 850 struct Response { | 839 struct Response { |
| 851 // Set this response into |trans|. | 840 // Set this response into |trans|. |
| 852 void AssignTo(MockTransaction* trans) const { | 841 void AssignTo(MockTransaction* trans) const { |
| 853 trans->status = status; | 842 trans->status = status; |
| 854 trans->response_headers = headers; | 843 trans->response_headers = headers; |
| 855 trans->data = body; | 844 trans->data = body; |
| 856 } | 845 } |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1200 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1212 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1201 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1213 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1202 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1214 } | 1203 } |
| 1215 | 1204 |
| 1216 static void PreserveRequestHeaders_Handler( | 1205 static void PreserveRequestHeaders_Handler( |
| 1217 const net::HttpRequestInfo* request, | 1206 const net::HttpRequestInfo* request, |
| 1218 std::string* response_status, | 1207 std::string* response_status, |
| 1219 std::string* response_headers, | 1208 std::string* response_headers, |
| 1220 std::string* response_data) { | 1209 std::string* response_data) { |
| 1221 EXPECT_TRUE(request->extra_headers.find(EXTRA_HEADER) != std::string::npos); | 1210 EXPECT_TRUE(request->extra_headers.HasHeader(kExtraHeaderKey)); |
| 1222 } | 1211 } |
| 1223 | 1212 |
| 1224 // Tests that we don't remove extra headers for simple requests. | 1213 // Tests that we don't remove extra headers for simple requests. |
| 1225 TEST(HttpCache, SimpleGET_PreserveRequestHeaders) { | 1214 TEST(HttpCache, SimpleGET_PreserveRequestHeaders) { |
| 1226 MockHttpCache cache; | 1215 MockHttpCache cache; |
| 1227 | 1216 |
| 1228 MockTransaction transaction(kSimpleGET_Transaction); | 1217 MockTransaction transaction(kSimpleGET_Transaction); |
| 1229 transaction.handler = PreserveRequestHeaders_Handler; | 1218 transaction.handler = PreserveRequestHeaders_Handler; |
| 1230 transaction.request_headers = EXTRA_HEADER; | 1219 transaction.request_headers = EXTRA_HEADER; |
| 1231 transaction.response_headers = "Cache-Control: max-age=0\n"; | 1220 transaction.response_headers = "Cache-Control: max-age=0\n"; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1243 | 1232 |
| 1244 // Tests that we don't remove extra headers for conditionalized requests. | 1233 // Tests that we don't remove extra headers for conditionalized requests. |
| 1245 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) { | 1234 TEST(HttpCache, ConditionalizedGET_PreserveRequestHeaders) { |
| 1246 MockHttpCache cache; | 1235 MockHttpCache cache; |
| 1247 | 1236 |
| 1248 // Write to the cache. | 1237 // Write to the cache. |
| 1249 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); | 1238 RunTransactionTest(cache.http_cache(), kETagGET_Transaction); |
| 1250 | 1239 |
| 1251 MockTransaction transaction(kETagGET_Transaction); | 1240 MockTransaction transaction(kETagGET_Transaction); |
| 1252 transaction.handler = PreserveRequestHeaders_Handler; | 1241 transaction.handler = PreserveRequestHeaders_Handler; |
| 1253 transaction.request_headers = "If-None-Match: \"foopy\"\n" | 1242 transaction.request_headers = "If-None-Match: \"foopy\"\r\n" |
| 1254 EXTRA_HEADER; | 1243 EXTRA_HEADER; |
| 1255 AddMockTransaction(&transaction); | 1244 AddMockTransaction(&transaction); |
| 1256 | 1245 |
| 1257 RunTransactionTest(cache.http_cache(), transaction); | 1246 RunTransactionTest(cache.http_cache(), transaction); |
| 1258 | 1247 |
| 1259 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1248 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1260 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1249 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1261 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1250 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1262 RemoveMockTransaction(&transaction); | 1251 RemoveMockTransaction(&transaction); |
| 1263 } | 1252 } |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1683 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1695 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1684 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1696 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1685 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1697 } | 1686 } |
| 1698 | 1687 |
| 1699 static void ETagGet_ConditionalRequest_Handler( | 1688 static void ETagGet_ConditionalRequest_Handler( |
| 1700 const net::HttpRequestInfo* request, | 1689 const net::HttpRequestInfo* request, |
| 1701 std::string* response_status, | 1690 std::string* response_status, |
| 1702 std::string* response_headers, | 1691 std::string* response_headers, |
| 1703 std::string* response_data) { | 1692 std::string* response_data) { |
| 1704 EXPECT_TRUE(request->extra_headers.find("If-None-Match") != | 1693 EXPECT_TRUE( |
| 1705 std::string::npos); | 1694 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); |
| 1706 response_status->assign("HTTP/1.1 304 Not Modified"); | 1695 response_status->assign("HTTP/1.1 304 Not Modified"); |
| 1707 response_headers->assign(kETagGET_Transaction.response_headers); | 1696 response_headers->assign(kETagGET_Transaction.response_headers); |
| 1708 response_data->clear(); | 1697 response_data->clear(); |
| 1709 } | 1698 } |
| 1710 | 1699 |
| 1711 TEST(HttpCache, ETagGET_ConditionalRequest_304) { | 1700 TEST(HttpCache, ETagGET_ConditionalRequest_304) { |
| 1712 MockHttpCache cache; | 1701 MockHttpCache cache; |
| 1713 | 1702 |
| 1714 ScopedMockTransaction transaction(kETagGET_Transaction); | 1703 ScopedMockTransaction transaction(kETagGET_Transaction); |
| 1715 | 1704 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1729 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1718 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 1730 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1719 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 1731 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1720 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 1732 } | 1721 } |
| 1733 | 1722 |
| 1734 static void ETagGet_ConditionalRequest_NoStore_Handler( | 1723 static void ETagGet_ConditionalRequest_NoStore_Handler( |
| 1735 const net::HttpRequestInfo* request, | 1724 const net::HttpRequestInfo* request, |
| 1736 std::string* response_status, | 1725 std::string* response_status, |
| 1737 std::string* response_headers, | 1726 std::string* response_headers, |
| 1738 std::string* response_data) { | 1727 std::string* response_data) { |
| 1739 EXPECT_TRUE(request->extra_headers.find("If-None-Match") != | 1728 EXPECT_TRUE( |
| 1740 std::string::npos); | 1729 request->extra_headers.HasHeader(net::HttpRequestHeaders::kIfNoneMatch)); |
| 1741 response_status->assign("HTTP/1.1 304 Not Modified"); | 1730 response_status->assign("HTTP/1.1 304 Not Modified"); |
| 1742 response_headers->assign("Cache-Control: no-store\n"); | 1731 response_headers->assign("Cache-Control: no-store\n"); |
| 1743 response_data->clear(); | 1732 response_data->clear(); |
| 1744 } | 1733 } |
| 1745 | 1734 |
| 1746 TEST(HttpCache, ETagGET_ConditionalRequest_304_NoStore) { | 1735 TEST(HttpCache, ETagGET_ConditionalRequest_304_NoStore) { |
| 1747 MockHttpCache cache; | 1736 MockHttpCache cache; |
| 1748 | 1737 |
| 1749 ScopedMockTransaction transaction(kETagGET_Transaction); | 1738 ScopedMockTransaction transaction(kETagGET_Transaction); |
| 1750 | 1739 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 const char* kUrl = "http://foobar.com/main.css"; | 1984 const char* kUrl = "http://foobar.com/main.css"; |
| 1996 | 1985 |
| 1997 static const Response kNetResponse = { | 1986 static const Response kNetResponse = { |
| 1998 "HTTP/1.1 304 Not Modified", | 1987 "HTTP/1.1 304 Not Modified", |
| 1999 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 1988 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 2000 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 1989 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 2001 "" | 1990 "" |
| 2002 }; | 1991 }; |
| 2003 | 1992 |
| 2004 const char* kExtraRequestHeaders = | 1993 const char* kExtraRequestHeaders = |
| 2005 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"; | 1994 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; |
| 2006 | 1995 |
| 2007 // We will control the network layer's responses for |kUrl| using | 1996 // We will control the network layer's responses for |kUrl| using |
| 2008 // |mock_network_response|. | 1997 // |mock_network_response|. |
| 2009 MockTransaction mock_network_response = { 0 }; | 1998 MockTransaction mock_network_response = { 0 }; |
| 2010 mock_network_response.url = kUrl; | 1999 mock_network_response.url = kUrl; |
| 2011 AddMockTransaction(&mock_network_response); | 2000 AddMockTransaction(&mock_network_response); |
| 2012 | 2001 |
| 2013 MockTransaction request = { 0 }; | 2002 MockTransaction request = { 0 }; |
| 2014 request.url = kUrl; | 2003 request.url = kUrl; |
| 2015 request.method = "GET"; | 2004 request.method = "GET"; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2039 const char* kUrl = "http://foobar.com/main.css"; | 2028 const char* kUrl = "http://foobar.com/main.css"; |
| 2040 | 2029 |
| 2041 static const Response kNetResponse = { | 2030 static const Response kNetResponse = { |
| 2042 "HTTP/1.1 200 OK", | 2031 "HTTP/1.1 200 OK", |
| 2043 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2032 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 2044 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2033 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 2045 "foobar!!!" | 2034 "foobar!!!" |
| 2046 }; | 2035 }; |
| 2047 | 2036 |
| 2048 const char* kExtraRequestHeaders = | 2037 const char* kExtraRequestHeaders = |
| 2049 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"; | 2038 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; |
| 2050 | 2039 |
| 2051 // We will control the network layer's responses for |kUrl| using | 2040 // We will control the network layer's responses for |kUrl| using |
| 2052 // |mock_network_response|. | 2041 // |mock_network_response|. |
| 2053 MockTransaction mock_network_response = { 0 }; | 2042 MockTransaction mock_network_response = { 0 }; |
| 2054 mock_network_response.url = kUrl; | 2043 mock_network_response.url = kUrl; |
| 2055 AddMockTransaction(&mock_network_response); | 2044 AddMockTransaction(&mock_network_response); |
| 2056 | 2045 |
| 2057 MockTransaction request = { 0 }; | 2046 MockTransaction request = { 0 }; |
| 2058 request.url = kUrl; | 2047 request.url = kUrl; |
| 2059 request.method = "GET"; | 2048 request.method = "GET"; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 // Second network response for |kUrl|. | 2136 // Second network response for |kUrl|. |
| 2148 static const Response kNetResponse2 = { | 2137 static const Response kNetResponse2 = { |
| 2149 "HTTP/1.1 200 OK", | 2138 "HTTP/1.1 200 OK", |
| 2150 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2139 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 2151 "Etag: \"Foo2\"\n" | 2140 "Etag: \"Foo2\"\n" |
| 2152 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2141 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
| 2153 "body2" | 2142 "body2" |
| 2154 }; | 2143 }; |
| 2155 | 2144 |
| 2156 const char* kExtraRequestHeaders = | 2145 const char* kExtraRequestHeaders = |
| 2157 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n" | 2146 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
| 2158 "If-None-Match: \"Foo1\"\n"; | 2147 "If-None-Match: \"Foo1\"\r\n"; |
| 2159 | 2148 |
| 2160 ConditionalizedRequestUpdatesCacheHelper( | 2149 ConditionalizedRequestUpdatesCacheHelper( |
| 2161 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); | 2150 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); |
| 2162 } | 2151 } |
| 2163 | 2152 |
| 2164 // Test that doing an externally conditionalized request with both if-none-match | 2153 // Test that doing an externally conditionalized request with both if-none-match |
| 2165 // and if-modified-since does not update the cache with only one match. | 2154 // and if-modified-since does not update the cache with only one match. |
| 2166 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { | 2155 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { |
| 2167 static const Response kNetResponse1 = { | 2156 static const Response kNetResponse1 = { |
| 2168 "HTTP/1.1 200 OK", | 2157 "HTTP/1.1 200 OK", |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2351 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 2363 } | 2352 } |
| 2364 | 2353 |
| 2365 // Test that we skip the cache for range requests that include a validation | 2354 // Test that we skip the cache for range requests that include a validation |
| 2366 // header. | 2355 // header. |
| 2367 TEST(HttpCache, RangeGET_SkipsCache2) { | 2356 TEST(HttpCache, RangeGET_SkipsCache2) { |
| 2368 MockHttpCache cache; | 2357 MockHttpCache cache; |
| 2369 cache.http_cache()->set_enable_range_support(true); | 2358 cache.http_cache()->set_enable_range_support(true); |
| 2370 | 2359 |
| 2371 MockTransaction transaction(kRangeGET_Transaction); | 2360 MockTransaction transaction(kRangeGET_Transaction); |
| 2372 transaction.request_headers = "If-None-Match: foo\n" | 2361 transaction.request_headers = "If-None-Match: foo\r\n" |
| 2373 EXTRA_HEADER | 2362 EXTRA_HEADER |
| 2374 "Range: bytes = 40-49\n"; | 2363 "\r\nRange: bytes = 40-49"; |
| 2375 RunTransactionTest(cache.http_cache(), transaction); | 2364 RunTransactionTest(cache.http_cache(), transaction); |
| 2376 | 2365 |
| 2377 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2366 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2378 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2367 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2379 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2368 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 2380 | 2369 |
| 2381 transaction.request_headers = | 2370 transaction.request_headers = |
| 2382 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\n" | 2371 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" |
| 2383 EXTRA_HEADER | 2372 EXTRA_HEADER |
| 2384 "Range: bytes = 40-49\n"; | 2373 "\r\nRange: bytes = 40-49"; |
| 2385 RunTransactionTest(cache.http_cache(), transaction); | 2374 RunTransactionTest(cache.http_cache(), transaction); |
| 2386 | 2375 |
| 2387 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2376 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2388 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2377 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2389 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2378 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 2390 | 2379 |
| 2391 transaction.request_headers = "If-Range: bla\n" | 2380 transaction.request_headers = "If-Range: bla\r\n" |
| 2392 EXTRA_HEADER | 2381 EXTRA_HEADER |
| 2393 "Range: bytes = 40-49\n"; | 2382 "\r\nRange: bytes = 40-49\n"; |
| 2394 RunTransactionTest(cache.http_cache(), transaction); | 2383 RunTransactionTest(cache.http_cache(), transaction); |
| 2395 | 2384 |
| 2396 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2385 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2397 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2386 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2398 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 2387 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 2399 } | 2388 } |
| 2400 | 2389 |
| 2401 // Tests that receiving 206 for a regular request is handled correctly. | 2390 // Tests that receiving 206 for a regular request is handled correctly. |
| 2402 TEST(HttpCache, GET_Crazy206) { | 2391 TEST(HttpCache, GET_Crazy206) { |
| 2403 MockHttpCache cache; | 2392 MockHttpCache cache; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2428 TEST(HttpCache, RangeGET_OK) { | 2417 TEST(HttpCache, RangeGET_OK) { |
| 2429 MockHttpCache cache; | 2418 MockHttpCache cache; |
| 2430 cache.http_cache()->set_enable_range_support(true); | 2419 cache.http_cache()->set_enable_range_support(true); |
| 2431 AddMockTransaction(&kRangeGET_TransactionOK); | 2420 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2432 std::string headers; | 2421 std::string headers; |
| 2433 | 2422 |
| 2434 // Write to the cache (40-49). | 2423 // Write to the cache (40-49). |
| 2435 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2424 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2436 &headers); | 2425 &headers); |
| 2437 | 2426 |
| 2438 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2427 Verify206Response(headers, 40, 49); |
| 2439 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2428 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2440 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2429 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2441 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2430 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2442 | 2431 |
| 2443 // Read from the cache (40-49). | 2432 // Read from the cache (40-49). |
| 2444 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2433 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2445 &headers); | 2434 &headers); |
| 2446 | 2435 |
| 2447 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2436 Verify206Response(headers, 40, 49); |
| 2448 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2437 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2449 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2438 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2450 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2439 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2451 | 2440 |
| 2452 // Make sure we are done with the previous transaction. | 2441 // Make sure we are done with the previous transaction. |
| 2453 MessageLoop::current()->RunAllPending(); | 2442 MessageLoop::current()->RunAllPending(); |
| 2454 | 2443 |
| 2455 // Write to the cache (30-39). | 2444 // Write to the cache (30-39). |
| 2456 MockTransaction transaction(kRangeGET_TransactionOK); | 2445 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2457 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 2446 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
| 2458 transaction.data = "rg: 30-39 "; | 2447 transaction.data = "rg: 30-39 "; |
| 2459 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2448 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2460 | 2449 |
| 2461 EXPECT_TRUE(Verify206Response(headers, 30, 39)); | 2450 Verify206Response(headers, 30, 39); |
| 2462 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2451 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2463 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 2452 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 2464 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2453 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2465 | 2454 |
| 2466 // Make sure we are done with the previous transaction. | 2455 // Make sure we are done with the previous transaction. |
| 2467 MessageLoop::current()->RunAllPending(); | 2456 MessageLoop::current()->RunAllPending(); |
| 2468 | 2457 |
| 2469 // Write and read from the cache (20-59). | 2458 // Write and read from the cache (20-59). |
| 2470 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 2459 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 2471 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 2460 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 2472 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2461 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2473 | 2462 |
| 2474 EXPECT_TRUE(Verify206Response(headers, 20, 59)); | 2463 Verify206Response(headers, 20, 59); |
| 2475 EXPECT_EQ(5, cache.network_layer()->transaction_count()); | 2464 EXPECT_EQ(5, cache.network_layer()->transaction_count()); |
| 2476 EXPECT_EQ(3, cache.disk_cache()->open_count()); | 2465 EXPECT_EQ(3, cache.disk_cache()->open_count()); |
| 2477 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2466 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2478 | 2467 |
| 2479 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2468 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2480 } | 2469 } |
| 2481 | 2470 |
| 2482 // Tests that we can cache range requests and fetch random blocks from the | 2471 // Tests that we can cache range requests and fetch random blocks from the |
| 2483 // cache and the network, with synchronous responses. | 2472 // cache and the network, with synchronous responses. |
| 2484 TEST(HttpCache, RangeGET_SyncOK) { | 2473 TEST(HttpCache, RangeGET_SyncOK) { |
| 2485 MockHttpCache cache; | 2474 MockHttpCache cache; |
| 2486 cache.http_cache()->set_enable_range_support(true); | 2475 cache.http_cache()->set_enable_range_support(true); |
| 2487 | 2476 |
| 2488 MockTransaction transaction(kRangeGET_TransactionOK); | 2477 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2489 transaction.test_mode = TEST_MODE_SYNC_ALL; | 2478 transaction.test_mode = TEST_MODE_SYNC_ALL; |
| 2490 AddMockTransaction(&transaction); | 2479 AddMockTransaction(&transaction); |
| 2491 | 2480 |
| 2492 // Write to the cache (40-49). | 2481 // Write to the cache (40-49). |
| 2493 std::string headers; | 2482 std::string headers; |
| 2494 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2483 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2495 | 2484 |
| 2496 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2485 Verify206Response(headers, 40, 49); |
| 2497 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2486 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2498 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2487 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2499 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2488 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2500 | 2489 |
| 2501 // Read from the cache (40-49). | 2490 // Read from the cache (40-49). |
| 2502 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2491 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2503 | 2492 |
| 2504 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2493 Verify206Response(headers, 40, 49); |
| 2505 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2494 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2506 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2495 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2507 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2496 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2508 | 2497 |
| 2509 // Make sure we are done with the previous transaction. | 2498 // Make sure we are done with the previous transaction. |
| 2510 MessageLoop::current()->RunAllPending(); | 2499 MessageLoop::current()->RunAllPending(); |
| 2511 | 2500 |
| 2512 // Write to the cache (30-39). | 2501 // Write to the cache (30-39). |
| 2513 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; | 2502 transaction.request_headers = "Range: bytes = 30-39\r\n" EXTRA_HEADER; |
| 2514 transaction.data = "rg: 30-39 "; | 2503 transaction.data = "rg: 30-39 "; |
| 2515 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2504 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2516 | 2505 |
| 2517 EXPECT_TRUE(Verify206Response(headers, 30, 39)); | 2506 Verify206Response(headers, 30, 39); |
| 2518 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2507 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2519 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2508 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2520 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2509 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2521 | 2510 |
| 2522 // Make sure we are done with the previous transaction. | 2511 // Make sure we are done with the previous transaction. |
| 2523 MessageLoop::current()->RunAllPending(); | 2512 MessageLoop::current()->RunAllPending(); |
| 2524 | 2513 |
| 2525 // Write and read from the cache (20-59). | 2514 // Write and read from the cache (20-59). |
| 2526 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; | 2515 transaction.request_headers = "Range: bytes = 20-59\r\n" EXTRA_HEADER; |
| 2527 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; | 2516 transaction.data = "rg: 20-29 rg: 30-39 rg: 40-49 rg: 50-59 "; |
| 2528 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2517 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2529 | 2518 |
| 2530 EXPECT_TRUE(Verify206Response(headers, 20, 59)); | 2519 Verify206Response(headers, 20, 59); |
| 2531 EXPECT_EQ(5, cache.network_layer()->transaction_count()); | 2520 EXPECT_EQ(5, cache.network_layer()->transaction_count()); |
| 2532 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 2521 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 2533 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2522 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2534 | 2523 |
| 2535 RemoveMockTransaction(&transaction); | 2524 RemoveMockTransaction(&transaction); |
| 2536 } | 2525 } |
| 2537 | 2526 |
| 2538 // Tests that we deal with 304s for range requests. | 2527 // Tests that we deal with 304s for range requests. |
| 2539 TEST(HttpCache, RangeGET_304) { | 2528 TEST(HttpCache, RangeGET_304) { |
| 2540 MockHttpCache cache; | 2529 MockHttpCache cache; |
| 2541 cache.http_cache()->set_enable_range_support(true); | 2530 cache.http_cache()->set_enable_range_support(true); |
| 2542 AddMockTransaction(&kRangeGET_TransactionOK); | 2531 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2543 std::string headers; | 2532 std::string headers; |
| 2544 | 2533 |
| 2545 // Write to the cache (40-49). | 2534 // Write to the cache (40-49). |
| 2546 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2535 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2547 &headers); | 2536 &headers); |
| 2548 | 2537 |
| 2549 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2538 Verify206Response(headers, 40, 49); |
| 2550 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2539 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2551 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2540 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2552 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2541 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2553 | 2542 |
| 2554 // Read from the cache (40-49). | 2543 // Read from the cache (40-49). |
| 2555 RangeTransactionServer handler; | 2544 RangeTransactionServer handler; |
| 2556 handler.set_not_modified(true); | 2545 handler.set_not_modified(true); |
| 2557 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2546 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2558 &headers); | 2547 &headers); |
| 2559 | 2548 |
| 2560 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2549 Verify206Response(headers, 40, 49); |
| 2561 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2550 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2562 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2551 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2563 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2552 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2564 | 2553 |
| 2565 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2554 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2566 } | 2555 } |
| 2567 | 2556 |
| 2568 // Tests that we deal with 206s when revalidating range requests. | 2557 // Tests that we deal with 206s when revalidating range requests. |
| 2569 TEST(HttpCache, RangeGET_ModifiedResult) { | 2558 TEST(HttpCache, RangeGET_ModifiedResult) { |
| 2570 MockHttpCache cache; | 2559 MockHttpCache cache; |
| 2571 cache.http_cache()->set_enable_range_support(true); | 2560 cache.http_cache()->set_enable_range_support(true); |
| 2572 AddMockTransaction(&kRangeGET_TransactionOK); | 2561 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2573 std::string headers; | 2562 std::string headers; |
| 2574 | 2563 |
| 2575 // Write to the cache (40-49). | 2564 // Write to the cache (40-49). |
| 2576 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2565 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2577 &headers); | 2566 &headers); |
| 2578 | 2567 |
| 2579 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2568 Verify206Response(headers, 40, 49); |
| 2580 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2569 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2581 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2570 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2582 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2571 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2583 | 2572 |
| 2584 // Attempt to read from the cache (40-49). | 2573 // Attempt to read from the cache (40-49). |
| 2585 RangeTransactionServer handler; | 2574 RangeTransactionServer handler; |
| 2586 handler.set_modified(true); | 2575 handler.set_modified(true); |
| 2587 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2576 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2588 &headers); | 2577 &headers); |
| 2589 | 2578 |
| 2590 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2579 Verify206Response(headers, 40, 49); |
| 2591 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2580 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2592 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2581 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2593 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2582 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2594 | 2583 |
| 2595 // And the entry should be gone. | 2584 // And the entry should be gone. |
| 2596 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); | 2585 RunTransactionTest(cache.http_cache(), kRangeGET_TransactionOK); |
| 2597 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2586 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2598 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2587 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2599 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 2588 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 2600 | 2589 |
| 2601 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2590 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2602 } | 2591 } |
| 2603 | 2592 |
| 2604 // Tests that we can cache range requests when the start or end is unknown. | 2593 // Tests that we can cache range requests when the start or end is unknown. |
| 2605 // We start with one suffix request, followed by a request from a given point. | 2594 // We start with one suffix request, followed by a request from a given point. |
| 2606 TEST(HttpCache, UnknownRangeGET_1) { | 2595 TEST(HttpCache, UnknownRangeGET_1) { |
| 2607 MockHttpCache cache; | 2596 MockHttpCache cache; |
| 2608 cache.http_cache()->set_enable_range_support(true); | 2597 cache.http_cache()->set_enable_range_support(true); |
| 2609 AddMockTransaction(&kRangeGET_TransactionOK); | 2598 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2610 std::string headers; | 2599 std::string headers; |
| 2611 | 2600 |
| 2612 // Write to the cache (70-79). | 2601 // Write to the cache (70-79). |
| 2613 MockTransaction transaction(kRangeGET_TransactionOK); | 2602 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2614 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; | 2603 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; |
| 2615 transaction.data = "rg: 70-79 "; | 2604 transaction.data = "rg: 70-79 "; |
| 2616 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2605 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2617 | 2606 |
| 2618 EXPECT_TRUE(Verify206Response(headers, 70, 79)); | 2607 Verify206Response(headers, 70, 79); |
| 2619 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2608 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2620 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2609 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2621 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2610 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2622 | 2611 |
| 2623 // Make sure we are done with the previous transaction. | 2612 // Make sure we are done with the previous transaction. |
| 2624 MessageLoop::current()->RunAllPending(); | 2613 MessageLoop::current()->RunAllPending(); |
| 2625 | 2614 |
| 2626 // Write and read from the cache (60-79). | 2615 // Write and read from the cache (60-79). |
| 2627 transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER; | 2616 transaction.request_headers = "Range: bytes = 60-\r\n" EXTRA_HEADER; |
| 2628 transaction.data = "rg: 60-69 rg: 70-79 "; | 2617 transaction.data = "rg: 60-69 rg: 70-79 "; |
| 2629 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2618 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2630 | 2619 |
| 2631 EXPECT_TRUE(Verify206Response(headers, 60, 79)); | 2620 Verify206Response(headers, 60, 79); |
| 2632 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2621 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2633 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2622 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2634 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2623 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2635 | 2624 |
| 2636 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2625 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2637 } | 2626 } |
| 2638 | 2627 |
| 2639 // Tests that we can cache range requests when the start or end is unknown. | 2628 // Tests that we can cache range requests when the start or end is unknown. |
| 2640 // We start with one request from a given point, followed by a suffix request. | 2629 // We start with one request from a given point, followed by a suffix request. |
| 2641 // We'll also verify that synchronous cache responses work as intended. | 2630 // We'll also verify that synchronous cache responses work as intended. |
| 2642 TEST(HttpCache, UnknownRangeGET_2) { | 2631 TEST(HttpCache, UnknownRangeGET_2) { |
| 2643 MockHttpCache cache; | 2632 MockHttpCache cache; |
| 2644 cache.http_cache()->set_enable_range_support(true); | 2633 cache.http_cache()->set_enable_range_support(true); |
| 2645 std::string headers; | 2634 std::string headers; |
| 2646 | 2635 |
| 2647 MockTransaction transaction(kRangeGET_TransactionOK); | 2636 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2648 transaction.test_mode = TEST_MODE_SYNC_CACHE_START | | 2637 transaction.test_mode = TEST_MODE_SYNC_CACHE_START | |
| 2649 TEST_MODE_SYNC_CACHE_READ | | 2638 TEST_MODE_SYNC_CACHE_READ | |
| 2650 TEST_MODE_SYNC_CACHE_WRITE; | 2639 TEST_MODE_SYNC_CACHE_WRITE; |
| 2651 AddMockTransaction(&transaction); | 2640 AddMockTransaction(&transaction); |
| 2652 | 2641 |
| 2653 // Write to the cache (70-79). | 2642 // Write to the cache (70-79). |
| 2654 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; | 2643 transaction.request_headers = "Range: bytes = 70-\r\n" EXTRA_HEADER; |
| 2655 transaction.data = "rg: 70-79 "; | 2644 transaction.data = "rg: 70-79 "; |
| 2656 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2645 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2657 | 2646 |
| 2658 EXPECT_TRUE(Verify206Response(headers, 70, 79)); | 2647 Verify206Response(headers, 70, 79); |
| 2659 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2648 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2660 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2649 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2661 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2650 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2662 | 2651 |
| 2663 // Make sure we are done with the previous transaction. | 2652 // Make sure we are done with the previous transaction. |
| 2664 MessageLoop::current()->RunAllPending(); | 2653 MessageLoop::current()->RunAllPending(); |
| 2665 | 2654 |
| 2666 // Write and read from the cache (60-79). | 2655 // Write and read from the cache (60-79). |
| 2667 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; | 2656 transaction.request_headers = "Range: bytes = -20\r\n" EXTRA_HEADER; |
| 2668 transaction.data = "rg: 60-69 rg: 70-79 "; | 2657 transaction.data = "rg: 60-69 rg: 70-79 "; |
| 2669 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2658 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2670 | 2659 |
| 2671 EXPECT_TRUE(Verify206Response(headers, 60, 79)); | 2660 Verify206Response(headers, 60, 79); |
| 2672 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2661 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2673 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2662 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2674 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2663 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2675 | 2664 |
| 2676 RemoveMockTransaction(&transaction); | 2665 RemoveMockTransaction(&transaction); |
| 2677 } | 2666 } |
| 2678 | 2667 |
| 2679 // Tests that receiving Not Modified when asking for an open range doesn't mess | 2668 // Tests that receiving Not Modified when asking for an open range doesn't mess |
| 2680 // up things. | 2669 // up things. |
| 2681 TEST(HttpCache, UnknownRangeGET_304) { | 2670 TEST(HttpCache, UnknownRangeGET_304) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2710 TEST(HttpCache, GET_Previous206) { | 2699 TEST(HttpCache, GET_Previous206) { |
| 2711 MockHttpCache cache; | 2700 MockHttpCache cache; |
| 2712 cache.http_cache()->set_enable_range_support(true); | 2701 cache.http_cache()->set_enable_range_support(true); |
| 2713 AddMockTransaction(&kRangeGET_TransactionOK); | 2702 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2714 std::string headers; | 2703 std::string headers; |
| 2715 | 2704 |
| 2716 // Write to the cache (40-49). | 2705 // Write to the cache (40-49). |
| 2717 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2706 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2718 &headers); | 2707 &headers); |
| 2719 | 2708 |
| 2720 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2709 Verify206Response(headers, 40, 49); |
| 2721 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2710 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2722 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2711 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2723 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2712 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2724 | 2713 |
| 2725 // Write and read from the cache (0-79), when not asked for a range. | 2714 // Write and read from the cache (0-79), when not asked for a range. |
| 2726 MockTransaction transaction(kRangeGET_TransactionOK); | 2715 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2727 transaction.request_headers = EXTRA_HEADER; | 2716 transaction.request_headers = EXTRA_HEADER; |
| 2728 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 2717 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 2729 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 2718 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 2730 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2719 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2745 | 2734 |
| 2746 MockTransaction transaction(kRangeGET_TransactionOK); | 2735 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2747 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | 2736 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |
| 2748 transaction.data = "rg: 00-09 "; | 2737 transaction.data = "rg: 00-09 "; |
| 2749 AddMockTransaction(&transaction); | 2738 AddMockTransaction(&transaction); |
| 2750 std::string headers; | 2739 std::string headers; |
| 2751 | 2740 |
| 2752 // Write to the cache (0-9). | 2741 // Write to the cache (0-9). |
| 2753 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2742 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2754 | 2743 |
| 2755 EXPECT_TRUE(Verify206Response(headers, 0, 9)); | 2744 Verify206Response(headers, 0, 9); |
| 2756 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2745 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2757 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2746 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2758 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2747 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2759 | 2748 |
| 2760 // Read from the cache (0-9), write and read from cache (10 - 79), | 2749 // Read from the cache (0-9), write and read from cache (10 - 79), |
| 2761 MockTransaction transaction2(kRangeGET_TransactionOK); | 2750 MockTransaction transaction2(kRangeGET_TransactionOK); |
| 2762 transaction2.request_headers = "Foo: bar\r\n" EXTRA_HEADER; | 2751 transaction2.request_headers = "Foo: bar\r\n" EXTRA_HEADER; |
| 2763 transaction2.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " | 2752 transaction2.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 " |
| 2764 "rg: 50-59 rg: 60-69 rg: 70-79 "; | 2753 "rg: 50-59 rg: 60-69 rg: 70-79 "; |
| 2765 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 2754 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2779 cache.http_cache()->set_enable_range_support(true); | 2768 cache.http_cache()->set_enable_range_support(true); |
| 2780 AddMockTransaction(&kRangeGET_TransactionOK); | 2769 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2781 std::string headers; | 2770 std::string headers; |
| 2782 | 2771 |
| 2783 // Write to the cache (0-9). | 2772 // Write to the cache (0-9). |
| 2784 MockTransaction transaction(kRangeGET_TransactionOK); | 2773 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2785 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; | 2774 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; |
| 2786 transaction.data = "rg: 00-09 "; | 2775 transaction.data = "rg: 00-09 "; |
| 2787 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2776 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2788 | 2777 |
| 2789 EXPECT_TRUE(Verify206Response(headers, 0, 9)); | 2778 Verify206Response(headers, 0, 9); |
| 2790 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2779 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2791 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2780 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2792 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2781 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2793 | 2782 |
| 2794 // Now we'll issue a request without any range that should result first in a | 2783 // Now we'll issue a request without any range that should result first in a |
| 2795 // 206 (when revalidating), and then in a weird standard answer: the test | 2784 // 206 (when revalidating), and then in a weird standard answer: the test |
| 2796 // server will not modify the response so we'll get the default range... a | 2785 // server will not modify the response so we'll get the default range... a |
| 2797 // real server will answer with 200. | 2786 // real server will answer with 200. |
| 2798 MockTransaction transaction2(kRangeGET_TransactionOK); | 2787 MockTransaction transaction2(kRangeGET_TransactionOK); |
| 2799 transaction2.request_headers = EXTRA_HEADER; | 2788 transaction2.request_headers = EXTRA_HEADER; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2883 kRangeGET_TransactionOK.data, 500)); | 2872 kRangeGET_TransactionOK.data, 500)); |
| 2884 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); | 2873 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); |
| 2885 entry->Close(); | 2874 entry->Close(); |
| 2886 | 2875 |
| 2887 // Now see that we don't use the stored entry. | 2876 // Now see that we don't use the stored entry. |
| 2888 std::string headers; | 2877 std::string headers; |
| 2889 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2878 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 2890 &headers); | 2879 &headers); |
| 2891 | 2880 |
| 2892 // We are expecting a 206. | 2881 // We are expecting a 206. |
| 2893 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2882 Verify206Response(headers, 40, 49); |
| 2894 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2883 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2895 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2884 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2896 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 2885 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 2897 | 2886 |
| 2898 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2887 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2899 } | 2888 } |
| 2900 | 2889 |
| 2901 // Tests that we can handle range requests with cached 200 responses. | 2890 // Tests that we can handle range requests with cached 200 responses. |
| 2902 TEST(HttpCache, RangeGET_Previous200) { | 2891 TEST(HttpCache, RangeGET_Previous200) { |
| 2903 MockHttpCache cache; | 2892 MockHttpCache cache; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2918 AddMockTransaction(&kRangeGET_TransactionOK); | 2907 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2919 | 2908 |
| 2920 // Now see that we use the stored entry. | 2909 // Now see that we use the stored entry. |
| 2921 std::string headers; | 2910 std::string headers; |
| 2922 MockTransaction transaction2(kRangeGET_TransactionOK); | 2911 MockTransaction transaction2(kRangeGET_TransactionOK); |
| 2923 RangeTransactionServer handler; | 2912 RangeTransactionServer handler; |
| 2924 handler.set_not_modified(true); | 2913 handler.set_not_modified(true); |
| 2925 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 2914 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 2926 | 2915 |
| 2927 // We are expecting a 206. | 2916 // We are expecting a 206. |
| 2928 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2917 Verify206Response(headers, 40, 49); |
| 2929 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2918 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 2930 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2919 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 2931 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2920 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2932 | 2921 |
| 2933 // The last transaction has finished so make sure the entry is deactivated. | 2922 // The last transaction has finished so make sure the entry is deactivated. |
| 2934 MessageLoop::current()->RunAllPending(); | 2923 MessageLoop::current()->RunAllPending(); |
| 2935 | 2924 |
| 2936 // Now we should receive a range from the server and drop the stored entry. | 2925 // Now we should receive a range from the server and drop the stored entry. |
| 2937 handler.set_not_modified(false); | 2926 handler.set_not_modified(false); |
| 2938 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; | 2927 transaction2.request_headers = kRangeGET_TransactionOK.request_headers; |
| 2939 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); | 2928 RunTransactionTestWithResponse(cache.http_cache(), transaction2, &headers); |
| 2940 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2929 Verify206Response(headers, 40, 49); |
| 2941 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 2930 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 2942 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 2931 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
| 2943 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2932 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2944 | 2933 |
| 2945 RunTransactionTest(cache.http_cache(), transaction2); | 2934 RunTransactionTest(cache.http_cache(), transaction2); |
| 2946 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 2935 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 2947 | 2936 |
| 2948 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2937 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2949 } | 2938 } |
| 2950 | 2939 |
| 2951 // Tests that we can handle a 200 response when dealing with sparse entries. | 2940 // Tests that we can handle a 200 response when dealing with sparse entries. |
| 2952 TEST(HttpCache, RangeRequestResultsIn200) { | 2941 TEST(HttpCache, RangeRequestResultsIn200) { |
| 2953 MockHttpCache cache; | 2942 MockHttpCache cache; |
| 2954 cache.http_cache()->set_enable_range_support(true); | 2943 cache.http_cache()->set_enable_range_support(true); |
| 2955 AddMockTransaction(&kRangeGET_TransactionOK); | 2944 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2956 std::string headers; | 2945 std::string headers; |
| 2957 | 2946 |
| 2958 // Write to the cache (70-79). | 2947 // Write to the cache (70-79). |
| 2959 MockTransaction transaction(kRangeGET_TransactionOK); | 2948 MockTransaction transaction(kRangeGET_TransactionOK); |
| 2960 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; | 2949 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; |
| 2961 transaction.data = "rg: 70-79 "; | 2950 transaction.data = "rg: 70-79 "; |
| 2962 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 2951 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 2963 | 2952 |
| 2964 EXPECT_TRUE(Verify206Response(headers, 70, 79)); | 2953 Verify206Response(headers, 70, 79); |
| 2965 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2954 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 2966 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2955 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 2967 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2956 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 2968 | 2957 |
| 2969 // Now we'll issue a request that results in a plain 200 response, but to | 2958 // Now we'll issue a request that results in a plain 200 response, but to |
| 2970 // the to the same URL that we used to store sparse data, and making sure | 2959 // the to the same URL that we used to store sparse data, and making sure |
| 2971 // that we ask for a range. | 2960 // that we ask for a range. |
| 2972 RemoveMockTransaction(&kRangeGET_TransactionOK); | 2961 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 2973 MockTransaction transaction2(kSimpleGET_Transaction); | 2962 MockTransaction transaction2(kSimpleGET_Transaction); |
| 2974 transaction2.url = kRangeGET_TransactionOK.url; | 2963 transaction2.url = kRangeGET_TransactionOK.url; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2993 TEST(HttpCache, RangeGET_MoreThanCurrentSize) { | 2982 TEST(HttpCache, RangeGET_MoreThanCurrentSize) { |
| 2994 MockHttpCache cache; | 2983 MockHttpCache cache; |
| 2995 cache.http_cache()->set_enable_range_support(true); | 2984 cache.http_cache()->set_enable_range_support(true); |
| 2996 AddMockTransaction(&kRangeGET_TransactionOK); | 2985 AddMockTransaction(&kRangeGET_TransactionOK); |
| 2997 std::string headers; | 2986 std::string headers; |
| 2998 | 2987 |
| 2999 // Write to the cache (40-49). | 2988 // Write to the cache (40-49). |
| 3000 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 2989 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3001 &headers); | 2990 &headers); |
| 3002 | 2991 |
| 3003 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 2992 Verify206Response(headers, 40, 49); |
| 3004 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2993 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3005 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2994 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3006 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2995 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3007 | 2996 |
| 3008 // A weird request should not delete this entry. Ask for bytes 120-. | 2997 // A weird request should not delete this entry. Ask for bytes 120-. |
| 3009 MockTransaction transaction(kRangeGET_TransactionOK); | 2998 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3010 transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER; | 2999 transaction.request_headers = "Range: bytes = 120-\r\n" EXTRA_HEADER; |
| 3011 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3000 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3012 | 3001 |
| 3013 EXPECT_EQ(0U, headers.find("HTTP/1.1 416 ")); | 3002 EXPECT_EQ(0U, headers.find("HTTP/1.1 416 ")); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3234 | 3223 |
| 3235 MockTransaction transaction(kRangeGET_TransactionOK); | 3224 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3236 transaction.handler = NULL; | 3225 transaction.handler = NULL; |
| 3237 transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER; | 3226 transaction.request_headers = "Range: bytes = 50-59\r\n" EXTRA_HEADER; |
| 3238 std::string response_headers(transaction.response_headers); | 3227 std::string response_headers(transaction.response_headers); |
| 3239 response_headers.append("Content-Range: bytes 50-59/160\n"); | 3228 response_headers.append("Content-Range: bytes 50-59/160\n"); |
| 3240 transaction.response_headers = response_headers.c_str(); | 3229 transaction.response_headers = response_headers.c_str(); |
| 3241 AddMockTransaction(&transaction); | 3230 AddMockTransaction(&transaction); |
| 3242 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3231 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3243 | 3232 |
| 3244 EXPECT_TRUE(Verify206Response(headers, 50, 59)); | 3233 Verify206Response(headers, 50, 59); |
| 3245 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3234 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3246 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3235 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3247 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3236 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3248 | 3237 |
| 3249 RemoveMockTransaction(&transaction); | 3238 RemoveMockTransaction(&transaction); |
| 3250 AddMockTransaction(&kRangeGET_TransactionOK); | 3239 AddMockTransaction(&kRangeGET_TransactionOK); |
| 3251 | 3240 |
| 3252 // This transaction will report a resource size of 80 bytes, and we think it's | 3241 // This transaction will report a resource size of 80 bytes, and we think it's |
| 3253 // 160 so we should ignore the response. | 3242 // 160 so we should ignore the response. |
| 3254 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3243 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3255 &headers); | 3244 &headers); |
| 3256 | 3245 |
| 3257 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 3246 Verify206Response(headers, 40, 49); |
| 3258 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3247 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
| 3259 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3248 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3260 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 3249 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 3261 | 3250 |
| 3262 // Verify that we cached the first response but not the second one. | 3251 // Verify that we cached the first response but not the second one. |
| 3263 disk_cache::Entry* en; | 3252 disk_cache::Entry* en; |
| 3264 ASSERT_EQ(net::OK, cache.disk_cache()->OpenEntry(kRangeGET_TransactionOK.url, | 3253 ASSERT_EQ(net::OK, cache.disk_cache()->OpenEntry(kRangeGET_TransactionOK.url, |
| 3265 &en, NULL)); | 3254 &en, NULL)); |
| 3266 int64 cached_start = 0; | 3255 int64 cached_start = 0; |
| 3267 EXPECT_EQ(10, en->GetAvailableRange(40, 20, &cached_start)); | 3256 EXPECT_EQ(10, en->GetAvailableRange(40, 20, &cached_start)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3325 AddMockTransaction(&kRangeGET_TransactionOK); | 3314 AddMockTransaction(&kRangeGET_TransactionOK); |
| 3326 | 3315 |
| 3327 MockTransaction transaction(kRangeGET_TransactionOK); | 3316 MockTransaction transaction(kRangeGET_TransactionOK); |
| 3328 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; | 3317 transaction.request_headers = "Range: bytes = -10\r\n" EXTRA_HEADER; |
| 3329 transaction.method = "HEAD"; | 3318 transaction.method = "HEAD"; |
| 3330 transaction.data = "rg: 70-79 "; | 3319 transaction.data = "rg: 70-79 "; |
| 3331 | 3320 |
| 3332 std::string headers; | 3321 std::string headers; |
| 3333 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); | 3322 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers); |
| 3334 | 3323 |
| 3335 EXPECT_TRUE(Verify206Response(headers, 70, 79)); | 3324 Verify206Response(headers, 70, 79); |
| 3336 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3325 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3337 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3326 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3338 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3327 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
| 3339 | 3328 |
| 3340 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3329 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 3341 } | 3330 } |
| 3342 | 3331 |
| 3343 // Tests that we don't crash when after reading from the cache we issue a | 3332 // Tests that we don't crash when after reading from the cache we issue a |
| 3344 // request for the next range and the server gives us a 200 synchronously. | 3333 // request for the next range and the server gives us a 200 synchronously. |
| 3345 TEST(HttpCache, RangeGET_FastFlakyServer) { | 3334 TEST(HttpCache, RangeGET_FastFlakyServer) { |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3867 int len = static_cast<int>(base::strlcpy(buf->data(), | 3856 int len = static_cast<int>(base::strlcpy(buf->data(), |
| 3868 "rg: 00-09 rg: 10-19 ", 100)); | 3857 "rg: 00-09 rg: 10-19 ", 100)); |
| 3869 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); | 3858 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true)); |
| 3870 entry->Close(); | 3859 entry->Close(); |
| 3871 | 3860 |
| 3872 // Now make a range request. | 3861 // Now make a range request. |
| 3873 std::string headers; | 3862 std::string headers; |
| 3874 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, | 3863 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK, |
| 3875 &headers); | 3864 &headers); |
| 3876 | 3865 |
| 3877 EXPECT_TRUE(Verify206Response(headers, 40, 49)); | 3866 Verify206Response(headers, 40, 49); |
| 3878 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3867 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 3879 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 3868 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 3880 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3869 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3881 | 3870 |
| 3882 RemoveMockTransaction(&kRangeGET_TransactionOK); | 3871 RemoveMockTransaction(&kRangeGET_TransactionOK); |
| 3883 } | 3872 } |
| 3884 | 3873 |
| 3885 TEST(HttpCache, SyncRead) { | 3874 TEST(HttpCache, SyncRead) { |
| 3886 MockHttpCache cache; | 3875 MockHttpCache cache; |
| 3887 | 3876 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4344 // Now return 200 when validating the entry so the metadata will be lost. | 4333 // Now return 200 when validating the entry so the metadata will be lost. |
| 4345 MockTransaction trans2(kTypicalGET_Transaction); | 4334 MockTransaction trans2(kTypicalGET_Transaction); |
| 4346 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4335 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
| 4347 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4336 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
| 4348 EXPECT_TRUE(response.metadata.get() == NULL); | 4337 EXPECT_TRUE(response.metadata.get() == NULL); |
| 4349 | 4338 |
| 4350 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4339 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 4351 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4340 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
| 4352 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4341 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 4353 } | 4342 } |
| OLD | NEW |