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

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: Incorporated comments. 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
« no previous file with comments | « net/http/http_transaction_unittest.h ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 231
227 MockNetworkTransaction::~MockNetworkTransaction() {} 232 MockNetworkTransaction::~MockNetworkTransaction() {}
228 233
229 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request, 234 int MockNetworkTransaction::Start(const net::HttpRequestInfo* request,
230 const net::CompletionCallback& callback, 235 const net::CompletionCallback& callback,
231 const net::BoundNetLog& net_log) { 236 const net::BoundNetLog& net_log) {
232 const MockTransaction* t = FindMockTransaction(request->url); 237 const MockTransaction* t = FindMockTransaction(request->url);
233 if (!t) 238 if (!t)
234 return net::ERR_FAILED; 239 return net::ERR_FAILED;
235 240
241 // Return immediately if we're returning in error.
242 if (net::OK != t->return_code) {
243 if (test_mode_ & TEST_MODE_SYNC_NET_START)
244 return t->return_code;
245 CallbackLater(callback, t->return_code);
246 return net::ERR_IO_PENDING;
247 }
248
236 std::string resp_status = t->status; 249 std::string resp_status = t->status;
237 std::string resp_headers = t->response_headers; 250 std::string resp_headers = t->response_headers;
238 std::string resp_data = t->data; 251 std::string resp_data = t->data;
239 if (t->handler) 252 if (t->handler)
240 (t->handler)(request, &resp_status, &resp_headers, &resp_data); 253 (t->handler)(request, &resp_status, &resp_headers, &resp_data);
241 254
242 std::string header_data = base::StringPrintf( 255 std::string header_data = base::StringPrintf(
243 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); 256 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str());
244 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); 257 std::replace(header_data.begin(), header_data.end(), '\n', '\0');
245 258
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 396
384 if (rv > 0) 397 if (rv > 0)
385 content.append(buf->data(), rv); 398 content.append(buf->data(), rv);
386 else if (rv < 0) 399 else if (rv < 0)
387 return rv; 400 return rv;
388 } while (rv > 0); 401 } while (rv > 0);
389 402
390 result->swap(content); 403 result->swap(content);
391 return net::OK; 404 return net::OK;
392 } 405 }
OLDNEW
« no previous file with comments | « net/http/http_transaction_unittest.h ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698