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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
9 | 10 |
10 #include "base/files/file.h" | 11 #include "base/files/file.h" |
11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 } | 444 } |
444 | 445 |
445 void SelectClientCertificate( | 446 void SelectClientCertificate( |
446 WebContents* web_contents, | 447 WebContents* web_contents, |
447 net::SSLCertRequestInfo* cert_request_info, | 448 net::SSLCertRequestInfo* cert_request_info, |
448 scoped_ptr<ClientCertificateDelegate> delegate) override { | 449 scoped_ptr<ClientCertificateDelegate> delegate) override { |
449 EXPECT_FALSE(delegate_.get()); | 450 EXPECT_FALSE(delegate_.get()); |
450 | 451 |
451 ++call_count_; | 452 ++call_count_; |
452 passed_certs_ = cert_request_info->client_certs; | 453 passed_certs_ = cert_request_info->client_certs; |
453 delegate_ = delegate.Pass(); | 454 delegate_ = std::move(delegate); |
454 select_certificate_run_loop_.Quit(); | 455 select_certificate_run_loop_.Quit(); |
455 } | 456 } |
456 | 457 |
457 int call_count() { return call_count_; } | 458 int call_count() { return call_count_; } |
458 net::CertificateList passed_certs() { return passed_certs_; } | 459 net::CertificateList passed_certs() { return passed_certs_; } |
459 | 460 |
460 void ContinueWithCertificate(net::X509Certificate* cert) { | 461 void ContinueWithCertificate(net::X509Certificate* cert) { |
461 delegate_->ContinueWithCertificate(cert); | 462 delegate_->ContinueWithCertificate(cert); |
462 delegate_.reset(); | 463 delegate_.reset(); |
463 } | 464 } |
464 | 465 |
465 void CancelCertificateSelection() { delegate_.reset(); } | 466 void CancelCertificateSelection() { delegate_.reset(); } |
466 | 467 |
467 private: | 468 private: |
468 net::CertificateList passed_certs_; | 469 net::CertificateList passed_certs_; |
469 int call_count_; | 470 int call_count_; |
470 scoped_ptr<ClientCertificateDelegate> delegate_; | 471 scoped_ptr<ClientCertificateDelegate> delegate_; |
471 | 472 |
472 base::RunLoop select_certificate_run_loop_; | 473 base::RunLoop select_certificate_run_loop_; |
473 | 474 |
474 DISALLOW_COPY_AND_ASSIGN(SelectCertificateBrowserClient); | 475 DISALLOW_COPY_AND_ASSIGN(SelectCertificateBrowserClient); |
475 }; | 476 }; |
476 | 477 |
477 class ResourceContextStub : public MockResourceContext { | 478 class ResourceContextStub : public MockResourceContext { |
478 public: | 479 public: |
479 explicit ResourceContextStub(net::URLRequestContext* test_request_context) | 480 explicit ResourceContextStub(net::URLRequestContext* test_request_context) |
480 : MockResourceContext(test_request_context) {} | 481 : MockResourceContext(test_request_context) {} |
481 | 482 |
482 scoped_ptr<net::ClientCertStore> CreateClientCertStore() override { | 483 scoped_ptr<net::ClientCertStore> CreateClientCertStore() override { |
483 return dummy_cert_store_.Pass(); | 484 return std::move(dummy_cert_store_); |
484 } | 485 } |
485 | 486 |
486 void SetClientCertStore(scoped_ptr<net::ClientCertStore> store) { | 487 void SetClientCertStore(scoped_ptr<net::ClientCertStore> store) { |
487 dummy_cert_store_ = store.Pass(); | 488 dummy_cert_store_ = std::move(store); |
488 } | 489 } |
489 | 490 |
490 private: | 491 private: |
491 scoped_ptr<net::ClientCertStore> dummy_cert_store_; | 492 scoped_ptr<net::ClientCertStore> dummy_cert_store_; |
492 }; | 493 }; |
493 | 494 |
494 // Wraps a ChunkedUploadDataStream to behave as non-chunked to enable upload | 495 // Wraps a ChunkedUploadDataStream to behave as non-chunked to enable upload |
495 // progress reporting. | 496 // progress reporting. |
496 class NonChunkedUploadDataStream : public net::UploadDataStream { | 497 class NonChunkedUploadDataStream : public net::UploadDataStream { |
497 public: | 498 public: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 555 } |
555 | 556 |
556 virtual scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | 557 virtual scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
557 CreateProtocolHandler() { | 558 CreateProtocolHandler() { |
558 return net::URLRequestTestJob::CreateProtocolHandler(); | 559 return net::URLRequestTestJob::CreateProtocolHandler(); |
559 } | 560 } |
560 | 561 |
561 virtual scoped_ptr<ResourceHandler> WrapResourceHandler( | 562 virtual scoped_ptr<ResourceHandler> WrapResourceHandler( |
562 scoped_ptr<ResourceHandlerStub> leaf_handler, | 563 scoped_ptr<ResourceHandlerStub> leaf_handler, |
563 net::URLRequest* request) { | 564 net::URLRequest* request) { |
564 return leaf_handler.Pass(); | 565 return std::move(leaf_handler); |
565 } | 566 } |
566 | 567 |
567 // Replaces loader_ with a new one for |request|. | 568 // Replaces loader_ with a new one for |request|. |
568 void SetUpResourceLoader(scoped_ptr<net::URLRequest> request) { | 569 void SetUpResourceLoader(scoped_ptr<net::URLRequest> request) { |
569 raw_ptr_to_request_ = request.get(); | 570 raw_ptr_to_request_ = request.get(); |
570 | 571 |
571 RenderFrameHost* rfh = web_contents_->GetMainFrame(); | 572 RenderFrameHost* rfh = web_contents_->GetMainFrame(); |
572 ResourceRequestInfo::AllocateForTesting( | 573 ResourceRequestInfo::AllocateForTesting( |
573 request.get(), RESOURCE_TYPE_MAIN_FRAME, &resource_context_, | 574 request.get(), RESOURCE_TYPE_MAIN_FRAME, &resource_context_, |
574 rfh->GetProcess()->GetID(), rfh->GetRenderViewHost()->GetRoutingID(), | 575 rfh->GetProcess()->GetID(), rfh->GetRenderViewHost()->GetRoutingID(), |
575 rfh->GetRoutingID(), true /* is_main_frame */, | 576 rfh->GetRoutingID(), true /* is_main_frame */, |
576 false /* parent_is_main_frame */, true /* allow_download */, | 577 false /* parent_is_main_frame */, true /* allow_download */, |
577 false /* is_async */, false /* is_using_lofi_ */); | 578 false /* is_async */, false /* is_using_lofi_ */); |
578 scoped_ptr<ResourceHandlerStub> resource_handler( | 579 scoped_ptr<ResourceHandlerStub> resource_handler( |
579 new ResourceHandlerStub(request.get())); | 580 new ResourceHandlerStub(request.get())); |
580 raw_ptr_resource_handler_ = resource_handler.get(); | 581 raw_ptr_resource_handler_ = resource_handler.get(); |
581 loader_.reset(new ResourceLoader( | 582 loader_.reset(new ResourceLoader( |
582 request.Pass(), | 583 std::move(request), |
583 WrapResourceHandler(resource_handler.Pass(), raw_ptr_to_request_), | 584 WrapResourceHandler(std::move(resource_handler), raw_ptr_to_request_), |
584 this)); | 585 this)); |
585 } | 586 } |
586 | 587 |
587 void SetUp() override { | 588 void SetUp() override { |
588 job_factory_.SetProtocolHandler("test", CreateProtocolHandler()); | 589 job_factory_.SetProtocolHandler("test", CreateProtocolHandler()); |
589 | 590 |
590 browser_context_.reset(new TestBrowserContext()); | 591 browser_context_.reset(new TestBrowserContext()); |
591 scoped_refptr<SiteInstance> site_instance = | 592 scoped_refptr<SiteInstance> site_instance = |
592 SiteInstance::Create(browser_context_.get()); | 593 SiteInstance::Create(browser_context_.get()); |
593 web_contents_.reset( | 594 web_contents_.reset( |
594 TestWebContents::Create(browser_context_.get(), site_instance.get())); | 595 TestWebContents::Create(browser_context_.get(), site_instance.get())); |
595 | 596 |
596 scoped_ptr<net::URLRequest> request( | 597 scoped_ptr<net::URLRequest> request( |
597 resource_context_.GetRequestContext()->CreateRequest( | 598 resource_context_.GetRequestContext()->CreateRequest( |
598 test_url(), | 599 test_url(), |
599 net::DEFAULT_PRIORITY, | 600 net::DEFAULT_PRIORITY, |
600 nullptr /* delegate */)); | 601 nullptr /* delegate */)); |
601 SetUpResourceLoader(request.Pass()); | 602 SetUpResourceLoader(std::move(request)); |
602 } | 603 } |
603 | 604 |
604 void TearDown() override { | 605 void TearDown() override { |
605 // Destroy the WebContents and pump the event loop before destroying | 606 // Destroy the WebContents and pump the event loop before destroying |
606 // |rvh_test_enabler_| and |thread_bundle_|. This lets asynchronous cleanup | 607 // |rvh_test_enabler_| and |thread_bundle_|. This lets asynchronous cleanup |
607 // tasks complete. | 608 // tasks complete. |
608 web_contents_.reset(); | 609 web_contents_.reset(); |
609 base::RunLoop().RunUntilIdle(); | 610 base::RunLoop().RunUntilIdle(); |
610 } | 611 } |
611 | 612 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 687 |
687 // Tests that client certificates are requested with ClientCertStore lookup. | 688 // Tests that client certificates are requested with ClientCertStore lookup. |
688 TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) { | 689 TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) { |
689 // Set up the test client cert store. | 690 // Set up the test client cert store. |
690 int store_request_count; | 691 int store_request_count; |
691 std::vector<std::string> store_requested_authorities; | 692 std::vector<std::string> store_requested_authorities; |
692 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( | 693 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( |
693 new net::X509Certificate("test", "test", base::Time(), base::Time()))); | 694 new net::X509Certificate("test", "test", base::Time(), base::Time()))); |
694 scoped_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub( | 695 scoped_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub( |
695 dummy_certs, &store_request_count, &store_requested_authorities)); | 696 dummy_certs, &store_request_count, &store_requested_authorities)); |
696 resource_context_.SetClientCertStore(test_store.Pass()); | 697 resource_context_.SetClientCertStore(std::move(test_store)); |
697 | 698 |
698 // Plug in test content browser client. | 699 // Plug in test content browser client. |
699 SelectCertificateBrowserClient test_client; | 700 SelectCertificateBrowserClient test_client; |
700 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); | 701 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); |
701 | 702 |
702 // Start the request and wait for it to pause. | 703 // Start the request and wait for it to pause. |
703 loader_->StartRequest(); | 704 loader_->StartRequest(); |
704 test_client.WaitForSelectCertificate(); | 705 test_client.WaitForSelectCertificate(); |
705 | 706 |
706 EXPECT_FALSE(raw_ptr_resource_handler_->received_response_completed()); | 707 EXPECT_FALSE(raw_ptr_resource_handler_->received_response_completed()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 887 |
887 // Make a temporary file. | 888 // Make a temporary file. |
888 CHECK(base::CreateTemporaryFile(&temp_path_)); | 889 CHECK(base::CreateTemporaryFile(&temp_path_)); |
889 int flags = base::File::FLAG_WRITE | base::File::FLAG_TEMPORARY | | 890 int flags = base::File::FLAG_WRITE | base::File::FLAG_TEMPORARY | |
890 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_ASYNC; | 891 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_ASYNC; |
891 base::File file(temp_path_, flags); | 892 base::File file(temp_path_, flags); |
892 CHECK(file.IsValid()); | 893 CHECK(file.IsValid()); |
893 | 894 |
894 // Create mock file streams and a ShareableFileReference. | 895 // Create mock file streams and a ShareableFileReference. |
895 scoped_ptr<net::testing::MockFileStream> file_stream( | 896 scoped_ptr<net::testing::MockFileStream> file_stream( |
896 new net::testing::MockFileStream(file.Pass(), | 897 new net::testing::MockFileStream(std::move(file), |
897 base::ThreadTaskRunnerHandle::Get())); | 898 base::ThreadTaskRunnerHandle::Get())); |
898 file_stream_ = file_stream.get(); | 899 file_stream_ = file_stream.get(); |
899 deletable_file_ = ShareableFileReference::GetOrCreate( | 900 deletable_file_ = ShareableFileReference::GetOrCreate( |
900 temp_path_, | 901 temp_path_, |
901 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 902 ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
902 BrowserThread::GetMessageLoopProxyForThread( | 903 BrowserThread::GetMessageLoopProxyForThread( |
903 BrowserThread::FILE).get()); | 904 BrowserThread::FILE).get()); |
904 | 905 |
905 // Inject them into the handler. | 906 // Inject them into the handler. |
906 scoped_ptr<RedirectToFileResourceHandler> handler( | 907 scoped_ptr<RedirectToFileResourceHandler> handler( |
907 new RedirectToFileResourceHandler(leaf_handler.Pass(), request)); | 908 new RedirectToFileResourceHandler(std::move(leaf_handler), request)); |
908 redirect_to_file_resource_handler_ = handler.get(); | 909 redirect_to_file_resource_handler_ = handler.get(); |
909 handler->SetCreateTemporaryFileStreamFunctionForTesting( | 910 handler->SetCreateTemporaryFileStreamFunctionForTesting( |
910 base::Bind(&ResourceLoaderRedirectToFileTest::PostCallback, | 911 base::Bind(&ResourceLoaderRedirectToFileTest::PostCallback, |
911 base::Unretained(this), | 912 base::Unretained(this), |
912 base::Passed(&file_stream))); | 913 base::Passed(&file_stream))); |
913 return handler.Pass(); | 914 return std::move(handler); |
914 } | 915 } |
915 | 916 |
916 private: | 917 private: |
917 void PostCallback( | 918 void PostCallback( |
918 scoped_ptr<net::FileStream> file_stream, | 919 scoped_ptr<net::FileStream> file_stream, |
919 const CreateTemporaryFileStreamCallback& callback) { | 920 const CreateTemporaryFileStreamCallback& callback) { |
920 base::ThreadTaskRunnerHandle::Get()->PostTask( | 921 base::ThreadTaskRunnerHandle::Get()->PostTask( |
921 FROM_HERE, base::Bind(callback, base::File::FILE_OK, | 922 FROM_HERE, base::Bind(callback, base::File::FILE_OK, |
922 base::Passed(&file_stream), deletable_file_)); | 923 base::Passed(&file_stream), deletable_file_)); |
923 } | 924 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 EXPECT_EQ(test_data(), contents); | 1075 EXPECT_EQ(test_data(), contents); |
1075 } | 1076 } |
1076 | 1077 |
1077 // Test that an HTTPS resource has the expected security info attached | 1078 // Test that an HTTPS resource has the expected security info attached |
1078 // to it. | 1079 // to it. |
1079 TEST_F(HTTPSSecurityInfoResourceLoaderTest, SecurityInfoOnHTTPSResource) { | 1080 TEST_F(HTTPSSecurityInfoResourceLoaderTest, SecurityInfoOnHTTPSResource) { |
1080 // Start the request and wait for it to finish. | 1081 // Start the request and wait for it to finish. |
1081 scoped_ptr<net::URLRequest> request( | 1082 scoped_ptr<net::URLRequest> request( |
1082 resource_context_.GetRequestContext()->CreateRequest( | 1083 resource_context_.GetRequestContext()->CreateRequest( |
1083 test_https_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); | 1084 test_https_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); |
1084 SetUpResourceLoader(request.Pass()); | 1085 SetUpResourceLoader(std::move(request)); |
1085 | 1086 |
1086 // Send the request and wait until it completes. | 1087 // Send the request and wait until it completes. |
1087 loader_->StartRequest(); | 1088 loader_->StartRequest(); |
1088 raw_ptr_resource_handler_->WaitForResponseComplete(); | 1089 raw_ptr_resource_handler_->WaitForResponseComplete(); |
1089 ASSERT_EQ(net::URLRequestStatus::SUCCESS, | 1090 ASSERT_EQ(net::URLRequestStatus::SUCCESS, |
1090 raw_ptr_to_request_->status().status()); | 1091 raw_ptr_to_request_->status().status()); |
1091 | 1092 |
1092 ResourceResponse* response = raw_ptr_resource_handler_->response(); | 1093 ResourceResponse* response = raw_ptr_resource_handler_->response(); |
1093 ASSERT_TRUE(response); | 1094 ASSERT_TRUE(response); |
1094 | 1095 |
(...skipping 18 matching lines...) Expand all Loading... |
1113 | 1114 |
1114 // Test that an HTTPS redirect response has the expected security info | 1115 // Test that an HTTPS redirect response has the expected security info |
1115 // attached to it. | 1116 // attached to it. |
1116 TEST_F(HTTPSSecurityInfoResourceLoaderTest, | 1117 TEST_F(HTTPSSecurityInfoResourceLoaderTest, |
1117 SecurityInfoOnHTTPSRedirectResource) { | 1118 SecurityInfoOnHTTPSRedirectResource) { |
1118 // Start the request and wait for it to finish. | 1119 // Start the request and wait for it to finish. |
1119 scoped_ptr<net::URLRequest> request( | 1120 scoped_ptr<net::URLRequest> request( |
1120 resource_context_.GetRequestContext()->CreateRequest( | 1121 resource_context_.GetRequestContext()->CreateRequest( |
1121 test_https_redirect_url(), net::DEFAULT_PRIORITY, | 1122 test_https_redirect_url(), net::DEFAULT_PRIORITY, |
1122 nullptr /* delegate */)); | 1123 nullptr /* delegate */)); |
1123 SetUpResourceLoader(request.Pass()); | 1124 SetUpResourceLoader(std::move(request)); |
1124 | 1125 |
1125 // Send the request and wait until it completes. | 1126 // Send the request and wait until it completes. |
1126 loader_->StartRequest(); | 1127 loader_->StartRequest(); |
1127 raw_ptr_resource_handler_->WaitForResponseComplete(); | 1128 raw_ptr_resource_handler_->WaitForResponseComplete(); |
1128 ASSERT_EQ(net::URLRequestStatus::SUCCESS, | 1129 ASSERT_EQ(net::URLRequestStatus::SUCCESS, |
1129 raw_ptr_to_request_->status().status()); | 1130 raw_ptr_to_request_->status().status()); |
1130 ASSERT_TRUE(raw_ptr_resource_handler_->received_request_redirected()); | 1131 ASSERT_TRUE(raw_ptr_resource_handler_->received_request_redirected()); |
1131 | 1132 |
1132 ResourceResponse* redirect_response = | 1133 ResourceResponse* redirect_response = |
1133 raw_ptr_resource_handler_->redirect_response(); | 1134 raw_ptr_resource_handler_->redirect_response(); |
(...skipping 12 matching lines...) Expand all Loading... |
1146 ASSERT_TRUE( | 1147 ASSERT_TRUE( |
1147 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert)); | 1148 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert)); |
1148 EXPECT_TRUE(cert->Equals(GetTestCert().get())); | 1149 EXPECT_TRUE(cert->Equals(GetTestCert().get())); |
1149 | 1150 |
1150 EXPECT_EQ(kTestCertError, deserialized.cert_status); | 1151 EXPECT_EQ(kTestCertError, deserialized.cert_status); |
1151 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status); | 1152 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status); |
1152 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits); | 1153 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits); |
1153 } | 1154 } |
1154 | 1155 |
1155 } // namespace content | 1156 } // namespace content |
OLD | NEW |