OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 // A net::URLRequestJob class that simulates network errors (including https | |
6 // related). | |
7 // It is based on URLRequestMockHttpJob. | |
8 | |
9 #ifndef CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_ | |
10 #define CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_ | |
11 #pragma once | |
12 | |
13 #include "base/task.h" | |
14 #include "content/browser/net/url_request_mock_http_job.h" | |
15 | |
16 class URLRequestMockNetErrorJob : public URLRequestMockHTTPJob { | |
17 public: | |
18 URLRequestMockNetErrorJob(net::URLRequest* request, | |
19 const std::vector<int>& errors, | |
20 net::X509Certificate* ssl_cert, | |
21 const FilePath& file_path); | |
22 | |
23 virtual void Start(); | |
24 virtual void ContinueDespiteLastError(); | |
25 | |
26 // Add the specified URL to the list of URLs that should be mocked. When this | |
27 // URL is hit, the specified |errors| will be played. If any of these errors | |
28 // is a cert error, |ssl_cert| will be used as the ssl cert when notifying of | |
29 // the error. |ssl_cert| can be NULL if |errors| does not contain any cert | |
30 // errors. |base| is the location on disk where the file mocking the URL | |
31 // contents and http-headers should be retrieved from. | |
32 static void AddMockedURL(const GURL& url, | |
33 const std::wstring& base, | |
34 const std::vector<int>& errors, | |
35 net::X509Certificate* ssl_cert); | |
36 | |
37 // Removes the specified |url| from the list of mocked urls. | |
38 static void RemoveMockedURL(const GURL& url); | |
39 | |
40 private: | |
41 virtual ~URLRequestMockNetErrorJob(); | |
42 | |
43 static net::URLRequest::ProtocolFactory Factory; | |
44 | |
45 void StartAsync(); | |
46 | |
47 // The errors to simulate. | |
48 std::vector<int> errors_; | |
49 | |
50 // The certificate to use for SSL errors. | |
51 scoped_refptr<net::X509Certificate> ssl_cert_; | |
52 | |
53 struct MockInfo; | |
54 typedef std::map<GURL, MockInfo> URLMockInfoMap; | |
55 static URLMockInfoMap url_mock_info_map_; | |
56 | |
57 ScopedRunnableMethodFactory<URLRequestMockNetErrorJob> method_factory_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(URLRequestMockNetErrorJob); | |
60 }; | |
61 | |
62 #endif // CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_ | |
OLD | NEW |