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

Unified Diff: chrome/browser/prerender/prerender_test_utils.cc

Issue 2508143002: Prerender: add true simultaneous nostate prefetch test. (Closed)
Patch Set: comments Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 364bfe579f57baa7b1c17ef274cb65c77f01f73d..0dbcf3bab3c355b57a357be54c74edd32ae5703f 100644
--- a/chrome/browser/prerender/prerender_test_utils.cc
+++ b/chrome/browser/prerender/prerender_test_utils.cc
@@ -104,6 +104,55 @@ class CountingInterceptor : public net::URLRequestInterceptor {
mutable base::WeakPtrFactory<CountingInterceptor> weak_factory_;
};
+// URLRequestJob (and associated handler) which hangs.
+class HangingURLRequestJob : public net::URLRequestJob {
+ public:
+ HangingURLRequestJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate)
+ : net::URLRequestJob(request, network_delegate) {
+ }
+
+ void Start() override {}
+
+ private:
+ ~HangingURLRequestJob() override {}
+};
+
+class HangingFirstRequestInterceptor : public net::URLRequestInterceptor {
+ public:
+ HangingFirstRequestInterceptor(const base::FilePath& file,
+ base::Closure callback)
+ : file_(file),
+ callback_(callback),
+ first_run_(true) {
+ }
+ ~HangingFirstRequestInterceptor() override {}
+
+ net::URLRequestJob* MaybeInterceptRequest(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const override {
+ if (first_run_) {
+ first_run_ = false;
+ if (!callback_.is_null()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE, callback_);
+ }
+ return new HangingURLRequestJob(request, network_delegate);
+ }
+ return new net::URLRequestMockHTTPJob(
+ request,
+ network_delegate,
+ file_,
+ BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
+ }
+
+ private:
+ base::FilePath file_;
+ base::Closure callback_;
+ mutable bool first_run_;
+};
+
// An ExternalProtocolHandler that blocks everything and asserts it never is
// called.
class NeverRunsExternalProtocolHandlerDelegate
@@ -656,6 +705,15 @@ void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) {
file, content::BrowserThread::GetBlockingPool()));
}
+void CreateHangingFirstRequestInterceptorOnIO(
+ const GURL& url, const base::FilePath& file, base::Closure callback) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ std::unique_ptr<net::URLRequestInterceptor> interceptor(
+ new HangingFirstRequestInterceptor(file, callback));
+ net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
+ url, std::move(interceptor));
+}
+
} // namespace test_utils
} // namespace prerender
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698