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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 base::RunLoop().Run(); | 1756 base::RunLoop().Run(); |
1757 EXPECT_EQ("", d.data_received()); | 1757 EXPECT_EQ("", d.data_received()); |
1758 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 1758 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
1759 } | 1759 } |
1760 | 1760 |
1761 // Make sure that SetPriority actually sets the URLRequest's priority | 1761 // Make sure that SetPriority actually sets the URLRequest's priority |
1762 // correctly, both before and after start. | 1762 // correctly, both before and after start. |
1763 TEST_F(URLRequestTest, SetPriorityBasic) { | 1763 TEST_F(URLRequestTest, SetPriorityBasic) { |
1764 TestDelegate d; | 1764 TestDelegate d; |
1765 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1765 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1766 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 1766 EXPECT_EQ(DEFAULT_PRIORITY, req.GetPriority()); |
1767 | 1767 |
1768 req.SetPriority(LOW); | 1768 req.SetPriority(LOW); |
1769 EXPECT_EQ(LOW, req.priority()); | 1769 EXPECT_EQ(LOW, req.GetPriority()); |
1770 | 1770 |
1771 req.Start(); | 1771 req.Start(); |
1772 EXPECT_EQ(LOW, req.priority()); | 1772 EXPECT_EQ(LOW, req.GetPriority()); |
1773 | 1773 |
1774 req.SetPriority(MEDIUM); | 1774 req.SetPriority(MEDIUM); |
1775 EXPECT_EQ(MEDIUM, req.priority()); | 1775 EXPECT_EQ(MEDIUM, req.GetPriority()); |
1776 } | 1776 } |
1777 | 1777 |
1778 // Make sure that URLRequest calls SetPriority on a job before calling | 1778 // Make sure that URLRequest calls SetPriority on a job before calling |
1779 // Start on it. | 1779 // Start on it. |
1780 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { | 1780 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
1781 TestDelegate d; | 1781 TestDelegate d; |
1782 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1782 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1783 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 1783 EXPECT_EQ(DEFAULT_PRIORITY, req.GetPriority()); |
1784 | 1784 |
1785 scoped_refptr<URLRequestTestJob> job = | 1785 scoped_refptr<URLRequestTestJob> job = |
1786 new URLRequestTestJob(&req, &default_network_delegate_); | 1786 new URLRequestTestJob(&req, &default_network_delegate_); |
1787 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1787 AddTestInterceptor()->set_main_intercept_job(job.get()); |
1788 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 1788 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
1789 | 1789 |
1790 req.SetPriority(LOW); | 1790 req.SetPriority(LOW); |
1791 | 1791 |
1792 req.Start(); | 1792 req.Start(); |
1793 EXPECT_EQ(LOW, job->priority()); | 1793 EXPECT_EQ(LOW, job->priority()); |
1794 } | 1794 } |
1795 | 1795 |
1796 // Make sure that URLRequest passes on its priority updates to its | 1796 // Make sure that URLRequest passes on its priority updates to its |
1797 // job. | 1797 // job. |
1798 TEST_F(URLRequestTest, SetJobPriority) { | 1798 TEST_F(URLRequestTest, SetJobPriority) { |
1799 TestDelegate d; | 1799 TestDelegate d; |
1800 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1800 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1801 | 1801 |
1802 scoped_refptr<URLRequestTestJob> job = | 1802 scoped_refptr<URLRequestTestJob> job = |
1803 new URLRequestTestJob(&req, &default_network_delegate_); | 1803 new URLRequestTestJob(&req, &default_network_delegate_); |
1804 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1804 AddTestInterceptor()->set_main_intercept_job(job.get()); |
1805 | 1805 |
1806 req.SetPriority(LOW); | 1806 req.SetPriority(LOW); |
1807 req.Start(); | 1807 req.Start(); |
1808 EXPECT_EQ(LOW, job->priority()); | 1808 EXPECT_EQ(LOW, job->priority()); |
1809 | 1809 |
1810 req.SetPriority(MEDIUM); | 1810 req.SetPriority(MEDIUM); |
1811 EXPECT_EQ(MEDIUM, req.priority()); | 1811 EXPECT_EQ(MEDIUM, req.GetPriority()); |
1812 EXPECT_EQ(MEDIUM, job->priority()); | 1812 EXPECT_EQ(MEDIUM, job->priority()); |
1813 } | 1813 } |
1814 | 1814 |
| 1815 // Setting the IGNORE_LIMITS load flag should cause priority to become |
| 1816 // MAXIMUM_PRIORITY, and unnsetting it should revert to the base |
| 1817 // priority. |
| 1818 TEST_F(URLRequestTest, PriorityIgnoreLimits) { |
| 1819 TestDelegate d; |
| 1820 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
| 1821 EXPECT_EQ(DEFAULT_PRIORITY, req.GetPriority()); |
| 1822 |
| 1823 scoped_refptr<URLRequestTestJob> job = |
| 1824 new URLRequestTestJob(&req, &default_network_delegate_); |
| 1825 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1826 |
| 1827 req.SetLoadFlags(LOAD_IGNORE_LIMITS); |
| 1828 EXPECT_EQ(MAXIMUM_PRIORITY, req.GetPriority()); |
| 1829 |
| 1830 req.SetPriority(LOW); |
| 1831 EXPECT_EQ(MAXIMUM_PRIORITY, req.GetPriority()); |
| 1832 |
| 1833 req.SetLoadFlags(~LOAD_IGNORE_LIMITS); |
| 1834 EXPECT_EQ(LOW, req.GetPriority()); |
| 1835 |
| 1836 req.SetLoadFlags(LOAD_IGNORE_LIMITS); |
| 1837 EXPECT_EQ(MAXIMUM_PRIORITY, req.GetPriority()); |
| 1838 |
| 1839 req.Start(); |
| 1840 EXPECT_EQ(MAXIMUM_PRIORITY, req.GetPriority()); |
| 1841 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); |
| 1842 |
| 1843 req.SetPriority(MEDIUM); |
| 1844 EXPECT_EQ(MAXIMUM_PRIORITY, req.GetPriority()); |
| 1845 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); |
| 1846 } |
| 1847 |
1815 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). | 1848 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). |
1816 #if !defined(OS_IOS) | 1849 #if !defined(OS_IOS) |
1817 // A subclass of SpawnedTestServer that uses a statically-configured hostname. | 1850 // A subclass of SpawnedTestServer that uses a statically-configured hostname. |
1818 // This is to work around mysterious failures in chrome_frame_net_tests. See: | 1851 // This is to work around mysterious failures in chrome_frame_net_tests. See: |
1819 // http://crbug.com/114369 | 1852 // http://crbug.com/114369 |
1820 class LocalHttpTestServer : public SpawnedTestServer { | 1853 class LocalHttpTestServer : public SpawnedTestServer { |
1821 public: | 1854 public: |
1822 explicit LocalHttpTestServer(const base::FilePath& document_root) | 1855 explicit LocalHttpTestServer(const base::FilePath& document_root) |
1823 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 1856 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
1824 ScopedCustomUrlRequestTestHttpHost::value(), | 1857 ScopedCustomUrlRequestTestHttpHost::value(), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1936 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1904 } | 1937 } |
1905 | 1938 |
1906 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 1939 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
1907 { | 1940 { |
1908 TestNetworkDelegate network_delegate; | 1941 TestNetworkDelegate network_delegate; |
1909 default_context_.set_network_delegate(&network_delegate); | 1942 default_context_.set_network_delegate(&network_delegate); |
1910 TestDelegate d; | 1943 TestDelegate d; |
1911 URLRequest req( | 1944 URLRequest req( |
1912 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 1945 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
1913 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); | 1946 req.SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
1914 req.Start(); | 1947 req.Start(); |
1915 base::RunLoop().Run(); | 1948 base::RunLoop().Run(); |
1916 | 1949 |
1917 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1950 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
1918 == std::string::npos); | 1951 == std::string::npos); |
1919 | 1952 |
1920 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1953 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
1921 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1954 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1922 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1955 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1923 } | 1956 } |
(...skipping 21 matching lines...) Expand all Loading... |
1945 | 1978 |
1946 // Try to set-up another cookie and update the previous cookie. | 1979 // Try to set-up another cookie and update the previous cookie. |
1947 { | 1980 { |
1948 TestNetworkDelegate network_delegate; | 1981 TestNetworkDelegate network_delegate; |
1949 default_context_.set_network_delegate(&network_delegate); | 1982 default_context_.set_network_delegate(&network_delegate); |
1950 TestDelegate d; | 1983 TestDelegate d; |
1951 URLRequest req( | 1984 URLRequest req( |
1952 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 1985 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
1953 &d, | 1986 &d, |
1954 &default_context_); | 1987 &default_context_); |
1955 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); | 1988 req.SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); |
1956 req.Start(); | 1989 req.Start(); |
1957 | 1990 |
1958 base::RunLoop().Run(); | 1991 base::RunLoop().Run(); |
1959 | 1992 |
1960 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 1993 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
1961 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1994 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1962 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1995 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1963 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 1996 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
1964 } | 1997 } |
1965 | 1998 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 // If extra headers contain a referer but the request does not, no referer | 2385 // If extra headers contain a referer but the request does not, no referer |
2353 // shall be sent in the header. | 2386 // shall be sent in the header. |
2354 { | 2387 { |
2355 TestDelegate d; | 2388 TestDelegate d; |
2356 URLRequest req( | 2389 URLRequest req( |
2357 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | 2390 test_server.GetURL("echoheader?Referer"), &d, &default_context_); |
2358 | 2391 |
2359 HttpRequestHeaders headers; | 2392 HttpRequestHeaders headers; |
2360 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2393 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
2361 req.SetExtraRequestHeaders(headers); | 2394 req.SetExtraRequestHeaders(headers); |
2362 req.set_load_flags(LOAD_VALIDATE_CACHE); | 2395 req.SetLoadFlags(LOAD_VALIDATE_CACHE); |
2363 | 2396 |
2364 req.Start(); | 2397 req.Start(); |
2365 base::RunLoop().Run(); | 2398 base::RunLoop().Run(); |
2366 | 2399 |
2367 EXPECT_EQ("None", d.data_received()); | 2400 EXPECT_EQ("None", d.data_received()); |
2368 } | 2401 } |
2369 } | 2402 } |
2370 | 2403 |
2371 class URLRequestTestHTTP : public URLRequestTest { | 2404 class URLRequestTestHTTP : public URLRequestTest { |
2372 public: | 2405 public: |
(...skipping 2700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5073 } | 5106 } |
5074 | 5107 |
5075 // repeat request with end-to-end validation. since auth-basic results in a | 5108 // repeat request with end-to-end validation. since auth-basic results in a |
5076 // cachable page, we expect this test to result in a 304. in which case, the | 5109 // cachable page, we expect this test to result in a 304. in which case, the |
5077 // response should be fetched from the cache. | 5110 // response should be fetched from the cache. |
5078 { | 5111 { |
5079 TestDelegate d; | 5112 TestDelegate d; |
5080 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5113 d.set_credentials(AuthCredentials(kUser, kSecret)); |
5081 | 5114 |
5082 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5115 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
5083 r.set_load_flags(LOAD_VALIDATE_CACHE); | 5116 r.SetLoadFlags(LOAD_VALIDATE_CACHE); |
5084 r.Start(); | 5117 r.Start(); |
5085 | 5118 |
5086 base::RunLoop().Run(); | 5119 base::RunLoop().Run(); |
5087 | 5120 |
5088 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5121 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
5089 | 5122 |
5090 // Should be the same cached document. | 5123 // Should be the same cached document. |
5091 EXPECT_TRUE(r.was_cached()); | 5124 EXPECT_TRUE(r.was_cached()); |
5092 } | 5125 } |
5093 } | 5126 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5187 } | 5220 } |
5188 | 5221 |
5189 // Repeat request with end-to-end validation. Since auth-basic results in a | 5222 // Repeat request with end-to-end validation. Since auth-basic results in a |
5190 // cachable page, we expect this test to result in a 304. In which case, the | 5223 // cachable page, we expect this test to result in a 304. In which case, the |
5191 // response should be fetched from the cache. | 5224 // response should be fetched from the cache. |
5192 { | 5225 { |
5193 TestDelegate d; | 5226 TestDelegate d; |
5194 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5227 d.set_credentials(AuthCredentials(kUser, kSecret)); |
5195 | 5228 |
5196 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5229 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
5197 r.set_load_flags(LOAD_VALIDATE_CACHE); | 5230 r.SetLoadFlags(LOAD_VALIDATE_CACHE); |
5198 r.Start(); | 5231 r.Start(); |
5199 | 5232 |
5200 base::RunLoop().Run(); | 5233 base::RunLoop().Run(); |
5201 | 5234 |
5202 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5235 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
5203 | 5236 |
5204 // Should be the same cached document. | 5237 // Should be the same cached document. |
5205 EXPECT_TRUE(r.was_cached()); | 5238 EXPECT_TRUE(r.was_cached()); |
5206 | 5239 |
5207 // Since there was a request that went over the wire, the load timing | 5240 // Since there was a request that went over the wire, the load timing |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5522 } | 5555 } |
5523 } | 5556 } |
5524 | 5557 |
5525 // Make sure that URLRequest passes on its priority updates to | 5558 // Make sure that URLRequest passes on its priority updates to |
5526 // newly-created jobs after the first one. | 5559 // newly-created jobs after the first one. |
5527 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 5560 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
5528 ASSERT_TRUE(test_server_.Start()); | 5561 ASSERT_TRUE(test_server_.Start()); |
5529 | 5562 |
5530 TestDelegate d; | 5563 TestDelegate d; |
5531 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 5564 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
5532 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 5565 EXPECT_EQ(DEFAULT_PRIORITY, req.GetPriority()); |
5533 | 5566 |
5534 scoped_refptr<URLRequestRedirectJob> redirect_job = | 5567 scoped_refptr<URLRequestRedirectJob> redirect_job = |
5535 new URLRequestRedirectJob( | 5568 new URLRequestRedirectJob( |
5536 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 5569 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
5537 URLRequestRedirectJob::REDIRECT_302_FOUND); | 5570 URLRequestRedirectJob::REDIRECT_302_FOUND); |
5538 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 5571 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
5539 | 5572 |
5540 req.SetPriority(LOW); | 5573 req.SetPriority(LOW); |
5541 req.Start(); | 5574 req.Start(); |
5542 EXPECT_TRUE(req.is_pending()); | 5575 EXPECT_TRUE(req.is_pending()); |
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6966 | 6999 |
6967 EXPECT_FALSE(r.is_pending()); | 7000 EXPECT_FALSE(r.is_pending()); |
6968 EXPECT_EQ(1, d->response_started_count()); | 7001 EXPECT_EQ(1, d->response_started_count()); |
6969 EXPECT_FALSE(d->received_data_before_response()); | 7002 EXPECT_FALSE(d->received_data_before_response()); |
6970 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7003 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6971 } | 7004 } |
6972 } | 7005 } |
6973 #endif // !defined(DISABLE_FTP_SUPPORT) | 7006 #endif // !defined(DISABLE_FTP_SUPPORT) |
6974 | 7007 |
6975 } // namespace net | 7008 } // namespace net |
OLD | NEW |