OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/test/url_request/url_request_hanging_connect_job.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <string> |
| 9 |
| 10 #include "net/url_request/url_request.h" |
| 11 #include "net/url_request/url_request_filter.h" |
| 12 #include "net/url_request/url_request_interceptor.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kMockHostname[] = "mock.hanging.connect"; |
| 19 |
| 20 GURL GetMockUrl(const std::string& scheme, const std::string& hostname) { |
| 21 return GURL(scheme + "://" + hostname); |
| 22 } |
| 23 |
| 24 class MockJobInterceptor : public URLRequestInterceptor { |
| 25 public: |
| 26 MockJobInterceptor() {} |
| 27 ~MockJobInterceptor() override {} |
| 28 |
| 29 // URLRequestJobFactory::ProtocolHandler implementation: |
| 30 URLRequestJob* MaybeInterceptRequest( |
| 31 URLRequest* request, |
| 32 NetworkDelegate* network_delegate) const override { |
| 33 return new URLRequestHangingConnectJob(request, network_delegate); |
| 34 } |
| 35 |
| 36 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); |
| 38 }; |
| 39 |
| 40 } // namespace |
| 41 |
| 42 URLRequestHangingConnectJob::URLRequestHangingConnectJob( |
| 43 URLRequest* request, |
| 44 NetworkDelegate* network_delegate) |
| 45 : URLRequestJob(request, network_delegate) {} |
| 46 |
| 47 void URLRequestHangingConnectJob::Start() { |
| 48 // Do nothing. |
| 49 } |
| 50 |
| 51 // static |
| 52 void URLRequestHangingConnectJob::AddUrlHandler() { |
| 53 URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
| 54 // Add |hostname| to URLRequestFilter for HTTP and HTTPS. |
| 55 filter->AddHostnameInterceptor( |
| 56 "http", kMockHostname, |
| 57 std::unique_ptr<URLRequestInterceptor>(new MockJobInterceptor())); |
| 58 filter->AddHostnameInterceptor( |
| 59 "https", kMockHostname, |
| 60 std::unique_ptr<URLRequestInterceptor>(new MockJobInterceptor())); |
| 61 } |
| 62 |
| 63 // static |
| 64 GURL URLRequestHangingConnectJob::GetMockHttpUrl() { |
| 65 return GetMockUrl("http", kMockHostname); |
| 66 } |
| 67 |
| 68 // static |
| 69 GURL URLRequestHangingConnectJob::GetMockHttpsUrl() { |
| 70 return GetMockUrl("https", kMockHostname); |
| 71 } |
| 72 |
| 73 URLRequestHangingConnectJob::~URLRequestHangingConnectJob() {} |
| 74 |
| 75 } // namespace net |
OLD | NEW |