Chromium Code Reviews| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 content::BrowserThread::UI, FROM_HERE, | 97 content::BrowserThread::UI, FROM_HERE, |
| 98 base::Bind(&RequestCounter::RequestStarted, counter_)); | 98 base::Bind(&RequestCounter::RequestStarted, counter_)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 base::FilePath file_; | 102 base::FilePath file_; |
| 103 base::WeakPtr<RequestCounter> counter_; | 103 base::WeakPtr<RequestCounter> counter_; |
| 104 mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_; | 104 mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // URLRequestJob (and associated handler) which hangs. | |
| 108 class HangingURLRequestJob : public net::URLRequestJob { | |
| 109 public: | |
| 110 HangingURLRequestJob(net::URLRequest* request, | |
| 111 net::NetworkDelegate* network_delegate) | |
| 112 : net::URLRequestJob(request, network_delegate) { | |
| 113 } | |
| 114 | |
| 115 void Start() override {} | |
| 116 | |
| 117 private: | |
| 118 ~HangingURLRequestJob() override {} | |
| 119 }; | |
| 120 | |
| 121 class HangingFirstRequestInterceptor : public net::URLRequestInterceptor { | |
| 122 public: | |
| 123 HangingFirstRequestInterceptor(const base::FilePath& file, | |
| 124 base::Closure callback) | |
| 125 : file_(file), | |
| 126 callback_(callback), | |
| 127 first_run_(true) { | |
| 128 } | |
| 129 ~HangingFirstRequestInterceptor() override {} | |
| 130 | |
| 131 net::URLRequestJob* MaybeInterceptRequest( | |
| 132 net::URLRequest* request, | |
| 133 net::NetworkDelegate* network_delegate) const override { | |
| 134 if (first_run_) { | |
| 135 first_run_ = false; | |
| 136 if (!callback_.is_null()) { | |
| 137 BrowserThread::PostTask( | |
| 138 BrowserThread::UI, FROM_HERE, callback_); | |
| 139 } | |
| 140 return new HangingURLRequestJob(request, network_delegate); | |
| 141 } | |
| 142 return new net::URLRequestMockHTTPJob( | |
| 143 request, | |
| 144 network_delegate, | |
| 145 file_, | |
| 146 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | |
| 147 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
| 148 } | |
| 149 | |
| 150 private: | |
| 151 base::FilePath file_; | |
| 152 base::Closure callback_; | |
| 153 mutable bool first_run_; | |
| 154 }; | |
| 155 | |
| 107 // An ExternalProtocolHandler that blocks everything and asserts it never is | 156 // An ExternalProtocolHandler that blocks everything and asserts it never is |
| 108 // called. | 157 // called. |
| 109 class NeverRunsExternalProtocolHandlerDelegate | 158 class NeverRunsExternalProtocolHandlerDelegate |
| 110 : public ExternalProtocolHandler::Delegate { | 159 : public ExternalProtocolHandler::Delegate { |
| 111 public: | 160 public: |
| 112 scoped_refptr<shell_integration::DefaultProtocolClientWorker> | 161 scoped_refptr<shell_integration::DefaultProtocolClientWorker> |
| 113 CreateShellWorker( | 162 CreateShellWorker( |
| 114 const shell_integration::DefaultWebClientWorkerCallback& callback, | 163 const shell_integration::DefaultWebClientWorkerCallback& callback, |
| 115 const std::string& protocol) override { | 164 const std::string& protocol) override { |
| 116 NOTREACHED(); | 165 NOTREACHED(); |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 url, base::MakeUnique<CountingInterceptor>(file, counter)); | 698 url, base::MakeUnique<CountingInterceptor>(file, counter)); |
| 650 } | 699 } |
| 651 | 700 |
| 652 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 701 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| 653 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 702 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 654 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 703 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 655 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 704 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 656 file, content::BrowserThread::GetBlockingPool())); | 705 file, content::BrowserThread::GetBlockingPool())); |
| 657 } | 706 } |
| 658 | 707 |
| 708 void CreateHangingFirstRequestInterceptorOnIO( | |
| 709 const GURL& url, const base::FilePath& file, base::Closure callback) { | |
| 710 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 711 std::unique_ptr<net::URLRequestInterceptor> never_respond_handler( | |
|
pasko
2016/11/17 17:19:28
nit: 'never' sounds confusing since it will respon
mattcary
2016/11/18 08:22:55
Done.
This was old code that was moved, but since
| |
| 712 new HangingFirstRequestInterceptor(file, callback)); | |
| 713 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | |
| 714 url, std::move(never_respond_handler)); | |
| 715 } | |
| 716 | |
| 659 } // namespace test_utils | 717 } // namespace test_utils |
| 660 | 718 |
| 661 } // namespace prerender | 719 } // namespace prerender |
| OLD | NEW |