| OLD | NEW |
| 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" |
| 11 #include "content/public/test/mock_resource_context.h" | 11 #include "content/public/test/mock_resource_context.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "content/test/test_content_browser_client.h" | 13 #include "content/test/test_content_browser_client.h" |
| 14 #include "net/base/request_priority.h" |
| 14 #include "net/cert/x509_certificate.h" | 15 #include "net/cert/x509_certificate.h" |
| 15 #include "net/ssl/client_cert_store.h" | 16 #include "net/ssl/client_cert_store.h" |
| 16 #include "net/ssl/ssl_cert_request_info.h" | 17 #include "net/ssl/ssl_cert_request_info.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 }; | 205 }; |
| 205 | 206 |
| 206 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested() | 207 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested() |
| 207 // causes client cert store to be queried for certificates and if the returned | 208 // causes client cert store to be queried for certificates and if the returned |
| 208 // certificates are correctly passed to the content browser client for | 209 // certificates are correctly passed to the content browser client for |
| 209 // selection. | 210 // selection. |
| 210 TEST_F(ResourceLoaderTest, ClientCertStoreLookup) { | 211 TEST_F(ResourceLoaderTest, ClientCertStoreLookup) { |
| 211 const int kRenderProcessId = 1; | 212 const int kRenderProcessId = 1; |
| 212 const int kRenderViewId = 2; | 213 const int kRenderViewId = 2; |
| 213 | 214 |
| 214 scoped_ptr<net::URLRequest> request(new net::URLRequest( | 215 scoped_ptr<net::URLRequest> request( |
| 215 GURL("dummy"), NULL, | 216 new net::URLRequest(GURL("dummy"), |
| 216 resource_context_.GetRequestContext())); | 217 net::DEFAULT_PRIORITY, |
| 218 NULL, |
| 219 resource_context_.GetRequestContext())); |
| 217 ResourceRequestInfo::AllocateForTesting(request.get(), | 220 ResourceRequestInfo::AllocateForTesting(request.get(), |
| 218 ResourceType::MAIN_FRAME, | 221 ResourceType::MAIN_FRAME, |
| 219 &resource_context_, | 222 &resource_context_, |
| 220 kRenderProcessId, | 223 kRenderProcessId, |
| 221 kRenderViewId, | 224 kRenderViewId, |
| 222 false); | 225 false); |
| 223 | 226 |
| 224 // Set up the test client cert store. | 227 // Set up the test client cert store. |
| 225 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( | 228 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( |
| 226 new net::X509Certificate("test", "test", base::Time(), base::Time()))); | 229 new net::X509Certificate("test", "test", base::Time(), base::Time()))); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 EXPECT_EQ(dummy_certs, test_client.passed_certs()); | 270 EXPECT_EQ(dummy_certs, test_client.passed_certs()); |
| 268 } | 271 } |
| 269 | 272 |
| 270 // Verifies if a call to net::URLRequest::Delegate::OnCertificateRequested() | 273 // Verifies if a call to net::URLRequest::Delegate::OnCertificateRequested() |
| 271 // on a platform with a NULL client cert store still calls the content browser | 274 // on a platform with a NULL client cert store still calls the content browser |
| 272 // client for selection. | 275 // client for selection. |
| 273 TEST_F(ResourceLoaderTest, ClientCertStoreNull) { | 276 TEST_F(ResourceLoaderTest, ClientCertStoreNull) { |
| 274 const int kRenderProcessId = 1; | 277 const int kRenderProcessId = 1; |
| 275 const int kRenderViewId = 2; | 278 const int kRenderViewId = 2; |
| 276 | 279 |
| 277 scoped_ptr<net::URLRequest> request(new net::URLRequest( | 280 scoped_ptr<net::URLRequest> request( |
| 278 GURL("dummy"), NULL, resource_context_.GetRequestContext())); | 281 new net::URLRequest(GURL("dummy"), |
| 282 net::DEFAULT_PRIORITY, |
| 283 NULL, |
| 284 resource_context_.GetRequestContext())); |
| 279 ResourceRequestInfo::AllocateForTesting(request.get(), | 285 ResourceRequestInfo::AllocateForTesting(request.get(), |
| 280 ResourceType::MAIN_FRAME, | 286 ResourceType::MAIN_FRAME, |
| 281 &resource_context_, | 287 &resource_context_, |
| 282 kRenderProcessId, | 288 kRenderProcessId, |
| 283 kRenderViewId, | 289 kRenderViewId, |
| 284 false); | 290 false); |
| 285 | 291 |
| 286 // Ownership of the |request| is about to be turned over to ResourceLoader. We | 292 // Ownership of the |request| is about to be turned over to ResourceLoader. We |
| 287 // need to keep a raw pointer copy to access this object later. | 293 // need to keep a raw pointer copy to access this object later. |
| 288 net::URLRequest* raw_ptr_to_request = request.get(); | 294 net::URLRequest* raw_ptr_to_request = request.get(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 308 // Restore the original content browser client. | 314 // Restore the original content browser client. |
| 309 SetBrowserClientForTesting(old_client); | 315 SetBrowserClientForTesting(old_client); |
| 310 | 316 |
| 311 // Check if the SelectClientCertificate was called on the content browser | 317 // Check if the SelectClientCertificate was called on the content browser |
| 312 // client. | 318 // client. |
| 313 EXPECT_EQ(1, test_client.call_count()); | 319 EXPECT_EQ(1, test_client.call_count()); |
| 314 EXPECT_EQ(net::CertificateList(), test_client.passed_certs()); | 320 EXPECT_EQ(net::CertificateList(), test_client.passed_certs()); |
| 315 } | 321 } |
| 316 | 322 |
| 317 } // namespace content | 323 } // namespace content |
| OLD | NEW |