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