| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 *response_headers = "Cache-Control: no-store\n"; | 229 *response_headers = "Cache-Control: no-store\n"; |
| 230 } | 230 } |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 static bool no_store; | 233 static bool no_store; |
| 234 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); | 234 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); |
| 235 }; | 235 }; |
| 236 bool FastTransactionServer::no_store; | 236 bool FastTransactionServer::no_store; |
| 237 | 237 |
| 238 const MockTransaction kFastNoStoreGET_Transaction = { | 238 const MockTransaction kFastNoStoreGET_Transaction = { |
| 239 net::OK, |
| 239 "http://www.google.com/nostore", | 240 "http://www.google.com/nostore", |
| 240 "GET", | 241 "GET", |
| 241 base::Time(), | 242 base::Time(), |
| 242 "", | 243 "", |
| 243 net::LOAD_VALIDATE_CACHE, | 244 net::LOAD_VALIDATE_CACHE, |
| 244 "HTTP/1.1 200 OK", | 245 "HTTP/1.1 200 OK", |
| 245 "Cache-Control: max-age=10000\n", | 246 "Cache-Control: max-age=10000\n", |
| 246 base::Time(), | 247 base::Time(), |
| 247 "<html><body>Google Blah Blah</body></html>", | 248 "<html><body>Google Blah Blah</body></html>", |
| 248 TEST_MODE_SYNC_NET_START, | 249 TEST_MODE_SYNC_NET_START, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 response_headers->replace(response_headers->find("Content-Length:"), | 367 response_headers->replace(response_headers->find("Content-Length:"), |
| 367 content_length.size(), content_length); | 368 content_length.size(), content_length); |
| 368 } | 369 } |
| 369 } else { | 370 } else { |
| 370 response_status->assign("HTTP/1.1 304 Not Modified"); | 371 response_status->assign("HTTP/1.1 304 Not Modified"); |
| 371 response_data->clear(); | 372 response_data->clear(); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 const MockTransaction kRangeGET_TransactionOK = { | 376 const MockTransaction kRangeGET_TransactionOK = { |
| 377 net::OK, |
| 376 "http://www.google.com/range", | 378 "http://www.google.com/range", |
| 377 "GET", | 379 "GET", |
| 378 base::Time(), | 380 base::Time(), |
| 379 "Range: bytes = 40-49\r\n" | 381 "Range: bytes = 40-49\r\n" |
| 380 EXTRA_HEADER, | 382 EXTRA_HEADER, |
| 381 net::LOAD_NORMAL, | 383 net::LOAD_NORMAL, |
| 382 "HTTP/1.1 206 Partial Content", | 384 "HTTP/1.1 206 Partial Content", |
| 383 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" | 385 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" |
| 384 "ETag: \"foo\"\n" | 386 "ETag: \"foo\"\n" |
| 385 "Accept-Ranges: bytes\n" | 387 "Accept-Ranges: bytes\n" |
| (...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 | 1786 |
| 1785 // Junk network response. | 1787 // Junk network response. |
| 1786 static const Response kUnexpectedResponse = { | 1788 static const Response kUnexpectedResponse = { |
| 1787 "HTTP/1.1 500 Unexpected", | 1789 "HTTP/1.1 500 Unexpected", |
| 1788 "Server: unexpected_header", | 1790 "Server: unexpected_header", |
| 1789 "unexpected body" | 1791 "unexpected body" |
| 1790 }; | 1792 }; |
| 1791 | 1793 |
| 1792 // We will control the network layer's responses for |kUrl| using | 1794 // We will control the network layer's responses for |kUrl| using |
| 1793 // |mock_network_response|. | 1795 // |mock_network_response|. |
| 1794 MockTransaction mock_network_response = { 0 }; | 1796 MockTransaction mock_network_response = { net::OK, 0 }; |
| 1795 mock_network_response.url = kUrl; | 1797 mock_network_response.url = kUrl; |
| 1796 AddMockTransaction(&mock_network_response); | 1798 AddMockTransaction(&mock_network_response); |
| 1797 | 1799 |
| 1798 // Request |kUrl| for the first time. It should hit the network and | 1800 // Request |kUrl| for the first time. It should hit the network and |
| 1799 // receive |kNetResponse1|, which it saves into the HTTP cache. | 1801 // receive |kNetResponse1|, which it saves into the HTTP cache. |
| 1800 | 1802 |
| 1801 MockTransaction request = { 0 }; | 1803 MockTransaction request = { net::OK, 0 }; |
| 1802 request.url = kUrl; | 1804 request.url = kUrl; |
| 1803 request.method = "GET"; | 1805 request.method = "GET"; |
| 1804 request.request_headers = ""; | 1806 request.request_headers = ""; |
| 1805 | 1807 |
| 1806 net_response_1.AssignTo(&mock_network_response); // Network mock. | 1808 net_response_1.AssignTo(&mock_network_response); // Network mock. |
| 1807 net_response_1.AssignTo(&request); // Expected result. | 1809 net_response_1.AssignTo(&request); // Expected result. |
| 1808 | 1810 |
| 1809 std::string response_headers; | 1811 std::string response_headers; |
| 1810 RunTransactionTestWithResponse( | 1812 RunTransactionTestWithResponse( |
| 1811 cache.http_cache(), request, &response_headers); | 1813 cache.http_cache(), request, &response_headers); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 1977 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 1976 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 1978 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 1977 "" | 1979 "" |
| 1978 }; | 1980 }; |
| 1979 | 1981 |
| 1980 const char* kExtraRequestHeaders = | 1982 const char* kExtraRequestHeaders = |
| 1981 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; | 1983 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; |
| 1982 | 1984 |
| 1983 // We will control the network layer's responses for |kUrl| using | 1985 // We will control the network layer's responses for |kUrl| using |
| 1984 // |mock_network_response|. | 1986 // |mock_network_response|. |
| 1985 MockTransaction mock_network_response = { 0 }; | 1987 MockTransaction mock_network_response = { net::OK, 0 }; |
| 1986 mock_network_response.url = kUrl; | 1988 mock_network_response.url = kUrl; |
| 1987 AddMockTransaction(&mock_network_response); | 1989 AddMockTransaction(&mock_network_response); |
| 1988 | 1990 |
| 1989 MockTransaction request = { 0 }; | 1991 MockTransaction request = { net::OK, 0 }; |
| 1990 request.url = kUrl; | 1992 request.url = kUrl; |
| 1991 request.method = "GET"; | 1993 request.method = "GET"; |
| 1992 request.request_headers = kExtraRequestHeaders; | 1994 request.request_headers = kExtraRequestHeaders; |
| 1993 | 1995 |
| 1994 kNetResponse.AssignTo(&mock_network_response); // Network mock. | 1996 kNetResponse.AssignTo(&mock_network_response); // Network mock. |
| 1995 kNetResponse.AssignTo(&request); // Expected result. | 1997 kNetResponse.AssignTo(&request); // Expected result. |
| 1996 | 1998 |
| 1997 std::string response_headers; | 1999 std::string response_headers; |
| 1998 RunTransactionTestWithResponse( | 2000 RunTransactionTestWithResponse( |
| 1999 cache.http_cache(), request, &response_headers); | 2001 cache.http_cache(), request, &response_headers); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2019 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2021 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 2020 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2022 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 2021 "foobar!!!" | 2023 "foobar!!!" |
| 2022 }; | 2024 }; |
| 2023 | 2025 |
| 2024 const char* kExtraRequestHeaders = | 2026 const char* kExtraRequestHeaders = |
| 2025 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; | 2027 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; |
| 2026 | 2028 |
| 2027 // We will control the network layer's responses for |kUrl| using | 2029 // We will control the network layer's responses for |kUrl| using |
| 2028 // |mock_network_response|. | 2030 // |mock_network_response|. |
| 2029 MockTransaction mock_network_response = { 0 }; | 2031 MockTransaction mock_network_response = { net::OK, 0 }; |
| 2030 mock_network_response.url = kUrl; | 2032 mock_network_response.url = kUrl; |
| 2031 AddMockTransaction(&mock_network_response); | 2033 AddMockTransaction(&mock_network_response); |
| 2032 | 2034 |
| 2033 MockTransaction request = { 0 }; | 2035 MockTransaction request = { net::OK, 0 }; |
| 2034 request.url = kUrl; | 2036 request.url = kUrl; |
| 2035 request.method = "GET"; | 2037 request.method = "GET"; |
| 2036 request.request_headers = kExtraRequestHeaders; | 2038 request.request_headers = kExtraRequestHeaders; |
| 2037 | 2039 |
| 2038 kNetResponse.AssignTo(&mock_network_response); // Network mock. | 2040 kNetResponse.AssignTo(&mock_network_response); // Network mock. |
| 2039 kNetResponse.AssignTo(&request); // Expected result. | 2041 kNetResponse.AssignTo(&request); // Expected result. |
| 2040 | 2042 |
| 2041 std::string response_headers; | 2043 std::string response_headers; |
| 2042 RunTransactionTestWithResponse( | 2044 RunTransactionTestWithResponse( |
| 2043 cache.http_cache(), request, &response_headers); | 2045 cache.http_cache(), request, &response_headers); |
| (...skipping 2607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4651 // get updated on 304. Here we specifically check that the | 4653 // get updated on 304. Here we specifically check that the |
| 4652 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time | 4654 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time |
| 4653 // fields also gets updated. | 4655 // fields also gets updated. |
| 4654 // http://crbug.com/20594. | 4656 // http://crbug.com/20594. |
| 4655 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { | 4657 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { |
| 4656 MockHttpCache cache; | 4658 MockHttpCache cache; |
| 4657 | 4659 |
| 4658 const char* kUrl = "http://foobar"; | 4660 const char* kUrl = "http://foobar"; |
| 4659 const char* kData = "body"; | 4661 const char* kData = "body"; |
| 4660 | 4662 |
| 4661 MockTransaction mock_network_response = { 0 }; | 4663 MockTransaction mock_network_response = { net::OK, 0 }; |
| 4662 mock_network_response.url = kUrl; | 4664 mock_network_response.url = kUrl; |
| 4663 | 4665 |
| 4664 AddMockTransaction(&mock_network_response); | 4666 AddMockTransaction(&mock_network_response); |
| 4665 | 4667 |
| 4666 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. | 4668 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. |
| 4667 | 4669 |
| 4668 MockTransaction request = { 0 }; | 4670 MockTransaction request = { net::OK, 0 }; |
| 4669 request.url = kUrl; | 4671 request.url = kUrl; |
| 4670 request.method = "GET"; | 4672 request.method = "GET"; |
| 4671 request.request_headers = ""; | 4673 request.request_headers = ""; |
| 4672 request.data = kData; | 4674 request.data = kData; |
| 4673 | 4675 |
| 4674 static const Response kNetResponse1 = { | 4676 static const Response kNetResponse1 = { |
| 4675 "HTTP/1.1 200 OK", | 4677 "HTTP/1.1 200 OK", |
| 4676 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 4678 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
| 4677 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 4679 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 4678 kData | 4680 kData |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5078 | 5080 |
| 5079 // Force this transaction to read from the cache. | 5081 // Force this transaction to read from the cache. |
| 5080 MockTransaction transaction(kSimpleGET_Transaction); | 5082 MockTransaction transaction(kSimpleGET_Transaction); |
| 5081 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; | 5083 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 5082 | 5084 |
| 5083 RunTransactionTestWithDelegate(cache.http_cache(), | 5085 RunTransactionTestWithDelegate(cache.http_cache(), |
| 5084 kSimpleGET_Transaction, | 5086 kSimpleGET_Transaction, |
| 5085 5, | 5087 5, |
| 5086 0); | 5088 0); |
| 5087 } | 5089 } |
| OLD | NEW |