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