OLD | NEW |
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 #endif | 10 #endif |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 private: | 247 private: |
248 mutable URLRequestJob* main_intercept_job_; | 248 mutable URLRequestJob* main_intercept_job_; |
249 }; | 249 }; |
250 | 250 |
251 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 251 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
252 class URLRequestTest : public PlatformTest { | 252 class URLRequestTest : public PlatformTest { |
253 public: | 253 public: |
254 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { | 254 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { |
255 default_context_->set_network_delegate(&default_network_delegate_); | 255 default_context_->set_network_delegate(&default_network_delegate_); |
| 256 default_context_->set_http_server_properties(NULL); |
256 default_context_->Init(); | 257 default_context_->Init(); |
257 } | 258 } |
258 | 259 |
259 static void SetUpTestCase() { | 260 static void SetUpTestCase() { |
260 URLRequest::AllowFileAccess(); | 261 URLRequest::AllowFileAccess(); |
261 } | 262 } |
262 | 263 |
263 // Adds the TestJobInterceptor to the default context. | 264 // Adds the TestJobInterceptor to the default context. |
264 TestJobInterceptor* AddTestInterceptor() { | 265 TestJobInterceptor* AddTestInterceptor() { |
265 TestJobInterceptor* interceptor = new TestJobInterceptor(); | 266 TestJobInterceptor* interceptor = new TestJobInterceptor(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // issuing a CONNECT request with the magic host name "www.redirect.com". | 357 // issuing a CONNECT request with the magic host name "www.redirect.com". |
357 // The HTTPTestServer will return a 302 response, which we should not | 358 // The HTTPTestServer will return a 302 response, which we should not |
358 // follow. | 359 // follow. |
359 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 360 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
360 ASSERT_TRUE(test_server_.Start()); | 361 ASSERT_TRUE(test_server_.Start()); |
361 | 362 |
362 TestNetworkDelegate network_delegate; // must outlive URLRequest | 363 TestNetworkDelegate network_delegate; // must outlive URLRequest |
363 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 364 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
364 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 365 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
365 context->set_network_delegate(&network_delegate); | 366 context->set_network_delegate(&network_delegate); |
| 367 context->set_http_server_properties(NULL); |
366 context->Init(); | 368 context->Init(); |
367 | 369 |
368 TestDelegate d; | 370 TestDelegate d; |
369 { | 371 { |
370 URLRequest r(GURL("https://www.redirect.com/"), &d); | 372 URLRequest r(GURL("https://www.redirect.com/"), &d); |
371 r.set_context(context); | 373 r.set_context(context); |
372 r.Start(); | 374 r.Start(); |
373 EXPECT_TRUE(r.is_pending()); | 375 EXPECT_TRUE(r.is_pending()); |
374 | 376 |
375 MessageLoop::current()->Run(); | 377 MessageLoop::current()->Run(); |
376 | 378 |
377 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 379 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
378 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 380 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
379 EXPECT_EQ(1, d.response_started_count()); | 381 EXPECT_EQ(1, d.response_started_count()); |
380 // We should not have followed the redirect. | 382 // We should not have followed the redirect. |
381 EXPECT_EQ(0, d.received_redirect_count()); | 383 EXPECT_EQ(0, d.received_redirect_count()); |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 // This is the same as the previous test, but checks that the network delegate | 387 // This is the same as the previous test, but checks that the network delegate |
386 // registers the error. | 388 // registers the error. |
387 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 389 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
388 ASSERT_TRUE(test_server_.Start()); | 390 ASSERT_TRUE(test_server_.Start()); |
389 | 391 |
390 TestNetworkDelegate network_delegate; // must outlive URLRequest | 392 TestNetworkDelegate network_delegate; // must outlive URLRequest |
391 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 393 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
392 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 394 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
393 context->set_network_delegate(&network_delegate); | 395 context->set_network_delegate(&network_delegate); |
| 396 context->set_http_server_properties(NULL); |
394 context->Init(); | 397 context->Init(); |
395 | 398 |
396 TestDelegate d; | 399 TestDelegate d; |
397 { | 400 { |
398 URLRequest r(GURL("https://www.redirect.com/"), &d); | 401 URLRequest r(GURL("https://www.redirect.com/"), &d); |
399 r.set_context(context); | 402 r.set_context(context); |
400 r.Start(); | 403 r.Start(); |
401 EXPECT_TRUE(r.is_pending()); | 404 EXPECT_TRUE(r.is_pending()); |
402 | 405 |
403 MessageLoop::current()->Run(); | 406 MessageLoop::current()->Run(); |
(...skipping 13 matching lines...) Expand all Loading... |
417 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 420 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
418 ASSERT_TRUE(test_server_.Start()); | 421 ASSERT_TRUE(test_server_.Start()); |
419 | 422 |
420 TestDelegate d; | 423 TestDelegate d; |
421 BlockingNetworkDelegate network_delegate; | 424 BlockingNetworkDelegate network_delegate; |
422 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); | 425 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); |
423 | 426 |
424 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 427 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
425 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 428 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
426 context->set_network_delegate(&network_delegate); | 429 context->set_network_delegate(&network_delegate); |
| 430 context->set_http_server_properties(NULL); |
427 context->Init(); | 431 context->Init(); |
428 | 432 |
429 { | 433 { |
430 TestURLRequest r(test_server_.GetURL(""), &d); | 434 TestURLRequest r(test_server_.GetURL(""), &d); |
431 r.set_context(context); | 435 r.set_context(context); |
432 | 436 |
433 r.Start(); | 437 r.Start(); |
434 MessageLoop::current()->Run(); | 438 MessageLoop::current()->Run(); |
435 | 439 |
436 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 440 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
437 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 441 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
438 EXPECT_EQ(1, network_delegate.created_requests()); | 442 EXPECT_EQ(1, network_delegate.created_requests()); |
439 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 443 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
440 } | 444 } |
441 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 445 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
442 } | 446 } |
443 | 447 |
444 // Tests that the network delegate can cancel a request synchronously. | 448 // Tests that the network delegate can cancel a request synchronously. |
445 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 449 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
446 ASSERT_TRUE(test_server_.Start()); | 450 ASSERT_TRUE(test_server_.Start()); |
447 | 451 |
448 TestDelegate d; | 452 TestDelegate d; |
449 BlockingNetworkDelegate network_delegate; | 453 BlockingNetworkDelegate network_delegate; |
450 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 454 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
451 | 455 |
452 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 456 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
453 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 457 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
454 context->set_network_delegate(&network_delegate); | 458 context->set_network_delegate(&network_delegate); |
| 459 context->set_http_server_properties(NULL); |
455 context->Init(); | 460 context->Init(); |
456 | 461 |
457 { | 462 { |
458 TestURLRequest r(test_server_.GetURL(""), &d); | 463 TestURLRequest r(test_server_.GetURL(""), &d); |
459 r.set_context(context); | 464 r.set_context(context); |
460 | 465 |
461 r.Start(); | 466 r.Start(); |
462 MessageLoop::current()->Run(); | 467 MessageLoop::current()->Run(); |
463 | 468 |
464 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 469 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
(...skipping 10 matching lines...) Expand all Loading... |
475 ASSERT_TRUE(test_server_.Start()); | 480 ASSERT_TRUE(test_server_.Start()); |
476 | 481 |
477 TestDelegate d; | 482 TestDelegate d; |
478 BlockingNetworkDelegate network_delegate; | 483 BlockingNetworkDelegate network_delegate; |
479 GURL redirect_url(test_server_.GetURL("simple.html")); | 484 GURL redirect_url(test_server_.GetURL("simple.html")); |
480 network_delegate.set_redirect_url(redirect_url); | 485 network_delegate.set_redirect_url(redirect_url); |
481 | 486 |
482 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 487 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
483 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 488 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
484 context->set_network_delegate(&network_delegate); | 489 context->set_network_delegate(&network_delegate); |
| 490 context->set_http_server_properties(NULL); |
485 context->Init(); | 491 context->Init(); |
486 | 492 |
487 { | 493 { |
488 GURL original_url(test_server_.GetURL("empty.html")); | 494 GURL original_url(test_server_.GetURL("empty.html")); |
489 TestURLRequest r(original_url, &d); | 495 TestURLRequest r(original_url, &d); |
490 r.set_context(context); | 496 r.set_context(context); |
491 | 497 |
492 r.Start(); | 498 r.Start(); |
493 MessageLoop::current()->Run(); | 499 MessageLoop::current()->Run(); |
494 | 500 |
(...skipping 14 matching lines...) Expand all Loading... |
509 | 515 |
510 const char kData[] = "hello world"; | 516 const char kData[] = "hello world"; |
511 | 517 |
512 TestDelegate d; | 518 TestDelegate d; |
513 BlockingNetworkDelegate network_delegate; | 519 BlockingNetworkDelegate network_delegate; |
514 GURL redirect_url(test_server_.GetURL("echo")); | 520 GURL redirect_url(test_server_.GetURL("echo")); |
515 network_delegate.set_redirect_url(redirect_url); | 521 network_delegate.set_redirect_url(redirect_url); |
516 | 522 |
517 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 523 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
518 context->set_network_delegate(&network_delegate); | 524 context->set_network_delegate(&network_delegate); |
| 525 context->set_http_server_properties(NULL); |
519 context->Init(); | 526 context->Init(); |
520 | 527 |
521 { | 528 { |
522 GURL original_url(test_server_.GetURL("empty.html")); | 529 GURL original_url(test_server_.GetURL("empty.html")); |
523 TestURLRequest r(original_url, &d); | 530 TestURLRequest r(original_url, &d); |
524 r.set_context(context); | 531 r.set_context(context); |
525 r.set_method("POST"); | 532 r.set_method("POST"); |
526 r.set_upload(CreateSimpleUploadData(kData).get()); | 533 r.set_upload(CreateSimpleUploadData(kData).get()); |
527 HttpRequestHeaders headers; | 534 HttpRequestHeaders headers; |
528 headers.SetHeader(HttpRequestHeaders::kContentLength, | 535 headers.SetHeader(HttpRequestHeaders::kContentLength, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 // In this unit test, we're using the HTTPTestServer as a proxy server and | 767 // In this unit test, we're using the HTTPTestServer as a proxy server and |
761 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 768 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
762 // The HTTPTestServer will return a 401 response, which we should balk at. | 769 // The HTTPTestServer will return a 401 response, which we should balk at. |
763 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 770 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
764 ASSERT_TRUE(test_server_.Start()); | 771 ASSERT_TRUE(test_server_.Start()); |
765 | 772 |
766 TestNetworkDelegate network_delegate; // must outlive URLRequest | 773 TestNetworkDelegate network_delegate; // must outlive URLRequest |
767 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 774 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
768 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 775 context->SetProxyFromString(test_server_.host_port_pair().ToString()); |
769 context->set_network_delegate(&network_delegate); | 776 context->set_network_delegate(&network_delegate); |
| 777 context->set_http_server_properties(NULL); |
770 context->Init(); | 778 context->Init(); |
771 | 779 |
772 TestDelegate d; | 780 TestDelegate d; |
773 { | 781 { |
774 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 782 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
775 r.set_context(context); | 783 r.set_context(context); |
776 | 784 |
777 r.Start(); | 785 r.Start(); |
778 EXPECT_TRUE(r.is_pending()); | 786 EXPECT_TRUE(r.is_pending()); |
779 | 787 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 TestDelegate d; | 861 TestDelegate d; |
854 { | 862 { |
855 std::string test_file = | 863 std::string test_file = |
856 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 864 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
857 test_parameters[i]); | 865 test_parameters[i]); |
858 | 866 |
859 TestNetworkDelegate network_delegate; // must outlive URLRequest | 867 TestNetworkDelegate network_delegate; // must outlive URLRequest |
860 scoped_refptr<TestURLRequestContext> context( | 868 scoped_refptr<TestURLRequestContext> context( |
861 new TestURLRequestContext(true)); | 869 new TestURLRequestContext(true)); |
862 context->set_network_delegate(&network_delegate); | 870 context->set_network_delegate(&network_delegate); |
| 871 context->set_http_server_properties(NULL); |
863 context->Init(); | 872 context->Init(); |
864 | 873 |
865 TestURLRequest r(test_server_.GetURL(test_file), &d); | 874 TestURLRequest r(test_server_.GetURL(test_file), &d); |
866 r.set_context(context); | 875 r.set_context(context); |
867 r.Start(); | 876 r.Start(); |
868 EXPECT_TRUE(r.is_pending()); | 877 EXPECT_TRUE(r.is_pending()); |
869 | 878 |
870 MessageLoop::current()->Run(); | 879 MessageLoop::current()->Run(); |
871 | 880 |
872 EXPECT_EQ(1, d.response_started_count()); | 881 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 ASSERT_EQ(3U, req.url_chain().size()); | 941 ASSERT_EQ(3U, req.url_chain().size()); |
933 EXPECT_EQ(original_url, req.url_chain()[0]); | 942 EXPECT_EQ(original_url, req.url_chain()[0]); |
934 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 943 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
935 EXPECT_EQ(destination_url, req.url_chain()[2]); | 944 EXPECT_EQ(destination_url, req.url_chain()[2]); |
936 } | 945 } |
937 | 946 |
938 class HTTPSRequestTest : public testing::Test { | 947 class HTTPSRequestTest : public testing::Test { |
939 public: | 948 public: |
940 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { | 949 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { |
941 default_context_->set_network_delegate(&default_network_delegate_); | 950 default_context_->set_network_delegate(&default_network_delegate_); |
| 951 default_context_->set_http_server_properties(NULL); |
942 default_context_->Init(); | 952 default_context_->Init(); |
943 } | 953 } |
944 virtual ~HTTPSRequestTest() {} | 954 virtual ~HTTPSRequestTest() {} |
945 | 955 |
946 protected: | 956 protected: |
947 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest | 957 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest |
948 scoped_refptr<TestURLRequestContext> default_context_; | 958 scoped_refptr<TestURLRequestContext> default_context_; |
949 }; | 959 }; |
950 | 960 |
951 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 961 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 GURL url_requiring_auth = | 1964 GURL url_requiring_auth = |
1955 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 1965 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
1956 | 1966 |
1957 // Request a page that will give a 401 containing a Set-Cookie header. | 1967 // Request a page that will give a 401 containing a Set-Cookie header. |
1958 // Verify that when the transaction is restarted, it includes the new cookie. | 1968 // Verify that when the transaction is restarted, it includes the new cookie. |
1959 { | 1969 { |
1960 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1970 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1961 scoped_refptr<TestURLRequestContext> context( | 1971 scoped_refptr<TestURLRequestContext> context( |
1962 new TestURLRequestContext(true)); | 1972 new TestURLRequestContext(true)); |
1963 context->set_network_delegate(&network_delegate); | 1973 context->set_network_delegate(&network_delegate); |
| 1974 context->set_http_server_properties(NULL); |
1964 context->Init(); | 1975 context->Init(); |
1965 | 1976 |
1966 TestDelegate d; | 1977 TestDelegate d; |
1967 d.set_username(kUser); | 1978 d.set_username(kUser); |
1968 d.set_password(kSecret); | 1979 d.set_password(kSecret); |
1969 | 1980 |
1970 URLRequest r(url_requiring_auth, &d); | 1981 URLRequest r(url_requiring_auth, &d); |
1971 r.set_context(context); | 1982 r.set_context(context); |
1972 r.Start(); | 1983 r.Start(); |
1973 | 1984 |
1974 MessageLoop::current()->Run(); | 1985 MessageLoop::current()->Run(); |
1975 | 1986 |
1976 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1987 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1977 | 1988 |
1978 // Make sure we sent the cookie in the restarted transaction. | 1989 // Make sure we sent the cookie in the restarted transaction. |
1979 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1990 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1980 != std::string::npos); | 1991 != std::string::npos); |
1981 } | 1992 } |
1982 | 1993 |
1983 // Same test as above, except this time the restart is initiated earlier | 1994 // Same test as above, except this time the restart is initiated earlier |
1984 // (without user intervention since identity is embedded in the URL). | 1995 // (without user intervention since identity is embedded in the URL). |
1985 { | 1996 { |
1986 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1997 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1987 scoped_refptr<TestURLRequestContext> context( | 1998 scoped_refptr<TestURLRequestContext> context( |
1988 new TestURLRequestContext(true)); | 1999 new TestURLRequestContext(true)); |
1989 context->set_network_delegate(&network_delegate); | 2000 context->set_network_delegate(&network_delegate); |
| 2001 context->set_http_server_properties(NULL); |
1990 context->Init(); | 2002 context->Init(); |
1991 | 2003 |
1992 TestDelegate d; | 2004 TestDelegate d; |
1993 | 2005 |
1994 GURL::Replacements replacements; | 2006 GURL::Replacements replacements; |
1995 std::string username("user2"); | 2007 std::string username("user2"); |
1996 std::string password("secret"); | 2008 std::string password("secret"); |
1997 replacements.SetUsernameStr(username); | 2009 replacements.SetUsernameStr(username); |
1998 replacements.SetPasswordStr(password); | 2010 replacements.SetPasswordStr(password); |
1999 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 2011 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2992 | 3004 |
2993 // Check that a failure to connect to the proxy is reported to the network | 3005 // Check that a failure to connect to the proxy is reported to the network |
2994 // delegate. | 3006 // delegate. |
2995 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 3007 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
2996 MockHostResolver host_resolver; | 3008 MockHostResolver host_resolver; |
2997 host_resolver.rules()->AddSimulatedFailure("*"); | 3009 host_resolver.rules()->AddSimulatedFailure("*"); |
2998 | 3010 |
2999 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3011 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3000 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3012 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3001 context->set_network_delegate(&network_delegate); | 3013 context->set_network_delegate(&network_delegate); |
| 3014 context->set_http_server_properties(NULL); |
3002 context->SetProxyFromString("myproxy:70"); | 3015 context->SetProxyFromString("myproxy:70"); |
3003 context->set_host_resolver(&host_resolver); | 3016 context->set_host_resolver(&host_resolver); |
3004 context->Init(); | 3017 context->Init(); |
3005 | 3018 |
3006 TestDelegate d; | 3019 TestDelegate d; |
3007 TestURLRequest req(GURL("http://example.com"), &d); | 3020 TestURLRequest req(GURL("http://example.com"), &d); |
3008 req.set_context(context); | 3021 req.set_context(context); |
3009 req.set_method("GET"); | 3022 req.set_method("GET"); |
3010 | 3023 |
3011 req.Start(); | 3024 req.Start(); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3408 } | 3421 } |
3409 } | 3422 } |
3410 | 3423 |
3411 // Check that default A-L header is sent. | 3424 // Check that default A-L header is sent. |
3412 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 3425 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
3413 ASSERT_TRUE(test_server_.Start()); | 3426 ASSERT_TRUE(test_server_.Start()); |
3414 | 3427 |
3415 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3428 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3416 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3429 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3417 context->set_network_delegate(&network_delegate); | 3430 context->set_network_delegate(&network_delegate); |
| 3431 context->set_http_server_properties(NULL); |
3418 context->set_accept_language("en"); | 3432 context->set_accept_language("en"); |
3419 context->Init(); | 3433 context->Init(); |
3420 | 3434 |
3421 TestDelegate d; | 3435 TestDelegate d; |
3422 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 3436 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
3423 req.set_context(context); | 3437 req.set_context(context); |
3424 req.Start(); | 3438 req.Start(); |
3425 MessageLoop::current()->Run(); | 3439 MessageLoop::current()->Run(); |
3426 EXPECT_EQ("en", d.data_received()); | 3440 EXPECT_EQ("en", d.data_received()); |
3427 } | 3441 } |
3428 | 3442 |
3429 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 3443 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
3430 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 3444 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
3431 ASSERT_TRUE(test_server_.Start()); | 3445 ASSERT_TRUE(test_server_.Start()); |
3432 | 3446 |
3433 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3447 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3434 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3448 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3435 context->set_network_delegate(&network_delegate); | 3449 context->set_network_delegate(&network_delegate); |
| 3450 context->set_http_server_properties(NULL); |
3436 context->Init(); | 3451 context->Init(); |
3437 // We override the language after initialization because empty entries | 3452 // We override the language after initialization because empty entries |
3438 // get overridden by Init(). | 3453 // get overridden by Init(). |
3439 context->set_accept_language(""); | 3454 context->set_accept_language(""); |
3440 | 3455 |
3441 TestDelegate d; | 3456 TestDelegate d; |
3442 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 3457 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
3443 req.set_context(context); | 3458 req.set_context(context); |
3444 req.Start(); | 3459 req.Start(); |
3445 MessageLoop::current()->Run(); | 3460 MessageLoop::current()->Run(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 3508 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
3494 } | 3509 } |
3495 | 3510 |
3496 // Check that default A-C header is sent. | 3511 // Check that default A-C header is sent. |
3497 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 3512 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
3498 ASSERT_TRUE(test_server_.Start()); | 3513 ASSERT_TRUE(test_server_.Start()); |
3499 | 3514 |
3500 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3515 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3501 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3516 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3502 context->set_network_delegate(&network_delegate); | 3517 context->set_network_delegate(&network_delegate); |
| 3518 context->set_http_server_properties(NULL); |
3503 context->set_accept_charset("en"); | 3519 context->set_accept_charset("en"); |
3504 context->Init(); | 3520 context->Init(); |
3505 | 3521 |
3506 TestDelegate d; | 3522 TestDelegate d; |
3507 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 3523 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
3508 req.set_context(context); | 3524 req.set_context(context); |
3509 req.Start(); | 3525 req.Start(); |
3510 MessageLoop::current()->Run(); | 3526 MessageLoop::current()->Run(); |
3511 EXPECT_EQ("en", d.data_received()); | 3527 EXPECT_EQ("en", d.data_received()); |
3512 } | 3528 } |
3513 | 3529 |
3514 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 3530 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
3515 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 3531 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
3516 ASSERT_TRUE(test_server_.Start()); | 3532 ASSERT_TRUE(test_server_.Start()); |
3517 | 3533 |
3518 TestNetworkDelegate network_delegate; // must outlive URLRequests | 3534 TestNetworkDelegate network_delegate; // must outlive URLRequests |
3519 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 3535 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); |
3520 context->set_network_delegate(&network_delegate); | 3536 context->set_network_delegate(&network_delegate); |
| 3537 context->set_http_server_properties(NULL); |
3521 context->Init(); | 3538 context->Init(); |
3522 // We override the accepted charset after initialization because empty | 3539 // We override the accepted charset after initialization because empty |
3523 // entries get overridden otherwise. | 3540 // entries get overridden otherwise. |
3524 context->set_accept_charset(""); | 3541 context->set_accept_charset(""); |
3525 | 3542 |
3526 TestDelegate d; | 3543 TestDelegate d; |
3527 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 3544 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
3528 req.set_context(context); | 3545 req.set_context(context); |
3529 req.Start(); | 3546 req.Start(); |
3530 MessageLoop::current()->Run(); | 3547 MessageLoop::current()->Run(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3572 req.SetExtraRequestHeaders(headers); | 3589 req.SetExtraRequestHeaders(headers); |
3573 req.Start(); | 3590 req.Start(); |
3574 MessageLoop::current()->Run(); | 3591 MessageLoop::current()->Run(); |
3575 // If the net tests are being run with ChromeFrame then we need to allow for | 3592 // If the net tests are being run with ChromeFrame then we need to allow for |
3576 // the 'chromeframe' suffix which is added to the user agent before the | 3593 // the 'chromeframe' suffix which is added to the user agent before the |
3577 // closing parentheses. | 3594 // closing parentheses. |
3578 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3595 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
3579 } | 3596 } |
3580 | 3597 |
3581 } // namespace net | 3598 } // namespace net |
OLD | NEW |