Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: net/test/url_request/url_request_mock_data_job.h

Issue 1459993003: [Cronet] Continue UrlRequest with NULL certificate if Client cert is requested. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Helen's comments. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "net/base/net_export.h" 11 #include "net/base/net_export.h"
12 #include "net/url_request/url_request_job.h" 12 #include "net/url_request/url_request_job.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 class URLRequest; 16 class URLRequest;
17 17
18 // Mock data job, which synchronously returns data repeated multiple times. 18 // Mock data job, which synchronously returns data repeated multiple times. If
19 // |request_client_certificate| is true, then this job will request client
20 // certificate before proceeding.
19 class URLRequestMockDataJob : public URLRequestJob { 21 class URLRequestMockDataJob : public URLRequestJob {
20 public: 22 public:
21 URLRequestMockDataJob(URLRequest* request, 23 URLRequestMockDataJob(URLRequest* request,
22 NetworkDelegate* network_delegate, 24 NetworkDelegate* network_delegate,
23 const std::string& data, 25 const std::string& data,
24 int data_repeat_count); 26 int data_repeat_count,
27 bool request_client_certificate);
25 28
26 void Start() override; 29 void Start() override;
27 int ReadRawData(IOBuffer* buf, int buf_size) override; 30 int ReadRawData(IOBuffer* buf, int buf_size) override;
28 int GetResponseCode() const override; 31 int GetResponseCode() const override;
29 void GetResponseInfo(HttpResponseInfo* info) override; 32 void GetResponseInfo(HttpResponseInfo* info) override;
33 void ContinueWithCertificate(X509Certificate* client_cert,
34 SSLPrivateKey* client_private_key) override;
30 35
31 // Adds the testing URLs to the URLRequestFilter. 36 // Adds the testing URLs to the URLRequestFilter.
32 static void AddUrlHandler(); 37 static void AddUrlHandler();
33 static void AddUrlHandlerForHostname(const std::string& hostname); 38 static void AddUrlHandlerForHostname(const std::string& hostname);
34 39
35 // Given data and repeat cound, constructs a mock URL that will return that 40 // Given data and repeat cound, constructs a mock URL that will return that
36 // data repeated |repeat_count| times when started. |data| must be safe for 41 // data repeated |repeat_count| times when started. |data| must be safe for
37 // URL. 42 // URL.
38 static GURL GetMockHttpUrl(const std::string& data, int repeat_count); 43 static GURL GetMockHttpUrl(const std::string& data, int repeat_count);
39 static GURL GetMockHttpsUrl(const std::string& data, int repeat_count); 44 static GURL GetMockHttpsUrl(const std::string& data, int repeat_count);
40 45
46 // Constructs Mock URL which will request client certificate and return the
47 // word "data" as the response.
48 static GURL GetMockUrlForClientCertificateRequest();
49
41 // URLRequestFailedJob must be added as a handler for |hostname| for 50 // URLRequestFailedJob must be added as a handler for |hostname| for
42 // the returned URL to return |net_error|. 51 // the returned URL to return |net_error|.
43 static GURL GetMockHttpUrlForHostname(const std::string& hostname, 52 static GURL GetMockHttpUrlForHostname(const std::string& hostname,
44 const std::string& data, 53 const std::string& data,
45 int repeat_count); 54 int repeat_count);
46 static GURL GetMockHttpsUrlForHostname(const std::string& hostname, 55 static GURL GetMockHttpsUrlForHostname(const std::string& hostname,
47 const std::string& data, 56 const std::string& data,
48 int repeat_count); 57 int repeat_count);
49 58
50 private: 59 private:
51 void GetResponseInfoConst(HttpResponseInfo* info) const; 60 void GetResponseInfoConst(HttpResponseInfo* info) const;
52 ~URLRequestMockDataJob() override; 61 ~URLRequestMockDataJob() override;
53 62
54 void StartAsync(); 63 void StartAsync();
55 64
56 std::string data_; 65 std::string data_;
57 size_t data_offset_; 66 size_t data_offset_;
67 bool request_client_certificate_;
58 base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_; 68 base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_;
59 }; 69 };
60 70
61 } // namespace net 71 } // namespace net
62 72
63 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ 73 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698