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

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

Issue 2088763004: Remove resource_context.h include from resource_loader.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 6 months 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 (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 9
10 #include <memory> 10 #include <memory>
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 private: 482 private:
483 net::CertificateList passed_certs_; 483 net::CertificateList passed_certs_;
484 int call_count_; 484 int call_count_;
485 std::unique_ptr<ClientCertificateDelegate> delegate_; 485 std::unique_ptr<ClientCertificateDelegate> delegate_;
486 486
487 base::RunLoop select_certificate_run_loop_; 487 base::RunLoop select_certificate_run_loop_;
488 488
489 DISALLOW_COPY_AND_ASSIGN(SelectCertificateBrowserClient); 489 DISALLOW_COPY_AND_ASSIGN(SelectCertificateBrowserClient);
490 }; 490 };
491 491
492 class ResourceContextStub : public MockResourceContext {
493 public:
494 explicit ResourceContextStub(net::URLRequestContext* test_request_context)
495 : MockResourceContext(test_request_context) {}
496
497 std::unique_ptr<net::ClientCertStore> CreateClientCertStore() override {
498 return std::move(dummy_cert_store_);
499 }
500
501 void SetClientCertStore(std::unique_ptr<net::ClientCertStore> store) {
502 dummy_cert_store_ = std::move(store);
503 }
504
505 private:
506 std::unique_ptr<net::ClientCertStore> dummy_cert_store_;
507 };
508
509 // Wraps a ChunkedUploadDataStream to behave as non-chunked to enable upload 492 // Wraps a ChunkedUploadDataStream to behave as non-chunked to enable upload
510 // progress reporting. 493 // progress reporting.
511 class NonChunkedUploadDataStream : public net::UploadDataStream { 494 class NonChunkedUploadDataStream : public net::UploadDataStream {
512 public: 495 public:
513 explicit NonChunkedUploadDataStream(uint64_t size) 496 explicit NonChunkedUploadDataStream(uint64_t size)
514 : net::UploadDataStream(false, 0), stream_(0), size_(size) {} 497 : net::UploadDataStream(false, 0), stream_(0), size_(size) {}
515 498
516 void AppendData(const char* data) { 499 void AppendData(const char* data) {
517 stream_.AppendData(data, strlen(data), false); 500 stream_.AppendData(data, strlen(data), false);
518 } 501 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 635 }
653 636
654 void TearDown() override { 637 void TearDown() override {
655 // Destroy the WebContents and pump the event loop before destroying 638 // Destroy the WebContents and pump the event loop before destroying
656 // |rvh_test_enabler_| and |thread_bundle_|. This lets asynchronous cleanup 639 // |rvh_test_enabler_| and |thread_bundle_|. This lets asynchronous cleanup
657 // tasks complete. 640 // tasks complete.
658 web_contents_.reset(); 641 web_contents_.reset();
659 base::RunLoop().RunUntilIdle(); 642 base::RunLoop().RunUntilIdle();
660 } 643 }
661 644
645 void SetClientCertStore(std::unique_ptr<net::ClientCertStore> store) {
646 dummy_cert_store_ = std::move(store);
647 }
648
662 // ResourceLoaderDelegate: 649 // ResourceLoaderDelegate:
663 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 650 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
664 ResourceLoader* loader, 651 ResourceLoader* loader,
665 net::AuthChallengeInfo* auth_info) override { 652 net::AuthChallengeInfo* auth_info) override {
666 return NULL; 653 return NULL;
667 } 654 }
668 bool HandleExternalProtocol(ResourceLoader* loader, 655 bool HandleExternalProtocol(ResourceLoader* loader,
669 const GURL& url) override { 656 const GURL& url) override {
670 return false; 657 return false;
671 } 658 }
672 void DidStartRequest(ResourceLoader* loader) override {} 659 void DidStartRequest(ResourceLoader* loader) override {}
673 void DidReceiveRedirect(ResourceLoader* loader, 660 void DidReceiveRedirect(ResourceLoader* loader,
674 const GURL& new_url) override {} 661 const GURL& new_url) override {}
675 void DidReceiveResponse(ResourceLoader* loader) override {} 662 void DidReceiveResponse(ResourceLoader* loader) override {}
676 void DidFinishLoading(ResourceLoader* loader) override {} 663 void DidFinishLoading(ResourceLoader* loader) override {}
664 std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
665 ResourceLoader* loader) override {
666 return std::move(dummy_cert_store_);
667 }
677 668
678 TestBrowserThreadBundle thread_bundle_; 669 TestBrowserThreadBundle thread_bundle_;
679 RenderViewHostTestEnabler rvh_test_enabler_; 670 RenderViewHostTestEnabler rvh_test_enabler_;
680 671
681 net::URLRequestJobFactoryImpl job_factory_; 672 net::URLRequestJobFactoryImpl job_factory_;
682 TestNetworkQualityEstimator network_quality_estimator_; 673 TestNetworkQualityEstimator network_quality_estimator_;
683 net::TestURLRequestContext test_url_request_context_; 674 net::TestURLRequestContext test_url_request_context_;
684 ResourceContextStub resource_context_; 675 MockResourceContext resource_context_;
685 std::unique_ptr<TestBrowserContext> browser_context_; 676 std::unique_ptr<TestBrowserContext> browser_context_;
686 std::unique_ptr<TestWebContents> web_contents_; 677 std::unique_ptr<TestWebContents> web_contents_;
678 std::unique_ptr<net::ClientCertStore> dummy_cert_store_;
687 679
688 // The ResourceLoader owns the URLRequest and the ResourceHandler. 680 // The ResourceLoader owns the URLRequest and the ResourceHandler.
689 ResourceHandlerStub* raw_ptr_resource_handler_; 681 ResourceHandlerStub* raw_ptr_resource_handler_;
690 net::URLRequest* raw_ptr_to_request_; 682 net::URLRequest* raw_ptr_to_request_;
691 std::unique_ptr<ResourceLoader> loader_; 683 std::unique_ptr<ResourceLoader> loader_;
692 }; 684 };
693 685
694 class ClientCertResourceLoaderTest : public ResourceLoaderTest { 686 class ClientCertResourceLoaderTest : public ResourceLoaderTest {
695 protected: 687 protected:
696 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> 688 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 729
738 // Tests that client certificates are requested with ClientCertStore lookup. 730 // Tests that client certificates are requested with ClientCertStore lookup.
739 TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) { 731 TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) {
740 // Set up the test client cert store. 732 // Set up the test client cert store.
741 int store_request_count; 733 int store_request_count;
742 std::vector<std::string> store_requested_authorities; 734 std::vector<std::string> store_requested_authorities;
743 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>( 735 net::CertificateList dummy_certs(1, scoped_refptr<net::X509Certificate>(
744 new net::X509Certificate("test", "test", base::Time(), base::Time()))); 736 new net::X509Certificate("test", "test", base::Time(), base::Time())));
745 std::unique_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub( 737 std::unique_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub(
746 dummy_certs, &store_request_count, &store_requested_authorities)); 738 dummy_certs, &store_request_count, &store_requested_authorities));
747 resource_context_.SetClientCertStore(std::move(test_store)); 739 SetClientCertStore(std::move(test_store));
748 740
749 // Plug in test content browser client. 741 // Plug in test content browser client.
750 SelectCertificateBrowserClient test_client; 742 SelectCertificateBrowserClient test_client;
751 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); 743 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client);
752 744
753 // Start the request and wait for it to pause. 745 // Start the request and wait for it to pause.
754 loader_->StartRequest(); 746 loader_->StartRequest();
755 test_client.WaitForSelectCertificate(); 747 test_client.WaitForSelectCertificate();
756 748
757 EXPECT_FALSE(raw_ptr_resource_handler_->received_response_completed()); 749 EXPECT_FALSE(raw_ptr_resource_handler_->received_response_completed());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 SetBrowserClientForTesting(old_client); 839 SetBrowserClientForTesting(old_client);
848 } 840 }
849 841
850 // Verifies that ClientCertStore's callback doesn't crash if called after the 842 // Verifies that ClientCertStore's callback doesn't crash if called after the
851 // loader is destroyed. 843 // loader is destroyed.
852 TEST_F(ClientCertResourceLoaderTest, StoreAsyncCancel) { 844 TEST_F(ClientCertResourceLoaderTest, StoreAsyncCancel) {
853 base::RunLoop loader_destroyed_run_loop; 845 base::RunLoop loader_destroyed_run_loop;
854 LoaderDestroyingCertStore* test_store = 846 LoaderDestroyingCertStore* test_store =
855 new LoaderDestroyingCertStore(&loader_, 847 new LoaderDestroyingCertStore(&loader_,
856 loader_destroyed_run_loop.QuitClosure()); 848 loader_destroyed_run_loop.QuitClosure());
857 resource_context_.SetClientCertStore(base::WrapUnique(test_store)); 849 SetClientCertStore(base::WrapUnique(test_store));
858 850
859 loader_->StartRequest(); 851 loader_->StartRequest();
860 loader_destroyed_run_loop.Run(); 852 loader_destroyed_run_loop.Run();
861 EXPECT_FALSE(loader_); 853 EXPECT_FALSE(loader_);
862 854
863 // Pump the event loop to ensure nothing asynchronous crashes either. 855 // Pump the event loop to ensure nothing asynchronous crashes either.
864 base::RunLoop().RunUntilIdle(); 856 base::RunLoop().RunUntilIdle();
865 } 857 }
866 858
867 TEST_F(ResourceLoaderTest, ResumeCancelledRequest) { 859 TEST_F(ResourceLoaderTest, ResumeCancelledRequest) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 1235
1244 // Tests that the effective connection type is not set on non-main frame 1236 // Tests that the effective connection type is not set on non-main frame
1245 // requests. 1237 // requests.
1246 TEST_F(EffectiveConnectionTypeResourceLoaderTest, NotAMainFrame) { 1238 TEST_F(EffectiveConnectionTypeResourceLoaderTest, NotAMainFrame) {
1247 VerifyEffectiveConnectionType( 1239 VerifyEffectiveConnectionType(
1248 false, net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G, 1240 false, net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G,
1249 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); 1241 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1250 } 1242 }
1251 1243
1252 } // namespace content 1244 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_loader_delegate.h ('k') | content/browser/resource_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698