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