Index: net/test/url_request/url_request_mock_http_job.cc |
diff --git a/net/test/url_request/url_request_mock_http_job.cc b/net/test/url_request/url_request_mock_http_job.cc |
index c611f36530bab8e49b2ad93397fbfe1ad65fe5a4..e018ead10fa6e4ada8645a6a01784d98a44a3933 100644 |
--- a/net/test/url_request/url_request_mock_http_job.cc |
+++ b/net/test/url_request/url_request_mock_http_job.cc |
@@ -6,12 +6,15 @@ |
#include "base/files/file_util.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/task_runner_util.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "base/threading/thread_restrictions.h" |
#include "net/base/filename_util.h" |
+#include "net/base/net_errors.h" |
+#include "net/base/url_util.h" |
#include "net/http/http_response_headers.h" |
#include "net/url_request/url_request_filter.h" |
#include "net/url_request/url_request_interceptor.h" |
@@ -20,6 +23,10 @@ const char kMockHostname[] = "mock.http"; |
const base::FilePath::CharType kMockHeaderFileSuffix[] = |
FILE_PATH_LITERAL(".mock-http-headers"); |
+const char kMockErrorStepRedirect[] = "redirect"; |
+const char kMockErrorStepHeaders[] = "headers"; |
+const char kMockErrorStepData[] = "data"; |
+ |
namespace net { |
namespace { |
@@ -156,6 +163,8 @@ void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { |
bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location, |
int* http_status_code) { |
+ if (ReportMockErrorFromQuery(kMockErrorStepRedirect)) |
+ return false; |
mmenke
2014/10/16 16:39:34
Hrm...I don't think this makes any sense. For err
mef
2014/10/16 21:36:50
Done.
|
// Override the net::URLRequestFileJob implementation to invoke the default |
// one based on HttpResponseInfo. |
return net::URLRequestJob::IsRedirectResponse(location, http_status_code); |
@@ -171,15 +180,45 @@ void URLRequestMockHTTPJob::Start() { |
weak_ptr_factory_.GetWeakPtr())); |
} |
+// Public virtual version. |
+bool URLRequestMockHTTPJob::ReadRawData(IOBuffer* buf, |
+ int buf_size, |
+ int* bytes_read) { |
+ if (ReportMockErrorFromQuery(kMockErrorStepData)) |
+ return false; |
+ return URLRequestFileJob::ReadRawData(buf, buf_size, bytes_read); |
+} |
+ |
void URLRequestMockHTTPJob::GetRawHeaders(std::string raw_headers) { |
mmenke
2014/10/16 16:39:34
While you're here, think this should probably be r
mef
2014/10/16 21:36:50
Done.
|
// Handle CRLF line-endings. |
ReplaceSubstringsAfterOffset(&raw_headers, 0, "\r\n", "\n"); |
// ParseRawHeaders expects \0 to end each header line. |
ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
raw_headers_ = raw_headers; |
+ if (ReportMockErrorFromQuery(kMockErrorStepHeaders)) |
+ return; |
mmenke
2014/10/16 16:39:34
Hrm...wonder if we should set the headers or not i
mef
2014/10/16 21:36:50
Done.
|
URLRequestFileJob::Start(); |
} |
+bool URLRequestMockHTTPJob::ReportMockErrorFromQuery(const std::string& step) { |
+ std::string value; |
+ if (!GetValueForKeyInQuery(request_->url(), step, &value)) |
+ return false; |
+ |
+ int net_error; |
+ if (!base::StringToInt(value, &net_error)) |
+ return false; |
+ |
+ if (net_error == net::ERR_IO_PENDING) { |
+ DLOG(ERROR) << "Report Mock ERR_IO_PENDING for step " << step; |
+ SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
+ } else { |
+ DLOG(ERROR) << "Report Mock Error " << net_error << " for step " << step; |
+ NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, net_error)); |
+ } |
+ return true; |
+} |
+ |
// Private const version. |
void URLRequestMockHTTPJob::GetResponseInfoConst( |
net::HttpResponseInfo* info) const { |