| OLD | NEW |
| 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 "content/test/net/url_request_mock_http_job.h" | 5 #include "content/test/net/url_request_mock_http_job.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_filter.h" | 17 #include "net/url_request/url_request_filter.h" |
| 16 | 18 |
| 17 const char kMockHostname[] = "mock.http"; | 19 const char kMockHostname[] = "mock.http"; |
| 18 const FilePath::CharType kMockHeaderFileSuffix[] = | 20 const FilePath::CharType kMockHeaderFileSuffix[] = |
| 19 FILE_PATH_LITERAL(".mock-http-headers"); | 21 FILE_PATH_LITERAL(".mock-http-headers"); |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // This is the file path leading to the root of the directory to use as the | 25 // This is the file path leading to the root of the directory to use as the |
| 24 // root of the http server. This returns a reference that can be assigned to. | 26 // root of the http server. This returns a reference that can be assigned to. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // path to that, and convert the final URL back to a FilePath. | 77 // path to that, and convert the final URL back to a FilePath. |
| 76 GURL file_url(net::FilePathToFileURL(base_path)); | 78 GURL file_url(net::FilePathToFileURL(base_path)); |
| 77 std::string url = file_url.spec() + request->url().path(); | 79 std::string url = file_url.spec() + request->url().path(); |
| 78 FilePath file_path; | 80 FilePath file_path; |
| 79 net::FileURLToFilePath(GURL(url), &file_path); | 81 net::FileURLToFilePath(GURL(url), &file_path); |
| 80 return file_path; | 82 return file_path; |
| 81 } | 83 } |
| 82 | 84 |
| 83 URLRequestMockHTTPJob::URLRequestMockHTTPJob(net::URLRequest* request, | 85 URLRequestMockHTTPJob::URLRequestMockHTTPJob(net::URLRequest* request, |
| 84 const FilePath& file_path) | 86 const FilePath& file_path) |
| 85 : net::URLRequestFileJob(request, file_path) { } | 87 : net::URLRequestFileJob( |
| 88 request, request->context()->network_delegate(), file_path) { } |
| 86 | 89 |
| 87 // Public virtual version. | 90 // Public virtual version. |
| 88 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { | 91 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 89 // Forward to private const version. | 92 // Forward to private const version. |
| 90 GetResponseInfoConst(info); | 93 GetResponseInfoConst(info); |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location, | 96 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location, |
| 94 int* http_status_code) { | 97 int* http_status_code) { |
| 95 // Override the net::URLRequestFileJob implementation to invoke the default | 98 // Override the net::URLRequestFileJob implementation to invoke the default |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if (info.headers) | 130 if (info.headers) |
| 128 return info.headers->response_code(); | 131 return info.headers->response_code(); |
| 129 return net::URLRequestJob::GetResponseCode(); | 132 return net::URLRequestJob::GetResponseCode(); |
| 130 } | 133 } |
| 131 | 134 |
| 132 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { | 135 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
| 133 net::HttpResponseInfo info; | 136 net::HttpResponseInfo info; |
| 134 GetResponseInfo(&info); | 137 GetResponseInfo(&info); |
| 135 return info.headers && info.headers->GetCharset(charset); | 138 return info.headers && info.headers->GetCharset(charset); |
| 136 } | 139 } |
| OLD | NEW |