OLD | NEW |
1 // Copyright (c) 2011 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 // This class simulates what wininet does when a dns lookup fails. | |
5 | 4 |
6 #ifndef CONTENT_TEST_NET_URL_REQUEST_FAILED_DNS_JOB_H_ | 5 #ifndef CONTENT_TEST_NET_URL_REQUEST_FAILED_JOB_H_ |
7 #define CONTENT_TEST_NET_URL_REQUEST_FAILED_DNS_JOB_H_ | 6 #define CONTENT_TEST_NET_URL_REQUEST_FAILED_JOB_H_ |
8 #pragma once | 7 #pragma once |
9 | 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/compiler_specific.h" |
10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "googleurl/src/gurl.h" |
12 #include "net/url_request/url_request_job.h" | 15 #include "net/url_request/url_request_job.h" |
13 | 16 |
14 class URLRequestFailedDnsJob : public net::URLRequestJob { | 17 // This class simulates a URLRequestJob failing with a given error code while |
| 18 // trying to connect. |
| 19 class URLRequestFailedJob : public net::URLRequestJob { |
15 public: | 20 public: |
16 explicit URLRequestFailedDnsJob(net::URLRequest* request); | 21 URLRequestFailedJob(net::URLRequest* request, int net_error); |
17 | 22 |
18 virtual void Start() OVERRIDE; | 23 virtual void Start() OVERRIDE; |
19 | 24 |
20 static net::URLRequestJob* Factory(net::URLRequest* request, | |
21 const std::string& scheme); | |
22 | |
23 // A test URL that can be used in UI tests. | |
24 CONTENT_EXPORT static const char kTestUrl[]; | |
25 | |
26 // Adds the testing URLs to the net::URLRequestFilter. | 25 // Adds the testing URLs to the net::URLRequestFilter. |
27 CONTENT_EXPORT static void AddUrlHandler(); | 26 CONTENT_EXPORT static void AddUrlHandler(); |
28 | 27 |
| 28 // Given a net error code, constructs a mock URL that will return that error |
| 29 // asynchronously when started. |net_error| must be a valid net error code |
| 30 // other than net::OK and net::ERR_IO_PENDING. |
| 31 CONTENT_EXPORT static GURL GetMockHttpUrl(int net_error); |
| 32 CONTENT_EXPORT static GURL GetMockHttpsUrl(int net_error); |
| 33 |
29 private: | 34 private: |
30 virtual ~URLRequestFailedDnsJob(); | 35 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 36 const std::string& scheme); |
31 | 37 |
32 // Simulate a DNS failure. | 38 virtual ~URLRequestFailedJob(); |
| 39 |
| 40 // Simulate a failure. |
33 void StartAsync(); | 41 void StartAsync(); |
34 | 42 |
35 base::WeakPtrFactory<URLRequestFailedDnsJob> weak_factory_; | 43 const int net_error_; |
| 44 |
| 45 base::WeakPtrFactory<URLRequestFailedJob> weak_factory_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(URLRequestFailedJob); |
36 }; | 48 }; |
37 | 49 |
38 #endif // CONTENT_TEST_NET_URL_REQUEST_FAILED_DNS_JOB_H_ | 50 #endif // CONTENT_TEST_NET_URL_REQUEST_FAILED_JOB_H_ |
OLD | NEW |