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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2602243002: Use TaskScheduler instead of WorkerPool in multi_threaded_cert_verifier.cc. (Closed)
Patch Set: self-review Created 3 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 25 matching lines...) Expand all
36 #include "base/power_monitor/power_monitor_source.h" 36 #include "base/power_monitor/power_monitor_source.h"
37 #include "base/run_loop.h" 37 #include "base/run_loop.h"
38 #include "base/single_thread_task_runner.h" 38 #include "base/single_thread_task_runner.h"
39 #include "base/strings/string_number_conversions.h" 39 #include "base/strings/string_number_conversions.h"
40 #include "base/strings/string_piece.h" 40 #include "base/strings/string_piece.h"
41 #include "base/strings/string_split.h" 41 #include "base/strings/string_split.h"
42 #include "base/strings/string_util.h" 42 #include "base/strings/string_util.h"
43 #include "base/strings/stringprintf.h" 43 #include "base/strings/stringprintf.h"
44 #include "base/strings/utf_string_conversions.h" 44 #include "base/strings/utf_string_conversions.h"
45 #include "base/test/histogram_tester.h" 45 #include "base/test/histogram_tester.h"
46 #include "base/test/scoped_async_task_scheduler.h"
46 #include "base/test/scoped_task_scheduler.h" 47 #include "base/test/scoped_task_scheduler.h"
47 #include "base/threading/thread_task_runner_handle.h" 48 #include "base/threading/thread_task_runner_handle.h"
48 #include "base/values.h" 49 #include "base/values.h"
49 #include "net/base/chunked_upload_data_stream.h" 50 #include "net/base/chunked_upload_data_stream.h"
50 #include "net/base/directory_listing.h" 51 #include "net/base/directory_listing.h"
51 #include "net/base/elements_upload_data_stream.h" 52 #include "net/base/elements_upload_data_stream.h"
52 #include "net/base/load_flags.h" 53 #include "net/base/load_flags.h"
53 #include "net/base/load_timing_info.h" 54 #include "net/base/load_timing_info.h"
54 #include "net/base/load_timing_info_test_util.h" 55 #include "net/base/load_timing_info_test_util.h"
55 #include "net/base/net_errors.h" 56 #include "net/base/net_errors.h"
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 private: 765 private:
765 bool on_ssl_certificate_error_called_ = false; 766 bool on_ssl_certificate_error_called_ = false;
766 SSLInfo ssl_info_; 767 SSLInfo ssl_info_;
767 }; 768 };
768 769
769 } // namespace 770 } // namespace
770 771
771 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 772 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
772 class URLRequestTest : public PlatformTest { 773 class URLRequestTest : public PlatformTest {
773 public: 774 public:
774 URLRequestTest() : default_context_(true) { 775 URLRequestTest()
776 : scoped_task_scheduler_(base::MessageLoop::current()),
777 default_context_(true) {
775 default_context_.set_network_delegate(&default_network_delegate_); 778 default_context_.set_network_delegate(&default_network_delegate_);
776 default_context_.set_net_log(&net_log_); 779 default_context_.set_net_log(&net_log_);
777 job_factory_impl_ = new URLRequestJobFactoryImpl(); 780 job_factory_impl_ = new URLRequestJobFactoryImpl();
778 job_factory_.reset(job_factory_impl_); 781 job_factory_.reset(job_factory_impl_);
779 } 782 }
780 783
781 ~URLRequestTest() override { 784 ~URLRequestTest() override {
782 // URLRequestJobs may post clean-up tasks on destruction. 785 // URLRequestJobs may post clean-up tasks on destruction.
783 base::RunLoop().RunUntilIdle(); 786 base::RunLoop().RunUntilIdle();
784 } 787 }
(...skipping 27 matching lines...) Expand all
812 // Adds the TestJobInterceptor to the default context. 815 // Adds the TestJobInterceptor to the default context.
813 TestJobInterceptor* AddTestInterceptor() { 816 TestJobInterceptor* AddTestInterceptor() {
814 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); 817 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
815 job_factory_impl_->SetProtocolHandler("http", nullptr); 818 job_factory_impl_->SetProtocolHandler("http", nullptr);
816 job_factory_impl_->SetProtocolHandler("http", 819 job_factory_impl_->SetProtocolHandler("http",
817 base::WrapUnique(protocol_handler_)); 820 base::WrapUnique(protocol_handler_));
818 return protocol_handler_; 821 return protocol_handler_;
819 } 822 }
820 823
821 protected: 824 protected:
825 // Required by ChannelIDService and MultiThreadedCertVerifier.
826 base::test::ScopedTaskScheduler scoped_task_scheduler_;
822 TestNetLog net_log_; 827 TestNetLog net_log_;
823 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 828 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
824 URLRequestJobFactoryImpl* job_factory_impl_; 829 URLRequestJobFactoryImpl* job_factory_impl_;
825 std::unique_ptr<URLRequestJobFactory> job_factory_; 830 std::unique_ptr<URLRequestJobFactory> job_factory_;
826 TestURLRequestContext default_context_; 831 TestURLRequestContext default_context_;
827 }; 832 };
828 833
829 TEST_F(URLRequestTest, AboutBlankTest) { 834 TEST_F(URLRequestTest, AboutBlankTest) {
830 TestDelegate d; 835 TestDelegate d;
831 { 836 {
(...skipping 2605 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 const bool online_rev_checking_; 3442 const bool online_rev_checking_;
3438 const bool rev_checking_required_local_anchors_; 3443 const bool rev_checking_required_local_anchors_;
3439 const bool token_binding_enabled_; 3444 const bool token_binding_enabled_;
3440 uint16_t min_version_; 3445 uint16_t min_version_;
3441 }; 3446 };
3442 3447
3443 // TODO(svaldez): Update tests to use EmbeddedTestServer. 3448 // TODO(svaldez): Update tests to use EmbeddedTestServer.
3444 #if !defined(OS_IOS) 3449 #if !defined(OS_IOS)
3445 class TokenBindingURLRequestTest : public URLRequestTestHTTP { 3450 class TokenBindingURLRequestTest : public URLRequestTestHTTP {
3446 public: 3451 public:
3447 TokenBindingURLRequestTest() 3452 TokenBindingURLRequestTest() = default;
3448 : scoped_task_scheduler_(base::MessageLoop::current()) {}
3449 3453
3450 void SetUp() override { 3454 void SetUp() override {
3451 default_context_.set_ssl_config_service( 3455 default_context_.set_ssl_config_service(
3452 new TestSSLConfigService(false, false, false, true)); 3456 new TestSSLConfigService(false, false, false, true));
3453 channel_id_service_.reset( 3457 channel_id_service_.reset(
3454 new ChannelIDService(new DefaultChannelIDStore(NULL))); 3458 new ChannelIDService(new DefaultChannelIDStore(NULL)));
3455 default_context_.set_channel_id_service(channel_id_service_.get()); 3459 default_context_.set_channel_id_service(channel_id_service_.get());
3456 URLRequestTestHTTP::SetUp(); 3460 URLRequestTestHTTP::SetUp();
3457 } 3461 }
3458 3462
3459 protected: 3463 protected:
3460 // Required by ChannelIDService.
3461 base::test::ScopedTaskScheduler scoped_task_scheduler_;
3462 std::unique_ptr<ChannelIDService> channel_id_service_; 3464 std::unique_ptr<ChannelIDService> channel_id_service_;
3463 }; 3465 };
3464 3466
3465 TEST_F(TokenBindingURLRequestTest, TokenBindingTest) { 3467 TEST_F(TokenBindingURLRequestTest, TokenBindingTest) {
3466 SpawnedTestServer::SSLOptions ssl_options; 3468 SpawnedTestServer::SSLOptions ssl_options;
3467 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); 3469 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256);
3468 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, 3470 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS,
3469 ssl_options, 3471 ssl_options,
3470 base::FilePath(kTestFilePath)); 3472 base::FilePath(kTestFilePath));
3471 ASSERT_TRUE(https_test_server.Start()); 3473 ASSERT_TRUE(https_test_server.Start());
(...skipping 5058 matching lines...) Expand 10 before | Expand all | Expand 10 after
8530 origin_server()->GetURL("/path/to/file.html"), 8532 origin_server()->GetURL("/path/to/file.html"),
8531 origin_server()->GetURL("/")); 8533 origin_server()->GetURL("/"));
8532 8534
8533 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, 8535 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER,
8534 origin_server()->GetURL("/path/to/file.html"), 8536 origin_server()->GetURL("/path/to/file.html"),
8535 origin_server()->GetURL("/path/to/file.html")); 8537 origin_server()->GetURL("/path/to/file.html"));
8536 } 8538 }
8537 8539
8538 class HTTPSRequestTest : public testing::Test { 8540 class HTTPSRequestTest : public testing::Test {
8539 public: 8541 public:
8540 HTTPSRequestTest() 8542 HTTPSRequestTest() : default_context_(true) {
8541 : scoped_task_scheduler_(base::MessageLoop::current()),
8542 default_context_(true) {
8543 default_context_.set_network_delegate(&default_network_delegate_); 8543 default_context_.set_network_delegate(&default_network_delegate_);
8544 default_context_.Init(); 8544 default_context_.Init();
8545 } 8545 }
8546 ~HTTPSRequestTest() override {} 8546 ~HTTPSRequestTest() override {}
8547 8547
8548 protected: 8548 protected:
8549 // Required by ChannelIDService. 8549 // Required by ChannelIDService and MultiThreadedCertVerifier. Needs to be a
8550 base::test::ScopedTaskScheduler scoped_task_scheduler_; 8550 // ScopedAsyncTaskScheduler rather than a ScopedTaskScheduler because the task
8551 // posted by MultiThreadedCertVerifier synchronously waits for a task running
8552 // on the main thread (OCSPRequestSession::Wait).
8553 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_;
8554
8555 protected:
8551 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 8556 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
8552 TestURLRequestContext default_context_; 8557 TestURLRequestContext default_context_;
8553 }; 8558 };
8554 8559
8555 TEST_F(HTTPSRequestTest, HTTPSGetTest) { 8560 TEST_F(HTTPSRequestTest, HTTPSGetTest) {
8556 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); 8561 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS);
8557 test_server.AddDefaultHandlers( 8562 test_server.AddDefaultHandlers(
8558 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 8563 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
8559 ASSERT_TRUE(test_server.Start()); 8564 ASSERT_TRUE(test_server.Start());
8560 8565
(...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after
10740 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10745 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10741 10746
10742 req->Start(); 10747 req->Start();
10743 req->Cancel(); 10748 req->Cancel();
10744 base::RunLoop().RunUntilIdle(); 10749 base::RunLoop().RunUntilIdle();
10745 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10750 EXPECT_EQ(ERR_ABORTED, d.request_status());
10746 EXPECT_EQ(0, d.received_redirect_count()); 10751 EXPECT_EQ(0, d.received_redirect_count());
10747 } 10752 }
10748 10753
10749 } // namespace net 10754 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698