Index: net/test/url_request/url_request_hanging_connect_job.cc |
diff --git a/net/test/url_request/url_request_hanging_connect_job.cc b/net/test/url_request/url_request_hanging_connect_job.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..adf150e22f8c44b6613f8d2e1f824f229936205e |
--- /dev/null |
+++ b/net/test/url_request/url_request_hanging_connect_job.cc |
@@ -0,0 +1,75 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/test/url_request/url_request_hanging_connect_job.h" |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "net/url_request/url_request.h" |
+#include "net/url_request/url_request_filter.h" |
+#include "net/url_request/url_request_interceptor.h" |
+ |
+namespace net { |
+ |
+namespace { |
+ |
+const char kMockHostname[] = "mock.hanging.connect"; |
+ |
+GURL GetMockUrl(const std::string& scheme, const std::string& hostname) { |
+ return GURL(scheme + "://" + hostname); |
+} |
+ |
+class MockJobInterceptor : public URLRequestInterceptor { |
+ public: |
+ MockJobInterceptor() {} |
+ ~MockJobInterceptor() override {} |
+ |
+ // URLRequestJobFactory::ProtocolHandler implementation: |
+ URLRequestJob* MaybeInterceptRequest( |
+ URLRequest* request, |
+ NetworkDelegate* network_delegate) const override { |
+ return new URLRequestHangingConnectJob(request, network_delegate); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); |
+}; |
+ |
+} // namespace |
+ |
+URLRequestHangingConnectJob::URLRequestHangingConnectJob( |
+ URLRequest* request, |
+ NetworkDelegate* network_delegate) |
+ : URLRequestJob(request, network_delegate) {} |
+ |
+void URLRequestHangingConnectJob::Start() { |
+ // Do nothing. |
+} |
+ |
+// static |
+void URLRequestHangingConnectJob::AddUrlHandler() { |
+ URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
+ // Add |hostname| to URLRequestFilter for HTTP and HTTPS. |
+ filter->AddHostnameInterceptor( |
+ "http", kMockHostname, |
+ std::unique_ptr<URLRequestInterceptor>(new MockJobInterceptor())); |
+ filter->AddHostnameInterceptor( |
+ "https", kMockHostname, |
+ std::unique_ptr<URLRequestInterceptor>(new MockJobInterceptor())); |
+} |
+ |
+// static |
+GURL URLRequestHangingConnectJob::GetMockHttpUrl() { |
+ return GetMockUrl("http", kMockHostname); |
+} |
+ |
+// static |
+GURL URLRequestHangingConnectJob::GetMockHttpsUrl() { |
+ return GetMockUrl("https", kMockHostname); |
+} |
+ |
+URLRequestHangingConnectJob::~URLRequestHangingConnectJob() {} |
+ |
+} // namespace net |