Chromium Code Reviews| 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 1b2960bb250e12fff7d9f10cc8fd4705b0bc6606..ecbdd33e6481b9d9f58d3fdb6bd9e3e23f0c6952 100644 |
| --- a/net/http/http_transaction_test_util.cc |
| +++ b/net/http/http_transaction_test_util.cc |
| @@ -49,7 +49,6 @@ const MockTransaction kSimpleGET_Transaction = { |
| nullptr, |
| nullptr, |
| 0, |
| - 0, |
|
rvargas (doing something else)
2015/09/15 01:07:39
Why are you removing stuff (xx_satus) instead of a
asanka
2015/09/17 22:20:29
Wow. Done.
|
| OK}; |
| const MockTransaction kSimplePOST_Transaction = { |
| @@ -66,7 +65,6 @@ const MockTransaction kSimplePOST_Transaction = { |
| nullptr, |
| nullptr, |
| 0, |
| - 0, |
| OK}; |
| const MockTransaction kTypicalGET_Transaction = { |
| @@ -84,7 +82,6 @@ const MockTransaction kTypicalGET_Transaction = { |
| nullptr, |
| nullptr, |
| 0, |
| - 0, |
| OK}; |
| const MockTransaction kETagGET_Transaction = { |
| @@ -102,7 +99,6 @@ const MockTransaction kETagGET_Transaction = { |
| nullptr, |
| nullptr, |
| 0, |
| - 0, |
| OK}; |
| const MockTransaction kRangeGET_Transaction = { |
| @@ -119,7 +115,6 @@ const MockTransaction kRangeGET_Transaction = { |
| nullptr, |
| nullptr, |
| 0, |
| - 0, |
| OK}; |
| static const MockTransaction* const kBuiltinMockTransactions[] = { |
| @@ -141,7 +136,7 @@ const MockTransaction* FindMockTransaction(const GURL& url) { |
| if (url == GURL(kBuiltinMockTransactions[i]->url)) |
| return kBuiltinMockTransactions[i]; |
| } |
| - return NULL; |
| + return nullptr; |
| } |
| void AddMockTransaction(const MockTransaction* trans) { |
| @@ -236,15 +231,16 @@ void TestTransactionConsumer::OnIOComplete(int result) { |
| MockNetworkTransaction::MockNetworkTransaction(RequestPriority priority, |
| MockNetworkLayer* factory) |
| - : request_(NULL), |
| + : request_(nullptr), |
| data_cursor_(0), |
| + content_length_(0), |
| priority_(priority), |
| - websocket_handshake_stream_create_helper_(NULL), |
| + read_handler_(nullptr), |
| + websocket_handshake_stream_create_helper_(nullptr), |
| transaction_factory_(factory->AsWeakPtr()), |
| received_bytes_(0), |
| socket_log_id_(NetLog::Source::kInvalidId), |
| - weak_factory_(this) { |
| -} |
| + weak_factory_(this) {} |
|
rvargas (doing something else)
2015/09/15 01:07:39
<rant>I hate cl format</rant>
asanka
2015/09/17 22:20:29
:)
|
| MockNetworkTransaction::~MockNetworkTransaction() {} |
| @@ -297,16 +293,22 @@ bool MockNetworkTransaction::IsReadyToRestartForAuth() { |
| status_line.find(" 407 ") != std::string::npos; |
| } |
| -int MockNetworkTransaction::Read(IOBuffer* buf, |
| +int MockNetworkTransaction::Read(net::IOBuffer* buf, |
| int buf_len, |
| const CompletionCallback& callback) { |
| - int data_len = static_cast<int>(data_.size()); |
| - int num = std::min(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 = 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>(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; |
| @@ -390,6 +392,13 @@ int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, |
| if (!t) |
| return ERR_FAILED; |
| + if (!before_network_start_callback_.is_null()) { |
| + bool defer = false; |
| + before_network_start_callback_.Run(&defer); |
| + if (defer) |
| + return net::ERR_IO_PENDING; |
| + } |
| + |
| test_mode_ = t->test_mode; |
| // Return immediately if we're returning an error. |
| @@ -406,6 +415,8 @@ int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, |
| received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size(); |
| if (t->handler) |
| (t->handler)(request, &resp_status, &resp_headers, &resp_data); |
| + if (t->read_handler) |
| + read_handler_ = t->read_handler; |
| std::string header_data = base::StringPrintf( |
| "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); |
| @@ -428,6 +439,7 @@ int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, |
| response_.ssl_info.cert_status = t->cert_status; |
| response_.ssl_info.connection_status = t->ssl_connection_status; |
| data_ = resp_data; |
| + content_length_ = response_.headers->GetContentLength(); |
| if (net_log.net_log()) |
| socket_log_id_ = net_log.net_log()->NextID(); |
| @@ -444,6 +456,7 @@ int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, |
| void MockNetworkTransaction::SetBeforeNetworkStartCallback( |
| const BeforeNetworkStartCallback& callback) { |
| + before_network_start_callback_ = callback; |
| } |
| void MockNetworkTransaction::SetBeforeProxyHeadersSentCallback( |
| @@ -490,6 +503,10 @@ void MockNetworkLayer::TransactionStopCaching() { |
| stop_caching_called_ = true; |
| } |
| +void MockNetworkLayer::ResetTransactionCount() { |
| + transaction_count_ = 0; |
| +} |
| + |
| int MockNetworkLayer::CreateTransaction(RequestPriority priority, |
| scoped_ptr<HttpTransaction>* trans) { |
| transaction_count_++; |