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_context.h" |
15 #include "net/url_request/url_request_filter.h" | 16 #include "net/url_request/url_request_filter.h" |
16 | 17 |
17 const char kMockHostname[] = "mock.http"; | 18 const char kMockHostname[] = "mock.http"; |
18 const FilePath::CharType kMockHeaderFileSuffix[] = | 19 const FilePath::CharType kMockHeaderFileSuffix[] = |
19 FILE_PATH_LITERAL(".mock-http-headers"); | 20 FILE_PATH_LITERAL(".mock-http-headers"); |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // This is the file path leading to the root of the directory to use as the | 24 // 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. | 25 // 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. | 76 // path to that, and convert the final URL back to a FilePath. |
76 GURL file_url(net::FilePathToFileURL(base_path)); | 77 GURL file_url(net::FilePathToFileURL(base_path)); |
77 std::string url = file_url.spec() + request->url().path(); | 78 std::string url = file_url.spec() + request->url().path(); |
78 FilePath file_path; | 79 FilePath file_path; |
79 net::FileURLToFilePath(GURL(url), &file_path); | 80 net::FileURLToFilePath(GURL(url), &file_path); |
80 return file_path; | 81 return file_path; |
81 } | 82 } |
82 | 83 |
83 URLRequestMockHTTPJob::URLRequestMockHTTPJob(net::URLRequest* request, | 84 URLRequestMockHTTPJob::URLRequestMockHTTPJob(net::URLRequest* request, |
84 const FilePath& file_path) | 85 const FilePath& file_path) |
85 : net::URLRequestFileJob(request, file_path) { } | 86 : net::URLRequestFileJob(request, |
| 87 file_path, |
| 88 request->context()->network_delegate()) { } |
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 |