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

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

Issue 12310075: Cache failover to LOAD_PREFERRING_CACHE if network response suggests offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed vestigial reference to new content flag. Created 7 years, 9 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_transaction_unittest.h" 5 #include "net/http/http_transaction_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 20 matching lines...) Expand all
31 "GET", 31 "GET",
32 base::Time(), 32 base::Time(),
33 "", 33 "",
34 net::LOAD_NORMAL, 34 net::LOAD_NORMAL,
35 "HTTP/1.1 200 OK", 35 "HTTP/1.1 200 OK",
36 "Cache-Control: max-age=10000\n", 36 "Cache-Control: max-age=10000\n",
37 base::Time(), 37 base::Time(),
38 "<html><body>Google Blah Blah</body></html>", 38 "<html><body>Google Blah Blah</body></html>",
39 TEST_MODE_NORMAL, 39 TEST_MODE_NORMAL,
40 NULL, 40 NULL,
41 0 41 0,
42 net::OK
42 }; 43 };
43 44
44 const MockTransaction kSimplePOST_Transaction = { 45 const MockTransaction kSimplePOST_Transaction = {
45 "http://bugdatabase.com/edit", 46 "http://bugdatabase.com/edit",
46 "POST", 47 "POST",
47 base::Time(), 48 base::Time(),
48 "", 49 "",
49 net::LOAD_NORMAL, 50 net::LOAD_NORMAL,
50 "HTTP/1.1 200 OK", 51 "HTTP/1.1 200 OK",
51 "", 52 "",
52 base::Time(), 53 base::Time(),
53 "<html><body>Google Blah Blah</body></html>", 54 "<html><body>Google Blah Blah</body></html>",
54 TEST_MODE_NORMAL, 55 TEST_MODE_NORMAL,
55 NULL, 56 NULL,
56 0 57 0,
58 net::OK
57 }; 59 };
58 60
59 const MockTransaction kTypicalGET_Transaction = { 61 const MockTransaction kTypicalGET_Transaction = {
60 "http://www.example.com/~foo/bar.html", 62 "http://www.example.com/~foo/bar.html",
61 "GET", 63 "GET",
62 base::Time(), 64 base::Time(),
63 "", 65 "",
64 net::LOAD_NORMAL, 66 net::LOAD_NORMAL,
65 "HTTP/1.1 200 OK", 67 "HTTP/1.1 200 OK",
66 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n" 68 "Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
67 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n", 69 "Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n",
68 base::Time(), 70 base::Time(),
69 "<html><body>Google Blah Blah</body></html>", 71 "<html><body>Google Blah Blah</body></html>",
70 TEST_MODE_NORMAL, 72 TEST_MODE_NORMAL,
71 NULL, 73 NULL,
72 0 74 0,
75 net::OK
73 }; 76 };
74 77
75 const MockTransaction kETagGET_Transaction = { 78 const MockTransaction kETagGET_Transaction = {
76 "http://www.google.com/foopy", 79 "http://www.google.com/foopy",
77 "GET", 80 "GET",
78 base::Time(), 81 base::Time(),
79 "", 82 "",
80 net::LOAD_NORMAL, 83 net::LOAD_NORMAL,
81 "HTTP/1.1 200 OK", 84 "HTTP/1.1 200 OK",
82 "Cache-Control: max-age=10000\n" 85 "Cache-Control: max-age=10000\n"
83 "Etag: \"foopy\"\n", 86 "Etag: \"foopy\"\n",
84 base::Time(), 87 base::Time(),
85 "<html><body>Google Blah Blah</body></html>", 88 "<html><body>Google Blah Blah</body></html>",
86 TEST_MODE_NORMAL, 89 TEST_MODE_NORMAL,
87 NULL, 90 NULL,
88 0 91 0,
92 net::OK
89 }; 93 };
90 94
91 const MockTransaction kRangeGET_Transaction = { 95 const MockTransaction kRangeGET_Transaction = {
92 "http://www.google.com/", 96 "http://www.google.com/",
93 "GET", 97 "GET",
94 base::Time(), 98 base::Time(),
95 "Range: 0-100\r\n", 99 "Range: 0-100\r\n",
96 net::LOAD_NORMAL, 100 net::LOAD_NORMAL,
97 "HTTP/1.1 200 OK", 101 "HTTP/1.1 200 OK",
98 "Cache-Control: max-age=10000\n", 102 "Cache-Control: max-age=10000\n",
99 base::Time(), 103 base::Time(),
100 "<html><body>Google Blah Blah</body></html>", 104 "<html><body>Google Blah Blah</body></html>",
101 TEST_MODE_NORMAL, 105 TEST_MODE_NORMAL,
102 NULL, 106 NULL,
103 0 107 0,
108 net::OK
104 }; 109 };
105 110
106 static const MockTransaction* const kBuiltinMockTransactions[] = { 111 static const MockTransaction* const kBuiltinMockTransactions[] = {
107 &kSimpleGET_Transaction, 112 &kSimpleGET_Transaction,
108 &kSimplePOST_Transaction, 113 &kSimplePOST_Transaction,
109 &kTypicalGET_Transaction, 114 &kTypicalGET_Transaction,
110 &kETagGET_Transaction, 115 &kETagGET_Transaction,
111 &kRangeGET_Transaction 116 &kRangeGET_Transaction
112 }; 117 };
113 118
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 227 }
223 228
224 MockNetworkTransaction::~MockNetworkTransaction() {} 229 MockNetworkTransaction::~MockNetworkTransaction() {}
225 230
226 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request, 231 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request,
227 const net::CompletionCallback& callback, 232 const net::CompletionCallback& callback,
228 const net::BoundNetLog& net_log) { 233 const net::BoundNetLog& net_log) {
229 const MockTransaction* t = FindMockTransaction(request->url); 234 const MockTransaction* t = FindMockTransaction(request->url);
230 if (!t) 235 if (!t)
231 return net::ERR_FAILED; 236 return net::ERR_FAILED;
232 237
rvargas (doing something else) 2013/03/05 02:58:19 Should'n we be returning here if the transaction s
Randy Smith (Not in Mondays) 2013/03/05 23:16:14 Good point. Done.
233 std::string resp_status = t->status; 238 std::string resp_status = t->status;
234 std::string resp_headers = t->response_headers; 239 std::string resp_headers = t->response_headers;
235 std::string resp_data = t->data; 240 std::string resp_data = t->data;
236 if (t->handler) 241 if (t->handler)
237 (t->handler)(request, &resp_status, &resp_headers, &resp_data); 242 (t->handler)(request, &resp_status, &resp_headers, &resp_data);
238 243
239 std::string header_data = base::StringPrintf( 244 std::string header_data = base::StringPrintf(
240 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); 245 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str());
241 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); 246 std::replace(header_data.begin(), header_data.end(), '\n', '\0');
242 247
243 response_.request_time = base::Time::Now(); 248 response_.request_time = base::Time::Now();
244 if (!t->request_time.is_null()) 249 if (!t->request_time.is_null())
245 response_.request_time = t->request_time; 250 response_.request_time = t->request_time;
246 251
247 response_.was_cached = false; 252 response_.was_cached = false;
248 253
249 response_.response_time = base::Time::Now(); 254 response_.response_time = base::Time::Now();
250 if (!t->response_time.is_null()) 255 if (!t->response_time.is_null())
251 response_.response_time = t->response_time; 256 response_.response_time = t->response_time;
252 257
253 response_.headers = new net::HttpResponseHeaders(header_data); 258 response_.headers = new net::HttpResponseHeaders(header_data);
254 response_.vary_data.Init(*request, *response_.headers); 259 response_.vary_data.Init(*request, *response_.headers);
255 response_.ssl_info.cert_status = t->cert_status; 260 response_.ssl_info.cert_status = t->cert_status;
256 data_ = resp_data; 261 data_ = resp_data;
257 test_mode_ = t->test_mode; 262 test_mode_ = t->test_mode;
258 263
259 if (test_mode_ & TEST_MODE_SYNC_NET_START) 264 if (test_mode_ & TEST_MODE_SYNC_NET_START)
260 return net::OK; 265 return t->error_return;
261 266
262 CallbackLater(callback, net::OK); 267 CallbackLater(callback, t->error_return);
263 return net::ERR_IO_PENDING; 268 return net::ERR_IO_PENDING;
264 } 269 }
265 270
266 int MockNetworkTransaction::RestartIgnoringLastError( 271 int MockNetworkTransaction::RestartIgnoringLastError(
267 const net::CompletionCallback& callback) { 272 const net::CompletionCallback& callback) {
268 return net::ERR_FAILED; 273 return net::ERR_FAILED;
269 } 274 }
270 275
271 int MockNetworkTransaction::RestartWithCertificate( 276 int MockNetworkTransaction::RestartWithCertificate(
272 net::X509Certificate* client_cert, 277 net::X509Certificate* client_cert,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 384
380 if (rv > 0) 385 if (rv > 0)
381 content.append(buf->data(), rv); 386 content.append(buf->data(), rv);
382 else if (rv < 0) 387 else if (rv < 0)
383 return rv; 388 return rv;
384 } while (rv > 0); 389 } while (rv > 0);
385 390
386 result->swap(content); 391 result->swap(content);
387 return net::OK; 392 return net::OK;
388 } 393 }
OLDNEW
« net/http/http_transaction_unittest.h ('K') | « net/http/http_transaction_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698