Chromium Code Reviews| Index: chrome/browser/prerender/prerender_test_utils.cc |
| diff --git a/chrome/browser/prerender/prerender_test_utils.cc b/chrome/browser/prerender/prerender_test_utils.cc |
| index 0dbcf3bab3c355b57a357be54c74edd32ae5703f..ed21e2bb10773b86eff7badd9a46d18fd8c5d473 100644 |
| --- a/chrome/browser/prerender/prerender_test_utils.cc |
| +++ b/chrome/browser/prerender/prerender_test_utils.cc |
| @@ -31,6 +31,7 @@ |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/url_constants.h" |
| #include "content/public/test/ppapi_test_utils.h" |
| +#include "net/base/load_flags.h" |
| #include "net/test/embedded_test_server/request_handler_util.h" |
| #include "net/url_request/url_request_filter.h" |
| #include "ppapi/shared_impl/ppapi_switches.h" |
| @@ -104,6 +105,28 @@ class CountingInterceptor : public net::URLRequestInterceptor { |
| mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_; |
| }; |
| +// URLRequestInterceptor which asserts that the request is prefetch only. Pings |
| +// |counter| after the flag is checked. |
| +class PrefetchOnlyInterceptor : public net::URLRequestInterceptor { |
| + public: |
| + explicit PrefetchOnlyInterceptor(const base::WeakPtr<RequestCounter>& counter) |
| + : counter_(counter) {} |
| + ~PrefetchOnlyInterceptor() override {} |
| + |
| + net::URLRequestJob* MaybeInterceptRequest( |
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate) const override { |
| + EXPECT_TRUE(request->load_flags() & net::LOAD_PREFETCH); |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind(&RequestCounter::RequestStarted, counter_)); |
| + return NULL; |
|
droger
2016/11/23 15:20:10
nullptr
mattcary
2016/11/23 15:28:32
Yikes, how 2010 of me.
|
| + } |
| + |
| + private: |
| + base::WeakPtr<RequestCounter> counter_; |
| +}; |
| + |
| // URLRequestJob (and associated handler) which hangs. |
| class HangingURLRequestJob : public net::URLRequestJob { |
| public: |
| @@ -698,6 +721,14 @@ void CreateCountingInterceptorOnIO( |
| url, base::MakeUnique<CountingInterceptor>(file, counter)); |
| } |
| +void CreatePrefetchOnlyInterceptorOnIO( |
| + const GURL& url, |
| + const base::WeakPtr<RequestCounter>& counter) { |
| + CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| + url, base::MakeUnique<PrefetchOnlyInterceptor>(counter)); |
| +} |
| + |
| void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
| CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |