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 "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 static bool not_modified_; | 290 static bool not_modified_; |
291 static bool modified_; | 291 static bool modified_; |
292 static bool bad_200_; | 292 static bool bad_200_; |
293 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); | 293 DISALLOW_COPY_AND_ASSIGN(RangeTransactionServer); |
294 }; | 294 }; |
295 bool RangeTransactionServer::not_modified_ = false; | 295 bool RangeTransactionServer::not_modified_ = false; |
296 bool RangeTransactionServer::modified_ = false; | 296 bool RangeTransactionServer::modified_ = false; |
297 bool RangeTransactionServer::bad_200_ = false; | 297 bool RangeTransactionServer::bad_200_ = false; |
298 | 298 |
299 // A dummy extra header that must be preserved on a given request. | 299 // A dummy extra header that must be preserved on a given request. |
300 #define EXTRA_HEADER "Extra: header" | 300 |
| 301 // EXTRA_HEADER_LINE doesn't include a line terminator because it |
| 302 // will be passed to AddHeaderFromString() which doesn't accept them. |
| 303 #define EXTRA_HEADER_LINE "Extra: header" |
| 304 |
| 305 // EXTRA_HEADER contains a line terminator, as expected by |
| 306 // AddHeadersFromString() (_not_ AddHeaderFromString()). |
| 307 #define EXTRA_HEADER EXTRA_HEADER_LINE "\r\n" |
| 308 |
301 static const char kExtraHeaderKey[] = "Extra"; | 309 static const char kExtraHeaderKey[] = "Extra"; |
302 | 310 |
303 // Static. | 311 // Static. |
304 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, | 312 void RangeTransactionServer::RangeHandler(const net::HttpRequestInfo* request, |
305 std::string* response_status, | 313 std::string* response_status, |
306 std::string* response_headers, | 314 std::string* response_headers, |
307 std::string* response_data) { | 315 std::string* response_data) { |
308 if (request->extra_headers.IsEmpty()) { | 316 if (request->extra_headers.IsEmpty()) { |
309 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); | 317 response_status->assign("HTTP/1.1 416 Requested Range Not Satisfiable"); |
310 response_data->clear(); | 318 response_data->clear(); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 813 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
806 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 814 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
807 } | 815 } |
808 | 816 |
809 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. | 817 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. |
810 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMatch) { | 818 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMatch) { |
811 MockHttpCache cache; | 819 MockHttpCache cache; |
812 | 820 |
813 // Write to the cache. | 821 // Write to the cache. |
814 MockTransaction transaction(kSimpleGET_Transaction); | 822 MockTransaction transaction(kSimpleGET_Transaction); |
815 transaction.request_headers = "Foo: bar\n"; | 823 transaction.request_headers = "Foo: bar\r\n"; |
816 transaction.response_headers = "Cache-Control: max-age=10000\n" | 824 transaction.response_headers = "Cache-Control: max-age=10000\n" |
817 "Vary: Foo\n"; | 825 "Vary: Foo\n"; |
818 AddMockTransaction(&transaction); | 826 AddMockTransaction(&transaction); |
819 RunTransactionTest(cache.http_cache(), transaction); | 827 RunTransactionTest(cache.http_cache(), transaction); |
820 | 828 |
821 // Read from the cache. | 829 // Read from the cache. |
822 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; | 830 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; |
823 RunTransactionTest(cache.http_cache(), transaction); | 831 RunTransactionTest(cache.http_cache(), transaction); |
824 | 832 |
825 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 833 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
826 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 834 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
827 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 835 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
828 RemoveMockTransaction(&transaction); | 836 RemoveMockTransaction(&transaction); |
829 } | 837 } |
830 | 838 |
831 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. | 839 // Tests LOAD_PREFERRING_CACHE in the presence of vary headers. |
832 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMismatch) { | 840 TEST(HttpCache, SimpleGET_LoadPreferringCache_VaryMismatch) { |
833 MockHttpCache cache; | 841 MockHttpCache cache; |
834 | 842 |
835 // Write to the cache. | 843 // Write to the cache. |
836 MockTransaction transaction(kSimpleGET_Transaction); | 844 MockTransaction transaction(kSimpleGET_Transaction); |
837 transaction.request_headers = "Foo: bar\n"; | 845 transaction.request_headers = "Foo: bar\r\n"; |
838 transaction.response_headers = "Cache-Control: max-age=10000\n" | 846 transaction.response_headers = "Cache-Control: max-age=10000\n" |
839 "Vary: Foo\n"; | 847 "Vary: Foo\n"; |
840 AddMockTransaction(&transaction); | 848 AddMockTransaction(&transaction); |
841 RunTransactionTest(cache.http_cache(), transaction); | 849 RunTransactionTest(cache.http_cache(), transaction); |
842 | 850 |
843 // Attempt to read from the cache... this is a vary mismatch that must reach | 851 // Attempt to read from the cache... this is a vary mismatch that must reach |
844 // the network again. | 852 // the network again. |
845 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; | 853 transaction.load_flags |= net::LOAD_PREFERRING_CACHE; |
846 transaction.request_headers = "Foo: none\n"; | 854 transaction.request_headers = "Foo: none\r\n"; |
847 RunTransactionTest(cache.http_cache(), transaction); | 855 RunTransactionTest(cache.http_cache(), transaction); |
848 | 856 |
849 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 857 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
850 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 858 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
851 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 859 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
852 RemoveMockTransaction(&transaction); | 860 RemoveMockTransaction(&transaction); |
853 } | 861 } |
854 | 862 |
855 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on | 863 // Tests that LOAD_FROM_CACHE_IF_OFFLINE returns proper response on |
856 // network success | 864 // network success |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } | 1045 } |
1038 | 1046 |
1039 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { | 1047 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit) { |
1040 MockHttpCache cache; | 1048 MockHttpCache cache; |
1041 | 1049 |
1042 // write to the cache | 1050 // write to the cache |
1043 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1051 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1044 | 1052 |
1045 // force this transaction to write to the cache again | 1053 // force this transaction to write to the cache again |
1046 MockTransaction transaction(kSimpleGET_Transaction); | 1054 MockTransaction transaction(kSimpleGET_Transaction); |
1047 transaction.request_headers = "pragma: no-cache"; | 1055 transaction.request_headers = "pragma: no-cache\r\n"; |
1048 | 1056 |
1049 RunTransactionTest(cache.http_cache(), transaction); | 1057 RunTransactionTest(cache.http_cache(), transaction); |
1050 | 1058 |
1051 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1059 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1052 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1060 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1053 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 1061 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
1054 } | 1062 } |
1055 | 1063 |
1056 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit2) { | 1064 TEST(HttpCache, SimpleGET_LoadBypassCache_Implicit2) { |
1057 MockHttpCache cache; | 1065 MockHttpCache cache; |
1058 | 1066 |
1059 // write to the cache | 1067 // write to the cache |
1060 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1068 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1061 | 1069 |
1062 // force this transaction to write to the cache again | 1070 // force this transaction to write to the cache again |
1063 MockTransaction transaction(kSimpleGET_Transaction); | 1071 MockTransaction transaction(kSimpleGET_Transaction); |
1064 transaction.request_headers = "cache-control: no-cache"; | 1072 transaction.request_headers = "cache-control: no-cache\r\n"; |
1065 | 1073 |
1066 RunTransactionTest(cache.http_cache(), transaction); | 1074 RunTransactionTest(cache.http_cache(), transaction); |
1067 | 1075 |
1068 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1076 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1069 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1077 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1070 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 1078 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
1071 } | 1079 } |
1072 | 1080 |
1073 TEST(HttpCache, SimpleGET_LoadValidateCache) { | 1081 TEST(HttpCache, SimpleGET_LoadValidateCache) { |
1074 MockHttpCache cache; | 1082 MockHttpCache cache; |
(...skipping 22 matching lines...) Expand all Loading... |
1097 MockHttpCache cache; | 1105 MockHttpCache cache; |
1098 | 1106 |
1099 // write to the cache | 1107 // write to the cache |
1100 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1108 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1101 | 1109 |
1102 // read from the cache | 1110 // read from the cache |
1103 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); | 1111 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
1104 | 1112 |
1105 // force this transaction to validate the cache | 1113 // force this transaction to validate the cache |
1106 MockTransaction transaction(kSimpleGET_Transaction); | 1114 MockTransaction transaction(kSimpleGET_Transaction); |
1107 transaction.request_headers = "cache-control: max-age=0"; | 1115 transaction.request_headers = "cache-control: max-age=0\r\n"; |
1108 | 1116 |
1109 RunTransactionTest(cache.http_cache(), transaction); | 1117 RunTransactionTest(cache.http_cache(), transaction); |
1110 | 1118 |
1111 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1119 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1112 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1120 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1113 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1121 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1114 } | 1122 } |
1115 | 1123 |
1116 static void PreserveRequestHeaders_Handler( | 1124 static void PreserveRequestHeaders_Handler( |
1117 const net::HttpRequestInfo* request, | 1125 const net::HttpRequestInfo* request, |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 response_data->assign(kTypicalGET_Transaction.data); | 1955 response_data->assign(kTypicalGET_Transaction.data); |
1948 } | 1956 } |
1949 } | 1957 } |
1950 | 1958 |
1951 // Tests revalidation after a vary match. | 1959 // Tests revalidation after a vary match. |
1952 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMatch) { | 1960 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMatch) { |
1953 MockHttpCache cache; | 1961 MockHttpCache cache; |
1954 | 1962 |
1955 // Write to the cache. | 1963 // Write to the cache. |
1956 MockTransaction transaction(kTypicalGET_Transaction); | 1964 MockTransaction transaction(kTypicalGET_Transaction); |
1957 transaction.request_headers = "Foo: bar\n"; | 1965 transaction.request_headers = "Foo: bar\r\n"; |
1958 transaction.response_headers = | 1966 transaction.response_headers = |
1959 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" | 1967 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" |
1960 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 1968 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
1961 "Etag: \"foopy\"\n" | 1969 "Etag: \"foopy\"\n" |
1962 "Cache-Control: max-age=0\n" | 1970 "Cache-Control: max-age=0\n" |
1963 "Vary: Foo\n"; | 1971 "Vary: Foo\n"; |
1964 AddMockTransaction(&transaction); | 1972 AddMockTransaction(&transaction); |
1965 RunTransactionTest(cache.http_cache(), transaction); | 1973 RunTransactionTest(cache.http_cache(), transaction); |
1966 | 1974 |
1967 // Read from the cache. | 1975 // Read from the cache. |
1968 RevalidationServer server; | 1976 RevalidationServer server; |
1969 transaction.handler = server.Handler; | 1977 transaction.handler = server.Handler; |
1970 RunTransactionTest(cache.http_cache(), transaction); | 1978 RunTransactionTest(cache.http_cache(), transaction); |
1971 | 1979 |
1972 EXPECT_TRUE(server.EtagUsed()); | 1980 EXPECT_TRUE(server.EtagUsed()); |
1973 EXPECT_TRUE(server.LastModifiedUsed()); | 1981 EXPECT_TRUE(server.LastModifiedUsed()); |
1974 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 1982 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
1975 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 1983 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
1976 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1984 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1977 RemoveMockTransaction(&transaction); | 1985 RemoveMockTransaction(&transaction); |
1978 } | 1986 } |
1979 | 1987 |
1980 // Tests revalidation after a vary mismatch if etag is present. | 1988 // Tests revalidation after a vary mismatch if etag is present. |
1981 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMismatch) { | 1989 TEST(HttpCache, SimpleGET_LoadValidateCache_VaryMismatch) { |
1982 MockHttpCache cache; | 1990 MockHttpCache cache; |
1983 | 1991 |
1984 // Write to the cache. | 1992 // Write to the cache. |
1985 MockTransaction transaction(kTypicalGET_Transaction); | 1993 MockTransaction transaction(kTypicalGET_Transaction); |
1986 transaction.request_headers = "Foo: bar\n"; | 1994 transaction.request_headers = "Foo: bar\r\n"; |
1987 transaction.response_headers = | 1995 transaction.response_headers = |
1988 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" | 1996 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" |
1989 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 1997 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
1990 "Etag: \"foopy\"\n" | 1998 "Etag: \"foopy\"\n" |
1991 "Cache-Control: max-age=0\n" | 1999 "Cache-Control: max-age=0\n" |
1992 "Vary: Foo\n"; | 2000 "Vary: Foo\n"; |
1993 AddMockTransaction(&transaction); | 2001 AddMockTransaction(&transaction); |
1994 RunTransactionTest(cache.http_cache(), transaction); | 2002 RunTransactionTest(cache.http_cache(), transaction); |
1995 | 2003 |
1996 // Read from the cache and revalidate the entry. | 2004 // Read from the cache and revalidate the entry. |
1997 RevalidationServer server; | 2005 RevalidationServer server; |
1998 transaction.handler = server.Handler; | 2006 transaction.handler = server.Handler; |
1999 transaction.request_headers = "Foo: none\n"; | 2007 transaction.request_headers = "Foo: none\r\n"; |
2000 RunTransactionTest(cache.http_cache(), transaction); | 2008 RunTransactionTest(cache.http_cache(), transaction); |
2001 | 2009 |
2002 EXPECT_TRUE(server.EtagUsed()); | 2010 EXPECT_TRUE(server.EtagUsed()); |
2003 EXPECT_FALSE(server.LastModifiedUsed()); | 2011 EXPECT_FALSE(server.LastModifiedUsed()); |
2004 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2012 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2005 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2013 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2006 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2014 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2007 RemoveMockTransaction(&transaction); | 2015 RemoveMockTransaction(&transaction); |
2008 } | 2016 } |
2009 | 2017 |
2010 // Tests lack of revalidation after a vary mismatch and no etag. | 2018 // Tests lack of revalidation after a vary mismatch and no etag. |
2011 TEST(HttpCache, SimpleGET_LoadDontValidateCache_VaryMismatch) { | 2019 TEST(HttpCache, SimpleGET_LoadDontValidateCache_VaryMismatch) { |
2012 MockHttpCache cache; | 2020 MockHttpCache cache; |
2013 | 2021 |
2014 // Write to the cache. | 2022 // Write to the cache. |
2015 MockTransaction transaction(kTypicalGET_Transaction); | 2023 MockTransaction transaction(kTypicalGET_Transaction); |
2016 transaction.request_headers = "Foo: bar\n"; | 2024 transaction.request_headers = "Foo: bar\r\n"; |
2017 transaction.response_headers = | 2025 transaction.response_headers = |
2018 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" | 2026 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" |
2019 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" | 2027 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n" |
2020 "Cache-Control: max-age=0\n" | 2028 "Cache-Control: max-age=0\n" |
2021 "Vary: Foo\n"; | 2029 "Vary: Foo\n"; |
2022 AddMockTransaction(&transaction); | 2030 AddMockTransaction(&transaction); |
2023 RunTransactionTest(cache.http_cache(), transaction); | 2031 RunTransactionTest(cache.http_cache(), transaction); |
2024 | 2032 |
2025 // Read from the cache and don't revalidate the entry. | 2033 // Read from the cache and don't revalidate the entry. |
2026 RevalidationServer server; | 2034 RevalidationServer server; |
2027 transaction.handler = server.Handler; | 2035 transaction.handler = server.Handler; |
2028 transaction.request_headers = "Foo: none\n"; | 2036 transaction.request_headers = "Foo: none\r\n"; |
2029 RunTransactionTest(cache.http_cache(), transaction); | 2037 RunTransactionTest(cache.http_cache(), transaction); |
2030 | 2038 |
2031 EXPECT_FALSE(server.EtagUsed()); | 2039 EXPECT_FALSE(server.EtagUsed()); |
2032 EXPECT_FALSE(server.LastModifiedUsed()); | 2040 EXPECT_FALSE(server.LastModifiedUsed()); |
2033 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2041 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2034 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2042 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2035 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2043 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2036 RemoveMockTransaction(&transaction); | 2044 RemoveMockTransaction(&transaction); |
2037 } | 2045 } |
2038 | 2046 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 // Write to the cache. | 2085 // Write to the cache. |
2078 RunTransactionTest(cache.http_cache(), transaction); | 2086 RunTransactionTest(cache.http_cache(), transaction); |
2079 | 2087 |
2080 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2088 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
2081 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 2089 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
2082 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 2090 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
2083 | 2091 |
2084 // Get the same URL again, but use a byte range request. | 2092 // Get the same URL again, but use a byte range request. |
2085 transaction.load_flags = net::LOAD_VALIDATE_CACHE; | 2093 transaction.load_flags = net::LOAD_VALIDATE_CACHE; |
2086 transaction.handler = ETagGet_UnconditionalRequest_Handler; | 2094 transaction.handler = ETagGet_UnconditionalRequest_Handler; |
2087 transaction.request_headers = "Range: bytes = 5-"; | 2095 transaction.request_headers = "Range: bytes = 5-\r\n"; |
2088 RunTransactionTest(cache.http_cache(), transaction); | 2096 RunTransactionTest(cache.http_cache(), transaction); |
2089 | 2097 |
2090 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 2098 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
2091 EXPECT_EQ(1, cache.disk_cache()->open_count()); | 2099 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
2092 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 2100 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
2093 } | 2101 } |
2094 | 2102 |
2095 static void ETagGet_ConditionalRequest_NoStore_Handler( | 2103 static void ETagGet_ConditionalRequest_NoStore_Handler( |
2096 const net::HttpRequestInfo* request, | 2104 const net::HttpRequestInfo* request, |
2097 std::string* response_status, | 2105 std::string* response_status, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 | 2265 |
2258 // Second network response for |kUrl|. | 2266 // Second network response for |kUrl|. |
2259 static const Response kNetResponse2 = { | 2267 static const Response kNetResponse2 = { |
2260 "HTTP/1.1 200 OK", | 2268 "HTTP/1.1 200 OK", |
2261 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2269 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2262 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2270 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2263 "body2" | 2271 "body2" |
2264 }; | 2272 }; |
2265 | 2273 |
2266 const char* extra_headers = | 2274 const char* extra_headers = |
2267 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"; | 2275 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2268 | 2276 |
2269 ConditionalizedRequestUpdatesCacheHelper( | 2277 ConditionalizedRequestUpdatesCacheHelper( |
2270 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2278 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2271 } | 2279 } |
2272 | 2280 |
2273 // Check that when an "if-none-match" header is attached | 2281 // Check that when an "if-none-match" header is attached |
2274 // to the request, the result updates the cached entry. | 2282 // to the request, the result updates the cached entry. |
2275 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { | 2283 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { |
2276 // First network response for |kUrl|. | 2284 // First network response for |kUrl|. |
2277 static const Response kNetResponse1 = { | 2285 static const Response kNetResponse1 = { |
2278 "HTTP/1.1 200 OK", | 2286 "HTTP/1.1 200 OK", |
2279 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2287 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2280 "Etag: \"ETAG1\"\n" | 2288 "Etag: \"ETAG1\"\n" |
2281 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2289 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2282 "body1" | 2290 "body1" |
2283 }; | 2291 }; |
2284 | 2292 |
2285 // Second network response for |kUrl|. | 2293 // Second network response for |kUrl|. |
2286 static const Response kNetResponse2 = { | 2294 static const Response kNetResponse2 = { |
2287 "HTTP/1.1 200 OK", | 2295 "HTTP/1.1 200 OK", |
2288 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2296 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2289 "Etag: \"ETAG2\"\n" | 2297 "Etag: \"ETAG2\"\n" |
2290 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2298 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2291 "body2" | 2299 "body2" |
2292 }; | 2300 }; |
2293 | 2301 |
2294 const char* extra_headers = "If-None-Match: \"ETAG1\"\n"; | 2302 const char* extra_headers = "If-None-Match: \"ETAG1\"\r\n"; |
2295 | 2303 |
2296 ConditionalizedRequestUpdatesCacheHelper( | 2304 ConditionalizedRequestUpdatesCacheHelper( |
2297 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2305 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2298 } | 2306 } |
2299 | 2307 |
2300 // Check that when an "if-modified-since" header is attached | 2308 // Check that when an "if-modified-since" header is attached |
2301 // to a request, the 304 (not modified result) result updates the cached | 2309 // to a request, the 304 (not modified result) result updates the cached |
2302 // headers, and the 304 response is returned rather than the cached response. | 2310 // headers, and the 304 response is returned rather than the cached response. |
2303 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { | 2311 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { |
2304 // First network response for |kUrl|. | 2312 // First network response for |kUrl|. |
(...skipping 16 matching lines...) Expand all Loading... |
2321 | 2329 |
2322 static const Response kCachedResponse2 = { | 2330 static const Response kCachedResponse2 = { |
2323 "HTTP/1.1 200 OK", | 2331 "HTTP/1.1 200 OK", |
2324 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2332 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2325 "Server: server2\n" | 2333 "Server: server2\n" |
2326 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2334 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2327 "body1" | 2335 "body1" |
2328 }; | 2336 }; |
2329 | 2337 |
2330 const char* extra_headers = | 2338 const char* extra_headers = |
2331 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"; | 2339 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2332 | 2340 |
2333 ConditionalizedRequestUpdatesCacheHelper( | 2341 ConditionalizedRequestUpdatesCacheHelper( |
2334 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); | 2342 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); |
2335 } | 2343 } |
2336 | 2344 |
2337 // Test that when doing an externally conditionalized if-modified-since | 2345 // Test that when doing an externally conditionalized if-modified-since |
2338 // and there is no corresponding cache entry, a new cache entry is NOT | 2346 // and there is no corresponding cache entry, a new cache entry is NOT |
2339 // created (304 response). | 2347 // created (304 response). |
2340 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { | 2348 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { |
2341 MockHttpCache cache; | 2349 MockHttpCache cache; |
2342 | 2350 |
2343 const char* kUrl = "http://foobar.com/main.css"; | 2351 const char* kUrl = "http://foobar.com/main.css"; |
2344 | 2352 |
2345 static const Response kNetResponse = { | 2353 static const Response kNetResponse = { |
2346 "HTTP/1.1 304 Not Modified", | 2354 "HTTP/1.1 304 Not Modified", |
2347 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2355 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2348 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2356 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2349 "" | 2357 "" |
2350 }; | 2358 }; |
2351 | 2359 |
2352 const char* kExtraRequestHeaders = | 2360 const char* kExtraRequestHeaders = |
2353 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; | 2361 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2354 | 2362 |
2355 // We will control the network layer's responses for |kUrl| using | 2363 // We will control the network layer's responses for |kUrl| using |
2356 // |mock_network_response|. | 2364 // |mock_network_response|. |
2357 MockTransaction mock_network_response = { 0 }; | 2365 MockTransaction mock_network_response = { 0 }; |
2358 mock_network_response.url = kUrl; | 2366 mock_network_response.url = kUrl; |
2359 AddMockTransaction(&mock_network_response); | 2367 AddMockTransaction(&mock_network_response); |
2360 | 2368 |
2361 MockTransaction request = { 0 }; | 2369 MockTransaction request = { 0 }; |
2362 request.url = kUrl; | 2370 request.url = kUrl; |
2363 request.method = "GET"; | 2371 request.method = "GET"; |
(...skipping 23 matching lines...) Expand all Loading... |
2387 const char* kUrl = "http://foobar.com/main.css"; | 2395 const char* kUrl = "http://foobar.com/main.css"; |
2388 | 2396 |
2389 static const Response kNetResponse = { | 2397 static const Response kNetResponse = { |
2390 "HTTP/1.1 200 OK", | 2398 "HTTP/1.1 200 OK", |
2391 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2399 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2392 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2400 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2393 "foobar!!!" | 2401 "foobar!!!" |
2394 }; | 2402 }; |
2395 | 2403 |
2396 const char* kExtraRequestHeaders = | 2404 const char* kExtraRequestHeaders = |
2397 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; | 2405 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2398 | 2406 |
2399 // We will control the network layer's responses for |kUrl| using | 2407 // We will control the network layer's responses for |kUrl| using |
2400 // |mock_network_response|. | 2408 // |mock_network_response|. |
2401 MockTransaction mock_network_response = { 0 }; | 2409 MockTransaction mock_network_response = { 0 }; |
2402 mock_network_response.url = kUrl; | 2410 mock_network_response.url = kUrl; |
2403 AddMockTransaction(&mock_network_response); | 2411 AddMockTransaction(&mock_network_response); |
2404 | 2412 |
2405 MockTransaction request = { 0 }; | 2413 MockTransaction request = { 0 }; |
2406 request.url = kUrl; | 2414 request.url = kUrl; |
2407 request.method = "GET"; | 2415 request.method = "GET"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 "HTTP/1.1 304 Not Modified", | 2448 "HTTP/1.1 304 Not Modified", |
2441 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2449 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2442 "Server: server2\n" | 2450 "Server: server2\n" |
2443 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2451 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2444 "" | 2452 "" |
2445 }; | 2453 }; |
2446 | 2454 |
2447 // This is two days in the future from the original response's last-modified | 2455 // This is two days in the future from the original response's last-modified |
2448 // date! | 2456 // date! |
2449 const char* kExtraRequestHeaders = | 2457 const char* kExtraRequestHeaders = |
2450 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\n"; | 2458 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; |
2451 | 2459 |
2452 ConditionalizedRequestUpdatesCacheHelper( | 2460 ConditionalizedRequestUpdatesCacheHelper( |
2453 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2461 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2454 } | 2462 } |
2455 | 2463 |
2456 // Test that when doing an externally conditionalized if-none-match | 2464 // Test that when doing an externally conditionalized if-none-match |
2457 // if the etag does not match the cache entry's etag, then we do not use the | 2465 // if the etag does not match the cache entry's etag, then we do not use the |
2458 // response (304) to update the cache. | 2466 // response (304) to update the cache. |
2459 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { | 2467 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { |
2460 static const Response kNetResponse1 = { | 2468 static const Response kNetResponse1 = { |
2461 "HTTP/1.1 200 OK", | 2469 "HTTP/1.1 200 OK", |
2462 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2470 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2463 "Etag: \"Foo1\"\n" | 2471 "Etag: \"Foo1\"\n" |
2464 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2472 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2465 "body1" | 2473 "body1" |
2466 }; | 2474 }; |
2467 | 2475 |
2468 // Second network response for |kUrl|. | 2476 // Second network response for |kUrl|. |
2469 static const Response kNetResponse2 = { | 2477 static const Response kNetResponse2 = { |
2470 "HTTP/1.1 304 Not Modified", | 2478 "HTTP/1.1 304 Not Modified", |
2471 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2479 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2472 "Etag: \"Foo2\"\n" | 2480 "Etag: \"Foo2\"\n" |
2473 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2481 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2474 "" | 2482 "" |
2475 }; | 2483 }; |
2476 | 2484 |
2477 // Different etag from original response. | 2485 // Different etag from original response. |
2478 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\n"; | 2486 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\r\n"; |
2479 | 2487 |
2480 ConditionalizedRequestUpdatesCacheHelper( | 2488 ConditionalizedRequestUpdatesCacheHelper( |
2481 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2489 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2482 } | 2490 } |
2483 | 2491 |
2484 // Test that doing an externally conditionalized request with both if-none-match | 2492 // Test that doing an externally conditionalized request with both if-none-match |
2485 // and if-modified-since updates the cache. | 2493 // and if-modified-since updates the cache. |
2486 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { | 2494 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { |
2487 static const Response kNetResponse1 = { | 2495 static const Response kNetResponse1 = { |
2488 "HTTP/1.1 200 OK", | 2496 "HTTP/1.1 200 OK", |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 static const Response kNetResponse2 = { | 2532 static const Response kNetResponse2 = { |
2525 "HTTP/1.1 200 OK", | 2533 "HTTP/1.1 200 OK", |
2526 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2534 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2527 "Etag: \"Foo2\"\n" | 2535 "Etag: \"Foo2\"\n" |
2528 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2536 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2529 "body2" | 2537 "body2" |
2530 }; | 2538 }; |
2531 | 2539 |
2532 // The etag doesn't match what we have stored. | 2540 // The etag doesn't match what we have stored. |
2533 const char* kExtraRequestHeaders = | 2541 const char* kExtraRequestHeaders = |
2534 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n" | 2542 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
2535 "If-None-Match: \"Foo2\"\n"; | 2543 "If-None-Match: \"Foo2\"\r\n"; |
2536 | 2544 |
2537 ConditionalizedRequestUpdatesCacheHelper( | 2545 ConditionalizedRequestUpdatesCacheHelper( |
2538 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2546 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2539 } | 2547 } |
2540 | 2548 |
2541 // Test that doing an externally conditionalized request with both if-none-match | 2549 // Test that doing an externally conditionalized request with both if-none-match |
2542 // and if-modified-since does not update the cache with only one match. | 2550 // and if-modified-since does not update the cache with only one match. |
2543 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { | 2551 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { |
2544 static const Response kNetResponse1 = { | 2552 static const Response kNetResponse1 = { |
2545 "HTTP/1.1 200 OK", | 2553 "HTTP/1.1 200 OK", |
2546 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2554 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2547 "Etag: \"Foo1\"\n" | 2555 "Etag: \"Foo1\"\n" |
2548 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2556 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2549 "body1" | 2557 "body1" |
2550 }; | 2558 }; |
2551 | 2559 |
2552 // Second network response for |kUrl|. | 2560 // Second network response for |kUrl|. |
2553 static const Response kNetResponse2 = { | 2561 static const Response kNetResponse2 = { |
2554 "HTTP/1.1 200 OK", | 2562 "HTTP/1.1 200 OK", |
2555 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2563 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2556 "Etag: \"Foo2\"\n" | 2564 "Etag: \"Foo2\"\n" |
2557 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2565 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2558 "body2" | 2566 "body2" |
2559 }; | 2567 }; |
2560 | 2568 |
2561 // The modification date doesn't match what we have stored. | 2569 // The modification date doesn't match what we have stored. |
2562 const char* kExtraRequestHeaders = | 2570 const char* kExtraRequestHeaders = |
2563 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\n" | 2571 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" |
2564 "If-None-Match: \"Foo1\"\n"; | 2572 "If-None-Match: \"Foo1\"\r\n"; |
2565 | 2573 |
2566 ConditionalizedRequestUpdatesCacheHelper( | 2574 ConditionalizedRequestUpdatesCacheHelper( |
2567 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2575 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2568 } | |
2569 | |
2570 // Test that doing an externally conditionalized request with two conflicting | |
2571 // headers does not update the cache. | |
2572 TEST(HttpCache, ConditionalizedRequestUpdatesCache11) { | |
2573 static const Response kNetResponse1 = { | |
2574 "HTTP/1.1 200 OK", | |
2575 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | |
2576 "Etag: \"Foo1\"\n" | |
2577 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | |
2578 "body1" | |
2579 }; | |
2580 | |
2581 // Second network response for |kUrl|. | |
2582 static const Response kNetResponse2 = { | |
2583 "HTTP/1.1 200 OK", | |
2584 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | |
2585 "Etag: \"Foo2\"\n" | |
2586 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | |
2587 "body2" | |
2588 }; | |
2589 | |
2590 // Two dates, the second matches what we have stored. | |
2591 const char* kExtraRequestHeaders = | |
2592 "If-Modified-Since: Mon, 04 Feb 2008 22:38:21 GMT\n" | |
2593 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"; | |
2594 | |
2595 ConditionalizedRequestUpdatesCacheHelper( | |
2596 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | |
2597 } | 2576 } |
2598 | 2577 |
2599 TEST(HttpCache, UrlContainingHash) { | 2578 TEST(HttpCache, UrlContainingHash) { |
2600 MockHttpCache cache; | 2579 MockHttpCache cache; |
2601 | 2580 |
2602 // Do a typical GET request -- should write an entry into our cache. | 2581 // Do a typical GET request -- should write an entry into our cache. |
2603 MockTransaction trans(kTypicalGET_Transaction); | 2582 MockTransaction trans(kTypicalGET_Transaction); |
2604 RunTransactionTest(cache.http_cache(), trans); | 2583 RunTransactionTest(cache.http_cache(), trans); |
2605 | 2584 |
2606 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 2585 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 // want to cache these, but we'll still have cases where skipping the cache | 3085 // want to cache these, but we'll still have cases where skipping the cache |
3107 // makes sense, so we want to make sure that it works properly. | 3086 // makes sense, so we want to make sure that it works properly. |
3108 | 3087 |
3109 RunTransactionTest(cache.http_cache(), kRangeGET_Transaction); | 3088 RunTransactionTest(cache.http_cache(), kRangeGET_Transaction); |
3110 | 3089 |
3111 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3090 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3112 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3091 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3113 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3092 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3114 | 3093 |
3115 MockTransaction transaction(kSimpleGET_Transaction); | 3094 MockTransaction transaction(kSimpleGET_Transaction); |
3116 transaction.request_headers = "If-None-Match: foo"; | 3095 transaction.request_headers = "If-None-Match: foo\r\n"; |
3117 RunTransactionTest(cache.http_cache(), transaction); | 3096 RunTransactionTest(cache.http_cache(), transaction); |
3118 | 3097 |
3119 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3098 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3120 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3099 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3121 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3100 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3122 | 3101 |
3123 transaction.request_headers = | 3102 transaction.request_headers = |
3124 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT"; | 3103 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n"; |
3125 RunTransactionTest(cache.http_cache(), transaction); | 3104 RunTransactionTest(cache.http_cache(), transaction); |
3126 | 3105 |
3127 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3106 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3128 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3107 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3129 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3108 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3130 } | 3109 } |
3131 | 3110 |
3132 // Test that we skip the cache for range requests that include a validation | 3111 // Test that we skip the cache for range requests that include a validation |
3133 // header. | 3112 // header. |
3134 TEST(HttpCache, RangeGET_SkipsCache2) { | 3113 TEST(HttpCache, RangeGET_SkipsCache2) { |
3135 MockHttpCache cache; | 3114 MockHttpCache cache; |
3136 | 3115 |
3137 MockTransaction transaction(kRangeGET_Transaction); | 3116 MockTransaction transaction(kRangeGET_Transaction); |
3138 transaction.request_headers = "If-None-Match: foo\r\n" | 3117 transaction.request_headers = "If-None-Match: foo\r\n" |
3139 EXTRA_HEADER | 3118 EXTRA_HEADER |
3140 "\r\nRange: bytes = 40-49"; | 3119 "Range: bytes = 40-49\r\n"; |
3141 RunTransactionTest(cache.http_cache(), transaction); | 3120 RunTransactionTest(cache.http_cache(), transaction); |
3142 | 3121 |
3143 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 3122 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
3144 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3123 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3145 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3124 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3146 | 3125 |
3147 transaction.request_headers = | 3126 transaction.request_headers = |
3148 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" | 3127 "If-Modified-Since: Wed, 28 Nov 2007 00:45:20 GMT\r\n" |
3149 EXTRA_HEADER | 3128 EXTRA_HEADER |
3150 "\r\nRange: bytes = 40-49"; | 3129 "Range: bytes = 40-49\r\n"; |
3151 RunTransactionTest(cache.http_cache(), transaction); | 3130 RunTransactionTest(cache.http_cache(), transaction); |
3152 | 3131 |
3153 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | 3132 EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
3154 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3133 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3155 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3134 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3156 | 3135 |
3157 transaction.request_headers = "If-Range: bla\r\n" | 3136 transaction.request_headers = "If-Range: bla\r\n" |
3158 EXTRA_HEADER | 3137 EXTRA_HEADER |
3159 "\r\nRange: bytes = 40-49\n"; | 3138 "Range: bytes = 40-49\r\n"; |
3160 RunTransactionTest(cache.http_cache(), transaction); | 3139 RunTransactionTest(cache.http_cache(), transaction); |
3161 | 3140 |
3162 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3141 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
3163 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3142 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
3164 EXPECT_EQ(0, cache.disk_cache()->create_count()); | 3143 EXPECT_EQ(0, cache.disk_cache()->create_count()); |
3165 } | 3144 } |
3166 | 3145 |
3167 // Tests that receiving 206 for a regular request is handled correctly. | 3146 // Tests that receiving 206 for a regular request is handled correctly. |
3168 TEST(HttpCache, GET_Crazy206) { | 3147 TEST(HttpCache, GET_Crazy206) { |
3169 MockHttpCache cache; | 3148 MockHttpCache cache; |
(...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5311 MockTransaction mock_network_response = { 0 }; | 5290 MockTransaction mock_network_response = { 0 }; |
5312 mock_network_response.url = kUrl; | 5291 mock_network_response.url = kUrl; |
5313 | 5292 |
5314 AddMockTransaction(&mock_network_response); | 5293 AddMockTransaction(&mock_network_response); |
5315 | 5294 |
5316 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. | 5295 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. |
5317 | 5296 |
5318 MockTransaction request = { 0 }; | 5297 MockTransaction request = { 0 }; |
5319 request.url = kUrl; | 5298 request.url = kUrl; |
5320 request.method = "GET"; | 5299 request.method = "GET"; |
5321 request.request_headers = ""; | 5300 request.request_headers = "\r\n"; |
5322 request.data = kData; | 5301 request.data = kData; |
5323 | 5302 |
5324 static const Response kNetResponse1 = { | 5303 static const Response kNetResponse1 = { |
5325 "HTTP/1.1 200 OK", | 5304 "HTTP/1.1 200 OK", |
5326 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 5305 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
5327 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 5306 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
5328 kData | 5307 kData |
5329 }; | 5308 }; |
5330 | 5309 |
5331 kNetResponse1.AssignTo(&mock_network_response); | 5310 kNetResponse1.AssignTo(&mock_network_response); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5624 EXPECT_TRUE(truncated); | 5603 EXPECT_TRUE(truncated); |
5625 entry->Close(); | 5604 entry->Close(); |
5626 } | 5605 } |
5627 | 5606 |
5628 // Tests that we handle truncated enries when StopCaching is called. | 5607 // Tests that we handle truncated enries when StopCaching is called. |
5629 TEST(HttpCache, StopCachingTruncatedEntry) { | 5608 TEST(HttpCache, StopCachingTruncatedEntry) { |
5630 MockHttpCache cache; | 5609 MockHttpCache cache; |
5631 net::TestCompletionCallback callback; | 5610 net::TestCompletionCallback callback; |
5632 MockHttpRequest request(kRangeGET_TransactionOK); | 5611 MockHttpRequest request(kRangeGET_TransactionOK); |
5633 request.extra_headers.Clear(); | 5612 request.extra_headers.Clear(); |
5634 request.extra_headers.AddHeaderFromString(EXTRA_HEADER); | 5613 request.extra_headers.AddHeaderFromString(EXTRA_HEADER_LINE); |
5635 AddMockTransaction(&kRangeGET_TransactionOK); | 5614 AddMockTransaction(&kRangeGET_TransactionOK); |
5636 | 5615 |
5637 std::string raw_headers("HTTP/1.1 200 OK\n" | 5616 std::string raw_headers("HTTP/1.1 200 OK\n" |
5638 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 5617 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
5639 "ETag: \"foo\"\n" | 5618 "ETag: \"foo\"\n" |
5640 "Accept-Ranges: bytes\n" | 5619 "Accept-Ranges: bytes\n" |
5641 "Content-Length: 80\n"); | 5620 "Content-Length: 80\n"); |
5642 CreateTruncatedEntry(raw_headers, &cache); | 5621 CreateTruncatedEntry(raw_headers, &cache); |
5643 | 5622 |
5644 { | 5623 { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5821 trans->SetPriority(net::HIGHEST); | 5800 trans->SetPriority(net::HIGHEST); |
5822 // Should trigger a new network transaction and pick up the new | 5801 // Should trigger a new network transaction and pick up the new |
5823 // priority. | 5802 // priority. |
5824 ReadAndVerifyTransaction(trans.get(), transaction); | 5803 ReadAndVerifyTransaction(trans.get(), transaction); |
5825 | 5804 |
5826 EXPECT_EQ(net::HIGHEST, | 5805 EXPECT_EQ(net::HIGHEST, |
5827 cache.network_layer()->last_create_transaction_priority()); | 5806 cache.network_layer()->last_create_transaction_priority()); |
5828 | 5807 |
5829 RemoveMockTransaction(&kRangeGET_TransactionOK); | 5808 RemoveMockTransaction(&kRangeGET_TransactionOK); |
5830 } | 5809 } |
OLD | NEW |