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

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

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased on top of URLRequest::Read CL Created 4 years, 3 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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 EXPECT_GT(info.size, 0); 1109 EXPECT_GT(info.size, 0);
1110 std::string sentinel_output = GetDirectoryListingEntry( 1110 std::string sentinel_output = GetDirectoryListingEntry(
1111 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), 1111 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)),
1112 std::string(sentinel_name), 1112 std::string(sentinel_name),
1113 false /* is_dir */, 1113 false /* is_dir */,
1114 info.size, 1114 info.size,
1115 info.last_modified); 1115 info.last_modified);
1116 1116
1117 ASSERT_LT(0, d.bytes_received()); 1117 ASSERT_LT(0, d.bytes_received());
1118 ASSERT_FALSE(d.request_failed()); 1118 ASSERT_FALSE(d.request_failed());
1119 ASSERT_TRUE(req->status().is_success()); 1119 EXPECT_EQ(OK, d.request_status());
1120 // Check for the entry generated for the "sentinel" file. 1120 // Check for the entry generated for the "sentinel" file.
1121 const std::string& data = d.data_received(); 1121 const std::string& data = d.data_received();
1122 ASSERT_NE(data.find(sentinel_output), std::string::npos); 1122 ASSERT_NE(data.find(sentinel_output), std::string::npos);
1123 } 1123 }
1124 1124
1125 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { 1125 TEST_F(URLRequestTest, FileDirRedirectNoCrash) {
1126 // There is an implicit redirect when loading a file path that matches a 1126 // There is an implicit redirect when loading a file path that matches a
1127 // directory and does not end with a slash. Ensure that following such 1127 // directory and does not end with a slash. Ensure that following such
1128 // redirects does not crash. See http://crbug.com/18686. 1128 // redirects does not crash. See http://crbug.com/18686.
1129 1129
1130 base::FilePath path; 1130 base::FilePath path;
1131 PathService::Get(base::DIR_SOURCE_ROOT, &path); 1131 PathService::Get(base::DIR_SOURCE_ROOT, &path);
1132 path = path.Append(kTestFilePath); 1132 path = path.Append(kTestFilePath);
1133 1133
1134 TestDelegate d; 1134 TestDelegate d;
1135 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 1135 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
1136 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); 1136 FilePathToFileURL(path), DEFAULT_PRIORITY, &d));
1137 req->Start(); 1137 req->Start();
1138 base::RunLoop().Run(); 1138 base::RunLoop().Run();
1139 1139
1140 ASSERT_EQ(1, d.received_redirect_count()); 1140 ASSERT_EQ(1, d.received_redirect_count());
1141 ASSERT_LT(0, d.bytes_received()); 1141 ASSERT_LT(0, d.bytes_received());
1142 ASSERT_FALSE(d.request_failed()); 1142 ASSERT_FALSE(d.request_failed());
1143 ASSERT_TRUE(req->status().is_success()); 1143 EXPECT_EQ(OK, d.request_status());
1144 } 1144 }
1145 1145
1146 #if defined(OS_WIN) 1146 #if defined(OS_WIN)
1147 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. 1147 // Don't accept the url "file:///" on windows. See http://crbug.com/1474.
1148 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { 1148 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) {
1149 TestDelegate d; 1149 TestDelegate d;
1150 std::unique_ptr<URLRequest> req( 1150 std::unique_ptr<URLRequest> req(
1151 default_context_.CreateRequest(GURL("file:///"), DEFAULT_PRIORITY, &d)); 1151 default_context_.CreateRequest(GURL("file:///"), DEFAULT_PRIORITY, &d));
1152 req->Start(); 1152 req->Start();
1153 base::RunLoop().Run(); 1153 base::RunLoop().Run();
1154 1154
1155 ASSERT_EQ(1, d.received_redirect_count()); 1155 ASSERT_EQ(1, d.received_redirect_count());
1156 ASSERT_FALSE(req->status().is_success()); 1156 EXPECT_NE(OK, d.request_status());
1157 } 1157 }
1158 #endif // defined(OS_WIN) 1158 #endif // defined(OS_WIN)
1159 1159
1160 #endif // !defined(DISABLE_FILE_SUPPORT) 1160 #endif // !defined(DISABLE_FILE_SUPPORT)
1161 1161
1162 TEST_F(URLRequestTest, InvalidUrlTest) { 1162 TEST_F(URLRequestTest, InvalidUrlTest) {
1163 TestDelegate d; 1163 TestDelegate d;
1164 { 1164 {
1165 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 1165 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
1166 GURL("invalid url"), DEFAULT_PRIORITY, &d)); 1166 GURL("invalid url"), DEFAULT_PRIORITY, &d));
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 req->set_method("GET"); 1608 req->set_method("GET");
1609 req->Start(); 1609 req->Start();
1610 base::RunLoop().Run(); 1610 base::RunLoop().Run();
1611 1611
1612 // Make sure we can retrieve our specific user data. 1612 // Make sure we can retrieve our specific user data.
1613 EXPECT_EQ(user_data0, req->GetUserData(nullptr)); 1613 EXPECT_EQ(user_data0, req->GetUserData(nullptr));
1614 EXPECT_EQ(user_data1, req->GetUserData(&user_data1)); 1614 EXPECT_EQ(user_data1, req->GetUserData(&user_data1));
1615 EXPECT_EQ(user_data2, req->GetUserData(&user_data2)); 1615 EXPECT_EQ(user_data2, req->GetUserData(&user_data2));
1616 1616
1617 // Check that we got one good response. 1617 // Check that we got one good response.
1618 EXPECT_TRUE(req->status().is_success()); 1618 EXPECT_EQ(OK, d.request_status());
1619 EXPECT_EQ(200, req->response_headers()->response_code()); 1619 EXPECT_EQ(200, req->response_headers()->response_code());
1620 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1620 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1621 EXPECT_EQ(1, d.response_started_count()); 1621 EXPECT_EQ(1, d.response_started_count());
1622 EXPECT_EQ(0, d.received_redirect_count()); 1622 EXPECT_EQ(0, d.received_redirect_count());
1623 } 1623 }
1624 1624
1625 TEST_F(URLRequestInterceptorTest, InterceptRedirect) { 1625 TEST_F(URLRequestInterceptorTest, InterceptRedirect) {
1626 // Intercept the main request and respond with a redirect. 1626 // Intercept the main request and respond with a redirect.
1627 interceptor()->set_intercept_main_request(true); 1627 interceptor()->set_intercept_main_request(true);
1628 interceptor()->set_main_headers( 1628 interceptor()->set_main_headers(
(...skipping 10 matching lines...) Expand all
1639 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1639 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1640 req->set_method("GET"); 1640 req->set_method("GET");
1641 req->Start(); 1641 req->Start();
1642 base::RunLoop().Run(); 1642 base::RunLoop().Run();
1643 1643
1644 // Check that the interceptor got called as expected. 1644 // Check that the interceptor got called as expected.
1645 EXPECT_TRUE(interceptor()->did_intercept_main()); 1645 EXPECT_TRUE(interceptor()->did_intercept_main());
1646 EXPECT_TRUE(interceptor()->did_intercept_redirect()); 1646 EXPECT_TRUE(interceptor()->did_intercept_redirect());
1647 1647
1648 // Check that we got one good response. 1648 // Check that we got one good response.
1649 EXPECT_TRUE(req->status().is_success()); 1649 int status = d.request_status();
1650 if (req->status().is_success()) 1650 EXPECT_EQ(OK, status);
1651 if (status == OK)
1651 EXPECT_EQ(200, req->response_headers()->response_code()); 1652 EXPECT_EQ(200, req->response_headers()->response_code());
1652 1653
1653 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1654 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1654 EXPECT_EQ(1, d.response_started_count()); 1655 EXPECT_EQ(1, d.response_started_count());
1655 EXPECT_EQ(0, d.received_redirect_count()); 1656 EXPECT_EQ(0, d.received_redirect_count());
1656 } 1657 }
1657 1658
1658 TEST_F(URLRequestInterceptorTest, InterceptServerError) { 1659 TEST_F(URLRequestInterceptorTest, InterceptServerError) {
1659 // Intercept the main request to generate a server error response. 1660 // Intercept the main request to generate a server error response.
1660 interceptor()->set_intercept_main_request(true); 1661 interceptor()->set_intercept_main_request(true);
(...skipping 10 matching lines...) Expand all
1671 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1672 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1672 req->set_method("GET"); 1673 req->set_method("GET");
1673 req->Start(); 1674 req->Start();
1674 base::RunLoop().Run(); 1675 base::RunLoop().Run();
1675 1676
1676 // Check that the interceptor got called as expected. 1677 // Check that the interceptor got called as expected.
1677 EXPECT_TRUE(interceptor()->did_intercept_main()); 1678 EXPECT_TRUE(interceptor()->did_intercept_main());
1678 EXPECT_TRUE(interceptor()->did_intercept_final()); 1679 EXPECT_TRUE(interceptor()->did_intercept_final());
1679 1680
1680 // Check that we got one good response. 1681 // Check that we got one good response.
1681 EXPECT_TRUE(req->status().is_success()); 1682 EXPECT_EQ(OK, d.request_status());
1682 EXPECT_EQ(200, req->response_headers()->response_code()); 1683 EXPECT_EQ(200, req->response_headers()->response_code());
1683 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1684 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1684 EXPECT_EQ(1, d.response_started_count()); 1685 EXPECT_EQ(1, d.response_started_count());
1685 EXPECT_EQ(0, d.received_redirect_count()); 1686 EXPECT_EQ(0, d.received_redirect_count());
1686 } 1687 }
1687 1688
1688 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) { 1689 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) {
1689 // Intercept the main request to simulate a network error. 1690 // Intercept the main request to simulate a network error.
1690 interceptor()->set_simulate_main_network_error(true); 1691 interceptor()->set_simulate_main_network_error(true);
1691 1692
1692 // Intercept that error and respond with an OK response. 1693 // Intercept that error and respond with an OK response.
1693 interceptor()->set_intercept_final_response(true); 1694 interceptor()->set_intercept_final_response(true);
1694 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1695 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1695 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1696 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1696 1697
1697 TestDelegate d; 1698 TestDelegate d;
1698 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 1699 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
1699 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1700 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1700 req->set_method("GET"); 1701 req->set_method("GET");
1701 req->Start(); 1702 req->Start();
1702 base::RunLoop().Run(); 1703 base::RunLoop().Run();
1703 1704
1704 // Check that the interceptor got called as expected. 1705 // Check that the interceptor got called as expected.
1705 EXPECT_TRUE(interceptor()->did_simulate_error_main()); 1706 EXPECT_TRUE(interceptor()->did_simulate_error_main());
1706 EXPECT_TRUE(interceptor()->did_intercept_final()); 1707 EXPECT_TRUE(interceptor()->did_intercept_final());
1707 1708
1708 // Check that we received one good response. 1709 // Check that we received one good response.
1709 EXPECT_TRUE(req->status().is_success()); 1710 EXPECT_EQ(OK, d.request_status());
1710 EXPECT_EQ(200, req->response_headers()->response_code()); 1711 EXPECT_EQ(200, req->response_headers()->response_code());
1711 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1712 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1712 EXPECT_EQ(1, d.response_started_count()); 1713 EXPECT_EQ(1, d.response_started_count());
1713 EXPECT_EQ(0, d.received_redirect_count()); 1714 EXPECT_EQ(0, d.received_redirect_count());
1714 } 1715 }
1715 1716
1716 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) { 1717 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) {
1717 // Restart the main request. 1718 // Restart the main request.
1718 interceptor()->set_restart_main_request(true); 1719 interceptor()->set_restart_main_request(true);
1719 1720
1720 // then intercept the new main request and respond with an OK response 1721 // then intercept the new main request and respond with an OK response
1721 interceptor()->set_intercept_main_request(true); 1722 interceptor()->set_intercept_main_request(true);
1722 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); 1723 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
1723 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); 1724 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
1724 1725
1725 TestDelegate d; 1726 TestDelegate d;
1726 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 1727 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
1727 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1728 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1728 req->set_method("GET"); 1729 req->set_method("GET");
1729 req->Start(); 1730 req->Start();
1730 base::RunLoop().Run(); 1731 base::RunLoop().Run();
1731 1732
1732 // Check that the interceptor got called as expected. 1733 // Check that the interceptor got called as expected.
1733 EXPECT_TRUE(interceptor()->did_restart_main()); 1734 EXPECT_TRUE(interceptor()->did_restart_main());
1734 EXPECT_TRUE(interceptor()->did_intercept_main()); 1735 EXPECT_TRUE(interceptor()->did_intercept_main());
1735 1736
1736 // Check that we received one good response. 1737 // Check that we received one good response.
1737 EXPECT_TRUE(req->status().is_success()); 1738 int status = d.request_status();
1738 if (req->status().is_success()) 1739 EXPECT_EQ(OK, status);
1740 if (status == OK)
1739 EXPECT_EQ(200, req->response_headers()->response_code()); 1741 EXPECT_EQ(200, req->response_headers()->response_code());
1740 1742
1741 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1743 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1742 EXPECT_EQ(1, d.response_started_count()); 1744 EXPECT_EQ(1, d.response_started_count());
1743 EXPECT_EQ(0, d.received_redirect_count()); 1745 EXPECT_EQ(0, d.received_redirect_count());
1744 } 1746 }
1745 1747
1746 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) { 1748 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) {
1747 // Intercept the main request and cancel from within the restarted job. 1749 // Intercept the main request and cancel from within the restarted job.
1748 interceptor()->set_cancel_main_request(true); 1750 interceptor()->set_cancel_main_request(true);
1749 1751
1750 // Set up to intercept the final response and override it with an OK response. 1752 // Set up to intercept the final response and override it with an OK response.
1751 interceptor()->set_intercept_final_response(true); 1753 interceptor()->set_intercept_final_response(true);
1752 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1754 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1753 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1755 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1754 1756
1755 TestDelegate d; 1757 TestDelegate d;
1756 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 1758 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
1757 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1759 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1758 req->set_method("GET"); 1760 req->set_method("GET");
1759 req->Start(); 1761 req->Start();
1760 base::RunLoop().Run(); 1762 base::RunLoop().Run();
1761 1763
1762 // Check that the interceptor got called as expected. 1764 // Check that the interceptor got called as expected.
1763 EXPECT_TRUE(interceptor()->did_cancel_main()); 1765 EXPECT_TRUE(interceptor()->did_cancel_main());
1764 EXPECT_FALSE(interceptor()->did_intercept_final()); 1766 EXPECT_FALSE(interceptor()->did_intercept_final());
1765 1767
1766 // Check that we see a canceled request. 1768 // Check that we see a canceled request.
1767 EXPECT_FALSE(req->status().is_success()); 1769 EXPECT_EQ(ERR_ABORTED, d.request_status());
1768 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1769 } 1770 }
1770 1771
1771 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelRedirect) { 1772 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelRedirect) {
1772 // Intercept the main request and respond with a redirect. 1773 // Intercept the main request and respond with a redirect.
1773 interceptor()->set_intercept_main_request(true); 1774 interceptor()->set_intercept_main_request(true);
1774 interceptor()->set_main_headers( 1775 interceptor()->set_main_headers(
1775 MockURLRequestInterceptor::redirect_headers()); 1776 MockURLRequestInterceptor::redirect_headers());
1776 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); 1777 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data());
1777 1778
1778 // Intercept the redirect and cancel from within that job. 1779 // Intercept the redirect and cancel from within that job.
(...skipping 10 matching lines...) Expand all
1789 req->set_method("GET"); 1790 req->set_method("GET");
1790 req->Start(); 1791 req->Start();
1791 base::RunLoop().Run(); 1792 base::RunLoop().Run();
1792 1793
1793 // Check that the interceptor got called as expected. 1794 // Check that the interceptor got called as expected.
1794 EXPECT_TRUE(interceptor()->did_intercept_main()); 1795 EXPECT_TRUE(interceptor()->did_intercept_main());
1795 EXPECT_TRUE(interceptor()->did_cancel_redirect()); 1796 EXPECT_TRUE(interceptor()->did_cancel_redirect());
1796 EXPECT_FALSE(interceptor()->did_intercept_final()); 1797 EXPECT_FALSE(interceptor()->did_intercept_final());
1797 1798
1798 // Check that we see a canceled request. 1799 // Check that we see a canceled request.
1799 EXPECT_FALSE(req->status().is_success()); 1800 EXPECT_EQ(ERR_ABORTED, d.request_status());
1800 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1801 } 1801 }
1802 1802
1803 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) { 1803 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) {
1804 // Intercept the main request to simulate a network error. 1804 // Intercept the main request to simulate a network error.
1805 interceptor()->set_simulate_main_network_error(true); 1805 interceptor()->set_simulate_main_network_error(true);
1806 1806
1807 // Set up to intercept final the response and cancel from within that job. 1807 // Set up to intercept final the response and cancel from within that job.
1808 interceptor()->set_cancel_final_request(true); 1808 interceptor()->set_cancel_final_request(true);
1809 1809
1810 TestDelegate d; 1810 TestDelegate d;
1811 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 1811 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
1812 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1812 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1813 req->set_method("GET"); 1813 req->set_method("GET");
1814 req->Start(); 1814 req->Start();
1815 base::RunLoop().Run(); 1815 base::RunLoop().Run();
1816 1816
1817 // Check that the interceptor got called as expected. 1817 // Check that the interceptor got called as expected.
1818 EXPECT_TRUE(interceptor()->did_simulate_error_main()); 1818 EXPECT_TRUE(interceptor()->did_simulate_error_main());
1819 EXPECT_TRUE(interceptor()->did_cancel_final()); 1819 EXPECT_TRUE(interceptor()->did_cancel_final());
1820 1820
1821 // Check that we see a canceled request. 1821 // Check that we see a canceled request.
1822 EXPECT_FALSE(req->status().is_success()); 1822 EXPECT_EQ(ERR_ABORTED, d.request_status());
1823 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1824 } 1823 }
1825 1824
1826 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) { 1825 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) {
1827 // Intercept the main request and cancel then restart from within that job. 1826 // Intercept the main request and cancel then restart from within that job.
1828 interceptor()->set_cancel_then_restart_main_request(true); 1827 interceptor()->set_cancel_then_restart_main_request(true);
1829 1828
1830 // Set up to intercept the final response and override it with an OK response. 1829 // Set up to intercept the final response and override it with an OK response.
1831 interceptor()->set_intercept_final_response(true); 1830 interceptor()->set_intercept_final_response(true);
1832 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1831 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1833 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1832 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1834 1833
1835 TestDelegate d; 1834 TestDelegate d;
1836 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 1835 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
1837 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 1836 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1838 req->set_method("GET"); 1837 req->set_method("GET");
1839 req->Start(); 1838 req->Start();
1840 base::RunLoop().Run(); 1839 base::RunLoop().Run();
1841 1840
1842 // Check that the interceptor got called as expected. 1841 // Check that the interceptor got called as expected.
1843 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main()); 1842 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main());
1844 EXPECT_FALSE(interceptor()->did_intercept_final()); 1843 EXPECT_FALSE(interceptor()->did_intercept_final());
1845 1844
1846 // Check that we see a canceled request. 1845 // Check that we see a canceled request.
1847 EXPECT_FALSE(req->status().is_success()); 1846 EXPECT_EQ(ERR_ABORTED, d.request_status());
1848 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1849 } 1847 }
1850 1848
1851 // "Normal" LoadTimingInfo as returned by a job. Everything is in order, not 1849 // "Normal" LoadTimingInfo as returned by a job. Everything is in order, not
1852 // reused. |connect_time_flags| is used to indicate if there should be dns 1850 // reused. |connect_time_flags| is used to indicate if there should be dns
1853 // or SSL times, and |used_proxy| is used for proxy times. 1851 // or SSL times, and |used_proxy| is used for proxy times.
1854 LoadTimingInfo NormalLoadTimingInfo(base::TimeTicks now, 1852 LoadTimingInfo NormalLoadTimingInfo(base::TimeTicks now,
1855 int connect_time_flags, 1853 int connect_time_flags,
1856 bool used_proxy) { 1854 bool used_proxy) {
1857 LoadTimingInfo load_timing; 1855 LoadTimingInfo load_timing;
1858 load_timing.socket_log_id = 1; 1856 load_timing.socket_log_id = 1;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 2146
2149 TestDelegate d; 2147 TestDelegate d;
2150 std::unique_ptr<URLRequest> req( 2148 std::unique_ptr<URLRequest> req(
2151 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); 2149 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2152 req->set_method("GET"); 2150 req->set_method("GET");
2153 2151
2154 req->Start(); 2152 req->Start();
2155 base::RunLoop().Run(); 2153 base::RunLoop().Run();
2156 2154
2157 // Check we see a failed request. 2155 // Check we see a failed request.
2158 EXPECT_FALSE(req->status().is_success());
2159 // The proxy server is not set before failure. 2156 // The proxy server is not set before failure.
2160 EXPECT_TRUE(req->proxy_server().IsEmpty()); 2157 EXPECT_TRUE(req->proxy_server().IsEmpty());
2161 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 2158 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status());
2162 EXPECT_THAT(req->status().error(), IsError(ERR_PROXY_CONNECTION_FAILED));
2163 2159
2164 EXPECT_EQ(1, network_delegate.error_count()); 2160 EXPECT_EQ(1, network_delegate.error_count());
2165 EXPECT_THAT(network_delegate.last_error(), 2161 EXPECT_THAT(network_delegate.last_error(),
2166 IsError(ERR_PROXY_CONNECTION_FAILED)); 2162 IsError(ERR_PROXY_CONNECTION_FAILED));
2167 EXPECT_EQ(1, network_delegate.completed_requests()); 2163 EXPECT_EQ(1, network_delegate.completed_requests());
2168 } 2164 }
2169 2165
2170 // Make sure that NetworkDelegate::NotifyCompleted is called if 2166 // Make sure that NetworkDelegate::NotifyCompleted is called if
2171 // content is empty. 2167 // content is empty.
2172 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { 2168 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
3005 TestDelegate d; 3001 TestDelegate d;
3006 // Request that just hangs. 3002 // Request that just hangs.
3007 GURL url(URLRequestFailedJob::GetMockHttpUrl(ERR_IO_PENDING)); 3003 GURL url(URLRequestFailedJob::GetMockHttpUrl(ERR_IO_PENDING));
3008 std::unique_ptr<URLRequest> r( 3004 std::unique_ptr<URLRequest> r(
3009 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); 3005 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
3010 r->Start(); 3006 r->Start();
3011 3007
3012 power_monitor_source->Suspend(); 3008 power_monitor_source->Suspend();
3013 // Wait for the suspend notification to cause the request to fail. 3009 // Wait for the suspend notification to cause the request to fail.
3014 base::RunLoop().Run(); 3010 base::RunLoop().Run();
3015 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 3011 EXPECT_EQ(ERR_ABORTED, d.request_status());
3016 EXPECT_TRUE(d.request_failed()); 3012 EXPECT_TRUE(d.request_failed());
3017 EXPECT_EQ(1, default_network_delegate_.completed_requests()); 3013 EXPECT_EQ(1, default_network_delegate_.completed_requests());
3018 3014
3019 URLRequestFilter::GetInstance()->ClearHandlers(); 3015 URLRequestFilter::GetInstance()->ClearHandlers();
3020 3016
3021 // Shouldn't be needed, but just in case. 3017 // Shouldn't be needed, but just in case.
3022 power_monitor_source->Resume(); 3018 power_monitor_source->Resume();
3023 } 3019 }
3024 3020
3025 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header 3021 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3190 req->set_upload(CreateSimpleUploadData(kData)); 3186 req->set_upload(CreateSimpleUploadData(kData));
3191 HttpRequestHeaders headers; 3187 HttpRequestHeaders headers;
3192 headers.SetHeader(HttpRequestHeaders::kContentLength, 3188 headers.SetHeader(HttpRequestHeaders::kContentLength,
3193 base::SizeTToString(arraysize(kData) - 1)); 3189 base::SizeTToString(arraysize(kData) - 1));
3194 headers.SetHeader(HttpRequestHeaders::kContentType, "text/plain"); 3190 headers.SetHeader(HttpRequestHeaders::kContentType, "text/plain");
3195 req->SetExtraRequestHeaders(headers); 3191 req->SetExtraRequestHeaders(headers);
3196 } 3192 }
3197 req->Start(); 3193 req->Start();
3198 base::RunLoop().Run(); 3194 base::RunLoop().Run();
3199 EXPECT_EQ(redirect_method, req->method()); 3195 EXPECT_EQ(redirect_method, req->method());
3200 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 3196 EXPECT_EQ(OK, d.request_status());
3201 EXPECT_THAT(req->status().error(), IsOk());
3202 if (include_data) { 3197 if (include_data) {
3203 if (request_method == redirect_method) { 3198 if (request_method == redirect_method) {
3204 EXPECT_TRUE(req->extra_request_headers().HasHeader( 3199 EXPECT_TRUE(req->extra_request_headers().HasHeader(
3205 HttpRequestHeaders::kContentLength)); 3200 HttpRequestHeaders::kContentLength));
3206 EXPECT_TRUE(req->extra_request_headers().HasHeader( 3201 EXPECT_TRUE(req->extra_request_headers().HasHeader(
3207 HttpRequestHeaders::kContentType)); 3202 HttpRequestHeaders::kContentType));
3208 EXPECT_EQ(kData, d.data_received()); 3203 EXPECT_EQ(kData, d.data_received());
3209 } else { 3204 } else {
3210 EXPECT_FALSE(req->extra_request_headers().HasHeader( 3205 EXPECT_FALSE(req->extra_request_headers().HasHeader(
3211 HttpRequestHeaders::kContentLength)); 3206 HttpRequestHeaders::kContentLength));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3280 test_server_.GetURL("/echo"), DEFAULT_PRIORITY, &d)); 3275 test_server_.GetURL("/echo"), DEFAULT_PRIORITY, &d));
3281 r->set_method(method.c_str()); 3276 r->set_method(method.c_str());
3282 3277
3283 r->set_upload(CreateSimpleUploadData(uploadBytes)); 3278 r->set_upload(CreateSimpleUploadData(uploadBytes));
3284 3279
3285 r->Start(); 3280 r->Start();
3286 EXPECT_TRUE(r->is_pending()); 3281 EXPECT_TRUE(r->is_pending());
3287 3282
3288 base::RunLoop().Run(); 3283 base::RunLoop().Run();
3289 3284
3290 ASSERT_EQ(1, d.response_started_count()) 3285 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: "
3291 << "request failed: " << r->status().status() 3286 << d.request_status();
3292 << ", os error: " << r->status().error();
3293 3287
3294 EXPECT_FALSE(d.received_data_before_response()); 3288 EXPECT_FALSE(d.received_data_before_response());
3295 EXPECT_EQ(uploadBytes, d.data_received()); 3289 EXPECT_EQ(uploadBytes, d.data_received());
3296 } 3290 }
3297 delete[] uploadBytes; 3291 delete[] uploadBytes;
3298 } 3292 }
3299 3293
3300 bool DoManyCookiesRequest(int num_cookies) { 3294 bool DoManyCookiesRequest(int num_cookies) {
3301 TestDelegate d; 3295 TestDelegate d;
3302 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 3296 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
3303 test_server_.GetURL("/set-many-cookies?" + 3297 test_server_.GetURL("/set-many-cookies?" +
3304 base::IntToString(num_cookies)), 3298 base::IntToString(num_cookies)),
3305 DEFAULT_PRIORITY, &d)); 3299 DEFAULT_PRIORITY, &d));
3306 3300
3307 r->Start(); 3301 r->Start();
3308 EXPECT_TRUE(r->is_pending()); 3302 EXPECT_TRUE(r->is_pending());
3309 3303
3310 base::RunLoop().Run(); 3304 base::RunLoop().Run();
3311 3305
3312 bool is_success = r->status().is_success(); 3306 if (d.request_status() != OK) {
3307 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, d.request_status());
3308 return false;
3309 }
3313 3310
3314 if (!is_success) 3311 return true;
3315 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG);
3316
3317 return is_success;
3318 } 3312 }
3319 3313
3320 LocalHttpTestServer* http_test_server() { return &test_server_; } 3314 LocalHttpTestServer* http_test_server() { return &test_server_; }
3321 3315
3322 private: 3316 private:
3323 LocalHttpTestServer test_server_; 3317 LocalHttpTestServer test_server_;
3324 }; 3318 };
3325 3319
3326 namespace { 3320 namespace {
3327 3321
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3411 3405
3412 TestDelegate d; 3406 TestDelegate d;
3413 { 3407 {
3414 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 3408 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
3415 https_test_server.GetURL("tokbind-ekm"), DEFAULT_PRIORITY, &d)); 3409 https_test_server.GetURL("tokbind-ekm"), DEFAULT_PRIORITY, &d));
3416 r->Start(); 3410 r->Start();
3417 EXPECT_TRUE(r->is_pending()); 3411 EXPECT_TRUE(r->is_pending());
3418 3412
3419 base::RunLoop().Run(); 3413 base::RunLoop().Run();
3420 3414
3421 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3415 EXPECT_EQ(OK, d.request_status());
3422 3416
3423 HttpRequestHeaders headers; 3417 HttpRequestHeaders headers;
3424 std::string token_binding_header, token_binding_message; 3418 std::string token_binding_header, token_binding_message;
3425 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 3419 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3426 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding, 3420 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding,
3427 &token_binding_header)); 3421 &token_binding_header));
3428 EXPECT_TRUE(base::Base64UrlDecode( 3422 EXPECT_TRUE(base::Base64UrlDecode(
3429 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING, 3423 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING,
3430 &token_binding_message)); 3424 &token_binding_message));
3431 std::vector<TokenBinding> token_bindings; 3425 std::vector<TokenBinding> token_bindings;
(...skipping 22 matching lines...) Expand all
3454 { 3448 {
3455 GURL redirect_url = 3449 GURL redirect_url =
3456 https_test_server.GetURL("forward-tokbind?/tokbind-ekm"); 3450 https_test_server.GetURL("forward-tokbind?/tokbind-ekm");
3457 std::unique_ptr<URLRequest> r( 3451 std::unique_ptr<URLRequest> r(
3458 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); 3452 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
3459 r->Start(); 3453 r->Start();
3460 EXPECT_TRUE(r->is_pending()); 3454 EXPECT_TRUE(r->is_pending());
3461 3455
3462 base::RunLoop().Run(); 3456 base::RunLoop().Run();
3463 3457
3464 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3458 EXPECT_EQ(OK, d.request_status());
3465 3459
3466 HttpRequestHeaders headers; 3460 HttpRequestHeaders headers;
3467 std::string token_binding_header, token_binding_message; 3461 std::string token_binding_header, token_binding_message;
3468 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 3462 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3469 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding, 3463 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding,
3470 &token_binding_header)); 3464 &token_binding_header));
3471 EXPECT_TRUE(base::Base64UrlDecode( 3465 EXPECT_TRUE(base::Base64UrlDecode(
3472 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING, 3466 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING,
3473 &token_binding_message)); 3467 &token_binding_message));
3474 std::vector<TokenBinding> token_bindings; 3468 std::vector<TokenBinding> token_bindings;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3507 { 3501 {
3508 GURL redirect_url = http_server.GetURL( 3502 GURL redirect_url = http_server.GetURL(
3509 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); 3503 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec());
3510 std::unique_ptr<URLRequest> r( 3504 std::unique_ptr<URLRequest> r(
3511 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); 3505 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
3512 r->Start(); 3506 r->Start();
3513 EXPECT_TRUE(r->is_pending()); 3507 EXPECT_TRUE(r->is_pending());
3514 3508
3515 base::RunLoop().Run(); 3509 base::RunLoop().Run();
3516 3510
3517 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3511 EXPECT_EQ(OK, d.request_status());
3518 3512
3519 HttpRequestHeaders headers; 3513 HttpRequestHeaders headers;
3520 std::string token_binding_header, token_binding_message; 3514 std::string token_binding_header, token_binding_message;
3521 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 3515 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3522 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding, 3516 EXPECT_TRUE(headers.GetHeader(HttpRequestHeaders::kTokenBinding,
3523 &token_binding_header)); 3517 &token_binding_header));
3524 EXPECT_TRUE(base::Base64UrlDecode( 3518 EXPECT_TRUE(base::Base64UrlDecode(
3525 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING, 3519 token_binding_header, base::Base64UrlDecodePolicy::REQUIRE_PADDING,
3526 &token_binding_message)); 3520 &token_binding_message));
3527 std::vector<TokenBinding> token_bindings; 3521 std::vector<TokenBinding> token_bindings;
(...skipping 30 matching lines...) Expand all
3558 { 3552 {
3559 GURL redirect_url = token_binding_test_server.GetURL( 3553 GURL redirect_url = token_binding_test_server.GetURL(
3560 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); 3554 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec());
3561 std::unique_ptr<URLRequest> r( 3555 std::unique_ptr<URLRequest> r(
3562 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); 3556 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
3563 r->Start(); 3557 r->Start();
3564 EXPECT_TRUE(r->is_pending()); 3558 EXPECT_TRUE(r->is_pending());
3565 3559
3566 base::RunLoop().Run(); 3560 base::RunLoop().Run();
3567 3561
3568 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3562 EXPECT_EQ(OK, d.request_status());
3569 3563
3570 HttpRequestHeaders headers; 3564 HttpRequestHeaders headers;
3571 std::string token_binding_header, token_binding_message; 3565 std::string token_binding_header, token_binding_message;
3572 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 3566 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3573 EXPECT_FALSE(headers.GetHeader(HttpRequestHeaders::kTokenBinding, 3567 EXPECT_FALSE(headers.GetHeader(HttpRequestHeaders::kTokenBinding,
3574 &token_binding_header)); 3568 &token_binding_header));
3575 } 3569 }
3576 } 3570 }
3577 #endif // !defined(OS_ANDROID) 3571 #endif // !defined(OS_ANDROID)
3578 #endif // !defined(OS_IOS) 3572 #endif // !defined(OS_IOS)
(...skipping 13 matching lines...) Expand all
3592 3586
3593 TestDelegate d; 3587 TestDelegate d;
3594 { 3588 {
3595 std::unique_ptr<URLRequest> r(context.CreateRequest( 3589 std::unique_ptr<URLRequest> r(context.CreateRequest(
3596 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3590 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3597 r->Start(); 3591 r->Start();
3598 EXPECT_TRUE(r->is_pending()); 3592 EXPECT_TRUE(r->is_pending());
3599 3593
3600 base::RunLoop().Run(); 3594 base::RunLoop().Run();
3601 3595
3602 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3603 // The proxy server is not set before failure. 3596 // The proxy server is not set before failure.
3604 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3597 EXPECT_TRUE(r->proxy_server().IsEmpty());
3605 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3598 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
3606 EXPECT_EQ(1, d.response_started_count()); 3599 EXPECT_EQ(1, d.response_started_count());
3607 // We should not have followed the redirect. 3600 // We should not have followed the redirect.
3608 EXPECT_EQ(0, d.received_redirect_count()); 3601 EXPECT_EQ(0, d.received_redirect_count());
3609 } 3602 }
3610 } 3603 }
3611 3604
3612 // This is the same as the previous test, but checks that the network delegate 3605 // This is the same as the previous test, but checks that the network delegate
3613 // registers the error. 3606 // registers the error.
3614 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 3607 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
3615 ASSERT_TRUE(http_test_server()->Start()); 3608 ASSERT_TRUE(http_test_server()->Start());
3616 3609
3617 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3610 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3618 TestURLRequestContextWithProxy context( 3611 TestURLRequestContextWithProxy context(
3619 http_test_server()->host_port_pair().ToString(), &network_delegate); 3612 http_test_server()->host_port_pair().ToString(), &network_delegate);
3620 3613
3621 TestDelegate d; 3614 TestDelegate d;
3622 { 3615 {
3623 std::unique_ptr<URLRequest> r(context.CreateRequest( 3616 std::unique_ptr<URLRequest> r(context.CreateRequest(
3624 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); 3617 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
3625 r->Start(); 3618 r->Start();
3626 EXPECT_TRUE(r->is_pending()); 3619 EXPECT_TRUE(r->is_pending());
3627 3620
3628 base::RunLoop().Run(); 3621 base::RunLoop().Run();
3629 3622
3630 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3631 // The proxy server is not set before failure. 3623 // The proxy server is not set before failure.
3632 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3624 EXPECT_TRUE(r->proxy_server().IsEmpty());
3633 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED));
3634 EXPECT_EQ(1, d.response_started_count()); 3625 EXPECT_EQ(1, d.response_started_count());
3626 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
3635 // We should not have followed the redirect. 3627 // We should not have followed the redirect.
3636 EXPECT_EQ(0, d.received_redirect_count()); 3628 EXPECT_EQ(0, d.received_redirect_count());
3637 3629
3638 EXPECT_EQ(1, network_delegate.error_count()); 3630 EXPECT_EQ(1, network_delegate.error_count());
3639 EXPECT_THAT(network_delegate.last_error(), 3631 EXPECT_THAT(network_delegate.last_error(),
3640 IsError(ERR_TUNNEL_CONNECTION_FAILED)); 3632 IsError(ERR_TUNNEL_CONNECTION_FAILED));
3641 } 3633 }
3642 } 3634 }
3643 3635
3644 // Tests that we can block and asynchronously return OK in various stages. 3636 // Tests that we can block and asynchronously return OK in various stages.
(...skipping 25 matching lines...) Expand all
3670 3662
3671 r->Start(); 3663 r->Start();
3672 for (size_t i = 0; i < blocking_stages_length; ++i) { 3664 for (size_t i = 0; i < blocking_stages_length; ++i) {
3673 base::RunLoop().Run(); 3665 base::RunLoop().Run();
3674 EXPECT_EQ(blocking_stages[i], 3666 EXPECT_EQ(blocking_stages[i],
3675 network_delegate.stage_blocked_for_callback()); 3667 network_delegate.stage_blocked_for_callback());
3676 network_delegate.DoCallback(OK); 3668 network_delegate.DoCallback(OK);
3677 } 3669 }
3678 base::RunLoop().Run(); 3670 base::RunLoop().Run();
3679 EXPECT_EQ(200, r->GetResponseCode()); 3671 EXPECT_EQ(200, r->GetResponseCode());
3680 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3672 EXPECT_EQ(OK, d.request_status());
3681 EXPECT_EQ(1, network_delegate.created_requests()); 3673 EXPECT_EQ(1, network_delegate.created_requests());
3682 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3674 EXPECT_EQ(0, network_delegate.destroyed_requests());
3683 } 3675 }
3684 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3676 EXPECT_EQ(1, network_delegate.destroyed_requests());
3685 } 3677 }
3686 3678
3687 // Tests that the network delegate can block and cancel a request. 3679 // Tests that the network delegate can block and cancel a request.
3688 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { 3680 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
3689 ASSERT_TRUE(http_test_server()->Start()); 3681 ASSERT_TRUE(http_test_server()->Start());
3690 3682
3691 TestDelegate d; 3683 TestDelegate d;
3692 BlockingNetworkDelegate network_delegate( 3684 BlockingNetworkDelegate network_delegate(
3693 BlockingNetworkDelegate::AUTO_CALLBACK); 3685 BlockingNetworkDelegate::AUTO_CALLBACK);
3694 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3686 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3695 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 3687 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
3696 3688
3697 TestURLRequestContextWithProxy context( 3689 TestURLRequestContextWithProxy context(
3698 http_test_server()->host_port_pair().ToString(), &network_delegate); 3690 http_test_server()->host_port_pair().ToString(), &network_delegate);
3699 3691
3700 { 3692 {
3701 std::unique_ptr<URLRequest> r(context.CreateRequest( 3693 std::unique_ptr<URLRequest> r(context.CreateRequest(
3702 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 3694 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
3703 3695
3704 r->Start(); 3696 r->Start();
3705 base::RunLoop().Run(); 3697 base::RunLoop().Run();
3706 3698
3707 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3708 // The proxy server is not set before cancellation. 3699 // The proxy server is not set before cancellation.
3709 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3700 EXPECT_TRUE(r->proxy_server().IsEmpty());
3710 EXPECT_THAT(r->status().error(), IsError(ERR_EMPTY_RESPONSE)); 3701 EXPECT_EQ(ERR_EMPTY_RESPONSE, d.request_status());
3711 EXPECT_EQ(1, network_delegate.created_requests()); 3702 EXPECT_EQ(1, network_delegate.created_requests());
3712 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3703 EXPECT_EQ(0, network_delegate.destroyed_requests());
3713 } 3704 }
3714 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3705 EXPECT_EQ(1, network_delegate.destroyed_requests());
3715 } 3706 }
3716 3707
3717 // Helper function for NetworkDelegateCancelRequestAsynchronously and 3708 // Helper function for NetworkDelegateCancelRequestAsynchronously and
3718 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network 3709 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network
3719 // delegate operating in |block_mode| and a request for |url|. It blocks the 3710 // delegate operating in |block_mode| and a request for |url|. It blocks the
3720 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. 3711 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT.
3721 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, 3712 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode,
3722 BlockingNetworkDelegate::Stage stage, 3713 BlockingNetworkDelegate::Stage stage,
3723 const GURL& url) { 3714 const GURL& url) {
3724 TestDelegate d; 3715 TestDelegate d;
3725 BlockingNetworkDelegate network_delegate(block_mode); 3716 BlockingNetworkDelegate network_delegate(block_mode);
3726 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); 3717 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT);
3727 network_delegate.set_block_on(stage); 3718 network_delegate.set_block_on(stage);
3728 3719
3729 TestURLRequestContext context(true); 3720 TestURLRequestContext context(true);
3730 context.set_network_delegate(&network_delegate); 3721 context.set_network_delegate(&network_delegate);
3731 context.Init(); 3722 context.Init();
3732 3723
3733 { 3724 {
3734 std::unique_ptr<URLRequest> r( 3725 std::unique_ptr<URLRequest> r(
3735 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 3726 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3736 3727
3737 r->Start(); 3728 r->Start();
3738 base::RunLoop().Run(); 3729 base::RunLoop().Run();
3739 3730
3740 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3741 // The proxy server is not set before cancellation. 3731 // The proxy server is not set before cancellation.
3742 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3732 EXPECT_TRUE(r->proxy_server().IsEmpty());
3743 EXPECT_THAT(r->status().error(), IsError(ERR_BLOCKED_BY_CLIENT)); 3733 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, d.request_status());
3744 EXPECT_EQ(1, network_delegate.created_requests()); 3734 EXPECT_EQ(1, network_delegate.created_requests());
3745 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3735 EXPECT_EQ(0, network_delegate.destroyed_requests());
3746 } 3736 }
3747 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3737 EXPECT_EQ(1, network_delegate.destroyed_requests());
3748 } 3738 }
3749 3739
3750 // The following 3 tests check that the network delegate can cancel a request 3740 // The following 3 tests check that the network delegate can cancel a request
3751 // synchronously in various stages of the request. 3741 // synchronously in various stages of the request.
3752 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { 3742 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) {
3753 ASSERT_TRUE(http_test_server()->Start()); 3743 ASSERT_TRUE(http_test_server()->Start());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3812 GURL original_url(http_test_server()->GetURL("/defaultresponse")); 3802 GURL original_url(http_test_server()->GetURL("/defaultresponse"));
3813 std::unique_ptr<URLRequest> r( 3803 std::unique_ptr<URLRequest> r(
3814 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 3804 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3815 3805
3816 // Quit after hitting the redirect, so can check the headers. 3806 // Quit after hitting the redirect, so can check the headers.
3817 d.set_quit_on_redirect(true); 3807 d.set_quit_on_redirect(true);
3818 r->Start(); 3808 r->Start();
3819 base::RunLoop().Run(); 3809 base::RunLoop().Run();
3820 3810
3821 // Check headers from URLRequestJob. 3811 // Check headers from URLRequestJob.
3822 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3823 EXPECT_EQ(307, r->GetResponseCode()); 3812 EXPECT_EQ(307, r->GetResponseCode());
3824 EXPECT_EQ(307, r->response_headers()->response_code()); 3813 EXPECT_EQ(307, r->response_headers()->response_code());
3825 std::string location; 3814 std::string location;
3826 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3815 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3827 &location)); 3816 &location));
3828 EXPECT_EQ(redirect_url, GURL(location)); 3817 EXPECT_EQ(redirect_url, GURL(location));
3829 3818
3830 // Let the request finish. 3819 // Let the request finish.
3831 r->FollowDeferredRedirect(); 3820 r->FollowDeferredRedirect();
3832 base::RunLoop().Run(); 3821 base::RunLoop().Run();
3833 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3822 EXPECT_EQ(OK, d.request_status());
3834 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3823 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair()));
3835 // before_send_headers_with_proxy_count only increments for headers sent 3824 // before_send_headers_with_proxy_count only increments for headers sent
3836 // through an untunneled proxy. 3825 // through an untunneled proxy.
3837 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3826 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3838 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3827 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3839 http_test_server()->host_port_pair())); 3828 http_test_server()->host_port_pair()));
3840 3829
3841 EXPECT_EQ(0, r->status().error()); 3830 EXPECT_EQ(OK, d.request_status());
3842 EXPECT_EQ(redirect_url, r->url()); 3831 EXPECT_EQ(redirect_url, r->url());
3843 EXPECT_EQ(original_url, r->original_url()); 3832 EXPECT_EQ(original_url, r->original_url());
3844 EXPECT_EQ(2U, r->url_chain().size()); 3833 EXPECT_EQ(2U, r->url_chain().size());
3845 EXPECT_EQ(1, network_delegate.created_requests()); 3834 EXPECT_EQ(1, network_delegate.created_requests());
3846 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3835 EXPECT_EQ(0, network_delegate.destroyed_requests());
3847 } 3836 }
3848 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3837 EXPECT_EQ(1, network_delegate.destroyed_requests());
3849 } 3838 }
3850 3839
3851 // Tests that the network delegate can block and redirect a request to a new 3840 // Tests that the network delegate can block and redirect a request to a new
(...skipping 14 matching lines...) Expand all
3866 GURL original_url(http_test_server()->GetURL("/defaultresponse")); 3855 GURL original_url(http_test_server()->GetURL("/defaultresponse"));
3867 std::unique_ptr<URLRequest> r( 3856 std::unique_ptr<URLRequest> r(
3868 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 3857 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3869 3858
3870 // Quit after hitting the redirect, so can check the headers. 3859 // Quit after hitting the redirect, so can check the headers.
3871 d.set_quit_on_redirect(true); 3860 d.set_quit_on_redirect(true);
3872 r->Start(); 3861 r->Start();
3873 base::RunLoop().Run(); 3862 base::RunLoop().Run();
3874 3863
3875 // Check headers from URLRequestJob. 3864 // Check headers from URLRequestJob.
3876 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3877 EXPECT_EQ(307, r->GetResponseCode()); 3865 EXPECT_EQ(307, r->GetResponseCode());
3878 EXPECT_EQ(307, r->response_headers()->response_code()); 3866 EXPECT_EQ(307, r->response_headers()->response_code());
3879 std::string location; 3867 std::string location;
3880 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3868 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3881 &location)); 3869 &location));
3882 EXPECT_EQ(redirect_url, GURL(location)); 3870 EXPECT_EQ(redirect_url, GURL(location));
3883 3871
3884 // Let the request finish. 3872 // Let the request finish.
3885 r->FollowDeferredRedirect(); 3873 r->FollowDeferredRedirect();
3886 base::RunLoop().Run(); 3874 base::RunLoop().Run();
3887 3875
3888 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3876 EXPECT_EQ(OK, d.request_status());
3889 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3877 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair()));
3890 // before_send_headers_with_proxy_count only increments for headers sent 3878 // before_send_headers_with_proxy_count only increments for headers sent
3891 // through an untunneled proxy. 3879 // through an untunneled proxy.
3892 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count()); 3880 EXPECT_EQ(1, network_delegate.before_send_headers_with_proxy_count());
3893 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3881 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3894 http_test_server()->host_port_pair())); 3882 http_test_server()->host_port_pair()));
3895 EXPECT_EQ(0, r->status().error()); 3883 EXPECT_EQ(OK, d.request_status());
3896 EXPECT_EQ(redirect_url, r->url()); 3884 EXPECT_EQ(redirect_url, r->url());
3897 EXPECT_EQ(original_url, r->original_url()); 3885 EXPECT_EQ(original_url, r->original_url());
3898 EXPECT_EQ(2U, r->url_chain().size()); 3886 EXPECT_EQ(2U, r->url_chain().size());
3899 EXPECT_EQ(1, network_delegate.created_requests()); 3887 EXPECT_EQ(1, network_delegate.created_requests());
3900 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3888 EXPECT_EQ(0, network_delegate.destroyed_requests());
3901 } 3889 }
3902 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3890 EXPECT_EQ(1, network_delegate.destroyed_requests());
3903 } 3891 }
3904 3892
3905 // Tests that redirects caused by the network delegate preserve POST data. 3893 // Tests that redirects caused by the network delegate preserve POST data.
(...skipping 23 matching lines...) Expand all
3929 headers.SetHeader(HttpRequestHeaders::kContentLength, 3917 headers.SetHeader(HttpRequestHeaders::kContentLength,
3930 base::SizeTToString(arraysize(kData) - 1)); 3918 base::SizeTToString(arraysize(kData) - 1));
3931 r->SetExtraRequestHeaders(headers); 3919 r->SetExtraRequestHeaders(headers);
3932 3920
3933 // Quit after hitting the redirect, so can check the headers. 3921 // Quit after hitting the redirect, so can check the headers.
3934 d.set_quit_on_redirect(true); 3922 d.set_quit_on_redirect(true);
3935 r->Start(); 3923 r->Start();
3936 base::RunLoop().Run(); 3924 base::RunLoop().Run();
3937 3925
3938 // Check headers from URLRequestJob. 3926 // Check headers from URLRequestJob.
3939 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3940 EXPECT_EQ(307, r->GetResponseCode()); 3927 EXPECT_EQ(307, r->GetResponseCode());
3941 EXPECT_EQ(307, r->response_headers()->response_code()); 3928 EXPECT_EQ(307, r->response_headers()->response_code());
3942 std::string location; 3929 std::string location;
3943 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location", 3930 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3944 &location)); 3931 &location));
3945 EXPECT_EQ(redirect_url, GURL(location)); 3932 EXPECT_EQ(redirect_url, GURL(location));
3946 3933
3947 // Let the request finish. 3934 // Let the request finish.
3948 r->FollowDeferredRedirect(); 3935 r->FollowDeferredRedirect();
3949 base::RunLoop().Run(); 3936 base::RunLoop().Run();
3950 3937
3951 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3938 EXPECT_EQ(OK, d.request_status());
3952 EXPECT_EQ(0, r->status().error());
3953 EXPECT_EQ(redirect_url, r->url()); 3939 EXPECT_EQ(redirect_url, r->url());
3954 EXPECT_EQ(original_url, r->original_url()); 3940 EXPECT_EQ(original_url, r->original_url());
3955 EXPECT_EQ(2U, r->url_chain().size()); 3941 EXPECT_EQ(2U, r->url_chain().size());
3956 EXPECT_EQ(1, network_delegate.created_requests()); 3942 EXPECT_EQ(1, network_delegate.created_requests());
3957 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3943 EXPECT_EQ(0, network_delegate.destroyed_requests());
3958 EXPECT_EQ("POST", r->method()); 3944 EXPECT_EQ("POST", r->method());
3959 EXPECT_EQ(kData, d.data_received()); 3945 EXPECT_EQ(kData, d.data_received());
3960 } 3946 }
3961 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3947 EXPECT_EQ(1, network_delegate.destroyed_requests());
3962 } 3948 }
(...skipping 14 matching lines...) Expand all
3977 http_test_server()->host_port_pair().ToString(), &network_delegate); 3963 http_test_server()->host_port_pair().ToString(), &network_delegate);
3978 3964
3979 { 3965 {
3980 GURL original_url(http_test_server()->GetURL("/defaultresponse")); 3966 GURL original_url(http_test_server()->GetURL("/defaultresponse"));
3981 std::unique_ptr<URLRequest> r( 3967 std::unique_ptr<URLRequest> r(
3982 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 3968 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3983 3969
3984 r->Start(); 3970 r->Start();
3985 base::RunLoop().Run(); 3971 base::RunLoop().Run();
3986 3972
3987 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3973 EXPECT_EQ(OK, d.request_status());
3988 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair())); 3974 EXPECT_TRUE(r->proxy_server().Equals(http_test_server()->host_port_pair()));
3989 // before_send_headers_with_proxy_count only increments for headers sent 3975 // before_send_headers_with_proxy_count only increments for headers sent
3990 // through an untunneled proxy. 3976 // through an untunneled proxy.
3991 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count()); 3977 EXPECT_EQ(2, network_delegate.before_send_headers_with_proxy_count());
3992 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals( 3978 EXPECT_TRUE(network_delegate.last_observed_proxy().Equals(
3993 http_test_server()->host_port_pair())); 3979 http_test_server()->host_port_pair()));
3994 3980
3995 EXPECT_THAT(r->status().error(), IsOk()); 3981 EXPECT_EQ(OK, d.request_status());
3996 EXPECT_EQ(redirect_url, r->url()); 3982 EXPECT_EQ(redirect_url, r->url());
3997 EXPECT_EQ(original_url, r->original_url()); 3983 EXPECT_EQ(original_url, r->original_url());
3998 EXPECT_EQ(2U, r->url_chain().size()); 3984 EXPECT_EQ(2U, r->url_chain().size());
3999 EXPECT_EQ(2, network_delegate.created_requests()); 3985 EXPECT_EQ(2, network_delegate.created_requests());
4000 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3986 EXPECT_EQ(0, network_delegate.destroyed_requests());
4001 } 3987 }
4002 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3988 EXPECT_EQ(1, network_delegate.destroyed_requests());
4003 } 3989 }
4004 3990
4005 // Tests that the network delegate can synchronously complete OnAuthRequired 3991 // Tests that the network delegate can synchronously complete OnAuthRequired
(...skipping 14 matching lines...) Expand all
4020 d.set_credentials(AuthCredentials(kUser, kSecret)); 4006 d.set_credentials(AuthCredentials(kUser, kSecret));
4021 4007
4022 { 4008 {
4023 GURL url(http_test_server()->GetURL("/auth-basic")); 4009 GURL url(http_test_server()->GetURL("/auth-basic"));
4024 std::unique_ptr<URLRequest> r( 4010 std::unique_ptr<URLRequest> r(
4025 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4011 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4026 r->Start(); 4012 r->Start();
4027 4013
4028 base::RunLoop().Run(); 4014 base::RunLoop().Run();
4029 4015
4030 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4016 EXPECT_EQ(OK, d.request_status());
4031 EXPECT_EQ(0, r->status().error());
4032 EXPECT_EQ(200, r->GetResponseCode()); 4017 EXPECT_EQ(200, r->GetResponseCode());
4033 EXPECT_TRUE(d.auth_required_called()); 4018 EXPECT_TRUE(d.auth_required_called());
4034 EXPECT_EQ(1, network_delegate.created_requests()); 4019 EXPECT_EQ(1, network_delegate.created_requests());
4035 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4020 EXPECT_EQ(0, network_delegate.destroyed_requests());
4036 } 4021 }
4037 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4022 EXPECT_EQ(1, network_delegate.destroyed_requests());
4038 } 4023 }
4039 4024
4040 TEST_F(URLRequestTestHTTP, 4025 TEST_F(URLRequestTestHTTP,
4041 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { 4026 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) {
(...skipping 16 matching lines...) Expand all
4058 r->Start(); 4043 r->Start();
4059 4044
4060 { 4045 {
4061 HttpRequestHeaders headers; 4046 HttpRequestHeaders headers;
4062 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 4047 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
4063 EXPECT_FALSE(headers.HasHeader("Authorization")); 4048 EXPECT_FALSE(headers.HasHeader("Authorization"));
4064 } 4049 }
4065 4050
4066 base::RunLoop().Run(); 4051 base::RunLoop().Run();
4067 4052
4068 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4053 EXPECT_EQ(OK, d.request_status());
4069 EXPECT_EQ(0, r->status().error());
4070 EXPECT_EQ(200, r->GetResponseCode()); 4054 EXPECT_EQ(200, r->GetResponseCode());
4071 EXPECT_TRUE(d.auth_required_called()); 4055 EXPECT_TRUE(d.auth_required_called());
4072 EXPECT_EQ(1, network_delegate.created_requests()); 4056 EXPECT_EQ(1, network_delegate.created_requests());
4073 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4057 EXPECT_EQ(0, network_delegate.destroyed_requests());
4074 } 4058 }
4075 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4059 EXPECT_EQ(1, network_delegate.destroyed_requests());
4076 } 4060 }
4077 4061
4078 // Tests that the network delegate can synchronously complete OnAuthRequired 4062 // Tests that the network delegate can synchronously complete OnAuthRequired
4079 // by setting credentials. 4063 // by setting credentials.
(...skipping 13 matching lines...) Expand all
4093 context.set_network_delegate(&network_delegate); 4077 context.set_network_delegate(&network_delegate);
4094 context.Init(); 4078 context.Init();
4095 4079
4096 { 4080 {
4097 GURL url(http_test_server()->GetURL("/auth-basic")); 4081 GURL url(http_test_server()->GetURL("/auth-basic"));
4098 std::unique_ptr<URLRequest> r( 4082 std::unique_ptr<URLRequest> r(
4099 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4083 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4100 r->Start(); 4084 r->Start();
4101 base::RunLoop().Run(); 4085 base::RunLoop().Run();
4102 4086
4103 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4087 EXPECT_EQ(OK, d.request_status());
4104 EXPECT_EQ(0, r->status().error());
4105 EXPECT_EQ(200, r->GetResponseCode()); 4088 EXPECT_EQ(200, r->GetResponseCode());
4106 EXPECT_FALSE(d.auth_required_called()); 4089 EXPECT_FALSE(d.auth_required_called());
4107 EXPECT_EQ(1, network_delegate.created_requests()); 4090 EXPECT_EQ(1, network_delegate.created_requests());
4108 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4091 EXPECT_EQ(0, network_delegate.destroyed_requests());
4109 } 4092 }
4110 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4093 EXPECT_EQ(1, network_delegate.destroyed_requests());
4111 } 4094 }
4112 4095
4113 // Same as above, but also tests that GetFullRequestHeaders returns the proper 4096 // Same as above, but also tests that GetFullRequestHeaders returns the proper
4114 // headers (for the first or second request) when called at the proper times. 4097 // headers (for the first or second request) when called at the proper times.
(...skipping 14 matching lines...) Expand all
4129 context.set_network_delegate(&network_delegate); 4112 context.set_network_delegate(&network_delegate);
4130 context.Init(); 4113 context.Init();
4131 4114
4132 { 4115 {
4133 GURL url(http_test_server()->GetURL("/auth-basic")); 4116 GURL url(http_test_server()->GetURL("/auth-basic"));
4134 std::unique_ptr<URLRequest> r( 4117 std::unique_ptr<URLRequest> r(
4135 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4118 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4136 r->Start(); 4119 r->Start();
4137 base::RunLoop().Run(); 4120 base::RunLoop().Run();
4138 4121
4139 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4122 EXPECT_EQ(OK, d.request_status());
4140 EXPECT_EQ(0, r->status().error());
4141 EXPECT_EQ(200, r->GetResponseCode()); 4123 EXPECT_EQ(200, r->GetResponseCode());
4142 EXPECT_FALSE(d.auth_required_called()); 4124 EXPECT_FALSE(d.auth_required_called());
4143 EXPECT_EQ(1, network_delegate.created_requests()); 4125 EXPECT_EQ(1, network_delegate.created_requests());
4144 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4126 EXPECT_EQ(0, network_delegate.destroyed_requests());
4145 4127
4146 { 4128 {
4147 HttpRequestHeaders headers; 4129 HttpRequestHeaders headers;
4148 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 4130 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
4149 EXPECT_TRUE(headers.HasHeader("Authorization")); 4131 EXPECT_TRUE(headers.HasHeader("Authorization"));
4150 } 4132 }
(...skipping 17 matching lines...) Expand all
4168 context.set_network_delegate(&network_delegate); 4150 context.set_network_delegate(&network_delegate);
4169 context.Init(); 4151 context.Init();
4170 4152
4171 { 4153 {
4172 GURL url(http_test_server()->GetURL("/auth-basic")); 4154 GURL url(http_test_server()->GetURL("/auth-basic"));
4173 std::unique_ptr<URLRequest> r( 4155 std::unique_ptr<URLRequest> r(
4174 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4156 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4175 r->Start(); 4157 r->Start();
4176 base::RunLoop().Run(); 4158 base::RunLoop().Run();
4177 4159
4178 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4160 EXPECT_EQ(OK, d.request_status());
4179 EXPECT_THAT(r->status().error(), IsOk());
4180 EXPECT_EQ(401, r->GetResponseCode()); 4161 EXPECT_EQ(401, r->GetResponseCode());
4181 EXPECT_FALSE(d.auth_required_called()); 4162 EXPECT_FALSE(d.auth_required_called());
4182 EXPECT_EQ(1, network_delegate.created_requests()); 4163 EXPECT_EQ(1, network_delegate.created_requests());
4183 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4164 EXPECT_EQ(0, network_delegate.destroyed_requests());
4184 } 4165 }
4185 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4166 EXPECT_EQ(1, network_delegate.destroyed_requests());
4186 } 4167 }
4187 4168
4188 // Tests that the network delegate can asynchronously complete OnAuthRequired 4169 // Tests that the network delegate can asynchronously complete OnAuthRequired
4189 // by taking no action. This indicates that the NetworkDelegate does not want 4170 // by taking no action. This indicates that the NetworkDelegate does not want
(...skipping 13 matching lines...) Expand all
4203 4184
4204 d.set_credentials(AuthCredentials(kUser, kSecret)); 4185 d.set_credentials(AuthCredentials(kUser, kSecret));
4205 4186
4206 { 4187 {
4207 GURL url(http_test_server()->GetURL("/auth-basic")); 4188 GURL url(http_test_server()->GetURL("/auth-basic"));
4208 std::unique_ptr<URLRequest> r( 4189 std::unique_ptr<URLRequest> r(
4209 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4190 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4210 r->Start(); 4191 r->Start();
4211 base::RunLoop().Run(); 4192 base::RunLoop().Run();
4212 4193
4213 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4194 EXPECT_EQ(OK, d.request_status());
4214 EXPECT_EQ(0, r->status().error());
4215 EXPECT_EQ(200, r->GetResponseCode()); 4195 EXPECT_EQ(200, r->GetResponseCode());
4216 EXPECT_TRUE(d.auth_required_called()); 4196 EXPECT_TRUE(d.auth_required_called());
4217 EXPECT_EQ(1, network_delegate.created_requests()); 4197 EXPECT_EQ(1, network_delegate.created_requests());
4218 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4198 EXPECT_EQ(0, network_delegate.destroyed_requests());
4219 } 4199 }
4220 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4200 EXPECT_EQ(1, network_delegate.destroyed_requests());
4221 } 4201 }
4222 4202
4223 // Tests that the network delegate can asynchronously complete OnAuthRequired 4203 // Tests that the network delegate can asynchronously complete OnAuthRequired
4224 // by setting credentials. 4204 // by setting credentials.
(...skipping 14 matching lines...) Expand all
4239 context.set_network_delegate(&network_delegate); 4219 context.set_network_delegate(&network_delegate);
4240 context.Init(); 4220 context.Init();
4241 4221
4242 { 4222 {
4243 GURL url(http_test_server()->GetURL("/auth-basic")); 4223 GURL url(http_test_server()->GetURL("/auth-basic"));
4244 std::unique_ptr<URLRequest> r( 4224 std::unique_ptr<URLRequest> r(
4245 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4225 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4246 r->Start(); 4226 r->Start();
4247 base::RunLoop().Run(); 4227 base::RunLoop().Run();
4248 4228
4249 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4229 EXPECT_EQ(OK, d.request_status());
4250 EXPECT_EQ(0, r->status().error());
4251
4252 EXPECT_EQ(200, r->GetResponseCode()); 4230 EXPECT_EQ(200, r->GetResponseCode());
4253 EXPECT_FALSE(d.auth_required_called()); 4231 EXPECT_FALSE(d.auth_required_called());
4254 EXPECT_EQ(1, network_delegate.created_requests()); 4232 EXPECT_EQ(1, network_delegate.created_requests());
4255 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4233 EXPECT_EQ(0, network_delegate.destroyed_requests());
4256 } 4234 }
4257 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4235 EXPECT_EQ(1, network_delegate.destroyed_requests());
4258 } 4236 }
4259 4237
4260 // Tests that the network delegate can asynchronously complete OnAuthRequired 4238 // Tests that the network delegate can asynchronously complete OnAuthRequired
4261 // by cancelling authentication. 4239 // by cancelling authentication.
(...skipping 11 matching lines...) Expand all
4273 context.set_network_delegate(&network_delegate); 4251 context.set_network_delegate(&network_delegate);
4274 context.Init(); 4252 context.Init();
4275 4253
4276 { 4254 {
4277 GURL url(http_test_server()->GetURL("/auth-basic")); 4255 GURL url(http_test_server()->GetURL("/auth-basic"));
4278 std::unique_ptr<URLRequest> r( 4256 std::unique_ptr<URLRequest> r(
4279 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 4257 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
4280 r->Start(); 4258 r->Start();
4281 base::RunLoop().Run(); 4259 base::RunLoop().Run();
4282 4260
4283 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4261 EXPECT_EQ(OK, d.request_status());
4284 EXPECT_THAT(r->status().error(), IsOk());
4285 EXPECT_EQ(401, r->GetResponseCode()); 4262 EXPECT_EQ(401, r->GetResponseCode());
4286 EXPECT_FALSE(d.auth_required_called()); 4263 EXPECT_FALSE(d.auth_required_called());
4287 EXPECT_EQ(1, network_delegate.created_requests()); 4264 EXPECT_EQ(1, network_delegate.created_requests());
4288 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4265 EXPECT_EQ(0, network_delegate.destroyed_requests());
4289 } 4266 }
4290 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4267 EXPECT_EQ(1, network_delegate.destroyed_requests());
4291 } 4268 }
4292 4269
4293 // Tests that we can handle when a network request was canceled while we were 4270 // Tests that we can handle when a network request was canceled while we were
4294 // waiting for the network delegate. 4271 // waiting for the network delegate.
(...skipping 16 matching lines...) Expand all
4311 4288
4312 r->Start(); 4289 r->Start();
4313 base::RunLoop().Run(); 4290 base::RunLoop().Run();
4314 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 4291 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
4315 network_delegate.stage_blocked_for_callback()); 4292 network_delegate.stage_blocked_for_callback());
4316 EXPECT_EQ(0, network_delegate.completed_requests()); 4293 EXPECT_EQ(0, network_delegate.completed_requests());
4317 // Cancel before callback. 4294 // Cancel before callback.
4318 r->Cancel(); 4295 r->Cancel();
4319 // Ensure that network delegate is notified. 4296 // Ensure that network delegate is notified.
4320 EXPECT_EQ(1, network_delegate.completed_requests()); 4297 EXPECT_EQ(1, network_delegate.completed_requests());
4321 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4298 EXPECT_EQ(1, network_delegate.canceled_requests());
4322 EXPECT_THAT(r->status().error(), IsError(ERR_ABORTED));
4323 EXPECT_EQ(1, network_delegate.created_requests()); 4299 EXPECT_EQ(1, network_delegate.created_requests());
4324 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4300 EXPECT_EQ(0, network_delegate.destroyed_requests());
4325 } 4301 }
4326 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4302 EXPECT_EQ(1, network_delegate.destroyed_requests());
4327 } 4303 }
4328 4304
4329 // Tests that we can handle when a network request was canceled while we were 4305 // Tests that we can handle when a network request was canceled while we were
4330 // waiting for the network delegate. 4306 // waiting for the network delegate.
4331 // Part 2: Request is cancelled while waiting for OnBeforeStartTransaction 4307 // Part 2: Request is cancelled while waiting for OnBeforeStartTransaction
4332 // callback. 4308 // callback.
(...skipping 16 matching lines...) Expand all
4349 4325
4350 r->Start(); 4326 r->Start();
4351 base::RunLoop().Run(); 4327 base::RunLoop().Run();
4352 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 4328 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
4353 network_delegate.stage_blocked_for_callback()); 4329 network_delegate.stage_blocked_for_callback());
4354 EXPECT_EQ(0, network_delegate.completed_requests()); 4330 EXPECT_EQ(0, network_delegate.completed_requests());
4355 // Cancel before callback. 4331 // Cancel before callback.
4356 r->Cancel(); 4332 r->Cancel();
4357 // Ensure that network delegate is notified. 4333 // Ensure that network delegate is notified.
4358 EXPECT_EQ(1, network_delegate.completed_requests()); 4334 EXPECT_EQ(1, network_delegate.completed_requests());
4359 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4335 EXPECT_EQ(1, network_delegate.canceled_requests());
4360 EXPECT_THAT(r->status().error(), IsError(ERR_ABORTED));
4361 EXPECT_EQ(1, network_delegate.created_requests()); 4336 EXPECT_EQ(1, network_delegate.created_requests());
4362 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4337 EXPECT_EQ(0, network_delegate.destroyed_requests());
4363 } 4338 }
4364 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4339 EXPECT_EQ(1, network_delegate.destroyed_requests());
4365 } 4340 }
4366 4341
4367 // Tests that we can handle when a network request was canceled while we were 4342 // Tests that we can handle when a network request was canceled while we were
4368 // waiting for the network delegate. 4343 // waiting for the network delegate.
4369 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. 4344 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback.
4370 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { 4345 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) {
(...skipping 14 matching lines...) Expand all
4385 4360
4386 r->Start(); 4361 r->Start();
4387 base::RunLoop().Run(); 4362 base::RunLoop().Run();
4388 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 4363 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
4389 network_delegate.stage_blocked_for_callback()); 4364 network_delegate.stage_blocked_for_callback());
4390 EXPECT_EQ(0, network_delegate.completed_requests()); 4365 EXPECT_EQ(0, network_delegate.completed_requests());
4391 // Cancel before callback. 4366 // Cancel before callback.
4392 r->Cancel(); 4367 r->Cancel();
4393 // Ensure that network delegate is notified. 4368 // Ensure that network delegate is notified.
4394 EXPECT_EQ(1, network_delegate.completed_requests()); 4369 EXPECT_EQ(1, network_delegate.completed_requests());
4395 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4370 EXPECT_EQ(1, network_delegate.canceled_requests());
4396 EXPECT_THAT(r->status().error(), IsError(ERR_ABORTED));
4397 EXPECT_EQ(1, network_delegate.created_requests()); 4371 EXPECT_EQ(1, network_delegate.created_requests());
4398 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4372 EXPECT_EQ(0, network_delegate.destroyed_requests());
4399 } 4373 }
4400 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4374 EXPECT_EQ(1, network_delegate.destroyed_requests());
4401 } 4375 }
4402 4376
4403 // Tests that we can handle when a network request was canceled while we were 4377 // Tests that we can handle when a network request was canceled while we were
4404 // waiting for the network delegate. 4378 // waiting for the network delegate.
4405 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. 4379 // Part 4: Request is cancelled while waiting for OnAuthRequired callback.
4406 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { 4380 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) {
(...skipping 14 matching lines...) Expand all
4421 4395
4422 r->Start(); 4396 r->Start();
4423 base::RunLoop().Run(); 4397 base::RunLoop().Run();
4424 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, 4398 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED,
4425 network_delegate.stage_blocked_for_callback()); 4399 network_delegate.stage_blocked_for_callback());
4426 EXPECT_EQ(0, network_delegate.completed_requests()); 4400 EXPECT_EQ(0, network_delegate.completed_requests());
4427 // Cancel before callback. 4401 // Cancel before callback.
4428 r->Cancel(); 4402 r->Cancel();
4429 // Ensure that network delegate is notified. 4403 // Ensure that network delegate is notified.
4430 EXPECT_EQ(1, network_delegate.completed_requests()); 4404 EXPECT_EQ(1, network_delegate.completed_requests());
4431 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4405 EXPECT_EQ(1, network_delegate.canceled_requests());
4432 EXPECT_THAT(r->status().error(), IsError(ERR_ABORTED));
4433 EXPECT_EQ(1, network_delegate.created_requests()); 4406 EXPECT_EQ(1, network_delegate.created_requests());
4434 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4407 EXPECT_EQ(0, network_delegate.destroyed_requests());
4435 } 4408 }
4436 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4409 EXPECT_EQ(1, network_delegate.destroyed_requests());
4437 } 4410 }
4438 4411
4439 namespace { 4412 namespace {
4440 4413
4441 std::unique_ptr<test_server::HttpResponse> HandleServerAuthConnect( 4414 std::unique_ptr<test_server::HttpResponse> HandleServerAuthConnect(
4442 const test_server::HttpRequest& request) { 4415 const test_server::HttpRequest& request) {
(...skipping 28 matching lines...) Expand all
4471 TestDelegate d; 4444 TestDelegate d;
4472 { 4445 {
4473 std::unique_ptr<URLRequest> r(context.CreateRequest( 4446 std::unique_ptr<URLRequest> r(context.CreateRequest(
4474 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); 4447 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d));
4475 4448
4476 r->Start(); 4449 r->Start();
4477 EXPECT_TRUE(r->is_pending()); 4450 EXPECT_TRUE(r->is_pending());
4478 4451
4479 base::RunLoop().Run(); 4452 base::RunLoop().Run();
4480 4453
4481 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
4482 // The proxy server is not set before failure. 4454 // The proxy server is not set before failure.
4483 EXPECT_TRUE(r->proxy_server().IsEmpty()); 4455 EXPECT_TRUE(r->proxy_server().IsEmpty());
4484 EXPECT_THAT(r->status().error(), IsError(ERR_TUNNEL_CONNECTION_FAILED)); 4456 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status());
4485 } 4457 }
4486 } 4458 }
4487 4459
4488 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 4460 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
4489 ASSERT_TRUE(http_test_server()->Start()); 4461 ASSERT_TRUE(http_test_server()->Start());
4490 4462
4491 TestDelegate d; 4463 TestDelegate d;
4492 { 4464 {
4493 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 4465 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
4494 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); 4466 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
4676 std::unique_ptr<URLRequest> r(context.CreateRequest( 4648 std::unique_ptr<URLRequest> r(context.CreateRequest(
4677 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d)); 4649 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d));
4678 r->Start(); 4650 r->Start();
4679 EXPECT_TRUE(r->is_pending()); 4651 EXPECT_TRUE(r->is_pending());
4680 4652
4681 base::RunLoop().Run(); 4653 base::RunLoop().Run();
4682 4654
4683 EXPECT_EQ(1, d.response_started_count()); 4655 EXPECT_EQ(1, d.response_started_count());
4684 EXPECT_FALSE(d.received_data_before_response()); 4656 EXPECT_FALSE(d.received_data_before_response());
4685 VLOG(1) << " Received " << d.bytes_received() << " bytes" 4657 VLOG(1) << " Received " << d.bytes_received() << " bytes"
4686 << " status = " << r->status().status() 4658 << " error = " << d.request_status();
4687 << " error = " << r->status().error();
4688 if (test_expect_success[i]) { 4659 if (test_expect_success[i]) {
4689 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) 4660 EXPECT_EQ(OK, d.request_status()) << " Parameter = \"" << test_file
4690 << " Parameter = \"" << test_file << "\""; 4661 << "\"";
4691 if (test_parameters[i] == 'S') { 4662 if (test_parameters[i] == 'S') {
4692 // When content length is smaller than both compressed length and 4663 // When content length is smaller than both compressed length and
4693 // uncompressed length, HttpStreamParser might not read the full 4664 // uncompressed length, HttpStreamParser might not read the full
4694 // response body. 4665 // response body.
4695 continue; 4666 continue;
4696 } 4667 }
4697 EXPECT_EQ(expected_content, d.data_received()); 4668 EXPECT_EQ(expected_content, d.data_received());
4698 } else { 4669 } else {
4699 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 4670 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, d.request_status())
4700 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error())
4701 << " Parameter = \"" << test_file << "\""; 4671 << " Parameter = \"" << test_file << "\"";
4702 } 4672 }
4703 } 4673 }
4704 } 4674 }
4705 } 4675 }
4706 #endif // !defined(OS_IOS) 4676 #endif // !defined(OS_IOS)
4707 4677
4708 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { 4678 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) {
4709 ASSERT_TRUE(http_test_server()->Start()); 4679 ASSERT_TRUE(http_test_server()->Start());
4710 4680
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
5074 AsyncDelegateLogger::Run( 5044 AsyncDelegateLogger::Run(
5075 r.get(), 5045 r.get(),
5076 LOAD_STATE_WAITING_FOR_DELEGATE, 5046 LOAD_STATE_WAITING_FOR_DELEGATE,
5077 LOAD_STATE_WAITING_FOR_DELEGATE, 5047 LOAD_STATE_WAITING_FOR_DELEGATE,
5078 LOAD_STATE_IDLE, 5048 LOAD_STATE_IDLE,
5079 base::Bind(&URLRequest::Start, base::Unretained(r.get()))); 5049 base::Bind(&URLRequest::Start, base::Unretained(r.get())));
5080 5050
5081 base::RunLoop().Run(); 5051 base::RunLoop().Run();
5082 5052
5083 EXPECT_EQ(200, r->GetResponseCode()); 5053 EXPECT_EQ(200, r->GetResponseCode());
5084 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5054 EXPECT_EQ(OK, request_delegate.request_status());
5085 } 5055 }
5086 5056
5087 TestNetLogEntry::List entries; 5057 TestNetLogEntry::List entries;
5088 net_log_.GetEntries(&entries); 5058 net_log_.GetEntries(&entries);
5089 size_t log_position = ExpectLogContainsSomewhereAfter( 5059 size_t log_position = ExpectLogContainsSomewhereAfter(
5090 entries, 5060 entries,
5091 0, 5061 0,
5092 NetLog::TYPE_DELEGATE_INFO, 5062 NetLog::TYPE_DELEGATE_INFO,
5093 NetLog::PHASE_BEGIN); 5063 NetLog::PHASE_BEGIN);
5094 5064
(...skipping 20 matching lines...) Expand all
5115 context.CreateRequest(http_test_server()->GetURL("/simple.html"), 5085 context.CreateRequest(http_test_server()->GetURL("/simple.html"),
5116 DEFAULT_PRIORITY, &request_delegate)); 5086 DEFAULT_PRIORITY, &request_delegate));
5117 LoadStateWithParam load_state = r->GetLoadState(); 5087 LoadStateWithParam load_state = r->GetLoadState();
5118 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 5088 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
5119 EXPECT_EQ(base::string16(), load_state.param); 5089 EXPECT_EQ(base::string16(), load_state.param);
5120 5090
5121 r->Start(); 5091 r->Start();
5122 base::RunLoop().Run(); 5092 base::RunLoop().Run();
5123 5093
5124 EXPECT_EQ(200, r->GetResponseCode()); 5094 EXPECT_EQ(200, r->GetResponseCode());
5125 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5095 EXPECT_EQ(OK, request_delegate.request_status());
5126 EXPECT_EQ(1, network_delegate.created_requests()); 5096 EXPECT_EQ(1, network_delegate.created_requests());
5127 EXPECT_EQ(0, network_delegate.destroyed_requests()); 5097 EXPECT_EQ(0, network_delegate.destroyed_requests());
5128 } 5098 }
5129 EXPECT_EQ(1, network_delegate.destroyed_requests()); 5099 EXPECT_EQ(1, network_delegate.destroyed_requests());
5130 5100
5131 size_t log_position = 0; 5101 size_t log_position = 0;
5132 TestNetLogEntry::List entries; 5102 TestNetLogEntry::List entries;
5133 net_log_.GetEntries(&entries); 5103 net_log_.GetEntries(&entries);
5134 for (size_t i = 0; i < 3; ++i) { 5104 for (size_t i = 0; i < 3; ++i) {
5135 log_position = ExpectLogContainsSomewhereAfter( 5105 log_position = ExpectLogContainsSomewhereAfter(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5167 http_test_server()->GetURL("/server-redirect?simple.html"), 5137 http_test_server()->GetURL("/server-redirect?simple.html"),
5168 DEFAULT_PRIORITY, &request_delegate)); 5138 DEFAULT_PRIORITY, &request_delegate));
5169 LoadStateWithParam load_state = r->GetLoadState(); 5139 LoadStateWithParam load_state = r->GetLoadState();
5170 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 5140 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
5171 EXPECT_EQ(base::string16(), load_state.param); 5141 EXPECT_EQ(base::string16(), load_state.param);
5172 5142
5173 r->Start(); 5143 r->Start();
5174 base::RunLoop().Run(); 5144 base::RunLoop().Run();
5175 5145
5176 EXPECT_EQ(200, r->GetResponseCode()); 5146 EXPECT_EQ(200, r->GetResponseCode());
5177 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5147 EXPECT_EQ(OK, request_delegate.request_status());
5178 EXPECT_EQ(2, network_delegate.created_requests()); 5148 EXPECT_EQ(2, network_delegate.created_requests());
5179 EXPECT_EQ(0, network_delegate.destroyed_requests()); 5149 EXPECT_EQ(0, network_delegate.destroyed_requests());
5180 } 5150 }
5181 EXPECT_EQ(1, network_delegate.destroyed_requests()); 5151 EXPECT_EQ(1, network_delegate.destroyed_requests());
5182 5152
5183 size_t log_position = 0; 5153 size_t log_position = 0;
5184 TestNetLogEntry::List entries; 5154 TestNetLogEntry::List entries;
5185 net_log_.GetEntries(&entries); 5155 net_log_.GetEntries(&entries);
5186 // The NetworkDelegate logged information in OnBeforeURLRequest, 5156 // The NetworkDelegate logged information in OnBeforeURLRequest,
5187 // OnBeforeStartTransaction, and OnHeadersReceived. 5157 // OnBeforeStartTransaction, and OnHeadersReceived.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
5244 context.CreateRequest(http_test_server()->GetURL("/auth-basic"), 5214 context.CreateRequest(http_test_server()->GetURL("/auth-basic"),
5245 DEFAULT_PRIORITY, &request_delegate)); 5215 DEFAULT_PRIORITY, &request_delegate));
5246 LoadStateWithParam load_state = r->GetLoadState(); 5216 LoadStateWithParam load_state = r->GetLoadState();
5247 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 5217 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
5248 EXPECT_EQ(base::string16(), load_state.param); 5218 EXPECT_EQ(base::string16(), load_state.param);
5249 5219
5250 r->Start(); 5220 r->Start();
5251 base::RunLoop().Run(); 5221 base::RunLoop().Run();
5252 5222
5253 EXPECT_EQ(200, r->GetResponseCode()); 5223 EXPECT_EQ(200, r->GetResponseCode());
5254 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5224 EXPECT_EQ(OK, request_delegate.request_status());
5255 EXPECT_EQ(1, network_delegate.created_requests()); 5225 EXPECT_EQ(1, network_delegate.created_requests());
5256 EXPECT_EQ(0, network_delegate.destroyed_requests()); 5226 EXPECT_EQ(0, network_delegate.destroyed_requests());
5257 } 5227 }
5258 EXPECT_EQ(1, network_delegate.destroyed_requests()); 5228 EXPECT_EQ(1, network_delegate.destroyed_requests());
5259 5229
5260 size_t log_position = 0; 5230 size_t log_position = 0;
5261 TestNetLogEntry::List entries; 5231 TestNetLogEntry::List entries;
5262 net_log_.GetEntries(&entries); 5232 net_log_.GetEntries(&entries);
5263 // The NetworkDelegate should have logged information in OnBeforeURLRequest, 5233 // The NetworkDelegate should have logged information in OnBeforeURLRequest,
5264 // OnBeforeStartTransaction, OnHeadersReceived, OnAuthRequired, and then again 5234 // OnBeforeStartTransaction, OnHeadersReceived, OnAuthRequired, and then again
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5307 // the possibility of multiple reads being combined in the unlikely event 5277 // the possibility of multiple reads being combined in the unlikely event
5308 // that it occurs. 5278 // that it occurs.
5309 std::unique_ptr<URLRequest> r(context.CreateRequest( 5279 std::unique_ptr<URLRequest> r(context.CreateRequest(
5310 test_server.GetURL("/chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, 5280 test_server.GetURL("/chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY,
5311 &request_delegate)); 5281 &request_delegate));
5312 LoadStateWithParam load_state = r->GetLoadState(); 5282 LoadStateWithParam load_state = r->GetLoadState();
5313 r->Start(); 5283 r->Start();
5314 base::RunLoop().Run(); 5284 base::RunLoop().Run();
5315 5285
5316 EXPECT_EQ(200, r->GetResponseCode()); 5286 EXPECT_EQ(200, r->GetResponseCode());
5317 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5287 EXPECT_EQ(OK, request_delegate.request_status());
5318 } 5288 }
5319 5289
5320 TestNetLogEntry::List entries; 5290 TestNetLogEntry::List entries;
5321 net_log_.GetEntries(&entries); 5291 net_log_.GetEntries(&entries);
5322 5292
5323 size_t log_position = 0; 5293 size_t log_position = 0;
5324 5294
5325 // The delegate info should only have been logged on header complete. Other 5295 // The delegate info should only have been logged on header complete. Other
5326 // times it should silently be ignored. 5296 // times it should silently be ignored.
5327 log_position = 5297 log_position =
(...skipping 30 matching lines...) Expand all
5358 5328
5359 { 5329 {
5360 std::unique_ptr<URLRequest> r(context.CreateRequest( 5330 std::unique_ptr<URLRequest> r(context.CreateRequest(
5361 http_test_server()->GetURL("/server-redirect?simple.html"), 5331 http_test_server()->GetURL("/server-redirect?simple.html"),
5362 DEFAULT_PRIORITY, &request_delegate)); 5332 DEFAULT_PRIORITY, &request_delegate));
5363 LoadStateWithParam load_state = r->GetLoadState(); 5333 LoadStateWithParam load_state = r->GetLoadState();
5364 r->Start(); 5334 r->Start();
5365 base::RunLoop().Run(); 5335 base::RunLoop().Run();
5366 5336
5367 EXPECT_EQ(200, r->GetResponseCode()); 5337 EXPECT_EQ(200, r->GetResponseCode());
5368 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5338 EXPECT_EQ(OK, request_delegate.request_status());
5369 } 5339 }
5370 5340
5371 TestNetLogEntry::List entries; 5341 TestNetLogEntry::List entries;
5372 net_log_.GetEntries(&entries); 5342 net_log_.GetEntries(&entries);
5373 5343
5374 // Delegate info should only have been logged in OnReceivedRedirect and 5344 // Delegate info should only have been logged in OnReceivedRedirect and
5375 // OnResponseStarted. 5345 // OnResponseStarted.
5376 size_t log_position = 0; 5346 size_t log_position = 0;
5377 for (int i = 0; i < 2; ++i) { 5347 for (int i = 0; i < 2; ++i) {
5378 log_position = ExpectLogContainsSomewhereAfter( 5348 log_position = ExpectLogContainsSomewhereAfter(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5415 context.set_net_log(&net_log); 5385 context.set_net_log(&net_log);
5416 context.Init(); 5386 context.Init();
5417 5387
5418 { 5388 {
5419 std::unique_ptr<URLRequest> r(context.CreateRequest( 5389 std::unique_ptr<URLRequest> r(context.CreateRequest(
5420 http_test_server()->GetURL("/server-redirect?simple.html"), 5390 http_test_server()->GetURL("/server-redirect?simple.html"),
5421 DEFAULT_PRIORITY, &request_delegate)); 5391 DEFAULT_PRIORITY, &request_delegate));
5422 LoadStateWithParam load_state = r->GetLoadState(); 5392 LoadStateWithParam load_state = r->GetLoadState();
5423 r->Start(); 5393 r->Start();
5424 base::RunLoop().Run(); 5394 base::RunLoop().Run();
5425 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 5395 EXPECT_EQ(ERR_ABORTED, request_delegate.request_status());
5426 } 5396 }
5427 5397
5428 TestNetLogEntry::List entries; 5398 TestNetLogEntry::List entries;
5429 net_log.GetEntries(&entries); 5399 net_log.GetEntries(&entries);
5430 5400
5431 // Delegate info is always logged in both OnReceivedRedirect and 5401 // Delegate info is always logged in both OnReceivedRedirect and
5432 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the 5402 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the
5433 // OnResponseStarted delegate call is after cancellation, but logging is 5403 // OnResponseStarted delegate call is after cancellation, but logging is
5434 // still currently supported in that call. 5404 // still currently supported in that call.
5435 size_t log_position = 0; 5405 size_t log_position = 0;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
5562 d.set_cancel_in_response_started(true); 5532 d.set_cancel_in_response_started(true);
5563 5533
5564 r->Start(); 5534 r->Start();
5565 EXPECT_TRUE(r->is_pending()); 5535 EXPECT_TRUE(r->is_pending());
5566 5536
5567 base::RunLoop().Run(); 5537 base::RunLoop().Run();
5568 5538
5569 EXPECT_EQ(1, d.response_started_count()); 5539 EXPECT_EQ(1, d.response_started_count());
5570 EXPECT_EQ(0, d.bytes_received()); 5540 EXPECT_EQ(0, d.bytes_received());
5571 EXPECT_FALSE(d.received_data_before_response()); 5541 EXPECT_FALSE(d.received_data_before_response());
5572 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 5542 EXPECT_EQ(ERR_ABORTED, d.request_status());
5573 } 5543 }
5574 } 5544 }
5575 5545
5576 TEST_F(URLRequestTestHTTP, CancelTest3) { 5546 TEST_F(URLRequestTestHTTP, CancelTest3) {
5577 ASSERT_TRUE(http_test_server()->Start()); 5547 ASSERT_TRUE(http_test_server()->Start());
5578 5548
5579 TestDelegate d; 5549 TestDelegate d;
5580 { 5550 {
5581 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5551 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5582 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 5552 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
5583 5553
5584 d.set_cancel_in_received_data(true); 5554 d.set_cancel_in_received_data(true);
5585 5555
5586 r->Start(); 5556 r->Start();
5587 EXPECT_TRUE(r->is_pending()); 5557 EXPECT_TRUE(r->is_pending());
5588 5558
5589 base::RunLoop().Run(); 5559 base::RunLoop().Run();
5590 5560
5591 EXPECT_EQ(1, d.response_started_count()); 5561 EXPECT_EQ(1, d.response_started_count());
5592 // There is no guarantee about how much data was received 5562 // There is no guarantee about how much data was received
5593 // before the cancel was issued. It could have been 0 bytes, 5563 // before the cancel was issued. It could have been 0 bytes,
5594 // or it could have been all the bytes. 5564 // or it could have been all the bytes.
5595 // EXPECT_EQ(0, d.bytes_received()); 5565 // EXPECT_EQ(0, d.bytes_received());
5596 EXPECT_FALSE(d.received_data_before_response()); 5566 EXPECT_FALSE(d.received_data_before_response());
5597 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 5567 EXPECT_EQ(ERR_ABORTED, d.request_status());
5598 } 5568 }
5599 } 5569 }
5600 5570
5601 TEST_F(URLRequestTestHTTP, CancelTest4) { 5571 TEST_F(URLRequestTestHTTP, CancelTest4) {
5602 ASSERT_TRUE(http_test_server()->Start()); 5572 ASSERT_TRUE(http_test_server()->Start());
5603 5573
5604 TestDelegate d; 5574 TestDelegate d;
5605 { 5575 {
5606 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5576 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5607 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); 5577 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d));
(...skipping 19 matching lines...) Expand all
5627 TEST_F(URLRequestTestHTTP, CancelTest5) { 5597 TEST_F(URLRequestTestHTTP, CancelTest5) {
5628 ASSERT_TRUE(http_test_server()->Start()); 5598 ASSERT_TRUE(http_test_server()->Start());
5629 5599
5630 // populate cache 5600 // populate cache
5631 { 5601 {
5632 TestDelegate d; 5602 TestDelegate d;
5633 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5603 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5634 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); 5604 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d));
5635 r->Start(); 5605 r->Start();
5636 base::RunLoop().Run(); 5606 base::RunLoop().Run();
5637 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5607 EXPECT_EQ(OK, d.request_status());
5638 } 5608 }
5639 5609
5640 // cancel read from cache (see bug 990242) 5610 // cancel read from cache (see bug 990242)
5641 { 5611 {
5642 TestDelegate d; 5612 TestDelegate d;
5643 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5613 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5644 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); 5614 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d));
5645 r->Start(); 5615 r->Start();
5646 r->Cancel(); 5616 r->Cancel();
5647 base::RunLoop().Run(); 5617 base::RunLoop().Run();
5648 5618
5649 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 5619 EXPECT_EQ(ERR_ABORTED, d.request_status());
5650 EXPECT_EQ(1, d.response_started_count()); 5620 EXPECT_EQ(1, d.response_started_count());
5651 EXPECT_EQ(0, d.bytes_received()); 5621 EXPECT_EQ(0, d.bytes_received());
5652 EXPECT_FALSE(d.received_data_before_response()); 5622 EXPECT_FALSE(d.received_data_before_response());
5653 } 5623 }
5654 } 5624 }
5655 5625
5656 TEST_F(URLRequestTestHTTP, PostTest) { 5626 TEST_F(URLRequestTestHTTP, PostTest) {
5657 ASSERT_TRUE(http_test_server()->Start()); 5627 ASSERT_TRUE(http_test_server()->Start());
5658 HTTPUploadDataOperationTest("POST"); 5628 HTTPUploadDataOperationTest("POST");
5659 } 5629 }
(...skipping 10 matching lines...) Expand all
5670 { 5640 {
5671 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 5641 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
5672 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); 5642 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d));
5673 r->set_method("POST"); 5643 r->set_method("POST");
5674 5644
5675 r->Start(); 5645 r->Start();
5676 EXPECT_TRUE(r->is_pending()); 5646 EXPECT_TRUE(r->is_pending());
5677 5647
5678 base::RunLoop().Run(); 5648 base::RunLoop().Run();
5679 5649
5680 ASSERT_EQ(1, d.response_started_count()) 5650 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: "
5681 << "request failed: " << r->status().status() 5651 << d.request_status();
5682 << ", error: " << r->status().error();
5683 5652
5684 EXPECT_FALSE(d.received_data_before_response()); 5653 EXPECT_FALSE(d.received_data_before_response());
5685 EXPECT_TRUE(d.data_received().empty()); 5654 EXPECT_TRUE(d.data_received().empty());
5686 } 5655 }
5687 } 5656 }
5688 5657
5689 TEST_F(URLRequestTestHTTP, PostFileTest) { 5658 TEST_F(URLRequestTestHTTP, PostFileTest) {
5690 ASSERT_TRUE(http_test_server()->Start()); 5659 ASSERT_TRUE(http_test_server()->Start());
5691 5660
5692 TestDelegate d; 5661 TestDelegate d;
(...skipping 24 matching lines...) Expand all
5717 base::RunLoop().Run(); 5686 base::RunLoop().Run();
5718 5687
5719 int64_t size64 = 0; 5688 int64_t size64 = 0;
5720 ASSERT_EQ(true, base::GetFileSize(path, &size64)); 5689 ASSERT_EQ(true, base::GetFileSize(path, &size64));
5721 ASSERT_LE(size64, std::numeric_limits<int>::max()); 5690 ASSERT_LE(size64, std::numeric_limits<int>::max());
5722 int size = static_cast<int>(size64); 5691 int size = static_cast<int>(size64);
5723 std::unique_ptr<char[]> buf(new char[size]); 5692 std::unique_ptr<char[]> buf(new char[size]);
5724 5693
5725 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); 5694 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size));
5726 5695
5727 ASSERT_EQ(1, d.response_started_count()) 5696 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: "
5728 << "request failed: " << r->status().status() 5697 << d.request_status();
5729 << ", error: " << r->status().error();
5730 5698
5731 EXPECT_FALSE(d.received_data_before_response()); 5699 EXPECT_FALSE(d.received_data_before_response());
5732 5700
5733 EXPECT_EQ(size, d.bytes_received()); 5701 EXPECT_EQ(size, d.bytes_received());
5734 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); 5702 EXPECT_EQ(std::string(&buf[0], size), d.data_received());
5735 } 5703 }
5736 } 5704 }
5737 5705
5738 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { 5706 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) {
5739 ASSERT_TRUE(http_test_server()->Start()); 5707 ASSERT_TRUE(http_test_server()->Start());
(...skipping 15 matching lines...) Expand all
5755 new ElementsUploadDataStream(std::move(element_readers), 0))); 5723 new ElementsUploadDataStream(std::move(element_readers), 0)));
5756 5724
5757 r->Start(); 5725 r->Start();
5758 EXPECT_TRUE(r->is_pending()); 5726 EXPECT_TRUE(r->is_pending());
5759 5727
5760 base::RunLoop().Run(); 5728 base::RunLoop().Run();
5761 5729
5762 EXPECT_TRUE(d.request_failed()); 5730 EXPECT_TRUE(d.request_failed());
5763 EXPECT_FALSE(d.received_data_before_response()); 5731 EXPECT_FALSE(d.received_data_before_response());
5764 EXPECT_EQ(0, d.bytes_received()); 5732 EXPECT_EQ(0, d.bytes_received());
5765 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 5733 EXPECT_EQ(ERR_FILE_NOT_FOUND, d.request_status());
5766 EXPECT_THAT(r->status().error(), IsError(ERR_FILE_NOT_FOUND));
5767 } 5734 }
5768 } 5735 }
5769 5736
5770 namespace { 5737 namespace {
5771 5738
5772 // Adds a standard set of data to an upload for chunked upload integration 5739 // Adds a standard set of data to an upload for chunked upload integration
5773 // tests. 5740 // tests.
5774 void AddDataToUpload(ChunkedUploadDataStream::Writer* writer) { 5741 void AddDataToUpload(ChunkedUploadDataStream::Writer* writer) {
5775 writer->AppendData("a", 1, false); 5742 writer->AppendData("a", 1, false);
5776 writer->AppendData("bcd", 3, false); 5743 writer->AppendData("bcd", 3, false);
5777 writer->AppendData("this is a longer chunk than before.", 35, false); 5744 writer->AppendData("this is a longer chunk than before.", 35, false);
5778 writer->AppendData("\r\n\r\n", 4, false); 5745 writer->AppendData("\r\n\r\n", 4, false);
5779 writer->AppendData("0", 1, false); 5746 writer->AppendData("0", 1, false);
5780 writer->AppendData("2323", 4, true); 5747 writer->AppendData("2323", 4, true);
5781 } 5748 }
5782 5749
5783 // Checks that the upload data added in AddChunksToUpload() was echoed back from 5750 // Checks that the upload data added in AddChunksToUpload() was echoed back from
5784 // the server. 5751 // the server.
5785 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) { 5752 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) {
5786 // This should match the chunks sent by AddChunksToUpload(). 5753 // This should match the chunks sent by AddChunksToUpload().
5787 const std::string expected_data = 5754 const std::string expected_data =
5788 "abcdthis is a longer chunk than before.\r\n\r\n02323"; 5755 "abcdthis is a longer chunk than before.\r\n\r\n02323";
5789 5756
5790 ASSERT_EQ(1, d->response_started_count()) 5757 ASSERT_EQ(1, d->response_started_count()) << "request failed. Error: "
5791 << "request failed: " << r->status().status() 5758 << d->request_status();
5792 << ", os error: " << r->status().error();
5793 5759
5794 EXPECT_FALSE(d->received_data_before_response()); 5760 EXPECT_FALSE(d->received_data_before_response());
5795 5761
5796 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); 5762 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received()));
5797 EXPECT_EQ(expected_data, d->data_received()); 5763 EXPECT_EQ(expected_data, d->data_received());
5798 } 5764 }
5799 5765
5800 } // namespace 5766 } // namespace
5801 5767
5802 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 5768 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
6534 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 6500 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
6535 ASSERT_TRUE(http_test_server()->Start()); 6501 ASSERT_TRUE(http_test_server()->Start());
6536 6502
6537 TestDelegate d; 6503 TestDelegate d;
6538 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6504 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6539 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY, 6505 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY,
6540 &d)); 6506 &d));
6541 req->Start(); 6507 req->Start();
6542 base::RunLoop().Run(); 6508 base::RunLoop().Run();
6543 6509
6544 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 6510 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
6545 EXPECT_THAT(req->status().error(), IsError(ERR_UNSAFE_REDIRECT));
6546 } 6511 }
6547 #endif // !defined(DISABLE_FILE_SUPPORT) 6512 #endif // !defined(DISABLE_FILE_SUPPORT)
6548 6513
6549 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 6514 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
6550 ASSERT_TRUE(http_test_server()->Start()); 6515 ASSERT_TRUE(http_test_server()->Start());
6551 6516
6552 TestDelegate d; 6517 TestDelegate d;
6553 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6518 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6554 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY, 6519 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY,
6555 &d)); 6520 &d));
6556 req->Start(); 6521 req->Start();
6557 base::RunLoop().Run(); 6522 base::RunLoop().Run();
6558 6523
6559 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 6524 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
6560 EXPECT_THAT(req->status().error(), IsError(ERR_UNSAFE_REDIRECT));
6561 } 6525 }
6562 6526
6563 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 6527 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
6564 ASSERT_TRUE(http_test_server()->Start()); 6528 ASSERT_TRUE(http_test_server()->Start());
6565 6529
6566 TestDelegate d; 6530 TestDelegate d;
6567 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6531 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6568 http_test_server()->GetURL("/redirect-to-invalid-url.html"), 6532 http_test_server()->GetURL("/redirect-to-invalid-url.html"),
6569 DEFAULT_PRIORITY, &d)); 6533 DEFAULT_PRIORITY, &d));
6570 req->Start(); 6534 req->Start();
6571 base::RunLoop().Run(); 6535 base::RunLoop().Run();
6572 6536
6573 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 6537 EXPECT_EQ(ERR_INVALID_URL, d.request_status());
6574 EXPECT_THAT(req->status().error(), IsError(ERR_INVALID_URL));
6575 } 6538 }
6576 6539
6577 // Make sure redirects are cached, despite not reading their bodies. 6540 // Make sure redirects are cached, despite not reading their bodies.
6578 TEST_F(URLRequestTestHTTP, CacheRedirect) { 6541 TEST_F(URLRequestTestHTTP, CacheRedirect) {
6579 ASSERT_TRUE(http_test_server()->Start()); 6542 ASSERT_TRUE(http_test_server()->Start());
6580 GURL redirect_url = 6543 GURL redirect_url =
6581 http_test_server()->GetURL("/redirect302-to-echo-cacheable"); 6544 http_test_server()->GetURL("/redirect302-to-echo-cacheable");
6582 6545
6583 { 6546 {
6584 TestDelegate d; 6547 TestDelegate d;
6585 std::unique_ptr<URLRequest> req( 6548 std::unique_ptr<URLRequest> req(
6586 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); 6549 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
6587 req->Start(); 6550 req->Start();
6588 base::RunLoop().Run(); 6551 base::RunLoop().Run();
6589 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6552 EXPECT_EQ(OK, d.request_status());
6590 EXPECT_EQ(1, d.received_redirect_count()); 6553 EXPECT_EQ(1, d.received_redirect_count());
6591 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); 6554 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url());
6592 } 6555 }
6593 6556
6594 { 6557 {
6595 TestDelegate d; 6558 TestDelegate d;
6596 d.set_quit_on_redirect(true); 6559 d.set_quit_on_redirect(true);
6597 std::unique_ptr<URLRequest> req( 6560 std::unique_ptr<URLRequest> req(
6598 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); 6561 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
6599 req->Start(); 6562 req->Start();
6600 base::RunLoop().Run(); 6563 base::RunLoop().Run();
6601 6564
6602 EXPECT_EQ(1, d.received_redirect_count()); 6565 EXPECT_EQ(1, d.received_redirect_count());
6603 EXPECT_EQ(0, d.response_started_count()); 6566 EXPECT_EQ(0, d.response_started_count());
6604 EXPECT_TRUE(req->was_cached()); 6567 EXPECT_TRUE(req->was_cached());
6605 6568
6606 req->FollowDeferredRedirect(); 6569 req->FollowDeferredRedirect();
6607 base::RunLoop().Run(); 6570 base::RunLoop().Run();
6608 EXPECT_EQ(1, d.received_redirect_count()); 6571 EXPECT_EQ(1, d.received_redirect_count());
6609 EXPECT_EQ(1, d.response_started_count()); 6572 EXPECT_EQ(1, d.response_started_count());
6610 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6573 EXPECT_EQ(OK, d.request_status());
6611 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); 6574 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url());
6612 } 6575 }
6613 } 6576 }
6614 6577
6615 // Make sure a request isn't cached when a NetworkDelegate forces a redirect 6578 // Make sure a request isn't cached when a NetworkDelegate forces a redirect
6616 // when the headers are read, since the body won't have been read. 6579 // when the headers are read, since the body won't have been read.
6617 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { 6580 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) {
6618 ASSERT_TRUE(http_test_server()->Start()); 6581 ASSERT_TRUE(http_test_server()->Start());
6619 // URL that is normally cached. 6582 // URL that is normally cached.
6620 GURL initial_url = http_test_server()->GetURL("/cachetime"); 6583 GURL initial_url = http_test_server()->GetURL("/cachetime");
6621 6584
6622 { 6585 {
6623 // Set up the TestNetworkDelegate tp force a redirect. 6586 // Set up the TestNetworkDelegate tp force a redirect.
6624 GURL redirect_to_url = http_test_server()->GetURL("/echo"); 6587 GURL redirect_to_url = http_test_server()->GetURL("/echo");
6625 default_network_delegate_.set_redirect_on_headers_received_url( 6588 default_network_delegate_.set_redirect_on_headers_received_url(
6626 redirect_to_url); 6589 redirect_to_url);
6627 6590
6628 TestDelegate d; 6591 TestDelegate d;
6629 std::unique_ptr<URLRequest> req( 6592 std::unique_ptr<URLRequest> req(
6630 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); 6593 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d));
6631 req->Start(); 6594 req->Start();
6632 base::RunLoop().Run(); 6595 base::RunLoop().Run();
6633 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6596 EXPECT_EQ(OK, d.request_status());
6634 EXPECT_EQ(1, d.received_redirect_count()); 6597 EXPECT_EQ(1, d.received_redirect_count());
6635 EXPECT_EQ(redirect_to_url, req->url()); 6598 EXPECT_EQ(redirect_to_url, req->url());
6636 } 6599 }
6637 6600
6638 { 6601 {
6639 TestDelegate d; 6602 TestDelegate d;
6640 std::unique_ptr<URLRequest> req( 6603 std::unique_ptr<URLRequest> req(
6641 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); 6604 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d));
6642 req->Start(); 6605 req->Start();
6643 base::RunLoop().Run(); 6606 base::RunLoop().Run();
6644 6607
6645 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6608 EXPECT_EQ(OK, d.request_status());
6646 EXPECT_FALSE(req->was_cached()); 6609 EXPECT_FALSE(req->was_cached());
6647 EXPECT_EQ(0, d.received_redirect_count()); 6610 EXPECT_EQ(0, d.received_redirect_count());
6648 EXPECT_EQ(initial_url, req->url()); 6611 EXPECT_EQ(initial_url, req->url());
6649 } 6612 }
6650 } 6613 }
6651 6614
6652 // Tests that redirection to an unsafe URL is allowed when it has been marked as 6615 // Tests that redirection to an unsafe URL is allowed when it has been marked as
6653 // safe. 6616 // safe.
6654 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { 6617 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) {
6655 ASSERT_TRUE(http_test_server()->Start()); 6618 ASSERT_TRUE(http_test_server()->Start());
6656 6619
6657 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); 6620 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url");
6658 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 6621 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
6659 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 6622 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
6660 6623
6661 TestDelegate d; 6624 TestDelegate d;
6662 { 6625 {
6663 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 6626 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
6664 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); 6627 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d));
6665 6628
6666 r->Start(); 6629 r->Start();
6667 base::RunLoop().Run(); 6630 base::RunLoop().Run();
6668 6631
6669 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6632 EXPECT_EQ(OK, d.request_status());
6670
6671 EXPECT_EQ(2U, r->url_chain().size()); 6633 EXPECT_EQ(2U, r->url_chain().size());
6672 EXPECT_THAT(r->status().error(), IsOk());
6673 EXPECT_EQ(unsafe_url, r->url()); 6634 EXPECT_EQ(unsafe_url, r->url());
6674 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); 6635 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received());
6675 } 6636 }
6676 } 6637 }
6677 6638
6678 // Tests that a redirect to a different unsafe URL is blocked, even after adding 6639 // Tests that a redirect to a different unsafe URL is blocked, even after adding
6679 // some other URL to the whitelist. 6640 // some other URL to the whitelist.
6680 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { 6641 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) {
6681 ASSERT_TRUE(http_test_server()->Start()); 6642 ASSERT_TRUE(http_test_server()->Start());
6682 6643
6683 GURL unsafe_url("data:text/html,something"); 6644 GURL unsafe_url("data:text/html,something");
6684 GURL different_unsafe_url("data:text/html,something-else"); 6645 GURL different_unsafe_url("data:text/html,something-else");
6685 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 6646 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
6686 default_network_delegate_.set_allowed_unsafe_redirect_url( 6647 default_network_delegate_.set_allowed_unsafe_redirect_url(
6687 different_unsafe_url); 6648 different_unsafe_url);
6688 6649
6689 TestDelegate d; 6650 TestDelegate d;
6690 { 6651 {
6691 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 6652 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
6692 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); 6653 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d));
6693 6654
6694 r->Start(); 6655 r->Start();
6695 base::RunLoop().Run(); 6656 base::RunLoop().Run();
6696 6657
6697 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 6658 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status());
6698 EXPECT_THAT(r->status().error(), IsError(ERR_UNSAFE_REDIRECT));
6699 } 6659 }
6700 } 6660 }
6701 6661
6702 // Redirects from an URL with fragment to an unsafe URL with fragment should 6662 // Redirects from an URL with fragment to an unsafe URL with fragment should
6703 // be allowed, and the reference fragment of the target URL should be preserved. 6663 // be allowed, and the reference fragment of the target URL should be preserved.
6704 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { 6664 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) {
6705 ASSERT_TRUE(http_test_server()->Start()); 6665 ASSERT_TRUE(http_test_server()->Start());
6706 6666
6707 GURL original_url(http_test_server()->GetURL("/original#fragment1")); 6667 GURL original_url(http_test_server()->GetURL("/original#fragment1"));
6708 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 6668 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
6709 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 6669 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
6710 6670
6711 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 6671 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
6712 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 6672 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
6713 6673
6714 TestDelegate d; 6674 TestDelegate d;
6715 { 6675 {
6716 std::unique_ptr<URLRequest> r( 6676 std::unique_ptr<URLRequest> r(
6717 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 6677 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6718 6678
6719 r->Start(); 6679 r->Start();
6720 base::RunLoop().Run(); 6680 base::RunLoop().Run();
6721 6681
6722 EXPECT_EQ(2U, r->url_chain().size()); 6682 EXPECT_EQ(2U, r->url_chain().size());
6723 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6683 EXPECT_EQ(OK, d.request_status());
6724 EXPECT_THAT(r->status().error(), IsOk());
6725 EXPECT_EQ(original_url, r->original_url()); 6684 EXPECT_EQ(original_url, r->original_url());
6726 EXPECT_EQ(expected_url, r->url()); 6685 EXPECT_EQ(expected_url, r->url());
6727 } 6686 }
6728 } 6687 }
6729 6688
6730 // When a delegate has specified a safe redirect URL, but it does not match the 6689 // When a delegate has specified a safe redirect URL, but it does not match the
6731 // redirect target, then do not prevent the reference fragment from being added. 6690 // redirect target, then do not prevent the reference fragment from being added.
6732 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { 6691 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) {
6733 ASSERT_TRUE(http_test_server()->Start()); 6692 ASSERT_TRUE(http_test_server()->Start());
6734 6693
6735 GURL original_url(http_test_server()->GetURL("/original#expected-fragment")); 6694 GURL original_url(http_test_server()->GetURL("/original#expected-fragment"));
6736 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); 6695 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url");
6737 GURL redirect_url(http_test_server()->GetURL("/target")); 6696 GURL redirect_url(http_test_server()->GetURL("/target"));
6738 GURL expected_redirect_url( 6697 GURL expected_redirect_url(
6739 http_test_server()->GetURL("/target#expected-fragment")); 6698 http_test_server()->GetURL("/target#expected-fragment"));
6740 6699
6741 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 6700 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
6742 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 6701 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
6743 6702
6744 TestDelegate d; 6703 TestDelegate d;
6745 { 6704 {
6746 std::unique_ptr<URLRequest> r( 6705 std::unique_ptr<URLRequest> r(
6747 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 6706 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6748 6707
6749 r->Start(); 6708 r->Start();
6750 base::RunLoop().Run(); 6709 base::RunLoop().Run();
6751 6710
6752 EXPECT_EQ(2U, r->url_chain().size()); 6711 EXPECT_EQ(2U, r->url_chain().size());
6753 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6712 EXPECT_EQ(OK, d.request_status());
6754 EXPECT_THAT(r->status().error(), IsOk());
6755 EXPECT_EQ(original_url, r->original_url()); 6713 EXPECT_EQ(original_url, r->original_url());
6756 EXPECT_EQ(expected_redirect_url, r->url()); 6714 EXPECT_EQ(expected_redirect_url, r->url());
6757 } 6715 }
6758 } 6716 }
6759 6717
6760 // When a delegate has specified a safe redirect URL, assume that the redirect 6718 // When a delegate has specified a safe redirect URL, assume that the redirect
6761 // URL should not be changed. In particular, the reference fragment should not 6719 // URL should not be changed. In particular, the reference fragment should not
6762 // be modified. 6720 // be modified.
6763 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { 6721 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) {
6764 ASSERT_TRUE(http_test_server()->Start()); 6722 ASSERT_TRUE(http_test_server()->Start());
6765 6723
6766 GURL original_url( 6724 GURL original_url(
6767 http_test_server()->GetURL("/original#should-not-be-appended")); 6725 http_test_server()->GetURL("/original#should-not-be-appended"));
6768 GURL redirect_url("data:text/html,expect-no-reference-fragment"); 6726 GURL redirect_url("data:text/html,expect-no-reference-fragment");
6769 6727
6770 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 6728 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
6771 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); 6729 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url);
6772 6730
6773 TestDelegate d; 6731 TestDelegate d;
6774 { 6732 {
6775 std::unique_ptr<URLRequest> r( 6733 std::unique_ptr<URLRequest> r(
6776 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 6734 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6777 6735
6778 r->Start(); 6736 r->Start();
6779 base::RunLoop().Run(); 6737 base::RunLoop().Run();
6780 6738
6781 EXPECT_EQ(2U, r->url_chain().size()); 6739 EXPECT_EQ(2U, r->url_chain().size());
6782 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6740 EXPECT_EQ(OK, d.request_status());
6783 EXPECT_THAT(r->status().error(), IsOk());
6784 EXPECT_EQ(original_url, r->original_url()); 6741 EXPECT_EQ(original_url, r->original_url());
6785 EXPECT_EQ(redirect_url, r->url()); 6742 EXPECT_EQ(redirect_url, r->url());
6786 } 6743 }
6787 } 6744 }
6788 6745
6789 // When a URLRequestRedirectJob is created, the redirection must be followed and 6746 // When a URLRequestRedirectJob is created, the redirection must be followed and
6790 // the reference fragment of the target URL must not be modified. 6747 // the reference fragment of the target URL must not be modified.
6791 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { 6748 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) {
6792 ASSERT_TRUE(http_test_server()->Start()); 6749 ASSERT_TRUE(http_test_server()->Start());
6793 6750
6794 GURL original_url( 6751 GURL original_url(
6795 http_test_server()->GetURL("/original#should-not-be-appended")); 6752 http_test_server()->GetURL("/original#should-not-be-appended"));
6796 GURL redirect_url(http_test_server()->GetURL("/echo")); 6753 GURL redirect_url(http_test_server()->GetURL("/echo"));
6797 6754
6798 TestDelegate d; 6755 TestDelegate d;
6799 std::unique_ptr<URLRequest> r( 6756 std::unique_ptr<URLRequest> r(
6800 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 6757 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6801 6758
6802 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 6759 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
6803 r.get(), &default_network_delegate_, redirect_url, 6760 r.get(), &default_network_delegate_, redirect_url,
6804 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); 6761 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
6805 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 6762 AddTestInterceptor()->set_main_intercept_job(std::move(job));
6806 6763
6807 r->Start(); 6764 r->Start();
6808 base::RunLoop().Run(); 6765 base::RunLoop().Run();
6809 6766
6810 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6767 EXPECT_EQ(OK, d.request_status());
6811 EXPECT_THAT(r->status().error(), IsOk());
6812 EXPECT_EQ(original_url, r->original_url()); 6768 EXPECT_EQ(original_url, r->original_url());
6813 EXPECT_EQ(redirect_url, r->url()); 6769 EXPECT_EQ(redirect_url, r->url());
6814 } 6770 }
6815 6771
6816 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) { 6772 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) {
6817 ASSERT_TRUE(http_test_server()->Start()); 6773 ASSERT_TRUE(http_test_server()->Start());
6818 6774
6819 const std::string referrer("foobar://totally.legit.referrer"); 6775 const std::string referrer("foobar://totally.legit.referrer");
6820 TestDelegate d; 6776 TestDelegate d;
6821 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6777 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
6875 d.set_cancel_in_received_redirect(true); 6831 d.set_cancel_in_received_redirect(true);
6876 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6832 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6877 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, 6833 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY,
6878 &d)); 6834 &d));
6879 req->Start(); 6835 req->Start();
6880 base::RunLoop().Run(); 6836 base::RunLoop().Run();
6881 6837
6882 EXPECT_EQ(1, d.response_started_count()); 6838 EXPECT_EQ(1, d.response_started_count());
6883 EXPECT_EQ(0, d.bytes_received()); 6839 EXPECT_EQ(0, d.bytes_received());
6884 EXPECT_FALSE(d.received_data_before_response()); 6840 EXPECT_FALSE(d.received_data_before_response());
6885 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 6841 EXPECT_EQ(ERR_ABORTED, d.request_status());
6886 } 6842 }
6887 } 6843 }
6888 6844
6889 TEST_F(URLRequestTestHTTP, DeferredRedirect) { 6845 TEST_F(URLRequestTestHTTP, DeferredRedirect) {
6890 ASSERT_TRUE(http_test_server()->Start()); 6846 ASSERT_TRUE(http_test_server()->Start());
6891 6847
6892 TestDelegate d; 6848 TestDelegate d;
6893 { 6849 {
6894 d.set_quit_on_redirect(true); 6850 d.set_quit_on_redirect(true);
6895 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); 6851 GURL test_url(http_test_server()->GetURL("/redirect-test.html"));
6896 std::unique_ptr<URLRequest> req( 6852 std::unique_ptr<URLRequest> req(
6897 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); 6853 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
6898 6854
6899 req->Start(); 6855 req->Start();
6900 base::RunLoop().Run(); 6856 base::RunLoop().Run();
6901 6857
6902 EXPECT_EQ(1, d.received_redirect_count()); 6858 EXPECT_EQ(1, d.received_redirect_count());
6903 6859
6904 req->FollowDeferredRedirect(); 6860 req->FollowDeferredRedirect();
6905 base::RunLoop().Run(); 6861 base::RunLoop().Run();
6906 6862
6907 EXPECT_EQ(1, d.response_started_count()); 6863 EXPECT_EQ(1, d.response_started_count());
6908 EXPECT_FALSE(d.received_data_before_response()); 6864 EXPECT_FALSE(d.received_data_before_response());
6909 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6865 EXPECT_EQ(OK, d.request_status());
6910 6866
6911 base::FilePath path; 6867 base::FilePath path;
6912 PathService::Get(base::DIR_SOURCE_ROOT, &path); 6868 PathService::Get(base::DIR_SOURCE_ROOT, &path);
6913 path = path.Append(kTestFilePath); 6869 path = path.Append(kTestFilePath);
6914 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 6870 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
6915 6871
6916 std::string contents; 6872 std::string contents;
6917 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 6873 EXPECT_TRUE(base::ReadFileToString(path, &contents));
6918 EXPECT_EQ(contents, d.data_received()); 6874 EXPECT_EQ(contents, d.data_received());
6919 } 6875 }
(...skipping 20 matching lines...) Expand all
6940 d.ClearFullRequestHeaders(); 6896 d.ClearFullRequestHeaders();
6941 6897
6942 req->FollowDeferredRedirect(); 6898 req->FollowDeferredRedirect();
6943 base::RunLoop().Run(); 6899 base::RunLoop().Run();
6944 6900
6945 GURL target_url(http_test_server()->GetURL("/with-headers.html")); 6901 GURL target_url(http_test_server()->GetURL("/with-headers.html"));
6946 EXPECT_EQ(1, d.response_started_count()); 6902 EXPECT_EQ(1, d.response_started_count());
6947 EXPECT_TRUE(d.have_full_request_headers()); 6903 EXPECT_TRUE(d.have_full_request_headers());
6948 CheckFullRequestHeaders(d.full_request_headers(), target_url); 6904 CheckFullRequestHeaders(d.full_request_headers(), target_url);
6949 EXPECT_FALSE(d.received_data_before_response()); 6905 EXPECT_FALSE(d.received_data_before_response());
6950 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 6906 EXPECT_EQ(OK, d.request_status());
6951 6907
6952 base::FilePath path; 6908 base::FilePath path;
6953 PathService::Get(base::DIR_SOURCE_ROOT, &path); 6909 PathService::Get(base::DIR_SOURCE_ROOT, &path);
6954 path = path.Append(kTestFilePath); 6910 path = path.Append(kTestFilePath);
6955 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 6911 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
6956 6912
6957 std::string contents; 6913 std::string contents;
6958 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 6914 EXPECT_TRUE(base::ReadFileToString(path, &contents));
6959 EXPECT_EQ(contents, d.data_received()); 6915 EXPECT_EQ(contents, d.data_received());
6960 } 6916 }
(...skipping 12 matching lines...) Expand all
6973 base::RunLoop().Run(); 6929 base::RunLoop().Run();
6974 6930
6975 EXPECT_EQ(1, d.received_redirect_count()); 6931 EXPECT_EQ(1, d.received_redirect_count());
6976 6932
6977 req->Cancel(); 6933 req->Cancel();
6978 base::RunLoop().Run(); 6934 base::RunLoop().Run();
6979 6935
6980 EXPECT_EQ(1, d.response_started_count()); 6936 EXPECT_EQ(1, d.response_started_count());
6981 EXPECT_EQ(0, d.bytes_received()); 6937 EXPECT_EQ(0, d.bytes_received());
6982 EXPECT_FALSE(d.received_data_before_response()); 6938 EXPECT_FALSE(d.received_data_before_response());
6983 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 6939 EXPECT_EQ(ERR_ABORTED, d.request_status());
6984 } 6940 }
6985 } 6941 }
6986 6942
6987 TEST_F(URLRequestTestHTTP, VaryHeader) { 6943 TEST_F(URLRequestTestHTTP, VaryHeader) {
6988 ASSERT_TRUE(http_test_server()->Start()); 6944 ASSERT_TRUE(http_test_server()->Start());
6989 6945
6990 // Populate the cache. 6946 // Populate the cache.
6991 { 6947 {
6992 TestDelegate d; 6948 TestDelegate d;
6993 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6949 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
7351 ASSERT_TRUE(http_test_server()->Start()); 7307 ASSERT_TRUE(http_test_server()->Start());
7352 7308
7353 TestDelegate d; 7309 TestDelegate d;
7354 const GURL url = http_test_server()->GetURL("/308-without-location-header"); 7310 const GURL url = http_test_server()->GetURL("/308-without-location-header");
7355 7311
7356 std::unique_ptr<URLRequest> request( 7312 std::unique_ptr<URLRequest> request(
7357 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); 7313 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
7358 7314
7359 request->Start(); 7315 request->Start();
7360 base::RunLoop().Run(); 7316 base::RunLoop().Run();
7361 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); 7317 EXPECT_EQ(OK, d.request_status());
7362 EXPECT_THAT(request->status().error(), IsOk());
7363 EXPECT_EQ(0, d.received_redirect_count()); 7318 EXPECT_EQ(0, d.received_redirect_count());
7364 EXPECT_EQ(308, request->response_headers()->response_code()); 7319 EXPECT_EQ(308, request->response_headers()->response_code());
7365 EXPECT_EQ("This is not a redirect.", d.data_received()); 7320 EXPECT_EQ("This is not a redirect.", d.data_received());
7366 } 7321 }
7367 7322
7368 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { 7323 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) {
7369 ASSERT_TRUE(http_test_server()->Start()); 7324 ASSERT_TRUE(http_test_server()->Start());
7370 7325
7371 GURL original_url( 7326 GURL original_url(
7372 http_test_server()->GetURL("/redirect302-to-echo#fragment")); 7327 http_test_server()->GetURL("/redirect302-to-echo#fragment"));
7373 GURL expected_url(http_test_server()->GetURL("/echo#fragment")); 7328 GURL expected_url(http_test_server()->GetURL("/echo#fragment"));
7374 7329
7375 TestDelegate d; 7330 TestDelegate d;
7376 { 7331 {
7377 std::unique_ptr<URLRequest> r( 7332 std::unique_ptr<URLRequest> r(
7378 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 7333 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
7379 7334
7380 r->Start(); 7335 r->Start();
7381 base::RunLoop().Run(); 7336 base::RunLoop().Run();
7382 7337
7383 EXPECT_EQ(2U, r->url_chain().size()); 7338 EXPECT_EQ(2U, r->url_chain().size());
7384 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 7339 EXPECT_EQ(OK, d.request_status());
7385 EXPECT_THAT(r->status().error(), IsOk());
7386 EXPECT_EQ(original_url, r->original_url()); 7340 EXPECT_EQ(original_url, r->original_url());
7387 EXPECT_EQ(expected_url, r->url()); 7341 EXPECT_EQ(expected_url, r->url());
7388 } 7342 }
7389 } 7343 }
7390 7344
7391 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { 7345 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) {
7392 ASSERT_TRUE(http_test_server()->Start()); 7346 ASSERT_TRUE(http_test_server()->Start());
7393 7347
7394 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); 7348 GURL url(http_test_server()->GetURL("/redirect302-to-echo"));
7395 GURL first_party_url("http://example.com"); 7349 GURL first_party_url("http://example.com");
7396 7350
7397 TestDelegate d; 7351 TestDelegate d;
7398 { 7352 {
7399 std::unique_ptr<URLRequest> r( 7353 std::unique_ptr<URLRequest> r(
7400 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); 7354 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
7401 r->set_first_party_for_cookies(first_party_url); 7355 r->set_first_party_for_cookies(first_party_url);
7402 7356
7403 r->Start(); 7357 r->Start();
7404 base::RunLoop().Run(); 7358 base::RunLoop().Run();
7405 7359
7406 EXPECT_EQ(2U, r->url_chain().size()); 7360 EXPECT_EQ(2U, r->url_chain().size());
7407 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 7361 EXPECT_EQ(OK, d.request_status());
7408 EXPECT_THAT(r->status().error(), IsOk());
7409 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); 7362 EXPECT_EQ(first_party_url, r->first_party_for_cookies());
7410 } 7363 }
7411 } 7364 }
7412 7365
7413 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { 7366 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) {
7414 ASSERT_TRUE(http_test_server()->Start()); 7367 ASSERT_TRUE(http_test_server()->Start());
7415 7368
7416 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); 7369 GURL url(http_test_server()->GetURL("/redirect302-to-echo"));
7417 GURL original_first_party_url("http://example.com"); 7370 GURL original_first_party_url("http://example.com");
7418 GURL expected_first_party_url(http_test_server()->GetURL("/echo")); 7371 GURL expected_first_party_url(http_test_server()->GetURL("/echo"));
7419 7372
7420 TestDelegate d; 7373 TestDelegate d;
7421 { 7374 {
7422 std::unique_ptr<URLRequest> r( 7375 std::unique_ptr<URLRequest> r(
7423 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); 7376 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
7424 r->set_first_party_for_cookies(original_first_party_url); 7377 r->set_first_party_for_cookies(original_first_party_url);
7425 r->set_first_party_url_policy( 7378 r->set_first_party_url_policy(
7426 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 7379 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
7427 7380
7428 r->Start(); 7381 r->Start();
7429 base::RunLoop().Run(); 7382 base::RunLoop().Run();
7430 7383
7431 EXPECT_EQ(2U, r->url_chain().size()); 7384 EXPECT_EQ(2U, r->url_chain().size());
7432 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 7385 EXPECT_EQ(OK, d.request_status());
7433 EXPECT_THAT(r->status().error(), IsOk());
7434 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); 7386 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies());
7435 } 7387 }
7436 } 7388 }
7437 7389
7438 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 7390 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
7439 ASSERT_TRUE(http_test_server()->Start()); 7391 ASSERT_TRUE(http_test_server()->Start());
7440 7392
7441 const char kData[] = "hello world"; 7393 const char kData[] = "hello world";
7442 7394
7443 TestDelegate d; 7395 TestDelegate d;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
7713 context.set_http_transaction_factory(&http_cache); 7665 context.set_http_transaction_factory(&http_cache);
7714 context.Init(); 7666 context.Init();
7715 7667
7716 TestDelegate d; 7668 TestDelegate d;
7717 std::unique_ptr<URLRequest> req( 7669 std::unique_ptr<URLRequest> req(
7718 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); 7670 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d));
7719 req->Start(); 7671 req->Start();
7720 base::RunLoop().Run(); 7672 base::RunLoop().Run();
7721 7673
7722 EXPECT_TRUE(d.request_failed()); 7674 EXPECT_TRUE(d.request_failed());
7723 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 7675 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, d.request_status());
7724 EXPECT_THAT(req->status().error(), IsError(ERR_NETWORK_IO_SUSPENDED));
7725 } 7676 }
7726 7677
7727 namespace { 7678 namespace {
7728 7679
7729 // HttpTransactionFactory that synchronously fails to create transactions. 7680 // HttpTransactionFactory that synchronously fails to create transactions.
7730 class FailingHttpTransactionFactory : public HttpTransactionFactory { 7681 class FailingHttpTransactionFactory : public HttpTransactionFactory {
7731 public: 7682 public:
7732 explicit FailingHttpTransactionFactory(HttpNetworkSession* network_session) 7683 explicit FailingHttpTransactionFactory(HttpNetworkSession* network_session)
7733 : network_session_(network_session) {} 7684 : network_session_(network_session) {}
7734 7685
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7774 // try to create an HttpNetworkTransaction synchronously on start). 7725 // try to create an HttpNetworkTransaction synchronously on start).
7775 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); 7726 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES);
7776 req->Start(); 7727 req->Start();
7777 req->Cancel(); 7728 req->Cancel();
7778 base::RunLoop().Run(); 7729 base::RunLoop().Run();
7779 // Run pending error task, if there is one. 7730 // Run pending error task, if there is one.
7780 base::RunLoop().RunUntilIdle(); 7731 base::RunLoop().RunUntilIdle();
7781 7732
7782 EXPECT_TRUE(d.request_failed()); 7733 EXPECT_TRUE(d.request_failed());
7783 EXPECT_EQ(1, d.response_started_count()); 7734 EXPECT_EQ(1, d.response_started_count());
7784 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 7735 EXPECT_EQ(ERR_ABORTED, d.request_status());
7785 7736
7786 // NetworkDelegate should see the cancellation, but not the error. 7737 // NetworkDelegate should see the cancellation, but not the error.
7787 EXPECT_EQ(1, default_network_delegate()->canceled_requests()); 7738 EXPECT_EQ(1, default_network_delegate()->canceled_requests());
7788 EXPECT_EQ(0, default_network_delegate()->error_count()); 7739 EXPECT_EQ(0, default_network_delegate()->error_count());
7789 } 7740 }
7790 7741
7791 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { 7742 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) {
7792 ASSERT_TRUE(http_test_server()->Start()); 7743 ASSERT_TRUE(http_test_server()->Start());
7793 7744
7794 TestDelegate d; 7745 TestDelegate d;
(...skipping 10 matching lines...) Expand all
7805 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { 7756 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) {
7806 ASSERT_TRUE(http_test_server()->Start()); 7757 ASSERT_TRUE(http_test_server()->Start());
7807 7758
7808 // Populate the cache. 7759 // Populate the cache.
7809 TestDelegate d; 7760 TestDelegate d;
7810 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 7761 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
7811 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); 7762 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d));
7812 req->Start(); 7763 req->Start();
7813 base::RunLoop().Run(); 7764 base::RunLoop().Run();
7814 7765
7815 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 7766 EXPECT_EQ(OK, d.request_status());
7816 EXPECT_TRUE(req->response_info().network_accessed); 7767 EXPECT_TRUE(req->response_info().network_accessed);
7817 EXPECT_FALSE(req->response_info().was_cached); 7768 EXPECT_FALSE(req->response_info().was_cached);
7818 7769
7819 req = default_context_.CreateRequest(http_test_server()->GetURL("/cachetime"), 7770 req = default_context_.CreateRequest(http_test_server()->GetURL("/cachetime"),
7820 DEFAULT_PRIORITY, &d); 7771 DEFAULT_PRIORITY, &d);
7821 req->Start(); 7772 req->Start();
7822 base::RunLoop().Run(); 7773 base::RunLoop().Run();
7823 7774
7824 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 7775 EXPECT_EQ(OK, d.request_status());
7825 EXPECT_FALSE(req->response_info().network_accessed); 7776 EXPECT_FALSE(req->response_info().network_accessed);
7826 EXPECT_TRUE(req->response_info().was_cached); 7777 EXPECT_TRUE(req->response_info().was_cached);
7827 } 7778 }
7828 7779
7829 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { 7780 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) {
7830 ASSERT_TRUE(http_test_server()->Start()); 7781 ASSERT_TRUE(http_test_server()->Start());
7831 7782
7832 TestDelegate d; 7783 TestDelegate d;
7833 GURL test_url(http_test_server()->GetURL("/")); 7784 GURL test_url(http_test_server()->GetURL("/"));
7834 std::unique_ptr<URLRequest> req( 7785 std::unique_ptr<URLRequest> req(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
7896 ASSERT_TRUE(http_test_server()->Start()); 7847 ASSERT_TRUE(http_test_server()->Start());
7897 7848
7898 TestDelegate d; 7849 TestDelegate d;
7899 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 7850 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
7900 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d)); 7851 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d));
7901 req->Start(); 7852 req->Start();
7902 base::RunLoop().Run(); 7853 base::RunLoop().Run();
7903 7854
7904 EXPECT_TRUE(interceptor()->did_intercept_redirect()); 7855 EXPECT_TRUE(interceptor()->did_intercept_redirect());
7905 // Check we got one good response 7856 // Check we got one good response
7906 EXPECT_TRUE(req->status().is_success()); 7857 int status = d.request_status();
7907 if (req->status().is_success()) 7858 EXPECT_EQ(OK, status);
7859 if (status == OK)
7908 EXPECT_EQ(200, req->response_headers()->response_code()); 7860 EXPECT_EQ(200, req->response_headers()->response_code());
7909 7861
7910 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 7862 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
7911 EXPECT_EQ(1, d.response_started_count()); 7863 EXPECT_EQ(1, d.response_started_count());
7912 EXPECT_EQ(0, d.received_redirect_count()); 7864 EXPECT_EQ(0, d.received_redirect_count());
7913 7865
7914 EXPECT_EQ(1, default_network_delegate()->created_requests()); 7866 EXPECT_EQ(1, default_network_delegate()->created_requests());
7915 EXPECT_EQ(1, default_network_delegate()->before_start_transaction_count()); 7867 EXPECT_EQ(1, default_network_delegate()->before_start_transaction_count());
7916 EXPECT_EQ(1, default_network_delegate()->headers_received_count()); 7868 EXPECT_EQ(1, default_network_delegate()->headers_received_count());
7917 } 7869 }
(...skipping 12 matching lines...) Expand all
7930 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 7882 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
7931 http_test_server()->GetURL("/two-content-lengths.html"), DEFAULT_PRIORITY, 7883 http_test_server()->GetURL("/two-content-lengths.html"), DEFAULT_PRIORITY,
7932 &d)); 7884 &d));
7933 req->set_method("GET"); 7885 req->set_method("GET");
7934 req->Start(); 7886 req->Start();
7935 base::RunLoop().Run(); 7887 base::RunLoop().Run();
7936 7888
7937 EXPECT_TRUE(interceptor()->did_intercept_final()); 7889 EXPECT_TRUE(interceptor()->did_intercept_final());
7938 7890
7939 // Check we received one good response. 7891 // Check we received one good response.
7940 EXPECT_TRUE(req->status().is_success()); 7892 int status = d.request_status();
7941 if (req->status().is_success()) 7893 EXPECT_EQ(OK, status);
7894 if (status == OK)
7942 EXPECT_EQ(200, req->response_headers()->response_code()); 7895 EXPECT_EQ(200, req->response_headers()->response_code());
7943 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 7896 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
7944 EXPECT_EQ(1, d.response_started_count()); 7897 EXPECT_EQ(1, d.response_started_count());
7945 EXPECT_EQ(0, d.received_redirect_count()); 7898 EXPECT_EQ(0, d.received_redirect_count());
7946 7899
7947 EXPECT_EQ(1, default_network_delegate()->created_requests()); 7900 EXPECT_EQ(1, default_network_delegate()->created_requests());
7948 EXPECT_EQ(1, default_network_delegate()->before_start_transaction_count()); 7901 EXPECT_EQ(1, default_network_delegate()->before_start_transaction_count());
7949 EXPECT_EQ(0, default_network_delegate()->headers_received_count()); 7902 EXPECT_EQ(0, default_network_delegate()->headers_received_count());
7950 } 7903 }
7951 7904
(...skipping 10 matching lines...) Expand all
7962 TestDelegate d; 7915 TestDelegate d;
7963 std::unique_ptr<URLRequest> req(default_context().CreateRequest( 7916 std::unique_ptr<URLRequest> req(default_context().CreateRequest(
7964 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); 7917 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d));
7965 req->set_method("GET"); 7918 req->set_method("GET");
7966 req->Start(); 7919 req->Start();
7967 base::RunLoop().Run(); 7920 base::RunLoop().Run();
7968 7921
7969 EXPECT_TRUE(interceptor()->did_intercept_final()); 7922 EXPECT_TRUE(interceptor()->did_intercept_final());
7970 7923
7971 // Check we received one good response. 7924 // Check we received one good response.
7972 EXPECT_TRUE(req->status().is_success()); 7925 int status = d.request_status();
7973 if (req->status().is_success()) 7926 EXPECT_EQ(OK, status);
7927 if (status == OK)
7974 EXPECT_EQ(200, req->response_headers()->response_code()); 7928 EXPECT_EQ(200, req->response_headers()->response_code());
7975 EXPECT_EQ("hello", d.data_received()); 7929 EXPECT_EQ("hello", d.data_received());
7976 EXPECT_EQ(1, d.response_started_count()); 7930 EXPECT_EQ(1, d.response_started_count());
7977 EXPECT_EQ(0, d.received_redirect_count()); 7931 EXPECT_EQ(0, d.received_redirect_count());
7978 7932
7979 EXPECT_EQ(1, default_network_delegate()->created_requests()); 7933 EXPECT_EQ(1, default_network_delegate()->created_requests());
7980 EXPECT_EQ(2, default_network_delegate()->before_start_transaction_count()); 7934 EXPECT_EQ(2, default_network_delegate()->before_start_transaction_count());
7981 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); 7935 EXPECT_EQ(2, default_network_delegate()->headers_received_count());
7982 } 7936 }
7983 7937
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
8033 std::unique_ptr<URLRequest> req( 7987 std::unique_ptr<URLRequest> req(
8034 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d)); 7988 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d));
8035 req->set_referrer_policy(policy); 7989 req->set_referrer_policy(policy);
8036 req->SetReferrer(referrer.spec()); 7990 req->SetReferrer(referrer.spec());
8037 req->Start(); 7991 req->Start();
8038 base::RunLoop().Run(); 7992 base::RunLoop().Run();
8039 7993
8040 EXPECT_EQ(1, d.response_started_count()); 7994 EXPECT_EQ(1, d.response_started_count());
8041 EXPECT_EQ(1, d.received_redirect_count()); 7995 EXPECT_EQ(1, d.received_redirect_count());
8042 EXPECT_EQ(destination_url, req->url()); 7996 EXPECT_EQ(destination_url, req->url());
8043 EXPECT_TRUE(req->status().is_success()); 7997 EXPECT_EQ(OK, d.request_status());
8044 EXPECT_EQ(200, req->response_headers()->response_code()); 7998 EXPECT_EQ(200, req->response_headers()->response_code());
8045 7999
8046 EXPECT_EQ(expected.spec(), req->referrer()); 8000 EXPECT_EQ(expected.spec(), req->referrer());
8047 if (expected.is_empty()) 8001 if (expected.is_empty())
8048 EXPECT_EQ("None", d.data_received()); 8002 EXPECT_EQ("None", d.data_received());
8049 else 8003 else
8050 EXPECT_EQ(expected.spec(), d.data_received()); 8004 EXPECT_EQ(expected.spec(), d.data_received());
8051 } 8005 }
8052 8006
8053 EmbeddedTestServer* origin_server() const { return origin_server_.get(); } 8007 EmbeddedTestServer* origin_server() const { return origin_server_.get(); }
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
8556 { 8510 {
8557 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 8511 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
8558 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); 8512 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d));
8559 8513
8560 r->Start(); 8514 r->Start();
8561 EXPECT_TRUE(r->is_pending()); 8515 EXPECT_TRUE(r->is_pending());
8562 8516
8563 base::RunLoop().Run(); 8517 base::RunLoop().Run();
8564 8518
8565 EXPECT_EQ(1, d.response_started_count()); 8519 EXPECT_EQ(1, d.response_started_count());
8566 EXPECT_FALSE(r->status().is_success()); 8520 EXPECT_EQ(ERR_SSL_OBSOLETE_CIPHER, d.request_status());
8567 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
8568 EXPECT_THAT(r->status().error(), IsError(ERR_SSL_OBSOLETE_CIPHER));
8569 } 8521 }
8570 } 8522 }
8571 8523
8572 namespace { 8524 namespace {
8573 8525
8574 class SSLClientAuthTestDelegate : public TestDelegate { 8526 class SSLClientAuthTestDelegate : public TestDelegate {
8575 public: 8527 public:
8576 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { 8528 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {
8577 } 8529 }
8578 void OnCertificateRequested(URLRequest* request, 8530 void OnCertificateRequested(URLRequest* request,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
8818 EXPECT_EQ(1, delegate_.response_started_count()); 8770 EXPECT_EQ(1, delegate_.response_started_count());
8819 EXPECT_NE(0, delegate_.bytes_received()); 8771 EXPECT_NE(0, delegate_.bytes_received());
8820 EXPECT_EQ(version, SSLConnectionStatusToVersion( 8772 EXPECT_EQ(version, SSLConnectionStatusToVersion(
8821 request_->ssl_info().connection_status)); 8773 request_->ssl_info().connection_status));
8822 EXPECT_TRUE(request_->ssl_info().connection_status & 8774 EXPECT_TRUE(request_->ssl_info().connection_status &
8823 SSL_CONNECTION_VERSION_FALLBACK); 8775 SSL_CONNECTION_VERSION_FALLBACK);
8824 } 8776 }
8825 8777
8826 void ExpectFailure(int error) { 8778 void ExpectFailure(int error) {
8827 EXPECT_EQ(1, delegate_.response_started_count()); 8779 EXPECT_EQ(1, delegate_.response_started_count());
8828 EXPECT_FALSE(request_->status().is_success()); 8780 EXPECT_EQ(error, delegate_.request_status());
8829 EXPECT_EQ(URLRequestStatus::FAILED, request_->status().status());
8830 EXPECT_EQ(error, request_->status().error());
8831 } 8781 }
8832 8782
8833 private: 8783 private:
8834 TestDelegate delegate_; 8784 TestDelegate delegate_;
8835 TestURLRequestContext context_; 8785 TestURLRequestContext context_;
8836 std::unique_ptr<URLRequest> request_; 8786 std::unique_ptr<URLRequest> request_;
8837 }; 8787 };
8838 8788
8839 // Tests the TLS 1.0 fallback doesn't happen. 8789 // Tests the TLS 1.0 fallback doesn't happen.
8840 TEST_F(HTTPSFallbackTest, TLSv1NoFallback) { 8790 TEST_F(HTTPSFallbackTest, TLSv1NoFallback) {
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
9932 TestDelegate d; 9882 TestDelegate d;
9933 { 9883 {
9934 std::unique_ptr<URLRequest> r( 9884 std::unique_ptr<URLRequest> r(
9935 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); 9885 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
9936 r->Start(); 9886 r->Start();
9937 EXPECT_TRUE(r->is_pending()); 9887 EXPECT_TRUE(r->is_pending());
9938 9888
9939 base::RunLoop().Run(); 9889 base::RunLoop().Run();
9940 9890
9941 EXPECT_FALSE(r->is_pending()); 9891 EXPECT_FALSE(r->is_pending());
9942 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 9892 EXPECT_EQ(ERR_UNSAFE_PORT, d.request_status());
9943 EXPECT_THAT(r->status().error(), IsError(ERR_UNSAFE_PORT));
9944 } 9893 }
9945 } 9894 }
9946 9895
9947 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { 9896 TEST_F(URLRequestTestFTP, FTPDirectoryListing) {
9948 ASSERT_TRUE(ftp_test_server_.Start()); 9897 ASSERT_TRUE(ftp_test_server_.Start());
9949 9898
9950 TestDelegate d; 9899 TestDelegate d;
9951 { 9900 {
9952 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 9901 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
9953 ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); 9902 ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d));
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
10247 10196
10248 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 10197 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
10249 req.get(), &default_network_delegate_, 10198 req.get(), &default_network_delegate_,
10250 GURL("http://this-should-never-be-navigated-to/"), 10199 GURL("http://this-should-never-be-navigated-to/"),
10251 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); 10200 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp"));
10252 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10201 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10253 10202
10254 req->Start(); 10203 req->Start();
10255 req->Cancel(); 10204 req->Cancel();
10256 base::RunLoop().RunUntilIdle(); 10205 base::RunLoop().RunUntilIdle();
10257 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10206 EXPECT_EQ(ERR_ABORTED, d.request_status());
10258 EXPECT_EQ(0, d.received_redirect_count()); 10207 EXPECT_EQ(0, d.received_redirect_count());
10259 } 10208 }
10260 10209
10261 } // namespace net 10210 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_simple_job_unittest.cc ('k') | net/websockets/websocket_end_to_end_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698