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

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 42773002: Get ClientCertStore through ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win #2 Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/loader/resource_loader_delegate.h" 9 #include "content/browser/loader/resource_loader_delegate.h"
10 #include "content/public/browser/resource_request_info.h" 10 #include "content/public/browser/resource_request_info.h"
(...skipping 30 matching lines...) Expand all
41 std::vector<std::string> requested_authorities() { 41 std::vector<std::string> requested_authorities() {
42 return requested_authorities_; 42 return requested_authorities_;
43 } 43 }
44 44
45 // Returns the number of calls to GetClientCerts(). 45 // Returns the number of calls to GetClientCerts().
46 int request_count() { 46 int request_count() {
47 return request_count_; 47 return request_count_;
48 } 48 }
49 49
50 // net::ClientCertStore: 50 // net::ClientCertStore:
51 virtual bool GetClientCerts(const net::SSLCertRequestInfo& cert_request_info, 51 virtual void GetClientCerts(const net::SSLCertRequestInfo& cert_request_info,
52 net::CertificateList* selected_certs) OVERRIDE { 52 net::CertificateList* selected_certs,
53 const base::Closure& callback) OVERRIDE {
53 ++request_count_; 54 ++request_count_;
54 requested_authorities_ = cert_request_info.cert_authorities; 55 requested_authorities_ = cert_request_info.cert_authorities;
55 *selected_certs = response_; 56 *selected_certs = response_;
56 return true; 57 callback.Run();
57 } 58 }
58 59
59 private: 60 private:
60 const net::CertificateList response_; 61 const net::CertificateList response_;
61 int request_count_; 62 int request_count_;
62 std::vector<std::string> requested_authorities_; 63 std::vector<std::string> requested_authorities_;
63 }; 64 };
64 65
65 // Dummy implementation of ResourceHandler, instance of which is needed to 66 // Dummy implementation of ResourceHandler, instance of which is needed to
66 // initialize ResourceLoader. 67 // initialize ResourceLoader.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 113
113 virtual void OnDataDownloaded(int request_id, 114 virtual void OnDataDownloaded(int request_id,
114 int bytes_downloaded) OVERRIDE {} 115 int bytes_downloaded) OVERRIDE {}
115 }; 116 };
116 117
117 // Test browser client that captures calls to SelectClientCertificates and 118 // Test browser client that captures calls to SelectClientCertificates and
118 // records the arguments of the most recent call for later inspection. 119 // records the arguments of the most recent call for later inspection.
119 class SelectCertificateBrowserClient : public TestContentBrowserClient { 120 class SelectCertificateBrowserClient : public TestContentBrowserClient {
120 public: 121 public:
121 SelectCertificateBrowserClient() : call_count_(0) {} 122 SelectCertificateBrowserClient(
123 scoped_ptr<net::ClientCertStore> dummy_cert_store)
124 : dummy_cert_store_(dummy_cert_store.Pass()), call_count_(0) {}
125
126 virtual scoped_ptr<net::ClientCertStore> GetClientCertStore(
127 content::ResourceContext* context) OVERRIDE {
128 return dummy_cert_store_.Pass();
129 }
122 130
123 virtual void SelectClientCertificate( 131 virtual void SelectClientCertificate(
124 int render_process_id, 132 int render_process_id,
125 int render_view_id, 133 int render_view_id,
126 const net::HttpNetworkSession* network_session, 134 const net::HttpNetworkSession* network_session,
127 net::SSLCertRequestInfo* cert_request_info, 135 net::SSLCertRequestInfo* cert_request_info,
128 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE { 136 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE {
129 ++call_count_; 137 ++call_count_;
130 passed_certs_ = cert_request_info->client_certs; 138 passed_certs_ = cert_request_info->client_certs;
131 } 139 }
132 140
133 int call_count() { 141 int call_count() {
134 return call_count_; 142 return call_count_;
135 } 143 }
136 144
137 net::CertificateList passed_certs() { 145 net::CertificateList passed_certs() {
138 return passed_certs_; 146 return passed_certs_;
139 } 147 }
140 148
141 private: 149 private:
150 scoped_ptr<net::ClientCertStore> dummy_cert_store_;
142 net::CertificateList passed_certs_; 151 net::CertificateList passed_certs_;
143 int call_count_; 152 int call_count_;
144 }; 153 };
145 154
146 } // namespace 155 } // namespace
147 156
148 class ResourceLoaderTest : public testing::Test, 157 class ResourceLoaderTest : public testing::Test,
149 public ResourceLoaderDelegate { 158 public ResourceLoaderDelegate {
150 protected: 159 protected:
151 ResourceLoaderTest() 160 ResourceLoaderTest()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 new ClientCertStoreStub(dummy_certs)); 222 new ClientCertStoreStub(dummy_certs));
214 EXPECT_EQ(0, test_store->request_count()); 223 EXPECT_EQ(0, test_store->request_count());
215 224
216 // Ownership of the |request| and |test_store| is about to be turned over to 225 // Ownership of the |request| and |test_store| is about to be turned over to
217 // ResourceLoader. We need to keep raw pointer copies to access these objects 226 // ResourceLoader. We need to keep raw pointer copies to access these objects
218 // later. 227 // later.
219 net::URLRequest* raw_ptr_to_request = request.get(); 228 net::URLRequest* raw_ptr_to_request = request.get();
220 ClientCertStoreStub* raw_ptr_to_store = test_store.get(); 229 ClientCertStoreStub* raw_ptr_to_store = test_store.get();
221 230
222 scoped_ptr<ResourceHandler> resource_handler(new ResourceHandlerStub()); 231 scoped_ptr<ResourceHandler> resource_handler(new ResourceHandlerStub());
223 ResourceLoader loader(request.Pass(), resource_handler.Pass(), this, 232 ResourceLoader loader(request.Pass(), resource_handler.Pass(), this);
224 test_store.PassAs<net::ClientCertStore>());
225 233
226 // Prepare a dummy certificate request. 234 // Prepare a dummy certificate request.
227 scoped_refptr<net::SSLCertRequestInfo> cert_request_info( 235 scoped_refptr<net::SSLCertRequestInfo> cert_request_info(
228 new net::SSLCertRequestInfo()); 236 new net::SSLCertRequestInfo());
229 std::vector<std::string> dummy_authority(1, "dummy"); 237 std::vector<std::string> dummy_authority(1, "dummy");
230 cert_request_info->cert_authorities = dummy_authority; 238 cert_request_info->cert_authorities = dummy_authority;
231 239
232 // Plug in test content browser client. 240 // Plug in test content browser client.
233 SelectCertificateBrowserClient test_client; 241 SelectCertificateBrowserClient test_client(
242 test_store.PassAs<net::ClientCertStore>());
234 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); 243 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client);
235 244
236 // Everything is set up. Trigger the resource loader certificate request event 245 // Everything is set up. Trigger the resource loader certificate request event
237 // and run the message loop. 246 // and run the message loop.
238 loader.OnCertificateRequested(raw_ptr_to_request, cert_request_info.get()); 247 loader.OnCertificateRequested(raw_ptr_to_request, cert_request_info.get());
239 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
240 249
241 // Restore the original content browser client. 250 // Restore the original content browser client.
242 SetBrowserClientForTesting(old_client); 251 SetBrowserClientForTesting(old_client);
243 252
244 // Check if the test store was queried against correct |cert_authorities|. 253 // Check if the test store was queried against correct |cert_authorities|.
245 EXPECT_EQ(1, raw_ptr_to_store->request_count()); 254 EXPECT_EQ(1, raw_ptr_to_store->request_count());
246 EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities()); 255 EXPECT_EQ(dummy_authority, raw_ptr_to_store->requested_authorities());
247 256
248 // Check if the retrieved certificates were passed to the content browser 257 // Check if the retrieved certificates were passed to the content browser
249 // client. 258 // client.
250 EXPECT_EQ(1, test_client.call_count()); 259 EXPECT_EQ(1, test_client.call_count());
251 EXPECT_EQ(dummy_certs, test_client.passed_certs()); 260 EXPECT_EQ(dummy_certs, test_client.passed_certs());
252 } 261 }
253 #endif // !defined(OPENSSL) 262 #endif // !defined(OPENSSL)
254 263
255 } // namespace content 264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698