Chromium Code Reviews| 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 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network | |
| 2068 // delegate operating in |block_mode| and a request for |url|. It blocks the | |
| 2069 // request in various tages and cancels it with ERR_BLOCKED_BY_CLIENT. | |
| 2070 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, | |
| 2071 const GURL& url) { | |
| 2072 static const BlockingNetworkDelegate::Stage blocking_stages[] = { | |
| 2073 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | |
|
erikwright (departed)
2012/09/26 15:41:42
Could you just make the blocking stage a parameter
vabr (Chromium)
2012/09/26 16:04:08
Done.
I disabled all of them in Chrome Frame, exce
| |
| 2074 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | |
| 2075 BlockingNetworkDelegate::ON_HEADERS_RECEIVED | |
| 2076 }; | |
| 2077 | |
| 2078 for (size_t i = 0; i < arraysize(blocking_stages); ++i) { | |
| 2079 TestDelegate d; | |
| 2080 BlockingNetworkDelegate network_delegate(block_mode); | |
| 2081 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); | |
| 2082 network_delegate.set_block_on(blocking_stages[i]); | |
| 2083 | |
| 2084 TestURLRequestContext context(true); | |
| 2085 context.set_network_delegate(&network_delegate); | |
| 2086 context.Init(); | |
| 2087 | |
| 2088 { | |
| 2089 URLRequest r(url, &d, &context); | |
| 2090 | |
| 2091 r.Start(); | |
| 2092 MessageLoop::current()->Run(); | |
| 2093 | |
| 2094 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | |
| 2095 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); | |
| 2096 EXPECT_EQ(1, network_delegate.created_requests()); | |
| 2097 EXPECT_EQ(0, network_delegate.destroyed_requests()); | |
| 2098 } | |
| 2099 EXPECT_EQ(1, network_delegate.destroyed_requests()); | |
| 2100 } | |
| 2101 } | |
| 2102 | |
| 2103 // Tests that the network delegate can cancel a request synchronously in | |
| 2104 // various stages of the request. | |
| 2067 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 2105 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
| 2068 ASSERT_TRUE(test_server_.Start()); | 2106 ASSERT_TRUE(test_server_.Start()); |
| 2107 NetworkDelegateCancelRequest(BlockingNetworkDelegate::SYNCHRONOUS, | |
| 2108 test_server_.GetURL("")); | |
| 2109 } | |
| 2069 | 2110 |
| 2070 TestDelegate d; | 2111 // Tests that the network delegate can cancel a request asynchronously in |
| 2071 BlockingNetworkDelegate network_delegate( | 2112 // various stages of the request. |
| 2072 BlockingNetworkDelegate::SYNCHRONOUS); | 2113 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestAsynchronously) { |
| 2073 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2114 ASSERT_TRUE(test_server_.Start()); |
| 2074 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 2115 NetworkDelegateCancelRequest(BlockingNetworkDelegate::AUTO_CALLBACK, |
| 2075 | 2116 test_server_.GetURL("")); |
| 2076 TestURLRequestContextWithProxy context( | |
| 2077 test_server_.host_port_pair().ToString(), | |
| 2078 &network_delegate); | |
| 2079 | |
| 2080 { | |
| 2081 URLRequest r(test_server_.GetURL(""), &d, &context); | |
| 2082 | |
| 2083 r.Start(); | |
| 2084 MessageLoop::current()->Run(); | |
| 2085 | |
| 2086 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | |
| 2087 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | |
| 2088 EXPECT_EQ(1, network_delegate.created_requests()); | |
| 2089 EXPECT_EQ(0, network_delegate.destroyed_requests()); | |
| 2090 } | |
| 2091 EXPECT_EQ(1, network_delegate.destroyed_requests()); | |
| 2092 } | 2117 } |
| 2093 | 2118 |
| 2094 // Tests that the network delegate can block and redirect a request to a new | 2119 // Tests that the network delegate can block and redirect a request to a new |
| 2095 // URL. | 2120 // URL. |
| 2096 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 2121 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
| 2097 ASSERT_TRUE(test_server_.Start()); | 2122 ASSERT_TRUE(test_server_.Start()); |
| 2098 | 2123 |
| 2099 TestDelegate d; | 2124 TestDelegate d; |
| 2100 BlockingNetworkDelegate network_delegate( | 2125 BlockingNetworkDelegate network_delegate( |
| 2101 BlockingNetworkDelegate::AUTO_CALLBACK); | 2126 BlockingNetworkDelegate::AUTO_CALLBACK); |
| (...skipping 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4791 | 4816 |
| 4792 EXPECT_FALSE(r.is_pending()); | 4817 EXPECT_FALSE(r.is_pending()); |
| 4793 EXPECT_EQ(1, d->response_started_count()); | 4818 EXPECT_EQ(1, d->response_started_count()); |
| 4794 EXPECT_FALSE(d->received_data_before_response()); | 4819 EXPECT_FALSE(d->received_data_before_response()); |
| 4795 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4820 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4796 } | 4821 } |
| 4797 } | 4822 } |
| 4798 #endif // !defined(DISABLE_FTP_SUPPORT) | 4823 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 4799 | 4824 |
| 4800 } // namespace net | 4825 } // namespace net |
| OLD | NEW |