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

Side by Side Diff: content/test/net/url_request_mock_http_job.cc

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
16 #include "net/url_request/url_request_filter.h" 15 #include "net/url_request/url_request_filter.h"
17 16
18 const char kMockHostname[] = "mock.http"; 17 const char kMockHostname[] = "mock.http";
19 const FilePath::CharType kMockHeaderFileSuffix[] = 18 const FilePath::CharType kMockHeaderFileSuffix[] =
20 FILE_PATH_LITERAL(".mock-http-headers"); 19 FILE_PATH_LITERAL(".mock-http-headers");
21 20
22 namespace { 21 namespace {
23 22
24 // This is the file path leading to the root of the directory to use as the 23 // This is the file path leading to the root of the directory to use as the
25 // root of the http server. This returns a reference that can be assigned to. 24 // root of the http server. This returns a reference that can be assigned to.
26 FilePath& BasePath() { 25 FilePath& BasePath() {
27 CR_DEFINE_STATIC_LOCAL(FilePath, base_path, ()); 26 CR_DEFINE_STATIC_LOCAL(FilePath, base_path, ());
28 return base_path; 27 return base_path;
29 } 28 }
30 29
31 } // namespace 30 } // namespace
32 31
33 // static 32 // static
34 net::URLRequestJob* URLRequestMockHTTPJob::Factory(net::URLRequest* request, 33 net::URLRequestJob* URLRequestMockHTTPJob::Factory(
35 const std::string& scheme) { 34 net::URLRequest* request,
35 net::NetworkDelegate* network_delegate,
36 const std::string& scheme) {
36 return new URLRequestMockHTTPJob(request, 37 return new URLRequestMockHTTPJob(request,
38 network_delegate,
37 GetOnDiskPath(BasePath(), request, scheme)); 39 GetOnDiskPath(BasePath(), request, scheme));
38 } 40 }
39 41
40 // static 42 // static
41 void URLRequestMockHTTPJob::AddUrlHandler(const FilePath& base_path) { 43 void URLRequestMockHTTPJob::AddUrlHandler(const FilePath& base_path) {
42 BasePath() = base_path; 44 BasePath() = base_path;
43 45
44 // Add kMockHostname to net::URLRequestFilter. 46 // Add kMockHostname to net::URLRequestFilter.
45 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); 47 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
46 filter->AddHostnameHandler("http", kMockHostname, 48 filter->AddHostnameHandler("http", kMockHostname,
(...skipping 27 matching lines...) Expand all
74 // But path in the request URL is in URL space (i.e. %-encoded spaces). 76 // But path in the request URL is in URL space (i.e. %-encoded spaces).
75 // So first we convert base FilePath to a URL, then append the URL 77 // So first we convert base FilePath to a URL, then append the URL
76 // path to that, and convert the final URL back to a FilePath. 78 // path to that, and convert the final URL back to a FilePath.
77 GURL file_url(net::FilePathToFileURL(base_path)); 79 GURL file_url(net::FilePathToFileURL(base_path));
78 std::string url = file_url.spec() + request->url().path(); 80 std::string url = file_url.spec() + request->url().path();
79 FilePath file_path; 81 FilePath file_path;
80 net::FileURLToFilePath(GURL(url), &file_path); 82 net::FileURLToFilePath(GURL(url), &file_path);
81 return file_path; 83 return file_path;
82 } 84 }
83 85
84 URLRequestMockHTTPJob::URLRequestMockHTTPJob(net::URLRequest* request, 86 URLRequestMockHTTPJob::URLRequestMockHTTPJob(
85 const FilePath& file_path) 87 net::URLRequest* request,
86 : net::URLRequestFileJob(request, 88 net::NetworkDelegate* network_delegate,
87 file_path, 89 const FilePath& file_path)
88 request->context()->network_delegate()) { } 90 : net::URLRequestFileJob(request, network_delegate, file_path) { }
89 91
90 // Public virtual version. 92 // Public virtual version.
91 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) { 93 void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) {
92 // Forward to private const version. 94 // Forward to private const version.
93 GetResponseInfoConst(info); 95 GetResponseInfoConst(info);
94 } 96 }
95 97
96 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location, 98 bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location,
97 int* http_status_code) { 99 int* http_status_code) {
98 // Override the net::URLRequestFileJob implementation to invoke the default 100 // Override the net::URLRequestFileJob implementation to invoke the default
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (info.headers) 132 if (info.headers)
131 return info.headers->response_code(); 133 return info.headers->response_code();
132 return net::URLRequestJob::GetResponseCode(); 134 return net::URLRequestJob::GetResponseCode();
133 } 135 }
134 136
135 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { 137 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) {
136 net::HttpResponseInfo info; 138 net::HttpResponseInfo info;
137 GetResponseInfo(&info); 139 GetResponseInfo(&info);
138 return info.headers && info.headers->GetCharset(charset); 140 return info.headers && info.headers->GetCharset(charset);
139 } 141 }
OLDNEW
« no previous file with comments | « content/test/net/url_request_mock_http_job.h ('k') | content/test/net/url_request_slow_download_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698