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

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

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | net/websockets/PRESUBMIT.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "net/proxy/proxy_service.h" 65 #include "net/proxy/proxy_service.h"
66 #include "net/socket/ssl_client_socket.h" 66 #include "net/socket/ssl_client_socket.h"
67 #include "net/ssl/ssl_cipher_suite_names.h" 67 #include "net/ssl/ssl_cipher_suite_names.h"
68 #include "net/ssl/ssl_connection_status_flags.h" 68 #include "net/ssl/ssl_connection_status_flags.h"
69 #include "net/test/cert_test_util.h" 69 #include "net/test/cert_test_util.h"
70 #include "net/test/spawned_test_server/spawned_test_server.h" 70 #include "net/test/spawned_test_server/spawned_test_server.h"
71 #include "net/url_request/data_protocol_handler.h" 71 #include "net/url_request/data_protocol_handler.h"
72 #include "net/url_request/static_http_user_agent_settings.h" 72 #include "net/url_request/static_http_user_agent_settings.h"
73 #include "net/url_request/url_request.h" 73 #include "net/url_request/url_request.h"
74 #include "net/url_request/url_request_http_job.h" 74 #include "net/url_request/url_request_http_job.h"
75 #include "net/url_request/url_request_intercepting_job_factory.h"
76 #include "net/url_request/url_request_interceptor.h"
75 #include "net/url_request/url_request_job_factory_impl.h" 77 #include "net/url_request/url_request_job_factory_impl.h"
76 #include "net/url_request/url_request_redirect_job.h" 78 #include "net/url_request/url_request_redirect_job.h"
77 #include "net/url_request/url_request_test_job.h" 79 #include "net/url_request/url_request_test_job.h"
78 #include "net/url_request/url_request_test_util.h" 80 #include "net/url_request/url_request_test_util.h"
79 #include "testing/gtest/include/gtest/gtest.h" 81 #include "testing/gtest/include/gtest/gtest.h"
80 #include "testing/platform_test.h" 82 #include "testing/platform_test.h"
81 83
82 #if !defined(DISABLE_FILE_SUPPORT) 84 #if !defined(DISABLE_FILE_SUPPORT)
83 #include "net/base/filename_util.h" 85 #include "net/base/filename_util.h"
84 #include "net/url_request/file_protocol_handler.h" 86 #include "net/url_request/file_protocol_handler.h"
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 }; 602 };
601 603
602 } // namespace 604 } // namespace
603 605
604 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 606 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
605 class URLRequestTest : public PlatformTest { 607 class URLRequestTest : public PlatformTest {
606 public: 608 public:
607 URLRequestTest() : default_context_(true) { 609 URLRequestTest() : default_context_(true) {
608 default_context_.set_network_delegate(&default_network_delegate_); 610 default_context_.set_network_delegate(&default_network_delegate_);
609 default_context_.set_net_log(&net_log_); 611 default_context_.set_net_log(&net_log_);
610 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); 612 job_factory_impl_ = new URLRequestJobFactoryImpl();
611 #if !defined(DISABLE_FILE_SUPPORT) 613 job_factory_.reset(job_factory_impl_);
612 job_factory_.SetProtocolHandler(
613 "file", new FileProtocolHandler(base::MessageLoopProxy::current()));
614 #endif
615 default_context_.set_job_factory(&job_factory_);
616 default_context_.Init();
617 } 614 }
615
618 ~URLRequestTest() override { 616 ~URLRequestTest() override {
619 // URLRequestJobs may post clean-up tasks on destruction. 617 // URLRequestJobs may post clean-up tasks on destruction.
620 base::RunLoop().RunUntilIdle(); 618 base::RunLoop().RunUntilIdle();
621 } 619 }
622 620
621 virtual void SetUp() {
622 SetUpFactory();
623 default_context_.set_job_factory(job_factory_.get());
624 default_context_.Init();
625 PlatformTest::SetUp();
626 }
627
628 virtual void SetUpFactory() {
629 job_factory_impl_->SetProtocolHandler("data", new DataProtocolHandler);
630 #if !defined(DISABLE_FILE_SUPPORT)
631 job_factory_impl_->SetProtocolHandler(
632 "file", new FileProtocolHandler(base::MessageLoopProxy::current()));
633 #endif
634 }
635
636 TestNetworkDelegate* default_network_delegate() {
637 return &default_network_delegate_;
638 }
639
640 const TestURLRequestContext& default_context() const {
641 return default_context_;
642 }
643
644
623 // Adds the TestJobInterceptor to the default context. 645 // Adds the TestJobInterceptor to the default context.
624 TestJobInterceptor* AddTestInterceptor() { 646 TestJobInterceptor* AddTestInterceptor() {
625 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); 647 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
626 job_factory_.SetProtocolHandler("http", NULL); 648 job_factory_impl_->SetProtocolHandler("http", NULL);
627 job_factory_.SetProtocolHandler("http", protocol_handler_); 649 job_factory_impl_->SetProtocolHandler("http", protocol_handler_);
628 return protocol_handler_; 650 return protocol_handler_;
629 } 651 }
630 652
631 protected: 653 protected:
632 CapturingNetLog net_log_; 654 CapturingNetLog net_log_;
633 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 655 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
634 URLRequestJobFactoryImpl job_factory_; 656 URLRequestJobFactoryImpl* job_factory_impl_;
657 scoped_ptr<URLRequestJobFactory> job_factory_;
635 TestURLRequestContext default_context_; 658 TestURLRequestContext default_context_;
636 }; 659 };
637 660
638 TEST_F(URLRequestTest, AboutBlankTest) { 661 TEST_F(URLRequestTest, AboutBlankTest) {
639 TestDelegate d; 662 TestDelegate d;
640 { 663 {
641 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 664 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
642 GURL("about:blank"), DEFAULT_PRIORITY, &d, NULL)); 665 GURL("about:blank"), DEFAULT_PRIORITY, &d, NULL));
643 666
644 r->Start(); 667 r->Start();
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 1590
1568 // Check the interceptor got called as expected 1591 // Check the interceptor got called as expected
1569 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 1592 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
1570 EXPECT_FALSE(interceptor.did_intercept_final_); 1593 EXPECT_FALSE(interceptor.did_intercept_final_);
1571 1594
1572 // Check we see a canceled request 1595 // Check we see a canceled request
1573 EXPECT_FALSE(req->status().is_success()); 1596 EXPECT_FALSE(req->status().is_success());
1574 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 1597 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1575 } 1598 }
1576 1599
1577 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, 1600 // An Interceptor for use with interceptor tests.
1578 URLRequestContext* context) { 1601 class MockURLRequestInterceptor : public URLRequestInterceptor {
1579 TestInterceptor interceptor; 1602 public:
1580 interceptor.intercept_main_request_ = true; 1603 // Static getters for canned response header and data strings.
1581 interceptor.main_request_load_timing_info_ = job_load_timing; 1604 static std::string ok_data() {
1582 TestDelegate d; 1605 return URLRequestTestJob::test_data_1();
1583 scoped_ptr<URLRequest> req(context->CreateRequest( 1606 }
1584 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); 1607
1585 req->Start(); 1608 static std::string ok_headers() {
1586 base::RunLoop().Run(); 1609 return URLRequestTestJob::test_headers();
1587 1610 }
1588 LoadTimingInfo resulting_load_timing; 1611
1589 req->GetLoadTimingInfo(&resulting_load_timing); 1612 static std::string redirect_data() {
1590 1613 return std::string();
1591 // None of these should be modified by the URLRequest. 1614 }
1592 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); 1615
1593 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); 1616 static std::string redirect_headers() {
1594 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); 1617 return URLRequestTestJob::test_redirect_headers();
1595 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); 1618 }
1596 EXPECT_EQ(job_load_timing.receive_headers_end, 1619
1597 resulting_load_timing.receive_headers_end); 1620 static std::string error_data() {
1598 1621 return std::string("ohhh nooooo mr. bill!");
1599 return resulting_load_timing; 1622 }
1623
1624 static std::string error_headers() {
1625 return URLRequestTestJob::test_error_headers();
1626 }
1627
1628 MockURLRequestInterceptor()
1629 : intercept_main_request_(false), restart_main_request_(false),
1630 cancel_main_request_(false), cancel_then_restart_main_request_(false),
1631 simulate_main_network_error_(false),
1632 intercept_redirect_(false), cancel_redirect_request_(false),
1633 intercept_final_response_(false), cancel_final_request_(false),
1634 use_url_request_http_job_(false),
1635 did_intercept_main_(false), did_restart_main_(false),
1636 did_cancel_main_(false), did_cancel_then_restart_main_(false),
1637 did_simulate_error_main_(false),
1638 did_intercept_redirect_(false), did_cancel_redirect_(false),
1639 did_intercept_final_(false), did_cancel_final_(false) {
1640 }
1641
1642 ~MockURLRequestInterceptor() override {
1643 }
1644
1645 // URLRequestInterceptor implementation:
1646 URLRequestJob* MaybeInterceptRequest(
1647 URLRequest* request,
1648 NetworkDelegate* network_delegate) const override {
1649 if (restart_main_request_) {
1650 restart_main_request_ = false;
1651 did_restart_main_ = true;
1652 return new RestartTestJob(request, network_delegate);
1653 }
1654 if (cancel_main_request_) {
1655 cancel_main_request_ = false;
1656 did_cancel_main_ = true;
1657 return new CancelTestJob(request, network_delegate);
1658 }
1659 if (cancel_then_restart_main_request_) {
1660 cancel_then_restart_main_request_ = false;
1661 did_cancel_then_restart_main_ = true;
1662 return new CancelThenRestartTestJob(request, network_delegate);
1663 }
1664 if (simulate_main_network_error_) {
1665 simulate_main_network_error_ = false;
1666 did_simulate_error_main_ = true;
1667 if (use_url_request_http_job_) {
1668 return URLRequestHttpJob::Factory(request, network_delegate, "http");
1669 }
1670 // This job will result in error since the requested URL is not one of the
1671 // URLs supported by these tests.
1672 return new URLRequestTestJob(request, network_delegate, true);
1673 }
1674 if (!intercept_main_request_)
1675 return nullptr;
1676 intercept_main_request_ = false;
1677 did_intercept_main_ = true;
1678 URLRequestTestJob* job = new URLRequestTestJob(request,
1679 network_delegate,
1680 main_headers_,
1681 main_data_,
1682 true);
1683 job->set_load_timing_info(main_request_load_timing_info_);
1684 return job;
1685 }
1686
1687 URLRequestJob* MaybeInterceptRedirect(URLRequest* request,
1688 NetworkDelegate* network_delegate,
1689 const GURL& location) const override {
1690 if (cancel_redirect_request_) {
1691 cancel_redirect_request_ = false;
1692 did_cancel_redirect_ = true;
1693 return new CancelTestJob(request, network_delegate);
1694 }
1695 if (!intercept_redirect_)
1696 return nullptr;
1697 intercept_redirect_ = false;
1698 did_intercept_redirect_ = true;
1699 if (use_url_request_http_job_) {
1700 return URLRequestHttpJob::Factory(request, network_delegate, "http");
1701 }
1702 return new URLRequestTestJob(request,
1703 network_delegate,
1704 redirect_headers_,
1705 redirect_data_,
1706 true);
1707 }
1708
1709 URLRequestJob* MaybeInterceptResponse(
1710 URLRequest* request,
1711 NetworkDelegate* network_delegate) const override {
1712 if (cancel_final_request_) {
1713 cancel_final_request_ = false;
1714 did_cancel_final_ = true;
1715 return new CancelTestJob(request, network_delegate);
1716 }
1717 if (!intercept_final_response_)
1718 return nullptr;
1719 intercept_final_response_ = false;
1720 did_intercept_final_ = true;
1721 if (use_url_request_http_job_) {
1722 return URLRequestHttpJob::Factory(request, network_delegate, "http");
1723 }
1724 return new URLRequestTestJob(request,
1725 network_delegate,
1726 final_headers_,
1727 final_data_,
1728 true);
1729 }
1730
1731 void set_intercept_main_request(bool intercept_main_request) {
1732 intercept_main_request_ = intercept_main_request;
1733 }
1734
1735 void set_main_headers(const std::string& main_headers) {
1736 main_headers_ = main_headers;
1737 }
1738
1739 void set_main_data(const std::string& main_data) {
1740 main_data_ = main_data;
1741 }
1742
1743 void set_main_request_load_timing_info(
1744 const LoadTimingInfo& main_request_load_timing_info) {
1745 main_request_load_timing_info_ = main_request_load_timing_info;
1746 }
1747
1748 void set_restart_main_request(bool restart_main_request) {
1749 restart_main_request_ = restart_main_request;
1750 }
1751
1752 void set_cancel_main_request(bool cancel_main_request) {
1753 cancel_main_request_ = cancel_main_request;
1754 }
1755
1756 void set_cancel_then_restart_main_request(
1757 bool cancel_then_restart_main_request) {
1758 cancel_then_restart_main_request_ = cancel_then_restart_main_request;
1759 }
1760
1761 void set_simulate_main_network_error(bool simulate_main_network_error) {
1762 simulate_main_network_error_ = simulate_main_network_error;
1763 }
1764
1765 void set_intercept_redirect(bool intercept_redirect) {
1766 intercept_redirect_ = intercept_redirect;
1767 }
1768
1769 void set_redirect_headers(const std::string& redirect_headers) {
1770 redirect_headers_ = redirect_headers;
1771 }
1772
1773 void set_redirect_data(const std::string& redirect_data) {
1774 redirect_data_ = redirect_data;
1775 }
1776
1777 void set_cancel_redirect_request(bool cancel_redirect_request) {
1778 cancel_redirect_request_ = cancel_redirect_request;
1779 }
1780
1781 void set_intercept_final_response(bool intercept_final_response) {
1782 intercept_final_response_ = intercept_final_response;
1783 }
1784
1785 void set_final_headers(const std::string& final_headers) {
1786 final_headers_ = final_headers;
1787 }
1788
1789 void set_final_data(const std::string& final_data) {
1790 final_data_ = final_data;
1791 }
1792
1793 void set_cancel_final_request(bool cancel_final_request) {
1794 cancel_final_request_ = cancel_final_request;
1795 }
1796
1797 void set_use_url_request_http_job(bool use_url_request_http_job) {
1798 use_url_request_http_job_ = use_url_request_http_job;
1799 }
1800
1801 bool did_intercept_main() const {
1802 return did_intercept_main_;
1803 }
1804
1805 bool did_restart_main() const {
1806 return did_restart_main_;
1807 }
1808
1809 bool did_cancel_main() const {
1810 return did_cancel_main_;
1811 }
1812
1813 bool did_cancel_then_restart_main() const {
1814 return did_cancel_then_restart_main_;
1815 }
1816
1817 bool did_simulate_error_main() const {
1818 return did_simulate_error_main_;
1819 }
1820
1821 bool did_intercept_redirect() const {
1822 return did_intercept_redirect_;
1823 }
1824
1825 bool did_cancel_redirect() const {
1826 return did_cancel_redirect_;
1827 }
1828
1829 bool did_intercept_final() const {
1830 return did_intercept_final_;
1831 }
1832
1833 bool did_cancel_final() const {
1834 return did_cancel_final_;
1835 }
1836
1837 private:
1838 // Indicate whether to intercept the main request, and if so specify the
1839 // response to return and the LoadTimingInfo to use.
1840 mutable bool intercept_main_request_;
1841 mutable std::string main_headers_;
1842 mutable std::string main_data_;
1843 mutable LoadTimingInfo main_request_load_timing_info_;
1844
1845 // These indicate actions that can be taken within MaybeInterceptRequest.
1846 mutable bool restart_main_request_;
1847 mutable bool cancel_main_request_;
1848 mutable bool cancel_then_restart_main_request_;
1849 mutable bool simulate_main_network_error_;
1850
1851 // Indicate whether to intercept redirects, and if so specify the response to
1852 // return.
1853 mutable bool intercept_redirect_;
1854 mutable std::string redirect_headers_;
1855 mutable std::string redirect_data_;
1856
1857 // Cancel the request within MaybeInterceptRedirect.
1858 mutable bool cancel_redirect_request_;
1859
1860 // Indicate whether to intercept the final response, and if so specify the
1861 // response to return.
1862 mutable bool intercept_final_response_;
1863 mutable std::string final_headers_;
1864 mutable std::string final_data_;
1865
1866 // Cancel the final request within MaybeInterceptResponse.
1867 mutable bool cancel_final_request_;
1868
1869 // Instruct the interceptor to use a real URLRequestHTTPJob.
1870 mutable bool use_url_request_http_job_;
1871
1872 // These indicate if the interceptor did something or not.
1873 mutable bool did_intercept_main_;
1874 mutable bool did_restart_main_;
1875 mutable bool did_cancel_main_;
1876 mutable bool did_cancel_then_restart_main_;
1877 mutable bool did_simulate_error_main_;
1878 mutable bool did_intercept_redirect_;
1879 mutable bool did_cancel_redirect_;
1880 mutable bool did_intercept_final_;
1881 mutable bool did_cancel_final_;
1882 };
1883
1884 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
1885 class URLRequestInterceptorTest : public URLRequestTest {
1886 public:
1887 URLRequestInterceptorTest() : URLRequestTest(), interceptor_(NULL) {
1888 }
1889
1890 ~URLRequestInterceptorTest() override {
1891 // URLRequestJobs may post clean-up tasks on destruction.
1892 base::RunLoop().RunUntilIdle();
1893 }
1894
1895 void SetUpFactory() override {
1896 interceptor_ = new MockURLRequestInterceptor();
1897 job_factory_.reset(new URLRequestInterceptingJobFactory(
1898 job_factory_.Pass(), make_scoped_ptr(interceptor_)));
1899 }
1900
1901 MockURLRequestInterceptor* interceptor() const {
1902 return interceptor_;
1903 }
1904
1905 private:
1906 MockURLRequestInterceptor* interceptor_;
1907 };
1908
1909 TEST_F(URLRequestInterceptorTest, Intercept) {
1910 // Intercept the main request and respond with a simple response.
1911 interceptor()->set_intercept_main_request(true);
1912 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
1913 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
1914 TestDelegate d;
1915 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1916 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
1917 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data();
1918 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data();
1919 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data();
1920 req->SetUserData(nullptr, user_data0);
1921 req->SetUserData(&user_data1, user_data1);
1922 req->SetUserData(&user_data2, user_data2);
1923 req->set_method("GET");
1924 req->Start();
1925 base::RunLoop().Run();
1926
1927 // Make sure we can retrieve our specific user data.
1928 EXPECT_EQ(user_data0, req->GetUserData(nullptr));
1929 EXPECT_EQ(user_data1, req->GetUserData(&user_data1));
1930 EXPECT_EQ(user_data2, req->GetUserData(&user_data2));
1931
1932 // Check that we got one good response.
1933 EXPECT_TRUE(req->status().is_success());
1934 EXPECT_EQ(200, req->response_headers()->response_code());
1935 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1936 EXPECT_EQ(1, d.response_started_count());
1937 EXPECT_EQ(0, d.received_redirect_count());
1938 }
1939
1940 TEST_F(URLRequestInterceptorTest, InterceptRedirect) {
1941 // Intercept the main request and respond with a redirect.
1942 interceptor()->set_intercept_main_request(true);
1943 interceptor()->set_main_headers(
1944 MockURLRequestInterceptor::redirect_headers());
1945 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data());
1946
1947 // Intercept that redirect and respond with a final OK response.
1948 interceptor()->set_intercept_redirect(true);
1949 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers());
1950 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data());
1951
1952 TestDelegate d;
1953 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1954 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
1955 req->set_method("GET");
1956 req->Start();
1957 base::RunLoop().Run();
1958
1959 // Check that the interceptor got called as expected.
1960 EXPECT_TRUE(interceptor()->did_intercept_main());
1961 EXPECT_TRUE(interceptor()->did_intercept_redirect());
1962
1963 // Check that we got one good response.
1964 EXPECT_TRUE(req->status().is_success());
1965 if (req->status().is_success())
1966 EXPECT_EQ(200, req->response_headers()->response_code());
1967
1968 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1969 EXPECT_EQ(1, d.response_started_count());
1970 EXPECT_EQ(0, d.received_redirect_count());
1971 }
1972
1973 TEST_F(URLRequestInterceptorTest, InterceptServerError) {
1974 // Intercept the main request to generate a server error response.
1975 interceptor()->set_intercept_main_request(true);
1976 interceptor()->set_main_headers(MockURLRequestInterceptor::error_headers());
1977 interceptor()->set_main_data(MockURLRequestInterceptor::error_data());
1978
1979 // Intercept that error and respond with an OK response.
1980 interceptor()->set_intercept_final_response(true);
1981 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1982 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1983
1984 TestDelegate d;
1985 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1986 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
1987 req->set_method("GET");
1988 req->Start();
1989 base::RunLoop().Run();
1990
1991 // Check that the interceptor got called as expected.
1992 EXPECT_TRUE(interceptor()->did_intercept_main());
1993 EXPECT_TRUE(interceptor()->did_intercept_final());
1994
1995 // Check that we got one good response.
1996 EXPECT_TRUE(req->status().is_success());
1997 EXPECT_EQ(200, req->response_headers()->response_code());
1998 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1999 EXPECT_EQ(1, d.response_started_count());
2000 EXPECT_EQ(0, d.received_redirect_count());
2001 }
2002
2003 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) {
2004 // Intercept the main request to simulate a network error.
2005 interceptor()->set_simulate_main_network_error(true);
2006
2007 // Intercept that error and respond with an OK response.
2008 interceptor()->set_intercept_final_response(true);
2009 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
2010 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
2011
2012 TestDelegate d;
2013 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2014 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2015 req->set_method("GET");
2016 req->Start();
2017 base::RunLoop().Run();
2018
2019 // Check that the interceptor got called as expected.
2020 EXPECT_TRUE(interceptor()->did_simulate_error_main());
2021 EXPECT_TRUE(interceptor()->did_intercept_final());
2022
2023 // Check that we received one good response.
2024 EXPECT_TRUE(req->status().is_success());
2025 EXPECT_EQ(200, req->response_headers()->response_code());
2026 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
2027 EXPECT_EQ(1, d.response_started_count());
2028 EXPECT_EQ(0, d.received_redirect_count());
2029 }
2030
2031 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) {
2032 // Restart the main request.
2033 interceptor()->set_restart_main_request(true);
2034
2035 // then intercept the new main request and respond with an OK response
2036 interceptor()->set_intercept_main_request(true);
2037 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
2038 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
2039
2040 TestDelegate d;
2041 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2042 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2043 req->set_method("GET");
2044 req->Start();
2045 base::RunLoop().Run();
2046
2047 // Check that the interceptor got called as expected.
2048 EXPECT_TRUE(interceptor()->did_restart_main());
2049 EXPECT_TRUE(interceptor()->did_intercept_main());
2050
2051 // Check that we received one good response.
2052 EXPECT_TRUE(req->status().is_success());
2053 if (req->status().is_success())
2054 EXPECT_EQ(200, req->response_headers()->response_code());
2055
2056 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
2057 EXPECT_EQ(1, d.response_started_count());
2058 EXPECT_EQ(0, d.received_redirect_count());
2059 }
2060
2061 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) {
2062 // Intercept the main request and cancel from within the restarted job.
2063 interceptor()->set_cancel_main_request(true);
2064
2065 // Set up to intercept the final response and override it with an OK response.
2066 interceptor()->set_intercept_final_response(true);
2067 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
2068 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
2069
2070 TestDelegate d;
2071 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2072 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2073 req->set_method("GET");
2074 req->Start();
2075 base::RunLoop().Run();
2076
2077 // Check that the interceptor got called as expected.
2078 EXPECT_TRUE(interceptor()->did_cancel_main());
2079 EXPECT_FALSE(interceptor()->did_intercept_final());
2080
2081 // Check that we see a canceled request.
2082 EXPECT_FALSE(req->status().is_success());
2083 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
2084 }
2085
2086 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelRedirect) {
2087 // Intercept the main request and respond with a redirect.
2088 interceptor()->set_intercept_main_request(true);
2089 interceptor()->set_main_headers(
2090 MockURLRequestInterceptor::redirect_headers());
2091 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data());
2092
2093 // Intercept the redirect and cancel from within that job.
2094 interceptor()->set_cancel_redirect_request(true);
2095
2096 // Set up to intercept the final response and override it with an OK response.
2097 interceptor()->set_intercept_final_response(true);
2098 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
2099 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
2100
2101 TestDelegate d;
2102 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2103 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2104 req->set_method("GET");
2105 req->Start();
2106 base::RunLoop().Run();
2107
2108 // Check that the interceptor got called as expected.
2109 EXPECT_TRUE(interceptor()->did_intercept_main());
2110 EXPECT_TRUE(interceptor()->did_cancel_redirect());
2111 EXPECT_FALSE(interceptor()->did_intercept_final());
2112
2113 // Check that we see a canceled request.
2114 EXPECT_FALSE(req->status().is_success());
2115 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
2116 }
2117
2118 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) {
2119 // Intercept the main request to simulate a network error.
2120 interceptor()->set_simulate_main_network_error(true);
2121
2122 // Set up to intercept final the response and cancel from within that job.
2123 interceptor()->set_cancel_final_request(true);
2124
2125 TestDelegate d;
2126 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2127 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2128 req->set_method("GET");
2129 req->Start();
2130 base::RunLoop().Run();
2131
2132 // Check that the interceptor got called as expected.
2133 EXPECT_TRUE(interceptor()->did_simulate_error_main());
2134 EXPECT_TRUE(interceptor()->did_cancel_final());
2135
2136 // Check that we see a canceled request.
2137 EXPECT_FALSE(req->status().is_success());
2138 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
2139 }
2140
2141 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) {
2142 // Intercept the main request and cancel then restart from within that job.
2143 interceptor()->set_cancel_then_restart_main_request(true);
2144
2145 // Set up to intercept the final response and override it with an OK response.
2146 interceptor()->set_intercept_final_response(true);
2147 interceptor()->set_final_headers(TestInterceptor::ok_headers());
2148 interceptor()->set_final_data(TestInterceptor::ok_data());
2149
2150 TestDelegate d;
2151 scoped_ptr<URLRequest> req(default_context().CreateRequest(
2152 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2153 req->set_method("GET");
2154 req->Start();
2155 base::RunLoop().Run();
2156
2157 // Check that the interceptor got called as expected.
2158 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main());
2159 EXPECT_FALSE(interceptor()->did_intercept_final());
2160
2161 // Check that we see a canceled request.
2162 EXPECT_FALSE(req->status().is_success());
2163 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1600 } 2164 }
1601 2165
1602 // "Normal" LoadTimingInfo as returned by a job. Everything is in order, not 2166 // "Normal" LoadTimingInfo as returned by a job. Everything is in order, not
1603 // reused. |connect_time_flags| is used to indicate if there should be dns 2167 // reused. |connect_time_flags| is used to indicate if there should be dns
1604 // or SSL times, and |used_proxy| is used for proxy times. 2168 // or SSL times, and |used_proxy| is used for proxy times.
1605 LoadTimingInfo NormalLoadTimingInfo(base::TimeTicks now, 2169 LoadTimingInfo NormalLoadTimingInfo(base::TimeTicks now,
1606 int connect_time_flags, 2170 int connect_time_flags,
1607 bool used_proxy) { 2171 bool used_proxy) {
1608 LoadTimingInfo load_timing; 2172 LoadTimingInfo load_timing;
1609 load_timing.socket_log_id = 1; 2173 load_timing.socket_log_id = 1;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 load_timing.proxy_resolve_start = now + base::TimeDelta::FromDays(1); 2206 load_timing.proxy_resolve_start = now + base::TimeDelta::FromDays(1);
1643 load_timing.proxy_resolve_end = now + base::TimeDelta::FromDays(2); 2207 load_timing.proxy_resolve_end = now + base::TimeDelta::FromDays(2);
1644 } 2208 }
1645 2209
1646 load_timing.send_start = now + base::TimeDelta::FromDays(9); 2210 load_timing.send_start = now + base::TimeDelta::FromDays(9);
1647 load_timing.send_end = now + base::TimeDelta::FromDays(10); 2211 load_timing.send_end = now + base::TimeDelta::FromDays(10);
1648 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11); 2212 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11);
1649 return load_timing; 2213 return load_timing;
1650 } 2214 }
1651 2215
2216 LoadTimingInfo RunURLRequestInterceptorLoadTimingTest(
2217 const LoadTimingInfo& job_load_timing,
2218 const URLRequestContext& context,
2219 MockURLRequestInterceptor* interceptor) {
2220 interceptor->set_intercept_main_request(true);
2221 interceptor->set_main_request_load_timing_info(job_load_timing);
2222 TestDelegate d;
2223 scoped_ptr<URLRequest> req(context.CreateRequest(
2224 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr));
2225 req->Start();
2226 base::RunLoop().Run();
2227
2228 LoadTimingInfo resulting_load_timing;
2229 req->GetLoadTimingInfo(&resulting_load_timing);
2230
2231 // None of these should be modified by the URLRequest.
2232 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused);
2233 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id);
2234 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start);
2235 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end);
2236 EXPECT_EQ(job_load_timing.receive_headers_end,
2237 resulting_load_timing.receive_headers_end);
2238
2239 return resulting_load_timing;
2240 }
2241
1652 // Basic test that the intercept + load timing tests work. 2242 // Basic test that the intercept + load timing tests work.
1653 TEST_F(URLRequestTest, InterceptLoadTiming) { 2243 TEST_F(URLRequestInterceptorTest, InterceptLoadTiming) {
1654 base::TimeTicks now = base::TimeTicks::Now(); 2244 base::TimeTicks now = base::TimeTicks::Now();
1655 LoadTimingInfo job_load_timing = 2245 LoadTimingInfo job_load_timing =
1656 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false); 2246 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false);
1657 2247
1658 LoadTimingInfo load_timing_result = 2248 LoadTimingInfo load_timing_result =
1659 RunLoadTimingTest(job_load_timing, &default_context_); 2249 RunURLRequestInterceptorLoadTimingTest(
2250 job_load_timing, default_context(), interceptor());
1660 2251
1661 // Nothing should have been changed by the URLRequest. 2252 // Nothing should have been changed by the URLRequest.
1662 EXPECT_EQ(job_load_timing.proxy_resolve_start, 2253 EXPECT_EQ(job_load_timing.proxy_resolve_start,
1663 load_timing_result.proxy_resolve_start); 2254 load_timing_result.proxy_resolve_start);
1664 EXPECT_EQ(job_load_timing.proxy_resolve_end, 2255 EXPECT_EQ(job_load_timing.proxy_resolve_end,
1665 load_timing_result.proxy_resolve_end); 2256 load_timing_result.proxy_resolve_end);
1666 EXPECT_EQ(job_load_timing.connect_timing.dns_start, 2257 EXPECT_EQ(job_load_timing.connect_timing.dns_start,
1667 load_timing_result.connect_timing.dns_start); 2258 load_timing_result.connect_timing.dns_start);
1668 EXPECT_EQ(job_load_timing.connect_timing.dns_end, 2259 EXPECT_EQ(job_load_timing.connect_timing.dns_end,
1669 load_timing_result.connect_timing.dns_end); 2260 load_timing_result.connect_timing.dns_end);
1670 EXPECT_EQ(job_load_timing.connect_timing.connect_start, 2261 EXPECT_EQ(job_load_timing.connect_timing.connect_start,
1671 load_timing_result.connect_timing.connect_start); 2262 load_timing_result.connect_timing.connect_start);
1672 EXPECT_EQ(job_load_timing.connect_timing.connect_end, 2263 EXPECT_EQ(job_load_timing.connect_timing.connect_end,
1673 load_timing_result.connect_timing.connect_end); 2264 load_timing_result.connect_timing.connect_end);
1674 EXPECT_EQ(job_load_timing.connect_timing.ssl_start, 2265 EXPECT_EQ(job_load_timing.connect_timing.ssl_start,
1675 load_timing_result.connect_timing.ssl_start); 2266 load_timing_result.connect_timing.ssl_start);
1676 EXPECT_EQ(job_load_timing.connect_timing.ssl_end, 2267 EXPECT_EQ(job_load_timing.connect_timing.ssl_end,
1677 load_timing_result.connect_timing.ssl_end); 2268 load_timing_result.connect_timing.ssl_end);
1678 2269
1679 // Redundant sanity check. 2270 // Redundant sanity check.
1680 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES); 2271 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES);
1681 } 2272 }
1682 2273
1683 // Another basic test, with proxy and SSL times, but no DNS times. 2274 // Another basic test, with proxy and SSL times, but no DNS times.
1684 TEST_F(URLRequestTest, InterceptLoadTimingProxy) { 2275 TEST_F(URLRequestInterceptorTest, InterceptLoadTimingProxy) {
1685 base::TimeTicks now = base::TimeTicks::Now(); 2276 base::TimeTicks now = base::TimeTicks::Now();
1686 LoadTimingInfo job_load_timing = 2277 LoadTimingInfo job_load_timing =
1687 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true); 2278 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true);
1688 2279
1689 LoadTimingInfo load_timing_result = 2280 LoadTimingInfo load_timing_result =
1690 RunLoadTimingTest(job_load_timing, &default_context_); 2281 RunURLRequestInterceptorLoadTimingTest(
2282 job_load_timing, default_context(), interceptor());
1691 2283
1692 // Nothing should have been changed by the URLRequest. 2284 // Nothing should have been changed by the URLRequest.
1693 EXPECT_EQ(job_load_timing.proxy_resolve_start, 2285 EXPECT_EQ(job_load_timing.proxy_resolve_start,
1694 load_timing_result.proxy_resolve_start); 2286 load_timing_result.proxy_resolve_start);
1695 EXPECT_EQ(job_load_timing.proxy_resolve_end, 2287 EXPECT_EQ(job_load_timing.proxy_resolve_end,
1696 load_timing_result.proxy_resolve_end); 2288 load_timing_result.proxy_resolve_end);
1697 EXPECT_EQ(job_load_timing.connect_timing.dns_start, 2289 EXPECT_EQ(job_load_timing.connect_timing.dns_start,
1698 load_timing_result.connect_timing.dns_start); 2290 load_timing_result.connect_timing.dns_start);
1699 EXPECT_EQ(job_load_timing.connect_timing.dns_end, 2291 EXPECT_EQ(job_load_timing.connect_timing.dns_end,
1700 load_timing_result.connect_timing.dns_end); 2292 load_timing_result.connect_timing.dns_end);
(...skipping 10 matching lines...) Expand all
1711 TestLoadTimingNotReusedWithProxy(load_timing_result, 2303 TestLoadTimingNotReusedWithProxy(load_timing_result,
1712 CONNECT_TIMING_HAS_SSL_TIMES); 2304 CONNECT_TIMING_HAS_SSL_TIMES);
1713 } 2305 }
1714 2306
1715 // Make sure that URLRequest correctly adjusts proxy times when they're before 2307 // Make sure that URLRequest correctly adjusts proxy times when they're before
1716 // |request_start|, due to already having a connected socket. This happens in 2308 // |request_start|, due to already having a connected socket. This happens in
1717 // the case of reusing a SPDY session. The connected socket is not considered 2309 // the case of reusing a SPDY session. The connected socket is not considered
1718 // reused in this test (May be a preconnect). 2310 // reused in this test (May be a preconnect).
1719 // 2311 //
1720 // To mix things up from the test above, assumes DNS times but no SSL times. 2312 // To mix things up from the test above, assumes DNS times but no SSL times.
1721 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolution) { 2313 TEST_F(URLRequestInterceptorTest, InterceptLoadTimingEarlyProxyResolution) {
1722 base::TimeTicks now = base::TimeTicks::Now(); 2314 base::TimeTicks now = base::TimeTicks::Now();
1723 LoadTimingInfo job_load_timing = 2315 LoadTimingInfo job_load_timing =
1724 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true); 2316 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true);
1725 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6); 2317 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6);
1726 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5); 2318 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5);
1727 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4); 2319 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4);
1728 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3); 2320 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3);
1729 job_load_timing.connect_timing.connect_start = 2321 job_load_timing.connect_timing.connect_start =
1730 now - base::TimeDelta::FromDays(2); 2322 now - base::TimeDelta::FromDays(2);
1731 job_load_timing.connect_timing.connect_end = 2323 job_load_timing.connect_timing.connect_end =
1732 now - base::TimeDelta::FromDays(1); 2324 now - base::TimeDelta::FromDays(1);
1733 2325
1734 LoadTimingInfo load_timing_result = 2326 LoadTimingInfo load_timing_result =
1735 RunLoadTimingTest(job_load_timing, &default_context_); 2327 RunURLRequestInterceptorLoadTimingTest(
2328 job_load_timing, default_context(), interceptor());
1736 2329
1737 // Proxy times, connect times, and DNS times should all be replaced with 2330 // Proxy times, connect times, and DNS times should all be replaced with
1738 // request_start. 2331 // request_start.
1739 EXPECT_EQ(load_timing_result.request_start, 2332 EXPECT_EQ(load_timing_result.request_start,
1740 load_timing_result.proxy_resolve_start); 2333 load_timing_result.proxy_resolve_start);
1741 EXPECT_EQ(load_timing_result.request_start, 2334 EXPECT_EQ(load_timing_result.request_start,
1742 load_timing_result.proxy_resolve_end); 2335 load_timing_result.proxy_resolve_end);
1743 EXPECT_EQ(load_timing_result.request_start, 2336 EXPECT_EQ(load_timing_result.request_start,
1744 load_timing_result.connect_timing.dns_start); 2337 load_timing_result.connect_timing.dns_start);
1745 EXPECT_EQ(load_timing_result.request_start, 2338 EXPECT_EQ(load_timing_result.request_start,
1746 load_timing_result.connect_timing.dns_end); 2339 load_timing_result.connect_timing.dns_end);
1747 EXPECT_EQ(load_timing_result.request_start, 2340 EXPECT_EQ(load_timing_result.request_start,
1748 load_timing_result.connect_timing.connect_start); 2341 load_timing_result.connect_timing.connect_start);
1749 EXPECT_EQ(load_timing_result.request_start, 2342 EXPECT_EQ(load_timing_result.request_start,
1750 load_timing_result.connect_timing.connect_end); 2343 load_timing_result.connect_timing.connect_end);
1751 2344
1752 // Other times should have been left null. 2345 // Other times should have been left null.
1753 TestLoadTimingNotReusedWithProxy(load_timing_result, 2346 TestLoadTimingNotReusedWithProxy(load_timing_result,
1754 CONNECT_TIMING_HAS_DNS_TIMES); 2347 CONNECT_TIMING_HAS_DNS_TIMES);
1755 } 2348 }
1756 2349
1757 // Same as above, but in the reused case. 2350 // Same as above, but in the reused case.
1758 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolutionReused) { 2351 TEST_F(URLRequestInterceptorTest,
2352 InterceptLoadTimingEarlyProxyResolutionReused) {
1759 base::TimeTicks now = base::TimeTicks::Now(); 2353 base::TimeTicks now = base::TimeTicks::Now();
1760 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true); 2354 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true);
1761 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4); 2355 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4);
1762 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3); 2356 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3);
1763 2357
1764 LoadTimingInfo load_timing_result = 2358 LoadTimingInfo load_timing_result =
1765 RunLoadTimingTest(job_load_timing, &default_context_); 2359 RunURLRequestInterceptorLoadTimingTest(
2360 job_load_timing, default_context(), interceptor());
1766 2361
1767 // Proxy times and connect times should all be replaced with request_start. 2362 // Proxy times and connect times should all be replaced with request_start.
1768 EXPECT_EQ(load_timing_result.request_start, 2363 EXPECT_EQ(load_timing_result.request_start,
1769 load_timing_result.proxy_resolve_start); 2364 load_timing_result.proxy_resolve_start);
1770 EXPECT_EQ(load_timing_result.request_start, 2365 EXPECT_EQ(load_timing_result.request_start,
1771 load_timing_result.proxy_resolve_end); 2366 load_timing_result.proxy_resolve_end);
1772 2367
1773 // Other times should have been left null. 2368 // Other times should have been left null.
1774 TestLoadTimingReusedWithProxy(load_timing_result); 2369 TestLoadTimingReusedWithProxy(load_timing_result);
1775 } 2370 }
1776 2371
1777 // Make sure that URLRequest correctly adjusts connect times when they're before 2372 // Make sure that URLRequest correctly adjusts connect times when they're before
1778 // |request_start|, due to reusing a connected socket. The connected socket is 2373 // |request_start|, due to reusing a connected socket. The connected socket is
1779 // not considered reused in this test (May be a preconnect). 2374 // not considered reused in this test (May be a preconnect).
1780 // 2375 //
1781 // To mix things up, the request has SSL times, but no DNS times. 2376 // To mix things up, the request has SSL times, but no DNS times.
1782 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnect) { 2377 TEST_F(URLRequestInterceptorTest, InterceptLoadTimingEarlyConnect) {
1783 base::TimeTicks now = base::TimeTicks::Now(); 2378 base::TimeTicks now = base::TimeTicks::Now();
1784 LoadTimingInfo job_load_timing = 2379 LoadTimingInfo job_load_timing =
1785 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false); 2380 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false);
1786 job_load_timing.connect_timing.connect_start = 2381 job_load_timing.connect_timing.connect_start =
1787 now - base::TimeDelta::FromDays(1); 2382 now - base::TimeDelta::FromDays(1);
1788 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2); 2383 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2);
1789 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3); 2384 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3);
1790 job_load_timing.connect_timing.connect_end = 2385 job_load_timing.connect_timing.connect_end =
1791 now - base::TimeDelta::FromDays(4); 2386 now - base::TimeDelta::FromDays(4);
1792 2387
1793 LoadTimingInfo load_timing_result = 2388 LoadTimingInfo load_timing_result =
1794 RunLoadTimingTest(job_load_timing, &default_context_); 2389 RunURLRequestInterceptorLoadTimingTest(
2390 job_load_timing, default_context(), interceptor());
1795 2391
1796 // Connect times, and SSL times should be replaced with request_start. 2392 // Connect times, and SSL times should be replaced with request_start.
1797 EXPECT_EQ(load_timing_result.request_start, 2393 EXPECT_EQ(load_timing_result.request_start,
1798 load_timing_result.connect_timing.connect_start); 2394 load_timing_result.connect_timing.connect_start);
1799 EXPECT_EQ(load_timing_result.request_start, 2395 EXPECT_EQ(load_timing_result.request_start,
1800 load_timing_result.connect_timing.ssl_start); 2396 load_timing_result.connect_timing.ssl_start);
1801 EXPECT_EQ(load_timing_result.request_start, 2397 EXPECT_EQ(load_timing_result.request_start,
1802 load_timing_result.connect_timing.ssl_end); 2398 load_timing_result.connect_timing.ssl_end);
1803 EXPECT_EQ(load_timing_result.request_start, 2399 EXPECT_EQ(load_timing_result.request_start,
1804 load_timing_result.connect_timing.connect_end); 2400 load_timing_result.connect_timing.connect_end);
1805 2401
1806 // Other times should have been left null. 2402 // Other times should have been left null.
1807 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_SSL_TIMES); 2403 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_SSL_TIMES);
1808 } 2404 }
1809 2405
1810 // Make sure that URLRequest correctly adjusts connect times when they're before 2406 // Make sure that URLRequest correctly adjusts connect times when they're before
1811 // |request_start|, due to reusing a connected socket in the case that there 2407 // |request_start|, due to reusing a connected socket in the case that there
1812 // are also proxy times. The connected socket is not considered reused in this 2408 // are also proxy times. The connected socket is not considered reused in this
1813 // test (May be a preconnect). 2409 // test (May be a preconnect).
1814 // 2410 //
1815 // In this test, there are no SSL or DNS times. 2411 // In this test, there are no SSL or DNS times.
1816 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnectWithProxy) { 2412 TEST_F(URLRequestInterceptorTest, InterceptLoadTimingEarlyConnectWithProxy) {
1817 base::TimeTicks now = base::TimeTicks::Now(); 2413 base::TimeTicks now = base::TimeTicks::Now();
1818 LoadTimingInfo job_load_timing = 2414 LoadTimingInfo job_load_timing =
1819 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true); 2415 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true);
1820 job_load_timing.connect_timing.connect_start = 2416 job_load_timing.connect_timing.connect_start =
1821 now - base::TimeDelta::FromDays(1); 2417 now - base::TimeDelta::FromDays(1);
1822 job_load_timing.connect_timing.connect_end = 2418 job_load_timing.connect_timing.connect_end =
1823 now - base::TimeDelta::FromDays(2); 2419 now - base::TimeDelta::FromDays(2);
1824 2420
1825 LoadTimingInfo load_timing_result = 2421 LoadTimingInfo load_timing_result =
1826 RunLoadTimingTest(job_load_timing, &default_context_); 2422 RunURLRequestInterceptorLoadTimingTest(
2423 job_load_timing, default_context(), interceptor());
1827 2424
1828 // Connect times should be replaced with proxy_resolve_end. 2425 // Connect times should be replaced with proxy_resolve_end.
1829 EXPECT_EQ(load_timing_result.proxy_resolve_end, 2426 EXPECT_EQ(load_timing_result.proxy_resolve_end,
1830 load_timing_result.connect_timing.connect_start); 2427 load_timing_result.connect_timing.connect_start);
1831 EXPECT_EQ(load_timing_result.proxy_resolve_end, 2428 EXPECT_EQ(load_timing_result.proxy_resolve_end,
1832 load_timing_result.connect_timing.connect_end); 2429 load_timing_result.connect_timing.connect_end);
1833 2430
1834 // Other times should have been left null. 2431 // Other times should have been left null.
1835 TestLoadTimingNotReusedWithProxy(load_timing_result, 2432 TestLoadTimingNotReusedWithProxy(load_timing_result,
1836 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); 2433 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); 3255 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG);
2659 // The test server appears to be unable to handle subsequent requests 3256 // The test server appears to be unable to handle subsequent requests
2660 // after this error is triggered. Force it to restart. 3257 // after this error is triggered. Force it to restart.
2661 EXPECT_TRUE(test_server_.Stop()); 3258 EXPECT_TRUE(test_server_.Stop());
2662 EXPECT_TRUE(test_server_.Start()); 3259 EXPECT_TRUE(test_server_.Start());
2663 } 3260 }
2664 3261
2665 return is_success; 3262 return is_success;
2666 } 3263 }
2667 3264
3265 LocalHttpTestServer* test_server() {
3266 return &test_server_;
3267 }
3268
3269 protected:
2668 LocalHttpTestServer test_server_; 3270 LocalHttpTestServer test_server_;
2669 }; 3271 };
2670 3272
2671 // In this unit test, we're using the HTTPTestServer as a proxy server and 3273 // In this unit test, we're using the HTTPTestServer as a proxy server and
2672 // issuing a CONNECT request with the magic host name "www.redirect.com". 3274 // issuing a CONNECT request with the magic host name "www.redirect.com".
2673 // The HTTPTestServer will return a 302 response, which we should not 3275 // The HTTPTestServer will return a 302 response, which we should not
2674 // follow. 3276 // follow.
2675 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { 3277 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) {
2676 ASSERT_TRUE(test_server_.Start()); 3278 ASSERT_TRUE(test_server_.Start());
2677 3279
(...skipping 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after
5159 req->Cancel(); 5761 req->Cancel();
5160 } 5762 }
5161 5763
5162 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) { 5764 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) {
5163 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). 5765 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5164 GURL data_url("data:,foo"); 5766 GURL data_url("data:,foo");
5165 DataProtocolHandler data_protocol_handler; 5767 DataProtocolHandler data_protocol_handler;
5166 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); 5768 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url));
5167 5769
5168 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5770 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5169 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); 5771 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(data_url));
5170 } 5772 }
5171 5773
5172 #if !defined(DISABLE_FILE_SUPPORT) 5774 #if !defined(DISABLE_FILE_SUPPORT)
5173 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { 5775 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) {
5174 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). 5776 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5175 GURL file_url("file:///foo.txt"); 5777 GURL file_url("file:///foo.txt");
5176 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); 5778 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current());
5177 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); 5779 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
5178 5780
5179 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5781 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5180 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); 5782 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url));
5181 } 5783 }
5182 5784
5183 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 5785 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
5184 ASSERT_TRUE(test_server_.Start()); 5786 ASSERT_TRUE(test_server_.Start());
5185 5787
5186 TestDelegate d; 5788 TestDelegate d;
5187 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5789 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5188 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, &d, 5790 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, &d,
5189 NULL)); 5791 NULL));
5190 req->Start(); 5792 req->Start();
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
6439 scoped_ptr<URLRequest> req(context.CreateRequest( 7041 scoped_ptr<URLRequest> req(context.CreateRequest(
6440 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL)); 7042 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL));
6441 req->Start(); 7043 req->Start();
6442 base::RunLoop().Run(); 7044 base::RunLoop().Run();
6443 7045
6444 EXPECT_TRUE(d.request_failed()); 7046 EXPECT_TRUE(d.request_failed());
6445 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 7047 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
6446 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); 7048 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error());
6447 } 7049 }
6448 7050
7051 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP {
7052 public:
7053 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture,
7054 // ideally remove the dependency on URLRequestTestJob, and maybe move these
7055 // tests into the factory tests.
7056 URLRequestInterceptorTestHTTP() : URLRequestTestHTTP(), interceptor_(NULL) {
7057 }
7058
7059 void SetUpFactory() override {
7060 interceptor_ = new MockURLRequestInterceptor();
7061 job_factory_.reset(new URLRequestInterceptingJobFactory(
7062 job_factory_.Pass(), make_scoped_ptr(interceptor_)));
7063 }
7064
7065 MockURLRequestInterceptor* interceptor() const {
7066 return interceptor_;
7067 }
7068
7069 private:
7070 MockURLRequestInterceptor* interceptor_;
7071 };
7072
7073 TEST_F(URLRequestInterceptorTestHTTP,
7074 NetworkDelegateNotificationOnRedirectIntercept) {
7075 interceptor()->set_intercept_redirect(true);
7076 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers());
7077 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data());
7078
7079 ASSERT_TRUE(test_server()->Start());
7080
7081 TestDelegate d;
7082 scoped_ptr<URLRequest> req(default_context().CreateRequest(
7083 test_server()->GetURL("files/redirect-test.html"), DEFAULT_PRIORITY,
7084 &d, nullptr));
7085 req->Start();
7086 base::RunLoop().Run();
7087
7088 EXPECT_TRUE(interceptor()->did_intercept_redirect());
7089 // Check we got one good response
7090 EXPECT_TRUE(req->status().is_success());
7091 if (req->status().is_success())
7092 EXPECT_EQ(200, req->response_headers()->response_code());
7093
7094 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
7095 EXPECT_EQ(1, d.response_started_count());
7096 EXPECT_EQ(0, d.received_redirect_count());
7097
7098 EXPECT_EQ(1, default_network_delegate()->created_requests());
7099 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count());
7100 EXPECT_EQ(1, default_network_delegate()->headers_received_count());
7101 }
7102
7103 TEST_F(URLRequestInterceptorTestHTTP,
7104 NetworkDelegateNotificationOnErrorIntercept) {
7105 // Intercept that error and respond with an OK response.
7106 interceptor()->set_intercept_final_response(true);
7107 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
7108 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
7109 default_network_delegate()->set_can_be_intercepted_on_error(true);
7110
7111 ASSERT_TRUE(test_server()->Start());
7112
7113 TestDelegate d;
7114 scoped_ptr<URLRequest> req(default_context().CreateRequest(
7115 test_server()->GetURL("files/two-content-lengths.html"), DEFAULT_PRIORITY,
7116 &d, nullptr));
7117 req->set_method("GET");
7118 req->Start();
7119 base::RunLoop().Run();
7120
7121 EXPECT_TRUE(interceptor()->did_intercept_final());
7122
7123 // Check we received one good response.
7124 EXPECT_TRUE(req->status().is_success());
7125 if (req->status().is_success())
7126 EXPECT_EQ(200, req->response_headers()->response_code());
7127 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
7128 EXPECT_EQ(1, d.response_started_count());
7129 EXPECT_EQ(0, d.received_redirect_count());
7130
7131 EXPECT_EQ(1, default_network_delegate()->created_requests());
7132 EXPECT_EQ(1, default_network_delegate()->before_send_headers_count());
7133 EXPECT_EQ(0, default_network_delegate()->headers_received_count());
7134 }
7135
7136 TEST_F(URLRequestInterceptorTestHTTP,
7137 NetworkDelegateNotificationOnResponseIntercept) {
7138 // Intercept that error and respond with an OK response.
7139 interceptor()->set_intercept_final_response(true);
7140
7141 // Intercept with a real URLRequestHttpJob.
7142 interceptor()->set_use_url_request_http_job(true);
7143
7144 ASSERT_TRUE(test_server()->Start());
7145
7146 TestDelegate d;
7147 scoped_ptr<URLRequest> req(default_context().CreateRequest(
7148 test_server()->GetURL("files/simple.html"), DEFAULT_PRIORITY,
7149 &d, nullptr));
7150 req->set_method("GET");
7151 req->Start();
7152 base::RunLoop().Run();
7153
7154 EXPECT_TRUE(interceptor()->did_intercept_final());
7155
7156 // Check we received one good response.
7157 EXPECT_TRUE(req->status().is_success());
7158 if (req->status().is_success())
7159 EXPECT_EQ(200, req->response_headers()->response_code());
7160 EXPECT_EQ("hello", d.data_received());
7161 EXPECT_EQ(1, d.response_started_count());
7162 EXPECT_EQ(0, d.received_redirect_count());
7163
7164 EXPECT_EQ(1, default_network_delegate()->created_requests());
7165 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count());
7166 EXPECT_EQ(2, default_network_delegate()->headers_received_count());
7167 }
7168
6449 class HTTPSRequestTest : public testing::Test { 7169 class HTTPSRequestTest : public testing::Test {
6450 public: 7170 public:
6451 HTTPSRequestTest() : default_context_(true) { 7171 HTTPSRequestTest() : default_context_(true) {
6452 default_context_.set_network_delegate(&default_network_delegate_); 7172 default_context_.set_network_delegate(&default_network_delegate_);
6453 default_context_.Init(); 7173 default_context_.Init();
6454 } 7174 }
6455 ~HTTPSRequestTest() override {} 7175 ~HTTPSRequestTest() override {}
6456 7176
6457 protected: 7177 protected:
6458 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 7178 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
7583 #elif (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) 8303 #elif (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID)
7584 // On OS X and Android, we use the system to tell us whether a certificate is 8304 // On OS X and Android, we use the system to tell us whether a certificate is
7585 // EV or not and the system won't recognise our testing root. 8305 // EV or not and the system won't recognise our testing root.
7586 return false; 8306 return false;
7587 #else 8307 #else
7588 return true; 8308 return true;
7589 #endif 8309 #endif
7590 } 8310 }
7591 8311
7592 static bool SystemSupportsOCSP() { 8312 static bool SystemSupportsOCSP() {
7593 #if defined(USE_OPENSSL) 8313 #if defined(USE_OPENSSL_CERTS)
7594 // http://crbug.com/117478 - OpenSSL does not support OCSP. 8314 // http://crbug.com/117478 - OpenSSL does not support OCSP.
7595 return false; 8315 return false;
7596 #elif defined(OS_WIN) 8316 #elif defined(OS_WIN)
7597 return base::win::GetVersion() >= base::win::VERSION_VISTA; 8317 return base::win::GetVersion() >= base::win::VERSION_VISTA;
7598 #elif defined(OS_ANDROID) 8318 #elif defined(OS_ANDROID)
7599 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported. 8319 // TODO(jnd): http://crbug.com/117478 - EV verification is not yet supported.
7600 return false; 8320 return false;
7601 #else 8321 #else
7602 return true; 8322 return true;
7603 #endif 8323 #endif
7604 } 8324 }
7605 8325
8326 static bool SystemSupportsOCSPStapling() {
8327 #if defined(USE_NSS)
8328 return true;
8329 #elif defined(OS_WIN)
8330 return base::win::GetVersion() >= base::win::VERSION_VISTA;
8331 #else
8332 return false;
8333 #endif
8334 }
8335
7606 TEST_F(HTTPSOCSPTest, Valid) { 8336 TEST_F(HTTPSOCSPTest, Valid) {
7607 if (!SystemSupportsOCSP()) { 8337 if (!SystemSupportsOCSP()) {
7608 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; 8338 LOG(WARNING) << "Skipping test because system doesn't support OCSP";
7609 return; 8339 return;
7610 } 8340 }
7611 8341
7612 SpawnedTestServer::SSLOptions ssl_options( 8342 SpawnedTestServer::SSLOptions ssl_options(
7613 SpawnedTestServer::SSLOptions::CERT_AUTO); 8343 SpawnedTestServer::SSLOptions::CERT_AUTO);
7614 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_OK; 8344 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_OK;
7615 8345
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
7659 DoConnection(ssl_options, &cert_status); 8389 DoConnection(ssl_options, &cert_status);
7660 8390
7661 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(), 8391 EXPECT_EQ(ExpectedCertStatusForFailedOnlineRevocationCheck(),
7662 cert_status & CERT_STATUS_ALL_ERRORS); 8392 cert_status & CERT_STATUS_ALL_ERRORS);
7663 8393
7664 // Without a positive OCSP response, we shouldn't show the EV status. 8394 // Without a positive OCSP response, we shouldn't show the EV status.
7665 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); 8395 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
7666 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED); 8396 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
7667 } 8397 }
7668 8398
8399 TEST_F(HTTPSOCSPTest, ValidStapled) {
8400 if (!SystemSupportsOCSPStapling()) {
8401 LOG(WARNING)
8402 << "Skipping test because system doesn't support OCSP stapling";
8403 return;
8404 }
8405
8406 SpawnedTestServer::SSLOptions ssl_options(
8407 SpawnedTestServer::SSLOptions::CERT_AUTO);
8408 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_OK;
8409 ssl_options.staple_ocsp_response = true;
8410 ssl_options.ocsp_server_unavailable = true;
8411
8412 CertStatus cert_status;
8413 DoConnection(ssl_options, &cert_status);
8414
8415 EXPECT_EQ(0u, cert_status & CERT_STATUS_ALL_ERRORS);
8416
8417 EXPECT_EQ(SystemUsesChromiumEVMetadata(),
8418 static_cast<bool>(cert_status & CERT_STATUS_IS_EV));
8419
8420 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
8421 }
8422
8423 TEST_F(HTTPSOCSPTest, RevokedStapled) {
8424 if (!SystemSupportsOCSPStapling()) {
8425 LOG(WARNING)
8426 << "Skipping test because system doesn't support OCSP stapling";
8427 return;
8428 }
8429
8430 SpawnedTestServer::SSLOptions ssl_options(
8431 SpawnedTestServer::SSLOptions::CERT_AUTO);
8432 ssl_options.ocsp_status = SpawnedTestServer::SSLOptions::OCSP_REVOKED;
8433 ssl_options.staple_ocsp_response = true;
8434 ssl_options.ocsp_server_unavailable = true;
8435
8436 CertStatus cert_status;
8437 DoConnection(ssl_options, &cert_status);
8438
8439 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS);
8440 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV);
8441 EXPECT_TRUE(cert_status & CERT_STATUS_REV_CHECKING_ENABLED);
8442 }
8443
7669 class HTTPSHardFailTest : public HTTPSOCSPTest { 8444 class HTTPSHardFailTest : public HTTPSOCSPTest {
7670 protected: 8445 protected:
7671 void SetupContext(URLRequestContext* context) override { 8446 void SetupContext(URLRequestContext* context) override {
7672 context->set_ssl_config_service( 8447 context->set_ssl_config_service(
7673 new TestSSLConfigService(false /* check for EV */, 8448 new TestSSLConfigService(false /* check for EV */,
7674 false /* online revocation checking */, 8449 false /* online revocation checking */,
7675 true /* require rev. checking for local 8450 true /* require rev. checking for local
7676 anchors */)); 8451 anchors */));
7677 } 8452 }
7678 }; 8453 };
7679 8454
7680
7681 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) { 8455 TEST_F(HTTPSHardFailTest, FailsOnOCSPInvalid) {
7682 if (!SystemSupportsOCSP()) { 8456 if (!SystemSupportsOCSP()) {
7683 LOG(WARNING) << "Skipping test because system doesn't support OCSP"; 8457 LOG(WARNING) << "Skipping test because system doesn't support OCSP";
7684 return; 8458 return;
7685 } 8459 }
7686 8460
7687 if (!SystemSupportsHardFailRevocationChecking()) { 8461 if (!SystemSupportsHardFailRevocationChecking()) {
7688 LOG(WARNING) << "Skipping test because system doesn't support hard fail " 8462 LOG(WARNING) << "Skipping test because system doesn't support hard fail "
7689 << "revocation checking"; 8463 << "revocation checking";
7690 return; 8464 return;
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
8287 9061
8288 EXPECT_FALSE(r->is_pending()); 9062 EXPECT_FALSE(r->is_pending());
8289 EXPECT_EQ(1, d->response_started_count()); 9063 EXPECT_EQ(1, d->response_started_count());
8290 EXPECT_FALSE(d->received_data_before_response()); 9064 EXPECT_FALSE(d->received_data_before_response());
8291 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 9065 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8292 } 9066 }
8293 } 9067 }
8294 #endif // !defined(DISABLE_FTP_SUPPORT) 9068 #endif // !defined(DISABLE_FTP_SUPPORT)
8295 9069
8296 } // namespace net 9070 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | net/websockets/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698