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

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

Issue 10408067: [net] Switch TestURLRequestContext to use MockCachingHostResolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to trunk. Created 8 years, 7 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') | sync/notifier/DEPS » ('j') | 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) 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return false; 153 return false;
154 154
155 for (size_t i = 0; i < size; ++i) { 155 for (size_t i = 0; i < size; ++i) {
156 if (!a[i].Equals(b[i])) 156 if (!a[i].Equals(b[i]))
157 return false; 157 return false;
158 } 158 }
159 159
160 return true; 160 return true;
161 } 161 }
162 162
163 } // namespace
164
165 // A network delegate that blocks requests, optionally cancelling or redirecting 163 // A network delegate that blocks requests, optionally cancelling or redirecting
166 // them. 164 // them.
167 class BlockingNetworkDelegate : public TestNetworkDelegate { 165 class BlockingNetworkDelegate : public TestNetworkDelegate {
168 public: 166 public:
169 BlockingNetworkDelegate() 167 BlockingNetworkDelegate()
170 : retval_(ERR_IO_PENDING), 168 : retval_(ERR_IO_PENDING),
171 callback_retval_(OK), 169 callback_retval_(OK),
172 auth_retval_(NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING), 170 auth_retval_(NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING),
173 auth_callback_retval_( 171 auth_callback_retval_(
174 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION), 172 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION),
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 394 }
397 395
398 void set_main_intercept_job(URLRequestJob* job) { 396 void set_main_intercept_job(URLRequestJob* job) {
399 main_intercept_job_ = job; 397 main_intercept_job_ = job;
400 } 398 }
401 399
402 private: 400 private:
403 mutable URLRequestJob* main_intercept_job_; 401 mutable URLRequestJob* main_intercept_job_;
404 }; 402 };
405 403
404 class TestURLRequestContextWithProxy : public TestURLRequestContext {
405 public:
406 // Does not own |delegate|.
407 TestURLRequestContextWithProxy(const std::string& proxy,
408 NetworkDelegate* delegate)
409 : TestURLRequestContext(true) {
410 context_storage_.set_proxy_service(ProxyService::CreateFixed(proxy));
411 set_network_delegate(delegate);
412 Init();
413 }
414 virtual ~TestURLRequestContextWithProxy() {}
415 };
416
417 } // namespace
418
406 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f 419 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f
407 class URLRequestTest : public PlatformTest { 420 class URLRequestTest : public PlatformTest {
408 public: 421 public:
409 URLRequestTest() : default_context_(true) { 422 URLRequestTest() : default_context_(true) {
410 default_context_.set_network_delegate(&default_network_delegate_); 423 default_context_.set_network_delegate(&default_network_delegate_);
411 default_context_.Init(); 424 default_context_.Init();
412 } 425 }
413 426
414 // Adds the TestJobInterceptor to the default context. 427 // Adds the TestJobInterceptor to the default context.
415 TestJobInterceptor* AddTestInterceptor() { 428 TestJobInterceptor* AddTestInterceptor() {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 556
544 // In this unit test, we're using the HTTPTestServer as a proxy server and 557 // In this unit test, we're using the HTTPTestServer as a proxy server and
545 // issuing a CONNECT request with the magic host name "www.redirect.com". 558 // issuing a CONNECT request with the magic host name "www.redirect.com".
546 // The HTTPTestServer will return a 302 response, which we should not 559 // The HTTPTestServer will return a 302 response, which we should not
547 // follow. 560 // follow.
548 // flaky: crbug.com/96594 561 // flaky: crbug.com/96594
549 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { 562 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) {
550 ASSERT_TRUE(test_server_.Start()); 563 ASSERT_TRUE(test_server_.Start());
551 564
552 TestNetworkDelegate network_delegate; // must outlive URLRequest 565 TestNetworkDelegate network_delegate; // must outlive URLRequest
553 TestURLRequestContext context(true); 566 TestURLRequestContextWithProxy context(
554 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 567 test_server_.host_port_pair().ToString(),
555 context.set_network_delegate(&network_delegate); 568 &network_delegate);
556 context.Init();
557 569
558 TestDelegate d; 570 TestDelegate d;
559 { 571 {
560 URLRequest r(GURL("https://www.redirect.com/"), &d); 572 URLRequest r(GURL("https://www.redirect.com/"), &d);
561 r.set_context(&context); 573 r.set_context(&context);
562 r.Start(); 574 r.Start();
563 EXPECT_TRUE(r.is_pending()); 575 EXPECT_TRUE(r.is_pending());
564 576
565 MessageLoop::current()->Run(); 577 MessageLoop::current()->Run();
566 578
567 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 579 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
568 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 580 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
569 EXPECT_EQ(1, d.response_started_count()); 581 EXPECT_EQ(1, d.response_started_count());
570 // We should not have followed the redirect. 582 // We should not have followed the redirect.
571 EXPECT_EQ(0, d.received_redirect_count()); 583 EXPECT_EQ(0, d.received_redirect_count());
572 } 584 }
573 } 585 }
574 586
575 // This is the same as the previous test, but checks that the network delegate 587 // This is the same as the previous test, but checks that the network delegate
576 // registers the error. 588 // registers the error.
577 // This test was disabled because it made chrome_frame_net_tests hang 589 // This test was disabled because it made chrome_frame_net_tests hang
578 // (see bug 102991). 590 // (see bug 102991).
579 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { 591 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) {
580 ASSERT_TRUE(test_server_.Start()); 592 ASSERT_TRUE(test_server_.Start());
581 593
582 TestNetworkDelegate network_delegate; // must outlive URLRequest 594 TestNetworkDelegate network_delegate; // must outlive URLRequest
583 TestURLRequestContext context(true); 595 TestURLRequestContextWithProxy context(
584 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 596 test_server_.host_port_pair().ToString(),
585 context.set_network_delegate(&network_delegate); 597 &network_delegate);
586 context.Init();
587 598
588 TestDelegate d; 599 TestDelegate d;
589 { 600 {
590 URLRequest r(GURL("https://www.redirect.com/"), &d); 601 URLRequest r(GURL("https://www.redirect.com/"), &d);
591 r.set_context(&context); 602 r.set_context(&context);
592 r.Start(); 603 r.Start();
593 EXPECT_TRUE(r.is_pending()); 604 EXPECT_TRUE(r.is_pending());
594 605
595 MessageLoop::current()->Run(); 606 MessageLoop::current()->Run();
596 607
597 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 608 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
598 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 609 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
599 EXPECT_EQ(1, d.response_started_count()); 610 EXPECT_EQ(1, d.response_started_count());
600 // We should not have followed the redirect. 611 // We should not have followed the redirect.
601 EXPECT_EQ(0, d.received_redirect_count()); 612 EXPECT_EQ(0, d.received_redirect_count());
602 613
603 EXPECT_EQ(1, network_delegate.error_count()); 614 EXPECT_EQ(1, network_delegate.error_count());
604 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); 615 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error());
605 } 616 }
606 } 617 }
607 618
608 // Tests that the network delegate can block and cancel a request. 619 // Tests that the network delegate can block and cancel a request.
609 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { 620 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
610 ASSERT_TRUE(test_server_.Start()); 621 ASSERT_TRUE(test_server_.Start());
611 622
612 TestDelegate d; 623 TestDelegate d;
613 BlockingNetworkDelegate network_delegate; 624 BlockingNetworkDelegate network_delegate;
614 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); 625 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE);
615 626
616 TestURLRequestContext context(true); 627 TestURLRequestContextWithProxy context(
617 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 628 test_server_.host_port_pair().ToString(),
618 context.set_network_delegate(&network_delegate); 629 &network_delegate);
619 context.Init();
620 630
621 { 631 {
622 URLRequest r(test_server_.GetURL(""), &d); 632 URLRequest r(test_server_.GetURL(""), &d);
623 r.set_context(&context); 633 r.set_context(&context);
624 634
625 r.Start(); 635 r.Start();
626 MessageLoop::current()->Run(); 636 MessageLoop::current()->Run();
627 637
628 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 638 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
629 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 639 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
630 EXPECT_EQ(1, network_delegate.created_requests()); 640 EXPECT_EQ(1, network_delegate.created_requests());
631 EXPECT_EQ(0, network_delegate.destroyed_requests()); 641 EXPECT_EQ(0, network_delegate.destroyed_requests());
632 } 642 }
633 EXPECT_EQ(1, network_delegate.destroyed_requests()); 643 EXPECT_EQ(1, network_delegate.destroyed_requests());
634 } 644 }
635 645
636 // Tests that the network delegate can cancel a request synchronously. 646 // Tests that the network delegate can cancel a request synchronously.
637 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { 647 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) {
638 ASSERT_TRUE(test_server_.Start()); 648 ASSERT_TRUE(test_server_.Start());
639 649
640 TestDelegate d; 650 TestDelegate d;
641 BlockingNetworkDelegate network_delegate; 651 BlockingNetworkDelegate network_delegate;
642 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 652 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
643 653
644 TestURLRequestContext context(true); 654 TestURLRequestContextWithProxy context(
645 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 655 test_server_.host_port_pair().ToString(),
646 context.set_network_delegate(&network_delegate); 656 &network_delegate);
647 context.Init();
648 657
649 { 658 {
650 URLRequest r(test_server_.GetURL(""), &d); 659 URLRequest r(test_server_.GetURL(""), &d);
651 r.set_context(&context); 660 r.set_context(&context);
652 661
653 r.Start(); 662 r.Start();
654 MessageLoop::current()->Run(); 663 MessageLoop::current()->Run();
655 664
656 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 665 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
657 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 666 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
658 EXPECT_EQ(1, network_delegate.created_requests()); 667 EXPECT_EQ(1, network_delegate.created_requests());
659 EXPECT_EQ(0, network_delegate.destroyed_requests()); 668 EXPECT_EQ(0, network_delegate.destroyed_requests());
660 } 669 }
661 EXPECT_EQ(1, network_delegate.destroyed_requests()); 670 EXPECT_EQ(1, network_delegate.destroyed_requests());
662 } 671 }
663 672
664 // Tests that the network delegate can block and redirect a request to a new 673 // Tests that the network delegate can block and redirect a request to a new
665 // URL. 674 // URL.
666 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { 675 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) {
667 ASSERT_TRUE(test_server_.Start()); 676 ASSERT_TRUE(test_server_.Start());
668 677
669 TestDelegate d; 678 TestDelegate d;
670 BlockingNetworkDelegate network_delegate; 679 BlockingNetworkDelegate network_delegate;
671 GURL redirect_url(test_server_.GetURL("simple.html")); 680 GURL redirect_url(test_server_.GetURL("simple.html"));
672 network_delegate.set_redirect_url(redirect_url); 681 network_delegate.set_redirect_url(redirect_url);
673 682
674 TestURLRequestContext context(true); 683 TestURLRequestContextWithProxy context(
675 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 684 test_server_.host_port_pair().ToString(),
676 context.set_network_delegate(&network_delegate); 685 &network_delegate);
677 context.Init();
678 686
679 { 687 {
680 GURL original_url(test_server_.GetURL("empty.html")); 688 GURL original_url(test_server_.GetURL("empty.html"));
681 URLRequest r(original_url, &d); 689 URLRequest r(original_url, &d);
682 r.set_context(&context); 690 r.set_context(&context);
683 691
684 r.Start(); 692 r.Start();
685 MessageLoop::current()->Run(); 693 MessageLoop::current()->Run();
686 694
687 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 695 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
(...skipping 11 matching lines...) Expand all
699 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. 707 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly.
700 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { 708 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) {
701 ASSERT_TRUE(test_server_.Start()); 709 ASSERT_TRUE(test_server_.Start());
702 710
703 TestDelegate d; 711 TestDelegate d;
704 BlockingNetworkDelegate network_delegate; 712 BlockingNetworkDelegate network_delegate;
705 GURL redirect_url(test_server_.GetURL("simple.html")); 713 GURL redirect_url(test_server_.GetURL("simple.html"));
706 network_delegate.set_redirect_url(redirect_url); 714 network_delegate.set_redirect_url(redirect_url);
707 network_delegate.set_retval(OK); 715 network_delegate.set_retval(OK);
708 716
709 TestURLRequestContext context(true); 717 TestURLRequestContextWithProxy context(
710 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 718 test_server_.host_port_pair().ToString(),
711 context.set_network_delegate(&network_delegate); 719 &network_delegate);
712 context.Init();
713 720
714 { 721 {
715 GURL original_url(test_server_.GetURL("empty.html")); 722 GURL original_url(test_server_.GetURL("empty.html"));
716 URLRequest r(original_url, &d); 723 URLRequest r(original_url, &d);
717 r.set_context(&context); 724 r.set_context(&context);
718 725
719 r.Start(); 726 r.Start();
720 MessageLoop::current()->Run(); 727 MessageLoop::current()->Run();
721 728
722 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 729 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 EXPECT_EQ(1, network_delegate.destroyed_requests()); 1124 EXPECT_EQ(1, network_delegate.destroyed_requests());
1118 } 1125 }
1119 1126
1120 // In this unit test, we're using the HTTPTestServer as a proxy server and 1127 // In this unit test, we're using the HTTPTestServer as a proxy server and
1121 // issuing a CONNECT request with the magic host name "www.server-auth.com". 1128 // issuing a CONNECT request with the magic host name "www.server-auth.com".
1122 // The HTTPTestServer will return a 401 response, which we should balk at. 1129 // The HTTPTestServer will return a 401 response, which we should balk at.
1123 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 1130 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
1124 ASSERT_TRUE(test_server_.Start()); 1131 ASSERT_TRUE(test_server_.Start());
1125 1132
1126 TestNetworkDelegate network_delegate; // must outlive URLRequest 1133 TestNetworkDelegate network_delegate; // must outlive URLRequest
1127 TestURLRequestContext context(true); 1134 TestURLRequestContextWithProxy context(
1128 context.SetProxyFromString(test_server_.host_port_pair().ToString()); 1135 test_server_.host_port_pair().ToString(),
1129 context.set_network_delegate(&network_delegate); 1136 &network_delegate);
1130 context.Init();
1131 1137
1132 TestDelegate d; 1138 TestDelegate d;
1133 { 1139 {
1134 URLRequest r(GURL("https://www.server-auth.com/"), &d); 1140 URLRequest r(GURL("https://www.server-auth.com/"), &d);
1135 r.set_context(&context); 1141 r.set_context(&context);
1136 1142
1137 r.Start(); 1143 r.Start();
1138 EXPECT_TRUE(r.is_pending()); 1144 EXPECT_TRUE(r.is_pending());
1139 1145
1140 MessageLoop::current()->Run(); 1146 MessageLoop::current()->Run();
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 req.Start(); 3058 req.Start();
3053 MessageLoop::current()->Run(); 3059 MessageLoop::current()->Run();
3054 3060
3055 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3061 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3056 == std::string::npos); 3062 == std::string::npos);
3057 3063
3058 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 3064 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
3059 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3065 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3060 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3066 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3061 } 3067 }
3062
3063 default_context_.set_network_delegate(&default_network_delegate_);
3064 } 3068 }
3065 3069
3066 TEST_F(URLRequestTest, DoNotSaveCookies) { 3070 TEST_F(URLRequestTest, DoNotSaveCookies) {
3067 LocalHttpTestServer test_server; 3071 LocalHttpTestServer test_server;
3068 ASSERT_TRUE(test_server.Start()); 3072 ASSERT_TRUE(test_server.Start());
3069 3073
3070 // Set up a cookie. 3074 // Set up a cookie.
3071 { 3075 {
3072 TestNetworkDelegate network_delegate; 3076 TestNetworkDelegate network_delegate;
3073 default_context_.set_network_delegate(&network_delegate); 3077 default_context_.set_network_delegate(&network_delegate);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 3117
3114 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3118 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3115 == std::string::npos); 3119 == std::string::npos);
3116 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3120 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3117 != std::string::npos); 3121 != std::string::npos);
3118 3122
3119 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3123 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3120 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3124 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3121 EXPECT_EQ(0, network_delegate.set_cookie_count()); 3125 EXPECT_EQ(0, network_delegate.set_cookie_count());
3122 } 3126 }
3123
3124 default_context_.set_network_delegate(&default_network_delegate_);
3125 } 3127 }
3126 3128
3127 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 3129 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
3128 LocalHttpTestServer test_server; 3130 LocalHttpTestServer test_server;
3129 ASSERT_TRUE(test_server.Start()); 3131 ASSERT_TRUE(test_server.Start());
3130 3132
3131 // Set up a cookie. 3133 // Set up a cookie.
3132 { 3134 {
3133 TestNetworkDelegate network_delegate; 3135 TestNetworkDelegate network_delegate;
3134 default_context_.set_network_delegate(&network_delegate); 3136 default_context_.set_network_delegate(&network_delegate);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3169 req.set_context(&default_context_); 3171 req.set_context(&default_context_);
3170 req.Start(); 3172 req.Start();
3171 MessageLoop::current()->Run(); 3173 MessageLoop::current()->Run();
3172 3174
3173 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3175 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3174 == std::string::npos); 3176 == std::string::npos);
3175 3177
3176 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 3178 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
3177 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3179 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3178 } 3180 }
3179
3180 default_context_.set_network_delegate(&default_network_delegate_);
3181 } 3181 }
3182 3182
3183 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 3183 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
3184 LocalHttpTestServer test_server; 3184 LocalHttpTestServer test_server;
3185 ASSERT_TRUE(test_server.Start()); 3185 ASSERT_TRUE(test_server.Start());
3186 3186
3187 // Set up a cookie. 3187 // Set up a cookie.
3188 { 3188 {
3189 TestNetworkDelegate network_delegate; 3189 TestNetworkDelegate network_delegate;
3190 default_context_.set_network_delegate(&network_delegate); 3190 default_context_.set_network_delegate(&network_delegate);
(...skipping 17 matching lines...) Expand all
3208 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 3208 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
3209 req.set_context(&default_context_); 3209 req.set_context(&default_context_);
3210 req.Start(); 3210 req.Start();
3211 3211
3212 MessageLoop::current()->Run(); 3212 MessageLoop::current()->Run();
3213 3213
3214 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3214 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3215 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 3215 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
3216 } 3216 }
3217 3217
3218
3219 // Verify the cookies weren't saved or updated. 3218 // Verify the cookies weren't saved or updated.
3220 { 3219 {
3221 TestNetworkDelegate network_delegate; 3220 TestNetworkDelegate network_delegate;
3222 default_context_.set_network_delegate(&network_delegate); 3221 default_context_.set_network_delegate(&network_delegate);
3223 TestDelegate d; 3222 TestDelegate d;
3224 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3223 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3225 req.set_context(&default_context_); 3224 req.set_context(&default_context_);
3226 req.Start(); 3225 req.Start();
3227 MessageLoop::current()->Run(); 3226 MessageLoop::current()->Run();
3228 3227
3229 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3228 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3230 == std::string::npos); 3229 == std::string::npos);
3231 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3230 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3232 != std::string::npos); 3231 != std::string::npos);
3233 3232
3234 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3233 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3235 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3234 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3236 } 3235 }
3237
3238 default_context_.set_network_delegate(&default_network_delegate_);
3239 } 3236 }
3240 3237
3241 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 3238 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
3242 LocalHttpTestServer test_server; 3239 LocalHttpTestServer test_server;
3243 ASSERT_TRUE(test_server.Start()); 3240 ASSERT_TRUE(test_server.Start());
3244 3241
3245 // Set up an empty cookie. 3242 // Set up an empty cookie.
3246 { 3243 {
3247 TestNetworkDelegate network_delegate; 3244 TestNetworkDelegate network_delegate;
3248 default_context_.set_network_delegate(&network_delegate); 3245 default_context_.set_network_delegate(&network_delegate);
3249 TestDelegate d; 3246 TestDelegate d;
3250 URLRequest req(test_server.GetURL("set-cookie"), &d); 3247 URLRequest req(test_server.GetURL("set-cookie"), &d);
3251 req.set_context(&default_context_); 3248 req.set_context(&default_context_);
3252 req.Start(); 3249 req.Start();
3253 MessageLoop::current()->Run(); 3250 MessageLoop::current()->Run();
3254 3251
3255 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3252 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3256 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3253 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3257 EXPECT_EQ(0, network_delegate.set_cookie_count()); 3254 EXPECT_EQ(0, network_delegate.set_cookie_count());
3258 } 3255 }
3259
3260 default_context_.set_network_delegate(&default_network_delegate_);
3261 } 3256 }
3262 3257
3263 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 3258 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
3264 LocalHttpTestServer test_server; 3259 LocalHttpTestServer test_server;
3265 ASSERT_TRUE(test_server.Start()); 3260 ASSERT_TRUE(test_server.Start());
3266 3261
3267 // Set up a cookie. 3262 // Set up a cookie.
3268 { 3263 {
3269 TestNetworkDelegate network_delegate; 3264 TestNetworkDelegate network_delegate;
3270 default_context_.set_network_delegate(&network_delegate); 3265 default_context_.set_network_delegate(&network_delegate);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3305 req.set_context(&default_context_); 3300 req.set_context(&default_context_);
3306 req.Start(); 3301 req.Start();
3307 MessageLoop::current()->Run(); 3302 MessageLoop::current()->Run();
3308 3303
3309 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3304 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3310 == std::string::npos); 3305 == std::string::npos);
3311 3306
3312 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 3307 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
3313 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3308 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3314 } 3309 }
3315
3316 default_context_.set_network_delegate(&default_network_delegate_);
3317 } 3310 }
3318 3311
3319 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 3312 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
3320 LocalHttpTestServer test_server; 3313 LocalHttpTestServer test_server;
3321 ASSERT_TRUE(test_server.Start()); 3314 ASSERT_TRUE(test_server.Start());
3322 3315
3323 // Set up a cookie. 3316 // Set up a cookie.
3324 { 3317 {
3325 TestNetworkDelegate network_delegate; 3318 TestNetworkDelegate network_delegate;
3326 default_context_.set_network_delegate(&network_delegate); 3319 default_context_.set_network_delegate(&network_delegate);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3362 MessageLoop::current()->Run(); 3355 MessageLoop::current()->Run();
3363 3356
3364 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3357 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3365 == std::string::npos); 3358 == std::string::npos);
3366 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3359 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3367 != std::string::npos); 3360 != std::string::npos);
3368 3361
3369 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3362 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3370 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3363 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3371 } 3364 }
3372
3373 default_context_.set_network_delegate(&default_network_delegate_);
3374 } 3365 }
3375 3366
3376 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { 3367 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) {
3377 EXPECT_EQ(1U, cookies.size()); 3368 EXPECT_EQ(1U, cookies.size());
3378 EXPECT_FALSE(cookies[0].IsPersistent()); 3369 EXPECT_FALSE(cookies[0].IsPersistent());
3379 *was_run = true; 3370 *was_run = true;
3380 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 3371 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
3381 } 3372 }
3382 3373
3383 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { 3374 TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 ASSERT_NE(req.identifier(), other_req.identifier()); 4019 ASSERT_NE(req.identifier(), other_req.identifier());
4029 } 4020 }
4030 4021
4031 // Check that a failure to connect to the proxy is reported to the network 4022 // Check that a failure to connect to the proxy is reported to the network
4032 // delegate. 4023 // delegate.
4033 TEST_F(URLRequestTest, NetworkDelegateProxyError) { 4024 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
4034 MockHostResolver host_resolver; 4025 MockHostResolver host_resolver;
4035 host_resolver.rules()->AddSimulatedFailure("*"); 4026 host_resolver.rules()->AddSimulatedFailure("*");
4036 4027
4037 TestNetworkDelegate network_delegate; // must outlive URLRequests 4028 TestNetworkDelegate network_delegate; // must outlive URLRequests
4038 TestURLRequestContext context(true); 4029 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate);
4039 context.set_network_delegate(&network_delegate);
4040 context.SetProxyFromString("myproxy:70");
4041 context.set_host_resolver(&host_resolver);
4042 context.Init();
4043 4030
4044 TestDelegate d; 4031 TestDelegate d;
4045 URLRequest req(GURL("http://example.com"), &d); 4032 URLRequest req(GURL("http://example.com"), &d);
4046 req.set_context(&context); 4033 req.set_context(&context);
4047 req.set_method("GET"); 4034 req.set_method("GET");
4048 4035
4049 req.Start(); 4036 req.Start();
4050 MessageLoop::current()->Run(); 4037 MessageLoop::current()->Run();
4051 4038
4052 // Check we see a failed request. 4039 // Check we see a failed request.
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
4607 req.SetExtraRequestHeaders(headers); 4594 req.SetExtraRequestHeaders(headers);
4608 req.Start(); 4595 req.Start();
4609 MessageLoop::current()->Run(); 4596 MessageLoop::current()->Run();
4610 // If the net tests are being run with ChromeFrame then we need to allow for 4597 // If the net tests are being run with ChromeFrame then we need to allow for
4611 // the 'chromeframe' suffix which is added to the user agent before the 4598 // the 'chromeframe' suffix which is added to the user agent before the
4612 // closing parentheses. 4599 // closing parentheses.
4613 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4600 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4614 } 4601 }
4615 4602
4616 } // namespace net 4603 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | sync/notifier/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698