| 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 "net/url_request/test_url_request_interceptor.h" | 5 #include "net/url_request/test_url_request_interceptor.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 base::AutoLock auto_lock(hit_count_lock_); | 86 base::AutoLock auto_lock(hit_count_lock_); |
| 87 return hit_count_; | 87 return hit_count_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 typedef std::map<GURL, base::FilePath> ResponseMap; | 91 typedef std::map<GURL, base::FilePath> ResponseMap; |
| 92 | 92 |
| 93 // When computing matches, this ignores the query parameters of the url. | 93 // When computing matches, this ignores the query parameters of the url. |
| 94 net::URLRequestJob* MaybeInterceptRequest( | 94 net::URLRequestJob* MaybeInterceptRequest( |
| 95 net::URLRequest* request, | 95 net::URLRequest* request, |
| 96 net::NetworkDelegate* network_delegate) const override { | 96 net::NetworkDelegate* network_delegate) override { |
| 97 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 97 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 98 if (request->url().scheme() != scheme_ || | 98 if (request->url().scheme() != scheme_ || |
| 99 request->url().host() != hostname_) { | 99 request->url().host() != hostname_) { |
| 100 return NULL; | 100 return NULL; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ResponseMap::const_iterator it = responses_.find(request->url()); | 103 ResponseMap::const_iterator it = responses_.find(request->url()); |
| 104 if (it == responses_.end()) { | 104 if (it == responses_.end()) { |
| 105 // Search for this request's url, ignoring any query parameters. | 105 // Search for this request's url, ignoring any query parameters. |
| 106 GURL url = request->url(); | 106 GURL url = request->url(); |
| 107 if (url.has_query()) { | 107 if (url.has_query()) { |
| 108 GURL::Replacements replacements; | 108 GURL::Replacements replacements; |
| 109 replacements.ClearQuery(); | 109 replacements.ClearQuery(); |
| 110 url = url.ReplaceComponents(replacements); | 110 url = url.ReplaceComponents(replacements); |
| 111 } | 111 } |
| 112 it = ignore_query_responses_.find(url); | 112 it = ignore_query_responses_.find(url); |
| 113 if (it == ignore_query_responses_.end()) | 113 if (it == ignore_query_responses_.end()) |
| 114 return NULL; | 114 return NULL; |
| 115 } | 115 } |
| 116 { | 116 { |
| 117 base::AutoLock auto_lock(hit_count_lock_); | 117 base::AutoLock auto_lock(hit_count_lock_); |
| 118 ++hit_count_; | 118 ++hit_count_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 return new TestURLRequestJob( | 121 return new TestURLRequestJob( |
| 122 request, network_delegate, it->second, worker_task_runner_); | 122 request, network_delegate, it->second, worker_task_runner_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 net::URLRequestJob* MaybeInterceptRedirect( |
| 126 net::URLRequest* request, |
| 127 net::NetworkDelegate* network_delegate, |
| 128 const GURL& location) override { |
| 129 return NULL; |
| 130 } |
| 131 |
| 132 net::URLRequestJob* MaybeInterceptResponse( |
| 133 net::URLRequest* request, |
| 134 net::NetworkDelegate* network_delegate) override { |
| 135 return NULL; |
| 136 } |
| 137 |
| 125 const std::string scheme_; | 138 const std::string scheme_; |
| 126 const std::string hostname_; | 139 const std::string hostname_; |
| 127 | 140 |
| 128 const scoped_refptr<base::TaskRunner> network_task_runner_; | 141 const scoped_refptr<base::TaskRunner> network_task_runner_; |
| 129 const scoped_refptr<base::TaskRunner> worker_task_runner_; | 142 const scoped_refptr<base::TaskRunner> worker_task_runner_; |
| 130 | 143 |
| 131 ResponseMap responses_; | 144 ResponseMap responses_; |
| 132 ResponseMap ignore_query_responses_; | 145 ResponseMap ignore_query_responses_; |
| 133 | 146 |
| 134 mutable base::Lock hit_count_lock_; | 147 mutable base::Lock hit_count_lock_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 LocalHostTestURLRequestInterceptor::LocalHostTestURLRequestInterceptor( | 203 LocalHostTestURLRequestInterceptor::LocalHostTestURLRequestInterceptor( |
| 191 const scoped_refptr<base::TaskRunner>& network_task_runner, | 204 const scoped_refptr<base::TaskRunner>& network_task_runner, |
| 192 const scoped_refptr<base::TaskRunner>& worker_task_runner) | 205 const scoped_refptr<base::TaskRunner>& worker_task_runner) |
| 193 : TestURLRequestInterceptor("http", | 206 : TestURLRequestInterceptor("http", |
| 194 "localhost", | 207 "localhost", |
| 195 network_task_runner, | 208 network_task_runner, |
| 196 worker_task_runner) { | 209 worker_task_runner) { |
| 197 } | 210 } |
| 198 | 211 |
| 199 } // namespace net | 212 } // namespace net |
| OLD | NEW |