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

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

Issue 407093011: Allow URLRequests from one context to have different NetworkDelegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix new tests Created 6 years, 4 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_throttler_unittest.cc ('k') | net/websockets/websocket_stream.cc » ('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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 protected: 627 protected:
628 CapturingNetLog net_log_; 628 CapturingNetLog net_log_;
629 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 629 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
630 URLRequestJobFactoryImpl job_factory_; 630 URLRequestJobFactoryImpl job_factory_;
631 TestURLRequestContext default_context_; 631 TestURLRequestContext default_context_;
632 }; 632 };
633 633
634 TEST_F(URLRequestTest, AboutBlankTest) { 634 TEST_F(URLRequestTest, AboutBlankTest) {
635 TestDelegate d; 635 TestDelegate d;
636 { 636 {
637 URLRequest r(GURL("about:blank"), DEFAULT_PRIORITY, &d, &default_context_); 637 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
638 GURL("about:blank"), DEFAULT_PRIORITY, &d, NULL));
638 639
639 r.Start(); 640 r->Start();
640 EXPECT_TRUE(r.is_pending()); 641 EXPECT_TRUE(r->is_pending());
641 642
642 base::RunLoop().Run(); 643 base::RunLoop().Run();
643 644
644 EXPECT_TRUE(!r.is_pending()); 645 EXPECT_TRUE(!r->is_pending());
645 EXPECT_FALSE(d.received_data_before_response()); 646 EXPECT_FALSE(d.received_data_before_response());
646 EXPECT_EQ(d.bytes_received(), 0); 647 EXPECT_EQ(d.bytes_received(), 0);
647 EXPECT_EQ("", r.GetSocketAddress().host()); 648 EXPECT_EQ("", r->GetSocketAddress().host());
648 EXPECT_EQ(0, r.GetSocketAddress().port()); 649 EXPECT_EQ(0, r->GetSocketAddress().port());
649 650
650 HttpRequestHeaders headers; 651 HttpRequestHeaders headers;
651 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 652 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
652 } 653 }
653 } 654 }
654 655
655 TEST_F(URLRequestTest, DataURLImageTest) { 656 TEST_F(URLRequestTest, DataURLImageTest) {
656 TestDelegate d; 657 TestDelegate d;
657 { 658 {
658 // Use our nice little Chrome logo. 659 // Use our nice little Chrome logo.
659 URLRequest r( 660 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
660 GURL( 661 GURL(
661 "data:image/png;base64," 662 "data:image/png;base64,"
662 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" 663 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3"
663 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" 664 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD"
664 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" 665 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t"
665 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" 666 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9"
666 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" 667 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1"
667 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" 668 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z"
668 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" 669 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW"
669 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" 670 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW"
670 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" 671 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb"
671 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" 672 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5"
672 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" 673 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV"
673 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" 674 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq"
674 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" 675 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F"
675 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" 676 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB"
676 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" 677 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM"
677 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" 678 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm"
678 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" 679 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En"
679 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), 680 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="),
680 DEFAULT_PRIORITY, 681 DEFAULT_PRIORITY, &d, NULL));
681 &d,
682 &default_context_);
683 682
684 r.Start(); 683 r->Start();
685 EXPECT_TRUE(r.is_pending()); 684 EXPECT_TRUE(r->is_pending());
686 685
687 base::RunLoop().Run(); 686 base::RunLoop().Run();
688 687
689 EXPECT_TRUE(!r.is_pending()); 688 EXPECT_TRUE(!r->is_pending());
690 EXPECT_FALSE(d.received_data_before_response()); 689 EXPECT_FALSE(d.received_data_before_response());
691 EXPECT_EQ(d.bytes_received(), 911); 690 EXPECT_EQ(d.bytes_received(), 911);
692 EXPECT_EQ("", r.GetSocketAddress().host()); 691 EXPECT_EQ("", r->GetSocketAddress().host());
693 EXPECT_EQ(0, r.GetSocketAddress().port()); 692 EXPECT_EQ(0, r->GetSocketAddress().port());
694 693
695 HttpRequestHeaders headers; 694 HttpRequestHeaders headers;
696 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 695 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
697 } 696 }
698 } 697 }
699 698
700 #if !defined(DISABLE_FILE_SUPPORT) 699 #if !defined(DISABLE_FILE_SUPPORT)
701 TEST_F(URLRequestTest, FileTest) { 700 TEST_F(URLRequestTest, FileTest) {
702 base::FilePath app_path; 701 base::FilePath app_path;
703 PathService::Get(base::FILE_EXE, &app_path); 702 PathService::Get(base::FILE_EXE, &app_path);
704 GURL app_url = FilePathToFileURL(app_path); 703 GURL app_url = FilePathToFileURL(app_path);
705 704
706 TestDelegate d; 705 TestDelegate d;
707 { 706 {
708 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_); 707 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
708 app_url, DEFAULT_PRIORITY, &d, NULL));
709 709
710 r.Start(); 710 r->Start();
711 EXPECT_TRUE(r.is_pending()); 711 EXPECT_TRUE(r->is_pending());
712 712
713 base::RunLoop().Run(); 713 base::RunLoop().Run();
714 714
715 int64 file_size = -1; 715 int64 file_size = -1;
716 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); 716 EXPECT_TRUE(base::GetFileSize(app_path, &file_size));
717 717
718 EXPECT_TRUE(!r.is_pending()); 718 EXPECT_TRUE(!r->is_pending());
719 EXPECT_EQ(1, d.response_started_count()); 719 EXPECT_EQ(1, d.response_started_count());
720 EXPECT_FALSE(d.received_data_before_response()); 720 EXPECT_FALSE(d.received_data_before_response());
721 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 721 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
722 EXPECT_EQ("", r.GetSocketAddress().host()); 722 EXPECT_EQ("", r->GetSocketAddress().host());
723 EXPECT_EQ(0, r.GetSocketAddress().port()); 723 EXPECT_EQ(0, r->GetSocketAddress().port());
724 724
725 HttpRequestHeaders headers; 725 HttpRequestHeaders headers;
726 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 726 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
727 } 727 }
728 } 728 }
729 729
730 TEST_F(URLRequestTest, FileTestCancel) { 730 TEST_F(URLRequestTest, FileTestCancel) {
731 base::FilePath app_path; 731 base::FilePath app_path;
732 PathService::Get(base::FILE_EXE, &app_path); 732 PathService::Get(base::FILE_EXE, &app_path);
733 GURL app_url = FilePathToFileURL(app_path); 733 GURL app_url = FilePathToFileURL(app_path);
734 734
735 TestDelegate d; 735 TestDelegate d;
736 { 736 {
737 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_); 737 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
738 app_url, DEFAULT_PRIORITY, &d, NULL));
738 739
739 r.Start(); 740 r->Start();
740 EXPECT_TRUE(r.is_pending()); 741 EXPECT_TRUE(r->is_pending());
741 r.Cancel(); 742 r->Cancel();
742 } 743 }
743 // Async cancellation should be safe even when URLRequest has been already 744 // Async cancellation should be safe even when URLRequest has been already
744 // destroyed. 745 // destroyed.
745 base::RunLoop().RunUntilIdle(); 746 base::RunLoop().RunUntilIdle();
746 } 747 }
747 748
748 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { 749 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) {
749 const size_t buffer_size = 4000; 750 const size_t buffer_size = 4000;
750 scoped_ptr<char[]> buffer(new char[buffer_size]); 751 scoped_ptr<char[]> buffer(new char[buffer_size]);
751 FillBuffer(buffer.get(), buffer_size); 752 FillBuffer(buffer.get(), buffer_size);
752 753
753 base::FilePath temp_path; 754 base::FilePath temp_path;
754 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 755 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
755 GURL temp_url = FilePathToFileURL(temp_path); 756 GURL temp_url = FilePathToFileURL(temp_path);
756 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 757 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
757 758
758 int64 file_size; 759 int64 file_size;
759 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 760 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
760 761
761 const size_t first_byte_position = 500; 762 const size_t first_byte_position = 500;
762 const size_t last_byte_position = buffer_size - first_byte_position; 763 const size_t last_byte_position = buffer_size - first_byte_position;
763 const size_t content_length = last_byte_position - first_byte_position + 1; 764 const size_t content_length = last_byte_position - first_byte_position + 1;
764 std::string partial_buffer_string(buffer.get() + first_byte_position, 765 std::string partial_buffer_string(buffer.get() + first_byte_position,
765 buffer.get() + last_byte_position + 1); 766 buffer.get() + last_byte_position + 1);
766 767
767 TestDelegate d; 768 TestDelegate d;
768 { 769 {
769 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); 770 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
771 temp_url, DEFAULT_PRIORITY, &d, NULL));
770 772
771 HttpRequestHeaders headers; 773 HttpRequestHeaders headers;
772 headers.SetHeader( 774 headers.SetHeader(
773 HttpRequestHeaders::kRange, 775 HttpRequestHeaders::kRange,
774 HttpByteRange::Bounded( 776 HttpByteRange::Bounded(
775 first_byte_position, last_byte_position).GetHeaderValue()); 777 first_byte_position, last_byte_position).GetHeaderValue());
776 r.SetExtraRequestHeaders(headers); 778 r->SetExtraRequestHeaders(headers);
777 r.Start(); 779 r->Start();
778 EXPECT_TRUE(r.is_pending()); 780 EXPECT_TRUE(r->is_pending());
779 781
780 base::RunLoop().Run(); 782 base::RunLoop().Run();
781 EXPECT_TRUE(!r.is_pending()); 783 EXPECT_TRUE(!r->is_pending());
782 EXPECT_EQ(1, d.response_started_count()); 784 EXPECT_EQ(1, d.response_started_count());
783 EXPECT_FALSE(d.received_data_before_response()); 785 EXPECT_FALSE(d.received_data_before_response());
784 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); 786 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received());
785 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. 787 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed.
786 EXPECT_TRUE(partial_buffer_string == d.data_received()); 788 EXPECT_TRUE(partial_buffer_string == d.data_received());
787 } 789 }
788 790
789 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 791 EXPECT_TRUE(base::DeleteFile(temp_path, false));
790 } 792 }
791 793
(...skipping 11 matching lines...) Expand all
803 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 805 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
804 806
805 const size_t first_byte_position = 500; 807 const size_t first_byte_position = 500;
806 const size_t last_byte_position = buffer_size - 1; 808 const size_t last_byte_position = buffer_size - 1;
807 const size_t content_length = last_byte_position - first_byte_position + 1; 809 const size_t content_length = last_byte_position - first_byte_position + 1;
808 std::string partial_buffer_string(buffer.get() + first_byte_position, 810 std::string partial_buffer_string(buffer.get() + first_byte_position,
809 buffer.get() + last_byte_position + 1); 811 buffer.get() + last_byte_position + 1);
810 812
811 TestDelegate d; 813 TestDelegate d;
812 { 814 {
813 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); 815 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
816 temp_url, DEFAULT_PRIORITY, &d, NULL));
814 817
815 HttpRequestHeaders headers; 818 HttpRequestHeaders headers;
816 headers.SetHeader(HttpRequestHeaders::kRange, 819 headers.SetHeader(HttpRequestHeaders::kRange,
817 HttpByteRange::RightUnbounded( 820 HttpByteRange::RightUnbounded(
818 first_byte_position).GetHeaderValue()); 821 first_byte_position).GetHeaderValue());
819 r.SetExtraRequestHeaders(headers); 822 r->SetExtraRequestHeaders(headers);
820 r.Start(); 823 r->Start();
821 EXPECT_TRUE(r.is_pending()); 824 EXPECT_TRUE(r->is_pending());
822 825
823 base::RunLoop().Run(); 826 base::RunLoop().Run();
824 EXPECT_TRUE(!r.is_pending()); 827 EXPECT_TRUE(!r->is_pending());
825 EXPECT_EQ(1, d.response_started_count()); 828 EXPECT_EQ(1, d.response_started_count());
826 EXPECT_FALSE(d.received_data_before_response()); 829 EXPECT_FALSE(d.received_data_before_response());
827 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); 830 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received());
828 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. 831 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed.
829 EXPECT_TRUE(partial_buffer_string == d.data_received()); 832 EXPECT_TRUE(partial_buffer_string == d.data_received());
830 } 833 }
831 834
832 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 835 EXPECT_TRUE(base::DeleteFile(temp_path, false));
833 } 836 }
834 837
835 TEST_F(URLRequestTest, FileTestMultipleRanges) { 838 TEST_F(URLRequestTest, FileTestMultipleRanges) {
836 const size_t buffer_size = 400000; 839 const size_t buffer_size = 400000;
837 scoped_ptr<char[]> buffer(new char[buffer_size]); 840 scoped_ptr<char[]> buffer(new char[buffer_size]);
838 FillBuffer(buffer.get(), buffer_size); 841 FillBuffer(buffer.get(), buffer_size);
839 842
840 base::FilePath temp_path; 843 base::FilePath temp_path;
841 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 844 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
842 GURL temp_url = FilePathToFileURL(temp_path); 845 GURL temp_url = FilePathToFileURL(temp_path);
843 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 846 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
844 847
845 int64 file_size; 848 int64 file_size;
846 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 849 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
847 850
848 TestDelegate d; 851 TestDelegate d;
849 { 852 {
850 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); 853 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
854 temp_url, DEFAULT_PRIORITY, &d, NULL));
851 855
852 HttpRequestHeaders headers; 856 HttpRequestHeaders headers;
853 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); 857 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300");
854 r.SetExtraRequestHeaders(headers); 858 r->SetExtraRequestHeaders(headers);
855 r.Start(); 859 r->Start();
856 EXPECT_TRUE(r.is_pending()); 860 EXPECT_TRUE(r->is_pending());
857 861
858 base::RunLoop().Run(); 862 base::RunLoop().Run();
859 EXPECT_TRUE(d.request_failed()); 863 EXPECT_TRUE(d.request_failed());
860 } 864 }
861 865
862 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 866 EXPECT_TRUE(base::DeleteFile(temp_path, false));
863 } 867 }
864 868
865 TEST_F(URLRequestTest, AllowFileURLs) { 869 TEST_F(URLRequestTest, AllowFileURLs) {
866 base::ScopedTempDir temp_dir; 870 base::ScopedTempDir temp_dir;
867 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 871 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
868 base::FilePath test_file; 872 base::FilePath test_file;
869 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); 873 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file));
870 std::string test_data("monkey"); 874 std::string test_data("monkey");
871 base::WriteFile(test_file, test_data.data(), test_data.size()); 875 base::WriteFile(test_file, test_data.data(), test_data.size());
872 GURL test_file_url = FilePathToFileURL(test_file); 876 GURL test_file_url = FilePathToFileURL(test_file);
873 877
874 { 878 {
875 TestDelegate d; 879 TestDelegate d;
876 TestNetworkDelegate network_delegate; 880 TestNetworkDelegate network_delegate;
877 network_delegate.set_can_access_files(true); 881 network_delegate.set_can_access_files(true);
878 default_context_.set_network_delegate(&network_delegate); 882 default_context_.set_network_delegate(&network_delegate);
879 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); 883 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
880 r.Start(); 884 test_file_url, DEFAULT_PRIORITY, &d, NULL));
885 r->Start();
881 base::RunLoop().Run(); 886 base::RunLoop().Run();
882 EXPECT_FALSE(d.request_failed()); 887 EXPECT_FALSE(d.request_failed());
883 EXPECT_EQ(test_data, d.data_received()); 888 EXPECT_EQ(test_data, d.data_received());
884 } 889 }
885 890
886 { 891 {
887 TestDelegate d; 892 TestDelegate d;
888 TestNetworkDelegate network_delegate; 893 TestNetworkDelegate network_delegate;
889 network_delegate.set_can_access_files(false); 894 network_delegate.set_can_access_files(false);
890 default_context_.set_network_delegate(&network_delegate); 895 default_context_.set_network_delegate(&network_delegate);
891 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); 896 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
892 r.Start(); 897 test_file_url, DEFAULT_PRIORITY, &d, NULL));
898 r->Start();
893 base::RunLoop().Run(); 899 base::RunLoop().Run();
894 EXPECT_TRUE(d.request_failed()); 900 EXPECT_TRUE(d.request_failed());
895 EXPECT_EQ("", d.data_received()); 901 EXPECT_EQ("", d.data_received());
896 } 902 }
897 } 903 }
898 904
899 905
900 TEST_F(URLRequestTest, FileDirCancelTest) { 906 TEST_F(URLRequestTest, FileDirCancelTest) {
901 // Put in mock resource provider. 907 // Put in mock resource provider.
902 NetModule::SetResourceProvider(TestNetResourceProvider); 908 NetModule::SetResourceProvider(TestNetResourceProvider);
903 909
904 TestDelegate d; 910 TestDelegate d;
905 { 911 {
906 base::FilePath file_path; 912 base::FilePath file_path;
907 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 913 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
908 file_path = file_path.Append(FILE_PATH_LITERAL("net")); 914 file_path = file_path.Append(FILE_PATH_LITERAL("net"));
909 file_path = file_path.Append(FILE_PATH_LITERAL("data")); 915 file_path = file_path.Append(FILE_PATH_LITERAL("data"));
910 916
911 URLRequest req( 917 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
912 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, &default_context_); 918 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, NULL));
913 req.Start(); 919 req->Start();
914 EXPECT_TRUE(req.is_pending()); 920 EXPECT_TRUE(req->is_pending());
915 921
916 d.set_cancel_in_received_data_pending(true); 922 d.set_cancel_in_received_data_pending(true);
917 923
918 base::RunLoop().Run(); 924 base::RunLoop().Run();
919 } 925 }
920 926
921 // Take out mock resource provider. 927 // Take out mock resource provider.
922 NetModule::SetResourceProvider(NULL); 928 NetModule::SetResourceProvider(NULL);
923 } 929 }
924 930
925 TEST_F(URLRequestTest, FileDirOutputSanity) { 931 TEST_F(URLRequestTest, FileDirOutputSanity) {
926 // Verify the general sanity of the the output of the file: 932 // Verify the general sanity of the the output of the file:
927 // directory lister by checking for the output of a known existing 933 // directory lister by checking for the output of a known existing
928 // file. 934 // file.
929 const char sentinel_name[] = "filedir-sentinel"; 935 const char sentinel_name[] = "filedir-sentinel";
930 936
931 base::FilePath path; 937 base::FilePath path;
932 PathService::Get(base::DIR_SOURCE_ROOT, &path); 938 PathService::Get(base::DIR_SOURCE_ROOT, &path);
933 path = path.Append(FILE_PATH_LITERAL("net")); 939 path = path.Append(FILE_PATH_LITERAL("net"));
934 path = path.Append(FILE_PATH_LITERAL("data")); 940 path = path.Append(FILE_PATH_LITERAL("data"));
935 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 941 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
936 942
937 TestDelegate d; 943 TestDelegate d;
938 URLRequest req( 944 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
939 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_); 945 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL));
940 req.Start(); 946 req->Start();
941 base::RunLoop().Run(); 947 base::RunLoop().Run();
942 948
943 // Generate entry for the sentinel file. 949 // Generate entry for the sentinel file.
944 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); 950 base::FilePath sentinel_path = path.AppendASCII(sentinel_name);
945 base::File::Info info; 951 base::File::Info info;
946 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); 952 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info));
947 EXPECT_GT(info.size, 0); 953 EXPECT_GT(info.size, 0);
948 std::string sentinel_output = GetDirectoryListingEntry( 954 std::string sentinel_output = GetDirectoryListingEntry(
949 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), 955 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)),
950 std::string(sentinel_name), 956 std::string(sentinel_name),
951 false /* is_dir */, 957 false /* is_dir */,
952 info.size, 958 info.size,
953 info.last_modified); 959 info.last_modified);
954 960
955 ASSERT_LT(0, d.bytes_received()); 961 ASSERT_LT(0, d.bytes_received());
956 ASSERT_FALSE(d.request_failed()); 962 ASSERT_FALSE(d.request_failed());
957 ASSERT_TRUE(req.status().is_success()); 963 ASSERT_TRUE(req->status().is_success());
958 // Check for the entry generated for the "sentinel" file. 964 // Check for the entry generated for the "sentinel" file.
959 const std::string& data = d.data_received(); 965 const std::string& data = d.data_received();
960 ASSERT_NE(data.find(sentinel_output), std::string::npos); 966 ASSERT_NE(data.find(sentinel_output), std::string::npos);
961 } 967 }
962 968
963 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { 969 TEST_F(URLRequestTest, FileDirRedirectNoCrash) {
964 // There is an implicit redirect when loading a file path that matches a 970 // There is an implicit redirect when loading a file path that matches a
965 // directory and does not end with a slash. Ensure that following such 971 // directory and does not end with a slash. Ensure that following such
966 // redirects does not crash. See http://crbug.com/18686. 972 // redirects does not crash. See http://crbug.com/18686.
967 973
968 base::FilePath path; 974 base::FilePath path;
969 PathService::Get(base::DIR_SOURCE_ROOT, &path); 975 PathService::Get(base::DIR_SOURCE_ROOT, &path);
970 path = path.Append(FILE_PATH_LITERAL("net")); 976 path = path.Append(FILE_PATH_LITERAL("net"));
971 path = path.Append(FILE_PATH_LITERAL("data")); 977 path = path.Append(FILE_PATH_LITERAL("data"));
972 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 978 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
973 979
974 TestDelegate d; 980 TestDelegate d;
975 URLRequest req( 981 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
976 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_); 982 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL));
977 req.Start(); 983 req->Start();
978 base::RunLoop().Run(); 984 base::RunLoop().Run();
979 985
980 ASSERT_EQ(1, d.received_redirect_count()); 986 ASSERT_EQ(1, d.received_redirect_count());
981 ASSERT_LT(0, d.bytes_received()); 987 ASSERT_LT(0, d.bytes_received());
982 ASSERT_FALSE(d.request_failed()); 988 ASSERT_FALSE(d.request_failed());
983 ASSERT_TRUE(req.status().is_success()); 989 ASSERT_TRUE(req->status().is_success());
984 } 990 }
985 991
986 #if defined(OS_WIN) 992 #if defined(OS_WIN)
987 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. 993 // Don't accept the url "file:///" on windows. See http://crbug.com/1474.
988 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { 994 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) {
989 TestDelegate d; 995 TestDelegate d;
990 URLRequest req(GURL("file:///"), DEFAULT_PRIORITY, &d, &default_context_); 996 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
991 req.Start(); 997 GURL("file:///"), DEFAULT_PRIORITY, &d, NULL));
998 req->Start();
992 base::RunLoop().Run(); 999 base::RunLoop().Run();
993 1000
994 ASSERT_EQ(1, d.received_redirect_count()); 1001 ASSERT_EQ(1, d.received_redirect_count());
995 ASSERT_FALSE(req.status().is_success()); 1002 ASSERT_FALSE(req->status().is_success());
996 } 1003 }
997 #endif // defined(OS_WIN) 1004 #endif // defined(OS_WIN)
998 1005
999 #endif // !defined(DISABLE_FILE_SUPPORT) 1006 #endif // !defined(DISABLE_FILE_SUPPORT)
1000 1007
1001 TEST_F(URLRequestTest, InvalidUrlTest) { 1008 TEST_F(URLRequestTest, InvalidUrlTest) {
1002 TestDelegate d; 1009 TestDelegate d;
1003 { 1010 {
1004 URLRequest r(GURL("invalid url"), DEFAULT_PRIORITY, &d, &default_context_); 1011 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
1012 GURL("invalid url"), DEFAULT_PRIORITY, &d, NULL));
1005 1013
1006 r.Start(); 1014 r->Start();
1007 EXPECT_TRUE(r.is_pending()); 1015 EXPECT_TRUE(r->is_pending());
1008 1016
1009 base::RunLoop().Run(); 1017 base::RunLoop().Run();
1010 EXPECT_TRUE(d.request_failed()); 1018 EXPECT_TRUE(d.request_failed());
1011 } 1019 }
1012 } 1020 }
1013 1021
1014 #if defined(OS_WIN) 1022 #if defined(OS_WIN)
1015 TEST_F(URLRequestTest, ResolveShortcutTest) { 1023 TEST_F(URLRequestTest, ResolveShortcutTest) {
1016 base::FilePath app_path; 1024 base::FilePath app_path;
1017 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 1025 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
(...skipping 13 matching lines...) Expand all
1031 CLSCTX_INPROC_SERVER))); 1039 CLSCTX_INPROC_SERVER)));
1032 base::win::ScopedComPtr<IPersistFile> persist; 1040 base::win::ScopedComPtr<IPersistFile> persist;
1033 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); 1041 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive())));
1034 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); 1042 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str())));
1035 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); 1043 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest")));
1036 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); 1044 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE)));
1037 } 1045 }
1038 1046
1039 TestDelegate d; 1047 TestDelegate d;
1040 { 1048 {
1041 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), 1049 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
1042 DEFAULT_PRIORITY, 1050 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d,
1043 &d, 1051 NULL));
1044 &default_context_);
1045 1052
1046 r.Start(); 1053 r->Start();
1047 EXPECT_TRUE(r.is_pending()); 1054 EXPECT_TRUE(r->is_pending());
1048 1055
1049 base::RunLoop().Run(); 1056 base::RunLoop().Run();
1050 1057
1051 WIN32_FILE_ATTRIBUTE_DATA data; 1058 WIN32_FILE_ATTRIBUTE_DATA data;
1052 GetFileAttributesEx(app_path.value().c_str(), 1059 GetFileAttributesEx(app_path.value().c_str(),
1053 GetFileExInfoStandard, &data); 1060 GetFileExInfoStandard, &data);
1054 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, 1061 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ,
1055 FILE_SHARE_READ, NULL, OPEN_EXISTING, 1062 FILE_SHARE_READ, NULL, OPEN_EXISTING,
1056 FILE_ATTRIBUTE_NORMAL, NULL); 1063 FILE_ATTRIBUTE_NORMAL, NULL);
1057 EXPECT_NE(INVALID_HANDLE_VALUE, file); 1064 EXPECT_NE(INVALID_HANDLE_VALUE, file);
1058 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); 1065 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]);
1059 DWORD read_size; 1066 DWORD read_size;
1060 BOOL result; 1067 BOOL result;
1061 result = ReadFile(file, buffer.get(), data.nFileSizeLow, 1068 result = ReadFile(file, buffer.get(), data.nFileSizeLow,
1062 &read_size, NULL); 1069 &read_size, NULL);
1063 std::string content(buffer.get(), read_size); 1070 std::string content(buffer.get(), read_size);
1064 CloseHandle(file); 1071 CloseHandle(file);
1065 1072
1066 EXPECT_TRUE(!r.is_pending()); 1073 EXPECT_TRUE(!r->is_pending());
1067 EXPECT_EQ(1, d.received_redirect_count()); 1074 EXPECT_EQ(1, d.received_redirect_count());
1068 EXPECT_EQ(content, d.data_received()); 1075 EXPECT_EQ(content, d.data_received());
1069 } 1076 }
1070 1077
1071 // Clean the shortcut 1078 // Clean the shortcut
1072 DeleteFile(lnk_path.c_str()); 1079 DeleteFile(lnk_path.c_str());
1073 } 1080 }
1074 #endif // defined(OS_WIN) 1081 #endif // defined(OS_WIN)
1075 1082
1076 // Custom URLRequestJobs for use with interceptor tests 1083 // Custom URLRequestJobs for use with interceptor tests
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 1285
1279 TEST_F(URLRequestTest, Intercept) { 1286 TEST_F(URLRequestTest, Intercept) {
1280 TestInterceptor interceptor; 1287 TestInterceptor interceptor;
1281 1288
1282 // intercept the main request and respond with a simple response 1289 // intercept the main request and respond with a simple response
1283 interceptor.intercept_main_request_ = true; 1290 interceptor.intercept_main_request_ = true;
1284 interceptor.main_headers_ = TestInterceptor::ok_headers(); 1291 interceptor.main_headers_ = TestInterceptor::ok_headers();
1285 interceptor.main_data_ = TestInterceptor::ok_data(); 1292 interceptor.main_data_ = TestInterceptor::ok_data();
1286 1293
1287 TestDelegate d; 1294 TestDelegate d;
1288 URLRequest req(GURL("http://test_intercept/foo"), 1295 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1289 DEFAULT_PRIORITY, 1296 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1290 &d,
1291 &default_context_);
1292 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); 1297 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data();
1293 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); 1298 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data();
1294 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); 1299 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data();
1295 req.SetUserData(NULL, user_data0); 1300 req->SetUserData(NULL, user_data0);
1296 req.SetUserData(&user_data1, user_data1); 1301 req->SetUserData(&user_data1, user_data1);
1297 req.SetUserData(&user_data2, user_data2); 1302 req->SetUserData(&user_data2, user_data2);
1298 req.set_method("GET"); 1303 req->set_method("GET");
1299 req.Start(); 1304 req->Start();
1300 base::RunLoop().Run(); 1305 base::RunLoop().Run();
1301 1306
1302 // Make sure we can retrieve our specific user data 1307 // Make sure we can retrieve our specific user data
1303 EXPECT_EQ(user_data0, req.GetUserData(NULL)); 1308 EXPECT_EQ(user_data0, req->GetUserData(NULL));
1304 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); 1309 EXPECT_EQ(user_data1, req->GetUserData(&user_data1));
1305 EXPECT_EQ(user_data2, req.GetUserData(&user_data2)); 1310 EXPECT_EQ(user_data2, req->GetUserData(&user_data2));
1306 1311
1307 // Check the interceptor got called as expected 1312 // Check the interceptor got called as expected
1308 EXPECT_TRUE(interceptor.did_intercept_main_); 1313 EXPECT_TRUE(interceptor.did_intercept_main_);
1309 1314
1310 // Check we got one good response 1315 // Check we got one good response
1311 EXPECT_TRUE(req.status().is_success()); 1316 EXPECT_TRUE(req->status().is_success());
1312 EXPECT_EQ(200, req.response_headers()->response_code()); 1317 EXPECT_EQ(200, req->response_headers()->response_code());
1313 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1318 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1314 EXPECT_EQ(1, d.response_started_count()); 1319 EXPECT_EQ(1, d.response_started_count());
1315 EXPECT_EQ(0, d.received_redirect_count()); 1320 EXPECT_EQ(0, d.received_redirect_count());
1316 } 1321 }
1317 1322
1318 TEST_F(URLRequestTest, InterceptRedirect) { 1323 TEST_F(URLRequestTest, InterceptRedirect) {
1319 TestInterceptor interceptor; 1324 TestInterceptor interceptor;
1320 1325
1321 // intercept the main request and respond with a redirect 1326 // intercept the main request and respond with a redirect
1322 interceptor.intercept_main_request_ = true; 1327 interceptor.intercept_main_request_ = true;
1323 interceptor.main_headers_ = TestInterceptor::redirect_headers(); 1328 interceptor.main_headers_ = TestInterceptor::redirect_headers();
1324 interceptor.main_data_ = TestInterceptor::redirect_data(); 1329 interceptor.main_data_ = TestInterceptor::redirect_data();
1325 1330
1326 // intercept that redirect and respond a final OK response 1331 // intercept that redirect and respond a final OK response
1327 interceptor.intercept_redirect_ = true; 1332 interceptor.intercept_redirect_ = true;
1328 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); 1333 interceptor.redirect_headers_ = TestInterceptor::ok_headers();
1329 interceptor.redirect_data_ = TestInterceptor::ok_data(); 1334 interceptor.redirect_data_ = TestInterceptor::ok_data();
1330 1335
1331 TestDelegate d; 1336 TestDelegate d;
1332 URLRequest req(GURL("http://test_intercept/foo"), 1337 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1333 DEFAULT_PRIORITY, 1338 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1334 &d, 1339 req->set_method("GET");
1335 &default_context_); 1340 req->Start();
1336 req.set_method("GET");
1337 req.Start();
1338 base::RunLoop().Run(); 1341 base::RunLoop().Run();
1339 1342
1340 // Check the interceptor got called as expected 1343 // Check the interceptor got called as expected
1341 EXPECT_TRUE(interceptor.did_intercept_main_); 1344 EXPECT_TRUE(interceptor.did_intercept_main_);
1342 EXPECT_TRUE(interceptor.did_intercept_redirect_); 1345 EXPECT_TRUE(interceptor.did_intercept_redirect_);
1343 1346
1344 // Check we got one good response 1347 // Check we got one good response
1345 EXPECT_TRUE(req.status().is_success()); 1348 EXPECT_TRUE(req->status().is_success());
1346 if (req.status().is_success()) { 1349 if (req->status().is_success()) {
1347 EXPECT_EQ(200, req.response_headers()->response_code()); 1350 EXPECT_EQ(200, req->response_headers()->response_code());
1348 } 1351 }
1349 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1352 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1350 EXPECT_EQ(1, d.response_started_count()); 1353 EXPECT_EQ(1, d.response_started_count());
1351 EXPECT_EQ(0, d.received_redirect_count()); 1354 EXPECT_EQ(0, d.received_redirect_count());
1352 } 1355 }
1353 1356
1354 TEST_F(URLRequestTest, InterceptServerError) { 1357 TEST_F(URLRequestTest, InterceptServerError) {
1355 TestInterceptor interceptor; 1358 TestInterceptor interceptor;
1356 1359
1357 // intercept the main request to generate a server error response 1360 // intercept the main request to generate a server error response
1358 interceptor.intercept_main_request_ = true; 1361 interceptor.intercept_main_request_ = true;
1359 interceptor.main_headers_ = TestInterceptor::error_headers(); 1362 interceptor.main_headers_ = TestInterceptor::error_headers();
1360 interceptor.main_data_ = TestInterceptor::error_data(); 1363 interceptor.main_data_ = TestInterceptor::error_data();
1361 1364
1362 // intercept that error and respond with an OK response 1365 // intercept that error and respond with an OK response
1363 interceptor.intercept_final_response_ = true; 1366 interceptor.intercept_final_response_ = true;
1364 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1367 interceptor.final_headers_ = TestInterceptor::ok_headers();
1365 interceptor.final_data_ = TestInterceptor::ok_data(); 1368 interceptor.final_data_ = TestInterceptor::ok_data();
1366 1369
1367 TestDelegate d; 1370 TestDelegate d;
1368 URLRequest req(GURL("http://test_intercept/foo"), 1371 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1369 DEFAULT_PRIORITY, 1372 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1370 &d, 1373 req->set_method("GET");
1371 &default_context_); 1374 req->Start();
1372 req.set_method("GET");
1373 req.Start();
1374 base::RunLoop().Run(); 1375 base::RunLoop().Run();
1375 1376
1376 // Check the interceptor got called as expected 1377 // Check the interceptor got called as expected
1377 EXPECT_TRUE(interceptor.did_intercept_main_); 1378 EXPECT_TRUE(interceptor.did_intercept_main_);
1378 EXPECT_TRUE(interceptor.did_intercept_final_); 1379 EXPECT_TRUE(interceptor.did_intercept_final_);
1379 1380
1380 // Check we got one good response 1381 // Check we got one good response
1381 EXPECT_TRUE(req.status().is_success()); 1382 EXPECT_TRUE(req->status().is_success());
1382 EXPECT_EQ(200, req.response_headers()->response_code()); 1383 EXPECT_EQ(200, req->response_headers()->response_code());
1383 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1384 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1384 EXPECT_EQ(1, d.response_started_count()); 1385 EXPECT_EQ(1, d.response_started_count());
1385 EXPECT_EQ(0, d.received_redirect_count()); 1386 EXPECT_EQ(0, d.received_redirect_count());
1386 } 1387 }
1387 1388
1388 TEST_F(URLRequestTest, InterceptNetworkError) { 1389 TEST_F(URLRequestTest, InterceptNetworkError) {
1389 TestInterceptor interceptor; 1390 TestInterceptor interceptor;
1390 1391
1391 // intercept the main request to simulate a network error 1392 // intercept the main request to simulate a network error
1392 interceptor.simulate_main_network_error_ = true; 1393 interceptor.simulate_main_network_error_ = true;
1393 1394
1394 // intercept that error and respond with an OK response 1395 // intercept that error and respond with an OK response
1395 interceptor.intercept_final_response_ = true; 1396 interceptor.intercept_final_response_ = true;
1396 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1397 interceptor.final_headers_ = TestInterceptor::ok_headers();
1397 interceptor.final_data_ = TestInterceptor::ok_data(); 1398 interceptor.final_data_ = TestInterceptor::ok_data();
1398 1399
1399 TestDelegate d; 1400 TestDelegate d;
1400 URLRequest req(GURL("http://test_intercept/foo"), 1401 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1401 DEFAULT_PRIORITY, 1402 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1402 &d, 1403 req->set_method("GET");
1403 &default_context_); 1404 req->Start();
1404 req.set_method("GET");
1405 req.Start();
1406 base::RunLoop().Run(); 1405 base::RunLoop().Run();
1407 1406
1408 // Check the interceptor got called as expected 1407 // Check the interceptor got called as expected
1409 EXPECT_TRUE(interceptor.did_simulate_error_main_); 1408 EXPECT_TRUE(interceptor.did_simulate_error_main_);
1410 EXPECT_TRUE(interceptor.did_intercept_final_); 1409 EXPECT_TRUE(interceptor.did_intercept_final_);
1411 1410
1412 // Check we received one good response 1411 // Check we received one good response
1413 EXPECT_TRUE(req.status().is_success()); 1412 EXPECT_TRUE(req->status().is_success());
1414 EXPECT_EQ(200, req.response_headers()->response_code()); 1413 EXPECT_EQ(200, req->response_headers()->response_code());
1415 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1414 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1416 EXPECT_EQ(1, d.response_started_count()); 1415 EXPECT_EQ(1, d.response_started_count());
1417 EXPECT_EQ(0, d.received_redirect_count()); 1416 EXPECT_EQ(0, d.received_redirect_count());
1418 } 1417 }
1419 1418
1420 TEST_F(URLRequestTest, InterceptRestartRequired) { 1419 TEST_F(URLRequestTest, InterceptRestartRequired) {
1421 TestInterceptor interceptor; 1420 TestInterceptor interceptor;
1422 1421
1423 // restart the main request 1422 // restart the main request
1424 interceptor.restart_main_request_ = true; 1423 interceptor.restart_main_request_ = true;
1425 1424
1426 // then intercept the new main request and respond with an OK response 1425 // then intercept the new main request and respond with an OK response
1427 interceptor.intercept_main_request_ = true; 1426 interceptor.intercept_main_request_ = true;
1428 interceptor.main_headers_ = TestInterceptor::ok_headers(); 1427 interceptor.main_headers_ = TestInterceptor::ok_headers();
1429 interceptor.main_data_ = TestInterceptor::ok_data(); 1428 interceptor.main_data_ = TestInterceptor::ok_data();
1430 1429
1431 TestDelegate d; 1430 TestDelegate d;
1432 URLRequest req(GURL("http://test_intercept/foo"), 1431 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1433 DEFAULT_PRIORITY, 1432 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1434 &d, 1433 req->set_method("GET");
1435 &default_context_); 1434 req->Start();
1436 req.set_method("GET");
1437 req.Start();
1438 base::RunLoop().Run(); 1435 base::RunLoop().Run();
1439 1436
1440 // Check the interceptor got called as expected 1437 // Check the interceptor got called as expected
1441 EXPECT_TRUE(interceptor.did_restart_main_); 1438 EXPECT_TRUE(interceptor.did_restart_main_);
1442 EXPECT_TRUE(interceptor.did_intercept_main_); 1439 EXPECT_TRUE(interceptor.did_intercept_main_);
1443 1440
1444 // Check we received one good response 1441 // Check we received one good response
1445 EXPECT_TRUE(req.status().is_success()); 1442 EXPECT_TRUE(req->status().is_success());
1446 if (req.status().is_success()) { 1443 if (req->status().is_success()) {
1447 EXPECT_EQ(200, req.response_headers()->response_code()); 1444 EXPECT_EQ(200, req->response_headers()->response_code());
1448 } 1445 }
1449 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1446 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1450 EXPECT_EQ(1, d.response_started_count()); 1447 EXPECT_EQ(1, d.response_started_count());
1451 EXPECT_EQ(0, d.received_redirect_count()); 1448 EXPECT_EQ(0, d.received_redirect_count());
1452 } 1449 }
1453 1450
1454 TEST_F(URLRequestTest, InterceptRespectsCancelMain) { 1451 TEST_F(URLRequestTest, InterceptRespectsCancelMain) {
1455 TestInterceptor interceptor; 1452 TestInterceptor interceptor;
1456 1453
1457 // intercept the main request and cancel from within the restarted job 1454 // intercept the main request and cancel from within the restarted job
1458 interceptor.cancel_main_request_ = true; 1455 interceptor.cancel_main_request_ = true;
1459 1456
1460 // setup to intercept final response and override it with an OK response 1457 // setup to intercept final response and override it with an OK response
1461 interceptor.intercept_final_response_ = true; 1458 interceptor.intercept_final_response_ = true;
1462 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1459 interceptor.final_headers_ = TestInterceptor::ok_headers();
1463 interceptor.final_data_ = TestInterceptor::ok_data(); 1460 interceptor.final_data_ = TestInterceptor::ok_data();
1464 1461
1465 TestDelegate d; 1462 TestDelegate d;
1466 URLRequest req(GURL("http://test_intercept/foo"), 1463 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1467 DEFAULT_PRIORITY, 1464 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1468 &d, 1465 req->set_method("GET");
1469 &default_context_); 1466 req->Start();
1470 req.set_method("GET");
1471 req.Start();
1472 base::RunLoop().Run(); 1467 base::RunLoop().Run();
1473 1468
1474 // Check the interceptor got called as expected 1469 // Check the interceptor got called as expected
1475 EXPECT_TRUE(interceptor.did_cancel_main_); 1470 EXPECT_TRUE(interceptor.did_cancel_main_);
1476 EXPECT_FALSE(interceptor.did_intercept_final_); 1471 EXPECT_FALSE(interceptor.did_intercept_final_);
1477 1472
1478 // Check we see a canceled request 1473 // Check we see a canceled request
1479 EXPECT_FALSE(req.status().is_success()); 1474 EXPECT_FALSE(req->status().is_success());
1480 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1475 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1481 } 1476 }
1482 1477
1483 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { 1478 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) {
1484 TestInterceptor interceptor; 1479 TestInterceptor interceptor;
1485 1480
1486 // intercept the main request and respond with a redirect 1481 // intercept the main request and respond with a redirect
1487 interceptor.intercept_main_request_ = true; 1482 interceptor.intercept_main_request_ = true;
1488 interceptor.main_headers_ = TestInterceptor::redirect_headers(); 1483 interceptor.main_headers_ = TestInterceptor::redirect_headers();
1489 interceptor.main_data_ = TestInterceptor::redirect_data(); 1484 interceptor.main_data_ = TestInterceptor::redirect_data();
1490 1485
1491 // intercept the redirect and cancel from within that job 1486 // intercept the redirect and cancel from within that job
1492 interceptor.cancel_redirect_request_ = true; 1487 interceptor.cancel_redirect_request_ = true;
1493 1488
1494 // setup to intercept final response and override it with an OK response 1489 // setup to intercept final response and override it with an OK response
1495 interceptor.intercept_final_response_ = true; 1490 interceptor.intercept_final_response_ = true;
1496 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1491 interceptor.final_headers_ = TestInterceptor::ok_headers();
1497 interceptor.final_data_ = TestInterceptor::ok_data(); 1492 interceptor.final_data_ = TestInterceptor::ok_data();
1498 1493
1499 TestDelegate d; 1494 TestDelegate d;
1500 URLRequest req(GURL("http://test_intercept/foo"), 1495 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1501 DEFAULT_PRIORITY, 1496 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1502 &d, 1497 req->set_method("GET");
1503 &default_context_); 1498 req->Start();
1504 req.set_method("GET");
1505 req.Start();
1506 base::RunLoop().Run(); 1499 base::RunLoop().Run();
1507 1500
1508 // Check the interceptor got called as expected 1501 // Check the interceptor got called as expected
1509 EXPECT_TRUE(interceptor.did_intercept_main_); 1502 EXPECT_TRUE(interceptor.did_intercept_main_);
1510 EXPECT_TRUE(interceptor.did_cancel_redirect_); 1503 EXPECT_TRUE(interceptor.did_cancel_redirect_);
1511 EXPECT_FALSE(interceptor.did_intercept_final_); 1504 EXPECT_FALSE(interceptor.did_intercept_final_);
1512 1505
1513 // Check we see a canceled request 1506 // Check we see a canceled request
1514 EXPECT_FALSE(req.status().is_success()); 1507 EXPECT_FALSE(req->status().is_success());
1515 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1516 } 1509 }
1517 1510
1518 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { 1511 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) {
1519 TestInterceptor interceptor; 1512 TestInterceptor interceptor;
1520 1513
1521 // intercept the main request to simulate a network error 1514 // intercept the main request to simulate a network error
1522 interceptor.simulate_main_network_error_ = true; 1515 interceptor.simulate_main_network_error_ = true;
1523 1516
1524 // setup to intercept final response and cancel from within that job 1517 // setup to intercept final response and cancel from within that job
1525 interceptor.cancel_final_request_ = true; 1518 interceptor.cancel_final_request_ = true;
1526 1519
1527 TestDelegate d; 1520 TestDelegate d;
1528 URLRequest req(GURL("http://test_intercept/foo"), 1521 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1529 DEFAULT_PRIORITY, 1522 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1530 &d, 1523 req->set_method("GET");
1531 &default_context_); 1524 req->Start();
1532 req.set_method("GET");
1533 req.Start();
1534 base::RunLoop().Run(); 1525 base::RunLoop().Run();
1535 1526
1536 // Check the interceptor got called as expected 1527 // Check the interceptor got called as expected
1537 EXPECT_TRUE(interceptor.did_simulate_error_main_); 1528 EXPECT_TRUE(interceptor.did_simulate_error_main_);
1538 EXPECT_TRUE(interceptor.did_cancel_final_); 1529 EXPECT_TRUE(interceptor.did_cancel_final_);
1539 1530
1540 // Check we see a canceled request 1531 // Check we see a canceled request
1541 EXPECT_FALSE(req.status().is_success()); 1532 EXPECT_FALSE(req->status().is_success());
1542 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1533 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1543 } 1534 }
1544 1535
1545 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { 1536 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
1546 TestInterceptor interceptor; 1537 TestInterceptor interceptor;
1547 1538
1548 // intercept the main request and cancel then restart from within that job 1539 // intercept the main request and cancel then restart from within that job
1549 interceptor.cancel_then_restart_main_request_ = true; 1540 interceptor.cancel_then_restart_main_request_ = true;
1550 1541
1551 // setup to intercept final response and override it with an OK response 1542 // setup to intercept final response and override it with an OK response
1552 interceptor.intercept_final_response_ = true; 1543 interceptor.intercept_final_response_ = true;
1553 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1544 interceptor.final_headers_ = TestInterceptor::ok_headers();
1554 interceptor.final_data_ = TestInterceptor::ok_data(); 1545 interceptor.final_data_ = TestInterceptor::ok_data();
1555 1546
1556 TestDelegate d; 1547 TestDelegate d;
1557 URLRequest req(GURL("http://test_intercept/foo"), 1548 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1558 DEFAULT_PRIORITY, 1549 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1559 &d, 1550 req->set_method("GET");
1560 &default_context_); 1551 req->Start();
1561 req.set_method("GET");
1562 req.Start();
1563 base::RunLoop().Run(); 1552 base::RunLoop().Run();
1564 1553
1565 // Check the interceptor got called as expected 1554 // Check the interceptor got called as expected
1566 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 1555 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
1567 EXPECT_FALSE(interceptor.did_intercept_final_); 1556 EXPECT_FALSE(interceptor.did_intercept_final_);
1568 1557
1569 // Check we see a canceled request 1558 // Check we see a canceled request
1570 EXPECT_FALSE(req.status().is_success()); 1559 EXPECT_FALSE(req->status().is_success());
1571 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1560 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1572 } 1561 }
1573 1562
1574 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, 1563 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing,
1575 URLRequestContext* context) { 1564 URLRequestContext* context) {
1576 TestInterceptor interceptor; 1565 TestInterceptor interceptor;
1577 interceptor.intercept_main_request_ = true; 1566 interceptor.intercept_main_request_ = true;
1578 interceptor.main_request_load_timing_info_ = job_load_timing; 1567 interceptor.main_request_load_timing_info_ = job_load_timing;
1579 TestDelegate d; 1568 TestDelegate d;
1580 URLRequest req( 1569 scoped_ptr<URLRequest> req(context->CreateRequest(
1581 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, context); 1570 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1582 req.Start(); 1571 req->Start();
1583 base::RunLoop().Run(); 1572 base::RunLoop().Run();
1584 1573
1585 LoadTimingInfo resulting_load_timing; 1574 LoadTimingInfo resulting_load_timing;
1586 req.GetLoadTimingInfo(&resulting_load_timing); 1575 req->GetLoadTimingInfo(&resulting_load_timing);
1587 1576
1588 // None of these should be modified by the URLRequest. 1577 // None of these should be modified by the URLRequest.
1589 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); 1578 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused);
1590 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); 1579 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id);
1591 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); 1580 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start);
1592 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); 1581 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end);
1593 EXPECT_EQ(job_load_timing.receive_headers_end, 1582 EXPECT_EQ(job_load_timing.receive_headers_end,
1594 resulting_load_timing.receive_headers_end); 1583 resulting_load_timing.receive_headers_end);
1595 1584
1596 return resulting_load_timing; 1585 return resulting_load_timing;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 // Check that a failure to connect to the proxy is reported to the network 1837 // Check that a failure to connect to the proxy is reported to the network
1849 // delegate. 1838 // delegate.
1850 TEST_F(URLRequestTest, NetworkDelegateProxyError) { 1839 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
1851 MockHostResolver host_resolver; 1840 MockHostResolver host_resolver;
1852 host_resolver.rules()->AddSimulatedFailure("*"); 1841 host_resolver.rules()->AddSimulatedFailure("*");
1853 1842
1854 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 1843 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
1855 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); 1844 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate);
1856 1845
1857 TestDelegate d; 1846 TestDelegate d;
1858 URLRequest req(GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context); 1847 scoped_ptr<URLRequest> req(context.CreateRequest(
1859 req.set_method("GET"); 1848 GURL("http://example.com"), DEFAULT_PRIORITY, &d, NULL));
1849 req->set_method("GET");
1860 1850
1861 req.Start(); 1851 req->Start();
1862 base::RunLoop().Run(); 1852 base::RunLoop().Run();
1863 1853
1864 // Check we see a failed request. 1854 // Check we see a failed request.
1865 EXPECT_FALSE(req.status().is_success()); 1855 EXPECT_FALSE(req->status().is_success());
1866 // The proxy server is not set before failure. 1856 // The proxy server is not set before failure.
1867 EXPECT_TRUE(req.proxy_server().IsEmpty()); 1857 EXPECT_TRUE(req->proxy_server().IsEmpty());
1868 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 1858 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
1869 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); 1859 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req->status().error());
1870 1860
1871 EXPECT_EQ(1, network_delegate.error_count()); 1861 EXPECT_EQ(1, network_delegate.error_count());
1872 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); 1862 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error());
1873 EXPECT_EQ(1, network_delegate.completed_requests()); 1863 EXPECT_EQ(1, network_delegate.completed_requests());
1874 } 1864 }
1875 1865
1876 // Make sure that NetworkDelegate::NotifyCompleted is called if 1866 // Make sure that NetworkDelegate::NotifyCompleted is called if
1877 // content is empty. 1867 // content is empty.
1878 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { 1868 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
1879 TestDelegate d; 1869 TestDelegate d;
1880 URLRequest req(GURL("data:,"), DEFAULT_PRIORITY, &d, &default_context_); 1870 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1881 req.Start(); 1871 GURL("data:,"), DEFAULT_PRIORITY, &d, NULL));
1872 req->Start();
1882 base::RunLoop().Run(); 1873 base::RunLoop().Run();
1883 EXPECT_EQ("", d.data_received()); 1874 EXPECT_EQ("", d.data_received());
1884 EXPECT_EQ(1, default_network_delegate_.completed_requests()); 1875 EXPECT_EQ(1, default_network_delegate_.completed_requests());
1885 } 1876 }
1886 1877
1887 // Make sure that SetPriority actually sets the URLRequest's priority 1878 // Make sure that SetPriority actually sets the URLRequest's priority
1888 // correctly, both before and after start. 1879 // correctly, both before and after start.
1889 TEST_F(URLRequestTest, SetPriorityBasic) { 1880 TEST_F(URLRequestTest, SetPriorityBasic) {
1890 TestDelegate d; 1881 TestDelegate d;
1891 URLRequest req(GURL("http://test_intercept/foo"), 1882 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1892 DEFAULT_PRIORITY, 1883 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1893 &d, 1884 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
1894 &default_context_);
1895 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
1896 1885
1897 req.SetPriority(LOW); 1886 req->SetPriority(LOW);
1898 EXPECT_EQ(LOW, req.priority()); 1887 EXPECT_EQ(LOW, req->priority());
1899 1888
1900 req.Start(); 1889 req->Start();
1901 EXPECT_EQ(LOW, req.priority()); 1890 EXPECT_EQ(LOW, req->priority());
1902 1891
1903 req.SetPriority(MEDIUM); 1892 req->SetPriority(MEDIUM);
1904 EXPECT_EQ(MEDIUM, req.priority()); 1893 EXPECT_EQ(MEDIUM, req->priority());
1905 } 1894 }
1906 1895
1907 // Make sure that URLRequest calls SetPriority on a job before calling 1896 // Make sure that URLRequest calls SetPriority on a job before calling
1908 // Start on it. 1897 // Start on it.
1909 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { 1898 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) {
1910 TestDelegate d; 1899 TestDelegate d;
1911 URLRequest req(GURL("http://test_intercept/foo"), 1900 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1912 DEFAULT_PRIORITY, 1901 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1913 &d, 1902 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
1914 &default_context_);
1915 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
1916 1903
1917 scoped_refptr<URLRequestTestJob> job = 1904 scoped_refptr<URLRequestTestJob> job =
1918 new URLRequestTestJob(&req, &default_network_delegate_); 1905 new URLRequestTestJob(req.get(), &default_network_delegate_);
1919 AddTestInterceptor()->set_main_intercept_job(job.get()); 1906 AddTestInterceptor()->set_main_intercept_job(job.get());
1920 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 1907 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
1921 1908
1922 req.SetPriority(LOW); 1909 req->SetPriority(LOW);
1923 1910
1924 req.Start(); 1911 req->Start();
1925 EXPECT_EQ(LOW, job->priority()); 1912 EXPECT_EQ(LOW, job->priority());
1926 } 1913 }
1927 1914
1928 // Make sure that URLRequest passes on its priority updates to its 1915 // Make sure that URLRequest passes on its priority updates to its
1929 // job. 1916 // job.
1930 TEST_F(URLRequestTest, SetJobPriority) { 1917 TEST_F(URLRequestTest, SetJobPriority) {
1931 TestDelegate d; 1918 TestDelegate d;
1932 URLRequest req(GURL("http://test_intercept/foo"), 1919 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1933 DEFAULT_PRIORITY, 1920 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL));
1934 &d,
1935 &default_context_);
1936 1921
1937 scoped_refptr<URLRequestTestJob> job = 1922 scoped_refptr<URLRequestTestJob> job =
1938 new URLRequestTestJob(&req, &default_network_delegate_); 1923 new URLRequestTestJob(req.get(), &default_network_delegate_);
1939 AddTestInterceptor()->set_main_intercept_job(job.get()); 1924 AddTestInterceptor()->set_main_intercept_job(job.get());
1940 1925
1941 req.SetPriority(LOW); 1926 req->SetPriority(LOW);
1942 req.Start(); 1927 req->Start();
1943 EXPECT_EQ(LOW, job->priority()); 1928 EXPECT_EQ(LOW, job->priority());
1944 1929
1945 req.SetPriority(MEDIUM); 1930 req->SetPriority(MEDIUM);
1946 EXPECT_EQ(MEDIUM, req.priority()); 1931 EXPECT_EQ(MEDIUM, req->priority());
1947 EXPECT_EQ(MEDIUM, job->priority()); 1932 EXPECT_EQ(MEDIUM, job->priority());
1948 } 1933 }
1949 1934
1950 // Setting the IGNORE_LIMITS load flag should be okay if the priority 1935 // Setting the IGNORE_LIMITS load flag should be okay if the priority
1951 // is MAXIMUM_PRIORITY. 1936 // is MAXIMUM_PRIORITY.
1952 TEST_F(URLRequestTest, PriorityIgnoreLimits) { 1937 TEST_F(URLRequestTest, PriorityIgnoreLimits) {
1953 TestDelegate d; 1938 TestDelegate d;
1954 URLRequest req(GURL("http://test_intercept/foo"), 1939 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1955 MAXIMUM_PRIORITY, 1940 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d, NULL));
1956 &d, 1941 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
1957 &default_context_);
1958 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority());
1959 1942
1960 scoped_refptr<URLRequestTestJob> job = 1943 scoped_refptr<URLRequestTestJob> job =
1961 new URLRequestTestJob(&req, &default_network_delegate_); 1944 new URLRequestTestJob(req.get(), &default_network_delegate_);
1962 AddTestInterceptor()->set_main_intercept_job(job.get()); 1945 AddTestInterceptor()->set_main_intercept_job(job.get());
1963 1946
1964 req.SetLoadFlags(LOAD_IGNORE_LIMITS); 1947 req->SetLoadFlags(LOAD_IGNORE_LIMITS);
1965 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); 1948 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
1966 1949
1967 req.SetPriority(MAXIMUM_PRIORITY); 1950 req->SetPriority(MAXIMUM_PRIORITY);
1968 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); 1951 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
1969 1952
1970 req.Start(); 1953 req->Start();
1971 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); 1954 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
1972 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); 1955 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority());
1973 } 1956 }
1974 1957
1975 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). 1958 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666).
1976 #if !defined(OS_IOS) 1959 #if !defined(OS_IOS)
1977 // A subclass of SpawnedTestServer that uses a statically-configured hostname. 1960 // A subclass of SpawnedTestServer that uses a statically-configured hostname.
1978 // This is to work around mysterious failures in chrome_frame_net_tests. See: 1961 // This is to work around mysterious failures in chrome_frame_net_tests. See:
1979 // http://crbug.com/114369 1962 // http://crbug.com/114369
1980 // TODO(erikwright): remove or update as needed; see http://crbug.com/334634. 1963 // TODO(erikwright): remove or update as needed; see http://crbug.com/334634.
1981 class LocalHttpTestServer : public SpawnedTestServer { 1964 class LocalHttpTestServer : public SpawnedTestServer {
(...skipping 16 matching lines...) Expand all
1998 scoped_refptr<DelayedCookieMonster> delayed_cm = 1981 scoped_refptr<DelayedCookieMonster> delayed_cm =
1999 new DelayedCookieMonster(); 1982 new DelayedCookieMonster();
2000 scoped_refptr<CookieStore> cookie_store = delayed_cm; 1983 scoped_refptr<CookieStore> cookie_store = delayed_cm;
2001 context.set_cookie_store(delayed_cm.get()); 1984 context.set_cookie_store(delayed_cm.get());
2002 1985
2003 // Set up a cookie. 1986 // Set up a cookie.
2004 { 1987 {
2005 TestNetworkDelegate network_delegate; 1988 TestNetworkDelegate network_delegate;
2006 context.set_network_delegate(&network_delegate); 1989 context.set_network_delegate(&network_delegate);
2007 TestDelegate d; 1990 TestDelegate d;
2008 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 1991 scoped_ptr<URLRequest> req(context.CreateRequest(
2009 DEFAULT_PRIORITY, 1992 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2010 &d, 1993 &d, NULL));
2011 &context); 1994 req->Start();
2012 req.Start();
2013 base::RunLoop().Run(); 1995 base::RunLoop().Run();
2014 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1996 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2015 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1997 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2016 EXPECT_EQ(1, network_delegate.set_cookie_count()); 1998 EXPECT_EQ(1, network_delegate.set_cookie_count());
2017 } 1999 }
2018 2000
2019 // Verify that the cookie is set. 2001 // Verify that the cookie is set.
2020 { 2002 {
2021 TestNetworkDelegate network_delegate; 2003 TestNetworkDelegate network_delegate;
2022 context.set_network_delegate(&network_delegate); 2004 context.set_network_delegate(&network_delegate);
2023 TestDelegate d; 2005 TestDelegate d;
2024 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2006 scoped_ptr<URLRequest> req(context.CreateRequest(
2025 DEFAULT_PRIORITY, 2007 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2026 &d, 2008 req->Start();
2027 &context);
2028 req.Start();
2029 base::RunLoop().Run(); 2009 base::RunLoop().Run();
2030 2010
2031 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2011 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2032 != std::string::npos); 2012 != std::string::npos);
2033 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2013 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2034 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2014 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2035 } 2015 }
2036 } 2016 }
2037 2017
2038 TEST_F(URLRequestTest, DoNotSendCookies) { 2018 TEST_F(URLRequestTest, DoNotSendCookies) {
2039 LocalHttpTestServer test_server; 2019 LocalHttpTestServer test_server;
2040 ASSERT_TRUE(test_server.Start()); 2020 ASSERT_TRUE(test_server.Start());
2041 2021
2042 // Set up a cookie. 2022 // Set up a cookie.
2043 { 2023 {
2044 TestNetworkDelegate network_delegate; 2024 TestNetworkDelegate network_delegate;
2045 default_context_.set_network_delegate(&network_delegate); 2025 default_context_.set_network_delegate(&network_delegate);
2046 TestDelegate d; 2026 TestDelegate d;
2047 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 2027 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2048 DEFAULT_PRIORITY, 2028 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2049 &d, 2029 &d, NULL));
2050 &default_context_); 2030 req->Start();
2051 req.Start();
2052 base::RunLoop().Run(); 2031 base::RunLoop().Run();
2053 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2032 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2054 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2033 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2055 } 2034 }
2056 2035
2057 // Verify that the cookie is set. 2036 // Verify that the cookie is set.
2058 { 2037 {
2059 TestNetworkDelegate network_delegate; 2038 TestNetworkDelegate network_delegate;
2060 default_context_.set_network_delegate(&network_delegate); 2039 default_context_.set_network_delegate(&network_delegate);
2061 TestDelegate d; 2040 TestDelegate d;
2062 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2041 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2063 DEFAULT_PRIORITY, 2042 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2064 &d, 2043 req->Start();
2065 &default_context_);
2066 req.Start();
2067 base::RunLoop().Run(); 2044 base::RunLoop().Run();
2068 2045
2069 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2046 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2070 != std::string::npos); 2047 != std::string::npos);
2071 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2048 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2072 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2049 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2073 } 2050 }
2074 2051
2075 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. 2052 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set.
2076 { 2053 {
2077 TestNetworkDelegate network_delegate; 2054 TestNetworkDelegate network_delegate;
2078 default_context_.set_network_delegate(&network_delegate); 2055 default_context_.set_network_delegate(&network_delegate);
2079 TestDelegate d; 2056 TestDelegate d;
2080 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2057 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2081 DEFAULT_PRIORITY, 2058 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2082 &d, 2059 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES);
2083 &default_context_); 2060 req->Start();
2084 req.SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES);
2085 req.Start();
2086 base::RunLoop().Run(); 2061 base::RunLoop().Run();
2087 2062
2088 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2063 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2089 == std::string::npos); 2064 == std::string::npos);
2090 2065
2091 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 2066 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
2092 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2067 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2093 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2068 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2094 } 2069 }
2095 } 2070 }
2096 2071
2097 TEST_F(URLRequestTest, DoNotSaveCookies) { 2072 TEST_F(URLRequestTest, DoNotSaveCookies) {
2098 LocalHttpTestServer test_server; 2073 LocalHttpTestServer test_server;
2099 ASSERT_TRUE(test_server.Start()); 2074 ASSERT_TRUE(test_server.Start());
2100 2075
2101 // Set up a cookie. 2076 // Set up a cookie.
2102 { 2077 {
2103 TestNetworkDelegate network_delegate; 2078 TestNetworkDelegate network_delegate;
2104 default_context_.set_network_delegate(&network_delegate); 2079 default_context_.set_network_delegate(&network_delegate);
2105 TestDelegate d; 2080 TestDelegate d;
2106 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2081 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2107 DEFAULT_PRIORITY, 2082 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2108 &d, 2083 &d, NULL));
2109 &default_context_); 2084 req->Start();
2110 req.Start();
2111 base::RunLoop().Run(); 2085 base::RunLoop().Run();
2112 2086
2113 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2087 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2114 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2088 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2115 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2089 EXPECT_EQ(1, network_delegate.set_cookie_count());
2116 } 2090 }
2117 2091
2118 // Try to set-up another cookie and update the previous cookie. 2092 // Try to set-up another cookie and update the previous cookie.
2119 { 2093 {
2120 TestNetworkDelegate network_delegate; 2094 TestNetworkDelegate network_delegate;
2121 default_context_.set_network_delegate(&network_delegate); 2095 default_context_.set_network_delegate(&network_delegate);
2122 TestDelegate d; 2096 TestDelegate d;
2123 URLRequest req( 2097 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2124 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2098 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2125 DEFAULT_PRIORITY, 2099 DEFAULT_PRIORITY, &d, NULL));
2126 &d, 2100 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES);
2127 &default_context_); 2101 req->Start();
2128 req.SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES);
2129 req.Start();
2130 2102
2131 base::RunLoop().Run(); 2103 base::RunLoop().Run();
2132 2104
2133 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. 2105 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie.
2134 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2106 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2135 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2107 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2136 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2108 EXPECT_EQ(0, network_delegate.set_cookie_count());
2137 } 2109 }
2138 2110
2139 // Verify the cookies weren't saved or updated. 2111 // Verify the cookies weren't saved or updated.
2140 { 2112 {
2141 TestNetworkDelegate network_delegate; 2113 TestNetworkDelegate network_delegate;
2142 default_context_.set_network_delegate(&network_delegate); 2114 default_context_.set_network_delegate(&network_delegate);
2143 TestDelegate d; 2115 TestDelegate d;
2144 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2116 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2145 DEFAULT_PRIORITY, 2117 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2146 &d, 2118 req->Start();
2147 &default_context_);
2148 req.Start();
2149 base::RunLoop().Run(); 2119 base::RunLoop().Run();
2150 2120
2151 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2121 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2152 == std::string::npos); 2122 == std::string::npos);
2153 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2123 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2154 != std::string::npos); 2124 != std::string::npos);
2155 2125
2156 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2126 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2157 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2127 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2158 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2128 EXPECT_EQ(0, network_delegate.set_cookie_count());
2159 } 2129 }
2160 } 2130 }
2161 2131
2162 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 2132 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
2163 LocalHttpTestServer test_server; 2133 LocalHttpTestServer test_server;
2164 ASSERT_TRUE(test_server.Start()); 2134 ASSERT_TRUE(test_server.Start());
2165 2135
2166 // Set up a cookie. 2136 // Set up a cookie.
2167 { 2137 {
2168 TestNetworkDelegate network_delegate; 2138 TestNetworkDelegate network_delegate;
2169 default_context_.set_network_delegate(&network_delegate); 2139 default_context_.set_network_delegate(&network_delegate);
2170 TestDelegate d; 2140 TestDelegate d;
2171 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 2141 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2172 DEFAULT_PRIORITY, 2142 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2173 &d, 2143 &d, NULL));
2174 &default_context_); 2144 req->Start();
2175 req.Start();
2176 base::RunLoop().Run(); 2145 base::RunLoop().Run();
2177 2146
2178 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2147 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2179 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2148 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2180 } 2149 }
2181 2150
2182 // Verify that the cookie is set. 2151 // Verify that the cookie is set.
2183 { 2152 {
2184 TestNetworkDelegate network_delegate; 2153 TestNetworkDelegate network_delegate;
2185 default_context_.set_network_delegate(&network_delegate); 2154 default_context_.set_network_delegate(&network_delegate);
2186 TestDelegate d; 2155 TestDelegate d;
2187 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2156 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2188 DEFAULT_PRIORITY, 2157 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2189 &d, 2158 req->Start();
2190 &default_context_);
2191 req.Start();
2192 base::RunLoop().Run(); 2159 base::RunLoop().Run();
2193 2160
2194 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2161 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2195 != std::string::npos); 2162 != std::string::npos);
2196 2163
2197 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2164 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2198 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2165 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2199 } 2166 }
2200 2167
2201 // Verify that the cookie isn't sent. 2168 // Verify that the cookie isn't sent.
2202 { 2169 {
2203 TestNetworkDelegate network_delegate; 2170 TestNetworkDelegate network_delegate;
2204 default_context_.set_network_delegate(&network_delegate); 2171 default_context_.set_network_delegate(&network_delegate);
2205 TestDelegate d; 2172 TestDelegate d;
2206 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2173 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2207 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2174 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2208 DEFAULT_PRIORITY, 2175 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2209 &d, 2176 req->Start();
2210 &default_context_);
2211 req.Start();
2212 base::RunLoop().Run(); 2177 base::RunLoop().Run();
2213 2178
2214 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2179 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2215 == std::string::npos); 2180 == std::string::npos);
2216 2181
2217 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2182 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2218 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2183 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2219 } 2184 }
2220 } 2185 }
2221 2186
2222 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2187 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2223 LocalHttpTestServer test_server; 2188 LocalHttpTestServer test_server;
2224 ASSERT_TRUE(test_server.Start()); 2189 ASSERT_TRUE(test_server.Start());
2225 2190
2226 // Set up a cookie. 2191 // Set up a cookie.
2227 { 2192 {
2228 TestNetworkDelegate network_delegate; 2193 TestNetworkDelegate network_delegate;
2229 default_context_.set_network_delegate(&network_delegate); 2194 default_context_.set_network_delegate(&network_delegate);
2230 TestDelegate d; 2195 TestDelegate d;
2231 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2196 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2232 DEFAULT_PRIORITY, 2197 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2233 &d, 2198 &d, NULL));
2234 &default_context_); 2199 req->Start();
2235 req.Start();
2236 base::RunLoop().Run(); 2200 base::RunLoop().Run();
2237 2201
2238 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2202 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2239 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2203 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2240 } 2204 }
2241 2205
2242 // Try to set-up another cookie and update the previous cookie. 2206 // Try to set-up another cookie and update the previous cookie.
2243 { 2207 {
2244 TestNetworkDelegate network_delegate; 2208 TestNetworkDelegate network_delegate;
2245 default_context_.set_network_delegate(&network_delegate); 2209 default_context_.set_network_delegate(&network_delegate);
2246 TestDelegate d; 2210 TestDelegate d;
2247 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2211 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2248 URLRequest req( 2212 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2249 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2213 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2250 DEFAULT_PRIORITY, 2214 DEFAULT_PRIORITY, &d, NULL));
2251 &d, 2215 req->Start();
2252 &default_context_);
2253 req.Start();
2254 2216
2255 base::RunLoop().Run(); 2217 base::RunLoop().Run();
2256 2218
2257 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2219 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2258 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2220 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2259 } 2221 }
2260 2222
2261 // Verify the cookies weren't saved or updated. 2223 // Verify the cookies weren't saved or updated.
2262 { 2224 {
2263 TestNetworkDelegate network_delegate; 2225 TestNetworkDelegate network_delegate;
2264 default_context_.set_network_delegate(&network_delegate); 2226 default_context_.set_network_delegate(&network_delegate);
2265 TestDelegate d; 2227 TestDelegate d;
2266 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2228 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2267 DEFAULT_PRIORITY, 2229 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2268 &d, 2230 req->Start();
2269 &default_context_);
2270 req.Start();
2271 base::RunLoop().Run(); 2231 base::RunLoop().Run();
2272 2232
2273 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2233 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2274 == std::string::npos); 2234 == std::string::npos);
2275 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2235 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2276 != std::string::npos); 2236 != std::string::npos);
2277 2237
2278 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2238 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2279 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2239 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2280 } 2240 }
2281 } 2241 }
2282 2242
2283 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 2243 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
2284 LocalHttpTestServer test_server; 2244 LocalHttpTestServer test_server;
2285 ASSERT_TRUE(test_server.Start()); 2245 ASSERT_TRUE(test_server.Start());
2286 2246
2287 // Set up an empty cookie. 2247 // Set up an empty cookie.
2288 { 2248 {
2289 TestNetworkDelegate network_delegate; 2249 TestNetworkDelegate network_delegate;
2290 default_context_.set_network_delegate(&network_delegate); 2250 default_context_.set_network_delegate(&network_delegate);
2291 TestDelegate d; 2251 TestDelegate d;
2292 URLRequest req(test_server.GetURL("set-cookie"), 2252 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2293 DEFAULT_PRIORITY, 2253 test_server.GetURL("set-cookie"), DEFAULT_PRIORITY, &d, NULL));
2294 &d, 2254 req->Start();
2295 &default_context_);
2296 req.Start();
2297 base::RunLoop().Run(); 2255 base::RunLoop().Run();
2298 2256
2299 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2257 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2300 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2258 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2301 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2259 EXPECT_EQ(0, network_delegate.set_cookie_count());
2302 } 2260 }
2303 } 2261 }
2304 2262
2305 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 2263 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
2306 LocalHttpTestServer test_server; 2264 LocalHttpTestServer test_server;
2307 ASSERT_TRUE(test_server.Start()); 2265 ASSERT_TRUE(test_server.Start());
2308 2266
2309 // Set up a cookie. 2267 // Set up a cookie.
2310 { 2268 {
2311 TestNetworkDelegate network_delegate; 2269 TestNetworkDelegate network_delegate;
2312 default_context_.set_network_delegate(&network_delegate); 2270 default_context_.set_network_delegate(&network_delegate);
2313 TestDelegate d; 2271 TestDelegate d;
2314 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 2272 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2315 DEFAULT_PRIORITY, 2273 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2316 &d, 2274 &d, NULL));
2317 &default_context_); 2275 req->Start();
2318 req.Start();
2319 base::RunLoop().Run(); 2276 base::RunLoop().Run();
2320 2277
2321 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2278 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2322 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2279 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2323 } 2280 }
2324 2281
2325 // Verify that the cookie is set. 2282 // Verify that the cookie is set.
2326 { 2283 {
2327 TestNetworkDelegate network_delegate; 2284 TestNetworkDelegate network_delegate;
2328 default_context_.set_network_delegate(&network_delegate); 2285 default_context_.set_network_delegate(&network_delegate);
2329 TestDelegate d; 2286 TestDelegate d;
2330 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2287 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2331 DEFAULT_PRIORITY, 2288 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2332 &d, 2289 req->Start();
2333 &default_context_);
2334 req.Start();
2335 base::RunLoop().Run(); 2290 base::RunLoop().Run();
2336 2291
2337 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2292 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2338 != std::string::npos); 2293 != std::string::npos);
2339 2294
2340 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2295 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2341 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2296 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2342 } 2297 }
2343 2298
2344 // Verify that the cookie isn't sent. 2299 // Verify that the cookie isn't sent.
2345 { 2300 {
2346 TestNetworkDelegate network_delegate; 2301 TestNetworkDelegate network_delegate;
2347 default_context_.set_network_delegate(&network_delegate); 2302 default_context_.set_network_delegate(&network_delegate);
2348 TestDelegate d; 2303 TestDelegate d;
2349 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2304 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2350 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2305 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2351 DEFAULT_PRIORITY, 2306 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2352 &d, 2307 req->Start();
2353 &default_context_);
2354 req.Start();
2355 base::RunLoop().Run(); 2308 base::RunLoop().Run();
2356 2309
2357 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2310 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2358 == std::string::npos); 2311 == std::string::npos);
2359 2312
2360 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2313 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2361 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2314 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2362 } 2315 }
2363 } 2316 }
2364 2317
2365 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2318 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2366 LocalHttpTestServer test_server; 2319 LocalHttpTestServer test_server;
2367 ASSERT_TRUE(test_server.Start()); 2320 ASSERT_TRUE(test_server.Start());
2368 2321
2369 // Set up a cookie. 2322 // Set up a cookie.
2370 { 2323 {
2371 TestNetworkDelegate network_delegate; 2324 TestNetworkDelegate network_delegate;
2372 default_context_.set_network_delegate(&network_delegate); 2325 default_context_.set_network_delegate(&network_delegate);
2373 TestDelegate d; 2326 TestDelegate d;
2374 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2327 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2375 DEFAULT_PRIORITY, 2328 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2376 &d, 2329 &d, NULL));
2377 &default_context_); 2330 req->Start();
2378 req.Start();
2379 base::RunLoop().Run(); 2331 base::RunLoop().Run();
2380 2332
2381 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2333 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2382 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2334 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2383 } 2335 }
2384 2336
2385 // Try to set-up another cookie and update the previous cookie. 2337 // Try to set-up another cookie and update the previous cookie.
2386 { 2338 {
2387 TestNetworkDelegate network_delegate; 2339 TestNetworkDelegate network_delegate;
2388 default_context_.set_network_delegate(&network_delegate); 2340 default_context_.set_network_delegate(&network_delegate);
2389 TestDelegate d; 2341 TestDelegate d;
2390 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2342 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2391 URLRequest req( 2343 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2392 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2344 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2393 DEFAULT_PRIORITY, 2345 DEFAULT_PRIORITY, &d, NULL));
2394 &d, 2346 req->Start();
2395 &default_context_);
2396 req.Start();
2397 2347
2398 base::RunLoop().Run(); 2348 base::RunLoop().Run();
2399 2349
2400 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2350 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2401 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2351 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2402 } 2352 }
2403 2353
2404 // Verify the cookies weren't saved or updated. 2354 // Verify the cookies weren't saved or updated.
2405 { 2355 {
2406 TestNetworkDelegate network_delegate; 2356 TestNetworkDelegate network_delegate;
2407 default_context_.set_network_delegate(&network_delegate); 2357 default_context_.set_network_delegate(&network_delegate);
2408 TestDelegate d; 2358 TestDelegate d;
2409 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2359 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2410 DEFAULT_PRIORITY, 2360 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2411 &d, 2361 req->Start();
2412 &default_context_);
2413 req.Start();
2414 base::RunLoop().Run(); 2362 base::RunLoop().Run();
2415 2363
2416 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2364 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2417 == std::string::npos); 2365 == std::string::npos);
2418 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2366 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2419 != std::string::npos); 2367 != std::string::npos);
2420 2368
2421 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2369 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2422 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2370 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2423 } 2371 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 // headers by defaulting to GMT. (crbug.com/135131) 2418 // headers by defaulting to GMT. (crbug.com/135131)
2471 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { 2419 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) {
2472 LocalHttpTestServer test_server; 2420 LocalHttpTestServer test_server;
2473 ASSERT_TRUE(test_server.Start()); 2421 ASSERT_TRUE(test_server.Start());
2474 2422
2475 // Set up an expired cookie. 2423 // Set up an expired cookie.
2476 { 2424 {
2477 TestNetworkDelegate network_delegate; 2425 TestNetworkDelegate network_delegate;
2478 default_context_.set_network_delegate(&network_delegate); 2426 default_context_.set_network_delegate(&network_delegate);
2479 TestDelegate d; 2427 TestDelegate d;
2480 URLRequest req( 2428 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2481 test_server.GetURL( 2429 test_server.GetURL(
2482 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2430 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2483 DEFAULT_PRIORITY, 2431 DEFAULT_PRIORITY, &d, NULL));
2484 &d, 2432 req->Start();
2485 &default_context_);
2486 req.Start();
2487 base::RunLoop().Run(); 2433 base::RunLoop().Run();
2488 } 2434 }
2489 // Verify that the cookie is not set. 2435 // Verify that the cookie is not set.
2490 { 2436 {
2491 TestNetworkDelegate network_delegate; 2437 TestNetworkDelegate network_delegate;
2492 default_context_.set_network_delegate(&network_delegate); 2438 default_context_.set_network_delegate(&network_delegate);
2493 TestDelegate d; 2439 TestDelegate d;
2494 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2440 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2495 DEFAULT_PRIORITY, 2441 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2496 &d, 2442 req->Start();
2497 &default_context_);
2498 req.Start();
2499 base::RunLoop().Run(); 2443 base::RunLoop().Run();
2500 2444
2501 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); 2445 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos);
2502 } 2446 }
2503 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. 2447 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier.
2504 { 2448 {
2505 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); 2449 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC");
2506 default_context_.set_network_delegate(&network_delegate); 2450 default_context_.set_network_delegate(&network_delegate);
2507 TestDelegate d; 2451 TestDelegate d;
2508 URLRequest req( 2452 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2509 test_server.GetURL( 2453 test_server.GetURL(
2510 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2454 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2511 DEFAULT_PRIORITY, 2455 DEFAULT_PRIORITY, &d, NULL));
2512 &d, 2456 req->Start();
2513 &default_context_);
2514 req.Start();
2515 base::RunLoop().Run(); 2457 base::RunLoop().Run();
2516 } 2458 }
2517 // Verify that the cookie is set. 2459 // Verify that the cookie is set.
2518 { 2460 {
2519 TestNetworkDelegate network_delegate; 2461 TestNetworkDelegate network_delegate;
2520 default_context_.set_network_delegate(&network_delegate); 2462 default_context_.set_network_delegate(&network_delegate);
2521 TestDelegate d; 2463 TestDelegate d;
2522 URLRequest req(test_server.GetURL("echoheader?Cookie"), 2464 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2523 DEFAULT_PRIORITY, 2465 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL));
2524 &d, 2466 req->Start();
2525 &default_context_);
2526 req.Start();
2527 base::RunLoop().Run(); 2467 base::RunLoop().Run();
2528 2468
2529 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); 2469 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos);
2530 } 2470 }
2531 } 2471 }
2532 2472
2533 2473
2534 // Check that it is impossible to change the referrer in the extra headers of 2474 // Check that it is impossible to change the referrer in the extra headers of
2535 // an URLRequest. 2475 // an URLRequest.
2536 TEST_F(URLRequestTest, DoNotOverrideReferrer) { 2476 TEST_F(URLRequestTest, DoNotOverrideReferrer) {
2537 LocalHttpTestServer test_server; 2477 LocalHttpTestServer test_server;
2538 ASSERT_TRUE(test_server.Start()); 2478 ASSERT_TRUE(test_server.Start());
2539 2479
2540 // If extra headers contain referer and the request contains a referer, 2480 // If extra headers contain referer and the request contains a referer,
2541 // only the latter shall be respected. 2481 // only the latter shall be respected.
2542 { 2482 {
2543 TestDelegate d; 2483 TestDelegate d;
2544 URLRequest req(test_server.GetURL("echoheader?Referer"), 2484 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2545 DEFAULT_PRIORITY, 2485 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL));
2546 &d, 2486 req->SetReferrer("http://foo.com/");
2547 &default_context_);
2548 req.SetReferrer("http://foo.com/");
2549 2487
2550 HttpRequestHeaders headers; 2488 HttpRequestHeaders headers;
2551 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2489 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2552 req.SetExtraRequestHeaders(headers); 2490 req->SetExtraRequestHeaders(headers);
2553 2491
2554 req.Start(); 2492 req->Start();
2555 base::RunLoop().Run(); 2493 base::RunLoop().Run();
2556 2494
2557 EXPECT_EQ("http://foo.com/", d.data_received()); 2495 EXPECT_EQ("http://foo.com/", d.data_received());
2558 } 2496 }
2559 2497
2560 // If extra headers contain a referer but the request does not, no referer 2498 // If extra headers contain a referer but the request does not, no referer
2561 // shall be sent in the header. 2499 // shall be sent in the header.
2562 { 2500 {
2563 TestDelegate d; 2501 TestDelegate d;
2564 URLRequest req(test_server.GetURL("echoheader?Referer"), 2502 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2565 DEFAULT_PRIORITY, 2503 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL));
2566 &d,
2567 &default_context_);
2568 2504
2569 HttpRequestHeaders headers; 2505 HttpRequestHeaders headers;
2570 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2506 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2571 req.SetExtraRequestHeaders(headers); 2507 req->SetExtraRequestHeaders(headers);
2572 req.SetLoadFlags(LOAD_VALIDATE_CACHE); 2508 req->SetLoadFlags(LOAD_VALIDATE_CACHE);
2573 2509
2574 req.Start(); 2510 req->Start();
2575 base::RunLoop().Run(); 2511 base::RunLoop().Run();
2576 2512
2577 EXPECT_EQ("None", d.data_received()); 2513 EXPECT_EQ("None", d.data_received());
2578 } 2514 }
2579 } 2515 }
2580 2516
2581 class URLRequestTestHTTP : public URLRequestTest { 2517 class URLRequestTestHTTP : public URLRequestTest {
2582 public: 2518 public:
2583 URLRequestTestHTTP() 2519 URLRequestTestHTTP()
2584 : test_server_(base::FilePath(FILE_PATH_LITERAL( 2520 : test_server_(base::FilePath(FILE_PATH_LITERAL(
2585 "net/data/url_request_unittest"))) { 2521 "net/data/url_request_unittest"))) {
2586 } 2522 }
2587 2523
2588 protected: 2524 protected:
2589 // Requests |redirect_url|, which must return a HTTP 3xx redirect. 2525 // Requests |redirect_url|, which must return a HTTP 3xx redirect.
2590 // |request_method| is the method to use for the initial request. 2526 // |request_method| is the method to use for the initial request.
2591 // |redirect_method| is the method that is expected to be used for the second 2527 // |redirect_method| is the method that is expected to be used for the second
2592 // request, after redirection. 2528 // request, after redirection.
2593 // If |include_data| is true, data is uploaded with the request. The 2529 // If |include_data| is true, data is uploaded with the request. The
2594 // response body is expected to match it exactly, if and only if 2530 // response body is expected to match it exactly, if and only if
2595 // |request_method| == |redirect_method|. 2531 // |request_method| == |redirect_method|.
2596 void HTTPRedirectMethodTest(const GURL& redirect_url, 2532 void HTTPRedirectMethodTest(const GURL& redirect_url,
2597 const std::string& request_method, 2533 const std::string& request_method,
2598 const std::string& redirect_method, 2534 const std::string& redirect_method,
2599 bool include_data) { 2535 bool include_data) {
2600 static const char kData[] = "hello world"; 2536 static const char kData[] = "hello world";
2601 TestDelegate d; 2537 TestDelegate d;
2602 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); 2538 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2603 req.set_method(request_method); 2539 redirect_url, DEFAULT_PRIORITY, &d, NULL));
2540 req->set_method(request_method);
2604 if (include_data) { 2541 if (include_data) {
2605 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 2542 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
2606 HttpRequestHeaders headers; 2543 HttpRequestHeaders headers;
2607 headers.SetHeader(HttpRequestHeaders::kContentLength, 2544 headers.SetHeader(HttpRequestHeaders::kContentLength,
2608 base::UintToString(arraysize(kData) - 1)); 2545 base::UintToString(arraysize(kData) - 1));
2609 req.SetExtraRequestHeaders(headers); 2546 req->SetExtraRequestHeaders(headers);
2610 } 2547 }
2611 req.Start(); 2548 req->Start();
2612 base::RunLoop().Run(); 2549 base::RunLoop().Run();
2613 EXPECT_EQ(redirect_method, req.method()); 2550 EXPECT_EQ(redirect_method, req->method());
2614 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 2551 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
2615 EXPECT_EQ(OK, req.status().error()); 2552 EXPECT_EQ(OK, req->status().error());
2616 if (include_data) { 2553 if (include_data) {
2617 if (request_method == redirect_method) { 2554 if (request_method == redirect_method) {
2618 EXPECT_EQ(kData, d.data_received()); 2555 EXPECT_EQ(kData, d.data_received());
2619 } else { 2556 } else {
2620 EXPECT_NE(kData, d.data_received()); 2557 EXPECT_NE(kData, d.data_received());
2621 } 2558 }
2622 } 2559 }
2623 if (HasFailure()) 2560 if (HasFailure())
2624 LOG(WARNING) << "Request method was: " << request_method; 2561 LOG(WARNING) << "Request method was: " << request_method;
2625 } 2562 }
(...skipping 11 matching lines...) Expand all
2637 ptr--; 2574 ptr--;
2638 *ptr++ = marker; 2575 *ptr++ = marker;
2639 if (++marker > 'z') 2576 if (++marker > 'z')
2640 marker = 'a'; 2577 marker = 'a';
2641 } 2578 }
2642 } 2579 }
2643 uploadBytes[kMsgSize] = '\0'; 2580 uploadBytes[kMsgSize] = '\0';
2644 2581
2645 for (int i = 0; i < kIterations; ++i) { 2582 for (int i = 0; i < kIterations; ++i) {
2646 TestDelegate d; 2583 TestDelegate d;
2647 URLRequest r( 2584 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
2648 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 2585 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
2649 r.set_method(method.c_str()); 2586 r->set_method(method.c_str());
2650 2587
2651 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); 2588 r->set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes)));
2652 2589
2653 r.Start(); 2590 r->Start();
2654 EXPECT_TRUE(r.is_pending()); 2591 EXPECT_TRUE(r->is_pending());
2655 2592
2656 base::RunLoop().Run(); 2593 base::RunLoop().Run();
2657 2594
2658 ASSERT_EQ(1, d.response_started_count()) 2595 ASSERT_EQ(1, d.response_started_count())
2659 << "request failed: " << r.status().status() 2596 << "request failed: " << r->status().status()
2660 << ", os error: " << r.status().error(); 2597 << ", os error: " << r->status().error();
2661 2598
2662 EXPECT_FALSE(d.received_data_before_response()); 2599 EXPECT_FALSE(d.received_data_before_response());
2663 EXPECT_EQ(uploadBytes, d.data_received()); 2600 EXPECT_EQ(uploadBytes, d.data_received());
2664 } 2601 }
2665 delete[] uploadBytes; 2602 delete[] uploadBytes;
2666 } 2603 }
2667 2604
2668 void AddChunksToUpload(URLRequest* r) { 2605 void AddChunksToUpload(URLRequest* r) {
2669 r->AppendChunkToUpload("a", 1, false); 2606 r->AppendChunkToUpload("a", 1, false);
2670 r->AppendChunkToUpload("bcd", 3, false); 2607 r->AppendChunkToUpload("bcd", 3, false);
(...skipping 13 matching lines...) Expand all
2684 << ", os error: " << r->status().error(); 2621 << ", os error: " << r->status().error();
2685 2622
2686 EXPECT_FALSE(d->received_data_before_response()); 2623 EXPECT_FALSE(d->received_data_before_response());
2687 2624
2688 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); 2625 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received()));
2689 EXPECT_EQ(expected_data, d->data_received()); 2626 EXPECT_EQ(expected_data, d->data_received());
2690 } 2627 }
2691 2628
2692 bool DoManyCookiesRequest(int num_cookies) { 2629 bool DoManyCookiesRequest(int num_cookies) {
2693 TestDelegate d; 2630 TestDelegate d;
2694 URLRequest r(test_server_.GetURL("set-many-cookies?" + 2631 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
2695 base::IntToString(num_cookies)), 2632 test_server_.GetURL("set-many-cookies?" +
2696 DEFAULT_PRIORITY, 2633 base::IntToString(num_cookies)),
2697 &d, 2634 DEFAULT_PRIORITY, &d, NULL));
2698 &default_context_);
2699 2635
2700 r.Start(); 2636 r->Start();
2701 EXPECT_TRUE(r.is_pending()); 2637 EXPECT_TRUE(r->is_pending());
2702 2638
2703 base::RunLoop().Run(); 2639 base::RunLoop().Run();
2704 2640
2705 bool is_success = r.status().is_success(); 2641 bool is_success = r->status().is_success();
2706 2642
2707 if (!is_success) { 2643 if (!is_success) {
2708 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); 2644 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG);
2709 // The test server appears to be unable to handle subsequent requests 2645 // The test server appears to be unable to handle subsequent requests
2710 // after this error is triggered. Force it to restart. 2646 // after this error is triggered. Force it to restart.
2711 EXPECT_TRUE(test_server_.Stop()); 2647 EXPECT_TRUE(test_server_.Stop());
2712 EXPECT_TRUE(test_server_.Start()); 2648 EXPECT_TRUE(test_server_.Start());
2713 } 2649 }
2714 2650
2715 return is_success; 2651 return is_success;
2716 } 2652 }
2717 2653
2718 LocalHttpTestServer test_server_; 2654 LocalHttpTestServer test_server_;
2719 }; 2655 };
2720 2656
2721 // In this unit test, we're using the HTTPTestServer as a proxy server and 2657 // In this unit test, we're using the HTTPTestServer as a proxy server and
2722 // issuing a CONNECT request with the magic host name "www.redirect.com". 2658 // issuing a CONNECT request with the magic host name "www.redirect.com".
2723 // The HTTPTestServer will return a 302 response, which we should not 2659 // The HTTPTestServer will return a 302 response, which we should not
2724 // follow. 2660 // follow.
2725 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { 2661 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) {
2726 ASSERT_TRUE(test_server_.Start()); 2662 ASSERT_TRUE(test_server_.Start());
2727 2663
2728 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 2664 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2729 TestURLRequestContextWithProxy context( 2665 TestURLRequestContextWithProxy context(
2730 test_server_.host_port_pair().ToString(), &network_delegate); 2666 test_server_.host_port_pair().ToString(), &network_delegate);
2731 2667
2732 TestDelegate d; 2668 TestDelegate d;
2733 { 2669 {
2734 URLRequest r( 2670 scoped_ptr<URLRequest> r(context.CreateRequest(
2735 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context); 2671 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL));
2736 r.Start(); 2672 r->Start();
2737 EXPECT_TRUE(r.is_pending()); 2673 EXPECT_TRUE(r->is_pending());
2738 2674
2739 base::RunLoop().Run(); 2675 base::RunLoop().Run();
2740 2676
2741 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2677 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
2742 // The proxy server is not set before failure. 2678 // The proxy server is not set before failure.
2743 EXPECT_TRUE(r.proxy_server().IsEmpty()); 2679 EXPECT_TRUE(r->proxy_server().IsEmpty());
2744 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 2680 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
2745 EXPECT_EQ(1, d.response_started_count()); 2681 EXPECT_EQ(1, d.response_started_count());
2746 // We should not have followed the redirect. 2682 // We should not have followed the redirect.
2747 EXPECT_EQ(0, d.received_redirect_count()); 2683 EXPECT_EQ(0, d.received_redirect_count());
2748 } 2684 }
2749 } 2685 }
2750 2686
2751 // This is the same as the previous test, but checks that the network delegate 2687 // This is the same as the previous test, but checks that the network delegate
2752 // registers the error. 2688 // registers the error.
2753 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 2689 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
2754 ASSERT_TRUE(test_server_.Start()); 2690 ASSERT_TRUE(test_server_.Start());
2755 2691
2756 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 2692 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2757 TestURLRequestContextWithProxy context( 2693 TestURLRequestContextWithProxy context(
2758 test_server_.host_port_pair().ToString(), &network_delegate); 2694 test_server_.host_port_pair().ToString(), &network_delegate);
2759 2695
2760 TestDelegate d; 2696 TestDelegate d;
2761 { 2697 {
2762 URLRequest r( 2698 scoped_ptr<URLRequest> r(context.CreateRequest(
2763 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context); 2699 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL));
2764 r.Start(); 2700 r->Start();
2765 EXPECT_TRUE(r.is_pending()); 2701 EXPECT_TRUE(r->is_pending());
2766 2702
2767 base::RunLoop().Run(); 2703 base::RunLoop().Run();
2768 2704
2769 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2705 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
2770 // The proxy server is not set before failure. 2706 // The proxy server is not set before failure.
2771 EXPECT_TRUE(r.proxy_server().IsEmpty()); 2707 EXPECT_TRUE(r->proxy_server().IsEmpty());
2772 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 2708 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
2773 EXPECT_EQ(1, d.response_started_count()); 2709 EXPECT_EQ(1, d.response_started_count());
2774 // We should not have followed the redirect. 2710 // We should not have followed the redirect.
2775 EXPECT_EQ(0, d.received_redirect_count()); 2711 EXPECT_EQ(0, d.received_redirect_count());
2776 2712
2777 EXPECT_EQ(1, network_delegate.error_count()); 2713 EXPECT_EQ(1, network_delegate.error_count());
2778 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); 2714 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error());
2779 } 2715 }
2780 } 2716 }
2781 2717
2782 // Tests that we can block and asynchronously return OK in various stages. 2718 // Tests that we can block and asynchronously return OK in various stages.
(...skipping 13 matching lines...) Expand all
2796 network_delegate.set_block_on( 2732 network_delegate.set_block_on(
2797 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | 2733 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST |
2798 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | 2734 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS |
2799 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 2735 BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
2800 2736
2801 TestURLRequestContext context(true); 2737 TestURLRequestContext context(true);
2802 context.set_network_delegate(&network_delegate); 2738 context.set_network_delegate(&network_delegate);
2803 context.Init(); 2739 context.Init();
2804 2740
2805 { 2741 {
2806 URLRequest r( 2742 scoped_ptr<URLRequest> r(context.CreateRequest(
2807 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, &context); 2743 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL));
2808 2744
2809 r.Start(); 2745 r->Start();
2810 for (size_t i = 0; i < blocking_stages_length; ++i) { 2746 for (size_t i = 0; i < blocking_stages_length; ++i) {
2811 base::RunLoop().Run(); 2747 base::RunLoop().Run();
2812 EXPECT_EQ(blocking_stages[i], 2748 EXPECT_EQ(blocking_stages[i],
2813 network_delegate.stage_blocked_for_callback()); 2749 network_delegate.stage_blocked_for_callback());
2814 network_delegate.DoCallback(OK); 2750 network_delegate.DoCallback(OK);
2815 } 2751 }
2816 base::RunLoop().Run(); 2752 base::RunLoop().Run();
2817 EXPECT_EQ(200, r.GetResponseCode()); 2753 EXPECT_EQ(200, r->GetResponseCode());
2818 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2754 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
2819 EXPECT_EQ(1, network_delegate.created_requests()); 2755 EXPECT_EQ(1, network_delegate.created_requests());
2820 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2756 EXPECT_EQ(0, network_delegate.destroyed_requests());
2821 } 2757 }
2822 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2758 EXPECT_EQ(1, network_delegate.destroyed_requests());
2823 } 2759 }
2824 2760
2825 // Tests that the network delegate can block and cancel a request. 2761 // Tests that the network delegate can block and cancel a request.
2826 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { 2762 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
2827 ASSERT_TRUE(test_server_.Start()); 2763 ASSERT_TRUE(test_server_.Start());
2828 2764
2829 TestDelegate d; 2765 TestDelegate d;
2830 BlockingNetworkDelegate network_delegate( 2766 BlockingNetworkDelegate network_delegate(
2831 BlockingNetworkDelegate::AUTO_CALLBACK); 2767 BlockingNetworkDelegate::AUTO_CALLBACK);
2832 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2768 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2833 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 2769 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
2834 2770
2835 TestURLRequestContextWithProxy context( 2771 TestURLRequestContextWithProxy context(
2836 test_server_.host_port_pair().ToString(), &network_delegate); 2772 test_server_.host_port_pair().ToString(), &network_delegate);
2837 2773
2838 { 2774 {
2839 URLRequest r( 2775 scoped_ptr<URLRequest> r(context.CreateRequest(
2840 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); 2776 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
2841 2777
2842 r.Start(); 2778 r->Start();
2843 base::RunLoop().Run(); 2779 base::RunLoop().Run();
2844 2780
2845 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2781 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
2846 // The proxy server is not set before cancellation. 2782 // The proxy server is not set before cancellation.
2847 EXPECT_TRUE(r.proxy_server().IsEmpty()); 2783 EXPECT_TRUE(r->proxy_server().IsEmpty());
2848 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 2784 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error());
2849 EXPECT_EQ(1, network_delegate.created_requests()); 2785 EXPECT_EQ(1, network_delegate.created_requests());
2850 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2786 EXPECT_EQ(0, network_delegate.destroyed_requests());
2851 } 2787 }
2852 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2788 EXPECT_EQ(1, network_delegate.destroyed_requests());
2853 } 2789 }
2854 2790
2855 // Helper function for NetworkDelegateCancelRequestAsynchronously and 2791 // Helper function for NetworkDelegateCancelRequestAsynchronously and
2856 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network 2792 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network
2857 // delegate operating in |block_mode| and a request for |url|. It blocks the 2793 // delegate operating in |block_mode| and a request for |url|. It blocks the
2858 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. 2794 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT.
2859 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, 2795 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode,
2860 BlockingNetworkDelegate::Stage stage, 2796 BlockingNetworkDelegate::Stage stage,
2861 const GURL& url) { 2797 const GURL& url) {
2862 TestDelegate d; 2798 TestDelegate d;
2863 BlockingNetworkDelegate network_delegate(block_mode); 2799 BlockingNetworkDelegate network_delegate(block_mode);
2864 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); 2800 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT);
2865 network_delegate.set_block_on(stage); 2801 network_delegate.set_block_on(stage);
2866 2802
2867 TestURLRequestContext context(true); 2803 TestURLRequestContext context(true);
2868 context.set_network_delegate(&network_delegate); 2804 context.set_network_delegate(&network_delegate);
2869 context.Init(); 2805 context.Init();
2870 2806
2871 { 2807 {
2872 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 2808 scoped_ptr<URLRequest> r(context.CreateRequest(
2809 url, DEFAULT_PRIORITY, &d, NULL));
2873 2810
2874 r.Start(); 2811 r->Start();
2875 base::RunLoop().Run(); 2812 base::RunLoop().Run();
2876 2813
2877 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2814 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
2878 // The proxy server is not set before cancellation. 2815 // The proxy server is not set before cancellation.
2879 EXPECT_TRUE(r.proxy_server().IsEmpty()); 2816 EXPECT_TRUE(r->proxy_server().IsEmpty());
2880 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); 2817 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error());
2881 EXPECT_EQ(1, network_delegate.created_requests()); 2818 EXPECT_EQ(1, network_delegate.created_requests());
2882 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2819 EXPECT_EQ(0, network_delegate.destroyed_requests());
2883 } 2820 }
2884 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2821 EXPECT_EQ(1, network_delegate.destroyed_requests());
2885 } 2822 }
2886 2823
2887 // The following 3 tests check that the network delegate can cancel a request 2824 // The following 3 tests check that the network delegate can cancel a request
2888 // synchronously in various stages of the request. 2825 // synchronously in various stages of the request.
2889 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { 2826 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) {
2890 ASSERT_TRUE(test_server_.Start()); 2827 ASSERT_TRUE(test_server_.Start());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2940 BlockingNetworkDelegate::AUTO_CALLBACK); 2877 BlockingNetworkDelegate::AUTO_CALLBACK);
2941 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2878 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2942 GURL redirect_url(test_server_.GetURL("simple.html")); 2879 GURL redirect_url(test_server_.GetURL("simple.html"));
2943 network_delegate.set_redirect_url(redirect_url); 2880 network_delegate.set_redirect_url(redirect_url);
2944 2881
2945 TestURLRequestContextWithProxy context( 2882 TestURLRequestContextWithProxy context(
2946 test_server_.host_port_pair().ToString(), &network_delegate); 2883 test_server_.host_port_pair().ToString(), &network_delegate);
2947 2884
2948 { 2885 {
2949 GURL original_url(test_server_.GetURL("empty.html")); 2886 GURL original_url(test_server_.GetURL("empty.html"));
2950 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); 2887 scoped_ptr<URLRequest> r(context.CreateRequest(
2888 original_url, DEFAULT_PRIORITY, &d, NULL));
2951 2889
2952 // Quit after hitting the redirect, so can check the headers. 2890 // Quit after hitting the redirect, so can check the headers.
2953 d.set_quit_on_redirect(true); 2891 d.set_quit_on_redirect(true);
2954 r.Start(); 2892 r->Start();
2955 base::RunLoop().Run(); 2893 base::RunLoop().Run();
2956 2894
2957 // Check headers from URLRequestJob. 2895 // Check headers from URLRequestJob.
2958 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2896 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
2959 EXPECT_EQ(307, r.GetResponseCode()); 2897 EXPECT_EQ(307, r->GetResponseCode());
2960 EXPECT_EQ(307, r.response_headers()->response_code()); 2898 EXPECT_EQ(307, r->response_headers()->response_code());
2961 std::string location; 2899 std::string location;
2962 ASSERT_TRUE(r.response_headers()->EnumerateHeader(NULL, "Location", 2900 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
2963 &location)); 2901 &location));
2964 EXPECT_EQ(redirect_url, GURL(location)); 2902 EXPECT_EQ(redirect_url, GURL(location));
2965 2903
2966 // Let the request finish. 2904 // Let the request finish.
2967 r.FollowDeferredRedirect(); 2905 r->FollowDeferredRedirect();
2968 base::RunLoop().Run(); 2906 base::RunLoop().Run();
2969 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2907 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
2970 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); 2908 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair()));
2971 EXPECT_EQ( 2909 EXPECT_EQ(
2972 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); 2910 1, network_delegate.observed_before_proxy_headers_sent_callbacks());
2973 EXPECT_TRUE( 2911 EXPECT_TRUE(
2974 network_delegate.last_observed_proxy().Equals( 2912 network_delegate.last_observed_proxy().Equals(
2975 test_server_.host_port_pair())); 2913 test_server_.host_port_pair()));
2976 2914
2977 EXPECT_EQ(0, r.status().error()); 2915 EXPECT_EQ(0, r->status().error());
2978 EXPECT_EQ(redirect_url, r.url()); 2916 EXPECT_EQ(redirect_url, r->url());
2979 EXPECT_EQ(original_url, r.original_url()); 2917 EXPECT_EQ(original_url, r->original_url());
2980 EXPECT_EQ(2U, r.url_chain().size()); 2918 EXPECT_EQ(2U, r->url_chain().size());
2981 EXPECT_EQ(1, network_delegate.created_requests()); 2919 EXPECT_EQ(1, network_delegate.created_requests());
2982 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2920 EXPECT_EQ(0, network_delegate.destroyed_requests());
2983 } 2921 }
2984 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2922 EXPECT_EQ(1, network_delegate.destroyed_requests());
2985 } 2923 }
2986 2924
2987 // Tests that the network delegate can block and redirect a request to a new 2925 // Tests that the network delegate can block and redirect a request to a new
2988 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. 2926 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly.
2989 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { 2927 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) {
2990 ASSERT_TRUE(test_server_.Start()); 2928 ASSERT_TRUE(test_server_.Start());
2991 2929
2992 TestDelegate d; 2930 TestDelegate d;
2993 BlockingNetworkDelegate network_delegate( 2931 BlockingNetworkDelegate network_delegate(
2994 BlockingNetworkDelegate::SYNCHRONOUS); 2932 BlockingNetworkDelegate::SYNCHRONOUS);
2995 GURL redirect_url(test_server_.GetURL("simple.html")); 2933 GURL redirect_url(test_server_.GetURL("simple.html"));
2996 network_delegate.set_redirect_url(redirect_url); 2934 network_delegate.set_redirect_url(redirect_url);
2997 2935
2998 TestURLRequestContextWithProxy context( 2936 TestURLRequestContextWithProxy context(
2999 test_server_.host_port_pair().ToString(), &network_delegate); 2937 test_server_.host_port_pair().ToString(), &network_delegate);
3000 2938
3001 { 2939 {
3002 GURL original_url(test_server_.GetURL("empty.html")); 2940 GURL original_url(test_server_.GetURL("empty.html"));
3003 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); 2941 scoped_ptr<URLRequest> r(context.CreateRequest(
2942 original_url, DEFAULT_PRIORITY, &d, NULL));
3004 2943
3005 // Quit after hitting the redirect, so can check the headers. 2944 // Quit after hitting the redirect, so can check the headers.
3006 d.set_quit_on_redirect(true); 2945 d.set_quit_on_redirect(true);
3007 r.Start(); 2946 r->Start();
3008 base::RunLoop().Run(); 2947 base::RunLoop().Run();
3009 2948
3010 // Check headers from URLRequestJob. 2949 // Check headers from URLRequestJob.
3011 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2950 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3012 EXPECT_EQ(307, r.GetResponseCode()); 2951 EXPECT_EQ(307, r->GetResponseCode());
3013 EXPECT_EQ(307, r.response_headers()->response_code()); 2952 EXPECT_EQ(307, r->response_headers()->response_code());
3014 std::string location; 2953 std::string location;
3015 ASSERT_TRUE(r.response_headers()->EnumerateHeader(NULL, "Location", 2954 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3016 &location)); 2955 &location));
3017 EXPECT_EQ(redirect_url, GURL(location)); 2956 EXPECT_EQ(redirect_url, GURL(location));
3018 2957
3019 // Let the request finish. 2958 // Let the request finish.
3020 r.FollowDeferredRedirect(); 2959 r->FollowDeferredRedirect();
3021 base::RunLoop().Run(); 2960 base::RunLoop().Run();
3022 2961
3023 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2962 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3024 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); 2963 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair()));
3025 EXPECT_EQ( 2964 EXPECT_EQ(
3026 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); 2965 1, network_delegate.observed_before_proxy_headers_sent_callbacks());
3027 EXPECT_TRUE( 2966 EXPECT_TRUE(
3028 network_delegate.last_observed_proxy().Equals( 2967 network_delegate.last_observed_proxy().Equals(
3029 test_server_.host_port_pair())); 2968 test_server_.host_port_pair()));
3030 EXPECT_EQ(0, r.status().error()); 2969 EXPECT_EQ(0, r->status().error());
3031 EXPECT_EQ(redirect_url, r.url()); 2970 EXPECT_EQ(redirect_url, r->url());
3032 EXPECT_EQ(original_url, r.original_url()); 2971 EXPECT_EQ(original_url, r->original_url());
3033 EXPECT_EQ(2U, r.url_chain().size()); 2972 EXPECT_EQ(2U, r->url_chain().size());
3034 EXPECT_EQ(1, network_delegate.created_requests()); 2973 EXPECT_EQ(1, network_delegate.created_requests());
3035 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2974 EXPECT_EQ(0, network_delegate.destroyed_requests());
3036 } 2975 }
3037 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2976 EXPECT_EQ(1, network_delegate.destroyed_requests());
3038 } 2977 }
3039 2978
3040 // Tests that redirects caused by the network delegate preserve POST data. 2979 // Tests that redirects caused by the network delegate preserve POST data.
3041 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { 2980 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) {
3042 ASSERT_TRUE(test_server_.Start()); 2981 ASSERT_TRUE(test_server_.Start());
3043 2982
3044 const char kData[] = "hello world"; 2983 const char kData[] = "hello world";
3045 2984
3046 TestDelegate d; 2985 TestDelegate d;
3047 BlockingNetworkDelegate network_delegate( 2986 BlockingNetworkDelegate network_delegate(
3048 BlockingNetworkDelegate::AUTO_CALLBACK); 2987 BlockingNetworkDelegate::AUTO_CALLBACK);
3049 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2988 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3050 GURL redirect_url(test_server_.GetURL("echo")); 2989 GURL redirect_url(test_server_.GetURL("echo"));
3051 network_delegate.set_redirect_url(redirect_url); 2990 network_delegate.set_redirect_url(redirect_url);
3052 2991
3053 TestURLRequestContext context(true); 2992 TestURLRequestContext context(true);
3054 context.set_network_delegate(&network_delegate); 2993 context.set_network_delegate(&network_delegate);
3055 context.Init(); 2994 context.Init();
3056 2995
3057 { 2996 {
3058 GURL original_url(test_server_.GetURL("empty.html")); 2997 GURL original_url(test_server_.GetURL("empty.html"));
3059 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); 2998 scoped_ptr<URLRequest> r(context.CreateRequest(
3060 r.set_method("POST"); 2999 original_url, DEFAULT_PRIORITY, &d, NULL));
3061 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 3000 r->set_method("POST");
3001 r->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
3062 HttpRequestHeaders headers; 3002 HttpRequestHeaders headers;
3063 headers.SetHeader(HttpRequestHeaders::kContentLength, 3003 headers.SetHeader(HttpRequestHeaders::kContentLength,
3064 base::UintToString(arraysize(kData) - 1)); 3004 base::UintToString(arraysize(kData) - 1));
3065 r.SetExtraRequestHeaders(headers); 3005 r->SetExtraRequestHeaders(headers);
3066 3006
3067 // Quit after hitting the redirect, so can check the headers. 3007 // Quit after hitting the redirect, so can check the headers.
3068 d.set_quit_on_redirect(true); 3008 d.set_quit_on_redirect(true);
3069 r.Start(); 3009 r->Start();
3070 base::RunLoop().Run(); 3010 base::RunLoop().Run();
3071 3011
3072 // Check headers from URLRequestJob. 3012 // Check headers from URLRequestJob.
3073 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3013 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3074 EXPECT_EQ(307, r.GetResponseCode()); 3014 EXPECT_EQ(307, r->GetResponseCode());
3075 EXPECT_EQ(307, r.response_headers()->response_code()); 3015 EXPECT_EQ(307, r->response_headers()->response_code());
3076 std::string location; 3016 std::string location;
3077 ASSERT_TRUE(r.response_headers()->EnumerateHeader(NULL, "Location", 3017 ASSERT_TRUE(r->response_headers()->EnumerateHeader(NULL, "Location",
3078 &location)); 3018 &location));
3079 EXPECT_EQ(redirect_url, GURL(location)); 3019 EXPECT_EQ(redirect_url, GURL(location));
3080 3020
3081 // Let the request finish. 3021 // Let the request finish.
3082 r.FollowDeferredRedirect(); 3022 r->FollowDeferredRedirect();
3083 base::RunLoop().Run(); 3023 base::RunLoop().Run();
3084 3024
3085 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3025 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3086 EXPECT_EQ(0, r.status().error()); 3026 EXPECT_EQ(0, r->status().error());
3087 EXPECT_EQ(redirect_url, r.url()); 3027 EXPECT_EQ(redirect_url, r->url());
3088 EXPECT_EQ(original_url, r.original_url()); 3028 EXPECT_EQ(original_url, r->original_url());
3089 EXPECT_EQ(2U, r.url_chain().size()); 3029 EXPECT_EQ(2U, r->url_chain().size());
3090 EXPECT_EQ(1, network_delegate.created_requests()); 3030 EXPECT_EQ(1, network_delegate.created_requests());
3091 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3031 EXPECT_EQ(0, network_delegate.destroyed_requests());
3092 EXPECT_EQ("POST", r.method()); 3032 EXPECT_EQ("POST", r->method());
3093 EXPECT_EQ(kData, d.data_received()); 3033 EXPECT_EQ(kData, d.data_received());
3094 } 3034 }
3095 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3035 EXPECT_EQ(1, network_delegate.destroyed_requests());
3096 } 3036 }
3097 3037
3098 // Tests that the network delegate can block and redirect a request to a new 3038 // Tests that the network delegate can block and redirect a request to a new
3099 // URL during OnHeadersReceived. 3039 // URL during OnHeadersReceived.
3100 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { 3040 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) {
3101 ASSERT_TRUE(test_server_.Start()); 3041 ASSERT_TRUE(test_server_.Start());
3102 3042
3103 TestDelegate d; 3043 TestDelegate d;
3104 BlockingNetworkDelegate network_delegate( 3044 BlockingNetworkDelegate network_delegate(
3105 BlockingNetworkDelegate::AUTO_CALLBACK); 3045 BlockingNetworkDelegate::AUTO_CALLBACK);
3106 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3046 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3107 GURL redirect_url(test_server_.GetURL("simple.html")); 3047 GURL redirect_url(test_server_.GetURL("simple.html"));
3108 network_delegate.set_redirect_on_headers_received_url(redirect_url); 3048 network_delegate.set_redirect_on_headers_received_url(redirect_url);
3109 3049
3110 TestURLRequestContextWithProxy context( 3050 TestURLRequestContextWithProxy context(
3111 test_server_.host_port_pair().ToString(), &network_delegate); 3051 test_server_.host_port_pair().ToString(), &network_delegate);
3112 3052
3113 { 3053 {
3114 GURL original_url(test_server_.GetURL("empty.html")); 3054 GURL original_url(test_server_.GetURL("empty.html"));
3115 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); 3055 scoped_ptr<URLRequest> r(context.CreateRequest(
3056 original_url, DEFAULT_PRIORITY, &d, NULL));
3116 3057
3117 r.Start(); 3058 r->Start();
3118 base::RunLoop().Run(); 3059 base::RunLoop().Run();
3119 3060
3120 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3061 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3121 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); 3062 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair()));
3122 EXPECT_EQ( 3063 EXPECT_EQ(
3123 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); 3064 2, network_delegate.observed_before_proxy_headers_sent_callbacks());
3124 EXPECT_TRUE( 3065 EXPECT_TRUE(
3125 network_delegate.last_observed_proxy().Equals( 3066 network_delegate.last_observed_proxy().Equals(
3126 test_server_.host_port_pair())); 3067 test_server_.host_port_pair()));
3127 EXPECT_EQ(OK, r.status().error()); 3068
3128 EXPECT_EQ(redirect_url, r.url()); 3069 EXPECT_EQ(OK, r->status().error());
3129 EXPECT_EQ(original_url, r.original_url()); 3070 EXPECT_EQ(redirect_url, r->url());
3130 EXPECT_EQ(2U, r.url_chain().size()); 3071 EXPECT_EQ(original_url, r->original_url());
3072 EXPECT_EQ(2U, r->url_chain().size());
3131 EXPECT_EQ(2, network_delegate.created_requests()); 3073 EXPECT_EQ(2, network_delegate.created_requests());
3132 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3074 EXPECT_EQ(0, network_delegate.destroyed_requests());
3133 } 3075 }
3134 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3076 EXPECT_EQ(1, network_delegate.destroyed_requests());
3135 } 3077 }
3136 3078
3137 // Tests that the network delegate can synchronously complete OnAuthRequired 3079 // Tests that the network delegate can synchronously complete OnAuthRequired
3138 // by taking no action. This indicates that the NetworkDelegate does not want to 3080 // by taking no action. This indicates that the NetworkDelegate does not want to
3139 // handle the challenge, and is passing the buck along to the 3081 // handle the challenge, and is passing the buck along to the
3140 // URLRequest::Delegate. 3082 // URLRequest::Delegate.
3141 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { 3083 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) {
3142 ASSERT_TRUE(test_server_.Start()); 3084 ASSERT_TRUE(test_server_.Start());
3143 3085
3144 TestDelegate d; 3086 TestDelegate d;
3145 BlockingNetworkDelegate network_delegate( 3087 BlockingNetworkDelegate network_delegate(
3146 BlockingNetworkDelegate::SYNCHRONOUS); 3088 BlockingNetworkDelegate::SYNCHRONOUS);
3147 3089
3148 TestURLRequestContext context(true); 3090 TestURLRequestContext context(true);
3149 context.set_network_delegate(&network_delegate); 3091 context.set_network_delegate(&network_delegate);
3150 context.Init(); 3092 context.Init();
3151 3093
3152 d.set_credentials(AuthCredentials(kUser, kSecret)); 3094 d.set_credentials(AuthCredentials(kUser, kSecret));
3153 3095
3154 { 3096 {
3155 GURL url(test_server_.GetURL("auth-basic")); 3097 GURL url(test_server_.GetURL("auth-basic"));
3156 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3098 scoped_ptr<URLRequest> r(context.CreateRequest(
3157 r.Start(); 3099 url, DEFAULT_PRIORITY, &d, NULL));
3100 r->Start();
3158 3101
3159 base::RunLoop().Run(); 3102 base::RunLoop().Run();
3160 3103
3161 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3104 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3162 EXPECT_EQ(0, r.status().error()); 3105 EXPECT_EQ(0, r->status().error());
3163 EXPECT_EQ(200, r.GetResponseCode()); 3106 EXPECT_EQ(200, r->GetResponseCode());
3164 EXPECT_TRUE(d.auth_required_called()); 3107 EXPECT_TRUE(d.auth_required_called());
3165 EXPECT_EQ(1, network_delegate.created_requests()); 3108 EXPECT_EQ(1, network_delegate.created_requests());
3166 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3109 EXPECT_EQ(0, network_delegate.destroyed_requests());
3167 } 3110 }
3168 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3111 EXPECT_EQ(1, network_delegate.destroyed_requests());
3169 } 3112 }
3170 3113
3171 TEST_F(URLRequestTestHTTP, 3114 TEST_F(URLRequestTestHTTP,
3172 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { 3115 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) {
3173 ASSERT_TRUE(test_server_.Start()); 3116 ASSERT_TRUE(test_server_.Start());
3174 3117
3175 TestDelegate d; 3118 TestDelegate d;
3176 BlockingNetworkDelegate network_delegate( 3119 BlockingNetworkDelegate network_delegate(
3177 BlockingNetworkDelegate::SYNCHRONOUS); 3120 BlockingNetworkDelegate::SYNCHRONOUS);
3178 3121
3179 TestURLRequestContext context(true); 3122 TestURLRequestContext context(true);
3180 context.set_network_delegate(&network_delegate); 3123 context.set_network_delegate(&network_delegate);
3181 context.Init(); 3124 context.Init();
3182 3125
3183 d.set_credentials(AuthCredentials(kUser, kSecret)); 3126 d.set_credentials(AuthCredentials(kUser, kSecret));
3184 3127
3185 { 3128 {
3186 GURL url(test_server_.GetURL("auth-basic")); 3129 GURL url(test_server_.GetURL("auth-basic"));
3187 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3130 scoped_ptr<URLRequest> r(context.CreateRequest(
3188 r.Start(); 3131 url, DEFAULT_PRIORITY, &d, NULL));
3132 r->Start();
3189 3133
3190 { 3134 {
3191 HttpRequestHeaders headers; 3135 HttpRequestHeaders headers;
3192 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); 3136 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3193 EXPECT_FALSE(headers.HasHeader("Authorization")); 3137 EXPECT_FALSE(headers.HasHeader("Authorization"));
3194 } 3138 }
3195 3139
3196 base::RunLoop().Run(); 3140 base::RunLoop().Run();
3197 3141
3198 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3142 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3199 EXPECT_EQ(0, r.status().error()); 3143 EXPECT_EQ(0, r->status().error());
3200 EXPECT_EQ(200, r.GetResponseCode()); 3144 EXPECT_EQ(200, r->GetResponseCode());
3201 EXPECT_TRUE(d.auth_required_called()); 3145 EXPECT_TRUE(d.auth_required_called());
3202 EXPECT_EQ(1, network_delegate.created_requests()); 3146 EXPECT_EQ(1, network_delegate.created_requests());
3203 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3147 EXPECT_EQ(0, network_delegate.destroyed_requests());
3204 } 3148 }
3205 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3149 EXPECT_EQ(1, network_delegate.destroyed_requests());
3206 } 3150 }
3207 3151
3208 // Tests that the network delegate can synchronously complete OnAuthRequired 3152 // Tests that the network delegate can synchronously complete OnAuthRequired
3209 // by setting credentials. 3153 // by setting credentials.
3210 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { 3154 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) {
3211 ASSERT_TRUE(test_server_.Start()); 3155 ASSERT_TRUE(test_server_.Start());
3212 3156
3213 TestDelegate d; 3157 TestDelegate d;
3214 BlockingNetworkDelegate network_delegate( 3158 BlockingNetworkDelegate network_delegate(
3215 BlockingNetworkDelegate::SYNCHRONOUS); 3159 BlockingNetworkDelegate::SYNCHRONOUS);
3216 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3160 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3217 network_delegate.set_auth_retval( 3161 network_delegate.set_auth_retval(
3218 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3162 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
3219 3163
3220 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3164 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
3221 3165
3222 TestURLRequestContext context(true); 3166 TestURLRequestContext context(true);
3223 context.set_network_delegate(&network_delegate); 3167 context.set_network_delegate(&network_delegate);
3224 context.Init(); 3168 context.Init();
3225 3169
3226 { 3170 {
3227 GURL url(test_server_.GetURL("auth-basic")); 3171 GURL url(test_server_.GetURL("auth-basic"));
3228 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3172 scoped_ptr<URLRequest> r(context.CreateRequest(
3229 r.Start(); 3173 url, DEFAULT_PRIORITY, &d, NULL));
3174 r->Start();
3230 base::RunLoop().Run(); 3175 base::RunLoop().Run();
3231 3176
3232 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3177 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3233 EXPECT_EQ(0, r.status().error()); 3178 EXPECT_EQ(0, r->status().error());
3234 EXPECT_EQ(200, r.GetResponseCode()); 3179 EXPECT_EQ(200, r->GetResponseCode());
3235 EXPECT_FALSE(d.auth_required_called()); 3180 EXPECT_FALSE(d.auth_required_called());
3236 EXPECT_EQ(1, network_delegate.created_requests()); 3181 EXPECT_EQ(1, network_delegate.created_requests());
3237 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3182 EXPECT_EQ(0, network_delegate.destroyed_requests());
3238 } 3183 }
3239 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3184 EXPECT_EQ(1, network_delegate.destroyed_requests());
3240 } 3185 }
3241 3186
3242 // Same as above, but also tests that GetFullRequestHeaders returns the proper 3187 // Same as above, but also tests that GetFullRequestHeaders returns the proper
3243 // headers (for the first or second request) when called at the proper times. 3188 // headers (for the first or second request) when called at the proper times.
3244 TEST_F(URLRequestTestHTTP, 3189 TEST_F(URLRequestTestHTTP,
3245 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { 3190 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) {
3246 ASSERT_TRUE(test_server_.Start()); 3191 ASSERT_TRUE(test_server_.Start());
3247 3192
3248 TestDelegate d; 3193 TestDelegate d;
3249 BlockingNetworkDelegate network_delegate( 3194 BlockingNetworkDelegate network_delegate(
3250 BlockingNetworkDelegate::SYNCHRONOUS); 3195 BlockingNetworkDelegate::SYNCHRONOUS);
3251 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3196 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3252 network_delegate.set_auth_retval( 3197 network_delegate.set_auth_retval(
3253 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3198 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
3254 3199
3255 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3200 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
3256 3201
3257 TestURLRequestContext context(true); 3202 TestURLRequestContext context(true);
3258 context.set_network_delegate(&network_delegate); 3203 context.set_network_delegate(&network_delegate);
3259 context.Init(); 3204 context.Init();
3260 3205
3261 { 3206 {
3262 GURL url(test_server_.GetURL("auth-basic")); 3207 GURL url(test_server_.GetURL("auth-basic"));
3263 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3208 scoped_ptr<URLRequest> r(context.CreateRequest(
3264 r.Start(); 3209 url, DEFAULT_PRIORITY, &d, NULL));
3210 r->Start();
3265 base::RunLoop().Run(); 3211 base::RunLoop().Run();
3266 3212
3267 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3213 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3268 EXPECT_EQ(0, r.status().error()); 3214 EXPECT_EQ(0, r->status().error());
3269 EXPECT_EQ(200, r.GetResponseCode()); 3215 EXPECT_EQ(200, r->GetResponseCode());
3270 EXPECT_FALSE(d.auth_required_called()); 3216 EXPECT_FALSE(d.auth_required_called());
3271 EXPECT_EQ(1, network_delegate.created_requests()); 3217 EXPECT_EQ(1, network_delegate.created_requests());
3272 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3218 EXPECT_EQ(0, network_delegate.destroyed_requests());
3273 3219
3274 { 3220 {
3275 HttpRequestHeaders headers; 3221 HttpRequestHeaders headers;
3276 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); 3222 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3277 EXPECT_TRUE(headers.HasHeader("Authorization")); 3223 EXPECT_TRUE(headers.HasHeader("Authorization"));
3278 } 3224 }
3279 } 3225 }
3280 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3226 EXPECT_EQ(1, network_delegate.destroyed_requests());
3281 } 3227 }
3282 3228
3283 // Tests that the network delegate can synchronously complete OnAuthRequired 3229 // Tests that the network delegate can synchronously complete OnAuthRequired
3284 // by cancelling authentication. 3230 // by cancelling authentication.
3285 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { 3231 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) {
3286 ASSERT_TRUE(test_server_.Start()); 3232 ASSERT_TRUE(test_server_.Start());
3287 3233
3288 TestDelegate d; 3234 TestDelegate d;
3289 BlockingNetworkDelegate network_delegate( 3235 BlockingNetworkDelegate network_delegate(
3290 BlockingNetworkDelegate::SYNCHRONOUS); 3236 BlockingNetworkDelegate::SYNCHRONOUS);
3291 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3237 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3292 network_delegate.set_auth_retval( 3238 network_delegate.set_auth_retval(
3293 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3239 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3294 3240
3295 TestURLRequestContext context(true); 3241 TestURLRequestContext context(true);
3296 context.set_network_delegate(&network_delegate); 3242 context.set_network_delegate(&network_delegate);
3297 context.Init(); 3243 context.Init();
3298 3244
3299 { 3245 {
3300 GURL url(test_server_.GetURL("auth-basic")); 3246 GURL url(test_server_.GetURL("auth-basic"));
3301 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3247 scoped_ptr<URLRequest> r(context.CreateRequest(
3302 r.Start(); 3248 url, DEFAULT_PRIORITY, &d, NULL));
3249 r->Start();
3303 base::RunLoop().Run(); 3250 base::RunLoop().Run();
3304 3251
3305 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3252 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3306 EXPECT_EQ(OK, r.status().error()); 3253 EXPECT_EQ(OK, r->status().error());
3307 EXPECT_EQ(401, r.GetResponseCode()); 3254 EXPECT_EQ(401, r->GetResponseCode());
3308 EXPECT_FALSE(d.auth_required_called()); 3255 EXPECT_FALSE(d.auth_required_called());
3309 EXPECT_EQ(1, network_delegate.created_requests()); 3256 EXPECT_EQ(1, network_delegate.created_requests());
3310 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3257 EXPECT_EQ(0, network_delegate.destroyed_requests());
3311 } 3258 }
3312 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3259 EXPECT_EQ(1, network_delegate.destroyed_requests());
3313 } 3260 }
3314 3261
3315 // Tests that the network delegate can asynchronously complete OnAuthRequired 3262 // Tests that the network delegate can asynchronously complete OnAuthRequired
3316 // by taking no action. This indicates that the NetworkDelegate does not want 3263 // by taking no action. This indicates that the NetworkDelegate does not want
3317 // to handle the challenge, and is passing the buck along to the 3264 // to handle the challenge, and is passing the buck along to the
3318 // URLRequest::Delegate. 3265 // URLRequest::Delegate.
3319 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { 3266 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) {
3320 ASSERT_TRUE(test_server_.Start()); 3267 ASSERT_TRUE(test_server_.Start());
3321 3268
3322 TestDelegate d; 3269 TestDelegate d;
3323 BlockingNetworkDelegate network_delegate( 3270 BlockingNetworkDelegate network_delegate(
3324 BlockingNetworkDelegate::AUTO_CALLBACK); 3271 BlockingNetworkDelegate::AUTO_CALLBACK);
3325 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3272 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3326 3273
3327 TestURLRequestContext context(true); 3274 TestURLRequestContext context(true);
3328 context.set_network_delegate(&network_delegate); 3275 context.set_network_delegate(&network_delegate);
3329 context.Init(); 3276 context.Init();
3330 3277
3331 d.set_credentials(AuthCredentials(kUser, kSecret)); 3278 d.set_credentials(AuthCredentials(kUser, kSecret));
3332 3279
3333 { 3280 {
3334 GURL url(test_server_.GetURL("auth-basic")); 3281 GURL url(test_server_.GetURL("auth-basic"));
3335 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3282 scoped_ptr<URLRequest> r(context.CreateRequest(
3336 r.Start(); 3283 url, DEFAULT_PRIORITY, &d, NULL));
3284 r->Start();
3337 base::RunLoop().Run(); 3285 base::RunLoop().Run();
3338 3286
3339 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3287 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3340 EXPECT_EQ(0, r.status().error()); 3288 EXPECT_EQ(0, r->status().error());
3341 EXPECT_EQ(200, r.GetResponseCode()); 3289 EXPECT_EQ(200, r->GetResponseCode());
3342 EXPECT_TRUE(d.auth_required_called()); 3290 EXPECT_TRUE(d.auth_required_called());
3343 EXPECT_EQ(1, network_delegate.created_requests()); 3291 EXPECT_EQ(1, network_delegate.created_requests());
3344 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3292 EXPECT_EQ(0, network_delegate.destroyed_requests());
3345 } 3293 }
3346 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3294 EXPECT_EQ(1, network_delegate.destroyed_requests());
3347 } 3295 }
3348 3296
3349 // Tests that the network delegate can asynchronously complete OnAuthRequired 3297 // Tests that the network delegate can asynchronously complete OnAuthRequired
3350 // by setting credentials. 3298 // by setting credentials.
3351 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { 3299 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) {
3352 ASSERT_TRUE(test_server_.Start()); 3300 ASSERT_TRUE(test_server_.Start());
3353 3301
3354 TestDelegate d; 3302 TestDelegate d;
3355 BlockingNetworkDelegate network_delegate( 3303 BlockingNetworkDelegate network_delegate(
3356 BlockingNetworkDelegate::AUTO_CALLBACK); 3304 BlockingNetworkDelegate::AUTO_CALLBACK);
3357 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3305 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3358 network_delegate.set_auth_retval( 3306 network_delegate.set_auth_retval(
3359 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3307 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
3360 3308
3361 AuthCredentials auth_credentials(kUser, kSecret); 3309 AuthCredentials auth_credentials(kUser, kSecret);
3362 network_delegate.set_auth_credentials(auth_credentials); 3310 network_delegate.set_auth_credentials(auth_credentials);
3363 3311
3364 TestURLRequestContext context(true); 3312 TestURLRequestContext context(true);
3365 context.set_network_delegate(&network_delegate); 3313 context.set_network_delegate(&network_delegate);
3366 context.Init(); 3314 context.Init();
3367 3315
3368 { 3316 {
3369 GURL url(test_server_.GetURL("auth-basic")); 3317 GURL url(test_server_.GetURL("auth-basic"));
3370 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3318 scoped_ptr<URLRequest> r(context.CreateRequest(
3371 r.Start(); 3319 url, DEFAULT_PRIORITY, &d, NULL));
3320 r->Start();
3372 base::RunLoop().Run(); 3321 base::RunLoop().Run();
3373 3322
3374 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3323 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3375 EXPECT_EQ(0, r.status().error()); 3324 EXPECT_EQ(0, r->status().error());
3376 3325
3377 EXPECT_EQ(200, r.GetResponseCode()); 3326 EXPECT_EQ(200, r->GetResponseCode());
3378 EXPECT_FALSE(d.auth_required_called()); 3327 EXPECT_FALSE(d.auth_required_called());
3379 EXPECT_EQ(1, network_delegate.created_requests()); 3328 EXPECT_EQ(1, network_delegate.created_requests());
3380 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3329 EXPECT_EQ(0, network_delegate.destroyed_requests());
3381 } 3330 }
3382 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3331 EXPECT_EQ(1, network_delegate.destroyed_requests());
3383 } 3332 }
3384 3333
3385 // Tests that the network delegate can asynchronously complete OnAuthRequired 3334 // Tests that the network delegate can asynchronously complete OnAuthRequired
3386 // by cancelling authentication. 3335 // by cancelling authentication.
3387 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { 3336 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) {
3388 ASSERT_TRUE(test_server_.Start()); 3337 ASSERT_TRUE(test_server_.Start());
3389 3338
3390 TestDelegate d; 3339 TestDelegate d;
3391 BlockingNetworkDelegate network_delegate( 3340 BlockingNetworkDelegate network_delegate(
3392 BlockingNetworkDelegate::AUTO_CALLBACK); 3341 BlockingNetworkDelegate::AUTO_CALLBACK);
3393 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3342 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3394 network_delegate.set_auth_retval( 3343 network_delegate.set_auth_retval(
3395 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3344 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3396 3345
3397 TestURLRequestContext context(true); 3346 TestURLRequestContext context(true);
3398 context.set_network_delegate(&network_delegate); 3347 context.set_network_delegate(&network_delegate);
3399 context.Init(); 3348 context.Init();
3400 3349
3401 { 3350 {
3402 GURL url(test_server_.GetURL("auth-basic")); 3351 GURL url(test_server_.GetURL("auth-basic"));
3403 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); 3352 scoped_ptr<URLRequest> r(context.CreateRequest(
3404 r.Start(); 3353 url, DEFAULT_PRIORITY, &d, NULL));
3354 r->Start();
3405 base::RunLoop().Run(); 3355 base::RunLoop().Run();
3406 3356
3407 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3357 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3408 EXPECT_EQ(OK, r.status().error()); 3358 EXPECT_EQ(OK, r->status().error());
3409 EXPECT_EQ(401, r.GetResponseCode()); 3359 EXPECT_EQ(401, r->GetResponseCode());
3410 EXPECT_FALSE(d.auth_required_called()); 3360 EXPECT_FALSE(d.auth_required_called());
3411 EXPECT_EQ(1, network_delegate.created_requests()); 3361 EXPECT_EQ(1, network_delegate.created_requests());
3412 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3362 EXPECT_EQ(0, network_delegate.destroyed_requests());
3413 } 3363 }
3414 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3364 EXPECT_EQ(1, network_delegate.destroyed_requests());
3415 } 3365 }
3416 3366
3417 // Tests that we can handle when a network request was canceled while we were 3367 // Tests that we can handle when a network request was canceled while we were
3418 // waiting for the network delegate. 3368 // waiting for the network delegate.
3419 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. 3369 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback.
3420 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { 3370 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) {
3421 ASSERT_TRUE(test_server_.Start()); 3371 ASSERT_TRUE(test_server_.Start());
3422 3372
3423 TestDelegate d; 3373 TestDelegate d;
3424 BlockingNetworkDelegate network_delegate( 3374 BlockingNetworkDelegate network_delegate(
3425 BlockingNetworkDelegate::USER_CALLBACK); 3375 BlockingNetworkDelegate::USER_CALLBACK);
3426 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3376 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3427 3377
3428 TestURLRequestContext context(true); 3378 TestURLRequestContext context(true);
3429 context.set_network_delegate(&network_delegate); 3379 context.set_network_delegate(&network_delegate);
3430 context.Init(); 3380 context.Init();
3431 3381
3432 { 3382 {
3433 URLRequest r( 3383 scoped_ptr<URLRequest> r(context.CreateRequest(
3434 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); 3384 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3435 3385
3436 r.Start(); 3386 r->Start();
3437 base::RunLoop().Run(); 3387 base::RunLoop().Run();
3438 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 3388 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
3439 network_delegate.stage_blocked_for_callback()); 3389 network_delegate.stage_blocked_for_callback());
3440 EXPECT_EQ(0, network_delegate.completed_requests()); 3390 EXPECT_EQ(0, network_delegate.completed_requests());
3441 // Cancel before callback. 3391 // Cancel before callback.
3442 r.Cancel(); 3392 r->Cancel();
3443 // Ensure that network delegate is notified. 3393 // Ensure that network delegate is notified.
3444 EXPECT_EQ(1, network_delegate.completed_requests()); 3394 EXPECT_EQ(1, network_delegate.completed_requests());
3445 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3395 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
3446 EXPECT_EQ(ERR_ABORTED, r.status().error()); 3396 EXPECT_EQ(ERR_ABORTED, r->status().error());
3447 EXPECT_EQ(1, network_delegate.created_requests()); 3397 EXPECT_EQ(1, network_delegate.created_requests());
3448 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3398 EXPECT_EQ(0, network_delegate.destroyed_requests());
3449 } 3399 }
3450 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3400 EXPECT_EQ(1, network_delegate.destroyed_requests());
3451 } 3401 }
3452 3402
3453 // Tests that we can handle when a network request was canceled while we were 3403 // Tests that we can handle when a network request was canceled while we were
3454 // waiting for the network delegate. 3404 // waiting for the network delegate.
3455 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. 3405 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback.
3456 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { 3406 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) {
3457 ASSERT_TRUE(test_server_.Start()); 3407 ASSERT_TRUE(test_server_.Start());
3458 3408
3459 TestDelegate d; 3409 TestDelegate d;
3460 BlockingNetworkDelegate network_delegate( 3410 BlockingNetworkDelegate network_delegate(
3461 BlockingNetworkDelegate::USER_CALLBACK); 3411 BlockingNetworkDelegate::USER_CALLBACK);
3462 network_delegate.set_block_on( 3412 network_delegate.set_block_on(
3463 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); 3413 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS);
3464 3414
3465 TestURLRequestContext context(true); 3415 TestURLRequestContext context(true);
3466 context.set_network_delegate(&network_delegate); 3416 context.set_network_delegate(&network_delegate);
3467 context.Init(); 3417 context.Init();
3468 3418
3469 { 3419 {
3470 URLRequest r( 3420 scoped_ptr<URLRequest> r(context.CreateRequest(
3471 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); 3421 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3472 3422
3473 r.Start(); 3423 r->Start();
3474 base::RunLoop().Run(); 3424 base::RunLoop().Run();
3475 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 3425 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
3476 network_delegate.stage_blocked_for_callback()); 3426 network_delegate.stage_blocked_for_callback());
3477 EXPECT_EQ(0, network_delegate.completed_requests()); 3427 EXPECT_EQ(0, network_delegate.completed_requests());
3478 // Cancel before callback. 3428 // Cancel before callback.
3479 r.Cancel(); 3429 r->Cancel();
3480 // Ensure that network delegate is notified. 3430 // Ensure that network delegate is notified.
3481 EXPECT_EQ(1, network_delegate.completed_requests()); 3431 EXPECT_EQ(1, network_delegate.completed_requests());
3482 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3432 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
3483 EXPECT_EQ(ERR_ABORTED, r.status().error()); 3433 EXPECT_EQ(ERR_ABORTED, r->status().error());
3484 EXPECT_EQ(1, network_delegate.created_requests()); 3434 EXPECT_EQ(1, network_delegate.created_requests());
3485 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3435 EXPECT_EQ(0, network_delegate.destroyed_requests());
3486 } 3436 }
3487 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3437 EXPECT_EQ(1, network_delegate.destroyed_requests());
3488 } 3438 }
3489 3439
3490 // Tests that we can handle when a network request was canceled while we were 3440 // Tests that we can handle when a network request was canceled while we were
3491 // waiting for the network delegate. 3441 // waiting for the network delegate.
3492 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. 3442 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback.
3493 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { 3443 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) {
3494 ASSERT_TRUE(test_server_.Start()); 3444 ASSERT_TRUE(test_server_.Start());
3495 3445
3496 TestDelegate d; 3446 TestDelegate d;
3497 BlockingNetworkDelegate network_delegate( 3447 BlockingNetworkDelegate network_delegate(
3498 BlockingNetworkDelegate::USER_CALLBACK); 3448 BlockingNetworkDelegate::USER_CALLBACK);
3499 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3449 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3500 3450
3501 TestURLRequestContext context(true); 3451 TestURLRequestContext context(true);
3502 context.set_network_delegate(&network_delegate); 3452 context.set_network_delegate(&network_delegate);
3503 context.Init(); 3453 context.Init();
3504 3454
3505 { 3455 {
3506 URLRequest r( 3456 scoped_ptr<URLRequest> r(context.CreateRequest(
3507 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); 3457 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3508 3458
3509 r.Start(); 3459 r->Start();
3510 base::RunLoop().Run(); 3460 base::RunLoop().Run();
3511 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 3461 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
3512 network_delegate.stage_blocked_for_callback()); 3462 network_delegate.stage_blocked_for_callback());
3513 EXPECT_EQ(0, network_delegate.completed_requests()); 3463 EXPECT_EQ(0, network_delegate.completed_requests());
3514 // Cancel before callback. 3464 // Cancel before callback.
3515 r.Cancel(); 3465 r->Cancel();
3516 // Ensure that network delegate is notified. 3466 // Ensure that network delegate is notified.
3517 EXPECT_EQ(1, network_delegate.completed_requests()); 3467 EXPECT_EQ(1, network_delegate.completed_requests());
3518 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3468 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
3519 EXPECT_EQ(ERR_ABORTED, r.status().error()); 3469 EXPECT_EQ(ERR_ABORTED, r->status().error());
3520 EXPECT_EQ(1, network_delegate.created_requests()); 3470 EXPECT_EQ(1, network_delegate.created_requests());
3521 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3471 EXPECT_EQ(0, network_delegate.destroyed_requests());
3522 } 3472 }
3523 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3473 EXPECT_EQ(1, network_delegate.destroyed_requests());
3524 } 3474 }
3525 3475
3526 // Tests that we can handle when a network request was canceled while we were 3476 // Tests that we can handle when a network request was canceled while we were
3527 // waiting for the network delegate. 3477 // waiting for the network delegate.
3528 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. 3478 // Part 4: Request is cancelled while waiting for OnAuthRequired callback.
3529 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { 3479 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) {
3530 ASSERT_TRUE(test_server_.Start()); 3480 ASSERT_TRUE(test_server_.Start());
3531 3481
3532 TestDelegate d; 3482 TestDelegate d;
3533 BlockingNetworkDelegate network_delegate( 3483 BlockingNetworkDelegate network_delegate(
3534 BlockingNetworkDelegate::USER_CALLBACK); 3484 BlockingNetworkDelegate::USER_CALLBACK);
3535 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3485 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3536 3486
3537 TestURLRequestContext context(true); 3487 TestURLRequestContext context(true);
3538 context.set_network_delegate(&network_delegate); 3488 context.set_network_delegate(&network_delegate);
3539 context.Init(); 3489 context.Init();
3540 3490
3541 { 3491 {
3542 URLRequest r( 3492 scoped_ptr<URLRequest> r(context.CreateRequest(
3543 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, &context); 3493 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL));
3544 3494
3545 r.Start(); 3495 r->Start();
3546 base::RunLoop().Run(); 3496 base::RunLoop().Run();
3547 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, 3497 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED,
3548 network_delegate.stage_blocked_for_callback()); 3498 network_delegate.stage_blocked_for_callback());
3549 EXPECT_EQ(0, network_delegate.completed_requests()); 3499 EXPECT_EQ(0, network_delegate.completed_requests());
3550 // Cancel before callback. 3500 // Cancel before callback.
3551 r.Cancel(); 3501 r->Cancel();
3552 // Ensure that network delegate is notified. 3502 // Ensure that network delegate is notified.
3553 EXPECT_EQ(1, network_delegate.completed_requests()); 3503 EXPECT_EQ(1, network_delegate.completed_requests());
3554 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3504 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
3555 EXPECT_EQ(ERR_ABORTED, r.status().error()); 3505 EXPECT_EQ(ERR_ABORTED, r->status().error());
3556 EXPECT_EQ(1, network_delegate.created_requests()); 3506 EXPECT_EQ(1, network_delegate.created_requests());
3557 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3507 EXPECT_EQ(0, network_delegate.destroyed_requests());
3558 } 3508 }
3559 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3509 EXPECT_EQ(1, network_delegate.destroyed_requests());
3560 } 3510 }
3561 3511
3562 // In this unit test, we're using the HTTPTestServer as a proxy server and 3512 // In this unit test, we're using the HTTPTestServer as a proxy server and
3563 // issuing a CONNECT request with the magic host name "www.server-auth.com". 3513 // issuing a CONNECT request with the magic host name "www.server-auth.com".
3564 // The HTTPTestServer will return a 401 response, which we should balk at. 3514 // The HTTPTestServer will return a 401 response, which we should balk at.
3565 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 3515 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
3566 ASSERT_TRUE(test_server_.Start()); 3516 ASSERT_TRUE(test_server_.Start());
3567 3517
3568 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3518 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3569 TestURLRequestContextWithProxy context( 3519 TestURLRequestContextWithProxy context(
3570 test_server_.host_port_pair().ToString(), &network_delegate); 3520 test_server_.host_port_pair().ToString(), &network_delegate);
3571 3521
3572 TestDelegate d; 3522 TestDelegate d;
3573 { 3523 {
3574 URLRequest r( 3524 scoped_ptr<URLRequest> r(context.CreateRequest(
3575 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, &context); 3525 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, NULL));
3576 3526
3577 r.Start(); 3527 r->Start();
3578 EXPECT_TRUE(r.is_pending()); 3528 EXPECT_TRUE(r->is_pending());
3579 3529
3580 base::RunLoop().Run(); 3530 base::RunLoop().Run();
3581 3531
3582 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 3532 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3583 // The proxy server is not set before failure. 3533 // The proxy server is not set before failure.
3584 EXPECT_TRUE(r.proxy_server().IsEmpty()); 3534 EXPECT_TRUE(r->proxy_server().IsEmpty());
3585 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 3535 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
3586 } 3536 }
3587 } 3537 }
3588 3538
3589 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 3539 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
3590 ASSERT_TRUE(test_server_.Start()); 3540 ASSERT_TRUE(test_server_.Start());
3591 3541
3592 TestDelegate d; 3542 TestDelegate d;
3593 { 3543 {
3594 URLRequest r(test_server_.GetURL(std::string()), 3544 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3595 DEFAULT_PRIORITY, 3545 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3596 &d,
3597 &default_context_);
3598 3546
3599 r.Start(); 3547 r->Start();
3600 EXPECT_TRUE(r.is_pending()); 3548 EXPECT_TRUE(r->is_pending());
3601 3549
3602 base::RunLoop().Run(); 3550 base::RunLoop().Run();
3603 3551
3604 EXPECT_EQ(1, d.response_started_count()); 3552 EXPECT_EQ(1, d.response_started_count());
3605 EXPECT_FALSE(d.received_data_before_response()); 3553 EXPECT_FALSE(d.received_data_before_response());
3606 EXPECT_NE(0, d.bytes_received()); 3554 EXPECT_NE(0, d.bytes_received());
3607 EXPECT_EQ(test_server_.host_port_pair().host(), 3555 EXPECT_EQ(test_server_.host_port_pair().host(),
3608 r.GetSocketAddress().host()); 3556 r->GetSocketAddress().host());
3609 EXPECT_EQ(test_server_.host_port_pair().port(), 3557 EXPECT_EQ(test_server_.host_port_pair().port(),
3610 r.GetSocketAddress().port()); 3558 r->GetSocketAddress().port());
3611 3559
3612 // TODO(eroman): Add back the NetLog tests... 3560 // TODO(eroman): Add back the NetLog tests...
3613 } 3561 }
3614 } 3562 }
3615 3563
3616 // This test has the server send a large number of cookies to the client. 3564 // This test has the server send a large number of cookies to the client.
3617 // To ensure that no number of cookies causes a crash, a galloping binary 3565 // To ensure that no number of cookies causes a crash, a galloping binary
3618 // search is used to estimate that maximum number of cookies that are accepted 3566 // search is used to estimate that maximum number of cookies that are accepted
3619 // by the browser. Beyond the maximum number, the request will fail with 3567 // by the browser. Beyond the maximum number, the request will fail with
3620 // ERR_RESPONSE_HEADERS_TOO_BIG. 3568 // ERR_RESPONSE_HEADERS_TOO_BIG.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 upper_bound = num_cookies; 3601 upper_bound = num_cookies;
3654 } 3602 }
3655 // Success: the test did not crash. 3603 // Success: the test did not crash.
3656 } 3604 }
3657 3605
3658 TEST_F(URLRequestTestHTTP, GetTest) { 3606 TEST_F(URLRequestTestHTTP, GetTest) {
3659 ASSERT_TRUE(test_server_.Start()); 3607 ASSERT_TRUE(test_server_.Start());
3660 3608
3661 TestDelegate d; 3609 TestDelegate d;
3662 { 3610 {
3663 URLRequest r(test_server_.GetURL(std::string()), 3611 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3664 DEFAULT_PRIORITY, 3612 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3665 &d,
3666 &default_context_);
3667 3613
3668 r.Start(); 3614 r->Start();
3669 EXPECT_TRUE(r.is_pending()); 3615 EXPECT_TRUE(r->is_pending());
3670 3616
3671 base::RunLoop().Run(); 3617 base::RunLoop().Run();
3672 3618
3673 EXPECT_EQ(1, d.response_started_count()); 3619 EXPECT_EQ(1, d.response_started_count());
3674 EXPECT_FALSE(d.received_data_before_response()); 3620 EXPECT_FALSE(d.received_data_before_response());
3675 EXPECT_NE(0, d.bytes_received()); 3621 EXPECT_NE(0, d.bytes_received());
3676 EXPECT_EQ(test_server_.host_port_pair().host(), 3622 EXPECT_EQ(test_server_.host_port_pair().host(),
3677 r.GetSocketAddress().host()); 3623 r->GetSocketAddress().host());
3678 EXPECT_EQ(test_server_.host_port_pair().port(), 3624 EXPECT_EQ(test_server_.host_port_pair().port(),
3679 r.GetSocketAddress().port()); 3625 r->GetSocketAddress().port());
3680 } 3626 }
3681 } 3627 }
3682 3628
3683 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { 3629 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) {
3684 ASSERT_TRUE(test_server_.Start()); 3630 ASSERT_TRUE(test_server_.Start());
3685 3631
3686 TestDelegate d; 3632 TestDelegate d;
3687 { 3633 {
3688 GURL test_url(test_server_.GetURL(std::string())); 3634 GURL test_url(test_server_.GetURL(std::string()));
3689 URLRequest r(test_url, DEFAULT_PRIORITY, &d, &default_context_); 3635 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3636 test_url, DEFAULT_PRIORITY, &d, NULL));
3690 3637
3691 HttpRequestHeaders headers; 3638 HttpRequestHeaders headers;
3692 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 3639 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
3693 3640
3694 r.Start(); 3641 r->Start();
3695 EXPECT_TRUE(r.is_pending()); 3642 EXPECT_TRUE(r->is_pending());
3696 3643
3697 base::RunLoop().Run(); 3644 base::RunLoop().Run();
3698 3645
3699 EXPECT_EQ(1, d.response_started_count()); 3646 EXPECT_EQ(1, d.response_started_count());
3700 EXPECT_FALSE(d.received_data_before_response()); 3647 EXPECT_FALSE(d.received_data_before_response());
3701 EXPECT_NE(0, d.bytes_received()); 3648 EXPECT_NE(0, d.bytes_received());
3702 EXPECT_EQ(test_server_.host_port_pair().host(), 3649 EXPECT_EQ(test_server_.host_port_pair().host(),
3703 r.GetSocketAddress().host()); 3650 r->GetSocketAddress().host());
3704 EXPECT_EQ(test_server_.host_port_pair().port(), 3651 EXPECT_EQ(test_server_.host_port_pair().port(),
3705 r.GetSocketAddress().port()); 3652 r->GetSocketAddress().port());
3706 3653
3707 EXPECT_TRUE(d.have_full_request_headers()); 3654 EXPECT_TRUE(d.have_full_request_headers());
3708 CheckFullRequestHeaders(d.full_request_headers(), test_url); 3655 CheckFullRequestHeaders(d.full_request_headers(), test_url);
3709 } 3656 }
3710 } 3657 }
3711 3658
3712 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { 3659 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) {
3713 ASSERT_TRUE(test_server_.Start()); 3660 ASSERT_TRUE(test_server_.Start());
3714 3661
3715 TestDelegate d; 3662 TestDelegate d;
3716 { 3663 {
3717 URLRequest r(test_server_.GetURL(std::string()), 3664 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3718 DEFAULT_PRIORITY, 3665 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
3719 &d,
3720 &default_context_);
3721 3666
3722 r.Start(); 3667 r->Start();
3723 EXPECT_TRUE(r.is_pending()); 3668 EXPECT_TRUE(r->is_pending());
3724 3669
3725 base::RunLoop().Run(); 3670 base::RunLoop().Run();
3726 3671
3727 LoadTimingInfo load_timing_info; 3672 LoadTimingInfo load_timing_info;
3728 r.GetLoadTimingInfo(&load_timing_info); 3673 r->GetLoadTimingInfo(&load_timing_info);
3729 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 3674 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
3730 3675
3731 EXPECT_EQ(1, d.response_started_count()); 3676 EXPECT_EQ(1, d.response_started_count());
3732 EXPECT_FALSE(d.received_data_before_response()); 3677 EXPECT_FALSE(d.received_data_before_response());
3733 EXPECT_NE(0, d.bytes_received()); 3678 EXPECT_NE(0, d.bytes_received());
3734 EXPECT_EQ(test_server_.host_port_pair().host(), 3679 EXPECT_EQ(test_server_.host_port_pair().host(),
3735 r.GetSocketAddress().host()); 3680 r->GetSocketAddress().host());
3736 EXPECT_EQ(test_server_.host_port_pair().port(), 3681 EXPECT_EQ(test_server_.host_port_pair().port(),
3737 r.GetSocketAddress().port()); 3682 r->GetSocketAddress().port());
3738 } 3683 }
3739 } 3684 }
3740 3685
3741 TEST_F(URLRequestTestHTTP, GetZippedTest) { 3686 TEST_F(URLRequestTestHTTP, GetZippedTest) {
3742 ASSERT_TRUE(test_server_.Start()); 3687 ASSERT_TRUE(test_server_.Start());
3743 3688
3744 // Parameter that specifies the Content-Length field in the response: 3689 // Parameter that specifies the Content-Length field in the response:
3745 // C - Compressed length. 3690 // C - Compressed length.
3746 // U - Uncompressed length. 3691 // U - Uncompressed length.
3747 // L - Large length (larger than both C & U). 3692 // L - Large length (larger than both C & U).
(...skipping 12 matching lines...) Expand all
3760 { 3705 {
3761 std::string test_file = 3706 std::string test_file =
3762 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", 3707 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c",
3763 test_parameters[i]); 3708 test_parameters[i]);
3764 3709
3765 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3710 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3766 TestURLRequestContext context(true); 3711 TestURLRequestContext context(true);
3767 context.set_network_delegate(&network_delegate); 3712 context.set_network_delegate(&network_delegate);
3768 context.Init(); 3713 context.Init();
3769 3714
3770 URLRequest r( 3715 scoped_ptr<URLRequest> r(context.CreateRequest(
3771 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, &context); 3716 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, NULL));
3772 r.Start(); 3717 r->Start();
3773 EXPECT_TRUE(r.is_pending()); 3718 EXPECT_TRUE(r->is_pending());
3774 3719
3775 base::RunLoop().Run(); 3720 base::RunLoop().Run();
3776 3721
3777 EXPECT_EQ(1, d.response_started_count()); 3722 EXPECT_EQ(1, d.response_started_count());
3778 EXPECT_FALSE(d.received_data_before_response()); 3723 EXPECT_FALSE(d.received_data_before_response());
3779 VLOG(1) << " Received " << d.bytes_received() << " bytes" 3724 VLOG(1) << " Received " << d.bytes_received() << " bytes"
3780 << " status = " << r.status().status() 3725 << " status = " << r->status().status()
3781 << " error = " << r.status().error(); 3726 << " error = " << r->status().error();
3782 if (test_expect_success[i]) { 3727 if (test_expect_success[i]) {
3783 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) 3728 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status())
3784 << " Parameter = \"" << test_file << "\""; 3729 << " Parameter = \"" << test_file << "\"";
3785 } else { 3730 } else {
3786 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 3731 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3787 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r.status().error()) 3732 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error())
3788 << " Parameter = \"" << test_file << "\""; 3733 << " Parameter = \"" << test_file << "\"";
3789 } 3734 }
3790 } 3735 }
3791 } 3736 }
3792 } 3737 }
3793 3738
3794 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { 3739 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) {
3795 ASSERT_TRUE(test_server_.Start()); 3740 ASSERT_TRUE(test_server_.Start());
3796 3741
3797 SpawnedTestServer https_test_server( 3742 SpawnedTestServer https_test_server(
3798 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, 3743 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
3799 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 3744 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
3800 ASSERT_TRUE(https_test_server.Start()); 3745 ASSERT_TRUE(https_test_server.Start());
3801 3746
3802 // An https server is sent a request with an https referer, 3747 // An https server is sent a request with an https referer,
3803 // and responds with a redirect to an http url. The http 3748 // and responds with a redirect to an http url. The http
3804 // server should not be sent the referer. 3749 // server should not be sent the referer.
3805 GURL http_destination = test_server_.GetURL(std::string()); 3750 GURL http_destination = test_server_.GetURL(std::string());
3806 TestDelegate d; 3751 TestDelegate d;
3807 URLRequest req( 3752 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
3808 https_test_server.GetURL("server-redirect?" + http_destination.spec()), 3753 https_test_server.GetURL("server-redirect?" + http_destination.spec()),
3809 DEFAULT_PRIORITY, 3754 DEFAULT_PRIORITY, &d, NULL));
3810 &d, 3755 req->SetReferrer("https://www.referrer.com/");
3811 &default_context_); 3756 req->Start();
3812 req.SetReferrer("https://www.referrer.com/");
3813 req.Start();
3814 base::RunLoop().Run(); 3757 base::RunLoop().Run();
3815 3758
3816 EXPECT_EQ(1, d.response_started_count()); 3759 EXPECT_EQ(1, d.response_started_count());
3817 EXPECT_EQ(1, d.received_redirect_count()); 3760 EXPECT_EQ(1, d.received_redirect_count());
3818 EXPECT_EQ(http_destination, req.url()); 3761 EXPECT_EQ(http_destination, req->url());
3819 EXPECT_EQ(std::string(), req.referrer()); 3762 EXPECT_EQ(std::string(), req->referrer());
3820 } 3763 }
3821 3764
3822 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { 3765 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) {
3823 ASSERT_TRUE(test_server_.Start()); 3766 ASSERT_TRUE(test_server_.Start());
3824 3767
3825 GURL destination_url = test_server_.GetURL(std::string()); 3768 GURL destination_url = test_server_.GetURL(std::string());
3826 GURL original_url = 3769 GURL original_url =
3827 test_server_.GetURL("server-redirect?" + destination_url.spec()); 3770 test_server_.GetURL("server-redirect?" + destination_url.spec());
3828 TestDelegate d; 3771 TestDelegate d;
3829 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); 3772 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
3830 req.Start(); 3773 original_url, DEFAULT_PRIORITY, &d, NULL));
3774 req->Start();
3831 base::RunLoop().Run(); 3775 base::RunLoop().Run();
3832 3776
3833 EXPECT_EQ(1, d.response_started_count()); 3777 EXPECT_EQ(1, d.response_started_count());
3834 EXPECT_EQ(1, d.received_redirect_count()); 3778 EXPECT_EQ(1, d.received_redirect_count());
3835 EXPECT_EQ(destination_url, req.url()); 3779 EXPECT_EQ(destination_url, req->url());
3836 EXPECT_EQ(original_url, req.original_url()); 3780 EXPECT_EQ(original_url, req->original_url());
3837 ASSERT_EQ(2U, req.url_chain().size()); 3781 ASSERT_EQ(2U, req->url_chain().size());
3838 EXPECT_EQ(original_url, req.url_chain()[0]); 3782 EXPECT_EQ(original_url, req->url_chain()[0]);
3839 EXPECT_EQ(destination_url, req.url_chain()[1]); 3783 EXPECT_EQ(destination_url, req->url_chain()[1]);
3840 3784
3841 LoadTimingInfo load_timing_info_before_redirect; 3785 LoadTimingInfo load_timing_info_before_redirect;
3842 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeRedirect( 3786 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeRedirect(
3843 &load_timing_info_before_redirect)); 3787 &load_timing_info_before_redirect));
3844 TestLoadTimingNotReused(load_timing_info_before_redirect, 3788 TestLoadTimingNotReused(load_timing_info_before_redirect,
3845 CONNECT_TIMING_HAS_DNS_TIMES); 3789 CONNECT_TIMING_HAS_DNS_TIMES);
3846 3790
3847 LoadTimingInfo load_timing_info; 3791 LoadTimingInfo load_timing_info;
3848 req.GetLoadTimingInfo(&load_timing_info); 3792 req->GetLoadTimingInfo(&load_timing_info);
3849 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 3793 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
3850 3794
3851 // Check that a new socket was used on redirect, since the server does not 3795 // Check that a new socket was used on redirect, since the server does not
3852 // supposed keep-alive sockets, and that the times before the redirect are 3796 // supposed keep-alive sockets, and that the times before the redirect are
3853 // before the ones recorded for the second request. 3797 // before the ones recorded for the second request.
3854 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, 3798 EXPECT_NE(load_timing_info_before_redirect.socket_log_id,
3855 load_timing_info.socket_log_id); 3799 load_timing_info.socket_log_id);
3856 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, 3800 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end,
3857 load_timing_info.connect_timing.connect_start); 3801 load_timing_info.connect_timing.connect_start);
3858 } 3802 }
3859 3803
3860 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { 3804 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
3861 ASSERT_TRUE(test_server_.Start()); 3805 ASSERT_TRUE(test_server_.Start());
3862 3806
3863 GURL destination_url = test_server_.GetURL(std::string()); 3807 GURL destination_url = test_server_.GetURL(std::string());
3864 GURL middle_redirect_url = 3808 GURL middle_redirect_url =
3865 test_server_.GetURL("server-redirect?" + destination_url.spec()); 3809 test_server_.GetURL("server-redirect?" + destination_url.spec());
3866 GURL original_url = test_server_.GetURL( 3810 GURL original_url = test_server_.GetURL(
3867 "server-redirect?" + middle_redirect_url.spec()); 3811 "server-redirect?" + middle_redirect_url.spec());
3868 TestDelegate d; 3812 TestDelegate d;
3869 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); 3813 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
3870 req.Start(); 3814 original_url, DEFAULT_PRIORITY, &d, NULL));
3815 req->Start();
3871 base::RunLoop().Run(); 3816 base::RunLoop().Run();
3872 3817
3873 EXPECT_EQ(1, d.response_started_count()); 3818 EXPECT_EQ(1, d.response_started_count());
3874 EXPECT_EQ(2, d.received_redirect_count()); 3819 EXPECT_EQ(2, d.received_redirect_count());
3875 EXPECT_EQ(destination_url, req.url()); 3820 EXPECT_EQ(destination_url, req->url());
3876 EXPECT_EQ(original_url, req.original_url()); 3821 EXPECT_EQ(original_url, req->original_url());
3877 ASSERT_EQ(3U, req.url_chain().size()); 3822 ASSERT_EQ(3U, req->url_chain().size());
3878 EXPECT_EQ(original_url, req.url_chain()[0]); 3823 EXPECT_EQ(original_url, req->url_chain()[0]);
3879 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); 3824 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]);
3880 EXPECT_EQ(destination_url, req.url_chain()[2]); 3825 EXPECT_EQ(destination_url, req->url_chain()[2]);
3881 } 3826 }
3882 3827
3883 // First and second pieces of information logged by delegates to URLRequests. 3828 // First and second pieces of information logged by delegates to URLRequests.
3884 const char kFirstDelegateInfo[] = "Wonderful delegate"; 3829 const char kFirstDelegateInfo[] = "Wonderful delegate";
3885 const char kSecondDelegateInfo[] = "Exciting delegate"; 3830 const char kSecondDelegateInfo[] = "Exciting delegate";
3886 3831
3887 // Logs delegate information to a URLRequest. The first string is logged 3832 // Logs delegate information to a URLRequest. The first string is logged
3888 // synchronously on Start(), using DELEGATE_INFO_DEBUG_ONLY. The second is 3833 // synchronously on Start(), using DELEGATE_INFO_DEBUG_ONLY. The second is
3889 // logged asynchronously, using DELEGATE_INFO_DISPLAY_TO_USER. Then 3834 // logged asynchronously, using DELEGATE_INFO_DISPLAY_TO_USER. Then
3890 // another asynchronous call is used to clear the delegate information 3835 // another asynchronous call is used to clear the delegate information
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { 4135 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) {
4191 ASSERT_TRUE(test_server_.Start()); 4136 ASSERT_TRUE(test_server_.Start());
4192 4137
4193 TestDelegate request_delegate; 4138 TestDelegate request_delegate;
4194 TestURLRequestContext context(true); 4139 TestURLRequestContext context(true);
4195 context.set_network_delegate(NULL); 4140 context.set_network_delegate(NULL);
4196 context.set_net_log(&net_log_); 4141 context.set_net_log(&net_log_);
4197 context.Init(); 4142 context.Init();
4198 4143
4199 { 4144 {
4200 URLRequest r(test_server_.GetURL("empty.html"), 4145 scoped_ptr<URLRequest> r(context.CreateRequest(
4201 DEFAULT_PRIORITY, 4146 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &request_delegate,
4202 &request_delegate, 4147 NULL));
4203 &context); 4148 LoadStateWithParam load_state = r->GetLoadState();
4204 LoadStateWithParam load_state = r.GetLoadState();
4205 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4149 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4206 EXPECT_EQ(base::string16(), load_state.param); 4150 EXPECT_EQ(base::string16(), load_state.param);
4207 4151
4208 AsyncDelegateLogger::Run( 4152 AsyncDelegateLogger::Run(
4209 &r, 4153 r.get(),
4210 LOAD_STATE_WAITING_FOR_DELEGATE, 4154 LOAD_STATE_WAITING_FOR_DELEGATE,
4211 LOAD_STATE_WAITING_FOR_DELEGATE, 4155 LOAD_STATE_WAITING_FOR_DELEGATE,
4212 LOAD_STATE_IDLE, 4156 LOAD_STATE_IDLE,
4213 base::Bind(&URLRequest::Start, base::Unretained(&r))); 4157 base::Bind(&URLRequest::Start, base::Unretained(r.get())));
4214 4158
4215 base::RunLoop().Run(); 4159 base::RunLoop().Run();
4216 4160
4217 EXPECT_EQ(200, r.GetResponseCode()); 4161 EXPECT_EQ(200, r->GetResponseCode());
4218 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4162 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4219 } 4163 }
4220 4164
4221 CapturingNetLog::CapturedEntryList entries; 4165 CapturingNetLog::CapturedEntryList entries;
4222 net_log_.GetEntries(&entries); 4166 net_log_.GetEntries(&entries);
4223 size_t log_position = ExpectLogContainsSomewhereAfter( 4167 size_t log_position = ExpectLogContainsSomewhereAfter(
4224 entries, 4168 entries,
4225 0, 4169 0,
4226 NetLog::TYPE_DELEGATE_INFO, 4170 NetLog::TYPE_DELEGATE_INFO,
4227 NetLog::PHASE_BEGIN); 4171 NetLog::PHASE_BEGIN);
4228 4172
4229 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); 4173 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position);
4230 4174
4231 // Nothing else should add any delegate info to the request. 4175 // Nothing else should add any delegate info to the request.
4232 EXPECT_FALSE(LogContainsEntryWithTypeAfter( 4176 EXPECT_FALSE(LogContainsEntryWithTypeAfter(
4233 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); 4177 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO));
4234 } 4178 }
4235 4179
4236 // Tests handling of delegate info from a network delegate. 4180 // Tests handling of delegate info from a network delegate.
4237 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { 4181 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) {
4238 ASSERT_TRUE(test_server_.Start()); 4182 ASSERT_TRUE(test_server_.Start());
4239 4183
4240 TestDelegate request_delegate; 4184 TestDelegate request_delegate;
4241 AsyncLoggingNetworkDelegate network_delegate; 4185 AsyncLoggingNetworkDelegate network_delegate;
4242 TestURLRequestContext context(true); 4186 TestURLRequestContext context(true);
4243 context.set_network_delegate(&network_delegate); 4187 context.set_network_delegate(&network_delegate);
4244 context.set_net_log(&net_log_); 4188 context.set_net_log(&net_log_);
4245 context.Init(); 4189 context.Init();
4246 4190
4247 { 4191 {
4248 URLRequest r(test_server_.GetURL("simple.html"), 4192 scoped_ptr<URLRequest> r(context.CreateRequest(
4249 DEFAULT_PRIORITY, 4193 test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &request_delegate,
4250 &request_delegate, 4194 NULL));
4251 &context); 4195 LoadStateWithParam load_state = r->GetLoadState();
4252 LoadStateWithParam load_state = r.GetLoadState();
4253 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4196 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4254 EXPECT_EQ(base::string16(), load_state.param); 4197 EXPECT_EQ(base::string16(), load_state.param);
4255 4198
4256 r.Start(); 4199 r->Start();
4257 base::RunLoop().Run(); 4200 base::RunLoop().Run();
4258 4201
4259 EXPECT_EQ(200, r.GetResponseCode()); 4202 EXPECT_EQ(200, r->GetResponseCode());
4260 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4203 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4261 EXPECT_EQ(1, network_delegate.created_requests()); 4204 EXPECT_EQ(1, network_delegate.created_requests());
4262 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4205 EXPECT_EQ(0, network_delegate.destroyed_requests());
4263 } 4206 }
4264 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4207 EXPECT_EQ(1, network_delegate.destroyed_requests());
4265 4208
4266 size_t log_position = 0; 4209 size_t log_position = 0;
4267 CapturingNetLog::CapturedEntryList entries; 4210 CapturingNetLog::CapturedEntryList entries;
4268 net_log_.GetEntries(&entries); 4211 net_log_.GetEntries(&entries);
4269 for (size_t i = 0; i < 3; ++i) { 4212 for (size_t i = 0; i < 3; ++i) {
4270 log_position = ExpectLogContainsSomewhereAfter( 4213 log_position = ExpectLogContainsSomewhereAfter(
(...skipping 25 matching lines...) Expand all
4296 ASSERT_TRUE(test_server_.Start()); 4239 ASSERT_TRUE(test_server_.Start());
4297 4240
4298 TestDelegate request_delegate; 4241 TestDelegate request_delegate;
4299 AsyncLoggingNetworkDelegate network_delegate; 4242 AsyncLoggingNetworkDelegate network_delegate;
4300 TestURLRequestContext context(true); 4243 TestURLRequestContext context(true);
4301 context.set_network_delegate(&network_delegate); 4244 context.set_network_delegate(&network_delegate);
4302 context.set_net_log(&net_log_); 4245 context.set_net_log(&net_log_);
4303 context.Init(); 4246 context.Init();
4304 4247
4305 { 4248 {
4306 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4249 scoped_ptr<URLRequest> r(context.CreateRequest(
4307 DEFAULT_PRIORITY, 4250 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4308 &request_delegate, 4251 &request_delegate, NULL));
4309 &context); 4252 LoadStateWithParam load_state = r->GetLoadState();
4310 LoadStateWithParam load_state = r.GetLoadState();
4311 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4253 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4312 EXPECT_EQ(base::string16(), load_state.param); 4254 EXPECT_EQ(base::string16(), load_state.param);
4313 4255
4314 r.Start(); 4256 r->Start();
4315 base::RunLoop().Run(); 4257 base::RunLoop().Run();
4316 4258
4317 EXPECT_EQ(200, r.GetResponseCode()); 4259 EXPECT_EQ(200, r->GetResponseCode());
4318 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4260 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4319 EXPECT_EQ(2, network_delegate.created_requests()); 4261 EXPECT_EQ(2, network_delegate.created_requests());
4320 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4262 EXPECT_EQ(0, network_delegate.destroyed_requests());
4321 } 4263 }
4322 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4264 EXPECT_EQ(1, network_delegate.destroyed_requests());
4323 4265
4324 size_t log_position = 0; 4266 size_t log_position = 0;
4325 CapturingNetLog::CapturedEntryList entries; 4267 CapturingNetLog::CapturedEntryList entries;
4326 net_log_.GetEntries(&entries); 4268 net_log_.GetEntries(&entries);
4327 // The NetworkDelegate logged information in OnBeforeURLRequest, 4269 // The NetworkDelegate logged information in OnBeforeURLRequest,
4328 // OnBeforeSendHeaders, and OnHeadersReceived. 4270 // OnBeforeSendHeaders, and OnHeadersReceived.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4379 ASSERT_TRUE(test_server_.Start()); 4321 ASSERT_TRUE(test_server_.Start());
4380 4322
4381 TestDelegate request_delegate; 4323 TestDelegate request_delegate;
4382 AsyncLoggingNetworkDelegate network_delegate; 4324 AsyncLoggingNetworkDelegate network_delegate;
4383 TestURLRequestContext context(true); 4325 TestURLRequestContext context(true);
4384 context.set_network_delegate(&network_delegate); 4326 context.set_network_delegate(&network_delegate);
4385 context.set_net_log(&net_log_); 4327 context.set_net_log(&net_log_);
4386 context.Init(); 4328 context.Init();
4387 4329
4388 { 4330 {
4389 URLRequest r(test_server_.GetURL("auth-basic"), 4331 scoped_ptr<URLRequest> r(context.CreateRequest(
4390 DEFAULT_PRIORITY, 4332 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &request_delegate,
4391 &request_delegate, 4333 NULL));
4392 &context); 4334 LoadStateWithParam load_state = r->GetLoadState();
4393 LoadStateWithParam load_state = r.GetLoadState();
4394 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4335 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4395 EXPECT_EQ(base::string16(), load_state.param); 4336 EXPECT_EQ(base::string16(), load_state.param);
4396 4337
4397 r.Start(); 4338 r->Start();
4398 base::RunLoop().Run(); 4339 base::RunLoop().Run();
4399 4340
4400 EXPECT_EQ(200, r.GetResponseCode()); 4341 EXPECT_EQ(200, r->GetResponseCode());
4401 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4342 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4402 EXPECT_EQ(1, network_delegate.created_requests()); 4343 EXPECT_EQ(1, network_delegate.created_requests());
4403 EXPECT_EQ(0, network_delegate.destroyed_requests()); 4344 EXPECT_EQ(0, network_delegate.destroyed_requests());
4404 } 4345 }
4405 EXPECT_EQ(1, network_delegate.destroyed_requests()); 4346 EXPECT_EQ(1, network_delegate.destroyed_requests());
4406 4347
4407 size_t log_position = 0; 4348 size_t log_position = 0;
4408 CapturingNetLog::CapturedEntryList entries; 4349 CapturingNetLog::CapturedEntryList entries;
4409 net_log_.GetEntries(&entries); 4350 net_log_.GetEntries(&entries);
4410 // The NetworkDelegate should have logged information in OnBeforeURLRequest, 4351 // The NetworkDelegate should have logged information in OnBeforeURLRequest,
4411 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in 4352 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4444 context.set_network_delegate(NULL); 4385 context.set_network_delegate(NULL);
4445 context.set_net_log(&net_log_); 4386 context.set_net_log(&net_log_);
4446 context.Init(); 4387 context.Init();
4447 4388
4448 { 4389 {
4449 // A chunked response with delays between chunks is used to make sure that 4390 // A chunked response with delays between chunks is used to make sure that
4450 // attempts by the URLRequest delegate to log information while reading the 4391 // attempts by the URLRequest delegate to log information while reading the
4451 // body are ignored. Since they are ignored, this test is robust against 4392 // body are ignored. Since they are ignored, this test is robust against
4452 // the possibility of multiple reads being combined in the unlikely event 4393 // the possibility of multiple reads being combined in the unlikely event
4453 // that it occurs. 4394 // that it occurs.
4454 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"), 4395 scoped_ptr<URLRequest> r(context.CreateRequest(
4455 DEFAULT_PRIORITY, 4396 test_server_.GetURL("chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY,
4456 &request_delegate, 4397 &request_delegate, NULL));
4457 &context); 4398 LoadStateWithParam load_state = r->GetLoadState();
4458 LoadStateWithParam load_state = r.GetLoadState(); 4399 r->Start();
4459 r.Start();
4460 base::RunLoop().Run(); 4400 base::RunLoop().Run();
4461 4401
4462 EXPECT_EQ(200, r.GetResponseCode()); 4402 EXPECT_EQ(200, r->GetResponseCode());
4463 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4403 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4464 } 4404 }
4465 4405
4466 CapturingNetLog::CapturedEntryList entries; 4406 CapturingNetLog::CapturedEntryList entries;
4467 net_log_.GetEntries(&entries); 4407 net_log_.GetEntries(&entries);
4468 4408
4469 size_t log_position = 0; 4409 size_t log_position = 0;
4470 4410
4471 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( 4411 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents(
4472 entries, log_position); 4412 entries, log_position);
4473 4413
(...skipping 24 matching lines...) Expand all
4498 ASSERT_TRUE(test_server_.Start()); 4438 ASSERT_TRUE(test_server_.Start());
4499 4439
4500 AsyncLoggingUrlRequestDelegate request_delegate( 4440 AsyncLoggingUrlRequestDelegate request_delegate(
4501 AsyncLoggingUrlRequestDelegate::NO_CANCEL); 4441 AsyncLoggingUrlRequestDelegate::NO_CANCEL);
4502 TestURLRequestContext context(true); 4442 TestURLRequestContext context(true);
4503 context.set_network_delegate(NULL); 4443 context.set_network_delegate(NULL);
4504 context.set_net_log(&net_log_); 4444 context.set_net_log(&net_log_);
4505 context.Init(); 4445 context.Init();
4506 4446
4507 { 4447 {
4508 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4448 scoped_ptr<URLRequest> r(context.CreateRequest(
4509 DEFAULT_PRIORITY, 4449 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4510 &request_delegate, 4450 &request_delegate, NULL));
4511 &context); 4451 LoadStateWithParam load_state = r->GetLoadState();
4512 LoadStateWithParam load_state = r.GetLoadState(); 4452 r->Start();
4513 r.Start();
4514 base::RunLoop().Run(); 4453 base::RunLoop().Run();
4515 4454
4516 EXPECT_EQ(200, r.GetResponseCode()); 4455 EXPECT_EQ(200, r->GetResponseCode());
4517 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4456 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4518 } 4457 }
4519 4458
4520 CapturingNetLog::CapturedEntryList entries; 4459 CapturingNetLog::CapturedEntryList entries;
4521 net_log_.GetEntries(&entries); 4460 net_log_.GetEntries(&entries);
4522 4461
4523 // Delegate info should only have been logged in OnReceivedRedirect and 4462 // Delegate info should only have been logged in OnReceivedRedirect and
4524 // OnResponseStarted. 4463 // OnResponseStarted.
4525 size_t log_position = 0; 4464 size_t log_position = 0;
4526 for (int i = 0; i < 2; ++i) { 4465 for (int i = 0; i < 2; ++i) {
4527 if (i == 0) { 4466 if (i == 0) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4563 for (size_t test_case = 0; test_case < arraysize(kCancelStages); 4502 for (size_t test_case = 0; test_case < arraysize(kCancelStages);
4564 ++test_case) { 4503 ++test_case) {
4565 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); 4504 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]);
4566 TestURLRequestContext context(true); 4505 TestURLRequestContext context(true);
4567 CapturingNetLog net_log; 4506 CapturingNetLog net_log;
4568 context.set_network_delegate(NULL); 4507 context.set_network_delegate(NULL);
4569 context.set_net_log(&net_log); 4508 context.set_net_log(&net_log);
4570 context.Init(); 4509 context.Init();
4571 4510
4572 { 4511 {
4573 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4512 scoped_ptr<URLRequest> r(context.CreateRequest(
4574 DEFAULT_PRIORITY, 4513 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4575 &request_delegate, 4514 &request_delegate, NULL));
4576 &context); 4515 LoadStateWithParam load_state = r->GetLoadState();
4577 LoadStateWithParam load_state = r.GetLoadState(); 4516 r->Start();
4578 r.Start();
4579 base::RunLoop().Run(); 4517 base::RunLoop().Run();
4580 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4518 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4581 } 4519 }
4582 4520
4583 CapturingNetLog::CapturedEntryList entries; 4521 CapturingNetLog::CapturedEntryList entries;
4584 net_log.GetEntries(&entries); 4522 net_log.GetEntries(&entries);
4585 4523
4586 // Delegate info is always logged in both OnReceivedRedirect and 4524 // Delegate info is always logged in both OnReceivedRedirect and
4587 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the 4525 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the
4588 // OnResponseStarted delegate call is after cancellation, but logging is 4526 // OnResponseStarted delegate call is after cancellation, but logging is
4589 // still currently supported in that call. 4527 // still currently supported in that call.
4590 size_t log_position = 0; 4528 size_t log_position = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4632 } // namespace 4570 } // namespace
4633 4571
4634 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { 4572 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) {
4635 ASSERT_TRUE(test_server_.Start()); 4573 ASSERT_TRUE(test_server_.Start());
4636 4574
4637 GURL destination_url = test_server_.GetURL( 4575 GURL destination_url = test_server_.GetURL(
4638 "echoheader?" + std::string(kExtraHeader)); 4576 "echoheader?" + std::string(kExtraHeader));
4639 GURL original_url = test_server_.GetURL( 4577 GURL original_url = test_server_.GetURL(
4640 "server-redirect?" + destination_url.spec()); 4578 "server-redirect?" + destination_url.spec());
4641 RedirectWithAdditionalHeadersDelegate d; 4579 RedirectWithAdditionalHeadersDelegate d;
4642 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); 4580 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
4643 req.Start(); 4581 original_url, DEFAULT_PRIORITY, &d, NULL));
4582 req->Start();
4644 base::RunLoop().Run(); 4583 base::RunLoop().Run();
4645 4584
4646 std::string value; 4585 std::string value;
4647 const HttpRequestHeaders& headers = req.extra_request_headers(); 4586 const HttpRequestHeaders& headers = req->extra_request_headers();
4648 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); 4587 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value));
4649 EXPECT_EQ(kExtraValue, value); 4588 EXPECT_EQ(kExtraValue, value);
4650 EXPECT_FALSE(req.is_pending()); 4589 EXPECT_FALSE(req->is_pending());
4651 EXPECT_FALSE(req.is_redirecting()); 4590 EXPECT_FALSE(req->is_redirecting());
4652 EXPECT_EQ(kExtraValue, d.data_received()); 4591 EXPECT_EQ(kExtraValue, d.data_received());
4653 } 4592 }
4654 4593
4655 namespace { 4594 namespace {
4656 4595
4657 const char kExtraHeaderToRemove[] = "To-Be-Removed"; 4596 const char kExtraHeaderToRemove[] = "To-Be-Removed";
4658 4597
4659 class RedirectWithHeaderRemovalDelegate : public TestDelegate { 4598 class RedirectWithHeaderRemovalDelegate : public TestDelegate {
4660 virtual void OnReceivedRedirect(URLRequest* request, 4599 virtual void OnReceivedRedirect(URLRequest* request,
4661 const RedirectInfo& redirect_info, 4600 const RedirectInfo& redirect_info,
4662 bool* defer_redirect) OVERRIDE { 4601 bool* defer_redirect) OVERRIDE {
4663 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect); 4602 TestDelegate::OnReceivedRedirect(request, redirect_info, defer_redirect);
4664 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); 4603 request->RemoveRequestHeaderByName(kExtraHeaderToRemove);
4665 } 4604 }
4666 }; 4605 };
4667 4606
4668 } // namespace 4607 } // namespace
4669 4608
4670 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { 4609 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) {
4671 ASSERT_TRUE(test_server_.Start()); 4610 ASSERT_TRUE(test_server_.Start());
4672 4611
4673 GURL destination_url = test_server_.GetURL( 4612 GURL destination_url = test_server_.GetURL(
4674 "echoheader?" + std::string(kExtraHeaderToRemove)); 4613 "echoheader?" + std::string(kExtraHeaderToRemove));
4675 GURL original_url = test_server_.GetURL( 4614 GURL original_url = test_server_.GetURL(
4676 "server-redirect?" + destination_url.spec()); 4615 "server-redirect?" + destination_url.spec());
4677 RedirectWithHeaderRemovalDelegate d; 4616 RedirectWithHeaderRemovalDelegate d;
4678 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); 4617 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
4679 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); 4618 original_url, DEFAULT_PRIORITY, &d, NULL));
4680 req.Start(); 4619 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false);
4620 req->Start();
4681 base::RunLoop().Run(); 4621 base::RunLoop().Run();
4682 4622
4683 std::string value; 4623 std::string value;
4684 const HttpRequestHeaders& headers = req.extra_request_headers(); 4624 const HttpRequestHeaders& headers = req->extra_request_headers();
4685 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); 4625 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value));
4686 EXPECT_FALSE(req.is_pending()); 4626 EXPECT_FALSE(req->is_pending());
4687 EXPECT_FALSE(req.is_redirecting()); 4627 EXPECT_FALSE(req->is_redirecting());
4688 EXPECT_EQ("None", d.data_received()); 4628 EXPECT_EQ("None", d.data_received());
4689 } 4629 }
4690 4630
4691 TEST_F(URLRequestTestHTTP, CancelTest) { 4631 TEST_F(URLRequestTestHTTP, CancelTest) {
4692 TestDelegate d; 4632 TestDelegate d;
4693 { 4633 {
4694 URLRequest r(GURL("http://www.google.com/"), 4634 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4695 DEFAULT_PRIORITY, 4635 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d, NULL));
4696 &d,
4697 &default_context_);
4698 4636
4699 r.Start(); 4637 r->Start();
4700 EXPECT_TRUE(r.is_pending()); 4638 EXPECT_TRUE(r->is_pending());
4701 4639
4702 r.Cancel(); 4640 r->Cancel();
4703 4641
4704 base::RunLoop().Run(); 4642 base::RunLoop().Run();
4705 4643
4706 // We expect to receive OnResponseStarted even though the request has been 4644 // We expect to receive OnResponseStarted even though the request has been
4707 // cancelled. 4645 // cancelled.
4708 EXPECT_EQ(1, d.response_started_count()); 4646 EXPECT_EQ(1, d.response_started_count());
4709 EXPECT_EQ(0, d.bytes_received()); 4647 EXPECT_EQ(0, d.bytes_received());
4710 EXPECT_FALSE(d.received_data_before_response()); 4648 EXPECT_FALSE(d.received_data_before_response());
4711 } 4649 }
4712 } 4650 }
4713 4651
4714 TEST_F(URLRequestTestHTTP, CancelTest2) { 4652 TEST_F(URLRequestTestHTTP, CancelTest2) {
4715 ASSERT_TRUE(test_server_.Start()); 4653 ASSERT_TRUE(test_server_.Start());
4716 4654
4717 TestDelegate d; 4655 TestDelegate d;
4718 { 4656 {
4719 URLRequest r(test_server_.GetURL(std::string()), 4657 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4720 DEFAULT_PRIORITY, 4658 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
4721 &d,
4722 &default_context_);
4723 4659
4724 d.set_cancel_in_response_started(true); 4660 d.set_cancel_in_response_started(true);
4725 4661
4726 r.Start(); 4662 r->Start();
4727 EXPECT_TRUE(r.is_pending()); 4663 EXPECT_TRUE(r->is_pending());
4728 4664
4729 base::RunLoop().Run(); 4665 base::RunLoop().Run();
4730 4666
4731 EXPECT_EQ(1, d.response_started_count()); 4667 EXPECT_EQ(1, d.response_started_count());
4732 EXPECT_EQ(0, d.bytes_received()); 4668 EXPECT_EQ(0, d.bytes_received());
4733 EXPECT_FALSE(d.received_data_before_response()); 4669 EXPECT_FALSE(d.received_data_before_response());
4734 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4670 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4735 } 4671 }
4736 } 4672 }
4737 4673
4738 TEST_F(URLRequestTestHTTP, CancelTest3) { 4674 TEST_F(URLRequestTestHTTP, CancelTest3) {
4739 ASSERT_TRUE(test_server_.Start()); 4675 ASSERT_TRUE(test_server_.Start());
4740 4676
4741 TestDelegate d; 4677 TestDelegate d;
4742 { 4678 {
4743 URLRequest r(test_server_.GetURL(std::string()), 4679 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4744 DEFAULT_PRIORITY, 4680 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
4745 &d,
4746 &default_context_);
4747 4681
4748 d.set_cancel_in_received_data(true); 4682 d.set_cancel_in_received_data(true);
4749 4683
4750 r.Start(); 4684 r->Start();
4751 EXPECT_TRUE(r.is_pending()); 4685 EXPECT_TRUE(r->is_pending());
4752 4686
4753 base::RunLoop().Run(); 4687 base::RunLoop().Run();
4754 4688
4755 EXPECT_EQ(1, d.response_started_count()); 4689 EXPECT_EQ(1, d.response_started_count());
4756 // There is no guarantee about how much data was received 4690 // There is no guarantee about how much data was received
4757 // before the cancel was issued. It could have been 0 bytes, 4691 // before the cancel was issued. It could have been 0 bytes,
4758 // or it could have been all the bytes. 4692 // or it could have been all the bytes.
4759 // EXPECT_EQ(0, d.bytes_received()); 4693 // EXPECT_EQ(0, d.bytes_received());
4760 EXPECT_FALSE(d.received_data_before_response()); 4694 EXPECT_FALSE(d.received_data_before_response());
4761 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4695 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4762 } 4696 }
4763 } 4697 }
4764 4698
4765 TEST_F(URLRequestTestHTTP, CancelTest4) { 4699 TEST_F(URLRequestTestHTTP, CancelTest4) {
4766 ASSERT_TRUE(test_server_.Start()); 4700 ASSERT_TRUE(test_server_.Start());
4767 4701
4768 TestDelegate d; 4702 TestDelegate d;
4769 { 4703 {
4770 URLRequest r(test_server_.GetURL(std::string()), 4704 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4771 DEFAULT_PRIORITY, 4705 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
4772 &d,
4773 &default_context_);
4774 4706
4775 r.Start(); 4707 r->Start();
4776 EXPECT_TRUE(r.is_pending()); 4708 EXPECT_TRUE(r->is_pending());
4777 4709
4778 // The request will be implicitly canceled when it is destroyed. The 4710 // The request will be implicitly canceled when it is destroyed. The
4779 // test delegate must not post a quit message when this happens because 4711 // test delegate must not post a quit message when this happens because
4780 // this test doesn't actually have a message loop. The quit message would 4712 // this test doesn't actually have a message loop. The quit message would
4781 // get put on this thread's message queue and the next test would exit 4713 // get put on this thread's message queue and the next test would exit
4782 // early, causing problems. 4714 // early, causing problems.
4783 d.set_quit_on_complete(false); 4715 d.set_quit_on_complete(false);
4784 } 4716 }
4785 // expect things to just cleanup properly. 4717 // expect things to just cleanup properly.
4786 4718
4787 // we won't actually get a received reponse here because we've never run the 4719 // we won't actually get a received reponse here because we've never run the
4788 // message loop 4720 // message loop
4789 EXPECT_FALSE(d.received_data_before_response()); 4721 EXPECT_FALSE(d.received_data_before_response());
4790 EXPECT_EQ(0, d.bytes_received()); 4722 EXPECT_EQ(0, d.bytes_received());
4791 } 4723 }
4792 4724
4793 TEST_F(URLRequestTestHTTP, CancelTest5) { 4725 TEST_F(URLRequestTestHTTP, CancelTest5) {
4794 ASSERT_TRUE(test_server_.Start()); 4726 ASSERT_TRUE(test_server_.Start());
4795 4727
4796 // populate cache 4728 // populate cache
4797 { 4729 {
4798 TestDelegate d; 4730 TestDelegate d;
4799 URLRequest r(test_server_.GetURL("cachetime"), 4731 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4800 DEFAULT_PRIORITY, 4732 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL));
4801 &d, 4733 r->Start();
4802 &default_context_);
4803 r.Start();
4804 base::RunLoop().Run(); 4734 base::RunLoop().Run();
4805 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4735 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4806 } 4736 }
4807 4737
4808 // cancel read from cache (see bug 990242) 4738 // cancel read from cache (see bug 990242)
4809 { 4739 {
4810 TestDelegate d; 4740 TestDelegate d;
4811 URLRequest r(test_server_.GetURL("cachetime"), 4741 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4812 DEFAULT_PRIORITY, 4742 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL));
4813 &d, 4743 r->Start();
4814 &default_context_); 4744 r->Cancel();
4815 r.Start();
4816 r.Cancel();
4817 base::RunLoop().Run(); 4745 base::RunLoop().Run();
4818 4746
4819 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4747 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4820 EXPECT_EQ(1, d.response_started_count()); 4748 EXPECT_EQ(1, d.response_started_count());
4821 EXPECT_EQ(0, d.bytes_received()); 4749 EXPECT_EQ(0, d.bytes_received());
4822 EXPECT_FALSE(d.received_data_before_response()); 4750 EXPECT_FALSE(d.received_data_before_response());
4823 } 4751 }
4824 } 4752 }
4825 4753
4826 TEST_F(URLRequestTestHTTP, PostTest) { 4754 TEST_F(URLRequestTestHTTP, PostTest) {
4827 ASSERT_TRUE(test_server_.Start()); 4755 ASSERT_TRUE(test_server_.Start());
4828 HTTPUploadDataOperationTest("POST"); 4756 HTTPUploadDataOperationTest("POST");
4829 } 4757 }
4830 4758
4831 TEST_F(URLRequestTestHTTP, PutTest) { 4759 TEST_F(URLRequestTestHTTP, PutTest) {
4832 ASSERT_TRUE(test_server_.Start()); 4760 ASSERT_TRUE(test_server_.Start());
4833 HTTPUploadDataOperationTest("PUT"); 4761 HTTPUploadDataOperationTest("PUT");
4834 } 4762 }
4835 4763
4836 TEST_F(URLRequestTestHTTP, PostEmptyTest) { 4764 TEST_F(URLRequestTestHTTP, PostEmptyTest) {
4837 ASSERT_TRUE(test_server_.Start()); 4765 ASSERT_TRUE(test_server_.Start());
4838 4766
4839 TestDelegate d; 4767 TestDelegate d;
4840 { 4768 {
4841 URLRequest r( 4769 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4842 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4770 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4843 r.set_method("POST"); 4771 r->set_method("POST");
4844 4772
4845 r.Start(); 4773 r->Start();
4846 EXPECT_TRUE(r.is_pending()); 4774 EXPECT_TRUE(r->is_pending());
4847 4775
4848 base::RunLoop().Run(); 4776 base::RunLoop().Run();
4849 4777
4850 ASSERT_EQ(1, d.response_started_count()) 4778 ASSERT_EQ(1, d.response_started_count())
4851 << "request failed: " << r.status().status() 4779 << "request failed: " << r->status().status()
4852 << ", error: " << r.status().error(); 4780 << ", error: " << r->status().error();
4853 4781
4854 EXPECT_FALSE(d.received_data_before_response()); 4782 EXPECT_FALSE(d.received_data_before_response());
4855 EXPECT_TRUE(d.data_received().empty()); 4783 EXPECT_TRUE(d.data_received().empty());
4856 } 4784 }
4857 } 4785 }
4858 4786
4859 TEST_F(URLRequestTestHTTP, PostFileTest) { 4787 TEST_F(URLRequestTestHTTP, PostFileTest) {
4860 ASSERT_TRUE(test_server_.Start()); 4788 ASSERT_TRUE(test_server_.Start());
4861 4789
4862 TestDelegate d; 4790 TestDelegate d;
4863 { 4791 {
4864 URLRequest r( 4792 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4865 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4793 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4866 r.set_method("POST"); 4794 r->set_method("POST");
4867 4795
4868 base::FilePath dir; 4796 base::FilePath dir;
4869 PathService::Get(base::DIR_EXE, &dir); 4797 PathService::Get(base::DIR_EXE, &dir);
4870 base::SetCurrentDirectory(dir); 4798 base::SetCurrentDirectory(dir);
4871 4799
4872 ScopedVector<UploadElementReader> element_readers; 4800 ScopedVector<UploadElementReader> element_readers;
4873 4801
4874 base::FilePath path; 4802 base::FilePath path;
4875 PathService::Get(base::DIR_SOURCE_ROOT, &path); 4803 PathService::Get(base::DIR_SOURCE_ROOT, &path);
4876 path = path.Append(FILE_PATH_LITERAL("net")); 4804 path = path.Append(FILE_PATH_LITERAL("net"));
4877 path = path.Append(FILE_PATH_LITERAL("data")); 4805 path = path.Append(FILE_PATH_LITERAL("data"));
4878 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 4806 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
4879 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 4807 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
4880 element_readers.push_back( 4808 element_readers.push_back(
4881 new UploadFileElementReader(base::MessageLoopProxy::current().get(), 4809 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
4882 path, 4810 path,
4883 0, 4811 0,
4884 kuint64max, 4812 kuint64max,
4885 base::Time())); 4813 base::Time()));
4886 r.set_upload(make_scoped_ptr( 4814 r->set_upload(make_scoped_ptr(
4887 new UploadDataStream(element_readers.Pass(), 0))); 4815 new UploadDataStream(element_readers.Pass(), 0)));
4888 4816
4889 r.Start(); 4817 r->Start();
4890 EXPECT_TRUE(r.is_pending()); 4818 EXPECT_TRUE(r->is_pending());
4891 4819
4892 base::RunLoop().Run(); 4820 base::RunLoop().Run();
4893 4821
4894 int64 size = 0; 4822 int64 size = 0;
4895 ASSERT_EQ(true, base::GetFileSize(path, &size)); 4823 ASSERT_EQ(true, base::GetFileSize(path, &size));
4896 scoped_ptr<char[]> buf(new char[size]); 4824 scoped_ptr<char[]> buf(new char[size]);
4897 4825
4898 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); 4826 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size));
4899 4827
4900 ASSERT_EQ(1, d.response_started_count()) 4828 ASSERT_EQ(1, d.response_started_count())
4901 << "request failed: " << r.status().status() 4829 << "request failed: " << r->status().status()
4902 << ", error: " << r.status().error(); 4830 << ", error: " << r->status().error();
4903 4831
4904 EXPECT_FALSE(d.received_data_before_response()); 4832 EXPECT_FALSE(d.received_data_before_response());
4905 4833
4906 EXPECT_EQ(size, d.bytes_received()); 4834 EXPECT_EQ(size, d.bytes_received());
4907 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); 4835 EXPECT_EQ(std::string(&buf[0], size), d.data_received());
4908 } 4836 }
4909 } 4837 }
4910 4838
4911 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { 4839 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) {
4912 ASSERT_TRUE(test_server_.Start()); 4840 ASSERT_TRUE(test_server_.Start());
4913 4841
4914 TestDelegate d; 4842 TestDelegate d;
4915 { 4843 {
4916 URLRequest r(test_server_.GetURL("echo"), DEFAULT_PRIORITY, 4844 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4917 &d, &default_context_); 4845 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4918 r.set_method("POST"); 4846 r->set_method("POST");
4919 4847
4920 ScopedVector<UploadElementReader> element_readers; 4848 ScopedVector<UploadElementReader> element_readers;
4921 4849
4922 element_readers.push_back(new UploadFileElementReader( 4850 element_readers.push_back(new UploadFileElementReader(
4923 base::MessageLoopProxy::current().get(), 4851 base::MessageLoopProxy::current().get(),
4924 base::FilePath(FILE_PATH_LITERAL( 4852 base::FilePath(FILE_PATH_LITERAL(
4925 "c:\\path\\to\\non\\existant\\file.randomness.12345")), 4853 "c:\\path\\to\\non\\existant\\file.randomness.12345")),
4926 0, 4854 0,
4927 kuint64max, 4855 kuint64max,
4928 base::Time())); 4856 base::Time()));
4929 r.set_upload(make_scoped_ptr( 4857 r->set_upload(make_scoped_ptr(
4930 new UploadDataStream(element_readers.Pass(), 0))); 4858 new UploadDataStream(element_readers.Pass(), 0)));
4931 4859
4932 r.Start(); 4860 r->Start();
4933 EXPECT_TRUE(r.is_pending()); 4861 EXPECT_TRUE(r->is_pending());
4934 4862
4935 base::RunLoop().Run(); 4863 base::RunLoop().Run();
4936 4864
4937 EXPECT_TRUE(d.request_failed()); 4865 EXPECT_TRUE(d.request_failed());
4938 EXPECT_FALSE(d.received_data_before_response()); 4866 EXPECT_FALSE(d.received_data_before_response());
4939 EXPECT_EQ(0, d.bytes_received()); 4867 EXPECT_EQ(0, d.bytes_received());
4940 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 4868 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
4941 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error()); 4869 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error());
4942 } 4870 }
4943 } 4871 }
4944 4872
4945 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 4873 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
4946 ASSERT_TRUE(test_server_.Start()); 4874 ASSERT_TRUE(test_server_.Start());
4947 4875
4948 TestDelegate d; 4876 TestDelegate d;
4949 { 4877 {
4950 URLRequest r( 4878 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4951 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4879 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4952 r.EnableChunkedUpload(); 4880 r->EnableChunkedUpload();
4953 r.set_method("POST"); 4881 r->set_method("POST");
4954 AddChunksToUpload(&r); 4882 AddChunksToUpload(r.get());
4955 r.Start(); 4883 r->Start();
4956 EXPECT_TRUE(r.is_pending()); 4884 EXPECT_TRUE(r->is_pending());
4957 4885
4958 base::RunLoop().Run(); 4886 base::RunLoop().Run();
4959 4887
4960 VerifyReceivedDataMatchesChunks(&r, &d); 4888 VerifyReceivedDataMatchesChunks(r.get(), &d);
4961 } 4889 }
4962 } 4890 }
4963 4891
4964 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { 4892 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) {
4965 ASSERT_TRUE(test_server_.Start()); 4893 ASSERT_TRUE(test_server_.Start());
4966 4894
4967 TestDelegate d; 4895 TestDelegate d;
4968 { 4896 {
4969 URLRequest r( 4897 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4970 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4898 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4971 r.EnableChunkedUpload(); 4899 r->EnableChunkedUpload();
4972 r.set_method("POST"); 4900 r->set_method("POST");
4973 r.Start(); 4901 r->Start();
4974 EXPECT_TRUE(r.is_pending()); 4902 EXPECT_TRUE(r->is_pending());
4975 AddChunksToUpload(&r); 4903 AddChunksToUpload(r.get());
4976 base::RunLoop().Run(); 4904 base::RunLoop().Run();
4977 4905
4978 VerifyReceivedDataMatchesChunks(&r, &d); 4906 VerifyReceivedDataMatchesChunks(r.get(), &d);
4979 } 4907 }
4980 } 4908 }
4981 4909
4982 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { 4910 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
4983 ASSERT_TRUE(test_server_.Start()); 4911 ASSERT_TRUE(test_server_.Start());
4984 4912
4985 TestDelegate d; 4913 TestDelegate d;
4986 { 4914 {
4987 URLRequest r( 4915 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4988 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); 4916 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL));
4989 r.EnableChunkedUpload(); 4917 r->EnableChunkedUpload();
4990 r.set_method("POST"); 4918 r->set_method("POST");
4991 r.Start(); 4919 r->Start();
4992 EXPECT_TRUE(r.is_pending()); 4920 EXPECT_TRUE(r->is_pending());
4993 4921
4994 base::RunLoop().RunUntilIdle(); 4922 base::RunLoop().RunUntilIdle();
4995 AddChunksToUpload(&r); 4923 AddChunksToUpload(r.get());
4996 base::RunLoop().Run(); 4924 base::RunLoop().Run();
4997 4925
4998 VerifyReceivedDataMatchesChunks(&r, &d); 4926 VerifyReceivedDataMatchesChunks(r.get(), &d);
4999 } 4927 }
5000 } 4928 }
5001 4929
5002 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { 4930 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) {
5003 ASSERT_TRUE(test_server_.Start()); 4931 ASSERT_TRUE(test_server_.Start());
5004 4932
5005 TestDelegate d; 4933 TestDelegate d;
5006 URLRequest req(test_server_.GetURL("files/with-headers.html"), 4934 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5007 DEFAULT_PRIORITY, 4935 test_server_.GetURL("files/with-headers.html"), DEFAULT_PRIORITY, &d,
5008 &d, 4936 NULL));
5009 &default_context_); 4937 req->Start();
5010 req.Start();
5011 base::RunLoop().Run(); 4938 base::RunLoop().Run();
5012 4939
5013 const HttpResponseHeaders* headers = req.response_headers(); 4940 const HttpResponseHeaders* headers = req->response_headers();
5014 4941
5015 // Simple sanity check that response_info() accesses the same data. 4942 // Simple sanity check that response_info() accesses the same data.
5016 EXPECT_EQ(headers, req.response_info().headers.get()); 4943 EXPECT_EQ(headers, req->response_info().headers.get());
5017 4944
5018 std::string header; 4945 std::string header;
5019 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); 4946 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header));
5020 EXPECT_EQ("private", header); 4947 EXPECT_EQ("private", header);
5021 4948
5022 header.clear(); 4949 header.clear();
5023 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); 4950 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header));
5024 EXPECT_EQ("text/html; charset=ISO-8859-1", header); 4951 EXPECT_EQ("text/html; charset=ISO-8859-1", header);
5025 4952
5026 // The response has two "X-Multiple-Entries" headers. 4953 // The response has two "X-Multiple-Entries" headers.
5027 // This verfies our output has them concatenated together. 4954 // This verfies our output has them concatenated together.
5028 header.clear(); 4955 header.clear();
5029 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); 4956 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header));
5030 EXPECT_EQ("a, b", header); 4957 EXPECT_EQ("a, b", header);
5031 } 4958 }
5032 4959
5033 TEST_F(URLRequestTestHTTP, ProcessSTS) { 4960 TEST_F(URLRequestTestHTTP, ProcessSTS) {
5034 SpawnedTestServer::SSLOptions ssl_options; 4961 SpawnedTestServer::SSLOptions ssl_options;
5035 SpawnedTestServer https_test_server( 4962 SpawnedTestServer https_test_server(
5036 SpawnedTestServer::TYPE_HTTPS, 4963 SpawnedTestServer::TYPE_HTTPS,
5037 ssl_options, 4964 ssl_options,
5038 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4965 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5039 ASSERT_TRUE(https_test_server.Start()); 4966 ASSERT_TRUE(https_test_server.Start());
5040 4967
5041 TestDelegate d; 4968 TestDelegate d;
5042 URLRequest request(https_test_server.GetURL("files/hsts-headers.html"), 4969 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5043 DEFAULT_PRIORITY, 4970 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, &d,
5044 &d, 4971 NULL));
5045 &default_context_); 4972 request->Start();
5046 request.Start();
5047 base::RunLoop().Run(); 4973 base::RunLoop().Run();
5048 4974
5049 TransportSecurityState* security_state = 4975 TransportSecurityState* security_state =
5050 default_context_.transport_security_state(); 4976 default_context_.transport_security_state();
5051 TransportSecurityState::DomainState domain_state; 4977 TransportSecurityState::DomainState domain_state;
5052 EXPECT_TRUE(security_state->GetDynamicDomainState( 4978 EXPECT_TRUE(security_state->GetDynamicDomainState(
5053 SpawnedTestServer::kLocalhost, &domain_state)); 4979 SpawnedTestServer::kLocalhost, &domain_state));
5054 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4980 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5055 domain_state.sts.upgrade_mode); 4981 domain_state.sts.upgrade_mode);
5056 EXPECT_TRUE(domain_state.sts.include_subdomains); 4982 EXPECT_TRUE(domain_state.sts.include_subdomains);
(...skipping 18 matching lines...) Expand all
5075 // validity/expiration. 5001 // validity/expiration.
5076 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { 5002 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) {
5077 SpawnedTestServer::SSLOptions ssl_options; 5003 SpawnedTestServer::SSLOptions ssl_options;
5078 SpawnedTestServer https_test_server( 5004 SpawnedTestServer https_test_server(
5079 SpawnedTestServer::TYPE_HTTPS, 5005 SpawnedTestServer::TYPE_HTTPS,
5080 ssl_options, 5006 ssl_options,
5081 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5007 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5082 ASSERT_TRUE(https_test_server.Start()); 5008 ASSERT_TRUE(https_test_server.Start());
5083 5009
5084 TestDelegate d; 5010 TestDelegate d;
5085 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"), 5011 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5086 DEFAULT_PRIORITY, 5012 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, &d,
5087 &d, 5013 NULL));
5088 &default_context_); 5014 request->Start();
5089 request.Start();
5090 base::RunLoop().Run(); 5015 base::RunLoop().Run();
5091 5016
5092 TransportSecurityState* security_state = 5017 TransportSecurityState* security_state =
5093 default_context_.transport_security_state(); 5018 default_context_.transport_security_state();
5094 TransportSecurityState::DomainState domain_state; 5019 TransportSecurityState::DomainState domain_state;
5095 EXPECT_TRUE(security_state->GetDynamicDomainState( 5020 EXPECT_TRUE(security_state->GetDynamicDomainState(
5096 SpawnedTestServer::kLocalhost, &domain_state)); 5021 SpawnedTestServer::kLocalhost, &domain_state));
5097 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 5022 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
5098 domain_state.sts.upgrade_mode); 5023 domain_state.sts.upgrade_mode);
5099 EXPECT_FALSE(domain_state.sts.include_subdomains); 5024 EXPECT_FALSE(domain_state.sts.include_subdomains);
5100 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5025 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5101 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 5026 EXPECT_TRUE(domain_state.HasPublicKeyPins());
5102 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); 5027 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry);
5103 } 5028 }
5104 5029
5105 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 5030 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
5106 SpawnedTestServer::SSLOptions ssl_options; 5031 SpawnedTestServer::SSLOptions ssl_options;
5107 SpawnedTestServer https_test_server( 5032 SpawnedTestServer https_test_server(
5108 SpawnedTestServer::TYPE_HTTPS, 5033 SpawnedTestServer::TYPE_HTTPS,
5109 ssl_options, 5034 ssl_options,
5110 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5035 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5111 ASSERT_TRUE(https_test_server.Start()); 5036 ASSERT_TRUE(https_test_server.Start());
5112 5037
5113 TestDelegate d; 5038 TestDelegate d;
5114 URLRequest request( 5039 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5115 https_test_server.GetURL("files/hsts-multiple-headers.html"), 5040 https_test_server.GetURL("files/hsts-multiple-headers.html"),
5116 DEFAULT_PRIORITY, 5041 DEFAULT_PRIORITY, &d, NULL));
5117 &d, 5042 request->Start();
5118 &default_context_);
5119 request.Start();
5120 base::RunLoop().Run(); 5043 base::RunLoop().Run();
5121 5044
5122 // We should have set parameters from the first header, not the second. 5045 // We should have set parameters from the first header, not the second.
5123 TransportSecurityState* security_state = 5046 TransportSecurityState* security_state =
5124 default_context_.transport_security_state(); 5047 default_context_.transport_security_state();
5125 TransportSecurityState::DomainState domain_state; 5048 TransportSecurityState::DomainState domain_state;
5126 EXPECT_TRUE(security_state->GetDynamicDomainState( 5049 EXPECT_TRUE(security_state->GetDynamicDomainState(
5127 SpawnedTestServer::kLocalhost, &domain_state)); 5050 SpawnedTestServer::kLocalhost, &domain_state));
5128 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5051 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5129 domain_state.sts.upgrade_mode); 5052 domain_state.sts.upgrade_mode);
5130 EXPECT_FALSE(domain_state.sts.include_subdomains); 5053 EXPECT_FALSE(domain_state.sts.include_subdomains);
5131 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5054 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5132 } 5055 }
5133 5056
5134 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 5057 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
5135 SpawnedTestServer::SSLOptions ssl_options; 5058 SpawnedTestServer::SSLOptions ssl_options;
5136 SpawnedTestServer https_test_server( 5059 SpawnedTestServer https_test_server(
5137 SpawnedTestServer::TYPE_HTTPS, 5060 SpawnedTestServer::TYPE_HTTPS,
5138 ssl_options, 5061 ssl_options,
5139 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5062 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5140 ASSERT_TRUE(https_test_server.Start()); 5063 ASSERT_TRUE(https_test_server.Start());
5141 5064
5142 TestDelegate d; 5065 TestDelegate d;
5143 URLRequest request( 5066 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5144 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 5067 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
5145 DEFAULT_PRIORITY, 5068 DEFAULT_PRIORITY, &d, NULL));
5146 &d, 5069 request->Start();
5147 &default_context_);
5148 request.Start();
5149 base::RunLoop().Run(); 5070 base::RunLoop().Run();
5150 5071
5151 // We should have set parameters from the first header, not the second. 5072 // We should have set parameters from the first header, not the second.
5152 TransportSecurityState* security_state = 5073 TransportSecurityState* security_state =
5153 default_context_.transport_security_state(); 5074 default_context_.transport_security_state();
5154 TransportSecurityState::DomainState domain_state; 5075 TransportSecurityState::DomainState domain_state;
5155 EXPECT_TRUE(security_state->GetDynamicDomainState( 5076 EXPECT_TRUE(security_state->GetDynamicDomainState(
5156 SpawnedTestServer::kLocalhost, &domain_state)); 5077 SpawnedTestServer::kLocalhost, &domain_state));
5157 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5078 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5158 domain_state.sts.upgrade_mode); 5079 domain_state.sts.upgrade_mode);
(...skipping 15 matching lines...) Expand all
5174 // policies, that only the first such policy is processed. 5095 // policies, that only the first such policy is processed.
5175 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { 5096 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) {
5176 SpawnedTestServer::SSLOptions ssl_options; 5097 SpawnedTestServer::SSLOptions ssl_options;
5177 SpawnedTestServer https_test_server( 5098 SpawnedTestServer https_test_server(
5178 SpawnedTestServer::TYPE_HTTPS, 5099 SpawnedTestServer::TYPE_HTTPS,
5179 ssl_options, 5100 ssl_options,
5180 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5101 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5181 ASSERT_TRUE(https_test_server.Start()); 5102 ASSERT_TRUE(https_test_server.Start());
5182 5103
5183 TestDelegate d; 5104 TestDelegate d;
5184 URLRequest request( 5105 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5185 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), 5106 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"),
5186 DEFAULT_PRIORITY, 5107 DEFAULT_PRIORITY, &d, NULL));
5187 &d, 5108 request->Start();
5188 &default_context_);
5189 request.Start();
5190 base::RunLoop().Run(); 5109 base::RunLoop().Run();
5191 5110
5192 TransportSecurityState* security_state = 5111 TransportSecurityState* security_state =
5193 default_context_.transport_security_state(); 5112 default_context_.transport_security_state();
5194 TransportSecurityState::DomainState domain_state; 5113 TransportSecurityState::DomainState domain_state;
5195 EXPECT_TRUE(security_state->GetDynamicDomainState( 5114 EXPECT_TRUE(security_state->GetDynamicDomainState(
5196 SpawnedTestServer::kLocalhost, &domain_state)); 5115 SpawnedTestServer::kLocalhost, &domain_state));
5197 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5116 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5198 domain_state.sts.upgrade_mode); 5117 domain_state.sts.upgrade_mode);
5199 #if defined(OS_ANDROID) 5118 #if defined(OS_ANDROID)
5200 // Android's CertVerifyProc does not (yet) handle pins. 5119 // Android's CertVerifyProc does not (yet) handle pins.
5201 #else 5120 #else
5202 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 5121 EXPECT_TRUE(domain_state.HasPublicKeyPins());
5203 #endif 5122 #endif
5204 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); 5123 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry);
5205 5124
5206 EXPECT_TRUE(domain_state.sts.include_subdomains); 5125 EXPECT_TRUE(domain_state.sts.include_subdomains);
5207 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5126 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5208 } 5127 }
5209 5128
5210 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { 5129 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
5211 ASSERT_TRUE(test_server_.Start()); 5130 ASSERT_TRUE(test_server_.Start());
5212 5131
5213 TestDelegate d; 5132 TestDelegate d;
5214 URLRequest req(test_server_.GetURL("files/content-type-normalization.html"), 5133 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5215 DEFAULT_PRIORITY, 5134 test_server_.GetURL("files/content-type-normalization.html"),
5216 &d, 5135 DEFAULT_PRIORITY, &d, NULL));
5217 &default_context_); 5136 req->Start();
5218 req.Start();
5219 base::RunLoop().Run(); 5137 base::RunLoop().Run();
5220 5138
5221 std::string mime_type; 5139 std::string mime_type;
5222 req.GetMimeType(&mime_type); 5140 req->GetMimeType(&mime_type);
5223 EXPECT_EQ("text/html", mime_type); 5141 EXPECT_EQ("text/html", mime_type);
5224 5142
5225 std::string charset; 5143 std::string charset;
5226 req.GetCharset(&charset); 5144 req->GetCharset(&charset);
5227 EXPECT_EQ("utf-8", charset); 5145 EXPECT_EQ("utf-8", charset);
5228 req.Cancel(); 5146 req->Cancel();
5229 } 5147 }
5230 5148
5231 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) { 5149 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) {
5232 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). 5150 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5233 GURL data_url("data:,foo"); 5151 GURL data_url("data:,foo");
5234 DataProtocolHandler data_protocol_handler; 5152 DataProtocolHandler data_protocol_handler;
5235 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); 5153 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url));
5236 5154
5237 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5155 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5238 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); 5156 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url));
5239 } 5157 }
5240 5158
5241 #if !defined(DISABLE_FILE_SUPPORT) 5159 #if !defined(DISABLE_FILE_SUPPORT)
5242 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { 5160 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) {
5243 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). 5161 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
5244 GURL file_url("file:///foo.txt"); 5162 GURL file_url("file:///foo.txt");
5245 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); 5163 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current());
5246 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); 5164 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
5247 5165
5248 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5166 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5249 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); 5167 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url));
5250 } 5168 }
5251 5169
5252 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 5170 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
5253 ASSERT_TRUE(test_server_.Start()); 5171 ASSERT_TRUE(test_server_.Start());
5254 5172
5255 TestDelegate d; 5173 TestDelegate d;
5256 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"), 5174 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5257 DEFAULT_PRIORITY, 5175 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, &d,
5258 &d, 5176 NULL));
5259 &default_context_); 5177 req->Start();
5260 req.Start();
5261 base::RunLoop().Run(); 5178 base::RunLoop().Run();
5262 5179
5263 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5180 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5264 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 5181 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error());
5265 } 5182 }
5266 #endif // !defined(DISABLE_FILE_SUPPORT) 5183 #endif // !defined(DISABLE_FILE_SUPPORT)
5267 5184
5268 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 5185 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
5269 ASSERT_TRUE(test_server_.Start()); 5186 ASSERT_TRUE(test_server_.Start());
5270 5187
5271 TestDelegate d; 5188 TestDelegate d;
5272 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"), 5189 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5273 DEFAULT_PRIORITY, 5190 test_server_.GetURL("files/redirect-to-data.html"), DEFAULT_PRIORITY, &d,
5274 &d, 5191 NULL));
5275 &default_context_); 5192 req->Start();
5276 req.Start();
5277 base::MessageLoop::current()->Run(); 5193 base::MessageLoop::current()->Run();
5278 5194
5279 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5195 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5280 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 5196 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error());
5281 } 5197 }
5282 5198
5283 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 5199 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
5284 ASSERT_TRUE(test_server_.Start()); 5200 ASSERT_TRUE(test_server_.Start());
5285 5201
5286 TestDelegate d; 5202 TestDelegate d;
5287 URLRequest req(test_server_.GetURL("files/redirect-to-invalid-url.html"), 5203 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5288 DEFAULT_PRIORITY, 5204 test_server_.GetURL("files/redirect-to-invalid-url.html"),
5289 &d, 5205 DEFAULT_PRIORITY, &d, NULL));
5290 &default_context_); 5206 req->Start();
5291 req.Start();
5292 base::RunLoop().Run(); 5207 base::RunLoop().Run();
5293 5208
5294 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5209 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5295 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); 5210 EXPECT_EQ(ERR_INVALID_URL, req->status().error());
5296 } 5211 }
5297 5212
5298 // Make sure redirects are cached, despite not reading their bodies. 5213 // Make sure redirects are cached, despite not reading their bodies.
5299 TEST_F(URLRequestTestHTTP, CacheRedirect) { 5214 TEST_F(URLRequestTestHTTP, CacheRedirect) {
5300 ASSERT_TRUE(test_server_.Start()); 5215 ASSERT_TRUE(test_server_.Start());
5301 GURL redirect_url = 5216 GURL redirect_url =
5302 test_server_.GetURL("files/redirect302-to-echo-cacheable"); 5217 test_server_.GetURL("files/redirect302-to-echo-cacheable");
5303 5218
5304 { 5219 {
5305 TestDelegate d; 5220 TestDelegate d;
5306 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); 5221 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5307 req.Start(); 5222 redirect_url, DEFAULT_PRIORITY, &d, NULL));
5223 req->Start();
5308 base::RunLoop().Run(); 5224 base::RunLoop().Run();
5309 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5225 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5310 EXPECT_EQ(1, d.received_redirect_count()); 5226 EXPECT_EQ(1, d.received_redirect_count());
5311 EXPECT_EQ(test_server_.GetURL("echo"), req.url()); 5227 EXPECT_EQ(test_server_.GetURL("echo"), req->url());
5312 } 5228 }
5313 5229
5314 { 5230 {
5315 TestDelegate d; 5231 TestDelegate d;
5316 d.set_quit_on_redirect(true); 5232 d.set_quit_on_redirect(true);
5317 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); 5233 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5318 req.Start(); 5234 redirect_url, DEFAULT_PRIORITY, &d, NULL));
5235 req->Start();
5319 base::RunLoop().Run(); 5236 base::RunLoop().Run();
5320 5237
5321 EXPECT_EQ(1, d.received_redirect_count()); 5238 EXPECT_EQ(1, d.received_redirect_count());
5322 EXPECT_EQ(0, d.response_started_count()); 5239 EXPECT_EQ(0, d.response_started_count());
5323 EXPECT_TRUE(req.was_cached()); 5240 EXPECT_TRUE(req->was_cached());
5324 5241
5325 req.FollowDeferredRedirect(); 5242 req->FollowDeferredRedirect();
5326 base::RunLoop().Run(); 5243 base::RunLoop().Run();
5327 EXPECT_EQ(1, d.received_redirect_count()); 5244 EXPECT_EQ(1, d.received_redirect_count());
5328 EXPECT_EQ(1, d.response_started_count()); 5245 EXPECT_EQ(1, d.response_started_count());
5329 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5246 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5330 EXPECT_EQ(test_server_.GetURL("echo"), req.url()); 5247 EXPECT_EQ(test_server_.GetURL("echo"), req->url());
5331 } 5248 }
5332 } 5249 }
5333 5250
5334 // Make sure a request isn't cached when a NetworkDelegate forces a redirect 5251 // Make sure a request isn't cached when a NetworkDelegate forces a redirect
5335 // when the headers are read, since the body won't have been read. 5252 // when the headers are read, since the body won't have been read.
5336 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { 5253 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) {
5337 ASSERT_TRUE(test_server_.Start()); 5254 ASSERT_TRUE(test_server_.Start());
5338 // URL that is normally cached. 5255 // URL that is normally cached.
5339 GURL initial_url = test_server_.GetURL("cachetime"); 5256 GURL initial_url = test_server_.GetURL("cachetime");
5340 5257
5341 { 5258 {
5342 // Set up the TestNetworkDelegate tp force a redirect. 5259 // Set up the TestNetworkDelegate tp force a redirect.
5343 GURL redirect_to_url = test_server_.GetURL("echo"); 5260 GURL redirect_to_url = test_server_.GetURL("echo");
5344 default_network_delegate_.set_redirect_on_headers_received_url( 5261 default_network_delegate_.set_redirect_on_headers_received_url(
5345 redirect_to_url); 5262 redirect_to_url);
5346 5263
5347 TestDelegate d; 5264 TestDelegate d;
5348 URLRequest req(initial_url, DEFAULT_PRIORITY, &d, &default_context_); 5265 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5349 req.Start(); 5266 initial_url, DEFAULT_PRIORITY, &d, NULL));
5267 req->Start();
5350 base::RunLoop().Run(); 5268 base::RunLoop().Run();
5351 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5269 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5352 EXPECT_EQ(1, d.received_redirect_count()); 5270 EXPECT_EQ(1, d.received_redirect_count());
5353 EXPECT_EQ(redirect_to_url, req.url()); 5271 EXPECT_EQ(redirect_to_url, req->url());
5354 } 5272 }
5355 5273
5356 { 5274 {
5357 TestDelegate d; 5275 TestDelegate d;
5358 URLRequest req(initial_url, DEFAULT_PRIORITY, &d, &default_context_); 5276 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5359 req.Start(); 5277 initial_url, DEFAULT_PRIORITY, &d, NULL));
5278 req->Start();
5360 base::RunLoop().Run(); 5279 base::RunLoop().Run();
5361 5280
5362 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5281 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5363 EXPECT_FALSE(req.was_cached()); 5282 EXPECT_FALSE(req->was_cached());
5364 EXPECT_EQ(0, d.received_redirect_count()); 5283 EXPECT_EQ(0, d.received_redirect_count());
5365 EXPECT_EQ(initial_url, req.url()); 5284 EXPECT_EQ(initial_url, req->url());
5366 } 5285 }
5367 } 5286 }
5368 5287
5369 // Tests that redirection to an unsafe URL is allowed when it has been marked as 5288 // Tests that redirection to an unsafe URL is allowed when it has been marked as
5370 // safe. 5289 // safe.
5371 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { 5290 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) {
5372 ASSERT_TRUE(test_server_.Start()); 5291 ASSERT_TRUE(test_server_.Start());
5373 5292
5374 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); 5293 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url");
5375 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5294 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5376 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5295 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5377 5296
5378 TestDelegate d; 5297 TestDelegate d;
5379 { 5298 {
5380 URLRequest r(test_server_.GetURL("whatever"), 5299 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5381 DEFAULT_PRIORITY, 5300 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL));
5382 &d,
5383 &default_context_);
5384 5301
5385 r.Start(); 5302 r->Start();
5386 base::RunLoop().Run(); 5303 base::RunLoop().Run();
5387 5304
5388 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 5305 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5389 5306
5390 EXPECT_EQ(2U, r.url_chain().size()); 5307 EXPECT_EQ(2U, r->url_chain().size());
5391 EXPECT_EQ(OK, r.status().error()); 5308 EXPECT_EQ(OK, r->status().error());
5392 EXPECT_EQ(unsafe_url, r.url()); 5309 EXPECT_EQ(unsafe_url, r->url());
5393 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); 5310 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received());
5394 } 5311 }
5395 } 5312 }
5396 5313
5397 // Tests that a redirect to a different unsafe URL is blocked, even after adding 5314 // Tests that a redirect to a different unsafe URL is blocked, even after adding
5398 // some other URL to the whitelist. 5315 // some other URL to the whitelist.
5399 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { 5316 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) {
5400 ASSERT_TRUE(test_server_.Start()); 5317 ASSERT_TRUE(test_server_.Start());
5401 5318
5402 GURL unsafe_url("data:text/html,something"); 5319 GURL unsafe_url("data:text/html,something");
5403 GURL different_unsafe_url("data:text/html,something-else"); 5320 GURL different_unsafe_url("data:text/html,something-else");
5404 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5321 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5405 default_network_delegate_.set_allowed_unsafe_redirect_url( 5322 default_network_delegate_.set_allowed_unsafe_redirect_url(
5406 different_unsafe_url); 5323 different_unsafe_url);
5407 5324
5408 TestDelegate d; 5325 TestDelegate d;
5409 { 5326 {
5410 URLRequest r(test_server_.GetURL("whatever"), 5327 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5411 DEFAULT_PRIORITY, 5328 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL));
5412 &d,
5413 &default_context_);
5414 5329
5415 r.Start(); 5330 r->Start();
5416 base::RunLoop().Run(); 5331 base::RunLoop().Run();
5417 5332
5418 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 5333 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
5419 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r.status().error()); 5334 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error());
5420 } 5335 }
5421 } 5336 }
5422 5337
5423 // Redirects from an URL with fragment to an unsafe URL with fragment should 5338 // Redirects from an URL with fragment to an unsafe URL with fragment should
5424 // be allowed, and the reference fragment of the target URL should be preserved. 5339 // be allowed, and the reference fragment of the target URL should be preserved.
5425 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { 5340 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) {
5426 ASSERT_TRUE(test_server_.Start()); 5341 ASSERT_TRUE(test_server_.Start());
5427 5342
5428 GURL original_url(test_server_.GetURL("original#fragment1")); 5343 GURL original_url(test_server_.GetURL("original#fragment1"));
5429 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 5344 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
5430 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 5345 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
5431 5346
5432 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5347 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5433 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5348 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5434 5349
5435 TestDelegate d; 5350 TestDelegate d;
5436 { 5351 {
5437 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); 5352 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5353 original_url, DEFAULT_PRIORITY, &d, NULL));
5438 5354
5439 r.Start(); 5355 r->Start();
5440 base::RunLoop().Run(); 5356 base::RunLoop().Run();
5441 5357
5442 EXPECT_EQ(2U, r.url_chain().size()); 5358 EXPECT_EQ(2U, r->url_chain().size());
5443 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 5359 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5444 EXPECT_EQ(OK, r.status().error()); 5360 EXPECT_EQ(OK, r->status().error());
5445 EXPECT_EQ(original_url, r.original_url()); 5361 EXPECT_EQ(original_url, r->original_url());
5446 EXPECT_EQ(expected_url, r.url()); 5362 EXPECT_EQ(expected_url, r->url());
5447 } 5363 }
5448 } 5364 }
5449 5365
5450 // When a delegate has specified a safe redirect URL, but it does not match the 5366 // When a delegate has specified a safe redirect URL, but it does not match the
5451 // redirect target, then do not prevent the reference fragment from being added. 5367 // redirect target, then do not prevent the reference fragment from being added.
5452 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { 5368 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) {
5453 ASSERT_TRUE(test_server_.Start()); 5369 ASSERT_TRUE(test_server_.Start());
5454 5370
5455 GURL original_url(test_server_.GetURL("original#expected-fragment")); 5371 GURL original_url(test_server_.GetURL("original#expected-fragment"));
5456 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); 5372 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url");
5457 GURL redirect_url(test_server_.GetURL("target")); 5373 GURL redirect_url(test_server_.GetURL("target"));
5458 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); 5374 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment"));
5459 5375
5460 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 5376 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
5461 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5377 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5462 5378
5463 TestDelegate d; 5379 TestDelegate d;
5464 { 5380 {
5465 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); 5381 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5382 original_url, DEFAULT_PRIORITY, &d, NULL));
5466 5383
5467 r.Start(); 5384 r->Start();
5468 base::RunLoop().Run(); 5385 base::RunLoop().Run();
5469 5386
5470 EXPECT_EQ(2U, r.url_chain().size()); 5387 EXPECT_EQ(2U, r->url_chain().size());
5471 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 5388 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5472 EXPECT_EQ(OK, r.status().error()); 5389 EXPECT_EQ(OK, r->status().error());
5473 EXPECT_EQ(original_url, r.original_url()); 5390 EXPECT_EQ(original_url, r->original_url());
5474 EXPECT_EQ(expected_redirect_url, r.url()); 5391 EXPECT_EQ(expected_redirect_url, r->url());
5475 } 5392 }
5476 } 5393 }
5477 5394
5478 // When a delegate has specified a safe redirect URL, assume that the redirect 5395 // When a delegate has specified a safe redirect URL, assume that the redirect
5479 // URL should not be changed. In particular, the reference fragment should not 5396 // URL should not be changed. In particular, the reference fragment should not
5480 // be modified. 5397 // be modified.
5481 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { 5398 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) {
5482 ASSERT_TRUE(test_server_.Start()); 5399 ASSERT_TRUE(test_server_.Start());
5483 5400
5484 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); 5401 GURL original_url(test_server_.GetURL("original#should-not-be-appended"));
5485 GURL redirect_url("data:text/html,expect-no-reference-fragment"); 5402 GURL redirect_url("data:text/html,expect-no-reference-fragment");
5486 5403
5487 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 5404 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
5488 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); 5405 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url);
5489 5406
5490 TestDelegate d; 5407 TestDelegate d;
5491 { 5408 {
5492 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); 5409 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5410 original_url, DEFAULT_PRIORITY, &d, NULL));
5493 5411
5494 r.Start(); 5412 r->Start();
5495 base::RunLoop().Run(); 5413 base::RunLoop().Run();
5496 5414
5497 EXPECT_EQ(2U, r.url_chain().size()); 5415 EXPECT_EQ(2U, r->url_chain().size());
5498 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 5416 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5499 EXPECT_EQ(OK, r.status().error()); 5417 EXPECT_EQ(OK, r->status().error());
5500 EXPECT_EQ(original_url, r.original_url()); 5418 EXPECT_EQ(original_url, r->original_url());
5501 EXPECT_EQ(redirect_url, r.url()); 5419 EXPECT_EQ(redirect_url, r->url());
5502 } 5420 }
5503 } 5421 }
5504 5422
5505 // When a URLRequestRedirectJob is created, the redirection must be followed and 5423 // When a URLRequestRedirectJob is created, the redirection must be followed and
5506 // the reference fragment of the target URL must not be modified. 5424 // the reference fragment of the target URL must not be modified.
5507 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { 5425 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) {
5508 ASSERT_TRUE(test_server_.Start()); 5426 ASSERT_TRUE(test_server_.Start());
5509 5427
5510 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); 5428 GURL original_url(test_server_.GetURL("original#should-not-be-appended"));
5511 GURL redirect_url(test_server_.GetURL("echo")); 5429 GURL redirect_url(test_server_.GetURL("echo"));
5512 5430
5513 TestDelegate d; 5431 TestDelegate d;
5514 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); 5432 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5433 original_url, DEFAULT_PRIORITY, &d, NULL));
5515 5434
5516 URLRequestRedirectJob* job = new URLRequestRedirectJob( 5435 URLRequestRedirectJob* job = new URLRequestRedirectJob(
5517 &r, &default_network_delegate_, redirect_url, 5436 r.get(), &default_network_delegate_, redirect_url,
5518 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 5437 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
5519 AddTestInterceptor()->set_main_intercept_job(job); 5438 AddTestInterceptor()->set_main_intercept_job(job);
5520 5439
5521 r.Start(); 5440 r->Start();
5522 base::RunLoop().Run(); 5441 base::RunLoop().Run();
5523 5442
5524 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 5443 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5525 EXPECT_EQ(OK, r.status().error()); 5444 EXPECT_EQ(OK, r->status().error());
5526 EXPECT_EQ(original_url, r.original_url()); 5445 EXPECT_EQ(original_url, r->original_url());
5527 EXPECT_EQ(redirect_url, r.url()); 5446 EXPECT_EQ(redirect_url, r->url());
5528 } 5447 }
5529 5448
5530 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { 5449 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) {
5531 ASSERT_TRUE(test_server_.Start()); 5450 ASSERT_TRUE(test_server_.Start());
5532 5451
5533 TestDelegate d; 5452 TestDelegate d;
5534 URLRequest req(test_server_.GetURL("echoheader?Referer"), 5453 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5535 DEFAULT_PRIORITY, 5454 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL));
5536 &d, 5455 req->SetReferrer("http://user:pass@foo.com/");
5537 &default_context_); 5456 req->Start();
5538 req.SetReferrer("http://user:pass@foo.com/");
5539 req.Start();
5540 base::RunLoop().Run(); 5457 base::RunLoop().Run();
5541 5458
5542 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); 5459 EXPECT_EQ(std::string("http://foo.com/"), d.data_received());
5543 } 5460 }
5544 5461
5545 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { 5462 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) {
5546 ASSERT_TRUE(test_server_.Start()); 5463 ASSERT_TRUE(test_server_.Start());
5547 5464
5548 TestDelegate d; 5465 TestDelegate d;
5549 URLRequest req(test_server_.GetURL("echoheader?Referer"), 5466 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5550 DEFAULT_PRIORITY, 5467 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL));
5551 &d, 5468 req->SetReferrer("http://foo.com/test#fragment");
5552 &default_context_); 5469 req->Start();
5553 req.SetReferrer("http://foo.com/test#fragment");
5554 req.Start();
5555 base::RunLoop().Run(); 5470 base::RunLoop().Run();
5556 5471
5557 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); 5472 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received());
5558 } 5473 }
5559 5474
5560 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { 5475 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) {
5561 ASSERT_TRUE(test_server_.Start()); 5476 ASSERT_TRUE(test_server_.Start());
5562 5477
5563 TestDelegate d; 5478 TestDelegate d;
5564 URLRequest req(test_server_.GetURL("echoheader?Referer"), 5479 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5565 DEFAULT_PRIORITY, 5480 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL));
5566 &d, 5481 req->SetReferrer("http://foo.com/test#fragment");
5567 &default_context_); 5482 req->SetReferrer("");
5568 req.SetReferrer("http://foo.com/test#fragment"); 5483 req->Start();
5569 req.SetReferrer("");
5570 req.Start();
5571 base::RunLoop().Run(); 5484 base::RunLoop().Run();
5572 5485
5573 EXPECT_EQ(std::string("None"), d.data_received()); 5486 EXPECT_EQ(std::string("None"), d.data_received());
5574 } 5487 }
5575 5488
5576 // Defer network start and then resume, checking that the request was a success 5489 // Defer network start and then resume, checking that the request was a success
5577 // and bytes were received. 5490 // and bytes were received.
5578 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { 5491 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) {
5579 ASSERT_TRUE(test_server_.Start()); 5492 ASSERT_TRUE(test_server_.Start());
5580 5493
5581 TestDelegate d; 5494 TestDelegate d;
5582 { 5495 {
5583 d.set_quit_on_network_start(true); 5496 d.set_quit_on_network_start(true);
5584 GURL test_url(test_server_.GetURL("echo")); 5497 GURL test_url(test_server_.GetURL("echo"));
5585 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); 5498 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5499 test_url, DEFAULT_PRIORITY, &d, NULL));
5586 5500
5587 req.Start(); 5501 req->Start();
5588 base::RunLoop().Run(); 5502 base::RunLoop().Run();
5589 5503
5590 EXPECT_EQ(1, d.received_before_network_start_count()); 5504 EXPECT_EQ(1, d.received_before_network_start_count());
5591 EXPECT_EQ(0, d.response_started_count()); 5505 EXPECT_EQ(0, d.response_started_count());
5592 5506
5593 req.ResumeNetworkStart(); 5507 req->ResumeNetworkStart();
5594 base::RunLoop().Run(); 5508 base::RunLoop().Run();
5595 5509
5596 EXPECT_EQ(1, d.response_started_count()); 5510 EXPECT_EQ(1, d.response_started_count());
5597 EXPECT_NE(0, d.bytes_received()); 5511 EXPECT_NE(0, d.bytes_received());
5598 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5512 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5599 } 5513 }
5600 } 5514 }
5601 5515
5602 // Check that OnBeforeNetworkStart is only called once even if there is a 5516 // Check that OnBeforeNetworkStart is only called once even if there is a
5603 // redirect. 5517 // redirect.
5604 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { 5518 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) {
5605 ASSERT_TRUE(test_server_.Start()); 5519 ASSERT_TRUE(test_server_.Start());
5606 5520
5607 TestDelegate d; 5521 TestDelegate d;
5608 { 5522 {
5609 d.set_quit_on_redirect(true); 5523 d.set_quit_on_redirect(true);
5610 d.set_quit_on_network_start(true); 5524 d.set_quit_on_network_start(true);
5611 URLRequest req(test_server_.GetURL("server-redirect?echo"), 5525 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5612 DEFAULT_PRIORITY, 5526 test_server_.GetURL("server-redirect?echo"), DEFAULT_PRIORITY, &d,
5613 &d, 5527 NULL));
5614 &default_context_);
5615 5528
5616 req.Start(); 5529 req->Start();
5617 base::RunLoop().Run(); 5530 base::RunLoop().Run();
5618 5531
5619 EXPECT_EQ(1, d.received_before_network_start_count()); 5532 EXPECT_EQ(1, d.received_before_network_start_count());
5620 EXPECT_EQ(0, d.response_started_count()); 5533 EXPECT_EQ(0, d.response_started_count());
5621 EXPECT_EQ(0, d.received_redirect_count()); 5534 EXPECT_EQ(0, d.received_redirect_count());
5622 5535
5623 req.ResumeNetworkStart(); 5536 req->ResumeNetworkStart();
5624 base::RunLoop().Run(); 5537 base::RunLoop().Run();
5625 5538
5626 EXPECT_EQ(1, d.received_redirect_count()); 5539 EXPECT_EQ(1, d.received_redirect_count());
5627 req.FollowDeferredRedirect(); 5540 req->FollowDeferredRedirect();
5628 base::RunLoop().Run(); 5541 base::RunLoop().Run();
5629 5542
5630 // Check that the redirect's new network transaction does not get propagated 5543 // Check that the redirect's new network transaction does not get propagated
5631 // to a second OnBeforeNetworkStart() notification. 5544 // to a second OnBeforeNetworkStart() notification.
5632 EXPECT_EQ(1, d.received_before_network_start_count()); 5545 EXPECT_EQ(1, d.received_before_network_start_count());
5633 5546
5634 EXPECT_EQ(1, d.response_started_count()); 5547 EXPECT_EQ(1, d.response_started_count());
5635 EXPECT_NE(0, d.bytes_received()); 5548 EXPECT_NE(0, d.bytes_received());
5636 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5549 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5637 } 5550 }
5638 } 5551 }
5639 5552
5640 // Cancel the request after learning that the request would use the network. 5553 // Cancel the request after learning that the request would use the network.
5641 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { 5554 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) {
5642 ASSERT_TRUE(test_server_.Start()); 5555 ASSERT_TRUE(test_server_.Start());
5643 5556
5644 TestDelegate d; 5557 TestDelegate d;
5645 { 5558 {
5646 d.set_quit_on_network_start(true); 5559 d.set_quit_on_network_start(true);
5647 GURL test_url(test_server_.GetURL("echo")); 5560 GURL test_url(test_server_.GetURL("echo"));
5648 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); 5561 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5562 test_url, DEFAULT_PRIORITY, &d, NULL));
5649 5563
5650 req.Start(); 5564 req->Start();
5651 base::RunLoop().Run(); 5565 base::RunLoop().Run();
5652 5566
5653 EXPECT_EQ(1, d.received_before_network_start_count()); 5567 EXPECT_EQ(1, d.received_before_network_start_count());
5654 EXPECT_EQ(0, d.response_started_count()); 5568 EXPECT_EQ(0, d.response_started_count());
5655 5569
5656 req.Cancel(); 5570 req->Cancel();
5657 base::RunLoop().Run(); 5571 base::RunLoop().Run();
5658 5572
5659 EXPECT_EQ(1, d.response_started_count()); 5573 EXPECT_EQ(1, d.response_started_count());
5660 EXPECT_EQ(0, d.bytes_received()); 5574 EXPECT_EQ(0, d.bytes_received());
5661 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 5575 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5662 } 5576 }
5663 } 5577 }
5664 5578
5665 TEST_F(URLRequestTestHTTP, CancelRedirect) { 5579 TEST_F(URLRequestTestHTTP, CancelRedirect) {
5666 ASSERT_TRUE(test_server_.Start()); 5580 ASSERT_TRUE(test_server_.Start());
5667 5581
5668 TestDelegate d; 5582 TestDelegate d;
5669 { 5583 {
5670 d.set_cancel_in_received_redirect(true); 5584 d.set_cancel_in_received_redirect(true);
5671 URLRequest req(test_server_.GetURL("files/redirect-test.html"), 5585 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5672 DEFAULT_PRIORITY, 5586 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d,
5673 &d, 5587 NULL));
5674 &default_context_); 5588 req->Start();
5675 req.Start();
5676 base::RunLoop().Run(); 5589 base::RunLoop().Run();
5677 5590
5678 EXPECT_EQ(1, d.response_started_count()); 5591 EXPECT_EQ(1, d.response_started_count());
5679 EXPECT_EQ(0, d.bytes_received()); 5592 EXPECT_EQ(0, d.bytes_received());
5680 EXPECT_FALSE(d.received_data_before_response()); 5593 EXPECT_FALSE(d.received_data_before_response());
5681 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 5594 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5682 } 5595 }
5683 } 5596 }
5684 5597
5685 TEST_F(URLRequestTestHTTP, DeferredRedirect) { 5598 TEST_F(URLRequestTestHTTP, DeferredRedirect) {
5686 ASSERT_TRUE(test_server_.Start()); 5599 ASSERT_TRUE(test_server_.Start());
5687 5600
5688 TestDelegate d; 5601 TestDelegate d;
5689 { 5602 {
5690 d.set_quit_on_redirect(true); 5603 d.set_quit_on_redirect(true);
5691 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5604 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
5692 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); 5605 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5606 test_url, DEFAULT_PRIORITY, &d, NULL));
5693 5607
5694 req.Start(); 5608 req->Start();
5695 base::RunLoop().Run(); 5609 base::RunLoop().Run();
5696 5610
5697 EXPECT_EQ(1, d.received_redirect_count()); 5611 EXPECT_EQ(1, d.received_redirect_count());
5698 5612
5699 req.FollowDeferredRedirect(); 5613 req->FollowDeferredRedirect();
5700 base::RunLoop().Run(); 5614 base::RunLoop().Run();
5701 5615
5702 EXPECT_EQ(1, d.response_started_count()); 5616 EXPECT_EQ(1, d.response_started_count());
5703 EXPECT_FALSE(d.received_data_before_response()); 5617 EXPECT_FALSE(d.received_data_before_response());
5704 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5618 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5705 5619
5706 base::FilePath path; 5620 base::FilePath path;
5707 PathService::Get(base::DIR_SOURCE_ROOT, &path); 5621 PathService::Get(base::DIR_SOURCE_ROOT, &path);
5708 path = path.Append(FILE_PATH_LITERAL("net")); 5622 path = path.Append(FILE_PATH_LITERAL("net"));
5709 path = path.Append(FILE_PATH_LITERAL("data")); 5623 path = path.Append(FILE_PATH_LITERAL("data"));
5710 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 5624 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
5711 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 5625 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
5712 5626
5713 std::string contents; 5627 std::string contents;
5714 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 5628 EXPECT_TRUE(base::ReadFileToString(path, &contents));
5715 EXPECT_EQ(contents, d.data_received()); 5629 EXPECT_EQ(contents, d.data_received());
5716 } 5630 }
5717 } 5631 }
5718 5632
5719 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { 5633 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) {
5720 ASSERT_TRUE(test_server_.Start()); 5634 ASSERT_TRUE(test_server_.Start());
5721 5635
5722 TestDelegate d; 5636 TestDelegate d;
5723 { 5637 {
5724 d.set_quit_on_redirect(true); 5638 d.set_quit_on_redirect(true);
5725 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5639 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
5726 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); 5640 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5641 test_url, DEFAULT_PRIORITY, &d, NULL));
5727 5642
5728 EXPECT_FALSE(d.have_full_request_headers()); 5643 EXPECT_FALSE(d.have_full_request_headers());
5729 5644
5730 req.Start(); 5645 req->Start();
5731 base::RunLoop().Run(); 5646 base::RunLoop().Run();
5732 5647
5733 EXPECT_EQ(1, d.received_redirect_count()); 5648 EXPECT_EQ(1, d.received_redirect_count());
5734 EXPECT_TRUE(d.have_full_request_headers()); 5649 EXPECT_TRUE(d.have_full_request_headers());
5735 CheckFullRequestHeaders(d.full_request_headers(), test_url); 5650 CheckFullRequestHeaders(d.full_request_headers(), test_url);
5736 d.ClearFullRequestHeaders(); 5651 d.ClearFullRequestHeaders();
5737 5652
5738 req.FollowDeferredRedirect(); 5653 req->FollowDeferredRedirect();
5739 base::RunLoop().Run(); 5654 base::RunLoop().Run();
5740 5655
5741 GURL target_url(test_server_.GetURL("files/with-headers.html")); 5656 GURL target_url(test_server_.GetURL("files/with-headers.html"));
5742 EXPECT_EQ(1, d.response_started_count()); 5657 EXPECT_EQ(1, d.response_started_count());
5743 EXPECT_TRUE(d.have_full_request_headers()); 5658 EXPECT_TRUE(d.have_full_request_headers());
5744 CheckFullRequestHeaders(d.full_request_headers(), target_url); 5659 CheckFullRequestHeaders(d.full_request_headers(), target_url);
5745 EXPECT_FALSE(d.received_data_before_response()); 5660 EXPECT_FALSE(d.received_data_before_response());
5746 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); 5661 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5747 5662
5748 base::FilePath path; 5663 base::FilePath path;
5749 PathService::Get(base::DIR_SOURCE_ROOT, &path); 5664 PathService::Get(base::DIR_SOURCE_ROOT, &path);
5750 path = path.Append(FILE_PATH_LITERAL("net")); 5665 path = path.Append(FILE_PATH_LITERAL("net"));
5751 path = path.Append(FILE_PATH_LITERAL("data")); 5666 path = path.Append(FILE_PATH_LITERAL("data"));
5752 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 5667 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
5753 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 5668 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
5754 5669
5755 std::string contents; 5670 std::string contents;
5756 EXPECT_TRUE(base::ReadFileToString(path, &contents)); 5671 EXPECT_TRUE(base::ReadFileToString(path, &contents));
5757 EXPECT_EQ(contents, d.data_received()); 5672 EXPECT_EQ(contents, d.data_received());
5758 } 5673 }
5759 } 5674 }
5760 5675
5761 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { 5676 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) {
5762 ASSERT_TRUE(test_server_.Start()); 5677 ASSERT_TRUE(test_server_.Start());
5763 5678
5764 TestDelegate d; 5679 TestDelegate d;
5765 { 5680 {
5766 d.set_quit_on_redirect(true); 5681 d.set_quit_on_redirect(true);
5767 URLRequest req(test_server_.GetURL("files/redirect-test.html"), 5682 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5768 DEFAULT_PRIORITY, 5683 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d,
5769 &d, 5684 NULL));
5770 &default_context_); 5685 req->Start();
5771 req.Start();
5772 base::RunLoop().Run(); 5686 base::RunLoop().Run();
5773 5687
5774 EXPECT_EQ(1, d.received_redirect_count()); 5688 EXPECT_EQ(1, d.received_redirect_count());
5775 5689
5776 req.Cancel(); 5690 req->Cancel();
5777 base::RunLoop().Run(); 5691 base::RunLoop().Run();
5778 5692
5779 EXPECT_EQ(1, d.response_started_count()); 5693 EXPECT_EQ(1, d.response_started_count());
5780 EXPECT_EQ(0, d.bytes_received()); 5694 EXPECT_EQ(0, d.bytes_received());
5781 EXPECT_FALSE(d.received_data_before_response()); 5695 EXPECT_FALSE(d.received_data_before_response());
5782 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 5696 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5783 } 5697 }
5784 } 5698 }
5785 5699
5786 TEST_F(URLRequestTestHTTP, VaryHeader) { 5700 TEST_F(URLRequestTestHTTP, VaryHeader) {
5787 ASSERT_TRUE(test_server_.Start()); 5701 ASSERT_TRUE(test_server_.Start());
5788 5702
5789 // Populate the cache. 5703 // Populate the cache.
5790 { 5704 {
5791 TestDelegate d; 5705 TestDelegate d;
5792 URLRequest req(test_server_.GetURL("echoheadercache?foo"), 5706 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5793 DEFAULT_PRIORITY, 5707 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d,
5794 &d, 5708 NULL));
5795 &default_context_);
5796 HttpRequestHeaders headers; 5709 HttpRequestHeaders headers;
5797 headers.SetHeader("foo", "1"); 5710 headers.SetHeader("foo", "1");
5798 req.SetExtraRequestHeaders(headers); 5711 req->SetExtraRequestHeaders(headers);
5799 req.Start(); 5712 req->Start();
5800 base::RunLoop().Run(); 5713 base::RunLoop().Run();
5801 5714
5802 LoadTimingInfo load_timing_info; 5715 LoadTimingInfo load_timing_info;
5803 req.GetLoadTimingInfo(&load_timing_info); 5716 req->GetLoadTimingInfo(&load_timing_info);
5804 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5717 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5805 } 5718 }
5806 5719
5807 // Expect a cache hit. 5720 // Expect a cache hit.
5808 { 5721 {
5809 TestDelegate d; 5722 TestDelegate d;
5810 URLRequest req(test_server_.GetURL("echoheadercache?foo"), 5723 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5811 DEFAULT_PRIORITY, 5724 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d,
5812 &d, 5725 NULL));
5813 &default_context_);
5814 HttpRequestHeaders headers; 5726 HttpRequestHeaders headers;
5815 headers.SetHeader("foo", "1"); 5727 headers.SetHeader("foo", "1");
5816 req.SetExtraRequestHeaders(headers); 5728 req->SetExtraRequestHeaders(headers);
5817 req.Start(); 5729 req->Start();
5818 base::RunLoop().Run(); 5730 base::RunLoop().Run();
5819 5731
5820 EXPECT_TRUE(req.was_cached()); 5732 EXPECT_TRUE(req->was_cached());
5821 5733
5822 LoadTimingInfo load_timing_info; 5734 LoadTimingInfo load_timing_info;
5823 req.GetLoadTimingInfo(&load_timing_info); 5735 req->GetLoadTimingInfo(&load_timing_info);
5824 TestLoadTimingCacheHitNoNetwork(load_timing_info); 5736 TestLoadTimingCacheHitNoNetwork(load_timing_info);
5825 } 5737 }
5826 5738
5827 // Expect a cache miss. 5739 // Expect a cache miss.
5828 { 5740 {
5829 TestDelegate d; 5741 TestDelegate d;
5830 URLRequest req(test_server_.GetURL("echoheadercache?foo"), 5742 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5831 DEFAULT_PRIORITY, 5743 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d,
5832 &d, 5744 NULL));
5833 &default_context_);
5834 HttpRequestHeaders headers; 5745 HttpRequestHeaders headers;
5835 headers.SetHeader("foo", "2"); 5746 headers.SetHeader("foo", "2");
5836 req.SetExtraRequestHeaders(headers); 5747 req->SetExtraRequestHeaders(headers);
5837 req.Start(); 5748 req->Start();
5838 base::RunLoop().Run(); 5749 base::RunLoop().Run();
5839 5750
5840 EXPECT_FALSE(req.was_cached()); 5751 EXPECT_FALSE(req->was_cached());
5841 5752
5842 LoadTimingInfo load_timing_info; 5753 LoadTimingInfo load_timing_info;
5843 req.GetLoadTimingInfo(&load_timing_info); 5754 req->GetLoadTimingInfo(&load_timing_info);
5844 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5755 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5845 } 5756 }
5846 } 5757 }
5847 5758
5848 TEST_F(URLRequestTestHTTP, BasicAuth) { 5759 TEST_F(URLRequestTestHTTP, BasicAuth) {
5849 ASSERT_TRUE(test_server_.Start()); 5760 ASSERT_TRUE(test_server_.Start());
5850 5761
5851 // populate the cache 5762 // populate the cache
5852 { 5763 {
5853 TestDelegate d; 5764 TestDelegate d;
5854 d.set_credentials(AuthCredentials(kUser, kSecret)); 5765 d.set_credentials(AuthCredentials(kUser, kSecret));
5855 5766
5856 URLRequest r(test_server_.GetURL("auth-basic"), 5767 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5857 DEFAULT_PRIORITY, 5768 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL));
5858 &d, 5769 r->Start();
5859 &default_context_);
5860 r.Start();
5861 5770
5862 base::RunLoop().Run(); 5771 base::RunLoop().Run();
5863 5772
5864 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5773 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5865 } 5774 }
5866 5775
5867 // repeat request with end-to-end validation. since auth-basic results in a 5776 // repeat request with end-to-end validation. since auth-basic results in a
5868 // cachable page, we expect this test to result in a 304. in which case, the 5777 // cachable page, we expect this test to result in a 304. in which case, the
5869 // response should be fetched from the cache. 5778 // response should be fetched from the cache.
5870 { 5779 {
5871 TestDelegate d; 5780 TestDelegate d;
5872 d.set_credentials(AuthCredentials(kUser, kSecret)); 5781 d.set_credentials(AuthCredentials(kUser, kSecret));
5873 5782
5874 URLRequest r(test_server_.GetURL("auth-basic"), 5783 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5875 DEFAULT_PRIORITY, 5784 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL));
5876 &d, 5785 r->SetLoadFlags(LOAD_VALIDATE_CACHE);
5877 &default_context_); 5786 r->Start();
5878 r.SetLoadFlags(LOAD_VALIDATE_CACHE);
5879 r.Start();
5880 5787
5881 base::RunLoop().Run(); 5788 base::RunLoop().Run();
5882 5789
5883 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5790 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5884 5791
5885 // Should be the same cached document. 5792 // Should be the same cached document.
5886 EXPECT_TRUE(r.was_cached()); 5793 EXPECT_TRUE(r->was_cached());
5887 } 5794 }
5888 } 5795 }
5889 5796
5890 // Check that Set-Cookie headers in 401 responses are respected. 5797 // Check that Set-Cookie headers in 401 responses are respected.
5891 // http://crbug.com/6450 5798 // http://crbug.com/6450
5892 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { 5799 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) {
5893 ASSERT_TRUE(test_server_.Start()); 5800 ASSERT_TRUE(test_server_.Start());
5894 5801
5895 GURL url_requiring_auth = 5802 GURL url_requiring_auth =
5896 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); 5803 test_server_.GetURL("auth-basic?set-cookie-if-challenged");
5897 5804
5898 // Request a page that will give a 401 containing a Set-Cookie header. 5805 // Request a page that will give a 401 containing a Set-Cookie header.
5899 // Verify that when the transaction is restarted, it includes the new cookie. 5806 // Verify that when the transaction is restarted, it includes the new cookie.
5900 { 5807 {
5901 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5808 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5902 TestURLRequestContext context(true); 5809 TestURLRequestContext context(true);
5903 context.set_network_delegate(&network_delegate); 5810 context.set_network_delegate(&network_delegate);
5904 context.Init(); 5811 context.Init();
5905 5812
5906 TestDelegate d; 5813 TestDelegate d;
5907 d.set_credentials(AuthCredentials(kUser, kSecret)); 5814 d.set_credentials(AuthCredentials(kUser, kSecret));
5908 5815
5909 URLRequest r(url_requiring_auth, DEFAULT_PRIORITY, &d, &context); 5816 scoped_ptr<URLRequest> r(context.CreateRequest(
5910 r.Start(); 5817 url_requiring_auth, DEFAULT_PRIORITY, &d, NULL));
5818 r->Start();
5911 5819
5912 base::RunLoop().Run(); 5820 base::RunLoop().Run();
5913 5821
5914 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5822 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5915 5823
5916 // Make sure we sent the cookie in the restarted transaction. 5824 // Make sure we sent the cookie in the restarted transaction.
5917 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 5825 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
5918 != std::string::npos); 5826 != std::string::npos);
5919 } 5827 }
5920 5828
5921 // Same test as above, except this time the restart is initiated earlier 5829 // Same test as above, except this time the restart is initiated earlier
5922 // (without user intervention since identity is embedded in the URL). 5830 // (without user intervention since identity is embedded in the URL).
5923 { 5831 {
5924 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5832 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5925 TestURLRequestContext context(true); 5833 TestURLRequestContext context(true);
5926 context.set_network_delegate(&network_delegate); 5834 context.set_network_delegate(&network_delegate);
5927 context.Init(); 5835 context.Init();
5928 5836
5929 TestDelegate d; 5837 TestDelegate d;
5930 5838
5931 GURL::Replacements replacements; 5839 GURL::Replacements replacements;
5932 std::string username("user2"); 5840 std::string username("user2");
5933 std::string password("secret"); 5841 std::string password("secret");
5934 replacements.SetUsernameStr(username); 5842 replacements.SetUsernameStr(username);
5935 replacements.SetPasswordStr(password); 5843 replacements.SetPasswordStr(password);
5936 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); 5844 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements);
5937 5845
5938 URLRequest r(url_with_identity, DEFAULT_PRIORITY, &d, &context); 5846 scoped_ptr<URLRequest> r(context.CreateRequest(
5939 r.Start(); 5847 url_with_identity, DEFAULT_PRIORITY, &d, NULL));
5848 r->Start();
5940 5849
5941 base::RunLoop().Run(); 5850 base::RunLoop().Run();
5942 5851
5943 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); 5852 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos);
5944 5853
5945 // Make sure we sent the cookie in the restarted transaction. 5854 // Make sure we sent the cookie in the restarted transaction.
5946 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 5855 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
5947 != std::string::npos); 5856 != std::string::npos);
5948 } 5857 }
5949 } 5858 }
5950 5859
5951 // Tests that load timing works as expected with auth and the cache. 5860 // Tests that load timing works as expected with auth and the cache.
5952 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { 5861 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) {
5953 ASSERT_TRUE(test_server_.Start()); 5862 ASSERT_TRUE(test_server_.Start());
5954 5863
5955 // populate the cache 5864 // populate the cache
5956 { 5865 {
5957 TestDelegate d; 5866 TestDelegate d;
5958 d.set_credentials(AuthCredentials(kUser, kSecret)); 5867 d.set_credentials(AuthCredentials(kUser, kSecret));
5959 5868
5960 URLRequest r(test_server_.GetURL("auth-basic"), 5869 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5961 DEFAULT_PRIORITY, 5870 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL));
5962 &d, 5871 r->Start();
5963 &default_context_);
5964 r.Start();
5965 5872
5966 base::RunLoop().Run(); 5873 base::RunLoop().Run();
5967 5874
5968 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5875 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5969 5876
5970 LoadTimingInfo load_timing_info_before_auth; 5877 LoadTimingInfo load_timing_info_before_auth;
5971 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( 5878 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth(
5972 &load_timing_info_before_auth)); 5879 &load_timing_info_before_auth));
5973 TestLoadTimingNotReused(load_timing_info_before_auth, 5880 TestLoadTimingNotReused(load_timing_info_before_auth,
5974 CONNECT_TIMING_HAS_DNS_TIMES); 5881 CONNECT_TIMING_HAS_DNS_TIMES);
5975 5882
5976 LoadTimingInfo load_timing_info; 5883 LoadTimingInfo load_timing_info;
5977 r.GetLoadTimingInfo(&load_timing_info); 5884 r->GetLoadTimingInfo(&load_timing_info);
5978 // The test server does not support keep alive sockets, so the second 5885 // The test server does not support keep alive sockets, so the second
5979 // request with auth should use a new socket. 5886 // request with auth should use a new socket.
5980 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5887 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5981 EXPECT_NE(load_timing_info_before_auth.socket_log_id, 5888 EXPECT_NE(load_timing_info_before_auth.socket_log_id,
5982 load_timing_info.socket_log_id); 5889 load_timing_info.socket_log_id);
5983 EXPECT_LE(load_timing_info_before_auth.receive_headers_end, 5890 EXPECT_LE(load_timing_info_before_auth.receive_headers_end,
5984 load_timing_info.connect_timing.connect_start); 5891 load_timing_info.connect_timing.connect_start);
5985 } 5892 }
5986 5893
5987 // Repeat request with end-to-end validation. Since auth-basic results in a 5894 // Repeat request with end-to-end validation. Since auth-basic results in a
5988 // cachable page, we expect this test to result in a 304. In which case, the 5895 // cachable page, we expect this test to result in a 304. In which case, the
5989 // response should be fetched from the cache. 5896 // response should be fetched from the cache.
5990 { 5897 {
5991 TestDelegate d; 5898 TestDelegate d;
5992 d.set_credentials(AuthCredentials(kUser, kSecret)); 5899 d.set_credentials(AuthCredentials(kUser, kSecret));
5993 5900
5994 URLRequest r(test_server_.GetURL("auth-basic"), 5901 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5995 DEFAULT_PRIORITY, 5902 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL));
5996 &d, 5903 r->SetLoadFlags(LOAD_VALIDATE_CACHE);
5997 &default_context_); 5904 r->Start();
5998 r.SetLoadFlags(LOAD_VALIDATE_CACHE);
5999 r.Start();
6000 5905
6001 base::RunLoop().Run(); 5906 base::RunLoop().Run();
6002 5907
6003 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5908 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6004 5909
6005 // Should be the same cached document. 5910 // Should be the same cached document.
6006 EXPECT_TRUE(r.was_cached()); 5911 EXPECT_TRUE(r->was_cached());
6007 5912
6008 // Since there was a request that went over the wire, the load timing 5913 // Since there was a request that went over the wire, the load timing
6009 // information should include connection times. 5914 // information should include connection times.
6010 LoadTimingInfo load_timing_info; 5915 LoadTimingInfo load_timing_info;
6011 r.GetLoadTimingInfo(&load_timing_info); 5916 r->GetLoadTimingInfo(&load_timing_info);
6012 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5917 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
6013 } 5918 }
6014 } 5919 }
6015 5920
6016 // In this test, we do a POST which the server will 302 redirect. 5921 // In this test, we do a POST which the server will 302 redirect.
6017 // The subsequent transaction should use GET, and should not send the 5922 // The subsequent transaction should use GET, and should not send the
6018 // Content-Type header. 5923 // Content-Type header.
6019 // http://code.google.com/p/chromium/issues/detail?id=843 5924 // http://code.google.com/p/chromium/issues/detail?id=843
6020 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 5925 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
6021 ASSERT_TRUE(test_server_.Start()); 5926 ASSERT_TRUE(test_server_.Start());
6022 5927
6023 const char kData[] = "hello world"; 5928 const char kData[] = "hello world";
6024 5929
6025 TestDelegate d; 5930 TestDelegate d;
6026 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), 5931 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6027 DEFAULT_PRIORITY, 5932 test_server_.GetURL("files/redirect-to-echoall"), DEFAULT_PRIORITY, &d,
6028 &d, 5933 NULL));
6029 &default_context_); 5934 req->set_method("POST");
6030 req.set_method("POST"); 5935 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6031 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6032 5936
6033 // Set headers (some of which are specific to the POST). 5937 // Set headers (some of which are specific to the POST).
6034 HttpRequestHeaders headers; 5938 HttpRequestHeaders headers;
6035 headers.AddHeadersFromString( 5939 headers.AddHeadersFromString(
6036 "Content-Type: multipart/form-data; " 5940 "Content-Type: multipart/form-data; "
6037 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" 5941 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
6038 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," 5942 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
6039 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" 5943 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
6040 "Accept-Language: en-US,en\r\n" 5944 "Accept-Language: en-US,en\r\n"
6041 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" 5945 "Accept-Charset: ISO-8859-1,*,utf-8\r\n"
6042 "Content-Length: 11\r\n" 5946 "Content-Length: 11\r\n"
6043 "Origin: http://localhost:1337/"); 5947 "Origin: http://localhost:1337/");
6044 req.SetExtraRequestHeaders(headers); 5948 req->SetExtraRequestHeaders(headers);
6045 req.Start(); 5949 req->Start();
6046 base::RunLoop().Run(); 5950 base::RunLoop().Run();
6047 5951
6048 std::string mime_type; 5952 std::string mime_type;
6049 req.GetMimeType(&mime_type); 5953 req->GetMimeType(&mime_type);
6050 EXPECT_EQ("text/html", mime_type); 5954 EXPECT_EQ("text/html", mime_type);
6051 5955
6052 const std::string& data = d.data_received(); 5956 const std::string& data = d.data_received();
6053 5957
6054 // Check that the post-specific headers were stripped: 5958 // Check that the post-specific headers were stripped:
6055 EXPECT_FALSE(ContainsString(data, "Content-Length:")); 5959 EXPECT_FALSE(ContainsString(data, "Content-Length:"));
6056 EXPECT_FALSE(ContainsString(data, "Content-Type:")); 5960 EXPECT_FALSE(ContainsString(data, "Content-Type:"));
6057 EXPECT_FALSE(ContainsString(data, "Origin:")); 5961 EXPECT_FALSE(ContainsString(data, "Origin:"));
6058 5962
6059 // These extra request headers should not have been stripped. 5963 // These extra request headers should not have been stripped.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
6118 6022
6119 // Make sure that 308 responses without bodies are not treated as redirects. 6023 // Make sure that 308 responses without bodies are not treated as redirects.
6120 // Certain legacy apis that pre-date the response code expect this behavior 6024 // Certain legacy apis that pre-date the response code expect this behavior
6121 // (Like Google Drive). 6025 // (Like Google Drive).
6122 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { 6026 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) {
6123 ASSERT_TRUE(test_server_.Start()); 6027 ASSERT_TRUE(test_server_.Start());
6124 6028
6125 TestDelegate d; 6029 TestDelegate d;
6126 const GURL url = test_server_.GetURL("files/308-without-location-header"); 6030 const GURL url = test_server_.GetURL("files/308-without-location-header");
6127 6031
6128 URLRequest request(url, DEFAULT_PRIORITY, &d, &default_context_); 6032 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
6033 url, DEFAULT_PRIORITY, &d, NULL));
6129 6034
6130 request.Start(); 6035 request->Start();
6131 base::RunLoop().Run(); 6036 base::RunLoop().Run();
6132 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); 6037 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status());
6133 EXPECT_EQ(OK, request.status().error()); 6038 EXPECT_EQ(OK, request->status().error());
6134 EXPECT_EQ(0, d.received_redirect_count()); 6039 EXPECT_EQ(0, d.received_redirect_count());
6135 EXPECT_EQ(308, request.response_headers()->response_code()); 6040 EXPECT_EQ(308, request->response_headers()->response_code());
6136 EXPECT_EQ("This is not a redirect.", d.data_received()); 6041 EXPECT_EQ("This is not a redirect.", d.data_received());
6137 } 6042 }
6138 6043
6139 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { 6044 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) {
6140 ASSERT_TRUE(test_server_.Start()); 6045 ASSERT_TRUE(test_server_.Start());
6141 6046
6142 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); 6047 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment"));
6143 GURL expected_url(test_server_.GetURL("echo#fragment")); 6048 GURL expected_url(test_server_.GetURL("echo#fragment"));
6144 6049
6145 TestDelegate d; 6050 TestDelegate d;
6146 { 6051 {
6147 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); 6052 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6053 original_url, DEFAULT_PRIORITY, &d, NULL));
6148 6054
6149 r.Start(); 6055 r->Start();
6150 base::RunLoop().Run(); 6056 base::RunLoop().Run();
6151 6057
6152 EXPECT_EQ(2U, r.url_chain().size()); 6058 EXPECT_EQ(2U, r->url_chain().size());
6153 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 6059 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6154 EXPECT_EQ(OK, r.status().error()); 6060 EXPECT_EQ(OK, r->status().error());
6155 EXPECT_EQ(original_url, r.original_url()); 6061 EXPECT_EQ(original_url, r->original_url());
6156 EXPECT_EQ(expected_url, r.url()); 6062 EXPECT_EQ(expected_url, r->url());
6157 } 6063 }
6158 } 6064 }
6159 6065
6160 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { 6066 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) {
6161 ASSERT_TRUE(test_server_.Start()); 6067 ASSERT_TRUE(test_server_.Start());
6162 6068
6163 GURL url(test_server_.GetURL("files/redirect302-to-echo")); 6069 GURL url(test_server_.GetURL("files/redirect302-to-echo"));
6164 GURL first_party_url("http://example.com"); 6070 GURL first_party_url("http://example.com");
6165 6071
6166 TestDelegate d; 6072 TestDelegate d;
6167 { 6073 {
6168 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); 6074 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6169 r.set_first_party_for_cookies(first_party_url); 6075 url, DEFAULT_PRIORITY, &d, NULL));
6076 r->set_first_party_for_cookies(first_party_url);
6170 6077
6171 r.Start(); 6078 r->Start();
6172 base::RunLoop().Run(); 6079 base::RunLoop().Run();
6173 6080
6174 EXPECT_EQ(2U, r.url_chain().size()); 6081 EXPECT_EQ(2U, r->url_chain().size());
6175 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 6082 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6176 EXPECT_EQ(OK, r.status().error()); 6083 EXPECT_EQ(OK, r->status().error());
6177 EXPECT_EQ(first_party_url, r.first_party_for_cookies()); 6084 EXPECT_EQ(first_party_url, r->first_party_for_cookies());
6178 } 6085 }
6179 } 6086 }
6180 6087
6181 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { 6088 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) {
6182 ASSERT_TRUE(test_server_.Start()); 6089 ASSERT_TRUE(test_server_.Start());
6183 6090
6184 GURL url(test_server_.GetURL("files/redirect302-to-echo")); 6091 GURL url(test_server_.GetURL("files/redirect302-to-echo"));
6185 GURL original_first_party_url("http://example.com"); 6092 GURL original_first_party_url("http://example.com");
6186 GURL expected_first_party_url(test_server_.GetURL("echo")); 6093 GURL expected_first_party_url(test_server_.GetURL("echo"));
6187 6094
6188 TestDelegate d; 6095 TestDelegate d;
6189 { 6096 {
6190 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); 6097 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6191 r.set_first_party_for_cookies(original_first_party_url); 6098 url, DEFAULT_PRIORITY, &d, NULL));
6192 r.set_first_party_url_policy( 6099 r->set_first_party_for_cookies(original_first_party_url);
6100 r->set_first_party_url_policy(
6193 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 6101 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
6194 6102
6195 r.Start(); 6103 r->Start();
6196 base::RunLoop().Run(); 6104 base::RunLoop().Run();
6197 6105
6198 EXPECT_EQ(2U, r.url_chain().size()); 6106 EXPECT_EQ(2U, r->url_chain().size());
6199 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 6107 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6200 EXPECT_EQ(OK, r.status().error()); 6108 EXPECT_EQ(OK, r->status().error());
6201 EXPECT_EQ(expected_first_party_url, r.first_party_for_cookies()); 6109 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies());
6202 } 6110 }
6203 } 6111 }
6204 6112
6205 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 6113 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
6206 ASSERT_TRUE(test_server_.Start()); 6114 ASSERT_TRUE(test_server_.Start());
6207 6115
6208 const char kData[] = "hello world"; 6116 const char kData[] = "hello world";
6209 6117
6210 TestDelegate d; 6118 TestDelegate d;
6211 URLRequest req(test_server_.GetURL("empty.html"), 6119 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6212 DEFAULT_PRIORITY, 6120 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL));
6213 &d, 6121 req->set_method("POST");
6214 &default_context_); 6122 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6215 req.set_method("POST");
6216 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6217 HttpRequestHeaders headers; 6123 HttpRequestHeaders headers;
6218 headers.SetHeader(HttpRequestHeaders::kContentLength, 6124 headers.SetHeader(HttpRequestHeaders::kContentLength,
6219 base::UintToString(arraysize(kData) - 1)); 6125 base::UintToString(arraysize(kData) - 1));
6220 req.SetExtraRequestHeaders(headers); 6126 req->SetExtraRequestHeaders(headers);
6221 6127
6222 URLRequestRedirectJob* job = new URLRequestRedirectJob( 6128 URLRequestRedirectJob* job = new URLRequestRedirectJob(
6223 &req, &default_network_delegate_, test_server_.GetURL("echo"), 6129 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6224 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 6130 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
6225 AddTestInterceptor()->set_main_intercept_job(job); 6131 AddTestInterceptor()->set_main_intercept_job(job);
6226 6132
6227 req.Start(); 6133 req->Start();
6228 base::RunLoop().Run(); 6134 base::RunLoop().Run();
6229 EXPECT_EQ("GET", req.method()); 6135 EXPECT_EQ("GET", req->method());
6230 } 6136 }
6231 6137
6232 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 6138 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
6233 ASSERT_TRUE(test_server_.Start()); 6139 ASSERT_TRUE(test_server_.Start());
6234 6140
6235 const char kData[] = "hello world"; 6141 const char kData[] = "hello world";
6236 6142
6237 TestDelegate d; 6143 TestDelegate d;
6238 URLRequest req(test_server_.GetURL("empty.html"), 6144 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6239 DEFAULT_PRIORITY, 6145 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL));
6240 &d, 6146 req->set_method("POST");
6241 &default_context_); 6147 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6242 req.set_method("POST");
6243 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6244 HttpRequestHeaders headers; 6148 HttpRequestHeaders headers;
6245 headers.SetHeader(HttpRequestHeaders::kContentLength, 6149 headers.SetHeader(HttpRequestHeaders::kContentLength,
6246 base::UintToString(arraysize(kData) - 1)); 6150 base::UintToString(arraysize(kData) - 1));
6247 req.SetExtraRequestHeaders(headers); 6151 req->SetExtraRequestHeaders(headers);
6248 6152
6249 URLRequestRedirectJob* job = new URLRequestRedirectJob( 6153 URLRequestRedirectJob* job = new URLRequestRedirectJob(
6250 &req, &default_network_delegate_, test_server_.GetURL("echo"), 6154 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6251 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, 6155 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
6252 "Very Good Reason"); 6156 "Very Good Reason");
6253 AddTestInterceptor()->set_main_intercept_job(job); 6157 AddTestInterceptor()->set_main_intercept_job(job);
6254 6158
6255 req.Start(); 6159 req->Start();
6256 base::RunLoop().Run(); 6160 base::RunLoop().Run();
6257 EXPECT_EQ("POST", req.method()); 6161 EXPECT_EQ("POST", req->method());
6258 EXPECT_EQ(kData, d.data_received()); 6162 EXPECT_EQ(kData, d.data_received());
6259 } 6163 }
6260 6164
6261 // Check that default A-L header is sent. 6165 // Check that default A-L header is sent.
6262 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { 6166 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) {
6263 ASSERT_TRUE(test_server_.Start()); 6167 ASSERT_TRUE(test_server_.Start());
6264 6168
6265 StaticHttpUserAgentSettings settings("en", std::string()); 6169 StaticHttpUserAgentSettings settings("en", std::string());
6266 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 6170 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
6267 TestURLRequestContext context(true); 6171 TestURLRequestContext context(true);
6268 context.set_network_delegate(&network_delegate); 6172 context.set_network_delegate(&network_delegate);
6269 context.set_http_user_agent_settings(&settings); 6173 context.set_http_user_agent_settings(&settings);
6270 context.Init(); 6174 context.Init();
6271 6175
6272 TestDelegate d; 6176 TestDelegate d;
6273 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), 6177 scoped_ptr<URLRequest> req(context.CreateRequest(
6274 DEFAULT_PRIORITY, 6178 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d,
6275 &d, 6179 NULL));
6276 &context); 6180 req->Start();
6277 req.Start();
6278 base::RunLoop().Run(); 6181 base::RunLoop().Run();
6279 EXPECT_EQ("en", d.data_received()); 6182 EXPECT_EQ("en", d.data_received());
6280 } 6183 }
6281 6184
6282 // Check that an empty A-L header is not sent. http://crbug.com/77365. 6185 // Check that an empty A-L header is not sent. http://crbug.com/77365.
6283 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { 6186 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) {
6284 ASSERT_TRUE(test_server_.Start()); 6187 ASSERT_TRUE(test_server_.Start());
6285 6188
6286 std::string empty_string; // Avoid most vexing parse on line below. 6189 std::string empty_string; // Avoid most vexing parse on line below.
6287 StaticHttpUserAgentSettings settings(empty_string, empty_string); 6190 StaticHttpUserAgentSettings settings(empty_string, empty_string);
6288 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 6191 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
6289 TestURLRequestContext context(true); 6192 TestURLRequestContext context(true);
6290 context.set_network_delegate(&network_delegate); 6193 context.set_network_delegate(&network_delegate);
6291 context.Init(); 6194 context.Init();
6292 // We override the language after initialization because empty entries 6195 // We override the language after initialization because empty entries
6293 // get overridden by Init(). 6196 // get overridden by Init().
6294 context.set_http_user_agent_settings(&settings); 6197 context.set_http_user_agent_settings(&settings);
6295 6198
6296 TestDelegate d; 6199 TestDelegate d;
6297 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), 6200 scoped_ptr<URLRequest> req(context.CreateRequest(
6298 DEFAULT_PRIORITY, 6201 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d,
6299 &d, 6202 NULL));
6300 &context); 6203 req->Start();
6301 req.Start();
6302 base::RunLoop().Run(); 6204 base::RunLoop().Run();
6303 EXPECT_EQ("None", d.data_received()); 6205 EXPECT_EQ("None", d.data_received());
6304 } 6206 }
6305 6207
6306 // Check that if request overrides the A-L header, the default is not appended. 6208 // Check that if request overrides the A-L header, the default is not appended.
6307 // See http://crbug.com/20894 6209 // See http://crbug.com/20894
6308 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { 6210 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
6309 ASSERT_TRUE(test_server_.Start()); 6211 ASSERT_TRUE(test_server_.Start());
6310 6212
6311 TestDelegate d; 6213 TestDelegate d;
6312 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), 6214 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6313 DEFAULT_PRIORITY, 6215 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d,
6314 &d, 6216 NULL));
6315 &default_context_);
6316 HttpRequestHeaders headers; 6217 HttpRequestHeaders headers;
6317 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); 6218 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru");
6318 req.SetExtraRequestHeaders(headers); 6219 req->SetExtraRequestHeaders(headers);
6319 req.Start(); 6220 req->Start();
6320 base::RunLoop().Run(); 6221 base::RunLoop().Run();
6321 EXPECT_EQ(std::string("ru"), d.data_received()); 6222 EXPECT_EQ(std::string("ru"), d.data_received());
6322 } 6223 }
6323 6224
6324 // Check that default A-E header is sent. 6225 // Check that default A-E header is sent.
6325 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { 6226 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) {
6326 ASSERT_TRUE(test_server_.Start()); 6227 ASSERT_TRUE(test_server_.Start());
6327 6228
6328 TestDelegate d; 6229 TestDelegate d;
6329 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), 6230 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6330 DEFAULT_PRIORITY, 6231 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d,
6331 &d, 6232 NULL));
6332 &default_context_);
6333 HttpRequestHeaders headers; 6233 HttpRequestHeaders headers;
6334 req.SetExtraRequestHeaders(headers); 6234 req->SetExtraRequestHeaders(headers);
6335 req.Start(); 6235 req->Start();
6336 base::RunLoop().Run(); 6236 base::RunLoop().Run();
6337 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); 6237 EXPECT_TRUE(ContainsString(d.data_received(), "gzip"));
6338 } 6238 }
6339 6239
6340 // Check that if request overrides the A-E header, the default is not appended. 6240 // Check that if request overrides the A-E header, the default is not appended.
6341 // See http://crbug.com/47381 6241 // See http://crbug.com/47381
6342 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { 6242 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) {
6343 ASSERT_TRUE(test_server_.Start()); 6243 ASSERT_TRUE(test_server_.Start());
6344 6244
6345 TestDelegate d; 6245 TestDelegate d;
6346 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), 6246 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6347 DEFAULT_PRIORITY, 6247 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d,
6348 &d, 6248 NULL));
6349 &default_context_);
6350 HttpRequestHeaders headers; 6249 HttpRequestHeaders headers;
6351 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); 6250 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity");
6352 req.SetExtraRequestHeaders(headers); 6251 req->SetExtraRequestHeaders(headers);
6353 req.Start(); 6252 req->Start();
6354 base::RunLoop().Run(); 6253 base::RunLoop().Run();
6355 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 6254 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
6356 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 6255 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
6357 } 6256 }
6358 6257
6359 // Check that setting the A-C header sends the proper header. 6258 // Check that setting the A-C header sends the proper header.
6360 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { 6259 TEST_F(URLRequestTestHTTP, SetAcceptCharset) {
6361 ASSERT_TRUE(test_server_.Start()); 6260 ASSERT_TRUE(test_server_.Start());
6362 6261
6363 TestDelegate d; 6262 TestDelegate d;
6364 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 6263 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6365 DEFAULT_PRIORITY, 6264 test_server_.GetURL("echoheader?Accept-Charset"), DEFAULT_PRIORITY, &d,
6366 &d, 6265 NULL));
6367 &default_context_);
6368 HttpRequestHeaders headers; 6266 HttpRequestHeaders headers;
6369 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); 6267 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r");
6370 req.SetExtraRequestHeaders(headers); 6268 req->SetExtraRequestHeaders(headers);
6371 req.Start(); 6269 req->Start();
6372 base::RunLoop().Run(); 6270 base::RunLoop().Run();
6373 EXPECT_EQ(std::string("koi-8r"), d.data_received()); 6271 EXPECT_EQ(std::string("koi-8r"), d.data_received());
6374 } 6272 }
6375 6273
6376 // Check that default User-Agent header is sent. 6274 // Check that default User-Agent header is sent.
6377 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { 6275 TEST_F(URLRequestTestHTTP, DefaultUserAgent) {
6378 ASSERT_TRUE(test_server_.Start()); 6276 ASSERT_TRUE(test_server_.Start());
6379 6277
6380 TestDelegate d; 6278 TestDelegate d;
6381 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), 6279 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6382 DEFAULT_PRIORITY, 6280 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d,
6383 &d, 6281 NULL));
6384 &default_context_); 6282 req->Start();
6385 req.Start();
6386 base::RunLoop().Run(); 6283 base::RunLoop().Run();
6387 EXPECT_EQ(req.context()->http_user_agent_settings()->GetUserAgent(), 6284 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(),
6388 d.data_received()); 6285 d.data_received());
6389 } 6286 }
6390 6287
6391 // Check that if request overrides the User-Agent header, 6288 // Check that if request overrides the User-Agent header,
6392 // the default is not appended. 6289 // the default is not appended.
6393 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { 6290 TEST_F(URLRequestTestHTTP, OverrideUserAgent) {
6394 ASSERT_TRUE(test_server_.Start()); 6291 ASSERT_TRUE(test_server_.Start());
6395 6292
6396 TestDelegate d; 6293 TestDelegate d;
6397 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), 6294 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6398 DEFAULT_PRIORITY, 6295 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d,
6399 &d, 6296 NULL));
6400 &default_context_);
6401 HttpRequestHeaders headers; 6297 HttpRequestHeaders headers;
6402 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 6298 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
6403 req.SetExtraRequestHeaders(headers); 6299 req->SetExtraRequestHeaders(headers);
6404 req.Start(); 6300 req->Start();
6405 base::RunLoop().Run(); 6301 base::RunLoop().Run();
6406 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); 6302 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received());
6407 } 6303 }
6408 6304
6409 // Check that a NULL HttpUserAgentSettings causes the corresponding empty 6305 // Check that a NULL HttpUserAgentSettings causes the corresponding empty
6410 // User-Agent header to be sent but does not send the Accept-Language and 6306 // User-Agent header to be sent but does not send the Accept-Language and
6411 // Accept-Charset headers. 6307 // Accept-Charset headers.
6412 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { 6308 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) {
6413 ASSERT_TRUE(test_server_.Start()); 6309 ASSERT_TRUE(test_server_.Start());
6414 6310
6415 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 6311 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
6416 TestURLRequestContext context(true); 6312 TestURLRequestContext context(true);
6417 context.set_network_delegate(&network_delegate); 6313 context.set_network_delegate(&network_delegate);
6418 context.Init(); 6314 context.Init();
6419 // We override the HttpUserAgentSettings after initialization because empty 6315 // We override the HttpUserAgentSettings after initialization because empty
6420 // entries get overridden by Init(). 6316 // entries get overridden by Init().
6421 context.set_http_user_agent_settings(NULL); 6317 context.set_http_user_agent_settings(NULL);
6422 6318
6423 struct { 6319 struct {
6424 const char* request; 6320 const char* request;
6425 const char* expected_response; 6321 const char* expected_response;
6426 } tests[] = { { "echoheader?Accept-Language", "None" }, 6322 } tests[] = { { "echoheader?Accept-Language", "None" },
6427 { "echoheader?Accept-Charset", "None" }, 6323 { "echoheader?Accept-Charset", "None" },
6428 { "echoheader?User-Agent", "" } }; 6324 { "echoheader?User-Agent", "" } };
6429 6325
6430 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { 6326 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
6431 TestDelegate d; 6327 TestDelegate d;
6432 URLRequest req( 6328 scoped_ptr<URLRequest> req(context.CreateRequest(
6433 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, &context); 6329 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, NULL));
6434 req.Start(); 6330 req->Start();
6435 base::RunLoop().Run(); 6331 base::RunLoop().Run();
6436 EXPECT_EQ(tests[i].expected_response, d.data_received()) 6332 EXPECT_EQ(tests[i].expected_response, d.data_received())
6437 << " Request = \"" << tests[i].request << "\""; 6333 << " Request = \"" << tests[i].request << "\"";
6438 } 6334 }
6439 } 6335 }
6440 6336
6441 // Make sure that URLRequest passes on its priority updates to 6337 // Make sure that URLRequest passes on its priority updates to
6442 // newly-created jobs after the first one. 6338 // newly-created jobs after the first one.
6443 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { 6339 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
6444 ASSERT_TRUE(test_server_.Start()); 6340 ASSERT_TRUE(test_server_.Start());
6445 6341
6446 TestDelegate d; 6342 TestDelegate d;
6447 URLRequest req(test_server_.GetURL("empty.html"), 6343 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6448 DEFAULT_PRIORITY, 6344 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL));
6449 &d, 6345 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
6450 &default_context_);
6451 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
6452 6346
6453 scoped_refptr<URLRequestRedirectJob> redirect_job = 6347 scoped_refptr<URLRequestRedirectJob> redirect_job =
6454 new URLRequestRedirectJob( 6348 new URLRequestRedirectJob(
6455 &req, &default_network_delegate_, test_server_.GetURL("echo"), 6349 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6456 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 6350 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
6457 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); 6351 AddTestInterceptor()->set_main_intercept_job(redirect_job.get());
6458 6352
6459 req.SetPriority(LOW); 6353 req->SetPriority(LOW);
6460 req.Start(); 6354 req->Start();
6461 EXPECT_TRUE(req.is_pending()); 6355 EXPECT_TRUE(req->is_pending());
6462 6356
6463 scoped_refptr<URLRequestTestJob> job = 6357 scoped_refptr<URLRequestTestJob> job =
6464 new URLRequestTestJob(&req, &default_network_delegate_); 6358 new URLRequestTestJob(req.get(), &default_network_delegate_);
6465 AddTestInterceptor()->set_main_intercept_job(job.get()); 6359 AddTestInterceptor()->set_main_intercept_job(job.get());
6466 6360
6467 // Should trigger |job| to be started. 6361 // Should trigger |job| to be started.
6468 base::RunLoop().Run(); 6362 base::RunLoop().Run();
6469 EXPECT_EQ(LOW, job->priority()); 6363 EXPECT_EQ(LOW, job->priority());
6470 } 6364 }
6471 6365
6472 // Check that creating a network request while entering/exiting suspend mode 6366 // Check that creating a network request while entering/exiting suspend mode
6473 // fails as it should. This is the only case where an HttpTransactionFactory 6367 // fails as it should. This is the only case where an HttpTransactionFactory
6474 // does not return an HttpTransaction. 6368 // does not return an HttpTransaction.
(...skipping 14 matching lines...) Expand all
6489 network_layer->OnSuspend(); 6383 network_layer->OnSuspend();
6490 6384
6491 HttpCache http_cache(network_layer.release(), default_context_.net_log(), 6385 HttpCache http_cache(network_layer.release(), default_context_.net_log(),
6492 HttpCache::DefaultBackend::InMemory(0)); 6386 HttpCache::DefaultBackend::InMemory(0));
6493 6387
6494 TestURLRequestContext context(true); 6388 TestURLRequestContext context(true);
6495 context.set_http_transaction_factory(&http_cache); 6389 context.set_http_transaction_factory(&http_cache);
6496 context.Init(); 6390 context.Init();
6497 6391
6498 TestDelegate d; 6392 TestDelegate d;
6499 URLRequest req(GURL("http://127.0.0.1/"), 6393 scoped_ptr<URLRequest> req(context.CreateRequest(
6500 DEFAULT_PRIORITY, 6394 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL));
6501 &d, 6395 req->Start();
6502 &context);
6503 req.Start();
6504 base::RunLoop().Run(); 6396 base::RunLoop().Run();
6505 6397
6506 EXPECT_TRUE(d.request_failed()); 6398 EXPECT_TRUE(d.request_failed());
6507 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 6399 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
6508 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); 6400 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error());
6509 } 6401 }
6510 6402
6511 // Check that creating a network request while entering/exiting suspend mode 6403 // Check that creating a network request while entering/exiting suspend mode
6512 // fails as it should in the case there is no cache. This is the only case 6404 // fails as it should in the case there is no cache. This is the only case
6513 // where an HttpTransactionFactory does not return an HttpTransaction. 6405 // where an HttpTransactionFactory does not return an HttpTransaction.
6514 TEST_F(URLRequestTestHTTP, NetworkSuspendTestNoCache) { 6406 TEST_F(URLRequestTestHTTP, NetworkSuspendTestNoCache) {
6515 // Create a new HttpNetworkLayer that thinks it's suspended. 6407 // Create a new HttpNetworkLayer that thinks it's suspended.
6516 HttpNetworkSession::Params params; 6408 HttpNetworkSession::Params params;
6517 params.host_resolver = default_context_.host_resolver(); 6409 params.host_resolver = default_context_.host_resolver();
6518 params.cert_verifier = default_context_.cert_verifier(); 6410 params.cert_verifier = default_context_.cert_verifier();
6519 params.transport_security_state = default_context_.transport_security_state(); 6411 params.transport_security_state = default_context_.transport_security_state();
6520 params.proxy_service = default_context_.proxy_service(); 6412 params.proxy_service = default_context_.proxy_service();
6521 params.ssl_config_service = default_context_.ssl_config_service(); 6413 params.ssl_config_service = default_context_.ssl_config_service();
6522 params.http_auth_handler_factory = 6414 params.http_auth_handler_factory =
6523 default_context_.http_auth_handler_factory(); 6415 default_context_.http_auth_handler_factory();
6524 params.network_delegate = &default_network_delegate_; 6416 params.network_delegate = &default_network_delegate_;
6525 params.http_server_properties = default_context_.http_server_properties(); 6417 params.http_server_properties = default_context_.http_server_properties();
6526 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); 6418 HttpNetworkLayer network_layer(new HttpNetworkSession(params));
6527 network_layer.OnSuspend(); 6419 network_layer.OnSuspend();
6528 6420
6529 TestURLRequestContext context(true); 6421 TestURLRequestContext context(true);
6530 context.set_http_transaction_factory(&network_layer); 6422 context.set_http_transaction_factory(&network_layer);
6531 context.Init(); 6423 context.Init();
6532 6424
6533 TestDelegate d; 6425 TestDelegate d;
6534 URLRequest req(GURL("http://127.0.0.1/"), 6426 scoped_ptr<URLRequest> req(context.CreateRequest(
6535 DEFAULT_PRIORITY, 6427 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL));
6536 &d, 6428 req->Start();
6537 &context);
6538 req.Start();
6539 base::RunLoop().Run(); 6429 base::RunLoop().Run();
6540 6430
6541 EXPECT_TRUE(d.request_failed()); 6431 EXPECT_TRUE(d.request_failed());
6542 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 6432 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
6543 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); 6433 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error());
6544 } 6434 }
6545 6435
6546 class HTTPSRequestTest : public testing::Test { 6436 class HTTPSRequestTest : public testing::Test {
6547 public: 6437 public:
6548 HTTPSRequestTest() : default_context_(true) { 6438 HTTPSRequestTest() : default_context_(true) {
6549 default_context_.set_network_delegate(&default_network_delegate_); 6439 default_context_.set_network_delegate(&default_network_delegate_);
6550 default_context_.Init(); 6440 default_context_.Init();
6551 } 6441 }
6552 virtual ~HTTPSRequestTest() {} 6442 virtual ~HTTPSRequestTest() {}
6553 6443
6554 protected: 6444 protected:
6555 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 6445 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
6556 TestURLRequestContext default_context_; 6446 TestURLRequestContext default_context_;
6557 }; 6447 };
6558 6448
6559 TEST_F(HTTPSRequestTest, HTTPSGetTest) { 6449 TEST_F(HTTPSRequestTest, HTTPSGetTest) {
6560 SpawnedTestServer test_server( 6450 SpawnedTestServer test_server(
6561 SpawnedTestServer::TYPE_HTTPS, 6451 SpawnedTestServer::TYPE_HTTPS,
6562 SpawnedTestServer::kLocalhost, 6452 SpawnedTestServer::kLocalhost,
6563 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6453 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6564 ASSERT_TRUE(test_server.Start()); 6454 ASSERT_TRUE(test_server.Start());
6565 6455
6566 TestDelegate d; 6456 TestDelegate d;
6567 { 6457 {
6568 URLRequest r(test_server.GetURL(std::string()), 6458 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6569 DEFAULT_PRIORITY, 6459 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
6570 &d, 6460 r->Start();
6571 &default_context_); 6461 EXPECT_TRUE(r->is_pending());
6572 r.Start();
6573 EXPECT_TRUE(r.is_pending());
6574 6462
6575 base::RunLoop().Run(); 6463 base::RunLoop().Run();
6576 6464
6577 EXPECT_EQ(1, d.response_started_count()); 6465 EXPECT_EQ(1, d.response_started_count());
6578 EXPECT_FALSE(d.received_data_before_response()); 6466 EXPECT_FALSE(d.received_data_before_response());
6579 EXPECT_NE(0, d.bytes_received()); 6467 EXPECT_NE(0, d.bytes_received());
6580 CheckSSLInfo(r.ssl_info()); 6468 CheckSSLInfo(r->ssl_info());
6581 EXPECT_EQ(test_server.host_port_pair().host(), 6469 EXPECT_EQ(test_server.host_port_pair().host(),
6582 r.GetSocketAddress().host()); 6470 r->GetSocketAddress().host());
6583 EXPECT_EQ(test_server.host_port_pair().port(), 6471 EXPECT_EQ(test_server.host_port_pair().port(),
6584 r.GetSocketAddress().port()); 6472 r->GetSocketAddress().port());
6585 } 6473 }
6586 } 6474 }
6587 6475
6588 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { 6476 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) {
6589 SpawnedTestServer::SSLOptions ssl_options( 6477 SpawnedTestServer::SSLOptions ssl_options(
6590 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); 6478 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME);
6591 SpawnedTestServer test_server( 6479 SpawnedTestServer test_server(
6592 SpawnedTestServer::TYPE_HTTPS, 6480 SpawnedTestServer::TYPE_HTTPS,
6593 ssl_options, 6481 ssl_options,
6594 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6482 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6595 ASSERT_TRUE(test_server.Start()); 6483 ASSERT_TRUE(test_server.Start());
6596 6484
6597 bool err_allowed = true; 6485 bool err_allowed = true;
6598 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 6486 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
6599 TestDelegate d; 6487 TestDelegate d;
6600 { 6488 {
6601 d.set_allow_certificate_errors(err_allowed); 6489 d.set_allow_certificate_errors(err_allowed);
6602 URLRequest r(test_server.GetURL(std::string()), 6490 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6603 DEFAULT_PRIORITY, 6491 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
6604 &d,
6605 &default_context_);
6606 6492
6607 r.Start(); 6493 r->Start();
6608 EXPECT_TRUE(r.is_pending()); 6494 EXPECT_TRUE(r->is_pending());
6609 6495
6610 base::RunLoop().Run(); 6496 base::RunLoop().Run();
6611 6497
6612 EXPECT_EQ(1, d.response_started_count()); 6498 EXPECT_EQ(1, d.response_started_count());
6613 EXPECT_FALSE(d.received_data_before_response()); 6499 EXPECT_FALSE(d.received_data_before_response());
6614 EXPECT_TRUE(d.have_certificate_errors()); 6500 EXPECT_TRUE(d.have_certificate_errors());
6615 if (err_allowed) { 6501 if (err_allowed) {
6616 EXPECT_NE(0, d.bytes_received()); 6502 EXPECT_NE(0, d.bytes_received());
6617 CheckSSLInfo(r.ssl_info()); 6503 CheckSSLInfo(r->ssl_info());
6618 } else { 6504 } else {
6619 EXPECT_EQ(0, d.bytes_received()); 6505 EXPECT_EQ(0, d.bytes_received());
6620 } 6506 }
6621 } 6507 }
6622 } 6508 }
6623 } 6509 }
6624 6510
6625 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { 6511 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) {
6626 SpawnedTestServer::SSLOptions ssl_options( 6512 SpawnedTestServer::SSLOptions ssl_options(
6627 SpawnedTestServer::SSLOptions::CERT_EXPIRED); 6513 SpawnedTestServer::SSLOptions::CERT_EXPIRED);
6628 SpawnedTestServer test_server( 6514 SpawnedTestServer test_server(
6629 SpawnedTestServer::TYPE_HTTPS, 6515 SpawnedTestServer::TYPE_HTTPS,
6630 ssl_options, 6516 ssl_options,
6631 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6517 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6632 ASSERT_TRUE(test_server.Start()); 6518 ASSERT_TRUE(test_server.Start());
6633 6519
6634 // Iterate from false to true, just so that we do the opposite of the 6520 // Iterate from false to true, just so that we do the opposite of the
6635 // previous test in order to increase test coverage. 6521 // previous test in order to increase test coverage.
6636 bool err_allowed = false; 6522 bool err_allowed = false;
6637 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 6523 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
6638 TestDelegate d; 6524 TestDelegate d;
6639 { 6525 {
6640 d.set_allow_certificate_errors(err_allowed); 6526 d.set_allow_certificate_errors(err_allowed);
6641 URLRequest r(test_server.GetURL(std::string()), 6527 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6642 DEFAULT_PRIORITY, 6528 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
6643 &d,
6644 &default_context_);
6645 6529
6646 r.Start(); 6530 r->Start();
6647 EXPECT_TRUE(r.is_pending()); 6531 EXPECT_TRUE(r->is_pending());
6648 6532
6649 base::RunLoop().Run(); 6533 base::RunLoop().Run();
6650 6534
6651 EXPECT_EQ(1, d.response_started_count()); 6535 EXPECT_EQ(1, d.response_started_count());
6652 EXPECT_FALSE(d.received_data_before_response()); 6536 EXPECT_FALSE(d.received_data_before_response());
6653 EXPECT_TRUE(d.have_certificate_errors()); 6537 EXPECT_TRUE(d.have_certificate_errors());
6654 if (err_allowed) { 6538 if (err_allowed) {
6655 EXPECT_NE(0, d.bytes_received()); 6539 EXPECT_NE(0, d.bytes_received());
6656 CheckSSLInfo(r.ssl_info()); 6540 CheckSSLInfo(r->ssl_info());
6657 } else { 6541 } else {
6658 EXPECT_EQ(0, d.bytes_received()); 6542 EXPECT_EQ(0, d.bytes_received());
6659 } 6543 }
6660 } 6544 }
6661 } 6545 }
6662 } 6546 }
6663 6547
6664 // This tests that a load of www.google.com with a certificate error sets 6548 // This tests that a load of www.google.com with a certificate error sets
6665 // the |certificate_errors_are_fatal| flag correctly. This flag will cause 6549 // the |certificate_errors_are_fatal| flag correctly. This flag will cause
6666 // the interstitial to be fatal. 6550 // the interstitial to be fatal.
(...skipping 14 matching lines...) Expand all
6681 MockHostResolver host_resolver; 6565 MockHostResolver host_resolver;
6682 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 6566 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
6683 TestURLRequestContext context(true); 6567 TestURLRequestContext context(true);
6684 context.set_network_delegate(&network_delegate); 6568 context.set_network_delegate(&network_delegate);
6685 context.set_host_resolver(&host_resolver); 6569 context.set_host_resolver(&host_resolver);
6686 TransportSecurityState transport_security_state; 6570 TransportSecurityState transport_security_state;
6687 context.set_transport_security_state(&transport_security_state); 6571 context.set_transport_security_state(&transport_security_state);
6688 context.Init(); 6572 context.Init();
6689 6573
6690 TestDelegate d; 6574 TestDelegate d;
6691 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 6575 scoped_ptr<URLRequest> r(context.CreateRequest(
6692 test_server.host_port_pair().port())), 6576 GURL(base::StringPrintf("https://www.google.com:%d",
6693 DEFAULT_PRIORITY, 6577 test_server.host_port_pair().port())),
6694 &d, 6578 DEFAULT_PRIORITY, &d, NULL));
6695 &context);
6696 6579
6697 r.Start(); 6580 r->Start();
6698 EXPECT_TRUE(r.is_pending()); 6581 EXPECT_TRUE(r->is_pending());
6699 6582
6700 base::RunLoop().Run(); 6583 base::RunLoop().Run();
6701 6584
6702 EXPECT_EQ(1, d.response_started_count()); 6585 EXPECT_EQ(1, d.response_started_count());
6703 EXPECT_FALSE(d.received_data_before_response()); 6586 EXPECT_FALSE(d.received_data_before_response());
6704 EXPECT_TRUE(d.have_certificate_errors()); 6587 EXPECT_TRUE(d.have_certificate_errors());
6705 EXPECT_TRUE(d.certificate_errors_are_fatal()); 6588 EXPECT_TRUE(d.certificate_errors_are_fatal());
6706 } 6589 }
6707 6590
6708 // This tests that cached HTTPS page loads do not cause any updates to the 6591 // This tests that cached HTTPS page loads do not cause any updates to the
(...skipping 25 matching lines...) Expand all
6734 EXPECT_TRUE(transport_security_state.GetStaticDomainState( 6617 EXPECT_TRUE(transport_security_state.GetStaticDomainState(
6735 "www.google.com", true, &static_domain_state)); 6618 "www.google.com", true, &static_domain_state));
6736 context.set_transport_security_state(&transport_security_state); 6619 context.set_transport_security_state(&transport_security_state);
6737 context.Init(); 6620 context.Init();
6738 6621
6739 TransportSecurityState::DomainState dynamic_domain_state; 6622 TransportSecurityState::DomainState dynamic_domain_state;
6740 EXPECT_FALSE(transport_security_state.GetDynamicDomainState( 6623 EXPECT_FALSE(transport_security_state.GetDynamicDomainState(
6741 "www.google.com", &dynamic_domain_state)); 6624 "www.google.com", &dynamic_domain_state));
6742 6625
6743 TestDelegate d; 6626 TestDelegate d;
6744 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 6627 scoped_ptr<URLRequest> r(context.CreateRequest(
6745 test_server.host_port_pair().port())), 6628 GURL(base::StringPrintf("https://www.google.com:%d",
6746 DEFAULT_PRIORITY, 6629 test_server.host_port_pair().port())),
6747 &d, 6630 DEFAULT_PRIORITY, &d, NULL));
6748 &context);
6749 6631
6750 r.Start(); 6632 r->Start();
6751 EXPECT_TRUE(r.is_pending()); 6633 EXPECT_TRUE(r->is_pending());
6752 6634
6753 base::RunLoop().Run(); 6635 base::RunLoop().Run();
6754 6636
6755 EXPECT_EQ(1, d.response_started_count()); 6637 EXPECT_EQ(1, d.response_started_count());
6756 EXPECT_FALSE(d.received_data_before_response()); 6638 EXPECT_FALSE(d.received_data_before_response());
6757 EXPECT_TRUE(d.have_certificate_errors()); 6639 EXPECT_TRUE(d.have_certificate_errors());
6758 EXPECT_TRUE(d.certificate_errors_are_fatal()); 6640 EXPECT_TRUE(d.certificate_errors_are_fatal());
6759 6641
6760 // Get a fresh copy of the states, and check that they haven't changed. 6642 // Get a fresh copy of the states, and check that they haven't changed.
6761 TransportSecurityState::DomainState new_static_domain_state; 6643 TransportSecurityState::DomainState new_static_domain_state;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
6809 context.set_host_resolver(&host_resolver); 6691 context.set_host_resolver(&host_resolver);
6810 context.set_transport_security_state(&transport_security_state); 6692 context.set_transport_security_state(&transport_security_state);
6811 context.set_network_delegate(&network_delegate); 6693 context.set_network_delegate(&network_delegate);
6812 context.Init(); 6694 context.Init();
6813 6695
6814 TestDelegate d; 6696 TestDelegate d;
6815 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will 6697 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will
6816 // cause a certificate error. Ignore the error. 6698 // cause a certificate error. Ignore the error.
6817 d.set_allow_certificate_errors(true); 6699 d.set_allow_certificate_errors(true);
6818 6700
6819 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", 6701 scoped_ptr<URLRequest> req(context.CreateRequest(
6820 test_server.host_port_pair().port())), 6702 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo",
6821 DEFAULT_PRIORITY, 6703 test_server.host_port_pair().port())),
6822 &d, 6704 DEFAULT_PRIORITY, &d, NULL));
6823 &context); 6705 req->set_method("POST");
6824 req.set_method("POST"); 6706 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6825 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
6826 6707
6827 req.Start(); 6708 req->Start();
6828 base::RunLoop().Run(); 6709 base::RunLoop().Run();
6829 6710
6830 EXPECT_EQ("https", req.url().scheme()); 6711 EXPECT_EQ("https", req->url().scheme());
6831 EXPECT_EQ("POST", req.method()); 6712 EXPECT_EQ("POST", req->method());
6832 EXPECT_EQ(kData, d.data_received()); 6713 EXPECT_EQ(kData, d.data_received());
6833 6714
6834 LoadTimingInfo load_timing_info; 6715 LoadTimingInfo load_timing_info;
6835 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); 6716 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info);
6836 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits 6717 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits
6837 TestLoadTimingCacheHitNoNetwork(load_timing_info); 6718 TestLoadTimingCacheHitNoNetwork(load_timing_info);
6838 } 6719 }
6839 6720
6840 namespace { 6721 namespace {
6841 6722
(...skipping 25 matching lines...) Expand all
6867 SpawnedTestServer::SSLOptions ssl_options; 6748 SpawnedTestServer::SSLOptions ssl_options;
6868 ssl_options.request_client_certificate = true; 6749 ssl_options.request_client_certificate = true;
6869 SpawnedTestServer test_server( 6750 SpawnedTestServer test_server(
6870 SpawnedTestServer::TYPE_HTTPS, 6751 SpawnedTestServer::TYPE_HTTPS,
6871 ssl_options, 6752 ssl_options,
6872 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6753 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6873 ASSERT_TRUE(test_server.Start()); 6754 ASSERT_TRUE(test_server.Start());
6874 6755
6875 SSLClientAuthTestDelegate d; 6756 SSLClientAuthTestDelegate d;
6876 { 6757 {
6877 URLRequest r(test_server.GetURL(std::string()), 6758 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6878 DEFAULT_PRIORITY, 6759 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
6879 &d,
6880 &default_context_);
6881 6760
6882 r.Start(); 6761 r->Start();
6883 EXPECT_TRUE(r.is_pending()); 6762 EXPECT_TRUE(r->is_pending());
6884 6763
6885 base::RunLoop().Run(); 6764 base::RunLoop().Run();
6886 6765
6887 EXPECT_EQ(1, d.on_certificate_requested_count()); 6766 EXPECT_EQ(1, d.on_certificate_requested_count());
6888 EXPECT_FALSE(d.received_data_before_response()); 6767 EXPECT_FALSE(d.received_data_before_response());
6889 EXPECT_EQ(0, d.bytes_received()); 6768 EXPECT_EQ(0, d.bytes_received());
6890 6769
6891 // Send no certificate. 6770 // Send no certificate.
6892 // TODO(davidben): Get temporary client cert import (with keys) working on 6771 // TODO(davidben): Get temporary client cert import (with keys) working on
6893 // all platforms so we can test sending a cert as well. 6772 // all platforms so we can test sending a cert as well.
6894 r.ContinueWithCertificate(NULL); 6773 r->ContinueWithCertificate(NULL);
6895 6774
6896 base::RunLoop().Run(); 6775 base::RunLoop().Run();
6897 6776
6898 EXPECT_EQ(1, d.response_started_count()); 6777 EXPECT_EQ(1, d.response_started_count());
6899 EXPECT_FALSE(d.received_data_before_response()); 6778 EXPECT_FALSE(d.received_data_before_response());
6900 EXPECT_NE(0, d.bytes_received()); 6779 EXPECT_NE(0, d.bytes_received());
6901 } 6780 }
6902 } 6781 }
6903 6782
6904 TEST_F(HTTPSRequestTest, ResumeTest) { 6783 TEST_F(HTTPSRequestTest, ResumeTest) {
6905 // Test that we attempt a session resume when making two connections to the 6784 // Test that we attempt a session resume when making two connections to the
6906 // same host. 6785 // same host.
6907 SpawnedTestServer::SSLOptions ssl_options; 6786 SpawnedTestServer::SSLOptions ssl_options;
6908 ssl_options.record_resume = true; 6787 ssl_options.record_resume = true;
6909 SpawnedTestServer test_server( 6788 SpawnedTestServer test_server(
6910 SpawnedTestServer::TYPE_HTTPS, 6789 SpawnedTestServer::TYPE_HTTPS,
6911 ssl_options, 6790 ssl_options,
6912 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6791 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6913 ASSERT_TRUE(test_server.Start()); 6792 ASSERT_TRUE(test_server.Start());
6914 6793
6915 SSLClientSocket::ClearSessionCache(); 6794 SSLClientSocket::ClearSessionCache();
6916 6795
6917 { 6796 {
6918 TestDelegate d; 6797 TestDelegate d;
6919 URLRequest r(test_server.GetURL("ssl-session-cache"), 6798 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6920 DEFAULT_PRIORITY, 6799 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
6921 &d,
6922 &default_context_);
6923 6800
6924 r.Start(); 6801 r->Start();
6925 EXPECT_TRUE(r.is_pending()); 6802 EXPECT_TRUE(r->is_pending());
6926 6803
6927 base::RunLoop().Run(); 6804 base::RunLoop().Run();
6928 6805
6929 EXPECT_EQ(1, d.response_started_count()); 6806 EXPECT_EQ(1, d.response_started_count());
6930 } 6807 }
6931 6808
6932 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> 6809 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
6933 CloseAllConnections(); 6810 CloseAllConnections();
6934 6811
6935 { 6812 {
6936 TestDelegate d; 6813 TestDelegate d;
6937 URLRequest r(test_server.GetURL("ssl-session-cache"), 6814 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6938 DEFAULT_PRIORITY, 6815 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
6939 &d,
6940 &default_context_);
6941 6816
6942 r.Start(); 6817 r->Start();
6943 EXPECT_TRUE(r.is_pending()); 6818 EXPECT_TRUE(r->is_pending());
6944 6819
6945 base::RunLoop().Run(); 6820 base::RunLoop().Run();
6946 6821
6947 // The response will look like; 6822 // The response will look like;
6948 // insert abc 6823 // insert abc
6949 // lookup abc 6824 // lookup abc
6950 // insert xyz 6825 // insert xyz
6951 // 6826 //
6952 // With a newline at the end which makes the split think that there are 6827 // With a newline at the end which makes the split think that there are
6953 // four lines. 6828 // four lines.
(...skipping 28 matching lines...) Expand all
6982 SpawnedTestServer test_server( 6857 SpawnedTestServer test_server(
6983 SpawnedTestServer::TYPE_HTTPS, 6858 SpawnedTestServer::TYPE_HTTPS,
6984 ssl_options, 6859 ssl_options,
6985 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6860 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6986 ASSERT_TRUE(test_server.Start()); 6861 ASSERT_TRUE(test_server.Start());
6987 6862
6988 SSLClientSocket::ClearSessionCache(); 6863 SSLClientSocket::ClearSessionCache();
6989 6864
6990 { 6865 {
6991 TestDelegate d; 6866 TestDelegate d;
6992 URLRequest r(test_server.GetURL("ssl-session-cache"), 6867 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6993 DEFAULT_PRIORITY, 6868 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
6994 &d,
6995 &default_context_);
6996 6869
6997 r.Start(); 6870 r->Start();
6998 EXPECT_TRUE(r.is_pending()); 6871 EXPECT_TRUE(r->is_pending());
6999 6872
7000 base::RunLoop().Run(); 6873 base::RunLoop().Run();
7001 6874
7002 EXPECT_EQ(1, d.response_started_count()); 6875 EXPECT_EQ(1, d.response_started_count());
7003 } 6876 }
7004 6877
7005 // Now create a new HttpCache with a different ssl_session_cache_shard value. 6878 // Now create a new HttpCache with a different ssl_session_cache_shard value.
7006 HttpNetworkSession::Params params; 6879 HttpNetworkSession::Params params;
7007 params.host_resolver = default_context_.host_resolver(); 6880 params.host_resolver = default_context_.host_resolver();
7008 params.cert_verifier = default_context_.cert_verifier(); 6881 params.cert_verifier = default_context_.cert_verifier();
7009 params.transport_security_state = default_context_.transport_security_state(); 6882 params.transport_security_state = default_context_.transport_security_state();
7010 params.proxy_service = default_context_.proxy_service(); 6883 params.proxy_service = default_context_.proxy_service();
7011 params.ssl_config_service = default_context_.ssl_config_service(); 6884 params.ssl_config_service = default_context_.ssl_config_service();
7012 params.http_auth_handler_factory = 6885 params.http_auth_handler_factory =
7013 default_context_.http_auth_handler_factory(); 6886 default_context_.http_auth_handler_factory();
7014 params.network_delegate = &default_network_delegate_; 6887 params.network_delegate = &default_network_delegate_;
7015 params.http_server_properties = default_context_.http_server_properties(); 6888 params.http_server_properties = default_context_.http_server_properties();
7016 params.ssl_session_cache_shard = "alternate"; 6889 params.ssl_session_cache_shard = "alternate";
7017 6890
7018 scoped_ptr<HttpCache> cache(new HttpCache( 6891 scoped_ptr<HttpCache> cache(new HttpCache(
7019 new HttpNetworkSession(params), 6892 new HttpNetworkSession(params),
7020 HttpCache::DefaultBackend::InMemory(0))); 6893 HttpCache::DefaultBackend::InMemory(0)));
7021 6894
7022 default_context_.set_http_transaction_factory(cache.get()); 6895 default_context_.set_http_transaction_factory(cache.get());
7023 6896
7024 { 6897 {
7025 TestDelegate d; 6898 TestDelegate d;
7026 URLRequest r(test_server.GetURL("ssl-session-cache"), 6899 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7027 DEFAULT_PRIORITY, 6900 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
7028 &d,
7029 &default_context_);
7030 6901
7031 r.Start(); 6902 r->Start();
7032 EXPECT_TRUE(r.is_pending()); 6903 EXPECT_TRUE(r->is_pending());
7033 6904
7034 base::RunLoop().Run(); 6905 base::RunLoop().Run();
7035 6906
7036 // The response will look like; 6907 // The response will look like;
7037 // insert abc 6908 // insert abc
7038 // insert xyz 6909 // insert xyz
7039 // 6910 //
7040 // With a newline at the end which makes the split think that there are 6911 // With a newline at the end which makes the split think that there are
7041 // three lines. 6912 // three lines.
7042 6913
(...skipping 27 matching lines...) Expand all
7070 6941
7071 protected: 6942 protected:
7072 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) { 6943 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) {
7073 DCHECK(!request_); 6944 DCHECK(!request_);
7074 SpawnedTestServer test_server( 6945 SpawnedTestServer test_server(
7075 SpawnedTestServer::TYPE_HTTPS, 6946 SpawnedTestServer::TYPE_HTTPS,
7076 ssl_options, 6947 ssl_options,
7077 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6948 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7078 ASSERT_TRUE(test_server.Start()); 6949 ASSERT_TRUE(test_server.Start());
7079 6950
7080 request_.reset(new URLRequest( 6951 request_ = context_.CreateRequest(
7081 test_server.GetURL(std::string()), DEFAULT_PRIORITY, 6952 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate_, NULL);
7082 &delegate_, &context_));
7083 request_->Start(); 6953 request_->Start();
7084 6954
7085 base::RunLoop().Run(); 6955 base::RunLoop().Run();
7086 } 6956 }
7087 6957
7088 void ExpectConnection(int version) { 6958 void ExpectConnection(int version) {
7089 EXPECT_EQ(1, delegate_.response_started_count()); 6959 EXPECT_EQ(1, delegate_.response_started_count());
7090 EXPECT_NE(0, delegate_.bytes_received()); 6960 EXPECT_NE(0, delegate_.bytes_received());
7091 EXPECT_EQ(version, SSLConnectionStatusToVersion( 6961 EXPECT_EQ(version, SSLConnectionStatusToVersion(
7092 request_->ssl_info().connection_status)); 6962 request_->ssl_info().connection_status));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
7247 ssl_options, 7117 ssl_options,
7248 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7118 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7249 ASSERT_TRUE(test_server.Start()); 7119 ASSERT_TRUE(test_server.Start());
7250 7120
7251 SSLClientSocket::ClearSessionCache(); 7121 SSLClientSocket::ClearSessionCache();
7252 7122
7253 // Simulate the certificate being expired and attempt a connection. 7123 // Simulate the certificate being expired and attempt a connection.
7254 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID); 7124 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID);
7255 { 7125 {
7256 TestDelegate d; 7126 TestDelegate d;
7257 URLRequest r(test_server.GetURL("ssl-session-cache"), 7127 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7258 DEFAULT_PRIORITY, 7128 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
7259 &d,
7260 &default_context_);
7261 7129
7262 r.Start(); 7130 r->Start();
7263 EXPECT_TRUE(r.is_pending()); 7131 EXPECT_TRUE(r->is_pending());
7264 7132
7265 base::RunLoop().Run(); 7133 base::RunLoop().Run();
7266 7134
7267 EXPECT_EQ(1, d.response_started_count()); 7135 EXPECT_EQ(1, d.response_started_count());
7268 } 7136 }
7269 7137
7270 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> 7138 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
7271 CloseAllConnections(); 7139 CloseAllConnections();
7272 7140
7273 // Now change the certificate to be acceptable (so that the response is 7141 // Now change the certificate to be acceptable (so that the response is
7274 // loaded), and ensure that no session id is presented to the peer. 7142 // loaded), and ensure that no session id is presented to the peer.
7275 cert_verifier_.set_default_result(OK); 7143 cert_verifier_.set_default_result(OK);
7276 { 7144 {
7277 TestDelegate d; 7145 TestDelegate d;
7278 URLRequest r(test_server.GetURL("ssl-session-cache"), 7146 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7279 DEFAULT_PRIORITY, 7147 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL));
7280 &d,
7281 &default_context_);
7282 7148
7283 r.Start(); 7149 r->Start();
7284 EXPECT_TRUE(r.is_pending()); 7150 EXPECT_TRUE(r->is_pending());
7285 7151
7286 base::RunLoop().Run(); 7152 base::RunLoop().Run();
7287 7153
7288 // The response will look like; 7154 // The response will look like;
7289 // insert abc 7155 // insert abc
7290 // insert xyz 7156 // insert xyz
7291 // 7157 //
7292 // With a newline at the end which makes the split think that there are 7158 // With a newline at the end which makes the split think that there are
7293 // three lines. 7159 // three lines.
7294 // 7160 //
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
7395 // We always overwrite out_cert_status. 7261 // We always overwrite out_cert_status.
7396 *out_cert_status = 0; 7262 *out_cert_status = 0;
7397 SpawnedTestServer test_server( 7263 SpawnedTestServer test_server(
7398 SpawnedTestServer::TYPE_HTTPS, 7264 SpawnedTestServer::TYPE_HTTPS,
7399 ssl_options, 7265 ssl_options,
7400 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7266 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7401 ASSERT_TRUE(test_server.Start()); 7267 ASSERT_TRUE(test_server.Start());
7402 7268
7403 TestDelegate d; 7269 TestDelegate d;
7404 d.set_allow_certificate_errors(true); 7270 d.set_allow_certificate_errors(true);
7405 URLRequest r( 7271 scoped_ptr<URLRequest> r(context_.CreateRequest(
7406 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context_); 7272 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL));
7407 r.Start(); 7273 r->Start();
7408 7274
7409 base::RunLoop().Run(); 7275 base::RunLoop().Run();
7410 7276
7411 EXPECT_EQ(1, d.response_started_count()); 7277 EXPECT_EQ(1, d.response_started_count());
7412 *out_cert_status = r.ssl_info().cert_status; 7278 *out_cert_status = r->ssl_info().cert_status;
7413 } 7279 }
7414 7280
7415 virtual ~HTTPSOCSPTest() { 7281 virtual ~HTTPSOCSPTest() {
7416 #if defined(USE_NSS) || defined(OS_IOS) 7282 #if defined(USE_NSS) || defined(OS_IOS)
7417 ShutdownNSSHttpIO(); 7283 ShutdownNSSHttpIO();
7418 #endif 7284 #endif
7419 } 7285 }
7420 7286
7421 protected: 7287 protected:
7422 // SetupContext configures the URLRequestContext that will be used for making 7288 // SetupContext configures the URLRequestContext that will be used for making
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
7851 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); 7717 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver());
7852 7718
7853 GURL url("ftp://127.0.0.1:7"); 7719 GURL url("ftp://127.0.0.1:7");
7854 job_factory.SetProtocolHandler( 7720 job_factory.SetProtocolHandler(
7855 "ftp", 7721 "ftp",
7856 new FtpProtocolHandler(&ftp_transaction_factory)); 7722 new FtpProtocolHandler(&ftp_transaction_factory));
7857 default_context_.set_job_factory(&job_factory); 7723 default_context_.set_job_factory(&job_factory);
7858 7724
7859 TestDelegate d; 7725 TestDelegate d;
7860 { 7726 {
7861 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); 7727 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7862 r.Start(); 7728 url, DEFAULT_PRIORITY, &d, NULL));
7863 EXPECT_TRUE(r.is_pending()); 7729 r->Start();
7730 EXPECT_TRUE(r->is_pending());
7864 7731
7865 base::RunLoop().Run(); 7732 base::RunLoop().Run();
7866 7733
7867 EXPECT_FALSE(r.is_pending()); 7734 EXPECT_FALSE(r->is_pending());
7868 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 7735 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
7869 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); 7736 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error());
7870 } 7737 }
7871 } 7738 }
7872 7739
7873 // Flaky, see http://crbug.com/25045. 7740 // Flaky, see http://crbug.com/25045.
7874 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { 7741 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) {
7875 ASSERT_TRUE(test_server_.Start()); 7742 ASSERT_TRUE(test_server_.Start());
7876 7743
7877 TestDelegate d; 7744 TestDelegate d;
7878 { 7745 {
7879 URLRequest r( 7746 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7880 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, &default_context_); 7747 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, NULL));
7881 r.Start(); 7748 r->Start();
7882 EXPECT_TRUE(r.is_pending()); 7749 EXPECT_TRUE(r->is_pending());
7883 7750
7884 base::RunLoop().Run(); 7751 base::RunLoop().Run();
7885 7752
7886 EXPECT_FALSE(r.is_pending()); 7753 EXPECT_FALSE(r->is_pending());
7887 EXPECT_EQ(1, d.response_started_count()); 7754 EXPECT_EQ(1, d.response_started_count());
7888 EXPECT_FALSE(d.received_data_before_response()); 7755 EXPECT_FALSE(d.received_data_before_response());
7889 EXPECT_LT(0, d.bytes_received()); 7756 EXPECT_LT(0, d.bytes_received());
7890 EXPECT_EQ(test_server_.host_port_pair().host(), 7757 EXPECT_EQ(test_server_.host_port_pair().host(),
7891 r.GetSocketAddress().host()); 7758 r->GetSocketAddress().host());
7892 EXPECT_EQ(test_server_.host_port_pair().port(), 7759 EXPECT_EQ(test_server_.host_port_pair().port(),
7893 r.GetSocketAddress().port()); 7760 r->GetSocketAddress().port());
7894 } 7761 }
7895 } 7762 }
7896 7763
7897 // Flaky, see http://crbug.com/25045. 7764 // Flaky, see http://crbug.com/25045.
7898 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { 7765 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) {
7899 ASSERT_TRUE(test_server_.Start()); 7766 ASSERT_TRUE(test_server_.Start());
7900 7767
7901 base::FilePath app_path; 7768 base::FilePath app_path;
7902 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7769 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
7903 app_path = app_path.AppendASCII("LICENSE"); 7770 app_path = app_path.AppendASCII("LICENSE");
7904 TestDelegate d; 7771 TestDelegate d;
7905 { 7772 {
7906 URLRequest r(test_server_.GetURL("/LICENSE"), 7773 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7907 DEFAULT_PRIORITY, 7774 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, &d, NULL));
7908 &d, 7775 r->Start();
7909 &default_context_); 7776 EXPECT_TRUE(r->is_pending());
7910 r.Start();
7911 EXPECT_TRUE(r.is_pending());
7912 7777
7913 base::RunLoop().Run(); 7778 base::RunLoop().Run();
7914 7779
7915 int64 file_size = 0; 7780 int64 file_size = 0;
7916 base::GetFileSize(app_path, &file_size); 7781 base::GetFileSize(app_path, &file_size);
7917 7782
7918 EXPECT_FALSE(r.is_pending()); 7783 EXPECT_FALSE(r->is_pending());
7919 EXPECT_EQ(1, d.response_started_count()); 7784 EXPECT_EQ(1, d.response_started_count());
7920 EXPECT_FALSE(d.received_data_before_response()); 7785 EXPECT_FALSE(d.received_data_before_response());
7921 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7786 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
7922 EXPECT_EQ(test_server_.host_port_pair().host(), 7787 EXPECT_EQ(test_server_.host_port_pair().host(),
7923 r.GetSocketAddress().host()); 7788 r->GetSocketAddress().host());
7924 EXPECT_EQ(test_server_.host_port_pair().port(), 7789 EXPECT_EQ(test_server_.host_port_pair().port(),
7925 r.GetSocketAddress().port()); 7790 r->GetSocketAddress().port());
7926 } 7791 }
7927 } 7792 }
7928 7793
7929 // Flaky, see http://crbug.com/25045. 7794 // Flaky, see http://crbug.com/25045.
7930 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { 7795 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) {
7931 ASSERT_TRUE(test_server_.Start()); 7796 ASSERT_TRUE(test_server_.Start());
7932 7797
7933 base::FilePath app_path; 7798 base::FilePath app_path;
7934 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7799 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
7935 app_path = app_path.AppendASCII("LICENSE"); 7800 app_path = app_path.AppendASCII("LICENSE");
7936 TestDelegate d; 7801 TestDelegate d;
7937 { 7802 {
7938 URLRequest r( 7803 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7939 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 7804 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
7940 DEFAULT_PRIORITY, 7805 DEFAULT_PRIORITY, &d, NULL));
7941 &d, 7806 r->Start();
7942 &default_context_); 7807 EXPECT_TRUE(r->is_pending());
7943 r.Start();
7944 EXPECT_TRUE(r.is_pending());
7945 7808
7946 base::RunLoop().Run(); 7809 base::RunLoop().Run();
7947 7810
7948 int64 file_size = 0; 7811 int64 file_size = 0;
7949 base::GetFileSize(app_path, &file_size); 7812 base::GetFileSize(app_path, &file_size);
7950 7813
7951 EXPECT_FALSE(r.is_pending()); 7814 EXPECT_FALSE(r->is_pending());
7952 EXPECT_EQ(test_server_.host_port_pair().host(), 7815 EXPECT_EQ(test_server_.host_port_pair().host(),
7953 r.GetSocketAddress().host()); 7816 r->GetSocketAddress().host());
7954 EXPECT_EQ(test_server_.host_port_pair().port(), 7817 EXPECT_EQ(test_server_.host_port_pair().port(),
7955 r.GetSocketAddress().port()); 7818 r->GetSocketAddress().port());
7956 EXPECT_EQ(1, d.response_started_count()); 7819 EXPECT_EQ(1, d.response_started_count());
7957 EXPECT_FALSE(d.received_data_before_response()); 7820 EXPECT_FALSE(d.received_data_before_response());
7958 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7821 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
7959 7822
7960 LoadTimingInfo load_timing_info; 7823 LoadTimingInfo load_timing_info;
7961 r.GetLoadTimingInfo(&load_timing_info); 7824 r->GetLoadTimingInfo(&load_timing_info);
7962 TestLoadTimingNoHttpResponse(load_timing_info); 7825 TestLoadTimingNoHttpResponse(load_timing_info);
7963 } 7826 }
7964 } 7827 }
7965 7828
7966 // Flaky, see http://crbug.com/25045. 7829 // Flaky, see http://crbug.com/25045.
7967 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { 7830 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) {
7968 ASSERT_TRUE(test_server_.Start()); 7831 ASSERT_TRUE(test_server_.Start());
7969 7832
7970 base::FilePath app_path; 7833 base::FilePath app_path;
7971 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7834 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
7972 app_path = app_path.AppendASCII("LICENSE"); 7835 app_path = app_path.AppendASCII("LICENSE");
7973 TestDelegate d; 7836 TestDelegate d;
7974 { 7837 {
7975 URLRequest r(test_server_.GetURLWithUserAndPassword( 7838 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7976 "/LICENSE", "chrome", "wrong_password"), 7839 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
7977 DEFAULT_PRIORITY, 7840 "wrong_password"),
7978 &d, 7841 DEFAULT_PRIORITY, &d, NULL));
7979 &default_context_); 7842 r->Start();
7980 r.Start(); 7843 EXPECT_TRUE(r->is_pending());
7981 EXPECT_TRUE(r.is_pending());
7982 7844
7983 base::RunLoop().Run(); 7845 base::RunLoop().Run();
7984 7846
7985 int64 file_size = 0; 7847 int64 file_size = 0;
7986 base::GetFileSize(app_path, &file_size); 7848 base::GetFileSize(app_path, &file_size);
7987 7849
7988 EXPECT_FALSE(r.is_pending()); 7850 EXPECT_FALSE(r->is_pending());
7989 EXPECT_EQ(1, d.response_started_count()); 7851 EXPECT_EQ(1, d.response_started_count());
7990 EXPECT_FALSE(d.received_data_before_response()); 7852 EXPECT_FALSE(d.received_data_before_response());
7991 EXPECT_EQ(d.bytes_received(), 0); 7853 EXPECT_EQ(d.bytes_received(), 0);
7992 } 7854 }
7993 } 7855 }
7994 7856
7995 // Flaky, see http://crbug.com/25045. 7857 // Flaky, see http://crbug.com/25045.
7996 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { 7858 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) {
7997 ASSERT_TRUE(test_server_.Start()); 7859 ASSERT_TRUE(test_server_.Start());
7998 7860
7999 base::FilePath app_path; 7861 base::FilePath app_path;
8000 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7862 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8001 app_path = app_path.AppendASCII("LICENSE"); 7863 app_path = app_path.AppendASCII("LICENSE");
8002 TestDelegate d; 7864 TestDelegate d;
8003 // Set correct login credentials. The delegate will be asked for them when 7865 // Set correct login credentials. The delegate will be asked for them when
8004 // the initial login with wrong credentials will fail. 7866 // the initial login with wrong credentials will fail.
8005 d.set_credentials(AuthCredentials(kChrome, kChrome)); 7867 d.set_credentials(AuthCredentials(kChrome, kChrome));
8006 { 7868 {
8007 URLRequest r(test_server_.GetURLWithUserAndPassword( 7869 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8008 "/LICENSE", "chrome", "wrong_password"), 7870 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
8009 DEFAULT_PRIORITY, 7871 "wrong_password"),
8010 &d, 7872 DEFAULT_PRIORITY, &d, NULL));
8011 &default_context_); 7873 r->Start();
8012 r.Start(); 7874 EXPECT_TRUE(r->is_pending());
8013 EXPECT_TRUE(r.is_pending());
8014 7875
8015 base::RunLoop().Run(); 7876 base::RunLoop().Run();
8016 7877
8017 int64 file_size = 0; 7878 int64 file_size = 0;
8018 base::GetFileSize(app_path, &file_size); 7879 base::GetFileSize(app_path, &file_size);
8019 7880
8020 EXPECT_FALSE(r.is_pending()); 7881 EXPECT_FALSE(r->is_pending());
8021 EXPECT_EQ(1, d.response_started_count()); 7882 EXPECT_EQ(1, d.response_started_count());
8022 EXPECT_FALSE(d.received_data_before_response()); 7883 EXPECT_FALSE(d.received_data_before_response());
8023 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7884 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
8024 } 7885 }
8025 } 7886 }
8026 7887
8027 // Flaky, see http://crbug.com/25045. 7888 // Flaky, see http://crbug.com/25045.
8028 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { 7889 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) {
8029 ASSERT_TRUE(test_server_.Start()); 7890 ASSERT_TRUE(test_server_.Start());
8030 7891
8031 base::FilePath app_path; 7892 base::FilePath app_path;
8032 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7893 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8033 app_path = app_path.AppendASCII("LICENSE"); 7894 app_path = app_path.AppendASCII("LICENSE");
8034 TestDelegate d; 7895 TestDelegate d;
8035 { 7896 {
8036 URLRequest r(test_server_.GetURLWithUserAndPassword( 7897 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8037 "/LICENSE", "wrong_user", "chrome"), 7898 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user",
8038 DEFAULT_PRIORITY, 7899 "chrome"),
8039 &d, 7900 DEFAULT_PRIORITY, &d, NULL));
8040 &default_context_); 7901 r->Start();
8041 r.Start(); 7902 EXPECT_TRUE(r->is_pending());
8042 EXPECT_TRUE(r.is_pending());
8043 7903
8044 base::RunLoop().Run(); 7904 base::RunLoop().Run();
8045 7905
8046 int64 file_size = 0; 7906 int64 file_size = 0;
8047 base::GetFileSize(app_path, &file_size); 7907 base::GetFileSize(app_path, &file_size);
8048 7908
8049 EXPECT_FALSE(r.is_pending()); 7909 EXPECT_FALSE(r->is_pending());
8050 EXPECT_EQ(1, d.response_started_count()); 7910 EXPECT_EQ(1, d.response_started_count());
8051 EXPECT_FALSE(d.received_data_before_response()); 7911 EXPECT_FALSE(d.received_data_before_response());
8052 EXPECT_EQ(d.bytes_received(), 0); 7912 EXPECT_EQ(d.bytes_received(), 0);
8053 } 7913 }
8054 } 7914 }
8055 7915
8056 // Flaky, see http://crbug.com/25045. 7916 // Flaky, see http://crbug.com/25045.
8057 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { 7917 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) {
8058 ASSERT_TRUE(test_server_.Start()); 7918 ASSERT_TRUE(test_server_.Start());
8059 7919
8060 base::FilePath app_path; 7920 base::FilePath app_path;
8061 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7921 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8062 app_path = app_path.AppendASCII("LICENSE"); 7922 app_path = app_path.AppendASCII("LICENSE");
8063 TestDelegate d; 7923 TestDelegate d;
8064 // Set correct login credentials. The delegate will be asked for them when 7924 // Set correct login credentials. The delegate will be asked for them when
8065 // the initial login with wrong credentials will fail. 7925 // the initial login with wrong credentials will fail.
8066 d.set_credentials(AuthCredentials(kChrome, kChrome)); 7926 d.set_credentials(AuthCredentials(kChrome, kChrome));
8067 { 7927 {
8068 URLRequest r(test_server_.GetURLWithUserAndPassword( 7928 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8069 "/LICENSE", "wrong_user", "chrome"), 7929 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user",
8070 DEFAULT_PRIORITY, 7930 "chrome"),
8071 &d, 7931 DEFAULT_PRIORITY, &d, NULL));
8072 &default_context_); 7932 r->Start();
8073 r.Start(); 7933 EXPECT_TRUE(r->is_pending());
8074 EXPECT_TRUE(r.is_pending());
8075 7934
8076 base::RunLoop().Run(); 7935 base::RunLoop().Run();
8077 7936
8078 int64 file_size = 0; 7937 int64 file_size = 0;
8079 base::GetFileSize(app_path, &file_size); 7938 base::GetFileSize(app_path, &file_size);
8080 7939
8081 EXPECT_FALSE(r.is_pending()); 7940 EXPECT_FALSE(r->is_pending());
8082 EXPECT_EQ(1, d.response_started_count()); 7941 EXPECT_EQ(1, d.response_started_count());
8083 EXPECT_FALSE(d.received_data_before_response()); 7942 EXPECT_FALSE(d.received_data_before_response());
8084 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7943 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
8085 } 7944 }
8086 } 7945 }
8087 7946
8088 // Flaky, see http://crbug.com/25045. 7947 // Flaky, see http://crbug.com/25045.
8089 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { 7948 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) {
8090 ASSERT_TRUE(test_server_.Start()); 7949 ASSERT_TRUE(test_server_.Start());
8091 7950
8092 base::FilePath app_path; 7951 base::FilePath app_path;
8093 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7952 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8094 app_path = app_path.AppendASCII("LICENSE"); 7953 app_path = app_path.AppendASCII("LICENSE");
8095 7954
8096 scoped_ptr<TestDelegate> d(new TestDelegate); 7955 scoped_ptr<TestDelegate> d(new TestDelegate);
8097 { 7956 {
8098 // Pass correct login identity in the URL. 7957 // Pass correct login identity in the URL.
8099 URLRequest r( 7958 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8100 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 7959 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
8101 DEFAULT_PRIORITY, 7960 DEFAULT_PRIORITY, d.get(), NULL));
8102 d.get(), 7961 r->Start();
8103 &default_context_); 7962 EXPECT_TRUE(r->is_pending());
8104 r.Start();
8105 EXPECT_TRUE(r.is_pending());
8106 7963
8107 base::RunLoop().Run(); 7964 base::RunLoop().Run();
8108 7965
8109 int64 file_size = 0; 7966 int64 file_size = 0;
8110 base::GetFileSize(app_path, &file_size); 7967 base::GetFileSize(app_path, &file_size);
8111 7968
8112 EXPECT_FALSE(r.is_pending()); 7969 EXPECT_FALSE(r->is_pending());
8113 EXPECT_EQ(1, d->response_started_count()); 7970 EXPECT_EQ(1, d->response_started_count());
8114 EXPECT_FALSE(d->received_data_before_response()); 7971 EXPECT_FALSE(d->received_data_before_response());
8115 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7972 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8116 } 7973 }
8117 7974
8118 d.reset(new TestDelegate); 7975 d.reset(new TestDelegate);
8119 { 7976 {
8120 // This request should use cached identity from previous request. 7977 // This request should use cached identity from previous request.
8121 URLRequest r(test_server_.GetURL("/LICENSE"), 7978 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8122 DEFAULT_PRIORITY, 7979 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL));
8123 d.get(), 7980 r->Start();
8124 &default_context_); 7981 EXPECT_TRUE(r->is_pending());
8125 r.Start();
8126 EXPECT_TRUE(r.is_pending());
8127 7982
8128 base::RunLoop().Run(); 7983 base::RunLoop().Run();
8129 7984
8130 int64 file_size = 0; 7985 int64 file_size = 0;
8131 base::GetFileSize(app_path, &file_size); 7986 base::GetFileSize(app_path, &file_size);
8132 7987
8133 EXPECT_FALSE(r.is_pending()); 7988 EXPECT_FALSE(r->is_pending());
8134 EXPECT_EQ(1, d->response_started_count()); 7989 EXPECT_EQ(1, d->response_started_count());
8135 EXPECT_FALSE(d->received_data_before_response()); 7990 EXPECT_FALSE(d->received_data_before_response());
8136 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7991 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8137 } 7992 }
8138 } 7993 }
8139 7994
8140 // Flaky, see http://crbug.com/25045. 7995 // Flaky, see http://crbug.com/25045.
8141 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { 7996 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) {
8142 ASSERT_TRUE(test_server_.Start()); 7997 ASSERT_TRUE(test_server_.Start());
8143 7998
8144 base::FilePath app_path; 7999 base::FilePath app_path;
8145 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8000 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8146 app_path = app_path.AppendASCII("LICENSE"); 8001 app_path = app_path.AppendASCII("LICENSE");
8147 8002
8148 scoped_ptr<TestDelegate> d(new TestDelegate); 8003 scoped_ptr<TestDelegate> d(new TestDelegate);
8149 // Set correct login credentials. The delegate will be asked for them when 8004 // Set correct login credentials. The delegate will be asked for them when
8150 // the initial login with wrong credentials will fail. 8005 // the initial login with wrong credentials will fail.
8151 d->set_credentials(AuthCredentials(kChrome, kChrome)); 8006 d->set_credentials(AuthCredentials(kChrome, kChrome));
8152 { 8007 {
8153 URLRequest r(test_server_.GetURLWithUserAndPassword( 8008 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8154 "/LICENSE", "chrome", "wrong_password"), 8009 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
8155 DEFAULT_PRIORITY, 8010 "wrong_password"),
8156 d.get(), 8011 DEFAULT_PRIORITY, d.get(), NULL));
8157 &default_context_); 8012 r->Start();
8158 r.Start(); 8013 EXPECT_TRUE(r->is_pending());
8159 EXPECT_TRUE(r.is_pending());
8160 8014
8161 base::RunLoop().Run(); 8015 base::RunLoop().Run();
8162 8016
8163 int64 file_size = 0; 8017 int64 file_size = 0;
8164 base::GetFileSize(app_path, &file_size); 8018 base::GetFileSize(app_path, &file_size);
8165 8019
8166 EXPECT_FALSE(r.is_pending()); 8020 EXPECT_FALSE(r->is_pending());
8167 EXPECT_EQ(1, d->response_started_count()); 8021 EXPECT_EQ(1, d->response_started_count());
8168 EXPECT_FALSE(d->received_data_before_response()); 8022 EXPECT_FALSE(d->received_data_before_response());
8169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8023 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8170 } 8024 }
8171 8025
8172 // Use a new delegate without explicit credentials. The cached ones should be 8026 // Use a new delegate without explicit credentials. The cached ones should be
8173 // used. 8027 // used.
8174 d.reset(new TestDelegate); 8028 d.reset(new TestDelegate);
8175 { 8029 {
8176 // Don't pass wrong credentials in the URL, they would override valid cached 8030 // Don't pass wrong credentials in the URL, they would override valid cached
8177 // ones. 8031 // ones.
8178 URLRequest r(test_server_.GetURL("/LICENSE"), 8032 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8179 DEFAULT_PRIORITY, 8033 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL));
8180 d.get(), 8034 r->Start();
8181 &default_context_); 8035 EXPECT_TRUE(r->is_pending());
8182 r.Start();
8183 EXPECT_TRUE(r.is_pending());
8184 8036
8185 base::RunLoop().Run(); 8037 base::RunLoop().Run();
8186 8038
8187 int64 file_size = 0; 8039 int64 file_size = 0;
8188 base::GetFileSize(app_path, &file_size); 8040 base::GetFileSize(app_path, &file_size);
8189 8041
8190 EXPECT_FALSE(r.is_pending()); 8042 EXPECT_FALSE(r->is_pending());
8191 EXPECT_EQ(1, d->response_started_count()); 8043 EXPECT_EQ(1, d->response_started_count());
8192 EXPECT_FALSE(d->received_data_before_response()); 8044 EXPECT_FALSE(d->received_data_before_response());
8193 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8045 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8194 } 8046 }
8195 } 8047 }
8196 #endif // !defined(DISABLE_FTP_SUPPORT) 8048 #endif // !defined(DISABLE_FTP_SUPPORT)
8197 8049
8198 } // namespace net 8050 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_unittest.cc ('k') | net/websockets/websocket_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698