Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 6541021: Send fatal proxy errors to the network delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 #elif defined(USE_NSS) 10 #elif defined(USE_NSS)
11 #include "base/nss_util.h" 11 #include "base/nss_util.h"
12 #endif 12 #endif
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <string> 15 #include <string>
16 16
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/format_macros.h" 18 #include "base/format_macros.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/process_util.h" 21 #include "base/process_util.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/string_piece.h" 23 #include "base/string_piece.h"
24 #include "base/string_util.h" 24 #include "base/string_util.h"
25 #include "base/stringprintf.h" 25 #include "base/stringprintf.h"
26 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
27 #include "net/base/cookie_monster.h" 27 #include "net/base/cookie_monster.h"
28 #include "net/base/cookie_policy.h" 28 #include "net/base/cookie_policy.h"
29 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
30 #include "net/base/mock_host_resolver.h"
30 #include "net/base/net_errors.h" 31 #include "net/base/net_errors.h"
31 #include "net/base/net_log.h" 32 #include "net/base/net_log.h"
32 #include "net/base/net_log_unittest.h" 33 #include "net/base/net_log_unittest.h"
33 #include "net/base/net_module.h" 34 #include "net/base/net_module.h"
34 #include "net/base/net_util.h" 35 #include "net/base/net_util.h"
35 #include "net/base/ssl_connection_status_flags.h" 36 #include "net/base/ssl_connection_status_flags.h"
36 #include "net/base/upload_data.h" 37 #include "net/base/upload_data.h"
37 #include "net/disk_cache/disk_cache.h" 38 #include "net/disk_cache/disk_cache.h"
38 #include "net/ftp/ftp_network_layer.h" 39 #include "net/ftp/ftp_network_layer.h"
39 #include "net/http/http_cache.h" 40 #include "net/http/http_cache.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 MessageLoop::current()->Run(); 224 MessageLoop::current()->Run();
224 225
225 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status()); 226 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status());
226 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error()); 227 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error());
227 EXPECT_EQ(1, d.response_started_count()); 228 EXPECT_EQ(1, d.response_started_count());
228 // We should not have followed the redirect. 229 // We should not have followed the redirect.
229 EXPECT_EQ(0, d.received_redirect_count()); 230 EXPECT_EQ(0, d.received_redirect_count());
230 } 231 }
231 } 232 }
232 233
234 // This is the same as the previous test, but checks that the network delegate
235 // registers the error.
236 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
237 ASSERT_TRUE(test_server_.Start());
238
239 TestDelegate d;
240 {
241 net::URLRequest r(GURL("https://www.redirect.com/"), &d);
242 scoped_refptr<TestURLRequestContext> context(
243 new TestURLRequestContext(test_server_.host_port_pair().ToString()));
244 TestHttpNetworkDelegate network_delegate;
245 context->set_network_delegate(&network_delegate);
246 r.set_context(context);
247
248 r.Start();
249 EXPECT_TRUE(r.is_pending());
250
251 MessageLoop::current()->Run();
252
253 EXPECT_EQ(net::URLRequestStatus::FAILED, r.status().status());
254 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED, r.status().os_error());
255 EXPECT_EQ(1, d.response_started_count());
256 // We should not have followed the redirect.
257 EXPECT_EQ(0, d.received_redirect_count());
258
259 EXPECT_EQ(1, network_delegate.error_count());
260 EXPECT_EQ(net::ERR_TUNNEL_CONNECTION_FAILED,
261 network_delegate.last_os_error());
262 }
263 }
264
233 // In this unit test, we're using the HTTPTestServer as a proxy server and 265 // In this unit test, we're using the HTTPTestServer as a proxy server and
234 // issuing a CONNECT request with the magic host name "www.server-auth.com". 266 // issuing a CONNECT request with the magic host name "www.server-auth.com".
235 // The HTTPTestServer will return a 401 response, which we should balk at. 267 // The HTTPTestServer will return a 401 response, which we should balk at.
236 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 268 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
237 ASSERT_TRUE(test_server_.Start()); 269 ASSERT_TRUE(test_server_.Start());
238 270
239 TestDelegate d; 271 TestDelegate d;
240 { 272 {
241 net::URLRequest r(GURL("https://www.server-auth.com/"), &d); 273 net::URLRequest r(GURL("https://www.server-auth.com/"), &d);
242 r.set_context( 274 r.set_context(
(...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 2373
2342 // Check that two different URL requests have different identifiers. 2374 // Check that two different URL requests have different identifiers.
2343 TEST_F(URLRequestTest, Identifiers) { 2375 TEST_F(URLRequestTest, Identifiers) {
2344 TestDelegate d; 2376 TestDelegate d;
2345 TestURLRequest req(GURL("http://example.com"), &d); 2377 TestURLRequest req(GURL("http://example.com"), &d);
2346 TestURLRequest other_req(GURL("http://example.com"), &d); 2378 TestURLRequest other_req(GURL("http://example.com"), &d);
2347 2379
2348 ASSERT_NE(req.identifier(), other_req.identifier()); 2380 ASSERT_NE(req.identifier(), other_req.identifier());
2349 } 2381 }
2350 2382
2383 // Check that a failure to connect to the proxy is reported to the network
2384 // delegate.
2385 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
2386 TestDelegate d;
2387 TestURLRequest req(GURL("http://example.com"), &d);
2388 req.set_method("GET");
2389
2390 scoped_ptr<net::MockHostResolverBase> host_resolver(
2391 new net::MockHostResolver);
2392 host_resolver->rules()->AddSimulatedFailure("*");
2393 scoped_refptr<TestURLRequestContext> context(
2394 new TestURLRequestContext("myproxy:70", host_resolver.release()));
2395 TestHttpNetworkDelegate network_delegate;
2396 context->set_network_delegate(&network_delegate);
2397 req.set_context(context);
2398
2399 req.Start();
2400 MessageLoop::current()->Run();
2401
2402 // Check we see a failed request.
2403 EXPECT_FALSE(req.status().is_success());
2404 EXPECT_EQ(net::URLRequestStatus::FAILED, req.status().status());
2405 EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED, req.status().os_error());
2406
2407 EXPECT_EQ(1, network_delegate.error_count());
2408 EXPECT_EQ(net::ERR_PROXY_CONNECTION_FAILED, network_delegate.last_os_error());
2409 }
2410
2351 class URLRequestTestFTP : public URLRequestTest { 2411 class URLRequestTestFTP : public URLRequestTest {
2352 public: 2412 public:
2353 URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) { 2413 URLRequestTestFTP() : test_server_(net::TestServer::TYPE_FTP, FilePath()) {
2354 } 2414 }
2355 2415
2356 protected: 2416 protected:
2357 net::TestServer test_server_; 2417 net::TestServer test_server_;
2358 }; 2418 };
2359 2419
2360 // Flaky, see http://crbug.com/25045. 2420 // Flaky, see http://crbug.com/25045.
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
2738 net::HttpRequestHeaders headers; 2798 net::HttpRequestHeaders headers;
2739 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 2799 headers.SetHeader(net::HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
2740 req.SetExtraRequestHeaders(headers); 2800 req.SetExtraRequestHeaders(headers);
2741 req.Start(); 2801 req.Start();
2742 MessageLoop::current()->Run(); 2802 MessageLoop::current()->Run();
2743 // If the net tests are being run with ChromeFrame then we need to allow for 2803 // If the net tests are being run with ChromeFrame then we need to allow for
2744 // the 'chromeframe' suffix which is added to the user agent before the 2804 // the 'chromeframe' suffix which is added to the user agent before the
2745 // closing parentheses. 2805 // closing parentheses.
2746 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 2806 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
2747 } 2807 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698