| 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 "chrome/browser/prerender/prerender_test_utils.h" | 5 #include "chrome/browser/prerender/prerender_test_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 void Start() override {} | 172 void Start() override {} |
| 173 | 173 |
| 174 private: | 174 private: |
| 175 ~HangingURLRequestJob() override {} | 175 ~HangingURLRequestJob() override {} |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor { | 178 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor { |
| 179 public: | 179 public: |
| 180 HangingFirstRequestInterceptor(const base::FilePath& file, | 180 HangingFirstRequestInterceptor( |
| 181 base::Closure callback) | 181 const base::FilePath& file, |
| 182 : file_(file), | 182 base::Callback<void(net::URLRequest*)> callback) |
| 183 callback_(callback), | 183 : file_(file), callback_(callback), first_run_(true) {} |
| 184 first_run_(true) { | |
| 185 } | |
| 186 ~HangingFirstRequestInterceptor() override {} | 184 ~HangingFirstRequestInterceptor() override {} |
| 187 | 185 |
| 188 net::URLRequestJob* MaybeInterceptRequest( | 186 net::URLRequestJob* MaybeInterceptRequest( |
| 189 net::URLRequest* request, | 187 net::URLRequest* request, |
| 190 net::NetworkDelegate* network_delegate) const override { | 188 net::NetworkDelegate* network_delegate) const override { |
| 191 if (first_run_) { | 189 if (first_run_) { |
| 192 first_run_ = false; | 190 first_run_ = false; |
| 193 if (!callback_.is_null()) { | 191 if (!callback_.is_null()) |
| 194 BrowserThread::PostTask( | 192 callback_.Run(request); |
| 195 BrowserThread::UI, FROM_HERE, callback_); | |
| 196 } | |
| 197 return new HangingURLRequestJob(request, network_delegate); | 193 return new HangingURLRequestJob(request, network_delegate); |
| 198 } | 194 } |
| 199 return new net::URLRequestMockHTTPJob( | 195 return new net::URLRequestMockHTTPJob( |
| 200 request, | 196 request, |
| 201 network_delegate, | 197 network_delegate, |
| 202 file_, | 198 file_, |
| 203 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 199 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 204 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 200 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 205 } | 201 } |
| 206 | 202 |
| 207 private: | 203 private: |
| 208 base::FilePath file_; | 204 base::FilePath file_; |
| 209 base::Closure callback_; | 205 base::Callback<void(net::URLRequest*)> callback_; |
| 210 mutable bool first_run_; | 206 mutable bool first_run_; |
| 211 }; | 207 }; |
| 212 | 208 |
| 213 // An ExternalProtocolHandler that blocks everything and asserts it never is | 209 // An ExternalProtocolHandler that blocks everything and asserts it never is |
| 214 // called. | 210 // called. |
| 215 class NeverRunsExternalProtocolHandlerDelegate | 211 class NeverRunsExternalProtocolHandlerDelegate |
| 216 : public ExternalProtocolHandler::Delegate { | 212 : public ExternalProtocolHandler::Delegate { |
| 217 public: | 213 public: |
| 218 scoped_refptr<shell_integration::DefaultProtocolClientWorker> | 214 scoped_refptr<shell_integration::DefaultProtocolClientWorker> |
| 219 CreateShellWorker( | 215 CreateShellWorker( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 244 | 240 |
| 245 void LaunchUrlWithoutSecurityCheck( | 241 void LaunchUrlWithoutSecurityCheck( |
| 246 const GURL& url, | 242 const GURL& url, |
| 247 content::WebContents* web_contents) override { | 243 content::WebContents* web_contents) override { |
| 248 NOTREACHED(); | 244 NOTREACHED(); |
| 249 } | 245 } |
| 250 | 246 |
| 251 void FinishedProcessingCheck() override { NOTREACHED(); } | 247 void FinishedProcessingCheck() override { NOTREACHED(); } |
| 252 }; | 248 }; |
| 253 | 249 |
| 250 void CreateHangingFirstRequestInterceptorOnIO( |
| 251 const GURL& url, |
| 252 const base::FilePath& file, |
| 253 base::Callback<void(net::URLRequest*)> callback_io) { |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 255 std::unique_ptr<net::URLRequestInterceptor> interceptor( |
| 256 new HangingFirstRequestInterceptor(file, callback_io)); |
| 257 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 258 url, std::move(interceptor)); |
| 259 } |
| 260 |
| 254 } // namespace | 261 } // namespace |
| 255 | 262 |
| 256 RequestCounter::RequestCounter() : count_(0), expected_count_(-1) {} | 263 RequestCounter::RequestCounter() : count_(0), expected_count_(-1) {} |
| 257 | 264 |
| 258 RequestCounter::~RequestCounter() {} | 265 RequestCounter::~RequestCounter() {} |
| 259 | 266 |
| 260 void RequestCounter::RequestStarted() { | 267 void RequestCounter::RequestStarted() { |
| 261 count_++; | 268 count_++; |
| 262 if (loop_ && count_ == expected_count_) | 269 if (loop_ && count_ == expected_count_) |
| 263 loop_->Quit(); | 270 loop_->Quit(); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 CountingInterceptorWithCallback::Initialize(url, counter, callback_io); | 801 CountingInterceptorWithCallback::Initialize(url, counter, callback_io); |
| 795 } | 802 } |
| 796 | 803 |
| 797 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 804 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 798 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 805 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 799 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 806 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 800 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 807 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 801 file, content::BrowserThread::GetBlockingPool())); | 808 file, content::BrowserThread::GetBlockingPool())); |
| 802 } | 809 } |
| 803 | 810 |
| 804 void CreateHangingFirstRequestInterceptorOnIO( | 811 void CreateHangingFirstRequestInterceptor( |
| 805 const GURL& url, const base::FilePath& file, base::Closure callback) { | 812 const GURL& url, |
| 806 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 813 const base::FilePath& file, |
| 807 std::unique_ptr<net::URLRequestInterceptor> interceptor( | 814 base::Callback<void(net::URLRequest*)> callback_io) { |
| 808 new HangingFirstRequestInterceptor(file, callback)); | 815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 809 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 816 content::BrowserThread::PostTask( |
| 810 url, std::move(interceptor)); | 817 content::BrowserThread::IO, FROM_HERE, |
| 818 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, url, file, |
| 819 callback_io)); |
| 811 } | 820 } |
| 812 | 821 |
| 813 } // namespace test_utils | 822 } // namespace test_utils |
| 814 | 823 |
| 815 } // namespace prerender | 824 } // namespace prerender |
| OLD | NEW |