| 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 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 MessageLoop::current()->Run(); | 2056 MessageLoop::current()->Run(); |
| 2057 | 2057 |
| 2058 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2058 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2059 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 2059 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 2060 EXPECT_EQ(1, network_delegate.created_requests()); | 2060 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2061 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2061 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2062 } | 2062 } |
| 2063 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2063 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2064 } | 2064 } |
| 2065 | 2065 |
| 2066 // Tests that the network delegate can cancel a request synchronously. | 2066 // Helper function for NetworkDelegateCancelRequestAsynchronously and |
| 2067 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 2067 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network |
| 2068 ASSERT_TRUE(test_server_.Start()); | 2068 // delegate operating in |block_mode| and a request for |url|. It blocks the |
| 2069 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. |
| 2070 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, |
| 2071 BlockingNetworkDelegate::Stage stage, |
| 2072 const GURL& url) { |
| 2073 TestDelegate d; |
| 2074 BlockingNetworkDelegate network_delegate(block_mode); |
| 2075 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); |
| 2076 network_delegate.set_block_on(stage); |
| 2069 | 2077 |
| 2070 TestDelegate d; | 2078 TestURLRequestContext context(true); |
| 2071 BlockingNetworkDelegate network_delegate( | 2079 context.set_network_delegate(&network_delegate); |
| 2072 BlockingNetworkDelegate::SYNCHRONOUS); | 2080 context.Init(); |
| 2073 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | |
| 2074 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | |
| 2075 | |
| 2076 TestURLRequestContextWithProxy context( | |
| 2077 test_server_.host_port_pair().ToString(), | |
| 2078 &network_delegate); | |
| 2079 | 2081 |
| 2080 { | 2082 { |
| 2081 URLRequest r(test_server_.GetURL(""), &d, &context); | 2083 URLRequest r(url, &d, &context); |
| 2082 | 2084 |
| 2083 r.Start(); | 2085 r.Start(); |
| 2084 MessageLoop::current()->Run(); | 2086 MessageLoop::current()->Run(); |
| 2085 | 2087 |
| 2086 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2088 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2087 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 2089 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); |
| 2088 EXPECT_EQ(1, network_delegate.created_requests()); | 2090 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2089 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2091 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2090 } | 2092 } |
| 2091 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2093 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2092 } | 2094 } |
| 2093 | 2095 |
| 2096 // The following 3 tests check that the network delegate can cancel a request |
| 2097 // synchronously in various stages of the request. |
| 2098 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { |
| 2099 ASSERT_TRUE(test_server_.Start()); |
| 2100 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 2101 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 2102 test_server_.GetURL("")); |
| 2103 } |
| 2104 |
| 2105 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously2) { |
| 2106 ASSERT_TRUE(test_server_.Start()); |
| 2107 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 2108 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 2109 test_server_.GetURL("")); |
| 2110 } |
| 2111 |
| 2112 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously3) { |
| 2113 ASSERT_TRUE(test_server_.Start()); |
| 2114 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, |
| 2115 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 2116 test_server_.GetURL("")); |
| 2117 } |
| 2118 |
| 2119 // The following 3 tests check that the network delegate can cancel a request |
| 2120 // asynchronously in various stages of the request. |
| 2121 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously1) { |
| 2122 ASSERT_TRUE(test_server_.Start()); |
| 2123 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 2124 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 2125 test_server_.GetURL("")); |
| 2126 } |
| 2127 |
| 2128 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously2) { |
| 2129 ASSERT_TRUE(test_server_.Start()); |
| 2130 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 2131 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 2132 test_server_.GetURL("")); |
| 2133 } |
| 2134 |
| 2135 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously3) { |
| 2136 ASSERT_TRUE(test_server_.Start()); |
| 2137 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 2138 BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 2139 test_server_.GetURL("")); |
| 2140 } |
| 2141 |
| 2094 // Tests that the network delegate can block and redirect a request to a new | 2142 // Tests that the network delegate can block and redirect a request to a new |
| 2095 // URL. | 2143 // URL. |
| 2096 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 2144 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
| 2097 ASSERT_TRUE(test_server_.Start()); | 2145 ASSERT_TRUE(test_server_.Start()); |
| 2098 | 2146 |
| 2099 TestDelegate d; | 2147 TestDelegate d; |
| 2100 BlockingNetworkDelegate network_delegate( | 2148 BlockingNetworkDelegate network_delegate( |
| 2101 BlockingNetworkDelegate::AUTO_CALLBACK); | 2149 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 2102 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2150 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2103 GURL redirect_url(test_server_.GetURL("simple.html")); | 2151 GURL redirect_url(test_server_.GetURL("simple.html")); |
| (...skipping 2687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4791 | 4839 |
| 4792 EXPECT_FALSE(r.is_pending()); | 4840 EXPECT_FALSE(r.is_pending()); |
| 4793 EXPECT_EQ(1, d->response_started_count()); | 4841 EXPECT_EQ(1, d->response_started_count()); |
| 4794 EXPECT_FALSE(d->received_data_before_response()); | 4842 EXPECT_FALSE(d->received_data_before_response()); |
| 4795 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4843 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4796 } | 4844 } |
| 4797 } | 4845 } |
| 4798 #endif // !defined(DISABLE_FTP_SUPPORT) | 4846 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 4799 | 4847 |
| 4800 } // namespace net | 4848 } // namespace net |
| OLD | NEW |