Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 10854204: Automatically retry failed network requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add back rest of no longer so mysteriously missing line Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 *response_headers = "Cache-Control: no-store\n"; 196 *response_headers = "Cache-Control: no-store\n";
197 } 197 }
198 198
199 private: 199 private:
200 static bool no_store; 200 static bool no_store;
201 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer); 201 DISALLOW_COPY_AND_ASSIGN(FastTransactionServer);
202 }; 202 };
203 bool FastTransactionServer::no_store; 203 bool FastTransactionServer::no_store;
204 204
205 const MockTransaction kFastNoStoreGET_Transaction = { 205 const MockTransaction kFastNoStoreGET_Transaction = {
206 net::OK,
206 "http://www.google.com/nostore", 207 "http://www.google.com/nostore",
207 "GET", 208 "GET",
208 base::Time(), 209 base::Time(),
209 "", 210 "",
210 net::LOAD_VALIDATE_CACHE, 211 net::LOAD_VALIDATE_CACHE,
211 "HTTP/1.1 200 OK", 212 "HTTP/1.1 200 OK",
212 "Cache-Control: max-age=10000\n", 213 "Cache-Control: max-age=10000\n",
213 base::Time(), 214 base::Time(),
214 "<html><body>Google Blah Blah</body></html>", 215 "<html><body>Google Blah Blah</body></html>",
215 TEST_MODE_SYNC_NET_START, 216 TEST_MODE_SYNC_NET_START,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 response_headers->replace(response_headers->find("Content-Length:"), 334 response_headers->replace(response_headers->find("Content-Length:"),
334 content_length.size(), content_length); 335 content_length.size(), content_length);
335 } 336 }
336 } else { 337 } else {
337 response_status->assign("HTTP/1.1 304 Not Modified"); 338 response_status->assign("HTTP/1.1 304 Not Modified");
338 response_data->clear(); 339 response_data->clear();
339 } 340 }
340 } 341 }
341 342
342 const MockTransaction kRangeGET_TransactionOK = { 343 const MockTransaction kRangeGET_TransactionOK = {
344 net::OK,
343 "http://www.google.com/range", 345 "http://www.google.com/range",
344 "GET", 346 "GET",
345 base::Time(), 347 base::Time(),
346 "Range: bytes = 40-49\r\n" 348 "Range: bytes = 40-49\r\n"
347 EXTRA_HEADER, 349 EXTRA_HEADER,
348 net::LOAD_NORMAL, 350 net::LOAD_NORMAL,
349 "HTTP/1.1 206 Partial Content", 351 "HTTP/1.1 206 Partial Content",
350 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 352 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
351 "ETag: \"foo\"\n" 353 "ETag: \"foo\"\n"
352 "Accept-Ranges: bytes\n" 354 "Accept-Ranges: bytes\n"
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 1753
1752 // Junk network response. 1754 // Junk network response.
1753 static const Response kUnexpectedResponse = { 1755 static const Response kUnexpectedResponse = {
1754 "HTTP/1.1 500 Unexpected", 1756 "HTTP/1.1 500 Unexpected",
1755 "Server: unexpected_header", 1757 "Server: unexpected_header",
1756 "unexpected body" 1758 "unexpected body"
1757 }; 1759 };
1758 1760
1759 // We will control the network layer's responses for |kUrl| using 1761 // We will control the network layer's responses for |kUrl| using
1760 // |mock_network_response|. 1762 // |mock_network_response|.
1761 MockTransaction mock_network_response = { 0 }; 1763 MockTransaction mock_network_response = { net::OK, 0 };
1762 mock_network_response.url = kUrl; 1764 mock_network_response.url = kUrl;
1763 AddMockTransaction(&mock_network_response); 1765 AddMockTransaction(&mock_network_response);
1764 1766
1765 // Request |kUrl| for the first time. It should hit the network and 1767 // Request |kUrl| for the first time. It should hit the network and
1766 // receive |kNetResponse1|, which it saves into the HTTP cache. 1768 // receive |kNetResponse1|, which it saves into the HTTP cache.
1767 1769
1768 MockTransaction request = { 0 }; 1770 MockTransaction request = { net::OK, 0 };
1769 request.url = kUrl; 1771 request.url = kUrl;
1770 request.method = "GET"; 1772 request.method = "GET";
1771 request.request_headers = ""; 1773 request.request_headers = "";
1772 1774
1773 net_response_1.AssignTo(&mock_network_response); // Network mock. 1775 net_response_1.AssignTo(&mock_network_response); // Network mock.
1774 net_response_1.AssignTo(&request); // Expected result. 1776 net_response_1.AssignTo(&request); // Expected result.
1775 1777
1776 std::string response_headers; 1778 std::string response_headers;
1777 RunTransactionTestWithResponse( 1779 RunTransactionTestWithResponse(
1778 cache.http_cache(), request, &response_headers); 1780 cache.http_cache(), request, &response_headers);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 1944 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1943 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 1945 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1944 "" 1946 ""
1945 }; 1947 };
1946 1948
1947 const char* kExtraRequestHeaders = 1949 const char* kExtraRequestHeaders =
1948 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; 1950 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT";
1949 1951
1950 // We will control the network layer's responses for |kUrl| using 1952 // We will control the network layer's responses for |kUrl| using
1951 // |mock_network_response|. 1953 // |mock_network_response|.
1952 MockTransaction mock_network_response = { 0 }; 1954 MockTransaction mock_network_response = { net::OK, 0 };
1953 mock_network_response.url = kUrl; 1955 mock_network_response.url = kUrl;
1954 AddMockTransaction(&mock_network_response); 1956 AddMockTransaction(&mock_network_response);
1955 1957
1956 MockTransaction request = { 0 }; 1958 MockTransaction request = { net::OK, 0 };
1957 request.url = kUrl; 1959 request.url = kUrl;
1958 request.method = "GET"; 1960 request.method = "GET";
1959 request.request_headers = kExtraRequestHeaders; 1961 request.request_headers = kExtraRequestHeaders;
1960 1962
1961 kNetResponse.AssignTo(&mock_network_response); // Network mock. 1963 kNetResponse.AssignTo(&mock_network_response); // Network mock.
1962 kNetResponse.AssignTo(&request); // Expected result. 1964 kNetResponse.AssignTo(&request); // Expected result.
1963 1965
1964 std::string response_headers; 1966 std::string response_headers;
1965 RunTransactionTestWithResponse( 1967 RunTransactionTestWithResponse(
1966 cache.http_cache(), request, &response_headers); 1968 cache.http_cache(), request, &response_headers);
(...skipping 19 matching lines...) Expand all
1986 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 1988 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1987 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 1989 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1988 "foobar!!!" 1990 "foobar!!!"
1989 }; 1991 };
1990 1992
1991 const char* kExtraRequestHeaders = 1993 const char* kExtraRequestHeaders =
1992 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT"; 1994 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT";
1993 1995
1994 // We will control the network layer's responses for |kUrl| using 1996 // We will control the network layer's responses for |kUrl| using
1995 // |mock_network_response|. 1997 // |mock_network_response|.
1996 MockTransaction mock_network_response = { 0 }; 1998 MockTransaction mock_network_response = { net::OK, 0 };
1997 mock_network_response.url = kUrl; 1999 mock_network_response.url = kUrl;
1998 AddMockTransaction(&mock_network_response); 2000 AddMockTransaction(&mock_network_response);
1999 2001
2000 MockTransaction request = { 0 }; 2002 MockTransaction request = { net::OK, 0 };
2001 request.url = kUrl; 2003 request.url = kUrl;
2002 request.method = "GET"; 2004 request.method = "GET";
2003 request.request_headers = kExtraRequestHeaders; 2005 request.request_headers = kExtraRequestHeaders;
2004 2006
2005 kNetResponse.AssignTo(&mock_network_response); // Network mock. 2007 kNetResponse.AssignTo(&mock_network_response); // Network mock.
2006 kNetResponse.AssignTo(&request); // Expected result. 2008 kNetResponse.AssignTo(&request); // Expected result.
2007 2009
2008 std::string response_headers; 2010 std::string response_headers;
2009 RunTransactionTestWithResponse( 2011 RunTransactionTestWithResponse(
2010 cache.http_cache(), request, &response_headers); 2012 cache.http_cache(), request, &response_headers);
(...skipping 2590 matching lines...) Expand 10 before | Expand all | Expand 10 after
4601 // get updated on 304. Here we specifically check that the 4603 // get updated on 304. Here we specifically check that the
4602 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time 4604 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time
4603 // fields also gets updated. 4605 // fields also gets updated.
4604 // http://crbug.com/20594. 4606 // http://crbug.com/20594.
4605 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { 4607 TEST(HttpCache, UpdatesRequestResponseTimeOn304) {
4606 MockHttpCache cache; 4608 MockHttpCache cache;
4607 4609
4608 const char* kUrl = "http://foobar"; 4610 const char* kUrl = "http://foobar";
4609 const char* kData = "body"; 4611 const char* kData = "body";
4610 4612
4611 MockTransaction mock_network_response = { 0 }; 4613 MockTransaction mock_network_response = { net::OK, 0 };
4612 mock_network_response.url = kUrl; 4614 mock_network_response.url = kUrl;
4613 4615
4614 AddMockTransaction(&mock_network_response); 4616 AddMockTransaction(&mock_network_response);
4615 4617
4616 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. 4618 // Request |kUrl|, causing |kNetResponse1| to be written to the cache.
4617 4619
4618 MockTransaction request = { 0 }; 4620 MockTransaction request = { net::OK, 0 };
4619 request.url = kUrl; 4621 request.url = kUrl;
4620 request.method = "GET"; 4622 request.method = "GET";
4621 request.request_headers = ""; 4623 request.request_headers = "";
4622 request.data = kData; 4624 request.data = kData;
4623 4625
4624 static const Response kNetResponse1 = { 4626 static const Response kNetResponse1 = {
4625 "HTTP/1.1 200 OK", 4627 "HTTP/1.1 200 OK",
4626 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" 4628 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n"
4627 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 4629 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
4628 kData 4630 kData
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
5026 8); 5028 8);
5027 5029
5028 // Force this transaction to read from the cache. 5030 // Force this transaction to read from the cache.
5029 MockTransaction transaction(kSimpleGET_Transaction); 5031 MockTransaction transaction(kSimpleGET_Transaction);
5030 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE; 5032 transaction.load_flags |= net::LOAD_ONLY_FROM_CACHE;
5031 5033
5032 RunTransactionTestWithDelegate(cache.http_cache(), 5034 RunTransactionTestWithDelegate(cache.http_cache(),
5033 kSimpleGET_Transaction, 5035 kSimpleGET_Transaction,
5034 5); 5036 5);
5035 } 5037 }
OLDNEW
« no previous file with comments | « no previous file | net/http/http_transaction_unittest.h » ('j') | net/url_request/url_request_http_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698