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

Side by Side Diff: chrome/browser/prerender/prerender_test_utils.cc

Issue 2807163002: [Prerender] Restore request priorities when swapped in (Closed)
Patch Set: Fix test: default image priority can be LOWEST or MEDIUM Created 3 years, 8 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
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 "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
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
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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 CountingInterceptorWithCallback::Initialize(url, counter, callback_io); 813 CountingInterceptorWithCallback::Initialize(url, counter, callback_io);
807 } 814 }
808 815
809 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { 816 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
810 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 817 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
811 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 818 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
812 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( 819 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
813 file, content::BrowserThread::GetBlockingPool())); 820 file, content::BrowserThread::GetBlockingPool()));
814 } 821 }
815 822
816 void CreateHangingFirstRequestInterceptorOnIO( 823 void CreateHangingFirstRequestInterceptor(
817 const GURL& url, const base::FilePath& file, base::Closure callback) { 824 const GURL& url,
818 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 825 const base::FilePath& file,
819 std::unique_ptr<net::URLRequestInterceptor> interceptor( 826 base::Callback<void(net::URLRequest*)> callback_io) {
820 new HangingFirstRequestInterceptor(file, callback)); 827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
821 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( 828 content::BrowserThread::PostTask(
822 url, std::move(interceptor)); 829 content::BrowserThread::IO, FROM_HERE,
830 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, url, file,
831 callback_io));
823 } 832 }
824 833
825 } // namespace test_utils 834 } // namespace test_utils
826 835
827 } // namespace prerender 836 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698