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

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

Issue 686343002: Add MaybeInterceptRedirect/Response to URLRequestInterceptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests, removed DRP Created 6 years, 1 month 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
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 "net/test/url_request/url_request_mock_http_job.h" 5 #include "net/test/url_request/url_request_mock_http_job.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 21 matching lines...) Expand all
32 // to use as the root of the HTTP server. 32 // to use as the root of the HTTP server.
33 MockJobInterceptor( 33 MockJobInterceptor(
34 const base::FilePath& base_path, 34 const base::FilePath& base_path,
35 bool map_all_requests_to_base_path, 35 bool map_all_requests_to_base_path,
36 const scoped_refptr<base::SequencedWorkerPool>& worker_pool) 36 const scoped_refptr<base::SequencedWorkerPool>& worker_pool)
37 : base_path_(base_path), 37 : base_path_(base_path),
38 map_all_requests_to_base_path_(map_all_requests_to_base_path), 38 map_all_requests_to_base_path_(map_all_requests_to_base_path),
39 worker_pool_(worker_pool) {} 39 worker_pool_(worker_pool) {}
40 ~MockJobInterceptor() override {} 40 ~MockJobInterceptor() override {}
41 41
42 // net::URLRequestJobFactory::ProtocolHandler implementation 42 // net::URLRequestInterceptor implementation
43 net::URLRequestJob* MaybeInterceptRequest( 43 net::URLRequestJob* MaybeInterceptRequest(
44 net::URLRequest* request, 44 net::URLRequest* request,
45 net::NetworkDelegate* network_delegate) const override { 45 net::NetworkDelegate* network_delegate) override {
46 return new URLRequestMockHTTPJob( 46 return new URLRequestMockHTTPJob(
47 request, 47 request,
48 network_delegate, 48 network_delegate,
49 map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request), 49 map_all_requests_to_base_path_ ? base_path_ : GetOnDiskPath(request),
50 worker_pool_->GetTaskRunnerWithShutdownBehavior( 50 worker_pool_->GetTaskRunnerWithShutdownBehavior(
51 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 51 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
52 } 52 }
53 53
54 net::URLRequestJob* MaybeInterceptRedirect(
55 net::URLRequest* request,
56 net::NetworkDelegate* network_delegate,
57 const GURL& location) override {
58 return NULL;
59 }
60
61 net::URLRequestJob* MaybeInterceptResponse(
62 net::URLRequest* request,
63 net::NetworkDelegate* network_delegate) override {
64 return NULL;
65 }
66
54 private: 67 private:
55 base::FilePath GetOnDiskPath(net::URLRequest* request) const { 68 base::FilePath GetOnDiskPath(net::URLRequest* request) const {
56 // Conceptually we just want to "return base_path_ + request->url().path()". 69 // Conceptually we just want to "return base_path_ + request->url().path()".
57 // But path in the request URL is in URL space (i.e. %-encoded spaces). 70 // But path in the request URL is in URL space (i.e. %-encoded spaces).
58 // So first we convert base FilePath to a URL, then append the URL 71 // So first we convert base FilePath to a URL, then append the URL
59 // path to that, and convert the final URL back to a FilePath. 72 // path to that, and convert the final URL back to a FilePath.
60 GURL file_url(net::FilePathToFileURL(base_path_)); 73 GURL file_url(net::FilePathToFileURL(base_path_));
61 std::string url = file_url.spec() + request->url().path(); 74 std::string url = file_url.spec() + request->url().path();
62 base::FilePath file_path; 75 base::FilePath file_path;
63 net::FileURLToFilePath(GURL(url), &file_path); 76 net::FileURLToFilePath(GURL(url), &file_path);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return net::URLRequestJob::GetResponseCode(); 214 return net::URLRequestJob::GetResponseCode();
202 } 215 }
203 216
204 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { 217 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) {
205 net::HttpResponseInfo info; 218 net::HttpResponseInfo info;
206 GetResponseInfo(&info); 219 GetResponseInfo(&info);
207 return info.headers.get() && info.headers->GetCharset(charset); 220 return info.headers.get() && info.headers->GetCharset(charset);
208 } 221 }
209 222
210 } // namespace net 223 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698