OLD | NEW |
1 // Copyright (c) 2012 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 | 4 |
5 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ | 5 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ |
6 #define NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ | 6 #define NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // This class simulates a URLRequestJob failing with a given error code at | 17 // This class simulates a URLRequestJob failing with a given error code at |
18 // a particular phase while trying to connect. | 18 // a particular phase while trying to connect. |
19 class URLRequestFailedJob : public URLRequestJob { | 19 class URLRequestFailedJob : public URLRequestJob { |
20 public: | 20 public: |
21 // A Java counterpart will be generated for this enum. | 21 // A Java counterpart will be generated for this enum. |
22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.test | 22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.test |
23 enum FailurePhase { | 23 enum FailurePhase { |
24 START = 0, | 24 START = 0, |
25 READ_SYNC = 1, | 25 READ_SYNC = 1, |
26 READ_ASYNC = 2, | 26 READ_ASYNC = 2, |
27 MAX_FAILURE_PHASE = 3, | 27 CERT_REQUESTED = 3, |
| 28 MAX_FAILURE_PHASE = 4, |
28 }; | 29 }; |
29 | 30 |
30 URLRequestFailedJob(URLRequest* request, | 31 URLRequestFailedJob(URLRequest* request, |
31 NetworkDelegate* network_delegate, | 32 NetworkDelegate* network_delegate, |
32 FailurePhase phase, | 33 FailurePhase phase, |
33 int net_error); | 34 int net_error); |
34 | 35 |
35 // Same as above, except that the job fails at FailurePhase.START. | 36 // Same as above, except that the job fails at FailurePhase.START. |
36 URLRequestFailedJob(URLRequest* request, | 37 URLRequestFailedJob(URLRequest* request, |
37 NetworkDelegate* network_delegate, | 38 NetworkDelegate* network_delegate, |
38 int net_error); | 39 int net_error); |
39 | 40 |
40 // URLRequestJob implementation: | 41 // URLRequestJob implementation: |
41 void Start() override; | 42 void Start() override; |
42 int ReadRawData(IOBuffer* buf, int buf_size) override; | 43 int ReadRawData(IOBuffer* buf, int buf_size) override; |
43 int GetResponseCode() const override; | 44 int GetResponseCode() const override; |
44 void GetResponseInfo(HttpResponseInfo* info) override; | 45 void GetResponseInfo(HttpResponseInfo* info) override; |
| 46 void ContinueWithCertificate(X509Certificate* client_cert, |
| 47 SSLPrivateKey* client_private_key) override; |
45 | 48 |
46 // Adds the testing URLs to the URLRequestFilter. | 49 // Adds the testing URLs to the URLRequestFilter. |
47 static void AddUrlHandler(); | 50 static void AddUrlHandler(); |
48 static void AddUrlHandlerForHostname(const std::string& hostname); | 51 static void AddUrlHandlerForHostname(const std::string& hostname); |
49 | 52 |
50 // Given a net error code, constructs a mock URL that will return that error | 53 // Given a net error code, constructs a mock URL that will return that error |
51 // asynchronously when started. |net_error| must be a valid net error code | 54 // asynchronously when started. |net_error| must be a valid net error code |
52 // other than net::OK. Passing net::ERR_IO_PENDING for |net_error| causes the | 55 // other than net::OK. Passing net::ERR_IO_PENDING for |net_error| causes the |
53 // resulting request to hang. | 56 // resulting request to hang. |
54 static GURL GetMockHttpUrl(int net_error); | 57 static GURL GetMockHttpUrl(int net_error); |
(...skipping 24 matching lines...) Expand all Loading... |
79 const int net_error_; | 82 const int net_error_; |
80 | 83 |
81 base::WeakPtrFactory<URLRequestFailedJob> weak_factory_; | 84 base::WeakPtrFactory<URLRequestFailedJob> weak_factory_; |
82 | 85 |
83 DISALLOW_COPY_AND_ASSIGN(URLRequestFailedJob); | 86 DISALLOW_COPY_AND_ASSIGN(URLRequestFailedJob); |
84 }; | 87 }; |
85 | 88 |
86 } // namespace net | 89 } // namespace net |
87 | 90 |
88 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ | 91 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_FAILED_JOB_H_ |
OLD | NEW |