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, | |
20 public base::SupportsWeakPtr<URLRequestFailedJob> { | |
15 public: | 21 public: |
16 explicit URLRequestFailedDnsJob(net::URLRequest* request); | 22 URLRequestFailedJob(net::URLRequest* request, int net_error); |
17 | 23 |
18 virtual void Start() OVERRIDE; | 24 virtual void Start() OVERRIDE; |
19 | 25 |
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. | 26 // Adds the testing URLs to the net::URLRequestFilter. |
27 CONTENT_EXPORT static void AddUrlHandler(); | 27 CONTENT_EXPORT static void AddUrlHandler(); |
28 | 28 |
29 // Given a net error code, constructs a mock URL that will return that error | |
30 // asynchronously when started. |net_error| must be a valid net error code | |
31 // other than net::OK and net::ERR_IO_PENDING. | |
32 CONTENT_EXPORT static GURL GetMockHttpUrl(int net_error); | |
33 CONTENT_EXPORT static GURL GetMockHttpsUrl(int net_error); | |
34 | |
29 private: | 35 private: |
30 virtual ~URLRequestFailedDnsJob(); | 36 static net::URLRequestJob* Factory(net::URLRequest* request, |
37 const std::string& scheme); | |
31 | 38 |
32 // Simulate a DNS failure. | 39 virtual ~URLRequestFailedJob(); |
40 | |
41 // Simulate a failure. | |
33 void StartAsync(); | 42 void StartAsync(); |
34 | 43 |
35 base::WeakPtrFactory<URLRequestFailedDnsJob> weak_factory_; | 44 const int net_error_; |
willchan no longer on Chromium
2012/03/15 22:42:28
Why are we using SupportsWeakPtr instead of a Weak
mmenke
2012/03/15 22:55:46
Mostly because it's not publicly accessible anyway
| |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(URLRequestFailedJob); | |
36 }; | 47 }; |
37 | 48 |
38 #endif // CONTENT_TEST_NET_URL_REQUEST_FAILED_DNS_JOB_H_ | 49 #endif // CONTENT_TEST_NET_URL_REQUEST_FAILED_JOB_H_ |
OLD | NEW |