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

Unified Diff: net/http/http_transaction_test_util.cc

Issue 2886483002: Adds a new class HttpCache::Writers for multiple cache transactions reading from the network. (Closed)
Patch Set: Comment changed. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_transaction_test_util.h ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_transaction_test_util.cc
diff --git a/net/http/http_transaction_test_util.cc b/net/http/http_transaction_test_util.cc
index cb46c907ab1793c5825a0bf465ff99e36920147b..19f27977ec0e6f96b3dd2a5dac5f256f89c2c3e2 100644
--- a/net/http/http_transaction_test_util.cc
+++ b/net/http/http_transaction_test_util.cc
@@ -58,6 +58,7 @@ const MockTransaction kSimpleGET_Transaction = {
nullptr,
0,
0,
+ OK,
OK};
const MockTransaction kSimplePOST_Transaction = {
@@ -76,23 +77,48 @@ const MockTransaction kSimplePOST_Transaction = {
nullptr,
0,
0,
+ OK,
OK};
const MockTransaction kTypicalGET_Transaction = {
- "http://www.example.com/~foo/bar.html", "GET", base::Time(), "",
- LOAD_NORMAL, "HTTP/1.1 200 OK",
+ "http://www.example.com/~foo/bar.html",
+ "GET",
+ base::Time(),
+ "",
+ LOAD_NORMAL,
+ "HTTP/1.1 200 OK",
"Date: Wed, 28 Nov 2007 09:40:09 GMT\n"
"Last-Modified: Wed, 28 Nov 2007 00:40:09 GMT\n",
- base::Time(), "<html><body>Google Blah Blah</body></html>",
- TEST_MODE_NORMAL, nullptr, nullptr, nullptr, 0, 0, OK};
+ base::Time(),
+ "<html><body>Google Blah Blah</body></html>",
+ TEST_MODE_NORMAL,
+ nullptr,
+ nullptr,
+ nullptr,
+ 0,
+ 0,
+ OK,
+ OK};
const MockTransaction kETagGET_Transaction = {
- "http://www.google.com/foopy", "GET", base::Time(), "", LOAD_NORMAL,
+ "http://www.google.com/foopy",
+ "GET",
+ base::Time(),
+ "",
+ LOAD_NORMAL,
"HTTP/1.1 200 OK",
"Cache-Control: max-age=10000\n"
"Etag: \"foopy\"\n",
- base::Time(), "<html><body>Google Blah Blah</body></html>",
- TEST_MODE_NORMAL, nullptr, nullptr, nullptr, 0, 0, OK};
+ base::Time(),
+ "<html><body>Google Blah Blah</body></html>",
+ TEST_MODE_NORMAL,
+ nullptr,
+ nullptr,
+ nullptr,
+ 0,
+ 0,
+ OK,
+ OK};
const MockTransaction kRangeGET_Transaction = {
"http://www.google.com/",
@@ -110,6 +136,7 @@ const MockTransaction kRangeGET_Transaction = {
nullptr,
0,
0,
+ OK,
OK};
static const MockTransaction* const kBuiltinMockTransactions[] = {
@@ -304,21 +331,29 @@ bool MockNetworkTransaction::IsReadyToRestartForAuth() {
int MockNetworkTransaction::Read(net::IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) {
+ const MockTransaction* t = FindMockTransaction(request_->url);
+ DCHECK(t);
+
CHECK(!done_reading_called_);
- int num = 0;
- if (read_handler_) {
- num = (*read_handler_)(content_length_, data_cursor_, buf, buf_len);
- data_cursor_ += num;
- } else {
- int data_len = static_cast<int>(data_.size());
- num = std::min(static_cast<int64_t>(buf_len), data_len - data_cursor_);
- if (test_mode_ & TEST_MODE_SLOW_READ)
- num = std::min(num, 1);
- if (num) {
- memcpy(buf->data(), data_.data() + data_cursor_, num);
+
+ int num = t->read_return_code;
+
+ if (OK == num) {
+ if (read_handler_) {
+ num = (*read_handler_)(content_length_, data_cursor_, buf, buf_len);
data_cursor_ += num;
+ } else {
+ int data_len = static_cast<int>(data_.size());
+ num = std::min(static_cast<int64_t>(buf_len), data_len - data_cursor_);
+ if (test_mode_ & TEST_MODE_SLOW_READ)
+ num = std::min(num, 1);
+ if (num) {
+ memcpy(buf->data(), data_.data() + data_cursor_, num);
+ data_cursor_ += num;
+ }
}
}
+
if (test_mode_ & TEST_MODE_SYNC_NET_READ)
return num;
@@ -417,10 +452,10 @@ int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request,
test_mode_ = t->test_mode;
// Return immediately if we're returning an error.
- if (OK != t->return_code) {
+ if (OK != t->start_return_code) {
if (test_mode_ & TEST_MODE_SYNC_NET_START)
- return t->return_code;
- CallbackLater(callback, t->return_code);
+ return t->start_return_code;
+ CallbackLater(callback, t->start_return_code);
return ERR_IO_PENDING;
}
« no previous file with comments | « net/http/http_transaction_test_util.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