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

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

Issue 51953002: [Net] Add a priority parameter to URLRequest's constructor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 1 month 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
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 19 matching lines...) Expand all
30 #include "base/strings/utf_string_conversions.h" 30 #include "base/strings/utf_string_conversions.h"
31 #include "net/base/capturing_net_log.h" 31 #include "net/base/capturing_net_log.h"
32 #include "net/base/load_flags.h" 32 #include "net/base/load_flags.h"
33 #include "net/base/load_timing_info.h" 33 #include "net/base/load_timing_info.h"
34 #include "net/base/load_timing_info_test_util.h" 34 #include "net/base/load_timing_info_test_util.h"
35 #include "net/base/net_errors.h" 35 #include "net/base/net_errors.h"
36 #include "net/base/net_log.h" 36 #include "net/base/net_log.h"
37 #include "net/base/net_log_unittest.h" 37 #include "net/base/net_log_unittest.h"
38 #include "net/base/net_module.h" 38 #include "net/base/net_module.h"
39 #include "net/base/net_util.h" 39 #include "net/base/net_util.h"
40 #include "net/base/request_priority.h"
40 #include "net/base/test_data_directory.h" 41 #include "net/base/test_data_directory.h"
41 #include "net/base/upload_bytes_element_reader.h" 42 #include "net/base/upload_bytes_element_reader.h"
42 #include "net/base/upload_data_stream.h" 43 #include "net/base/upload_data_stream.h"
43 #include "net/base/upload_file_element_reader.h" 44 #include "net/base/upload_file_element_reader.h"
44 #include "net/cert/ev_root_ca_metadata.h" 45 #include "net/cert/ev_root_ca_metadata.h"
45 #include "net/cert/test_root_certs.h" 46 #include "net/cert/test_root_certs.h"
46 #include "net/cookies/cookie_monster.h" 47 #include "net/cookies/cookie_monster.h"
47 #include "net/cookies/cookie_store_test_helpers.h" 48 #include "net/cookies/cookie_store_test_helpers.h"
48 #include "net/disk_cache/disk_cache.h" 49 #include "net/disk_cache/disk_cache.h"
49 #include "net/dns/mock_host_resolver.h" 50 #include "net/dns/mock_host_resolver.h"
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 protected: 615 protected:
615 CapturingNetLog net_log_; 616 CapturingNetLog net_log_;
616 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 617 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
617 URLRequestJobFactoryImpl job_factory_; 618 URLRequestJobFactoryImpl job_factory_;
618 TestURLRequestContext default_context_; 619 TestURLRequestContext default_context_;
619 }; 620 };
620 621
621 TEST_F(URLRequestTest, AboutBlankTest) { 622 TEST_F(URLRequestTest, AboutBlankTest) {
622 TestDelegate d; 623 TestDelegate d;
623 { 624 {
624 URLRequest r(GURL("about:blank"), &d, &default_context_); 625 URLRequest r(GURL("about:blank"), DEFAULT_PRIORITY, &d, &default_context_);
625 626
626 r.Start(); 627 r.Start();
627 EXPECT_TRUE(r.is_pending()); 628 EXPECT_TRUE(r.is_pending());
628 629
629 base::RunLoop().Run(); 630 base::RunLoop().Run();
630 631
631 EXPECT_TRUE(!r.is_pending()); 632 EXPECT_TRUE(!r.is_pending());
632 EXPECT_FALSE(d.received_data_before_response()); 633 EXPECT_FALSE(d.received_data_before_response());
633 EXPECT_EQ(d.bytes_received(), 0); 634 EXPECT_EQ(d.bytes_received(), 0);
634 EXPECT_EQ("", r.GetSocketAddress().host()); 635 EXPECT_EQ("", r.GetSocketAddress().host());
635 EXPECT_EQ(0, r.GetSocketAddress().port()); 636 EXPECT_EQ(0, r.GetSocketAddress().port());
636 637
637 HttpRequestHeaders headers; 638 HttpRequestHeaders headers;
638 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 639 EXPECT_FALSE(r.GetFullRequestHeaders(&headers));
639 } 640 }
640 } 641 }
641 642
642 TEST_F(URLRequestTest, DataURLImageTest) { 643 TEST_F(URLRequestTest, DataURLImageTest) {
643 TestDelegate d; 644 TestDelegate d;
644 { 645 {
645 // Use our nice little Chrome logo. 646 // Use our nice little Chrome logo.
646 URLRequest r(GURL( 647 URLRequest r(
648 GURL(
647 "data:image/png;base64," 649 "data:image/png;base64,"
648 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" 650 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3"
649 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" 651 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD"
650 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" 652 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t"
651 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" 653 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9"
652 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" 654 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1"
653 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" 655 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z"
654 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" 656 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW"
655 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" 657 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW"
656 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" 658 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb"
657 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" 659 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5"
658 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" 660 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV"
659 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" 661 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq"
660 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" 662 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F"
661 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" 663 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB"
662 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" 664 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM"
663 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" 665 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm"
664 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" 666 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En"
665 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), 667 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="),
668 DEFAULT_PRIORITY,
666 &d, 669 &d,
667 &default_context_); 670 &default_context_);
668 671
669 r.Start(); 672 r.Start();
670 EXPECT_TRUE(r.is_pending()); 673 EXPECT_TRUE(r.is_pending());
671 674
672 base::RunLoop().Run(); 675 base::RunLoop().Run();
673 676
674 EXPECT_TRUE(!r.is_pending()); 677 EXPECT_TRUE(!r.is_pending());
675 EXPECT_FALSE(d.received_data_before_response()); 678 EXPECT_FALSE(d.received_data_before_response());
676 EXPECT_EQ(d.bytes_received(), 911); 679 EXPECT_EQ(d.bytes_received(), 911);
677 EXPECT_EQ("", r.GetSocketAddress().host()); 680 EXPECT_EQ("", r.GetSocketAddress().host());
678 EXPECT_EQ(0, r.GetSocketAddress().port()); 681 EXPECT_EQ(0, r.GetSocketAddress().port());
679 682
680 HttpRequestHeaders headers; 683 HttpRequestHeaders headers;
681 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 684 EXPECT_FALSE(r.GetFullRequestHeaders(&headers));
682 } 685 }
683 } 686 }
684 687
685 TEST_F(URLRequestTest, FileTest) { 688 TEST_F(URLRequestTest, FileTest) {
686 base::FilePath app_path; 689 base::FilePath app_path;
687 PathService::Get(base::FILE_EXE, &app_path); 690 PathService::Get(base::FILE_EXE, &app_path);
688 GURL app_url = FilePathToFileURL(app_path); 691 GURL app_url = FilePathToFileURL(app_path);
689 692
690 TestDelegate d; 693 TestDelegate d;
691 { 694 {
692 URLRequest r(app_url, &d, &default_context_); 695 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_);
693 696
694 r.Start(); 697 r.Start();
695 EXPECT_TRUE(r.is_pending()); 698 EXPECT_TRUE(r.is_pending());
696 699
697 base::RunLoop().Run(); 700 base::RunLoop().Run();
698 701
699 int64 file_size = -1; 702 int64 file_size = -1;
700 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); 703 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size));
701 704
702 EXPECT_TRUE(!r.is_pending()); 705 EXPECT_TRUE(!r.is_pending());
703 EXPECT_EQ(1, d.response_started_count()); 706 EXPECT_EQ(1, d.response_started_count());
704 EXPECT_FALSE(d.received_data_before_response()); 707 EXPECT_FALSE(d.received_data_before_response());
705 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 708 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
706 EXPECT_EQ("", r.GetSocketAddress().host()); 709 EXPECT_EQ("", r.GetSocketAddress().host());
707 EXPECT_EQ(0, r.GetSocketAddress().port()); 710 EXPECT_EQ(0, r.GetSocketAddress().port());
708 711
709 HttpRequestHeaders headers; 712 HttpRequestHeaders headers;
710 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 713 EXPECT_FALSE(r.GetFullRequestHeaders(&headers));
711 } 714 }
712 } 715 }
713 716
714 TEST_F(URLRequestTest, FileTestCancel) { 717 TEST_F(URLRequestTest, FileTestCancel) {
715 base::FilePath app_path; 718 base::FilePath app_path;
716 PathService::Get(base::FILE_EXE, &app_path); 719 PathService::Get(base::FILE_EXE, &app_path);
717 GURL app_url = FilePathToFileURL(app_path); 720 GURL app_url = FilePathToFileURL(app_path);
718 721
719 TestDelegate d; 722 TestDelegate d;
720 { 723 {
721 URLRequest r(app_url, &d, &default_context_); 724 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_);
722 725
723 r.Start(); 726 r.Start();
724 EXPECT_TRUE(r.is_pending()); 727 EXPECT_TRUE(r.is_pending());
725 r.Cancel(); 728 r.Cancel();
726 } 729 }
727 // Async cancellation should be safe even when URLRequest has been already 730 // Async cancellation should be safe even when URLRequest has been already
728 // destroyed. 731 // destroyed.
729 base::RunLoop().RunUntilIdle(); 732 base::RunLoop().RunUntilIdle();
730 } 733 }
731 734
(...skipping 11 matching lines...) Expand all
743 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 746 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
744 747
745 const size_t first_byte_position = 500; 748 const size_t first_byte_position = 500;
746 const size_t last_byte_position = buffer_size - first_byte_position; 749 const size_t last_byte_position = buffer_size - first_byte_position;
747 const size_t content_length = last_byte_position - first_byte_position + 1; 750 const size_t content_length = last_byte_position - first_byte_position + 1;
748 std::string partial_buffer_string(buffer.get() + first_byte_position, 751 std::string partial_buffer_string(buffer.get() + first_byte_position,
749 buffer.get() + last_byte_position + 1); 752 buffer.get() + last_byte_position + 1);
750 753
751 TestDelegate d; 754 TestDelegate d;
752 { 755 {
753 URLRequest r(temp_url, &d, &default_context_); 756 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_);
754 757
755 HttpRequestHeaders headers; 758 HttpRequestHeaders headers;
756 headers.SetHeader(HttpRequestHeaders::kRange, 759 headers.SetHeader(HttpRequestHeaders::kRange,
757 base::StringPrintf( 760 base::StringPrintf(
758 "bytes=%" PRIuS "-%" PRIuS, 761 "bytes=%" PRIuS "-%" PRIuS,
759 first_byte_position, last_byte_position)); 762 first_byte_position, last_byte_position));
760 r.SetExtraRequestHeaders(headers); 763 r.SetExtraRequestHeaders(headers);
761 r.Start(); 764 r.Start();
762 EXPECT_TRUE(r.is_pending()); 765 EXPECT_TRUE(r.is_pending());
763 766
(...skipping 23 matching lines...) Expand all
787 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 790 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
788 791
789 const size_t first_byte_position = 500; 792 const size_t first_byte_position = 500;
790 const size_t last_byte_position = buffer_size - 1; 793 const size_t last_byte_position = buffer_size - 1;
791 const size_t content_length = last_byte_position - first_byte_position + 1; 794 const size_t content_length = last_byte_position - first_byte_position + 1;
792 std::string partial_buffer_string(buffer.get() + first_byte_position, 795 std::string partial_buffer_string(buffer.get() + first_byte_position,
793 buffer.get() + last_byte_position + 1); 796 buffer.get() + last_byte_position + 1);
794 797
795 TestDelegate d; 798 TestDelegate d;
796 { 799 {
797 URLRequest r(temp_url, &d, &default_context_); 800 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_);
798 801
799 HttpRequestHeaders headers; 802 HttpRequestHeaders headers;
800 headers.SetHeader(HttpRequestHeaders::kRange, 803 headers.SetHeader(HttpRequestHeaders::kRange,
801 base::StringPrintf("bytes=%" PRIuS "-", 804 base::StringPrintf("bytes=%" PRIuS "-",
802 first_byte_position)); 805 first_byte_position));
803 r.SetExtraRequestHeaders(headers); 806 r.SetExtraRequestHeaders(headers);
804 r.Start(); 807 r.Start();
805 EXPECT_TRUE(r.is_pending()); 808 EXPECT_TRUE(r.is_pending());
806 809
807 base::RunLoop().Run(); 810 base::RunLoop().Run();
(...skipping 16 matching lines...) Expand all
824 base::FilePath temp_path; 827 base::FilePath temp_path;
825 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 828 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path));
826 GURL temp_url = FilePathToFileURL(temp_path); 829 GURL temp_url = FilePathToFileURL(temp_path);
827 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); 830 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size));
828 831
829 int64 file_size; 832 int64 file_size;
830 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 833 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
831 834
832 TestDelegate d; 835 TestDelegate d;
833 { 836 {
834 URLRequest r(temp_url, &d, &default_context_); 837 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_);
835 838
836 HttpRequestHeaders headers; 839 HttpRequestHeaders headers;
837 headers.SetHeader(HttpRequestHeaders::kRange, 840 headers.SetHeader(HttpRequestHeaders::kRange,
838 "bytes=0-0,10-200,200-300"); 841 "bytes=0-0,10-200,200-300");
839 r.SetExtraRequestHeaders(headers); 842 r.SetExtraRequestHeaders(headers);
840 r.Start(); 843 r.Start();
841 EXPECT_TRUE(r.is_pending()); 844 EXPECT_TRUE(r.is_pending());
842 845
843 base::RunLoop().Run(); 846 base::RunLoop().Run();
844 EXPECT_TRUE(d.request_failed()); 847 EXPECT_TRUE(d.request_failed());
845 } 848 }
846 849
847 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 850 EXPECT_TRUE(base::DeleteFile(temp_path, false));
848 } 851 }
849 852
850 TEST_F(URLRequestTest, InvalidUrlTest) { 853 TEST_F(URLRequestTest, InvalidUrlTest) {
851 TestDelegate d; 854 TestDelegate d;
852 { 855 {
853 URLRequest r(GURL("invalid url"), &d, &default_context_); 856 URLRequest r(GURL("invalid url"), DEFAULT_PRIORITY, &d, &default_context_);
854 857
855 r.Start(); 858 r.Start();
856 EXPECT_TRUE(r.is_pending()); 859 EXPECT_TRUE(r.is_pending());
857 860
858 base::RunLoop().Run(); 861 base::RunLoop().Run();
859 EXPECT_TRUE(d.request_failed()); 862 EXPECT_TRUE(d.request_failed());
860 } 863 }
861 } 864 }
862 865
863 #if defined(OS_WIN) 866 #if defined(OS_WIN)
(...skipping 16 matching lines...) Expand all
880 CLSCTX_INPROC_SERVER))); 883 CLSCTX_INPROC_SERVER)));
881 base::win::ScopedComPtr<IPersistFile> persist; 884 base::win::ScopedComPtr<IPersistFile> persist;
882 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); 885 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive())));
883 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); 886 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str())));
884 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); 887 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest")));
885 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); 888 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE)));
886 } 889 }
887 890
888 TestDelegate d; 891 TestDelegate d;
889 { 892 {
890 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), &d, 893 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)),
894 DEFAULT_PRIORITY,
895 &d,
891 &default_context_); 896 &default_context_);
892 897
893 r.Start(); 898 r.Start();
894 EXPECT_TRUE(r.is_pending()); 899 EXPECT_TRUE(r.is_pending());
895 900
896 base::RunLoop().Run(); 901 base::RunLoop().Run();
897 902
898 WIN32_FILE_ATTRIBUTE_DATA data; 903 WIN32_FILE_ATTRIBUTE_DATA data;
899 GetFileAttributesEx(app_path.value().c_str(), 904 GetFileAttributesEx(app_path.value().c_str(),
900 GetFileExInfoStandard, &data); 905 GetFileExInfoStandard, &data);
(...skipping 23 matching lines...) Expand all
924 // Put in mock resource provider. 929 // Put in mock resource provider.
925 NetModule::SetResourceProvider(TestNetResourceProvider); 930 NetModule::SetResourceProvider(TestNetResourceProvider);
926 931
927 TestDelegate d; 932 TestDelegate d;
928 { 933 {
929 base::FilePath file_path; 934 base::FilePath file_path;
930 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 935 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
931 file_path = file_path.Append(FILE_PATH_LITERAL("net")); 936 file_path = file_path.Append(FILE_PATH_LITERAL("net"));
932 file_path = file_path.Append(FILE_PATH_LITERAL("data")); 937 file_path = file_path.Append(FILE_PATH_LITERAL("data"));
933 938
934 URLRequest req(FilePathToFileURL(file_path), &d, &default_context_); 939 URLRequest req(
940 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, &default_context_);
935 req.Start(); 941 req.Start();
936 EXPECT_TRUE(req.is_pending()); 942 EXPECT_TRUE(req.is_pending());
937 943
938 d.set_cancel_in_received_data_pending(true); 944 d.set_cancel_in_received_data_pending(true);
939 945
940 base::RunLoop().Run(); 946 base::RunLoop().Run();
941 } 947 }
942 948
943 // Take out mock resource provider. 949 // Take out mock resource provider.
944 NetModule::SetResourceProvider(NULL); 950 NetModule::SetResourceProvider(NULL);
945 } 951 }
946 952
947 TEST_F(URLRequestTest, FileDirOutputSanity) { 953 TEST_F(URLRequestTest, FileDirOutputSanity) {
948 // Verify the general sanity of the the output of the file: 954 // Verify the general sanity of the the output of the file:
949 // directory lister by checking for the output of a known existing 955 // directory lister by checking for the output of a known existing
950 // file. 956 // file.
951 const char sentinel_name[] = "filedir-sentinel"; 957 const char sentinel_name[] = "filedir-sentinel";
952 958
953 base::FilePath path; 959 base::FilePath path;
954 PathService::Get(base::DIR_SOURCE_ROOT, &path); 960 PathService::Get(base::DIR_SOURCE_ROOT, &path);
955 path = path.Append(FILE_PATH_LITERAL("net")); 961 path = path.Append(FILE_PATH_LITERAL("net"));
956 path = path.Append(FILE_PATH_LITERAL("data")); 962 path = path.Append(FILE_PATH_LITERAL("data"));
957 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 963 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
958 964
959 TestDelegate d; 965 TestDelegate d;
960 URLRequest req(FilePathToFileURL(path), &d, &default_context_); 966 URLRequest req(
967 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_);
961 req.Start(); 968 req.Start();
962 base::RunLoop().Run(); 969 base::RunLoop().Run();
963 970
964 // Generate entry for the sentinel file. 971 // Generate entry for the sentinel file.
965 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); 972 base::FilePath sentinel_path = path.AppendASCII(sentinel_name);
966 base::PlatformFileInfo info; 973 base::PlatformFileInfo info;
967 EXPECT_TRUE(file_util::GetFileInfo(sentinel_path, &info)); 974 EXPECT_TRUE(file_util::GetFileInfo(sentinel_path, &info));
968 EXPECT_GT(info.size, 0); 975 EXPECT_GT(info.size, 0);
969 std::string sentinel_output = GetDirectoryListingEntry( 976 std::string sentinel_output = GetDirectoryListingEntry(
970 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), 977 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)),
(...skipping 15 matching lines...) Expand all
986 // directory and does not end with a slash. Ensure that following such 993 // directory and does not end with a slash. Ensure that following such
987 // redirects does not crash. See http://crbug.com/18686. 994 // redirects does not crash. See http://crbug.com/18686.
988 995
989 base::FilePath path; 996 base::FilePath path;
990 PathService::Get(base::DIR_SOURCE_ROOT, &path); 997 PathService::Get(base::DIR_SOURCE_ROOT, &path);
991 path = path.Append(FILE_PATH_LITERAL("net")); 998 path = path.Append(FILE_PATH_LITERAL("net"));
992 path = path.Append(FILE_PATH_LITERAL("data")); 999 path = path.Append(FILE_PATH_LITERAL("data"));
993 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 1000 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
994 1001
995 TestDelegate d; 1002 TestDelegate d;
996 URLRequest req(FilePathToFileURL(path), &d, &default_context_); 1003 URLRequest req(
1004 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_);
997 req.Start(); 1005 req.Start();
998 base::RunLoop().Run(); 1006 base::RunLoop().Run();
999 1007
1000 ASSERT_EQ(1, d.received_redirect_count()); 1008 ASSERT_EQ(1, d.received_redirect_count());
1001 ASSERT_LT(0, d.bytes_received()); 1009 ASSERT_LT(0, d.bytes_received());
1002 ASSERT_FALSE(d.request_failed()); 1010 ASSERT_FALSE(d.request_failed());
1003 ASSERT_TRUE(req.status().is_success()); 1011 ASSERT_TRUE(req.status().is_success());
1004 } 1012 }
1005 1013
1006 #if defined(OS_WIN) 1014 #if defined(OS_WIN)
1007 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. 1015 // Don't accept the url "file:///" on windows. See http://crbug.com/1474.
1008 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { 1016 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) {
1009 TestDelegate d; 1017 TestDelegate d;
1010 URLRequest req(GURL("file:///"), &d, &default_context_); 1018 URLRequest req(GURL("file:///"), DEFAULT_PRIORITY, &d, &default_context_);
1011 req.Start(); 1019 req.Start();
1012 base::RunLoop().Run(); 1020 base::RunLoop().Run();
1013 1021
1014 ASSERT_EQ(1, d.received_redirect_count()); 1022 ASSERT_EQ(1, d.received_redirect_count());
1015 ASSERT_FALSE(req.status().is_success()); 1023 ASSERT_FALSE(req.status().is_success());
1016 } 1024 }
1017 #endif 1025 #endif
1018 1026
1019 // Custom URLRequestJobs for use with interceptor tests 1027 // Custom URLRequestJobs for use with interceptor tests
1020 class RestartTestJob : public URLRequestTestJob { 1028 class RestartTestJob : public URLRequestTestJob {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 1229
1222 TEST_F(URLRequestTest, Intercept) { 1230 TEST_F(URLRequestTest, Intercept) {
1223 TestInterceptor interceptor; 1231 TestInterceptor interceptor;
1224 1232
1225 // intercept the main request and respond with a simple response 1233 // intercept the main request and respond with a simple response
1226 interceptor.intercept_main_request_ = true; 1234 interceptor.intercept_main_request_ = true;
1227 interceptor.main_headers_ = TestInterceptor::ok_headers(); 1235 interceptor.main_headers_ = TestInterceptor::ok_headers();
1228 interceptor.main_data_ = TestInterceptor::ok_data(); 1236 interceptor.main_data_ = TestInterceptor::ok_data();
1229 1237
1230 TestDelegate d; 1238 TestDelegate d;
1231 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1239 URLRequest req(GURL("http://test_intercept/foo"),
1240 DEFAULT_PRIORITY,
1241 &d,
1242 &default_context_);
1232 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); 1243 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data();
1233 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); 1244 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data();
1234 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); 1245 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data();
1235 req.SetUserData(NULL, user_data0); 1246 req.SetUserData(NULL, user_data0);
1236 req.SetUserData(&user_data1, user_data1); 1247 req.SetUserData(&user_data1, user_data1);
1237 req.SetUserData(&user_data2, user_data2); 1248 req.SetUserData(&user_data2, user_data2);
1238 req.set_method("GET"); 1249 req.set_method("GET");
1239 req.Start(); 1250 req.Start();
1240 base::RunLoop().Run(); 1251 base::RunLoop().Run();
1241 1252
(...skipping 20 matching lines...) Expand all
1262 interceptor.intercept_main_request_ = true; 1273 interceptor.intercept_main_request_ = true;
1263 interceptor.main_headers_ = TestInterceptor::redirect_headers(); 1274 interceptor.main_headers_ = TestInterceptor::redirect_headers();
1264 interceptor.main_data_ = TestInterceptor::redirect_data(); 1275 interceptor.main_data_ = TestInterceptor::redirect_data();
1265 1276
1266 // intercept that redirect and respond a final OK response 1277 // intercept that redirect and respond a final OK response
1267 interceptor.intercept_redirect_ = true; 1278 interceptor.intercept_redirect_ = true;
1268 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); 1279 interceptor.redirect_headers_ = TestInterceptor::ok_headers();
1269 interceptor.redirect_data_ = TestInterceptor::ok_data(); 1280 interceptor.redirect_data_ = TestInterceptor::ok_data();
1270 1281
1271 TestDelegate d; 1282 TestDelegate d;
1272 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1283 URLRequest req(GURL("http://test_intercept/foo"),
1284 DEFAULT_PRIORITY,
1285 &d,
1286 &default_context_);
1273 req.set_method("GET"); 1287 req.set_method("GET");
1274 req.Start(); 1288 req.Start();
1275 base::RunLoop().Run(); 1289 base::RunLoop().Run();
1276 1290
1277 // Check the interceptor got called as expected 1291 // Check the interceptor got called as expected
1278 EXPECT_TRUE(interceptor.did_intercept_main_); 1292 EXPECT_TRUE(interceptor.did_intercept_main_);
1279 EXPECT_TRUE(interceptor.did_intercept_redirect_); 1293 EXPECT_TRUE(interceptor.did_intercept_redirect_);
1280 1294
1281 // Check we got one good response 1295 // Check we got one good response
1282 EXPECT_TRUE(req.status().is_success()); 1296 EXPECT_TRUE(req.status().is_success());
(...skipping 12 matching lines...) Expand all
1295 interceptor.intercept_main_request_ = true; 1309 interceptor.intercept_main_request_ = true;
1296 interceptor.main_headers_ = TestInterceptor::error_headers(); 1310 interceptor.main_headers_ = TestInterceptor::error_headers();
1297 interceptor.main_data_ = TestInterceptor::error_data(); 1311 interceptor.main_data_ = TestInterceptor::error_data();
1298 1312
1299 // intercept that error and respond with an OK response 1313 // intercept that error and respond with an OK response
1300 interceptor.intercept_final_response_ = true; 1314 interceptor.intercept_final_response_ = true;
1301 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1315 interceptor.final_headers_ = TestInterceptor::ok_headers();
1302 interceptor.final_data_ = TestInterceptor::ok_data(); 1316 interceptor.final_data_ = TestInterceptor::ok_data();
1303 1317
1304 TestDelegate d; 1318 TestDelegate d;
1305 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1319 URLRequest req(GURL("http://test_intercept/foo"),
1320 DEFAULT_PRIORITY,
1321 &d,
1322 &default_context_);
1306 req.set_method("GET"); 1323 req.set_method("GET");
1307 req.Start(); 1324 req.Start();
1308 base::RunLoop().Run(); 1325 base::RunLoop().Run();
1309 1326
1310 // Check the interceptor got called as expected 1327 // Check the interceptor got called as expected
1311 EXPECT_TRUE(interceptor.did_intercept_main_); 1328 EXPECT_TRUE(interceptor.did_intercept_main_);
1312 EXPECT_TRUE(interceptor.did_intercept_final_); 1329 EXPECT_TRUE(interceptor.did_intercept_final_);
1313 1330
1314 // Check we got one good response 1331 // Check we got one good response
1315 EXPECT_TRUE(req.status().is_success()); 1332 EXPECT_TRUE(req.status().is_success());
1316 EXPECT_EQ(200, req.response_headers()->response_code()); 1333 EXPECT_EQ(200, req.response_headers()->response_code());
1317 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1334 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1318 EXPECT_EQ(1, d.response_started_count()); 1335 EXPECT_EQ(1, d.response_started_count());
1319 EXPECT_EQ(0, d.received_redirect_count()); 1336 EXPECT_EQ(0, d.received_redirect_count());
1320 } 1337 }
1321 1338
1322 TEST_F(URLRequestTest, InterceptNetworkError) { 1339 TEST_F(URLRequestTest, InterceptNetworkError) {
1323 TestInterceptor interceptor; 1340 TestInterceptor interceptor;
1324 1341
1325 // intercept the main request to simulate a network error 1342 // intercept the main request to simulate a network error
1326 interceptor.simulate_main_network_error_ = true; 1343 interceptor.simulate_main_network_error_ = true;
1327 1344
1328 // intercept that error and respond with an OK response 1345 // intercept that error and respond with an OK response
1329 interceptor.intercept_final_response_ = true; 1346 interceptor.intercept_final_response_ = true;
1330 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1347 interceptor.final_headers_ = TestInterceptor::ok_headers();
1331 interceptor.final_data_ = TestInterceptor::ok_data(); 1348 interceptor.final_data_ = TestInterceptor::ok_data();
1332 1349
1333 TestDelegate d; 1350 TestDelegate d;
1334 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1351 URLRequest req(GURL("http://test_intercept/foo"),
1352 DEFAULT_PRIORITY,
1353 &d,
1354 &default_context_);
1335 req.set_method("GET"); 1355 req.set_method("GET");
1336 req.Start(); 1356 req.Start();
1337 base::RunLoop().Run(); 1357 base::RunLoop().Run();
1338 1358
1339 // Check the interceptor got called as expected 1359 // Check the interceptor got called as expected
1340 EXPECT_TRUE(interceptor.did_simulate_error_main_); 1360 EXPECT_TRUE(interceptor.did_simulate_error_main_);
1341 EXPECT_TRUE(interceptor.did_intercept_final_); 1361 EXPECT_TRUE(interceptor.did_intercept_final_);
1342 1362
1343 // Check we received one good response 1363 // Check we received one good response
1344 EXPECT_TRUE(req.status().is_success()); 1364 EXPECT_TRUE(req.status().is_success());
1345 EXPECT_EQ(200, req.response_headers()->response_code()); 1365 EXPECT_EQ(200, req.response_headers()->response_code());
1346 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 1366 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
1347 EXPECT_EQ(1, d.response_started_count()); 1367 EXPECT_EQ(1, d.response_started_count());
1348 EXPECT_EQ(0, d.received_redirect_count()); 1368 EXPECT_EQ(0, d.received_redirect_count());
1349 } 1369 }
1350 1370
1351 TEST_F(URLRequestTest, InterceptRestartRequired) { 1371 TEST_F(URLRequestTest, InterceptRestartRequired) {
1352 TestInterceptor interceptor; 1372 TestInterceptor interceptor;
1353 1373
1354 // restart the main request 1374 // restart the main request
1355 interceptor.restart_main_request_ = true; 1375 interceptor.restart_main_request_ = true;
1356 1376
1357 // then intercept the new main request and respond with an OK response 1377 // then intercept the new main request and respond with an OK response
1358 interceptor.intercept_main_request_ = true; 1378 interceptor.intercept_main_request_ = true;
1359 interceptor.main_headers_ = TestInterceptor::ok_headers(); 1379 interceptor.main_headers_ = TestInterceptor::ok_headers();
1360 interceptor.main_data_ = TestInterceptor::ok_data(); 1380 interceptor.main_data_ = TestInterceptor::ok_data();
1361 1381
1362 TestDelegate d; 1382 TestDelegate d;
1363 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1383 URLRequest req(GURL("http://test_intercept/foo"),
1384 DEFAULT_PRIORITY,
1385 &d,
1386 &default_context_);
1364 req.set_method("GET"); 1387 req.set_method("GET");
1365 req.Start(); 1388 req.Start();
1366 base::RunLoop().Run(); 1389 base::RunLoop().Run();
1367 1390
1368 // Check the interceptor got called as expected 1391 // Check the interceptor got called as expected
1369 EXPECT_TRUE(interceptor.did_restart_main_); 1392 EXPECT_TRUE(interceptor.did_restart_main_);
1370 EXPECT_TRUE(interceptor.did_intercept_main_); 1393 EXPECT_TRUE(interceptor.did_intercept_main_);
1371 1394
1372 // Check we received one good response 1395 // Check we received one good response
1373 EXPECT_TRUE(req.status().is_success()); 1396 EXPECT_TRUE(req.status().is_success());
(...skipping 10 matching lines...) Expand all
1384 1407
1385 // intercept the main request and cancel from within the restarted job 1408 // intercept the main request and cancel from within the restarted job
1386 interceptor.cancel_main_request_ = true; 1409 interceptor.cancel_main_request_ = true;
1387 1410
1388 // setup to intercept final response and override it with an OK response 1411 // setup to intercept final response and override it with an OK response
1389 interceptor.intercept_final_response_ = true; 1412 interceptor.intercept_final_response_ = true;
1390 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1413 interceptor.final_headers_ = TestInterceptor::ok_headers();
1391 interceptor.final_data_ = TestInterceptor::ok_data(); 1414 interceptor.final_data_ = TestInterceptor::ok_data();
1392 1415
1393 TestDelegate d; 1416 TestDelegate d;
1394 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1417 URLRequest req(GURL("http://test_intercept/foo"),
1418 DEFAULT_PRIORITY,
1419 &d,
1420 &default_context_);
1395 req.set_method("GET"); 1421 req.set_method("GET");
1396 req.Start(); 1422 req.Start();
1397 base::RunLoop().Run(); 1423 base::RunLoop().Run();
1398 1424
1399 // Check the interceptor got called as expected 1425 // Check the interceptor got called as expected
1400 EXPECT_TRUE(interceptor.did_cancel_main_); 1426 EXPECT_TRUE(interceptor.did_cancel_main_);
1401 EXPECT_FALSE(interceptor.did_intercept_final_); 1427 EXPECT_FALSE(interceptor.did_intercept_final_);
1402 1428
1403 // Check we see a canceled request 1429 // Check we see a canceled request
1404 EXPECT_FALSE(req.status().is_success()); 1430 EXPECT_FALSE(req.status().is_success());
(...skipping 10 matching lines...) Expand all
1415 1441
1416 // intercept the redirect and cancel from within that job 1442 // intercept the redirect and cancel from within that job
1417 interceptor.cancel_redirect_request_ = true; 1443 interceptor.cancel_redirect_request_ = true;
1418 1444
1419 // setup to intercept final response and override it with an OK response 1445 // setup to intercept final response and override it with an OK response
1420 interceptor.intercept_final_response_ = true; 1446 interceptor.intercept_final_response_ = true;
1421 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1447 interceptor.final_headers_ = TestInterceptor::ok_headers();
1422 interceptor.final_data_ = TestInterceptor::ok_data(); 1448 interceptor.final_data_ = TestInterceptor::ok_data();
1423 1449
1424 TestDelegate d; 1450 TestDelegate d;
1425 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1451 URLRequest req(GURL("http://test_intercept/foo"),
1452 DEFAULT_PRIORITY,
1453 &d,
1454 &default_context_);
1426 req.set_method("GET"); 1455 req.set_method("GET");
1427 req.Start(); 1456 req.Start();
1428 base::RunLoop().Run(); 1457 base::RunLoop().Run();
1429 1458
1430 // Check the interceptor got called as expected 1459 // Check the interceptor got called as expected
1431 EXPECT_TRUE(interceptor.did_intercept_main_); 1460 EXPECT_TRUE(interceptor.did_intercept_main_);
1432 EXPECT_TRUE(interceptor.did_cancel_redirect_); 1461 EXPECT_TRUE(interceptor.did_cancel_redirect_);
1433 EXPECT_FALSE(interceptor.did_intercept_final_); 1462 EXPECT_FALSE(interceptor.did_intercept_final_);
1434 1463
1435 // Check we see a canceled request 1464 // Check we see a canceled request
1436 EXPECT_FALSE(req.status().is_success()); 1465 EXPECT_FALSE(req.status().is_success());
1437 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1466 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
1438 } 1467 }
1439 1468
1440 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { 1469 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) {
1441 TestInterceptor interceptor; 1470 TestInterceptor interceptor;
1442 1471
1443 // intercept the main request to simulate a network error 1472 // intercept the main request to simulate a network error
1444 interceptor.simulate_main_network_error_ = true; 1473 interceptor.simulate_main_network_error_ = true;
1445 1474
1446 // setup to intercept final response and cancel from within that job 1475 // setup to intercept final response and cancel from within that job
1447 interceptor.cancel_final_request_ = true; 1476 interceptor.cancel_final_request_ = true;
1448 1477
1449 TestDelegate d; 1478 TestDelegate d;
1450 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1479 URLRequest req(GURL("http://test_intercept/foo"),
1480 DEFAULT_PRIORITY,
1481 &d,
1482 &default_context_);
1451 req.set_method("GET"); 1483 req.set_method("GET");
1452 req.Start(); 1484 req.Start();
1453 base::RunLoop().Run(); 1485 base::RunLoop().Run();
1454 1486
1455 // Check the interceptor got called as expected 1487 // Check the interceptor got called as expected
1456 EXPECT_TRUE(interceptor.did_simulate_error_main_); 1488 EXPECT_TRUE(interceptor.did_simulate_error_main_);
1457 EXPECT_TRUE(interceptor.did_cancel_final_); 1489 EXPECT_TRUE(interceptor.did_cancel_final_);
1458 1490
1459 // Check we see a canceled request 1491 // Check we see a canceled request
1460 EXPECT_FALSE(req.status().is_success()); 1492 EXPECT_FALSE(req.status().is_success());
1461 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1493 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
1462 } 1494 }
1463 1495
1464 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { 1496 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
1465 TestInterceptor interceptor; 1497 TestInterceptor interceptor;
1466 1498
1467 // intercept the main request and cancel then restart from within that job 1499 // intercept the main request and cancel then restart from within that job
1468 interceptor.cancel_then_restart_main_request_ = true; 1500 interceptor.cancel_then_restart_main_request_ = true;
1469 1501
1470 // setup to intercept final response and override it with an OK response 1502 // setup to intercept final response and override it with an OK response
1471 interceptor.intercept_final_response_ = true; 1503 interceptor.intercept_final_response_ = true;
1472 interceptor.final_headers_ = TestInterceptor::ok_headers(); 1504 interceptor.final_headers_ = TestInterceptor::ok_headers();
1473 interceptor.final_data_ = TestInterceptor::ok_data(); 1505 interceptor.final_data_ = TestInterceptor::ok_data();
1474 1506
1475 TestDelegate d; 1507 TestDelegate d;
1476 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1508 URLRequest req(GURL("http://test_intercept/foo"),
1509 DEFAULT_PRIORITY,
1510 &d,
1511 &default_context_);
1477 req.set_method("GET"); 1512 req.set_method("GET");
1478 req.Start(); 1513 req.Start();
1479 base::RunLoop().Run(); 1514 base::RunLoop().Run();
1480 1515
1481 // Check the interceptor got called as expected 1516 // Check the interceptor got called as expected
1482 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 1517 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
1483 EXPECT_FALSE(interceptor.did_intercept_final_); 1518 EXPECT_FALSE(interceptor.did_intercept_final_);
1484 1519
1485 // Check we see a canceled request 1520 // Check we see a canceled request
1486 EXPECT_FALSE(req.status().is_success()); 1521 EXPECT_FALSE(req.status().is_success());
1487 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 1522 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
1488 } 1523 }
1489 1524
1490 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, 1525 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing,
1491 URLRequestContext* context) { 1526 URLRequestContext* context) {
1492 TestInterceptor interceptor; 1527 TestInterceptor interceptor;
1493 interceptor.intercept_main_request_ = true; 1528 interceptor.intercept_main_request_ = true;
1494 interceptor.main_request_load_timing_info_ = job_load_timing; 1529 interceptor.main_request_load_timing_info_ = job_load_timing;
1495 TestDelegate d; 1530 TestDelegate d;
1496 URLRequest req(GURL("http://test_intercept/foo"), &d, context); 1531 URLRequest req(
1532 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, context);
1497 req.Start(); 1533 req.Start();
1498 base::RunLoop().Run(); 1534 base::RunLoop().Run();
1499 1535
1500 LoadTimingInfo resulting_load_timing; 1536 LoadTimingInfo resulting_load_timing;
1501 req.GetLoadTimingInfo(&resulting_load_timing); 1537 req.GetLoadTimingInfo(&resulting_load_timing);
1502 1538
1503 // None of these should be modified by the URLRequest. 1539 // None of these should be modified by the URLRequest.
1504 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); 1540 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused);
1505 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); 1541 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id);
1506 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); 1542 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11); 1596 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11);
1561 return load_timing; 1597 return load_timing;
1562 } 1598 }
1563 1599
1564 // Basic test that the intercept + load timing tests work. 1600 // Basic test that the intercept + load timing tests work.
1565 TEST_F(URLRequestTest, InterceptLoadTiming) { 1601 TEST_F(URLRequestTest, InterceptLoadTiming) {
1566 base::TimeTicks now = base::TimeTicks::Now(); 1602 base::TimeTicks now = base::TimeTicks::Now();
1567 LoadTimingInfo job_load_timing = 1603 LoadTimingInfo job_load_timing =
1568 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false); 1604 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false);
1569 1605
1570 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1606 LoadTimingInfo load_timing_result =
1571 &default_context_); 1607 RunLoadTimingTest(job_load_timing, &default_context_);
1572 1608
1573 // Nothing should have been changed by the URLRequest. 1609 // Nothing should have been changed by the URLRequest.
1574 EXPECT_EQ(job_load_timing.proxy_resolve_start, 1610 EXPECT_EQ(job_load_timing.proxy_resolve_start,
1575 load_timing_result.proxy_resolve_start); 1611 load_timing_result.proxy_resolve_start);
1576 EXPECT_EQ(job_load_timing.proxy_resolve_end, 1612 EXPECT_EQ(job_load_timing.proxy_resolve_end,
1577 load_timing_result.proxy_resolve_end); 1613 load_timing_result.proxy_resolve_end);
1578 EXPECT_EQ(job_load_timing.connect_timing.dns_start, 1614 EXPECT_EQ(job_load_timing.connect_timing.dns_start,
1579 load_timing_result.connect_timing.dns_start); 1615 load_timing_result.connect_timing.dns_start);
1580 EXPECT_EQ(job_load_timing.connect_timing.dns_end, 1616 EXPECT_EQ(job_load_timing.connect_timing.dns_end,
1581 load_timing_result.connect_timing.dns_end); 1617 load_timing_result.connect_timing.dns_end);
1582 EXPECT_EQ(job_load_timing.connect_timing.connect_start, 1618 EXPECT_EQ(job_load_timing.connect_timing.connect_start,
1583 load_timing_result.connect_timing.connect_start); 1619 load_timing_result.connect_timing.connect_start);
1584 EXPECT_EQ(job_load_timing.connect_timing.connect_end, 1620 EXPECT_EQ(job_load_timing.connect_timing.connect_end,
1585 load_timing_result.connect_timing.connect_end); 1621 load_timing_result.connect_timing.connect_end);
1586 EXPECT_EQ(job_load_timing.connect_timing.ssl_start, 1622 EXPECT_EQ(job_load_timing.connect_timing.ssl_start,
1587 load_timing_result.connect_timing.ssl_start); 1623 load_timing_result.connect_timing.ssl_start);
1588 EXPECT_EQ(job_load_timing.connect_timing.ssl_end, 1624 EXPECT_EQ(job_load_timing.connect_timing.ssl_end,
1589 load_timing_result.connect_timing.ssl_end); 1625 load_timing_result.connect_timing.ssl_end);
1590 1626
1591 // Redundant sanity check. 1627 // Redundant sanity check.
1592 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES); 1628 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES);
1593 } 1629 }
1594 1630
1595 // Another basic test, with proxy and SSL times, but no DNS times. 1631 // Another basic test, with proxy and SSL times, but no DNS times.
1596 TEST_F(URLRequestTest, InterceptLoadTimingProxy) { 1632 TEST_F(URLRequestTest, InterceptLoadTimingProxy) {
1597 base::TimeTicks now = base::TimeTicks::Now(); 1633 base::TimeTicks now = base::TimeTicks::Now();
1598 LoadTimingInfo job_load_timing = 1634 LoadTimingInfo job_load_timing =
1599 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true); 1635 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true);
1600 1636
1601 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1637 LoadTimingInfo load_timing_result =
1602 &default_context_); 1638 RunLoadTimingTest(job_load_timing, &default_context_);
1603 1639
1604 // Nothing should have been changed by the URLRequest. 1640 // Nothing should have been changed by the URLRequest.
1605 EXPECT_EQ(job_load_timing.proxy_resolve_start, 1641 EXPECT_EQ(job_load_timing.proxy_resolve_start,
1606 load_timing_result.proxy_resolve_start); 1642 load_timing_result.proxy_resolve_start);
1607 EXPECT_EQ(job_load_timing.proxy_resolve_end, 1643 EXPECT_EQ(job_load_timing.proxy_resolve_end,
1608 load_timing_result.proxy_resolve_end); 1644 load_timing_result.proxy_resolve_end);
1609 EXPECT_EQ(job_load_timing.connect_timing.dns_start, 1645 EXPECT_EQ(job_load_timing.connect_timing.dns_start,
1610 load_timing_result.connect_timing.dns_start); 1646 load_timing_result.connect_timing.dns_start);
1611 EXPECT_EQ(job_load_timing.connect_timing.dns_end, 1647 EXPECT_EQ(job_load_timing.connect_timing.dns_end,
1612 load_timing_result.connect_timing.dns_end); 1648 load_timing_result.connect_timing.dns_end);
(...skipping 23 matching lines...) Expand all
1636 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true); 1672 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true);
1637 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6); 1673 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6);
1638 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5); 1674 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5);
1639 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4); 1675 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4);
1640 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3); 1676 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3);
1641 job_load_timing.connect_timing.connect_start = 1677 job_load_timing.connect_timing.connect_start =
1642 now - base::TimeDelta::FromDays(2); 1678 now - base::TimeDelta::FromDays(2);
1643 job_load_timing.connect_timing.connect_end = 1679 job_load_timing.connect_timing.connect_end =
1644 now - base::TimeDelta::FromDays(1); 1680 now - base::TimeDelta::FromDays(1);
1645 1681
1646 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1682 LoadTimingInfo load_timing_result =
1647 &default_context_); 1683 RunLoadTimingTest(job_load_timing, &default_context_);
1648 1684
1649 // Proxy times, connect times, and DNS times should all be replaced with 1685 // Proxy times, connect times, and DNS times should all be replaced with
1650 // request_start. 1686 // request_start.
1651 EXPECT_EQ(load_timing_result.request_start, 1687 EXPECT_EQ(load_timing_result.request_start,
1652 load_timing_result.proxy_resolve_start); 1688 load_timing_result.proxy_resolve_start);
1653 EXPECT_EQ(load_timing_result.request_start, 1689 EXPECT_EQ(load_timing_result.request_start,
1654 load_timing_result.proxy_resolve_end); 1690 load_timing_result.proxy_resolve_end);
1655 EXPECT_EQ(load_timing_result.request_start, 1691 EXPECT_EQ(load_timing_result.request_start,
1656 load_timing_result.connect_timing.dns_start); 1692 load_timing_result.connect_timing.dns_start);
1657 EXPECT_EQ(load_timing_result.request_start, 1693 EXPECT_EQ(load_timing_result.request_start,
1658 load_timing_result.connect_timing.dns_end); 1694 load_timing_result.connect_timing.dns_end);
1659 EXPECT_EQ(load_timing_result.request_start, 1695 EXPECT_EQ(load_timing_result.request_start,
1660 load_timing_result.connect_timing.connect_start); 1696 load_timing_result.connect_timing.connect_start);
1661 EXPECT_EQ(load_timing_result.request_start, 1697 EXPECT_EQ(load_timing_result.request_start,
1662 load_timing_result.connect_timing.connect_end); 1698 load_timing_result.connect_timing.connect_end);
1663 1699
1664 // Other times should have been left null. 1700 // Other times should have been left null.
1665 TestLoadTimingNotReusedWithProxy(load_timing_result, 1701 TestLoadTimingNotReusedWithProxy(load_timing_result,
1666 CONNECT_TIMING_HAS_DNS_TIMES); 1702 CONNECT_TIMING_HAS_DNS_TIMES);
1667 } 1703 }
1668 1704
1669 // Same as above, but in the reused case. 1705 // Same as above, but in the reused case.
1670 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolutionReused) { 1706 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolutionReused) {
1671 base::TimeTicks now = base::TimeTicks::Now(); 1707 base::TimeTicks now = base::TimeTicks::Now();
1672 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true); 1708 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true);
1673 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4); 1709 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4);
1674 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3); 1710 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3);
1675 1711
1676 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1712 LoadTimingInfo load_timing_result =
1677 &default_context_); 1713 RunLoadTimingTest(job_load_timing, &default_context_);
1678 1714
1679 // Proxy times and connect times should all be replaced with request_start. 1715 // Proxy times and connect times should all be replaced with request_start.
1680 EXPECT_EQ(load_timing_result.request_start, 1716 EXPECT_EQ(load_timing_result.request_start,
1681 load_timing_result.proxy_resolve_start); 1717 load_timing_result.proxy_resolve_start);
1682 EXPECT_EQ(load_timing_result.request_start, 1718 EXPECT_EQ(load_timing_result.request_start,
1683 load_timing_result.proxy_resolve_end); 1719 load_timing_result.proxy_resolve_end);
1684 1720
1685 // Other times should have been left null. 1721 // Other times should have been left null.
1686 TestLoadTimingReusedWithProxy(load_timing_result); 1722 TestLoadTimingReusedWithProxy(load_timing_result);
1687 } 1723 }
1688 1724
1689 // Make sure that URLRequest correctly adjusts connect times when they're before 1725 // Make sure that URLRequest correctly adjusts connect times when they're before
1690 // |request_start|, due to reusing a connected socket. The connected socket is 1726 // |request_start|, due to reusing a connected socket. The connected socket is
1691 // not considered reused in this test (May be a preconnect). 1727 // not considered reused in this test (May be a preconnect).
1692 // 1728 //
1693 // To mix things up, the request has SSL times, but no DNS times. 1729 // To mix things up, the request has SSL times, but no DNS times.
1694 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnect) { 1730 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnect) {
1695 base::TimeTicks now = base::TimeTicks::Now(); 1731 base::TimeTicks now = base::TimeTicks::Now();
1696 LoadTimingInfo job_load_timing = 1732 LoadTimingInfo job_load_timing =
1697 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false); 1733 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false);
1698 job_load_timing.connect_timing.connect_start = 1734 job_load_timing.connect_timing.connect_start =
1699 now - base::TimeDelta::FromDays(1); 1735 now - base::TimeDelta::FromDays(1);
1700 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2); 1736 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2);
1701 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3); 1737 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3);
1702 job_load_timing.connect_timing.connect_end = 1738 job_load_timing.connect_timing.connect_end =
1703 now - base::TimeDelta::FromDays(4); 1739 now - base::TimeDelta::FromDays(4);
1704 1740
1705 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1741 LoadTimingInfo load_timing_result =
1706 &default_context_); 1742 RunLoadTimingTest(job_load_timing, &default_context_);
1707 1743
1708 // Connect times, and SSL times should be replaced with request_start. 1744 // Connect times, and SSL times should be replaced with request_start.
1709 EXPECT_EQ(load_timing_result.request_start, 1745 EXPECT_EQ(load_timing_result.request_start,
1710 load_timing_result.connect_timing.connect_start); 1746 load_timing_result.connect_timing.connect_start);
1711 EXPECT_EQ(load_timing_result.request_start, 1747 EXPECT_EQ(load_timing_result.request_start,
1712 load_timing_result.connect_timing.ssl_start); 1748 load_timing_result.connect_timing.ssl_start);
1713 EXPECT_EQ(load_timing_result.request_start, 1749 EXPECT_EQ(load_timing_result.request_start,
1714 load_timing_result.connect_timing.ssl_end); 1750 load_timing_result.connect_timing.ssl_end);
1715 EXPECT_EQ(load_timing_result.request_start, 1751 EXPECT_EQ(load_timing_result.request_start,
1716 load_timing_result.connect_timing.connect_end); 1752 load_timing_result.connect_timing.connect_end);
(...skipping 10 matching lines...) Expand all
1727 // In this test, there are no SSL or DNS times. 1763 // In this test, there are no SSL or DNS times.
1728 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnectWithProxy) { 1764 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnectWithProxy) {
1729 base::TimeTicks now = base::TimeTicks::Now(); 1765 base::TimeTicks now = base::TimeTicks::Now();
1730 LoadTimingInfo job_load_timing = 1766 LoadTimingInfo job_load_timing =
1731 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true); 1767 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true);
1732 job_load_timing.connect_timing.connect_start = 1768 job_load_timing.connect_timing.connect_start =
1733 now - base::TimeDelta::FromDays(1); 1769 now - base::TimeDelta::FromDays(1);
1734 job_load_timing.connect_timing.connect_end = 1770 job_load_timing.connect_timing.connect_end =
1735 now - base::TimeDelta::FromDays(2); 1771 now - base::TimeDelta::FromDays(2);
1736 1772
1737 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, 1773 LoadTimingInfo load_timing_result =
1738 &default_context_); 1774 RunLoadTimingTest(job_load_timing, &default_context_);
1739 1775
1740 // Connect times should be replaced with proxy_resolve_end. 1776 // Connect times should be replaced with proxy_resolve_end.
1741 EXPECT_EQ(load_timing_result.proxy_resolve_end, 1777 EXPECT_EQ(load_timing_result.proxy_resolve_end,
1742 load_timing_result.connect_timing.connect_start); 1778 load_timing_result.connect_timing.connect_start);
1743 EXPECT_EQ(load_timing_result.proxy_resolve_end, 1779 EXPECT_EQ(load_timing_result.proxy_resolve_end,
1744 load_timing_result.connect_timing.connect_end); 1780 load_timing_result.connect_timing.connect_end);
1745 1781
1746 // Other times should have been left null. 1782 // Other times should have been left null.
1747 TestLoadTimingNotReusedWithProxy(load_timing_result, 1783 TestLoadTimingNotReusedWithProxy(load_timing_result,
1748 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); 1784 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
1749 } 1785 }
1750 1786
1751 // Check that two different URL requests have different identifiers. 1787 // Check that two different URL requests have different identifiers.
1752 TEST_F(URLRequestTest, Identifiers) { 1788 TEST_F(URLRequestTest, Identifiers) {
1753 TestDelegate d; 1789 TestDelegate d;
1754 TestURLRequestContext context; 1790 TestURLRequestContext context;
1755 TestURLRequest req(GURL("http://example.com"), &d, &context, NULL); 1791 TestURLRequest req(
1756 TestURLRequest other_req(GURL("http://example.com"), &d, &context, NULL); 1792 GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context);
1793 TestURLRequest other_req(
1794 GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context);
1757 1795
1758 ASSERT_NE(req.identifier(), other_req.identifier()); 1796 ASSERT_NE(req.identifier(), other_req.identifier());
1759 } 1797 }
1760 1798
1761 // Check that a failure to connect to the proxy is reported to the network 1799 // Check that a failure to connect to the proxy is reported to the network
1762 // delegate. 1800 // delegate.
1763 TEST_F(URLRequestTest, NetworkDelegateProxyError) { 1801 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
1764 MockHostResolver host_resolver; 1802 MockHostResolver host_resolver;
1765 host_resolver.rules()->AddSimulatedFailure("*"); 1803 host_resolver.rules()->AddSimulatedFailure("*");
1766 1804
1767 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 1805 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
1768 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); 1806 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate);
1769 1807
1770 TestDelegate d; 1808 TestDelegate d;
1771 URLRequest req(GURL("http://example.com"), &d, &context); 1809 URLRequest req(GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context);
1772 req.set_method("GET"); 1810 req.set_method("GET");
1773 1811
1774 req.Start(); 1812 req.Start();
1775 base::RunLoop().Run(); 1813 base::RunLoop().Run();
1776 1814
1777 // Check we see a failed request. 1815 // Check we see a failed request.
1778 EXPECT_FALSE(req.status().is_success()); 1816 EXPECT_FALSE(req.status().is_success());
1779 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 1817 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
1780 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); 1818 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error());
1781 1819
1782 EXPECT_EQ(1, network_delegate.error_count()); 1820 EXPECT_EQ(1, network_delegate.error_count());
1783 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); 1821 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error());
1784 EXPECT_EQ(1, network_delegate.completed_requests()); 1822 EXPECT_EQ(1, network_delegate.completed_requests());
1785 } 1823 }
1786 1824
1787 // Make sure that net::NetworkDelegate::NotifyCompleted is called if 1825 // Make sure that net::NetworkDelegate::NotifyCompleted is called if
1788 // content is empty. 1826 // content is empty.
1789 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { 1827 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
1790 TestDelegate d; 1828 TestDelegate d;
1791 URLRequest req(GURL("data:,"), &d, &default_context_); 1829 URLRequest req(GURL("data:,"), DEFAULT_PRIORITY, &d, &default_context_);
1792 req.Start(); 1830 req.Start();
1793 base::RunLoop().Run(); 1831 base::RunLoop().Run();
1794 EXPECT_EQ("", d.data_received()); 1832 EXPECT_EQ("", d.data_received());
1795 EXPECT_EQ(1, default_network_delegate_.completed_requests()); 1833 EXPECT_EQ(1, default_network_delegate_.completed_requests());
1796 } 1834 }
1797 1835
1798 // Make sure that SetPriority actually sets the URLRequest's priority 1836 // Make sure that SetPriority actually sets the URLRequest's priority
1799 // correctly, both before and after start. 1837 // correctly, both before and after start.
1800 TEST_F(URLRequestTest, SetPriorityBasic) { 1838 TEST_F(URLRequestTest, SetPriorityBasic) {
1801 TestDelegate d; 1839 TestDelegate d;
1802 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1840 URLRequest req(GURL("http://test_intercept/foo"),
1841 DEFAULT_PRIORITY,
1842 &d,
1843 &default_context_);
1803 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); 1844 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
1804 1845
1805 req.SetPriority(LOW); 1846 req.SetPriority(LOW);
1806 EXPECT_EQ(LOW, req.priority()); 1847 EXPECT_EQ(LOW, req.priority());
1807 1848
1808 req.Start(); 1849 req.Start();
1809 EXPECT_EQ(LOW, req.priority()); 1850 EXPECT_EQ(LOW, req.priority());
1810 1851
1811 req.SetPriority(MEDIUM); 1852 req.SetPriority(MEDIUM);
1812 EXPECT_EQ(MEDIUM, req.priority()); 1853 EXPECT_EQ(MEDIUM, req.priority());
1813 } 1854 }
1814 1855
1815 // Make sure that URLRequest calls SetPriority on a job before calling 1856 // Make sure that URLRequest calls SetPriority on a job before calling
1816 // Start on it. 1857 // Start on it.
1817 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { 1858 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) {
1818 TestDelegate d; 1859 TestDelegate d;
1819 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1860 URLRequest req(GURL("http://test_intercept/foo"),
1861 DEFAULT_PRIORITY,
1862 &d,
1863 &default_context_);
1820 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); 1864 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
1821 1865
1822 scoped_refptr<URLRequestTestJob> job = 1866 scoped_refptr<URLRequestTestJob> job =
1823 new URLRequestTestJob(&req, &default_network_delegate_); 1867 new URLRequestTestJob(&req, &default_network_delegate_);
1824 AddTestInterceptor()->set_main_intercept_job(job.get()); 1868 AddTestInterceptor()->set_main_intercept_job(job.get());
1825 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 1869 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
1826 1870
1827 req.SetPriority(LOW); 1871 req.SetPriority(LOW);
1828 1872
1829 req.Start(); 1873 req.Start();
1830 EXPECT_EQ(LOW, job->priority()); 1874 EXPECT_EQ(LOW, job->priority());
1831 } 1875 }
1832 1876
1833 // Make sure that URLRequest passes on its priority updates to its 1877 // Make sure that URLRequest passes on its priority updates to its
1834 // job. 1878 // job.
1835 TEST_F(URLRequestTest, SetJobPriority) { 1879 TEST_F(URLRequestTest, SetJobPriority) {
1836 TestDelegate d; 1880 TestDelegate d;
1837 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); 1881 URLRequest req(GURL("http://test_intercept/foo"),
1882 DEFAULT_PRIORITY,
1883 &d,
1884 &default_context_);
1838 1885
1839 scoped_refptr<URLRequestTestJob> job = 1886 scoped_refptr<URLRequestTestJob> job =
1840 new URLRequestTestJob(&req, &default_network_delegate_); 1887 new URLRequestTestJob(&req, &default_network_delegate_);
1841 AddTestInterceptor()->set_main_intercept_job(job.get()); 1888 AddTestInterceptor()->set_main_intercept_job(job.get());
1842 1889
1843 req.SetPriority(LOW); 1890 req.SetPriority(LOW);
1844 req.Start(); 1891 req.Start();
1845 EXPECT_EQ(LOW, job->priority()); 1892 EXPECT_EQ(LOW, job->priority());
1846 1893
1847 req.SetPriority(MEDIUM); 1894 req.SetPriority(MEDIUM);
(...skipping 26 matching lines...) Expand all
1874 scoped_refptr<DelayedCookieMonster> delayed_cm = 1921 scoped_refptr<DelayedCookieMonster> delayed_cm =
1875 new DelayedCookieMonster(); 1922 new DelayedCookieMonster();
1876 scoped_refptr<CookieStore> cookie_store = delayed_cm; 1923 scoped_refptr<CookieStore> cookie_store = delayed_cm;
1877 context.set_cookie_store(delayed_cm.get()); 1924 context.set_cookie_store(delayed_cm.get());
1878 1925
1879 // Set up a cookie. 1926 // Set up a cookie.
1880 { 1927 {
1881 TestNetworkDelegate network_delegate; 1928 TestNetworkDelegate network_delegate;
1882 context.set_network_delegate(&network_delegate); 1929 context.set_network_delegate(&network_delegate);
1883 TestDelegate d; 1930 TestDelegate d;
1884 URLRequest req( 1931 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"),
1885 test_server.GetURL("set-cookie?CookieToNotSend=1"), &d, &context); 1932 DEFAULT_PRIORITY,
1933 &d,
1934 &context);
1886 req.Start(); 1935 req.Start();
1887 base::RunLoop().Run(); 1936 base::RunLoop().Run();
1888 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1937 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1889 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1938 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1890 EXPECT_EQ(1, network_delegate.set_cookie_count()); 1939 EXPECT_EQ(1, network_delegate.set_cookie_count());
1891 } 1940 }
1892 1941
1893 // Verify that the cookie is set. 1942 // Verify that the cookie is set.
1894 { 1943 {
1895 TestNetworkDelegate network_delegate; 1944 TestNetworkDelegate network_delegate;
1896 context.set_network_delegate(&network_delegate); 1945 context.set_network_delegate(&network_delegate);
1897 TestDelegate d; 1946 TestDelegate d;
1898 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d, &context); 1947 URLRequest req(test_server.GetURL("echoheader?Cookie"),
1948 DEFAULT_PRIORITY,
1949 &d,
1950 &context);
1899 req.Start(); 1951 req.Start();
1900 base::RunLoop().Run(); 1952 base::RunLoop().Run();
1901 1953
1902 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 1954 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
1903 != std::string::npos); 1955 != std::string::npos);
1904 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1956 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1905 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1957 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1906 } 1958 }
1907 } 1959 }
1908 1960
1909 TEST_F(URLRequestTest, DoNotSendCookies) { 1961 TEST_F(URLRequestTest, DoNotSendCookies) {
1910 LocalHttpTestServer test_server; 1962 LocalHttpTestServer test_server;
1911 ASSERT_TRUE(test_server.Start()); 1963 ASSERT_TRUE(test_server.Start());
1912 1964
1913 // Set up a cookie. 1965 // Set up a cookie.
1914 { 1966 {
1915 TestNetworkDelegate network_delegate; 1967 TestNetworkDelegate network_delegate;
1916 default_context_.set_network_delegate(&network_delegate); 1968 default_context_.set_network_delegate(&network_delegate);
1917 TestDelegate d; 1969 TestDelegate d;
1918 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 1970 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"),
1971 DEFAULT_PRIORITY,
1919 &d, 1972 &d,
1920 &default_context_); 1973 &default_context_);
1921 req.Start(); 1974 req.Start();
1922 base::RunLoop().Run(); 1975 base::RunLoop().Run();
1923 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1976 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1924 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1977 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1925 } 1978 }
1926 1979
1927 // Verify that the cookie is set. 1980 // Verify that the cookie is set.
1928 { 1981 {
1929 TestNetworkDelegate network_delegate; 1982 TestNetworkDelegate network_delegate;
1930 default_context_.set_network_delegate(&network_delegate); 1983 default_context_.set_network_delegate(&network_delegate);
1931 TestDelegate d; 1984 TestDelegate d;
1932 URLRequest req( 1985 URLRequest req(test_server.GetURL("echoheader?Cookie"),
1933 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 1986 DEFAULT_PRIORITY,
1987 &d,
1988 &default_context_);
1934 req.Start(); 1989 req.Start();
1935 base::RunLoop().Run(); 1990 base::RunLoop().Run();
1936 1991
1937 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 1992 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
1938 != std::string::npos); 1993 != std::string::npos);
1939 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 1994 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1940 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 1995 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1941 } 1996 }
1942 1997
1943 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. 1998 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set.
1944 { 1999 {
1945 TestNetworkDelegate network_delegate; 2000 TestNetworkDelegate network_delegate;
1946 default_context_.set_network_delegate(&network_delegate); 2001 default_context_.set_network_delegate(&network_delegate);
1947 TestDelegate d; 2002 TestDelegate d;
1948 URLRequest req( 2003 URLRequest req(test_server.GetURL("echoheader?Cookie"),
1949 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2004 DEFAULT_PRIORITY,
2005 &d,
2006 &default_context_);
1950 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); 2007 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES);
1951 req.Start(); 2008 req.Start();
1952 base::RunLoop().Run(); 2009 base::RunLoop().Run();
1953 2010
1954 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2011 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
1955 == std::string::npos); 2012 == std::string::npos);
1956 2013
1957 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 2014 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
1958 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2015 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1959 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2016 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1960 } 2017 }
1961 } 2018 }
1962 2019
1963 TEST_F(URLRequestTest, DoNotSaveCookies) { 2020 TEST_F(URLRequestTest, DoNotSaveCookies) {
1964 LocalHttpTestServer test_server; 2021 LocalHttpTestServer test_server;
1965 ASSERT_TRUE(test_server.Start()); 2022 ASSERT_TRUE(test_server.Start());
1966 2023
1967 // Set up a cookie. 2024 // Set up a cookie.
1968 { 2025 {
1969 TestNetworkDelegate network_delegate; 2026 TestNetworkDelegate network_delegate;
1970 default_context_.set_network_delegate(&network_delegate); 2027 default_context_.set_network_delegate(&network_delegate);
1971 TestDelegate d; 2028 TestDelegate d;
1972 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2029 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"),
2030 DEFAULT_PRIORITY,
1973 &d, 2031 &d,
1974 &default_context_); 2032 &default_context_);
1975 req.Start(); 2033 req.Start();
1976 base::RunLoop().Run(); 2034 base::RunLoop().Run();
1977 2035
1978 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2036 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1979 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2037 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
1980 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2038 EXPECT_EQ(1, network_delegate.set_cookie_count());
1981 } 2039 }
1982 2040
1983 // Try to set-up another cookie and update the previous cookie. 2041 // Try to set-up another cookie and update the previous cookie.
1984 { 2042 {
1985 TestNetworkDelegate network_delegate; 2043 TestNetworkDelegate network_delegate;
1986 default_context_.set_network_delegate(&network_delegate); 2044 default_context_.set_network_delegate(&network_delegate);
1987 TestDelegate d; 2045 TestDelegate d;
1988 URLRequest req( 2046 URLRequest req(
1989 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2047 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2048 DEFAULT_PRIORITY,
1990 &d, 2049 &d,
1991 &default_context_); 2050 &default_context_);
1992 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); 2051 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES);
1993 req.Start(); 2052 req.Start();
1994 2053
1995 base::RunLoop().Run(); 2054 base::RunLoop().Run();
1996 2055
1997 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. 2056 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie.
1998 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2057 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
1999 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2058 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2000 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2059 EXPECT_EQ(0, network_delegate.set_cookie_count());
2001 } 2060 }
2002 2061
2003 // Verify the cookies weren't saved or updated. 2062 // Verify the cookies weren't saved or updated.
2004 { 2063 {
2005 TestNetworkDelegate network_delegate; 2064 TestNetworkDelegate network_delegate;
2006 default_context_.set_network_delegate(&network_delegate); 2065 default_context_.set_network_delegate(&network_delegate);
2007 TestDelegate d; 2066 TestDelegate d;
2008 URLRequest req( 2067 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2009 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2068 DEFAULT_PRIORITY,
2069 &d,
2070 &default_context_);
2010 req.Start(); 2071 req.Start();
2011 base::RunLoop().Run(); 2072 base::RunLoop().Run();
2012 2073
2013 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2074 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2014 == std::string::npos); 2075 == std::string::npos);
2015 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2076 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2016 != std::string::npos); 2077 != std::string::npos);
2017 2078
2018 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2079 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2019 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2080 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2020 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2081 EXPECT_EQ(0, network_delegate.set_cookie_count());
2021 } 2082 }
2022 } 2083 }
2023 2084
2024 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 2085 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
2025 LocalHttpTestServer test_server; 2086 LocalHttpTestServer test_server;
2026 ASSERT_TRUE(test_server.Start()); 2087 ASSERT_TRUE(test_server.Start());
2027 2088
2028 // Set up a cookie. 2089 // Set up a cookie.
2029 { 2090 {
2030 TestNetworkDelegate network_delegate; 2091 TestNetworkDelegate network_delegate;
2031 default_context_.set_network_delegate(&network_delegate); 2092 default_context_.set_network_delegate(&network_delegate);
2032 TestDelegate d; 2093 TestDelegate d;
2033 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 2094 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"),
2095 DEFAULT_PRIORITY,
2034 &d, 2096 &d,
2035 &default_context_); 2097 &default_context_);
2036 req.Start(); 2098 req.Start();
2037 base::RunLoop().Run(); 2099 base::RunLoop().Run();
2038 2100
2039 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2101 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2040 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2102 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2041 } 2103 }
2042 2104
2043 // Verify that the cookie is set. 2105 // Verify that the cookie is set.
2044 { 2106 {
2045 TestNetworkDelegate network_delegate; 2107 TestNetworkDelegate network_delegate;
2046 default_context_.set_network_delegate(&network_delegate); 2108 default_context_.set_network_delegate(&network_delegate);
2047 TestDelegate d; 2109 TestDelegate d;
2048 URLRequest req( 2110 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2049 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2111 DEFAULT_PRIORITY,
2112 &d,
2113 &default_context_);
2050 req.Start(); 2114 req.Start();
2051 base::RunLoop().Run(); 2115 base::RunLoop().Run();
2052 2116
2053 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2117 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2054 != std::string::npos); 2118 != std::string::npos);
2055 2119
2056 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2120 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2057 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2121 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2058 } 2122 }
2059 2123
2060 // Verify that the cookie isn't sent. 2124 // Verify that the cookie isn't sent.
2061 { 2125 {
2062 TestNetworkDelegate network_delegate; 2126 TestNetworkDelegate network_delegate;
2063 default_context_.set_network_delegate(&network_delegate); 2127 default_context_.set_network_delegate(&network_delegate);
2064 TestDelegate d; 2128 TestDelegate d;
2065 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2129 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2066 URLRequest req( 2130 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2067 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2131 DEFAULT_PRIORITY,
2132 &d,
2133 &default_context_);
2068 req.Start(); 2134 req.Start();
2069 base::RunLoop().Run(); 2135 base::RunLoop().Run();
2070 2136
2071 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2137 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2072 == std::string::npos); 2138 == std::string::npos);
2073 2139
2074 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2140 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2075 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2141 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2076 } 2142 }
2077 } 2143 }
2078 2144
2079 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2145 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2080 LocalHttpTestServer test_server; 2146 LocalHttpTestServer test_server;
2081 ASSERT_TRUE(test_server.Start()); 2147 ASSERT_TRUE(test_server.Start());
2082 2148
2083 // Set up a cookie. 2149 // Set up a cookie.
2084 { 2150 {
2085 TestNetworkDelegate network_delegate; 2151 TestNetworkDelegate network_delegate;
2086 default_context_.set_network_delegate(&network_delegate); 2152 default_context_.set_network_delegate(&network_delegate);
2087 TestDelegate d; 2153 TestDelegate d;
2088 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2154 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"),
2155 DEFAULT_PRIORITY,
2089 &d, 2156 &d,
2090 &default_context_); 2157 &default_context_);
2091 req.Start(); 2158 req.Start();
2092 base::RunLoop().Run(); 2159 base::RunLoop().Run();
2093 2160
2094 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2161 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2095 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2162 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2096 } 2163 }
2097 2164
2098 // Try to set-up another cookie and update the previous cookie. 2165 // Try to set-up another cookie and update the previous cookie.
2099 { 2166 {
2100 TestNetworkDelegate network_delegate; 2167 TestNetworkDelegate network_delegate;
2101 default_context_.set_network_delegate(&network_delegate); 2168 default_context_.set_network_delegate(&network_delegate);
2102 TestDelegate d; 2169 TestDelegate d;
2103 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2170 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2104 URLRequest req( 2171 URLRequest req(
2105 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2172 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2173 DEFAULT_PRIORITY,
2106 &d, 2174 &d,
2107 &default_context_); 2175 &default_context_);
2108 req.Start(); 2176 req.Start();
2109 2177
2110 base::RunLoop().Run(); 2178 base::RunLoop().Run();
2111 2179
2112 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2180 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2113 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2181 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2114 } 2182 }
2115 2183
2116 // Verify the cookies weren't saved or updated. 2184 // Verify the cookies weren't saved or updated.
2117 { 2185 {
2118 TestNetworkDelegate network_delegate; 2186 TestNetworkDelegate network_delegate;
2119 default_context_.set_network_delegate(&network_delegate); 2187 default_context_.set_network_delegate(&network_delegate);
2120 TestDelegate d; 2188 TestDelegate d;
2121 URLRequest req( 2189 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2122 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2190 DEFAULT_PRIORITY,
2191 &d,
2192 &default_context_);
2123 req.Start(); 2193 req.Start();
2124 base::RunLoop().Run(); 2194 base::RunLoop().Run();
2125 2195
2126 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2196 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2127 == std::string::npos); 2197 == std::string::npos);
2128 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2198 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2129 != std::string::npos); 2199 != std::string::npos);
2130 2200
2131 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2201 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2132 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2202 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2133 } 2203 }
2134 } 2204 }
2135 2205
2136 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 2206 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
2137 LocalHttpTestServer test_server; 2207 LocalHttpTestServer test_server;
2138 ASSERT_TRUE(test_server.Start()); 2208 ASSERT_TRUE(test_server.Start());
2139 2209
2140 // Set up an empty cookie. 2210 // Set up an empty cookie.
2141 { 2211 {
2142 TestNetworkDelegate network_delegate; 2212 TestNetworkDelegate network_delegate;
2143 default_context_.set_network_delegate(&network_delegate); 2213 default_context_.set_network_delegate(&network_delegate);
2144 TestDelegate d; 2214 TestDelegate d;
2145 URLRequest req(test_server.GetURL("set-cookie"), &d, &default_context_); 2215 URLRequest req(test_server.GetURL("set-cookie"),
2216 DEFAULT_PRIORITY,
2217 &d,
2218 &default_context_);
2146 req.Start(); 2219 req.Start();
2147 base::RunLoop().Run(); 2220 base::RunLoop().Run();
2148 2221
2149 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2222 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2150 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2223 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2151 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2224 EXPECT_EQ(0, network_delegate.set_cookie_count());
2152 } 2225 }
2153 } 2226 }
2154 2227
2155 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 2228 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
2156 LocalHttpTestServer test_server; 2229 LocalHttpTestServer test_server;
2157 ASSERT_TRUE(test_server.Start()); 2230 ASSERT_TRUE(test_server.Start());
2158 2231
2159 // Set up a cookie. 2232 // Set up a cookie.
2160 { 2233 {
2161 TestNetworkDelegate network_delegate; 2234 TestNetworkDelegate network_delegate;
2162 default_context_.set_network_delegate(&network_delegate); 2235 default_context_.set_network_delegate(&network_delegate);
2163 TestDelegate d; 2236 TestDelegate d;
2164 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), 2237 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"),
2238 DEFAULT_PRIORITY,
2165 &d, 2239 &d,
2166 &default_context_); 2240 &default_context_);
2167 req.Start(); 2241 req.Start();
2168 base::RunLoop().Run(); 2242 base::RunLoop().Run();
2169 2243
2170 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2244 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2171 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2245 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2172 } 2246 }
2173 2247
2174 // Verify that the cookie is set. 2248 // Verify that the cookie is set.
2175 { 2249 {
2176 TestNetworkDelegate network_delegate; 2250 TestNetworkDelegate network_delegate;
2177 default_context_.set_network_delegate(&network_delegate); 2251 default_context_.set_network_delegate(&network_delegate);
2178 TestDelegate d; 2252 TestDelegate d;
2179 URLRequest req( 2253 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2180 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2254 DEFAULT_PRIORITY,
2255 &d,
2256 &default_context_);
2181 req.Start(); 2257 req.Start();
2182 base::RunLoop().Run(); 2258 base::RunLoop().Run();
2183 2259
2184 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2260 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2185 != std::string::npos); 2261 != std::string::npos);
2186 2262
2187 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2263 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2188 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2264 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2189 } 2265 }
2190 2266
2191 // Verify that the cookie isn't sent. 2267 // Verify that the cookie isn't sent.
2192 { 2268 {
2193 TestNetworkDelegate network_delegate; 2269 TestNetworkDelegate network_delegate;
2194 default_context_.set_network_delegate(&network_delegate); 2270 default_context_.set_network_delegate(&network_delegate);
2195 TestDelegate d; 2271 TestDelegate d;
2196 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2272 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2197 URLRequest req( 2273 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2198 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2274 DEFAULT_PRIORITY,
2275 &d,
2276 &default_context_);
2199 req.Start(); 2277 req.Start();
2200 base::RunLoop().Run(); 2278 base::RunLoop().Run();
2201 2279
2202 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2280 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2203 == std::string::npos); 2281 == std::string::npos);
2204 2282
2205 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2283 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2206 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2284 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2207 } 2285 }
2208 } 2286 }
2209 2287
2210 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2288 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2211 LocalHttpTestServer test_server; 2289 LocalHttpTestServer test_server;
2212 ASSERT_TRUE(test_server.Start()); 2290 ASSERT_TRUE(test_server.Start());
2213 2291
2214 // Set up a cookie. 2292 // Set up a cookie.
2215 { 2293 {
2216 TestNetworkDelegate network_delegate; 2294 TestNetworkDelegate network_delegate;
2217 default_context_.set_network_delegate(&network_delegate); 2295 default_context_.set_network_delegate(&network_delegate);
2218 TestDelegate d; 2296 TestDelegate d;
2219 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), 2297 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"),
2298 DEFAULT_PRIORITY,
2220 &d, 2299 &d,
2221 &default_context_); 2300 &default_context_);
2222 req.Start(); 2301 req.Start();
2223 base::RunLoop().Run(); 2302 base::RunLoop().Run();
2224 2303
2225 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2304 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2226 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2305 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2227 } 2306 }
2228 2307
2229 // Try to set-up another cookie and update the previous cookie. 2308 // Try to set-up another cookie and update the previous cookie.
2230 { 2309 {
2231 TestNetworkDelegate network_delegate; 2310 TestNetworkDelegate network_delegate;
2232 default_context_.set_network_delegate(&network_delegate); 2311 default_context_.set_network_delegate(&network_delegate);
2233 TestDelegate d; 2312 TestDelegate d;
2234 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2313 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2235 URLRequest req( 2314 URLRequest req(
2236 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2315 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2316 DEFAULT_PRIORITY,
2237 &d, 2317 &d,
2238 &default_context_); 2318 &default_context_);
2239 req.Start(); 2319 req.Start();
2240 2320
2241 base::RunLoop().Run(); 2321 base::RunLoop().Run();
2242 2322
2243 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2323 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2244 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2324 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2245 } 2325 }
2246 2326
2247 // Verify the cookies weren't saved or updated. 2327 // Verify the cookies weren't saved or updated.
2248 { 2328 {
2249 TestNetworkDelegate network_delegate; 2329 TestNetworkDelegate network_delegate;
2250 default_context_.set_network_delegate(&network_delegate); 2330 default_context_.set_network_delegate(&network_delegate);
2251 TestDelegate d; 2331 TestDelegate d;
2252 URLRequest req( 2332 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2253 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2333 DEFAULT_PRIORITY,
2334 &d,
2335 &default_context_);
2254 req.Start(); 2336 req.Start();
2255 base::RunLoop().Run(); 2337 base::RunLoop().Run();
2256 2338
2257 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2339 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2258 == std::string::npos); 2340 == std::string::npos);
2259 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2341 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2260 != std::string::npos); 2342 != std::string::npos);
2261 2343
2262 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2344 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2263 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2345 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 // headers by defaulting to GMT. (crbug.com/135131) 2391 // headers by defaulting to GMT. (crbug.com/135131)
2310 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { 2392 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) {
2311 LocalHttpTestServer test_server; 2393 LocalHttpTestServer test_server;
2312 ASSERT_TRUE(test_server.Start()); 2394 ASSERT_TRUE(test_server.Start());
2313 2395
2314 // Set up an expired cookie. 2396 // Set up an expired cookie.
2315 { 2397 {
2316 TestNetworkDelegate network_delegate; 2398 TestNetworkDelegate network_delegate;
2317 default_context_.set_network_delegate(&network_delegate); 2399 default_context_.set_network_delegate(&network_delegate);
2318 TestDelegate d; 2400 TestDelegate d;
2319 URLRequest req(test_server.GetURL( 2401 URLRequest req(
2320 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2402 test_server.GetURL(
2403 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2404 DEFAULT_PRIORITY,
2321 &d, 2405 &d,
2322 &default_context_); 2406 &default_context_);
2323 req.Start(); 2407 req.Start();
2324 base::RunLoop().Run(); 2408 base::RunLoop().Run();
2325 } 2409 }
2326 // Verify that the cookie is not set. 2410 // Verify that the cookie is not set.
2327 { 2411 {
2328 TestNetworkDelegate network_delegate; 2412 TestNetworkDelegate network_delegate;
2329 default_context_.set_network_delegate(&network_delegate); 2413 default_context_.set_network_delegate(&network_delegate);
2330 TestDelegate d; 2414 TestDelegate d;
2331 URLRequest req( 2415 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2332 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2416 DEFAULT_PRIORITY,
2417 &d,
2418 &default_context_);
2333 req.Start(); 2419 req.Start();
2334 base::RunLoop().Run(); 2420 base::RunLoop().Run();
2335 2421
2336 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); 2422 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos);
2337 } 2423 }
2338 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. 2424 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier.
2339 { 2425 {
2340 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); 2426 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC");
2341 default_context_.set_network_delegate(&network_delegate); 2427 default_context_.set_network_delegate(&network_delegate);
2342 TestDelegate d; 2428 TestDelegate d;
2343 URLRequest req(test_server.GetURL( 2429 URLRequest req(
2344 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2430 test_server.GetURL(
2431 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2432 DEFAULT_PRIORITY,
2345 &d, 2433 &d,
2346 &default_context_); 2434 &default_context_);
2347 req.Start(); 2435 req.Start();
2348 base::RunLoop().Run(); 2436 base::RunLoop().Run();
2349 } 2437 }
2350 // Verify that the cookie is set. 2438 // Verify that the cookie is set.
2351 { 2439 {
2352 TestNetworkDelegate network_delegate; 2440 TestNetworkDelegate network_delegate;
2353 default_context_.set_network_delegate(&network_delegate); 2441 default_context_.set_network_delegate(&network_delegate);
2354 TestDelegate d; 2442 TestDelegate d;
2355 URLRequest req( 2443 URLRequest req(test_server.GetURL("echoheader?Cookie"),
2356 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); 2444 DEFAULT_PRIORITY,
2445 &d,
2446 &default_context_);
2357 req.Start(); 2447 req.Start();
2358 base::RunLoop().Run(); 2448 base::RunLoop().Run();
2359 2449
2360 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); 2450 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos);
2361 } 2451 }
2362 } 2452 }
2363 2453
2364 2454
2365 // Check that it is impossible to change the referrer in the extra headers of 2455 // Check that it is impossible to change the referrer in the extra headers of
2366 // an URLRequest. 2456 // an URLRequest.
2367 TEST_F(URLRequestTest, DoNotOverrideReferrer) { 2457 TEST_F(URLRequestTest, DoNotOverrideReferrer) {
2368 LocalHttpTestServer test_server; 2458 LocalHttpTestServer test_server;
2369 ASSERT_TRUE(test_server.Start()); 2459 ASSERT_TRUE(test_server.Start());
2370 2460
2371 // If extra headers contain referer and the request contains a referer, 2461 // If extra headers contain referer and the request contains a referer,
2372 // only the latter shall be respected. 2462 // only the latter shall be respected.
2373 { 2463 {
2374 TestDelegate d; 2464 TestDelegate d;
2375 URLRequest req( 2465 URLRequest req(test_server.GetURL("echoheader?Referer"),
2376 test_server.GetURL("echoheader?Referer"), &d, &default_context_); 2466 DEFAULT_PRIORITY,
2467 &d,
2468 &default_context_);
2377 req.SetReferrer("http://foo.com/"); 2469 req.SetReferrer("http://foo.com/");
2378 2470
2379 HttpRequestHeaders headers; 2471 HttpRequestHeaders headers;
2380 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2472 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2381 req.SetExtraRequestHeaders(headers); 2473 req.SetExtraRequestHeaders(headers);
2382 2474
2383 req.Start(); 2475 req.Start();
2384 base::RunLoop().Run(); 2476 base::RunLoop().Run();
2385 2477
2386 EXPECT_EQ("http://foo.com/", d.data_received()); 2478 EXPECT_EQ("http://foo.com/", d.data_received());
2387 } 2479 }
2388 2480
2389 // If extra headers contain a referer but the request does not, no referer 2481 // If extra headers contain a referer but the request does not, no referer
2390 // shall be sent in the header. 2482 // shall be sent in the header.
2391 { 2483 {
2392 TestDelegate d; 2484 TestDelegate d;
2393 URLRequest req( 2485 URLRequest req(test_server.GetURL("echoheader?Referer"),
2394 test_server.GetURL("echoheader?Referer"), &d, &default_context_); 2486 DEFAULT_PRIORITY,
2487 &d,
2488 &default_context_);
2395 2489
2396 HttpRequestHeaders headers; 2490 HttpRequestHeaders headers;
2397 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2491 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2398 req.SetExtraRequestHeaders(headers); 2492 req.SetExtraRequestHeaders(headers);
2399 req.set_load_flags(LOAD_VALIDATE_CACHE); 2493 req.set_load_flags(LOAD_VALIDATE_CACHE);
2400 2494
2401 req.Start(); 2495 req.Start();
2402 base::RunLoop().Run(); 2496 base::RunLoop().Run();
2403 2497
2404 EXPECT_EQ("None", d.data_received()); 2498 EXPECT_EQ("None", d.data_received());
(...skipping 14 matching lines...) Expand all
2419 // request, after redirection. 2513 // request, after redirection.
2420 // If |include_data| is true, data is uploaded with the request. The 2514 // If |include_data| is true, data is uploaded with the request. The
2421 // response body is expected to match it exactly, if and only if 2515 // response body is expected to match it exactly, if and only if
2422 // |request_method| == |redirect_method|. 2516 // |request_method| == |redirect_method|.
2423 void HTTPRedirectMethodTest(const GURL& redirect_url, 2517 void HTTPRedirectMethodTest(const GURL& redirect_url,
2424 const std::string& request_method, 2518 const std::string& request_method,
2425 const std::string& redirect_method, 2519 const std::string& redirect_method,
2426 bool include_data) { 2520 bool include_data) {
2427 static const char kData[] = "hello world"; 2521 static const char kData[] = "hello world";
2428 TestDelegate d; 2522 TestDelegate d;
2429 URLRequest req(redirect_url, &d, &default_context_); 2523 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_);
2430 req.set_method(request_method); 2524 req.set_method(request_method);
2431 if (include_data) { 2525 if (include_data) {
2432 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 2526 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
2433 HttpRequestHeaders headers; 2527 HttpRequestHeaders headers;
2434 headers.SetHeader(HttpRequestHeaders::kContentLength, 2528 headers.SetHeader(HttpRequestHeaders::kContentLength,
2435 base::UintToString(arraysize(kData) - 1)); 2529 base::UintToString(arraysize(kData) - 1));
2436 req.SetExtraRequestHeaders(headers); 2530 req.SetExtraRequestHeaders(headers);
2437 } 2531 }
2438 req.Start(); 2532 req.Start();
2439 base::RunLoop().Run(); 2533 base::RunLoop().Run();
(...skipping 24 matching lines...) Expand all
2464 ptr--; 2558 ptr--;
2465 *ptr++ = marker; 2559 *ptr++ = marker;
2466 if (++marker > 'z') 2560 if (++marker > 'z')
2467 marker = 'a'; 2561 marker = 'a';
2468 } 2562 }
2469 } 2563 }
2470 uploadBytes[kMsgSize] = '\0'; 2564 uploadBytes[kMsgSize] = '\0';
2471 2565
2472 for (int i = 0; i < kIterations; ++i) { 2566 for (int i = 0; i < kIterations; ++i) {
2473 TestDelegate d; 2567 TestDelegate d;
2474 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 2568 URLRequest r(
2569 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
2475 r.set_method(method.c_str()); 2570 r.set_method(method.c_str());
2476 2571
2477 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); 2572 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes)));
2478 2573
2479 r.Start(); 2574 r.Start();
2480 EXPECT_TRUE(r.is_pending()); 2575 EXPECT_TRUE(r.is_pending());
2481 2576
2482 base::RunLoop().Run(); 2577 base::RunLoop().Run();
2483 2578
2484 ASSERT_EQ(1, d.response_started_count()) 2579 ASSERT_EQ(1, d.response_started_count())
(...skipping 27 matching lines...) Expand all
2512 EXPECT_FALSE(d->received_data_before_response()); 2607 EXPECT_FALSE(d->received_data_before_response());
2513 2608
2514 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); 2609 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received()));
2515 EXPECT_EQ(expected_data, d->data_received()); 2610 EXPECT_EQ(expected_data, d->data_received());
2516 } 2611 }
2517 2612
2518 bool DoManyCookiesRequest(int num_cookies) { 2613 bool DoManyCookiesRequest(int num_cookies) {
2519 TestDelegate d; 2614 TestDelegate d;
2520 URLRequest r(test_server_.GetURL("set-many-cookies?" + 2615 URLRequest r(test_server_.GetURL("set-many-cookies?" +
2521 base::IntToString(num_cookies)), 2616 base::IntToString(num_cookies)),
2522 &d, 2617 DEFAULT_PRIORITY,
2523 &default_context_); 2618 &d,
2619 &default_context_);
2524 2620
2525 r.Start(); 2621 r.Start();
2526 EXPECT_TRUE(r.is_pending()); 2622 EXPECT_TRUE(r.is_pending());
2527 2623
2528 base::RunLoop().Run(); 2624 base::RunLoop().Run();
2529 2625
2530 bool is_success = r.status().is_success(); 2626 bool is_success = r.status().is_success();
2531 2627
2532 if (!is_success) { 2628 if (!is_success) {
2533 // Requests handled by ChromeFrame send a less precise error message, 2629 // Requests handled by ChromeFrame send a less precise error message,
(...skipping 14 matching lines...) Expand all
2548 2644
2549 // In this unit test, we're using the HTTPTestServer as a proxy server and 2645 // In this unit test, we're using the HTTPTestServer as a proxy server and
2550 // issuing a CONNECT request with the magic host name "www.redirect.com". 2646 // issuing a CONNECT request with the magic host name "www.redirect.com".
2551 // The HTTPTestServer will return a 302 response, which we should not 2647 // The HTTPTestServer will return a 302 response, which we should not
2552 // follow. 2648 // follow.
2553 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { 2649 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) {
2554 ASSERT_TRUE(test_server_.Start()); 2650 ASSERT_TRUE(test_server_.Start());
2555 2651
2556 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 2652 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2557 TestURLRequestContextWithProxy context( 2653 TestURLRequestContextWithProxy context(
2558 test_server_.host_port_pair().ToString(), 2654 test_server_.host_port_pair().ToString(), &network_delegate);
2559 &network_delegate);
2560 2655
2561 TestDelegate d; 2656 TestDelegate d;
2562 { 2657 {
2563 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); 2658 URLRequest r(
2659 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context);
2564 r.Start(); 2660 r.Start();
2565 EXPECT_TRUE(r.is_pending()); 2661 EXPECT_TRUE(r.is_pending());
2566 2662
2567 base::RunLoop().Run(); 2663 base::RunLoop().Run();
2568 2664
2569 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2665 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
2570 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 2666 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
2571 EXPECT_EQ(1, d.response_started_count()); 2667 EXPECT_EQ(1, d.response_started_count());
2572 // We should not have followed the redirect. 2668 // We should not have followed the redirect.
2573 EXPECT_EQ(0, d.received_redirect_count()); 2669 EXPECT_EQ(0, d.received_redirect_count());
2574 } 2670 }
2575 } 2671 }
2576 2672
2577 // This is the same as the previous test, but checks that the network delegate 2673 // This is the same as the previous test, but checks that the network delegate
2578 // registers the error. 2674 // registers the error.
2579 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 2675 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
2580 ASSERT_TRUE(test_server_.Start()); 2676 ASSERT_TRUE(test_server_.Start());
2581 2677
2582 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 2678 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2583 TestURLRequestContextWithProxy context( 2679 TestURLRequestContextWithProxy context(
2584 test_server_.host_port_pair().ToString(), 2680 test_server_.host_port_pair().ToString(), &network_delegate);
2585 &network_delegate);
2586 2681
2587 TestDelegate d; 2682 TestDelegate d;
2588 { 2683 {
2589 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); 2684 URLRequest r(
2685 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context);
2590 r.Start(); 2686 r.Start();
2591 EXPECT_TRUE(r.is_pending()); 2687 EXPECT_TRUE(r.is_pending());
2592 2688
2593 base::RunLoop().Run(); 2689 base::RunLoop().Run();
2594 2690
2595 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2691 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
2596 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 2692 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
2597 EXPECT_EQ(1, d.response_started_count()); 2693 EXPECT_EQ(1, d.response_started_count());
2598 // We should not have followed the redirect. 2694 // We should not have followed the redirect.
2599 EXPECT_EQ(0, d.received_redirect_count()); 2695 EXPECT_EQ(0, d.received_redirect_count());
(...skipping 20 matching lines...) Expand all
2620 network_delegate.set_block_on( 2716 network_delegate.set_block_on(
2621 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | 2717 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST |
2622 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | 2718 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS |
2623 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 2719 BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
2624 2720
2625 TestURLRequestContext context(true); 2721 TestURLRequestContext context(true);
2626 context.set_network_delegate(&network_delegate); 2722 context.set_network_delegate(&network_delegate);
2627 context.Init(); 2723 context.Init();
2628 2724
2629 { 2725 {
2630 URLRequest r(test_server_.GetURL("empty.html"), &d, &context); 2726 URLRequest r(
2727 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, &context);
2631 2728
2632 r.Start(); 2729 r.Start();
2633 for (size_t i = 0; i < blocking_stages_length; ++i) { 2730 for (size_t i = 0; i < blocking_stages_length; ++i) {
2634 base::RunLoop().Run(); 2731 base::RunLoop().Run();
2635 EXPECT_EQ(blocking_stages[i], 2732 EXPECT_EQ(blocking_stages[i],
2636 network_delegate.stage_blocked_for_callback()); 2733 network_delegate.stage_blocked_for_callback());
2637 network_delegate.DoCallback(OK); 2734 network_delegate.DoCallback(OK);
2638 } 2735 }
2639 base::RunLoop().Run(); 2736 base::RunLoop().Run();
2640 EXPECT_EQ(200, r.GetResponseCode()); 2737 EXPECT_EQ(200, r.GetResponseCode());
2641 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2738 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2642 EXPECT_EQ(1, network_delegate.created_requests()); 2739 EXPECT_EQ(1, network_delegate.created_requests());
2643 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2740 EXPECT_EQ(0, network_delegate.destroyed_requests());
2644 } 2741 }
2645 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2742 EXPECT_EQ(1, network_delegate.destroyed_requests());
2646 } 2743 }
2647 2744
2648 // Tests that the network delegate can block and cancel a request. 2745 // Tests that the network delegate can block and cancel a request.
2649 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { 2746 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
2650 ASSERT_TRUE(test_server_.Start()); 2747 ASSERT_TRUE(test_server_.Start());
2651 2748
2652 TestDelegate d; 2749 TestDelegate d;
2653 BlockingNetworkDelegate network_delegate( 2750 BlockingNetworkDelegate network_delegate(
2654 BlockingNetworkDelegate::AUTO_CALLBACK); 2751 BlockingNetworkDelegate::AUTO_CALLBACK);
2655 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2752 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2656 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 2753 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
2657 2754
2658 TestURLRequestContextWithProxy context( 2755 TestURLRequestContextWithProxy context(
2659 test_server_.host_port_pair().ToString(), 2756 test_server_.host_port_pair().ToString(), &network_delegate);
2660 &network_delegate);
2661 2757
2662 { 2758 {
2663 URLRequest r(test_server_.GetURL(std::string()), &d, &context); 2759 URLRequest r(
2760 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
2664 2761
2665 r.Start(); 2762 r.Start();
2666 base::RunLoop().Run(); 2763 base::RunLoop().Run();
2667 2764
2668 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2765 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
2669 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 2766 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
2670 EXPECT_EQ(1, network_delegate.created_requests()); 2767 EXPECT_EQ(1, network_delegate.created_requests());
2671 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2768 EXPECT_EQ(0, network_delegate.destroyed_requests());
2672 } 2769 }
2673 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2770 EXPECT_EQ(1, network_delegate.destroyed_requests());
2674 } 2771 }
2675 2772
2676 // Helper function for NetworkDelegateCancelRequestAsynchronously and 2773 // Helper function for NetworkDelegateCancelRequestAsynchronously and
2677 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network 2774 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network
2678 // delegate operating in |block_mode| and a request for |url|. It blocks the 2775 // delegate operating in |block_mode| and a request for |url|. It blocks the
2679 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. 2776 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT.
2680 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, 2777 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode,
2681 BlockingNetworkDelegate::Stage stage, 2778 BlockingNetworkDelegate::Stage stage,
2682 const GURL& url) { 2779 const GURL& url) {
2683 TestDelegate d; 2780 TestDelegate d;
2684 BlockingNetworkDelegate network_delegate(block_mode); 2781 BlockingNetworkDelegate network_delegate(block_mode);
2685 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); 2782 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT);
2686 network_delegate.set_block_on(stage); 2783 network_delegate.set_block_on(stage);
2687 2784
2688 TestURLRequestContext context(true); 2785 TestURLRequestContext context(true);
2689 context.set_network_delegate(&network_delegate); 2786 context.set_network_delegate(&network_delegate);
2690 context.Init(); 2787 context.Init();
2691 2788
2692 { 2789 {
2693 URLRequest r(url, &d, &context); 2790 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
2694 2791
2695 r.Start(); 2792 r.Start();
2696 base::RunLoop().Run(); 2793 base::RunLoop().Run();
2697 2794
2698 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 2795 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
2699 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); 2796 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error());
2700 EXPECT_EQ(1, network_delegate.created_requests()); 2797 EXPECT_EQ(1, network_delegate.created_requests());
2701 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2798 EXPECT_EQ(0, network_delegate.destroyed_requests());
2702 } 2799 }
2703 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2800 EXPECT_EQ(1, network_delegate.destroyed_requests());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 ASSERT_TRUE(test_server_.Start()); 2852 ASSERT_TRUE(test_server_.Start());
2756 2853
2757 TestDelegate d; 2854 TestDelegate d;
2758 BlockingNetworkDelegate network_delegate( 2855 BlockingNetworkDelegate network_delegate(
2759 BlockingNetworkDelegate::AUTO_CALLBACK); 2856 BlockingNetworkDelegate::AUTO_CALLBACK);
2760 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2857 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2761 GURL redirect_url(test_server_.GetURL("simple.html")); 2858 GURL redirect_url(test_server_.GetURL("simple.html"));
2762 network_delegate.set_redirect_url(redirect_url); 2859 network_delegate.set_redirect_url(redirect_url);
2763 2860
2764 TestURLRequestContextWithProxy context( 2861 TestURLRequestContextWithProxy context(
2765 test_server_.host_port_pair().ToString(), 2862 test_server_.host_port_pair().ToString(), &network_delegate);
2766 &network_delegate);
2767 2863
2768 { 2864 {
2769 GURL original_url(test_server_.GetURL("empty.html")); 2865 GURL original_url(test_server_.GetURL("empty.html"));
2770 URLRequest r(original_url, &d, &context); 2866 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context);
2771 2867
2772 r.Start(); 2868 r.Start();
2773 base::RunLoop().Run(); 2869 base::RunLoop().Run();
2774 2870
2775 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2871 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2776 EXPECT_EQ(0, r.status().error()); 2872 EXPECT_EQ(0, r.status().error());
2777 EXPECT_EQ(redirect_url, r.url()); 2873 EXPECT_EQ(redirect_url, r.url());
2778 EXPECT_EQ(original_url, r.original_url()); 2874 EXPECT_EQ(original_url, r.original_url());
2779 EXPECT_EQ(2U, r.url_chain().size()); 2875 EXPECT_EQ(2U, r.url_chain().size());
2780 EXPECT_EQ(1, network_delegate.created_requests()); 2876 EXPECT_EQ(1, network_delegate.created_requests());
2781 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2877 EXPECT_EQ(0, network_delegate.destroyed_requests());
2782 } 2878 }
2783 EXPECT_EQ(1, network_delegate.destroyed_requests()); 2879 EXPECT_EQ(1, network_delegate.destroyed_requests());
2784 } 2880 }
2785 2881
2786 // Tests that the network delegate can block and redirect a request to a new 2882 // Tests that the network delegate can block and redirect a request to a new
2787 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. 2883 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly.
2788 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { 2884 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) {
2789 ASSERT_TRUE(test_server_.Start()); 2885 ASSERT_TRUE(test_server_.Start());
2790 2886
2791 TestDelegate d; 2887 TestDelegate d;
2792 BlockingNetworkDelegate network_delegate( 2888 BlockingNetworkDelegate network_delegate(
2793 BlockingNetworkDelegate::SYNCHRONOUS); 2889 BlockingNetworkDelegate::SYNCHRONOUS);
2794 GURL redirect_url(test_server_.GetURL("simple.html")); 2890 GURL redirect_url(test_server_.GetURL("simple.html"));
2795 network_delegate.set_redirect_url(redirect_url); 2891 network_delegate.set_redirect_url(redirect_url);
2796 2892
2797 TestURLRequestContextWithProxy context( 2893 TestURLRequestContextWithProxy context(
2798 test_server_.host_port_pair().ToString(), 2894 test_server_.host_port_pair().ToString(), &network_delegate);
2799 &network_delegate);
2800 2895
2801 { 2896 {
2802 GURL original_url(test_server_.GetURL("empty.html")); 2897 GURL original_url(test_server_.GetURL("empty.html"));
2803 URLRequest r(original_url, &d, &context); 2898 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context);
2804 2899
2805 r.Start(); 2900 r.Start();
2806 base::RunLoop().Run(); 2901 base::RunLoop().Run();
2807 2902
2808 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2903 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2809 EXPECT_EQ(0, r.status().error()); 2904 EXPECT_EQ(0, r.status().error());
2810 EXPECT_EQ(redirect_url, r.url()); 2905 EXPECT_EQ(redirect_url, r.url());
2811 EXPECT_EQ(original_url, r.original_url()); 2906 EXPECT_EQ(original_url, r.original_url());
2812 EXPECT_EQ(2U, r.url_chain().size()); 2907 EXPECT_EQ(2U, r.url_chain().size());
2813 EXPECT_EQ(1, network_delegate.created_requests()); 2908 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 14 matching lines...) Expand all
2828 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 2923 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
2829 GURL redirect_url(test_server_.GetURL("echo")); 2924 GURL redirect_url(test_server_.GetURL("echo"));
2830 network_delegate.set_redirect_url(redirect_url); 2925 network_delegate.set_redirect_url(redirect_url);
2831 2926
2832 TestURLRequestContext context(true); 2927 TestURLRequestContext context(true);
2833 context.set_network_delegate(&network_delegate); 2928 context.set_network_delegate(&network_delegate);
2834 context.Init(); 2929 context.Init();
2835 2930
2836 { 2931 {
2837 GURL original_url(test_server_.GetURL("empty.html")); 2932 GURL original_url(test_server_.GetURL("empty.html"));
2838 URLRequest r(original_url, &d, &context); 2933 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context);
2839 r.set_method("POST"); 2934 r.set_method("POST");
2840 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 2935 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
2841 HttpRequestHeaders headers; 2936 HttpRequestHeaders headers;
2842 headers.SetHeader(HttpRequestHeaders::kContentLength, 2937 headers.SetHeader(HttpRequestHeaders::kContentLength,
2843 base::UintToString(arraysize(kData) - 1)); 2938 base::UintToString(arraysize(kData) - 1));
2844 r.SetExtraRequestHeaders(headers); 2939 r.SetExtraRequestHeaders(headers);
2845 r.Start(); 2940 r.Start();
2846 base::RunLoop().Run(); 2941 base::RunLoop().Run();
2847 2942
2848 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2943 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
(...skipping 21 matching lines...) Expand all
2870 BlockingNetworkDelegate::SYNCHRONOUS); 2965 BlockingNetworkDelegate::SYNCHRONOUS);
2871 2966
2872 TestURLRequestContext context(true); 2967 TestURLRequestContext context(true);
2873 context.set_network_delegate(&network_delegate); 2968 context.set_network_delegate(&network_delegate);
2874 context.Init(); 2969 context.Init();
2875 2970
2876 d.set_credentials(AuthCredentials(kUser, kSecret)); 2971 d.set_credentials(AuthCredentials(kUser, kSecret));
2877 2972
2878 { 2973 {
2879 GURL url(test_server_.GetURL("auth-basic")); 2974 GURL url(test_server_.GetURL("auth-basic"));
2880 URLRequest r(url, &d, &context); 2975 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
2881 r.Start(); 2976 r.Start();
2882 2977
2883 base::RunLoop().Run(); 2978 base::RunLoop().Run();
2884 2979
2885 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2980 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2886 EXPECT_EQ(0, r.status().error()); 2981 EXPECT_EQ(0, r.status().error());
2887 EXPECT_EQ(200, r.GetResponseCode()); 2982 EXPECT_EQ(200, r.GetResponseCode());
2888 EXPECT_TRUE(d.auth_required_called()); 2983 EXPECT_TRUE(d.auth_required_called());
2889 EXPECT_EQ(1, network_delegate.created_requests()); 2984 EXPECT_EQ(1, network_delegate.created_requests());
2890 EXPECT_EQ(0, network_delegate.destroyed_requests()); 2985 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 10 matching lines...) Expand all
2901 BlockingNetworkDelegate::SYNCHRONOUS); 2996 BlockingNetworkDelegate::SYNCHRONOUS);
2902 2997
2903 TestURLRequestContext context(true); 2998 TestURLRequestContext context(true);
2904 context.set_network_delegate(&network_delegate); 2999 context.set_network_delegate(&network_delegate);
2905 context.Init(); 3000 context.Init();
2906 3001
2907 d.set_credentials(AuthCredentials(kUser, kSecret)); 3002 d.set_credentials(AuthCredentials(kUser, kSecret));
2908 3003
2909 { 3004 {
2910 GURL url(test_server_.GetURL("auth-basic")); 3005 GURL url(test_server_.GetURL("auth-basic"));
2911 URLRequest r(url, &d, &context); 3006 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
2912 r.Start(); 3007 r.Start();
2913 3008
2914 { 3009 {
2915 HttpRequestHeaders headers; 3010 HttpRequestHeaders headers;
2916 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); 3011 EXPECT_TRUE(r.GetFullRequestHeaders(&headers));
2917 EXPECT_FALSE(headers.HasHeader("Authorization")); 3012 EXPECT_FALSE(headers.HasHeader("Authorization"));
2918 } 3013 }
2919 3014
2920 base::RunLoop().Run(); 3015 base::RunLoop().Run();
2921 3016
(...skipping 20 matching lines...) Expand all
2942 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3037 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
2943 3038
2944 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3039 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
2945 3040
2946 TestURLRequestContext context(true); 3041 TestURLRequestContext context(true);
2947 context.set_network_delegate(&network_delegate); 3042 context.set_network_delegate(&network_delegate);
2948 context.Init(); 3043 context.Init();
2949 3044
2950 { 3045 {
2951 GURL url(test_server_.GetURL("auth-basic")); 3046 GURL url(test_server_.GetURL("auth-basic"));
2952 URLRequest r(url, &d, &context); 3047 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
2953 r.Start(); 3048 r.Start();
2954 base::RunLoop().Run(); 3049 base::RunLoop().Run();
2955 3050
2956 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3051 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2957 EXPECT_EQ(0, r.status().error()); 3052 EXPECT_EQ(0, r.status().error());
2958 EXPECT_EQ(200, r.GetResponseCode()); 3053 EXPECT_EQ(200, r.GetResponseCode());
2959 EXPECT_FALSE(d.auth_required_called()); 3054 EXPECT_FALSE(d.auth_required_called());
2960 EXPECT_EQ(1, network_delegate.created_requests()); 3055 EXPECT_EQ(1, network_delegate.created_requests());
2961 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3056 EXPECT_EQ(0, network_delegate.destroyed_requests());
2962 } 3057 }
(...skipping 14 matching lines...) Expand all
2977 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3072 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
2978 3073
2979 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3074 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
2980 3075
2981 TestURLRequestContext context(true); 3076 TestURLRequestContext context(true);
2982 context.set_network_delegate(&network_delegate); 3077 context.set_network_delegate(&network_delegate);
2983 context.Init(); 3078 context.Init();
2984 3079
2985 { 3080 {
2986 GURL url(test_server_.GetURL("auth-basic")); 3081 GURL url(test_server_.GetURL("auth-basic"));
2987 URLRequest r(url, &d, &context); 3082 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
2988 r.Start(); 3083 r.Start();
2989 base::RunLoop().Run(); 3084 base::RunLoop().Run();
2990 3085
2991 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3086 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2992 EXPECT_EQ(0, r.status().error()); 3087 EXPECT_EQ(0, r.status().error());
2993 EXPECT_EQ(200, r.GetResponseCode()); 3088 EXPECT_EQ(200, r.GetResponseCode());
2994 EXPECT_FALSE(d.auth_required_called()); 3089 EXPECT_FALSE(d.auth_required_called());
2995 EXPECT_EQ(1, network_delegate.created_requests()); 3090 EXPECT_EQ(1, network_delegate.created_requests());
2996 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3091 EXPECT_EQ(0, network_delegate.destroyed_requests());
2997 3092
(...skipping 17 matching lines...) Expand all
3015 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3110 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3016 network_delegate.set_auth_retval( 3111 network_delegate.set_auth_retval(
3017 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3112 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3018 3113
3019 TestURLRequestContext context(true); 3114 TestURLRequestContext context(true);
3020 context.set_network_delegate(&network_delegate); 3115 context.set_network_delegate(&network_delegate);
3021 context.Init(); 3116 context.Init();
3022 3117
3023 { 3118 {
3024 GURL url(test_server_.GetURL("auth-basic")); 3119 GURL url(test_server_.GetURL("auth-basic"));
3025 URLRequest r(url, &d, &context); 3120 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
3026 r.Start(); 3121 r.Start();
3027 base::RunLoop().Run(); 3122 base::RunLoop().Run();
3028 3123
3029 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3124 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3030 EXPECT_EQ(OK, r.status().error()); 3125 EXPECT_EQ(OK, r.status().error());
3031 EXPECT_EQ(401, r.GetResponseCode()); 3126 EXPECT_EQ(401, r.GetResponseCode());
3032 EXPECT_FALSE(d.auth_required_called()); 3127 EXPECT_FALSE(d.auth_required_called());
3033 EXPECT_EQ(1, network_delegate.created_requests()); 3128 EXPECT_EQ(1, network_delegate.created_requests());
3034 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3129 EXPECT_EQ(0, network_delegate.destroyed_requests());
3035 } 3130 }
(...skipping 13 matching lines...) Expand all
3049 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3144 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3050 3145
3051 TestURLRequestContext context(true); 3146 TestURLRequestContext context(true);
3052 context.set_network_delegate(&network_delegate); 3147 context.set_network_delegate(&network_delegate);
3053 context.Init(); 3148 context.Init();
3054 3149
3055 d.set_credentials(AuthCredentials(kUser, kSecret)); 3150 d.set_credentials(AuthCredentials(kUser, kSecret));
3056 3151
3057 { 3152 {
3058 GURL url(test_server_.GetURL("auth-basic")); 3153 GURL url(test_server_.GetURL("auth-basic"));
3059 URLRequest r(url, &d, &context); 3154 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
3060 r.Start(); 3155 r.Start();
3061 base::RunLoop().Run(); 3156 base::RunLoop().Run();
3062 3157
3063 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3158 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3064 EXPECT_EQ(0, r.status().error()); 3159 EXPECT_EQ(0, r.status().error());
3065 EXPECT_EQ(200, r.GetResponseCode()); 3160 EXPECT_EQ(200, r.GetResponseCode());
3066 EXPECT_TRUE(d.auth_required_called()); 3161 EXPECT_TRUE(d.auth_required_called());
3067 EXPECT_EQ(1, network_delegate.created_requests()); 3162 EXPECT_EQ(1, network_delegate.created_requests());
3068 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3163 EXPECT_EQ(0, network_delegate.destroyed_requests());
3069 } 3164 }
(...skipping 14 matching lines...) Expand all
3084 3179
3085 AuthCredentials auth_credentials(kUser, kSecret); 3180 AuthCredentials auth_credentials(kUser, kSecret);
3086 network_delegate.set_auth_credentials(auth_credentials); 3181 network_delegate.set_auth_credentials(auth_credentials);
3087 3182
3088 TestURLRequestContext context(true); 3183 TestURLRequestContext context(true);
3089 context.set_network_delegate(&network_delegate); 3184 context.set_network_delegate(&network_delegate);
3090 context.Init(); 3185 context.Init();
3091 3186
3092 { 3187 {
3093 GURL url(test_server_.GetURL("auth-basic")); 3188 GURL url(test_server_.GetURL("auth-basic"));
3094 URLRequest r(url, &d, &context); 3189 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
3095 r.Start(); 3190 r.Start();
3096 base::RunLoop().Run(); 3191 base::RunLoop().Run();
3097 3192
3098 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3193 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3099 EXPECT_EQ(0, r.status().error()); 3194 EXPECT_EQ(0, r.status().error());
3100 3195
3101 EXPECT_EQ(200, r.GetResponseCode()); 3196 EXPECT_EQ(200, r.GetResponseCode());
3102 EXPECT_FALSE(d.auth_required_called()); 3197 EXPECT_FALSE(d.auth_required_called());
3103 EXPECT_EQ(1, network_delegate.created_requests()); 3198 EXPECT_EQ(1, network_delegate.created_requests());
3104 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3199 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 12 matching lines...) Expand all
3117 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3212 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3118 network_delegate.set_auth_retval( 3213 network_delegate.set_auth_retval(
3119 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3214 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3120 3215
3121 TestURLRequestContext context(true); 3216 TestURLRequestContext context(true);
3122 context.set_network_delegate(&network_delegate); 3217 context.set_network_delegate(&network_delegate);
3123 context.Init(); 3218 context.Init();
3124 3219
3125 { 3220 {
3126 GURL url(test_server_.GetURL("auth-basic")); 3221 GURL url(test_server_.GetURL("auth-basic"));
3127 URLRequest r(url, &d, &context); 3222 URLRequest r(url, DEFAULT_PRIORITY, &d, &context);
3128 r.Start(); 3223 r.Start();
3129 base::RunLoop().Run(); 3224 base::RunLoop().Run();
3130 3225
3131 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 3226 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3132 EXPECT_EQ(OK, r.status().error()); 3227 EXPECT_EQ(OK, r.status().error());
3133 EXPECT_EQ(401, r.GetResponseCode()); 3228 EXPECT_EQ(401, r.GetResponseCode());
3134 EXPECT_FALSE(d.auth_required_called()); 3229 EXPECT_FALSE(d.auth_required_called());
3135 EXPECT_EQ(1, network_delegate.created_requests()); 3230 EXPECT_EQ(1, network_delegate.created_requests());
3136 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3231 EXPECT_EQ(0, network_delegate.destroyed_requests());
3137 } 3232 }
3138 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3233 EXPECT_EQ(1, network_delegate.destroyed_requests());
3139 } 3234 }
3140 3235
3141 // Tests that we can handle when a network request was canceled while we were 3236 // Tests that we can handle when a network request was canceled while we were
3142 // waiting for the network delegate. 3237 // waiting for the network delegate.
3143 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. 3238 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback.
3144 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { 3239 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) {
3145 ASSERT_TRUE(test_server_.Start()); 3240 ASSERT_TRUE(test_server_.Start());
3146 3241
3147 TestDelegate d; 3242 TestDelegate d;
3148 BlockingNetworkDelegate network_delegate( 3243 BlockingNetworkDelegate network_delegate(
3149 BlockingNetworkDelegate::USER_CALLBACK); 3244 BlockingNetworkDelegate::USER_CALLBACK);
3150 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3245 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3151 3246
3152 TestURLRequestContext context(true); 3247 TestURLRequestContext context(true);
3153 context.set_network_delegate(&network_delegate); 3248 context.set_network_delegate(&network_delegate);
3154 context.Init(); 3249 context.Init();
3155 3250
3156 { 3251 {
3157 URLRequest r(test_server_.GetURL(std::string()), &d, &context); 3252 URLRequest r(
3253 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
3158 3254
3159 r.Start(); 3255 r.Start();
3160 base::RunLoop().Run(); 3256 base::RunLoop().Run();
3161 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 3257 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
3162 network_delegate.stage_blocked_for_callback()); 3258 network_delegate.stage_blocked_for_callback());
3163 EXPECT_EQ(0, network_delegate.completed_requests()); 3259 EXPECT_EQ(0, network_delegate.completed_requests());
3164 // Cancel before callback. 3260 // Cancel before callback.
3165 r.Cancel(); 3261 r.Cancel();
3166 // Ensure that network delegate is notified. 3262 // Ensure that network delegate is notified.
3167 EXPECT_EQ(1, network_delegate.completed_requests()); 3263 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 15 matching lines...) Expand all
3183 BlockingNetworkDelegate network_delegate( 3279 BlockingNetworkDelegate network_delegate(
3184 BlockingNetworkDelegate::USER_CALLBACK); 3280 BlockingNetworkDelegate::USER_CALLBACK);
3185 network_delegate.set_block_on( 3281 network_delegate.set_block_on(
3186 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); 3282 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS);
3187 3283
3188 TestURLRequestContext context(true); 3284 TestURLRequestContext context(true);
3189 context.set_network_delegate(&network_delegate); 3285 context.set_network_delegate(&network_delegate);
3190 context.Init(); 3286 context.Init();
3191 3287
3192 { 3288 {
3193 URLRequest r(test_server_.GetURL(std::string()), &d, &context); 3289 URLRequest r(
3290 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
3194 3291
3195 r.Start(); 3292 r.Start();
3196 base::RunLoop().Run(); 3293 base::RunLoop().Run();
3197 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 3294 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
3198 network_delegate.stage_blocked_for_callback()); 3295 network_delegate.stage_blocked_for_callback());
3199 EXPECT_EQ(0, network_delegate.completed_requests()); 3296 EXPECT_EQ(0, network_delegate.completed_requests());
3200 // Cancel before callback. 3297 // Cancel before callback.
3201 r.Cancel(); 3298 r.Cancel();
3202 // Ensure that network delegate is notified. 3299 // Ensure that network delegate is notified.
3203 EXPECT_EQ(1, network_delegate.completed_requests()); 3300 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 14 matching lines...) Expand all
3218 TestDelegate d; 3315 TestDelegate d;
3219 BlockingNetworkDelegate network_delegate( 3316 BlockingNetworkDelegate network_delegate(
3220 BlockingNetworkDelegate::USER_CALLBACK); 3317 BlockingNetworkDelegate::USER_CALLBACK);
3221 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3318 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3222 3319
3223 TestURLRequestContext context(true); 3320 TestURLRequestContext context(true);
3224 context.set_network_delegate(&network_delegate); 3321 context.set_network_delegate(&network_delegate);
3225 context.Init(); 3322 context.Init();
3226 3323
3227 { 3324 {
3228 URLRequest r(test_server_.GetURL(std::string()), &d, &context); 3325 URLRequest r(
3326 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
3229 3327
3230 r.Start(); 3328 r.Start();
3231 base::RunLoop().Run(); 3329 base::RunLoop().Run();
3232 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 3330 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
3233 network_delegate.stage_blocked_for_callback()); 3331 network_delegate.stage_blocked_for_callback());
3234 EXPECT_EQ(0, network_delegate.completed_requests()); 3332 EXPECT_EQ(0, network_delegate.completed_requests());
3235 // Cancel before callback. 3333 // Cancel before callback.
3236 r.Cancel(); 3334 r.Cancel();
3237 // Ensure that network delegate is notified. 3335 // Ensure that network delegate is notified.
3238 EXPECT_EQ(1, network_delegate.completed_requests()); 3336 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 14 matching lines...) Expand all
3253 TestDelegate d; 3351 TestDelegate d;
3254 BlockingNetworkDelegate network_delegate( 3352 BlockingNetworkDelegate network_delegate(
3255 BlockingNetworkDelegate::USER_CALLBACK); 3353 BlockingNetworkDelegate::USER_CALLBACK);
3256 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3354 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3257 3355
3258 TestURLRequestContext context(true); 3356 TestURLRequestContext context(true);
3259 context.set_network_delegate(&network_delegate); 3357 context.set_network_delegate(&network_delegate);
3260 context.Init(); 3358 context.Init();
3261 3359
3262 { 3360 {
3263 URLRequest r(test_server_.GetURL("auth-basic"), &d, &context); 3361 URLRequest r(
3362 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, &context);
3264 3363
3265 r.Start(); 3364 r.Start();
3266 base::RunLoop().Run(); 3365 base::RunLoop().Run();
3267 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, 3366 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED,
3268 network_delegate.stage_blocked_for_callback()); 3367 network_delegate.stage_blocked_for_callback());
3269 EXPECT_EQ(0, network_delegate.completed_requests()); 3368 EXPECT_EQ(0, network_delegate.completed_requests());
3270 // Cancel before callback. 3369 // Cancel before callback.
3271 r.Cancel(); 3370 r.Cancel();
3272 // Ensure that network delegate is notified. 3371 // Ensure that network delegate is notified.
3273 EXPECT_EQ(1, network_delegate.completed_requests()); 3372 EXPECT_EQ(1, network_delegate.completed_requests());
3274 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 3373 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
3275 EXPECT_EQ(ERR_ABORTED, r.status().error()); 3374 EXPECT_EQ(ERR_ABORTED, r.status().error());
3276 EXPECT_EQ(1, network_delegate.created_requests()); 3375 EXPECT_EQ(1, network_delegate.created_requests());
3277 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3376 EXPECT_EQ(0, network_delegate.destroyed_requests());
3278 } 3377 }
3279 EXPECT_EQ(1, network_delegate.destroyed_requests()); 3378 EXPECT_EQ(1, network_delegate.destroyed_requests());
3280 } 3379 }
3281 3380
3282 // In this unit test, we're using the HTTPTestServer as a proxy server and 3381 // In this unit test, we're using the HTTPTestServer as a proxy server and
3283 // issuing a CONNECT request with the magic host name "www.server-auth.com". 3382 // issuing a CONNECT request with the magic host name "www.server-auth.com".
3284 // The HTTPTestServer will return a 401 response, which we should balk at. 3383 // The HTTPTestServer will return a 401 response, which we should balk at.
3285 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 3384 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
3286 ASSERT_TRUE(test_server_.Start()); 3385 ASSERT_TRUE(test_server_.Start());
3287 3386
3288 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3387 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3289 TestURLRequestContextWithProxy context( 3388 TestURLRequestContextWithProxy context(
3290 test_server_.host_port_pair().ToString(), 3389 test_server_.host_port_pair().ToString(), &network_delegate);
3291 &network_delegate);
3292 3390
3293 TestDelegate d; 3391 TestDelegate d;
3294 { 3392 {
3295 URLRequest r(GURL("https://www.server-auth.com/"), &d, &context); 3393 URLRequest r(
3394 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, &context);
3296 3395
3297 r.Start(); 3396 r.Start();
3298 EXPECT_TRUE(r.is_pending()); 3397 EXPECT_TRUE(r.is_pending());
3299 3398
3300 base::RunLoop().Run(); 3399 base::RunLoop().Run();
3301 3400
3302 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 3401 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
3303 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 3402 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
3304 } 3403 }
3305 } 3404 }
3306 3405
3307 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 3406 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
3308 ASSERT_TRUE(test_server_.Start()); 3407 ASSERT_TRUE(test_server_.Start());
3309 3408
3310 TestDelegate d; 3409 TestDelegate d;
3311 { 3410 {
3312 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 3411 URLRequest r(test_server_.GetURL(std::string()),
3412 DEFAULT_PRIORITY,
3413 &d,
3414 &default_context_);
3313 3415
3314 r.Start(); 3416 r.Start();
3315 EXPECT_TRUE(r.is_pending()); 3417 EXPECT_TRUE(r.is_pending());
3316 3418
3317 base::RunLoop().Run(); 3419 base::RunLoop().Run();
3318 3420
3319 EXPECT_EQ(1, d.response_started_count()); 3421 EXPECT_EQ(1, d.response_started_count());
3320 EXPECT_FALSE(d.received_data_before_response()); 3422 EXPECT_FALSE(d.received_data_before_response());
3321 EXPECT_NE(0, d.bytes_received()); 3423 EXPECT_NE(0, d.bytes_received());
3322 EXPECT_EQ(test_server_.host_port_pair().host(), 3424 EXPECT_EQ(test_server_.host_port_pair().host(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 upper_bound = num_cookies; 3470 upper_bound = num_cookies;
3369 } 3471 }
3370 // Success: the test did not crash. 3472 // Success: the test did not crash.
3371 } 3473 }
3372 3474
3373 TEST_F(URLRequestTestHTTP, GetTest) { 3475 TEST_F(URLRequestTestHTTP, GetTest) {
3374 ASSERT_TRUE(test_server_.Start()); 3476 ASSERT_TRUE(test_server_.Start());
3375 3477
3376 TestDelegate d; 3478 TestDelegate d;
3377 { 3479 {
3378 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 3480 URLRequest r(test_server_.GetURL(std::string()),
3481 DEFAULT_PRIORITY,
3482 &d,
3483 &default_context_);
3379 3484
3380 r.Start(); 3485 r.Start();
3381 EXPECT_TRUE(r.is_pending()); 3486 EXPECT_TRUE(r.is_pending());
3382 3487
3383 base::RunLoop().Run(); 3488 base::RunLoop().Run();
3384 3489
3385 EXPECT_EQ(1, d.response_started_count()); 3490 EXPECT_EQ(1, d.response_started_count());
3386 EXPECT_FALSE(d.received_data_before_response()); 3491 EXPECT_FALSE(d.received_data_before_response());
3387 EXPECT_NE(0, d.bytes_received()); 3492 EXPECT_NE(0, d.bytes_received());
3388 EXPECT_EQ(test_server_.host_port_pair().host(), 3493 EXPECT_EQ(test_server_.host_port_pair().host(),
3389 r.GetSocketAddress().host()); 3494 r.GetSocketAddress().host());
3390 EXPECT_EQ(test_server_.host_port_pair().port(), 3495 EXPECT_EQ(test_server_.host_port_pair().port(),
3391 r.GetSocketAddress().port()); 3496 r.GetSocketAddress().port());
3392 } 3497 }
3393 } 3498 }
3394 3499
3395 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { 3500 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) {
3396 ASSERT_TRUE(test_server_.Start()); 3501 ASSERT_TRUE(test_server_.Start());
3397 3502
3398 TestDelegate d; 3503 TestDelegate d;
3399 { 3504 {
3400 GURL test_url(test_server_.GetURL(std::string())); 3505 GURL test_url(test_server_.GetURL(std::string()));
3401 URLRequest r(test_url, &d, &default_context_); 3506 URLRequest r(test_url, DEFAULT_PRIORITY, &d, &default_context_);
3402 3507
3403 HttpRequestHeaders headers; 3508 HttpRequestHeaders headers;
3404 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); 3509 EXPECT_FALSE(r.GetFullRequestHeaders(&headers));
3405 3510
3406 r.Start(); 3511 r.Start();
3407 EXPECT_TRUE(r.is_pending()); 3512 EXPECT_TRUE(r.is_pending());
3408 3513
3409 base::RunLoop().Run(); 3514 base::RunLoop().Run();
3410 3515
3411 EXPECT_EQ(1, d.response_started_count()); 3516 EXPECT_EQ(1, d.response_started_count());
3412 EXPECT_FALSE(d.received_data_before_response()); 3517 EXPECT_FALSE(d.received_data_before_response());
3413 EXPECT_NE(0, d.bytes_received()); 3518 EXPECT_NE(0, d.bytes_received());
3414 EXPECT_EQ(test_server_.host_port_pair().host(), 3519 EXPECT_EQ(test_server_.host_port_pair().host(),
3415 r.GetSocketAddress().host()); 3520 r.GetSocketAddress().host());
3416 EXPECT_EQ(test_server_.host_port_pair().port(), 3521 EXPECT_EQ(test_server_.host_port_pair().port(),
3417 r.GetSocketAddress().port()); 3522 r.GetSocketAddress().port());
3418 3523
3419 EXPECT_TRUE(d.have_full_request_headers()); 3524 EXPECT_TRUE(d.have_full_request_headers());
3420 CheckFullRequestHeaders(d.full_request_headers(), test_url); 3525 CheckFullRequestHeaders(d.full_request_headers(), test_url);
3421 } 3526 }
3422 } 3527 }
3423 3528
3424 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { 3529 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) {
3425 ASSERT_TRUE(test_server_.Start()); 3530 ASSERT_TRUE(test_server_.Start());
3426 3531
3427 TestDelegate d; 3532 TestDelegate d;
3428 { 3533 {
3429 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 3534 URLRequest r(test_server_.GetURL(std::string()),
3535 DEFAULT_PRIORITY,
3536 &d,
3537 &default_context_);
3430 3538
3431 r.Start(); 3539 r.Start();
3432 EXPECT_TRUE(r.is_pending()); 3540 EXPECT_TRUE(r.is_pending());
3433 3541
3434 base::RunLoop().Run(); 3542 base::RunLoop().Run();
3435 3543
3436 LoadTimingInfo load_timing_info; 3544 LoadTimingInfo load_timing_info;
3437 r.GetLoadTimingInfo(&load_timing_info); 3545 r.GetLoadTimingInfo(&load_timing_info);
3438 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 3546 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
3439 3547
(...skipping 29 matching lines...) Expand all
3469 { 3577 {
3470 std::string test_file = 3578 std::string test_file =
3471 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", 3579 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c",
3472 test_parameters[i]); 3580 test_parameters[i]);
3473 3581
3474 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3582 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3475 TestURLRequestContext context(true); 3583 TestURLRequestContext context(true);
3476 context.set_network_delegate(&network_delegate); 3584 context.set_network_delegate(&network_delegate);
3477 context.Init(); 3585 context.Init();
3478 3586
3479 URLRequest r(test_server_.GetURL(test_file), &d, &context); 3587 URLRequest r(
3588 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, &context);
3480 r.Start(); 3589 r.Start();
3481 EXPECT_TRUE(r.is_pending()); 3590 EXPECT_TRUE(r.is_pending());
3482 3591
3483 base::RunLoop().Run(); 3592 base::RunLoop().Run();
3484 3593
3485 EXPECT_EQ(1, d.response_started_count()); 3594 EXPECT_EQ(1, d.response_started_count());
3486 EXPECT_FALSE(d.received_data_before_response()); 3595 EXPECT_FALSE(d.received_data_before_response());
3487 VLOG(1) << " Received " << d.bytes_received() << " bytes" 3596 VLOG(1) << " Received " << d.bytes_received() << " bytes"
3488 << " status = " << r.status().status() 3597 << " status = " << r.status().status()
3489 << " error = " << r.status().error(); 3598 << " error = " << r.status().error();
(...skipping 15 matching lines...) Expand all
3505 SpawnedTestServer https_test_server( 3614 SpawnedTestServer https_test_server(
3506 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, 3615 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
3507 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 3616 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
3508 ASSERT_TRUE(https_test_server.Start()); 3617 ASSERT_TRUE(https_test_server.Start());
3509 3618
3510 // An https server is sent a request with an https referer, 3619 // An https server is sent a request with an https referer,
3511 // and responds with a redirect to an http url. The http 3620 // and responds with a redirect to an http url. The http
3512 // server should not be sent the referer. 3621 // server should not be sent the referer.
3513 GURL http_destination = test_server_.GetURL(std::string()); 3622 GURL http_destination = test_server_.GetURL(std::string());
3514 TestDelegate d; 3623 TestDelegate d;
3515 URLRequest req(https_test_server.GetURL( 3624 URLRequest req(
3516 "server-redirect?" + http_destination.spec()), &d, &default_context_); 3625 https_test_server.GetURL("server-redirect?" + http_destination.spec()),
3626 DEFAULT_PRIORITY,
3627 &d,
3628 &default_context_);
3517 req.SetReferrer("https://www.referrer.com/"); 3629 req.SetReferrer("https://www.referrer.com/");
3518 req.Start(); 3630 req.Start();
3519 base::RunLoop().Run(); 3631 base::RunLoop().Run();
3520 3632
3521 EXPECT_EQ(1, d.response_started_count()); 3633 EXPECT_EQ(1, d.response_started_count());
3522 EXPECT_EQ(1, d.received_redirect_count()); 3634 EXPECT_EQ(1, d.received_redirect_count());
3523 EXPECT_EQ(http_destination, req.url()); 3635 EXPECT_EQ(http_destination, req.url());
3524 EXPECT_EQ(std::string(), req.referrer()); 3636 EXPECT_EQ(std::string(), req.referrer());
3525 } 3637 }
3526 3638
3527 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { 3639 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) {
3528 ASSERT_TRUE(test_server_.Start()); 3640 ASSERT_TRUE(test_server_.Start());
3529 3641
3530 GURL destination_url = test_server_.GetURL(std::string()); 3642 GURL destination_url = test_server_.GetURL(std::string());
3531 GURL original_url = 3643 GURL original_url =
3532 test_server_.GetURL("server-redirect?" + destination_url.spec()); 3644 test_server_.GetURL("server-redirect?" + destination_url.spec());
3533 TestDelegate d; 3645 TestDelegate d;
3534 URLRequest req(original_url, &d, &default_context_); 3646 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_);
3535 req.Start(); 3647 req.Start();
3536 base::RunLoop().Run(); 3648 base::RunLoop().Run();
3537 3649
3538 EXPECT_EQ(1, d.response_started_count()); 3650 EXPECT_EQ(1, d.response_started_count());
3539 EXPECT_EQ(1, d.received_redirect_count()); 3651 EXPECT_EQ(1, d.received_redirect_count());
3540 EXPECT_EQ(destination_url, req.url()); 3652 EXPECT_EQ(destination_url, req.url());
3541 EXPECT_EQ(original_url, req.original_url()); 3653 EXPECT_EQ(original_url, req.original_url());
3542 ASSERT_EQ(2U, req.url_chain().size()); 3654 ASSERT_EQ(2U, req.url_chain().size());
3543 EXPECT_EQ(original_url, req.url_chain()[0]); 3655 EXPECT_EQ(original_url, req.url_chain()[0]);
3544 EXPECT_EQ(destination_url, req.url_chain()[1]); 3656 EXPECT_EQ(destination_url, req.url_chain()[1]);
(...skipping 19 matching lines...) Expand all
3564 3676
3565 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { 3677 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
3566 ASSERT_TRUE(test_server_.Start()); 3678 ASSERT_TRUE(test_server_.Start());
3567 3679
3568 GURL destination_url = test_server_.GetURL(std::string()); 3680 GURL destination_url = test_server_.GetURL(std::string());
3569 GURL middle_redirect_url = 3681 GURL middle_redirect_url =
3570 test_server_.GetURL("server-redirect?" + destination_url.spec()); 3682 test_server_.GetURL("server-redirect?" + destination_url.spec());
3571 GURL original_url = test_server_.GetURL( 3683 GURL original_url = test_server_.GetURL(
3572 "server-redirect?" + middle_redirect_url.spec()); 3684 "server-redirect?" + middle_redirect_url.spec());
3573 TestDelegate d; 3685 TestDelegate d;
3574 URLRequest req(original_url, &d, &default_context_); 3686 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_);
3575 req.Start(); 3687 req.Start();
3576 base::RunLoop().Run(); 3688 base::RunLoop().Run();
3577 3689
3578 EXPECT_EQ(1, d.response_started_count()); 3690 EXPECT_EQ(1, d.response_started_count());
3579 EXPECT_EQ(2, d.received_redirect_count()); 3691 EXPECT_EQ(2, d.received_redirect_count());
3580 EXPECT_EQ(destination_url, req.url()); 3692 EXPECT_EQ(destination_url, req.url());
3581 EXPECT_EQ(original_url, req.original_url()); 3693 EXPECT_EQ(original_url, req.original_url());
3582 ASSERT_EQ(3U, req.url_chain().size()); 3694 ASSERT_EQ(3U, req.url_chain().size());
3583 EXPECT_EQ(original_url, req.url_chain()[0]); 3695 EXPECT_EQ(original_url, req.url_chain()[0]);
3584 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); 3696 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]);
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
3880 ASSERT_TRUE(test_server_.Start()); 3992 ASSERT_TRUE(test_server_.Start());
3881 3993
3882 TestDelegate request_delegate; 3994 TestDelegate request_delegate;
3883 TestURLRequestContext context(true); 3995 TestURLRequestContext context(true);
3884 context.set_network_delegate(NULL); 3996 context.set_network_delegate(NULL);
3885 context.set_net_log(&net_log_); 3997 context.set_net_log(&net_log_);
3886 context.Init(); 3998 context.Init();
3887 3999
3888 { 4000 {
3889 URLRequest r(test_server_.GetURL("empty.html"), 4001 URLRequest r(test_server_.GetURL("empty.html"),
3890 &request_delegate, &context); 4002 DEFAULT_PRIORITY,
4003 &request_delegate,
4004 &context);
3891 LoadStateWithParam load_state = r.GetLoadState(); 4005 LoadStateWithParam load_state = r.GetLoadState();
3892 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4006 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
3893 EXPECT_EQ(string16(), load_state.param); 4007 EXPECT_EQ(string16(), load_state.param);
3894 4008
3895 AsyncDelegateLogger::Run( 4009 AsyncDelegateLogger::Run(
3896 &r, 4010 &r,
3897 LOAD_STATE_WAITING_FOR_DELEGATE, 4011 LOAD_STATE_WAITING_FOR_DELEGATE,
3898 LOAD_STATE_WAITING_FOR_DELEGATE, 4012 LOAD_STATE_WAITING_FOR_DELEGATE,
3899 LOAD_STATE_IDLE, 4013 LOAD_STATE_IDLE,
3900 base::Bind(&URLRequest::Start, base::Unretained(&r))); 4014 base::Bind(&URLRequest::Start, base::Unretained(&r)));
(...skipping 25 matching lines...) Expand all
3926 4040
3927 TestDelegate request_delegate; 4041 TestDelegate request_delegate;
3928 AsyncLoggingNetworkDelegate network_delegate; 4042 AsyncLoggingNetworkDelegate network_delegate;
3929 TestURLRequestContext context(true); 4043 TestURLRequestContext context(true);
3930 context.set_network_delegate(&network_delegate); 4044 context.set_network_delegate(&network_delegate);
3931 context.set_net_log(&net_log_); 4045 context.set_net_log(&net_log_);
3932 context.Init(); 4046 context.Init();
3933 4047
3934 { 4048 {
3935 URLRequest r(test_server_.GetURL("simple.html"), 4049 URLRequest r(test_server_.GetURL("simple.html"),
3936 &request_delegate, &context); 4050 DEFAULT_PRIORITY,
4051 &request_delegate,
4052 &context);
3937 LoadStateWithParam load_state = r.GetLoadState(); 4053 LoadStateWithParam load_state = r.GetLoadState();
3938 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4054 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
3939 EXPECT_EQ(string16(), load_state.param); 4055 EXPECT_EQ(string16(), load_state.param);
3940 4056
3941 r.Start(); 4057 r.Start();
3942 base::RunLoop().Run(); 4058 base::RunLoop().Run();
3943 4059
3944 EXPECT_EQ(200, r.GetResponseCode()); 4060 EXPECT_EQ(200, r.GetResponseCode());
3945 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4061 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3946 EXPECT_EQ(1, network_delegate.created_requests()); 4062 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 30 matching lines...) Expand all
3977 4093
3978 TestDelegate request_delegate; 4094 TestDelegate request_delegate;
3979 AsyncLoggingNetworkDelegate network_delegate; 4095 AsyncLoggingNetworkDelegate network_delegate;
3980 TestURLRequestContext context(true); 4096 TestURLRequestContext context(true);
3981 context.set_network_delegate(&network_delegate); 4097 context.set_network_delegate(&network_delegate);
3982 context.set_net_log(&net_log_); 4098 context.set_net_log(&net_log_);
3983 context.Init(); 4099 context.Init();
3984 4100
3985 { 4101 {
3986 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4102 URLRequest r(test_server_.GetURL("server-redirect?simple.html"),
3987 &request_delegate, &context); 4103 DEFAULT_PRIORITY,
4104 &request_delegate,
4105 &context);
3988 LoadStateWithParam load_state = r.GetLoadState(); 4106 LoadStateWithParam load_state = r.GetLoadState();
3989 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4107 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
3990 EXPECT_EQ(string16(), load_state.param); 4108 EXPECT_EQ(string16(), load_state.param);
3991 4109
3992 r.Start(); 4110 r.Start();
3993 base::RunLoop().Run(); 4111 base::RunLoop().Run();
3994 4112
3995 EXPECT_EQ(200, r.GetResponseCode()); 4113 EXPECT_EQ(200, r.GetResponseCode());
3996 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4114 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
3997 EXPECT_EQ(2, network_delegate.created_requests()); 4115 EXPECT_EQ(2, network_delegate.created_requests());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4053 4171
4054 TestDelegate request_delegate; 4172 TestDelegate request_delegate;
4055 AsyncLoggingNetworkDelegate network_delegate; 4173 AsyncLoggingNetworkDelegate network_delegate;
4056 TestURLRequestContext context(true); 4174 TestURLRequestContext context(true);
4057 context.set_network_delegate(&network_delegate); 4175 context.set_network_delegate(&network_delegate);
4058 context.set_net_log(&net_log_); 4176 context.set_net_log(&net_log_);
4059 context.Init(); 4177 context.Init();
4060 4178
4061 { 4179 {
4062 URLRequest r(test_server_.GetURL("auth-basic"), 4180 URLRequest r(test_server_.GetURL("auth-basic"),
4063 &request_delegate, &context); 4181 DEFAULT_PRIORITY,
4182 &request_delegate,
4183 &context);
4064 LoadStateWithParam load_state = r.GetLoadState(); 4184 LoadStateWithParam load_state = r.GetLoadState();
4065 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4185 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4066 EXPECT_EQ(string16(), load_state.param); 4186 EXPECT_EQ(string16(), load_state.param);
4067 4187
4068 r.Start(); 4188 r.Start();
4069 base::RunLoop().Run(); 4189 base::RunLoop().Run();
4070 4190
4071 EXPECT_EQ(200, r.GetResponseCode()); 4191 EXPECT_EQ(200, r.GetResponseCode());
4072 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4192 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
4073 EXPECT_EQ(1, network_delegate.created_requests()); 4193 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 context.set_net_log(&net_log_); 4231 context.set_net_log(&net_log_);
4112 context.Init(); 4232 context.Init();
4113 4233
4114 { 4234 {
4115 // A chunked response with delays between chunks is used to make sure that 4235 // A chunked response with delays between chunks is used to make sure that
4116 // attempts by the URLRequest delegate to log information while reading the 4236 // attempts by the URLRequest delegate to log information while reading the
4117 // body are ignored. Since they are ignored, this test is robust against 4237 // body are ignored. Since they are ignored, this test is robust against
4118 // the possability of multiple reads being combined in the unlikely event 4238 // the possability of multiple reads being combined in the unlikely event
4119 // that it occurs. 4239 // that it occurs.
4120 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"), 4240 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"),
4121 &request_delegate, &context); 4241 DEFAULT_PRIORITY,
4242 &request_delegate,
4243 &context);
4122 LoadStateWithParam load_state = r.GetLoadState(); 4244 LoadStateWithParam load_state = r.GetLoadState();
4123 r.Start(); 4245 r.Start();
4124 base::RunLoop().Run(); 4246 base::RunLoop().Run();
4125 4247
4126 EXPECT_EQ(200, r.GetResponseCode()); 4248 EXPECT_EQ(200, r.GetResponseCode());
4127 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4249 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
4128 } 4250 }
4129 4251
4130 CapturingNetLog::CapturedEntryList entries; 4252 CapturingNetLog::CapturedEntryList entries;
4131 net_log_.GetEntries(&entries); 4253 net_log_.GetEntries(&entries);
(...skipping 27 matching lines...) Expand all
4159 4281
4160 AsyncLoggingUrlRequestDelegate request_delegate( 4282 AsyncLoggingUrlRequestDelegate request_delegate(
4161 AsyncLoggingUrlRequestDelegate::NO_CANCEL); 4283 AsyncLoggingUrlRequestDelegate::NO_CANCEL);
4162 TestURLRequestContext context(true); 4284 TestURLRequestContext context(true);
4163 context.set_network_delegate(NULL); 4285 context.set_network_delegate(NULL);
4164 context.set_net_log(&net_log_); 4286 context.set_net_log(&net_log_);
4165 context.Init(); 4287 context.Init();
4166 4288
4167 { 4289 {
4168 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4290 URLRequest r(test_server_.GetURL("server-redirect?simple.html"),
4169 &request_delegate, &context); 4291 DEFAULT_PRIORITY,
4292 &request_delegate,
4293 &context);
4170 LoadStateWithParam load_state = r.GetLoadState(); 4294 LoadStateWithParam load_state = r.GetLoadState();
4171 r.Start(); 4295 r.Start();
4172 base::RunLoop().Run(); 4296 base::RunLoop().Run();
4173 4297
4174 EXPECT_EQ(200, r.GetResponseCode()); 4298 EXPECT_EQ(200, r.GetResponseCode());
4175 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4299 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
4176 } 4300 }
4177 4301
4178 CapturingNetLog::CapturedEntryList entries; 4302 CapturingNetLog::CapturedEntryList entries;
4179 net_log_.GetEntries(&entries); 4303 net_log_.GetEntries(&entries);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4217 ++test_case) { 4341 ++test_case) {
4218 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); 4342 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]);
4219 TestURLRequestContext context(true); 4343 TestURLRequestContext context(true);
4220 CapturingNetLog net_log; 4344 CapturingNetLog net_log;
4221 context.set_network_delegate(NULL); 4345 context.set_network_delegate(NULL);
4222 context.set_net_log(&net_log); 4346 context.set_net_log(&net_log);
4223 context.Init(); 4347 context.Init();
4224 4348
4225 { 4349 {
4226 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), 4350 URLRequest r(test_server_.GetURL("server-redirect?simple.html"),
4227 &request_delegate, &context); 4351 DEFAULT_PRIORITY,
4352 &request_delegate,
4353 &context);
4228 LoadStateWithParam load_state = r.GetLoadState(); 4354 LoadStateWithParam load_state = r.GetLoadState();
4229 r.Start(); 4355 r.Start();
4230 base::RunLoop().Run(); 4356 base::RunLoop().Run();
4231 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4357 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
4232 } 4358 }
4233 4359
4234 CapturingNetLog::CapturedEntryList entries; 4360 CapturingNetLog::CapturedEntryList entries;
4235 net_log.GetEntries(&entries); 4361 net_log.GetEntries(&entries);
4236 4362
4237 // Delegate info is always logged in both OnReceivedRedirect and 4363 // Delegate info is always logged in both OnReceivedRedirect and
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 } // namespace 4404 } // namespace
4279 4405
4280 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { 4406 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) {
4281 ASSERT_TRUE(test_server_.Start()); 4407 ASSERT_TRUE(test_server_.Start());
4282 4408
4283 GURL destination_url = test_server_.GetURL( 4409 GURL destination_url = test_server_.GetURL(
4284 "echoheader?" + std::string(kExtraHeader)); 4410 "echoheader?" + std::string(kExtraHeader));
4285 GURL original_url = test_server_.GetURL( 4411 GURL original_url = test_server_.GetURL(
4286 "server-redirect?" + destination_url.spec()); 4412 "server-redirect?" + destination_url.spec());
4287 RedirectWithAdditionalHeadersDelegate d; 4413 RedirectWithAdditionalHeadersDelegate d;
4288 URLRequest req(original_url, &d, &default_context_); 4414 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_);
4289 req.Start(); 4415 req.Start();
4290 base::RunLoop().Run(); 4416 base::RunLoop().Run();
4291 4417
4292 std::string value; 4418 std::string value;
4293 const HttpRequestHeaders& headers = req.extra_request_headers(); 4419 const HttpRequestHeaders& headers = req.extra_request_headers();
4294 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); 4420 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value));
4295 EXPECT_EQ(kExtraValue, value); 4421 EXPECT_EQ(kExtraValue, value);
4296 EXPECT_FALSE(req.is_pending()); 4422 EXPECT_FALSE(req.is_pending());
4297 EXPECT_FALSE(req.is_redirecting()); 4423 EXPECT_FALSE(req.is_redirecting());
4298 EXPECT_EQ(kExtraValue, d.data_received()); 4424 EXPECT_EQ(kExtraValue, d.data_received());
(...skipping 15 matching lines...) Expand all
4314 } // namespace 4440 } // namespace
4315 4441
4316 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { 4442 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) {
4317 ASSERT_TRUE(test_server_.Start()); 4443 ASSERT_TRUE(test_server_.Start());
4318 4444
4319 GURL destination_url = test_server_.GetURL( 4445 GURL destination_url = test_server_.GetURL(
4320 "echoheader?" + std::string(kExtraHeaderToRemove)); 4446 "echoheader?" + std::string(kExtraHeaderToRemove));
4321 GURL original_url = test_server_.GetURL( 4447 GURL original_url = test_server_.GetURL(
4322 "server-redirect?" + destination_url.spec()); 4448 "server-redirect?" + destination_url.spec());
4323 RedirectWithHeaderRemovalDelegate d; 4449 RedirectWithHeaderRemovalDelegate d;
4324 URLRequest req(original_url, &d, &default_context_); 4450 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_);
4325 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); 4451 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false);
4326 req.Start(); 4452 req.Start();
4327 base::RunLoop().Run(); 4453 base::RunLoop().Run();
4328 4454
4329 std::string value; 4455 std::string value;
4330 const HttpRequestHeaders& headers = req.extra_request_headers(); 4456 const HttpRequestHeaders& headers = req.extra_request_headers();
4331 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); 4457 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value));
4332 EXPECT_FALSE(req.is_pending()); 4458 EXPECT_FALSE(req.is_pending());
4333 EXPECT_FALSE(req.is_redirecting()); 4459 EXPECT_FALSE(req.is_redirecting());
4334 EXPECT_EQ("None", d.data_received()); 4460 EXPECT_EQ("None", d.data_received());
4335 } 4461 }
4336 4462
4337 TEST_F(URLRequestTestHTTP, CancelTest) { 4463 TEST_F(URLRequestTestHTTP, CancelTest) {
4338 TestDelegate d; 4464 TestDelegate d;
4339 { 4465 {
4340 URLRequest r(GURL("http://www.google.com/"), &d, &default_context_); 4466 URLRequest r(GURL("http://www.google.com/"),
4467 DEFAULT_PRIORITY,
4468 &d,
4469 &default_context_);
4341 4470
4342 r.Start(); 4471 r.Start();
4343 EXPECT_TRUE(r.is_pending()); 4472 EXPECT_TRUE(r.is_pending());
4344 4473
4345 r.Cancel(); 4474 r.Cancel();
4346 4475
4347 base::RunLoop().Run(); 4476 base::RunLoop().Run();
4348 4477
4349 // We expect to receive OnResponseStarted even though the request has been 4478 // We expect to receive OnResponseStarted even though the request has been
4350 // cancelled. 4479 // cancelled.
4351 EXPECT_EQ(1, d.response_started_count()); 4480 EXPECT_EQ(1, d.response_started_count());
4352 EXPECT_EQ(0, d.bytes_received()); 4481 EXPECT_EQ(0, d.bytes_received());
4353 EXPECT_FALSE(d.received_data_before_response()); 4482 EXPECT_FALSE(d.received_data_before_response());
4354 } 4483 }
4355 } 4484 }
4356 4485
4357 TEST_F(URLRequestTestHTTP, CancelTest2) { 4486 TEST_F(URLRequestTestHTTP, CancelTest2) {
4358 ASSERT_TRUE(test_server_.Start()); 4487 ASSERT_TRUE(test_server_.Start());
4359 4488
4360 TestDelegate d; 4489 TestDelegate d;
4361 { 4490 {
4362 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 4491 URLRequest r(test_server_.GetURL(std::string()),
4492 DEFAULT_PRIORITY,
4493 &d,
4494 &default_context_);
4363 4495
4364 d.set_cancel_in_response_started(true); 4496 d.set_cancel_in_response_started(true);
4365 4497
4366 r.Start(); 4498 r.Start();
4367 EXPECT_TRUE(r.is_pending()); 4499 EXPECT_TRUE(r.is_pending());
4368 4500
4369 base::RunLoop().Run(); 4501 base::RunLoop().Run();
4370 4502
4371 EXPECT_EQ(1, d.response_started_count()); 4503 EXPECT_EQ(1, d.response_started_count());
4372 EXPECT_EQ(0, d.bytes_received()); 4504 EXPECT_EQ(0, d.bytes_received());
4373 EXPECT_FALSE(d.received_data_before_response()); 4505 EXPECT_FALSE(d.received_data_before_response());
4374 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4506 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
4375 } 4507 }
4376 } 4508 }
4377 4509
4378 TEST_F(URLRequestTestHTTP, CancelTest3) { 4510 TEST_F(URLRequestTestHTTP, CancelTest3) {
4379 ASSERT_TRUE(test_server_.Start()); 4511 ASSERT_TRUE(test_server_.Start());
4380 4512
4381 TestDelegate d; 4513 TestDelegate d;
4382 { 4514 {
4383 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 4515 URLRequest r(test_server_.GetURL(std::string()),
4516 DEFAULT_PRIORITY,
4517 &d,
4518 &default_context_);
4384 4519
4385 d.set_cancel_in_received_data(true); 4520 d.set_cancel_in_received_data(true);
4386 4521
4387 r.Start(); 4522 r.Start();
4388 EXPECT_TRUE(r.is_pending()); 4523 EXPECT_TRUE(r.is_pending());
4389 4524
4390 base::RunLoop().Run(); 4525 base::RunLoop().Run();
4391 4526
4392 EXPECT_EQ(1, d.response_started_count()); 4527 EXPECT_EQ(1, d.response_started_count());
4393 // There is no guarantee about how much data was received 4528 // There is no guarantee about how much data was received
4394 // before the cancel was issued. It could have been 0 bytes, 4529 // before the cancel was issued. It could have been 0 bytes,
4395 // or it could have been all the bytes. 4530 // or it could have been all the bytes.
4396 // EXPECT_EQ(0, d.bytes_received()); 4531 // EXPECT_EQ(0, d.bytes_received());
4397 EXPECT_FALSE(d.received_data_before_response()); 4532 EXPECT_FALSE(d.received_data_before_response());
4398 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4533 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
4399 } 4534 }
4400 } 4535 }
4401 4536
4402 TEST_F(URLRequestTestHTTP, CancelTest4) { 4537 TEST_F(URLRequestTestHTTP, CancelTest4) {
4403 ASSERT_TRUE(test_server_.Start()); 4538 ASSERT_TRUE(test_server_.Start());
4404 4539
4405 TestDelegate d; 4540 TestDelegate d;
4406 { 4541 {
4407 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); 4542 URLRequest r(test_server_.GetURL(std::string()),
4543 DEFAULT_PRIORITY,
4544 &d,
4545 &default_context_);
4408 4546
4409 r.Start(); 4547 r.Start();
4410 EXPECT_TRUE(r.is_pending()); 4548 EXPECT_TRUE(r.is_pending());
4411 4549
4412 // The request will be implicitly canceled when it is destroyed. The 4550 // The request will be implicitly canceled when it is destroyed. The
4413 // test delegate must not post a quit message when this happens because 4551 // test delegate must not post a quit message when this happens because
4414 // this test doesn't actually have a message loop. The quit message would 4552 // this test doesn't actually have a message loop. The quit message would
4415 // get put on this thread's message queue and the next test would exit 4553 // get put on this thread's message queue and the next test would exit
4416 // early, causing problems. 4554 // early, causing problems.
4417 d.set_quit_on_complete(false); 4555 d.set_quit_on_complete(false);
4418 } 4556 }
4419 // expect things to just cleanup properly. 4557 // expect things to just cleanup properly.
4420 4558
4421 // we won't actually get a received reponse here because we've never run the 4559 // we won't actually get a received reponse here because we've never run the
4422 // message loop 4560 // message loop
4423 EXPECT_FALSE(d.received_data_before_response()); 4561 EXPECT_FALSE(d.received_data_before_response());
4424 EXPECT_EQ(0, d.bytes_received()); 4562 EXPECT_EQ(0, d.bytes_received());
4425 } 4563 }
4426 4564
4427 TEST_F(URLRequestTestHTTP, CancelTest5) { 4565 TEST_F(URLRequestTestHTTP, CancelTest5) {
4428 ASSERT_TRUE(test_server_.Start()); 4566 ASSERT_TRUE(test_server_.Start());
4429 4567
4430 // populate cache 4568 // populate cache
4431 { 4569 {
4432 TestDelegate d; 4570 TestDelegate d;
4433 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); 4571 URLRequest r(test_server_.GetURL("cachetime"),
4572 DEFAULT_PRIORITY,
4573 &d,
4574 &default_context_);
4434 r.Start(); 4575 r.Start();
4435 base::RunLoop().Run(); 4576 base::RunLoop().Run();
4436 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 4577 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
4437 } 4578 }
4438 4579
4439 // cancel read from cache (see bug 990242) 4580 // cancel read from cache (see bug 990242)
4440 { 4581 {
4441 TestDelegate d; 4582 TestDelegate d;
4442 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); 4583 URLRequest r(test_server_.GetURL("cachetime"),
4584 DEFAULT_PRIORITY,
4585 &d,
4586 &default_context_);
4443 r.Start(); 4587 r.Start();
4444 r.Cancel(); 4588 r.Cancel();
4445 base::RunLoop().Run(); 4589 base::RunLoop().Run();
4446 4590
4447 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 4591 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
4448 EXPECT_EQ(1, d.response_started_count()); 4592 EXPECT_EQ(1, d.response_started_count());
4449 EXPECT_EQ(0, d.bytes_received()); 4593 EXPECT_EQ(0, d.bytes_received());
4450 EXPECT_FALSE(d.received_data_before_response()); 4594 EXPECT_FALSE(d.received_data_before_response());
4451 } 4595 }
4452 } 4596 }
4453 4597
4454 TEST_F(URLRequestTestHTTP, PostTest) { 4598 TEST_F(URLRequestTestHTTP, PostTest) {
4455 ASSERT_TRUE(test_server_.Start()); 4599 ASSERT_TRUE(test_server_.Start());
4456 HTTPUploadDataOperationTest("POST"); 4600 HTTPUploadDataOperationTest("POST");
4457 } 4601 }
4458 4602
4459 TEST_F(URLRequestTestHTTP, PutTest) { 4603 TEST_F(URLRequestTestHTTP, PutTest) {
4460 ASSERT_TRUE(test_server_.Start()); 4604 ASSERT_TRUE(test_server_.Start());
4461 HTTPUploadDataOperationTest("PUT"); 4605 HTTPUploadDataOperationTest("PUT");
4462 } 4606 }
4463 4607
4464 TEST_F(URLRequestTestHTTP, PostEmptyTest) { 4608 TEST_F(URLRequestTestHTTP, PostEmptyTest) {
4465 ASSERT_TRUE(test_server_.Start()); 4609 ASSERT_TRUE(test_server_.Start());
4466 4610
4467 TestDelegate d; 4611 TestDelegate d;
4468 { 4612 {
4469 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 4613 URLRequest r(
4614 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4470 r.set_method("POST"); 4615 r.set_method("POST");
4471 4616
4472 r.Start(); 4617 r.Start();
4473 EXPECT_TRUE(r.is_pending()); 4618 EXPECT_TRUE(r.is_pending());
4474 4619
4475 base::RunLoop().Run(); 4620 base::RunLoop().Run();
4476 4621
4477 ASSERT_EQ(1, d.response_started_count()) 4622 ASSERT_EQ(1, d.response_started_count())
4478 << "request failed: " << r.status().status() 4623 << "request failed: " << r.status().status()
4479 << ", error: " << r.status().error(); 4624 << ", error: " << r.status().error();
4480 4625
4481 EXPECT_FALSE(d.received_data_before_response()); 4626 EXPECT_FALSE(d.received_data_before_response());
4482 EXPECT_TRUE(d.data_received().empty()); 4627 EXPECT_TRUE(d.data_received().empty());
4483 } 4628 }
4484 } 4629 }
4485 4630
4486 TEST_F(URLRequestTestHTTP, PostFileTest) { 4631 TEST_F(URLRequestTestHTTP, PostFileTest) {
4487 ASSERT_TRUE(test_server_.Start()); 4632 ASSERT_TRUE(test_server_.Start());
4488 4633
4489 TestDelegate d; 4634 TestDelegate d;
4490 { 4635 {
4491 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 4636 URLRequest r(
4637 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4492 r.set_method("POST"); 4638 r.set_method("POST");
4493 4639
4494 base::FilePath dir; 4640 base::FilePath dir;
4495 PathService::Get(base::DIR_EXE, &dir); 4641 PathService::Get(base::DIR_EXE, &dir);
4496 file_util::SetCurrentDirectory(dir); 4642 file_util::SetCurrentDirectory(dir);
4497 4643
4498 ScopedVector<UploadElementReader> element_readers; 4644 ScopedVector<UploadElementReader> element_readers;
4499 4645
4500 base::FilePath path; 4646 base::FilePath path;
4501 PathService::Get(base::DIR_SOURCE_ROOT, &path); 4647 PathService::Get(base::DIR_SOURCE_ROOT, &path);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4541 EXPECT_EQ(size, d.bytes_received()); 4687 EXPECT_EQ(size, d.bytes_received());
4542 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); 4688 EXPECT_EQ(std::string(&buf[0], size), d.data_received());
4543 } 4689 }
4544 } 4690 }
4545 4691
4546 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 4692 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
4547 ASSERT_TRUE(test_server_.Start()); 4693 ASSERT_TRUE(test_server_.Start());
4548 4694
4549 TestDelegate d; 4695 TestDelegate d;
4550 { 4696 {
4551 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 4697 URLRequest r(
4698 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4552 r.EnableChunkedUpload(); 4699 r.EnableChunkedUpload();
4553 r.set_method("POST"); 4700 r.set_method("POST");
4554 AddChunksToUpload(&r); 4701 AddChunksToUpload(&r);
4555 r.Start(); 4702 r.Start();
4556 EXPECT_TRUE(r.is_pending()); 4703 EXPECT_TRUE(r.is_pending());
4557 4704
4558 base::RunLoop().Run(); 4705 base::RunLoop().Run();
4559 4706
4560 VerifyReceivedDataMatchesChunks(&r, &d); 4707 VerifyReceivedDataMatchesChunks(&r, &d);
4561 } 4708 }
4562 } 4709 }
4563 4710
4564 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { 4711 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) {
4565 ASSERT_TRUE(test_server_.Start()); 4712 ASSERT_TRUE(test_server_.Start());
4566 4713
4567 TestDelegate d; 4714 TestDelegate d;
4568 { 4715 {
4569 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 4716 URLRequest r(
4717 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4570 r.EnableChunkedUpload(); 4718 r.EnableChunkedUpload();
4571 r.set_method("POST"); 4719 r.set_method("POST");
4572 r.Start(); 4720 r.Start();
4573 EXPECT_TRUE(r.is_pending()); 4721 EXPECT_TRUE(r.is_pending());
4574 AddChunksToUpload(&r); 4722 AddChunksToUpload(&r);
4575 base::RunLoop().Run(); 4723 base::RunLoop().Run();
4576 4724
4577 VerifyReceivedDataMatchesChunks(&r, &d); 4725 VerifyReceivedDataMatchesChunks(&r, &d);
4578 } 4726 }
4579 } 4727 }
4580 4728
4581 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { 4729 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
4582 ASSERT_TRUE(test_server_.Start()); 4730 ASSERT_TRUE(test_server_.Start());
4583 4731
4584 TestDelegate d; 4732 TestDelegate d;
4585 { 4733 {
4586 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 4734 URLRequest r(
4735 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_);
4587 r.EnableChunkedUpload(); 4736 r.EnableChunkedUpload();
4588 r.set_method("POST"); 4737 r.set_method("POST");
4589 r.Start(); 4738 r.Start();
4590 EXPECT_TRUE(r.is_pending()); 4739 EXPECT_TRUE(r.is_pending());
4591 4740
4592 base::RunLoop().RunUntilIdle(); 4741 base::RunLoop().RunUntilIdle();
4593 AddChunksToUpload(&r); 4742 AddChunksToUpload(&r);
4594 base::RunLoop().Run(); 4743 base::RunLoop().Run();
4595 4744
4596 VerifyReceivedDataMatchesChunks(&r, &d); 4745 VerifyReceivedDataMatchesChunks(&r, &d);
4597 } 4746 }
4598 } 4747 }
4599 4748
4600 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { 4749 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) {
4601 ASSERT_TRUE(test_server_.Start()); 4750 ASSERT_TRUE(test_server_.Start());
4602 4751
4603 TestDelegate d; 4752 TestDelegate d;
4604 URLRequest req( 4753 URLRequest req(test_server_.GetURL("files/with-headers.html"),
4605 test_server_.GetURL("files/with-headers.html"), &d, &default_context_); 4754 DEFAULT_PRIORITY,
4755 &d,
4756 &default_context_);
4606 req.Start(); 4757 req.Start();
4607 base::RunLoop().Run(); 4758 base::RunLoop().Run();
4608 4759
4609 const HttpResponseHeaders* headers = req.response_headers(); 4760 const HttpResponseHeaders* headers = req.response_headers();
4610 4761
4611 // Simple sanity check that response_info() accesses the same data. 4762 // Simple sanity check that response_info() accesses the same data.
4612 EXPECT_EQ(headers, req.response_info().headers.get()); 4763 EXPECT_EQ(headers, req.response_info().headers.get());
4613 4764
4614 std::string header; 4765 std::string header;
4615 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); 4766 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header));
(...skipping 12 matching lines...) Expand all
4628 4779
4629 TEST_F(URLRequestTestHTTP, ProcessSTS) { 4780 TEST_F(URLRequestTestHTTP, ProcessSTS) {
4630 SpawnedTestServer::SSLOptions ssl_options; 4781 SpawnedTestServer::SSLOptions ssl_options;
4631 SpawnedTestServer https_test_server( 4782 SpawnedTestServer https_test_server(
4632 SpawnedTestServer::TYPE_HTTPS, 4783 SpawnedTestServer::TYPE_HTTPS,
4633 ssl_options, 4784 ssl_options,
4634 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4785 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4635 ASSERT_TRUE(https_test_server.Start()); 4786 ASSERT_TRUE(https_test_server.Start());
4636 4787
4637 TestDelegate d; 4788 TestDelegate d;
4638 URLRequest request( 4789 URLRequest request(https_test_server.GetURL("files/hsts-headers.html"),
4639 https_test_server.GetURL("files/hsts-headers.html"), 4790 DEFAULT_PRIORITY,
4640 &d, 4791 &d,
4641 &default_context_); 4792 &default_context_);
4642 request.Start(); 4793 request.Start();
4643 base::RunLoop().Run(); 4794 base::RunLoop().Run();
4644 4795
4645 TransportSecurityState* security_state = 4796 TransportSecurityState* security_state =
4646 default_context_.transport_security_state(); 4797 default_context_.transport_security_state();
4647 bool sni_available = true; 4798 bool sni_available = true;
4648 TransportSecurityState::DomainState domain_state; 4799 TransportSecurityState::DomainState domain_state;
4649 EXPECT_TRUE(security_state->GetDomainState( 4800 EXPECT_TRUE(security_state->GetDomainState(
4650 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4801 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4651 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4802 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
(...skipping 20 matching lines...) Expand all
4672 // validity/expiration. 4823 // validity/expiration.
4673 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { 4824 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) {
4674 SpawnedTestServer::SSLOptions ssl_options; 4825 SpawnedTestServer::SSLOptions ssl_options;
4675 SpawnedTestServer https_test_server( 4826 SpawnedTestServer https_test_server(
4676 SpawnedTestServer::TYPE_HTTPS, 4827 SpawnedTestServer::TYPE_HTTPS,
4677 ssl_options, 4828 ssl_options,
4678 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4829 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4679 ASSERT_TRUE(https_test_server.Start()); 4830 ASSERT_TRUE(https_test_server.Start());
4680 4831
4681 TestDelegate d; 4832 TestDelegate d;
4682 URLRequest request( 4833 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"),
4683 https_test_server.GetURL("files/hpkp-headers.html"), 4834 DEFAULT_PRIORITY,
4684 &d, 4835 &d,
4685 &default_context_); 4836 &default_context_);
4686 request.Start(); 4837 request.Start();
4687 base::RunLoop().Run(); 4838 base::RunLoop().Run();
4688 4839
4689 TransportSecurityState* security_state = 4840 TransportSecurityState* security_state =
4690 default_context_.transport_security_state(); 4841 default_context_.transport_security_state();
4691 bool sni_available = true; 4842 bool sni_available = true;
4692 TransportSecurityState::DomainState domain_state; 4843 TransportSecurityState::DomainState domain_state;
4693 EXPECT_TRUE(security_state->GetDomainState( 4844 EXPECT_TRUE(security_state->GetDomainState(
4694 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4845 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4695 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 4846 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
4696 domain_state.upgrade_mode); 4847 domain_state.upgrade_mode);
4697 EXPECT_FALSE(domain_state.sts_include_subdomains); 4848 EXPECT_FALSE(domain_state.sts_include_subdomains);
4698 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4849 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4699 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4850 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4700 EXPECT_NE(domain_state.upgrade_expiry, 4851 EXPECT_NE(domain_state.upgrade_expiry,
4701 domain_state.dynamic_spki_hashes_expiry); 4852 domain_state.dynamic_spki_hashes_expiry);
4702 } 4853 }
4703 4854
4704 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 4855 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
4705 SpawnedTestServer::SSLOptions ssl_options; 4856 SpawnedTestServer::SSLOptions ssl_options;
4706 SpawnedTestServer https_test_server( 4857 SpawnedTestServer https_test_server(
4707 SpawnedTestServer::TYPE_HTTPS, 4858 SpawnedTestServer::TYPE_HTTPS,
4708 ssl_options, 4859 ssl_options,
4709 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4860 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4710 ASSERT_TRUE(https_test_server.Start()); 4861 ASSERT_TRUE(https_test_server.Start());
4711 4862
4712 TestDelegate d; 4863 TestDelegate d;
4713 URLRequest request( 4864 URLRequest request(
4714 https_test_server.GetURL("files/hsts-multiple-headers.html"), 4865 https_test_server.GetURL("files/hsts-multiple-headers.html"),
4866 DEFAULT_PRIORITY,
4715 &d, 4867 &d,
4716 &default_context_); 4868 &default_context_);
4717 request.Start(); 4869 request.Start();
4718 base::RunLoop().Run(); 4870 base::RunLoop().Run();
4719 4871
4720 // We should have set parameters from the first header, not the second. 4872 // We should have set parameters from the first header, not the second.
4721 TransportSecurityState* security_state = 4873 TransportSecurityState* security_state =
4722 default_context_.transport_security_state(); 4874 default_context_.transport_security_state();
4723 bool sni_available = true; 4875 bool sni_available = true;
4724 TransportSecurityState::DomainState domain_state; 4876 TransportSecurityState::DomainState domain_state;
4725 EXPECT_TRUE(security_state->GetDomainState( 4877 EXPECT_TRUE(security_state->GetDomainState(
4726 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4878 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4727 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4879 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4728 domain_state.upgrade_mode); 4880 domain_state.upgrade_mode);
4729 EXPECT_FALSE(domain_state.sts_include_subdomains); 4881 EXPECT_FALSE(domain_state.sts_include_subdomains);
4730 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4882 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4731 } 4883 }
4732 4884
4733 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 4885 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
4734 SpawnedTestServer::SSLOptions ssl_options; 4886 SpawnedTestServer::SSLOptions ssl_options;
4735 SpawnedTestServer https_test_server( 4887 SpawnedTestServer https_test_server(
4736 SpawnedTestServer::TYPE_HTTPS, 4888 SpawnedTestServer::TYPE_HTTPS,
4737 ssl_options, 4889 ssl_options,
4738 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4890 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4739 ASSERT_TRUE(https_test_server.Start()); 4891 ASSERT_TRUE(https_test_server.Start());
4740 4892
4741 TestDelegate d; 4893 TestDelegate d;
4742 URLRequest request( 4894 URLRequest request(
4743 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 4895 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
4896 DEFAULT_PRIORITY,
4744 &d, 4897 &d,
4745 &default_context_); 4898 &default_context_);
4746 request.Start(); 4899 request.Start();
4747 base::RunLoop().Run(); 4900 base::RunLoop().Run();
4748 4901
4749 // We should have set parameters from the first header, not the second. 4902 // We should have set parameters from the first header, not the second.
4750 TransportSecurityState* security_state = 4903 TransportSecurityState* security_state =
4751 default_context_.transport_security_state(); 4904 default_context_.transport_security_state();
4752 bool sni_available = true; 4905 bool sni_available = true;
4753 TransportSecurityState::DomainState domain_state; 4906 TransportSecurityState::DomainState domain_state;
(...skipping 22 matching lines...) Expand all
4776 SpawnedTestServer::SSLOptions ssl_options; 4929 SpawnedTestServer::SSLOptions ssl_options;
4777 SpawnedTestServer https_test_server( 4930 SpawnedTestServer https_test_server(
4778 SpawnedTestServer::TYPE_HTTPS, 4931 SpawnedTestServer::TYPE_HTTPS,
4779 ssl_options, 4932 ssl_options,
4780 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 4933 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
4781 ASSERT_TRUE(https_test_server.Start()); 4934 ASSERT_TRUE(https_test_server.Start());
4782 4935
4783 TestDelegate d; 4936 TestDelegate d;
4784 URLRequest request( 4937 URLRequest request(
4785 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), 4938 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"),
4939 DEFAULT_PRIORITY,
4786 &d, 4940 &d,
4787 &default_context_); 4941 &default_context_);
4788 request.Start(); 4942 request.Start();
4789 base::RunLoop().Run(); 4943 base::RunLoop().Run();
4790 4944
4791 TransportSecurityState* security_state = 4945 TransportSecurityState* security_state =
4792 default_context_.transport_security_state(); 4946 default_context_.transport_security_state();
4793 bool sni_available = true; 4947 bool sni_available = true;
4794 TransportSecurityState::DomainState domain_state; 4948 TransportSecurityState::DomainState domain_state;
4795 EXPECT_TRUE(security_state->GetDomainState( 4949 EXPECT_TRUE(security_state->GetDomainState(
4796 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); 4950 SpawnedTestServer::kLocalhost, sni_available, &domain_state));
4797 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 4951 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
4798 domain_state.upgrade_mode); 4952 domain_state.upgrade_mode);
4799 #if defined(OS_ANDROID) 4953 #if defined(OS_ANDROID)
4800 // Android's CertVerifyProc does not (yet) handle pins. 4954 // Android's CertVerifyProc does not (yet) handle pins.
4801 #else 4955 #else
4802 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 4956 EXPECT_TRUE(domain_state.HasPublicKeyPins());
4803 #endif 4957 #endif
4804 EXPECT_NE(domain_state.upgrade_expiry, 4958 EXPECT_NE(domain_state.upgrade_expiry,
4805 domain_state.dynamic_spki_hashes_expiry); 4959 domain_state.dynamic_spki_hashes_expiry);
4806 4960
4807 EXPECT_TRUE(domain_state.sts_include_subdomains); 4961 EXPECT_TRUE(domain_state.sts_include_subdomains);
4808 EXPECT_FALSE(domain_state.pkp_include_subdomains); 4962 EXPECT_FALSE(domain_state.pkp_include_subdomains);
4809 } 4963 }
4810 4964
4811 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { 4965 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
4812 ASSERT_TRUE(test_server_.Start()); 4966 ASSERT_TRUE(test_server_.Start());
4813 4967
4814 TestDelegate d; 4968 TestDelegate d;
4815 URLRequest req(test_server_.GetURL( 4969 URLRequest req(test_server_.GetURL("files/content-type-normalization.html"),
4816 "files/content-type-normalization.html"), &d, &default_context_); 4970 DEFAULT_PRIORITY,
4971 &d,
4972 &default_context_);
4817 req.Start(); 4973 req.Start();
4818 base::RunLoop().Run(); 4974 base::RunLoop().Run();
4819 4975
4820 std::string mime_type; 4976 std::string mime_type;
4821 req.GetMimeType(&mime_type); 4977 req.GetMimeType(&mime_type);
4822 EXPECT_EQ("text/html", mime_type); 4978 EXPECT_EQ("text/html", mime_type);
4823 4979
4824 std::string charset; 4980 std::string charset;
4825 req.GetCharset(&charset); 4981 req.GetCharset(&charset);
4826 EXPECT_EQ("utf-8", charset); 4982 EXPECT_EQ("utf-8", charset);
(...skipping 11 matching lines...) Expand all
4838 4994
4839 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 4995 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
4840 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); 4996 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url));
4841 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); 4997 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url));
4842 } 4998 }
4843 4999
4844 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 5000 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
4845 ASSERT_TRUE(test_server_.Start()); 5001 ASSERT_TRUE(test_server_.Start());
4846 5002
4847 TestDelegate d; 5003 TestDelegate d;
4848 URLRequest req(test_server_.GetURL( 5004 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"),
4849 "files/redirect-to-file.html"), &d, &default_context_); 5005 DEFAULT_PRIORITY,
5006 &d,
5007 &default_context_);
4850 req.Start(); 5008 req.Start();
4851 base::RunLoop().Run(); 5009 base::RunLoop().Run();
4852 5010
4853 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5011 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
4854 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 5012 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error());
4855 } 5013 }
4856 5014
4857 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 5015 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
4858 ASSERT_TRUE(test_server_.Start()); 5016 ASSERT_TRUE(test_server_.Start());
4859 5017
4860 TestDelegate d; 5018 TestDelegate d;
4861 URLRequest req(test_server_.GetURL( 5019 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"),
4862 "files/redirect-to-data.html"), &d, &default_context_); 5020 DEFAULT_PRIORITY,
5021 &d,
5022 &default_context_);
4863 req.Start(); 5023 req.Start();
4864 base::MessageLoop::current()->Run(); 5024 base::MessageLoop::current()->Run();
4865 5025
4866 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5026 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
4867 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 5027 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error());
4868 } 5028 }
4869 5029
4870 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 5030 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
4871 ASSERT_TRUE(test_server_.Start()); 5031 ASSERT_TRUE(test_server_.Start());
4872 5032
4873 TestDelegate d; 5033 TestDelegate d;
4874 URLRequest req(test_server_.GetURL( 5034 URLRequest req(test_server_.GetURL("files/redirect-to-invalid-url.html"),
4875 "files/redirect-to-invalid-url.html"), &d, &default_context_); 5035 DEFAULT_PRIORITY,
5036 &d,
5037 &default_context_);
4876 req.Start(); 5038 req.Start();
4877 base::RunLoop().Run(); 5039 base::RunLoop().Run();
4878 5040
4879 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 5041 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
4880 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); 5042 EXPECT_EQ(ERR_INVALID_URL, req.status().error());
4881 } 5043 }
4882 5044
4883 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { 5045 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) {
4884 ASSERT_TRUE(test_server_.Start()); 5046 ASSERT_TRUE(test_server_.Start());
4885 5047
4886 TestDelegate d; 5048 TestDelegate d;
4887 URLRequest req( 5049 URLRequest req(test_server_.GetURL("echoheader?Referer"),
4888 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); 5050 DEFAULT_PRIORITY,
5051 &d,
5052 &default_context_);
4889 req.SetReferrer("http://user:pass@foo.com/"); 5053 req.SetReferrer("http://user:pass@foo.com/");
4890 req.Start(); 5054 req.Start();
4891 base::RunLoop().Run(); 5055 base::RunLoop().Run();
4892 5056
4893 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); 5057 EXPECT_EQ(std::string("http://foo.com/"), d.data_received());
4894 } 5058 }
4895 5059
4896 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { 5060 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) {
4897 ASSERT_TRUE(test_server_.Start()); 5061 ASSERT_TRUE(test_server_.Start());
4898 5062
4899 TestDelegate d; 5063 TestDelegate d;
4900 URLRequest req( 5064 URLRequest req(test_server_.GetURL("echoheader?Referer"),
4901 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); 5065 DEFAULT_PRIORITY,
5066 &d,
5067 &default_context_);
4902 req.SetReferrer("http://foo.com/test#fragment"); 5068 req.SetReferrer("http://foo.com/test#fragment");
4903 req.Start(); 5069 req.Start();
4904 base::RunLoop().Run(); 5070 base::RunLoop().Run();
4905 5071
4906 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); 5072 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received());
4907 } 5073 }
4908 5074
4909 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { 5075 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) {
4910 ASSERT_TRUE(test_server_.Start()); 5076 ASSERT_TRUE(test_server_.Start());
4911 5077
4912 TestDelegate d; 5078 TestDelegate d;
4913 URLRequest req( 5079 URLRequest req(test_server_.GetURL("echoheader?Referer"),
4914 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); 5080 DEFAULT_PRIORITY,
5081 &d,
5082 &default_context_);
4915 req.SetReferrer("http://foo.com/test#fragment"); 5083 req.SetReferrer("http://foo.com/test#fragment");
4916 req.SetReferrer(""); 5084 req.SetReferrer("");
4917 req.Start(); 5085 req.Start();
4918 base::RunLoop().Run(); 5086 base::RunLoop().Run();
4919 5087
4920 EXPECT_EQ(std::string("None"), d.data_received()); 5088 EXPECT_EQ(std::string("None"), d.data_received());
4921 } 5089 }
4922 5090
4923 TEST_F(URLRequestTestHTTP, CancelRedirect) { 5091 TEST_F(URLRequestTestHTTP, CancelRedirect) {
4924 ASSERT_TRUE(test_server_.Start()); 5092 ASSERT_TRUE(test_server_.Start());
4925 5093
4926 TestDelegate d; 5094 TestDelegate d;
4927 { 5095 {
4928 d.set_cancel_in_received_redirect(true); 5096 d.set_cancel_in_received_redirect(true);
4929 URLRequest req( 5097 URLRequest req(test_server_.GetURL("files/redirect-test.html"),
4930 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); 5098 DEFAULT_PRIORITY,
5099 &d,
5100 &default_context_);
4931 req.Start(); 5101 req.Start();
4932 base::RunLoop().Run(); 5102 base::RunLoop().Run();
4933 5103
4934 EXPECT_EQ(1, d.response_started_count()); 5104 EXPECT_EQ(1, d.response_started_count());
4935 EXPECT_EQ(0, d.bytes_received()); 5105 EXPECT_EQ(0, d.bytes_received());
4936 EXPECT_FALSE(d.received_data_before_response()); 5106 EXPECT_FALSE(d.received_data_before_response());
4937 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 5107 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
4938 } 5108 }
4939 } 5109 }
4940 5110
4941 TEST_F(URLRequestTestHTTP, DeferredRedirect) { 5111 TEST_F(URLRequestTestHTTP, DeferredRedirect) {
4942 ASSERT_TRUE(test_server_.Start()); 5112 ASSERT_TRUE(test_server_.Start());
4943 5113
4944 TestDelegate d; 5114 TestDelegate d;
4945 { 5115 {
4946 d.set_quit_on_redirect(true); 5116 d.set_quit_on_redirect(true);
4947 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5117 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4948 URLRequest req(test_url, &d, &default_context_); 5118 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_);
4949 5119
4950 req.Start(); 5120 req.Start();
4951 base::RunLoop().Run(); 5121 base::RunLoop().Run();
4952 5122
4953 EXPECT_EQ(1, d.received_redirect_count()); 5123 EXPECT_EQ(1, d.received_redirect_count());
4954 5124
4955 req.FollowDeferredRedirect(); 5125 req.FollowDeferredRedirect();
4956 base::RunLoop().Run(); 5126 base::RunLoop().Run();
4957 5127
4958 EXPECT_EQ(1, d.response_started_count()); 5128 EXPECT_EQ(1, d.response_started_count());
(...skipping 13 matching lines...) Expand all
4972 } 5142 }
4973 } 5143 }
4974 5144
4975 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { 5145 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) {
4976 ASSERT_TRUE(test_server_.Start()); 5146 ASSERT_TRUE(test_server_.Start());
4977 5147
4978 TestDelegate d; 5148 TestDelegate d;
4979 { 5149 {
4980 d.set_quit_on_redirect(true); 5150 d.set_quit_on_redirect(true);
4981 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5151 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
4982 URLRequest req(test_url, &d, &default_context_); 5152 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_);
4983 5153
4984 EXPECT_FALSE(d.have_full_request_headers()); 5154 EXPECT_FALSE(d.have_full_request_headers());
4985 5155
4986 req.Start(); 5156 req.Start();
4987 base::RunLoop().Run(); 5157 base::RunLoop().Run();
4988 5158
4989 EXPECT_EQ(1, d.received_redirect_count()); 5159 EXPECT_EQ(1, d.received_redirect_count());
4990 EXPECT_TRUE(d.have_full_request_headers()); 5160 EXPECT_TRUE(d.have_full_request_headers());
4991 CheckFullRequestHeaders(d.full_request_headers(), test_url); 5161 CheckFullRequestHeaders(d.full_request_headers(), test_url);
4992 d.ClearFullRequestHeaders(); 5162 d.ClearFullRequestHeaders();
(...skipping 20 matching lines...) Expand all
5013 EXPECT_EQ(contents, d.data_received()); 5183 EXPECT_EQ(contents, d.data_received());
5014 } 5184 }
5015 } 5185 }
5016 5186
5017 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { 5187 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) {
5018 ASSERT_TRUE(test_server_.Start()); 5188 ASSERT_TRUE(test_server_.Start());
5019 5189
5020 TestDelegate d; 5190 TestDelegate d;
5021 { 5191 {
5022 d.set_quit_on_redirect(true); 5192 d.set_quit_on_redirect(true);
5023 URLRequest req( 5193 URLRequest req(test_server_.GetURL("files/redirect-test.html"),
5024 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); 5194 DEFAULT_PRIORITY,
5195 &d,
5196 &default_context_);
5025 req.Start(); 5197 req.Start();
5026 base::RunLoop().Run(); 5198 base::RunLoop().Run();
5027 5199
5028 EXPECT_EQ(1, d.received_redirect_count()); 5200 EXPECT_EQ(1, d.received_redirect_count());
5029 5201
5030 req.Cancel(); 5202 req.Cancel();
5031 base::RunLoop().Run(); 5203 base::RunLoop().Run();
5032 5204
5033 EXPECT_EQ(1, d.response_started_count()); 5205 EXPECT_EQ(1, d.response_started_count());
5034 EXPECT_EQ(0, d.bytes_received()); 5206 EXPECT_EQ(0, d.bytes_received());
5035 EXPECT_FALSE(d.received_data_before_response()); 5207 EXPECT_FALSE(d.received_data_before_response());
5036 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 5208 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
5037 } 5209 }
5038 } 5210 }
5039 5211
5040 TEST_F(URLRequestTestHTTP, VaryHeader) { 5212 TEST_F(URLRequestTestHTTP, VaryHeader) {
5041 ASSERT_TRUE(test_server_.Start()); 5213 ASSERT_TRUE(test_server_.Start());
5042 5214
5043 // Populate the cache. 5215 // Populate the cache.
5044 { 5216 {
5045 TestDelegate d; 5217 TestDelegate d;
5046 URLRequest req( 5218 URLRequest req(test_server_.GetURL("echoheadercache?foo"),
5047 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 5219 DEFAULT_PRIORITY,
5220 &d,
5221 &default_context_);
5048 HttpRequestHeaders headers; 5222 HttpRequestHeaders headers;
5049 headers.SetHeader("foo", "1"); 5223 headers.SetHeader("foo", "1");
5050 req.SetExtraRequestHeaders(headers); 5224 req.SetExtraRequestHeaders(headers);
5051 req.Start(); 5225 req.Start();
5052 base::RunLoop().Run(); 5226 base::RunLoop().Run();
5053 5227
5054 LoadTimingInfo load_timing_info; 5228 LoadTimingInfo load_timing_info;
5055 req.GetLoadTimingInfo(&load_timing_info); 5229 req.GetLoadTimingInfo(&load_timing_info);
5056 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5230 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5057 } 5231 }
5058 5232
5059 // Expect a cache hit. 5233 // Expect a cache hit.
5060 { 5234 {
5061 TestDelegate d; 5235 TestDelegate d;
5062 URLRequest req( 5236 URLRequest req(test_server_.GetURL("echoheadercache?foo"),
5063 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 5237 DEFAULT_PRIORITY,
5238 &d,
5239 &default_context_);
5064 HttpRequestHeaders headers; 5240 HttpRequestHeaders headers;
5065 headers.SetHeader("foo", "1"); 5241 headers.SetHeader("foo", "1");
5066 req.SetExtraRequestHeaders(headers); 5242 req.SetExtraRequestHeaders(headers);
5067 req.Start(); 5243 req.Start();
5068 base::RunLoop().Run(); 5244 base::RunLoop().Run();
5069 5245
5070 EXPECT_TRUE(req.was_cached()); 5246 EXPECT_TRUE(req.was_cached());
5071 5247
5072 LoadTimingInfo load_timing_info; 5248 LoadTimingInfo load_timing_info;
5073 req.GetLoadTimingInfo(&load_timing_info); 5249 req.GetLoadTimingInfo(&load_timing_info);
5074 TestLoadTimingCacheHitNoNetwork(load_timing_info); 5250 TestLoadTimingCacheHitNoNetwork(load_timing_info);
5075 } 5251 }
5076 5252
5077 // Expect a cache miss. 5253 // Expect a cache miss.
5078 { 5254 {
5079 TestDelegate d; 5255 TestDelegate d;
5080 URLRequest req( 5256 URLRequest req(test_server_.GetURL("echoheadercache?foo"),
5081 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); 5257 DEFAULT_PRIORITY,
5258 &d,
5259 &default_context_);
5082 HttpRequestHeaders headers; 5260 HttpRequestHeaders headers;
5083 headers.SetHeader("foo", "2"); 5261 headers.SetHeader("foo", "2");
5084 req.SetExtraRequestHeaders(headers); 5262 req.SetExtraRequestHeaders(headers);
5085 req.Start(); 5263 req.Start();
5086 base::RunLoop().Run(); 5264 base::RunLoop().Run();
5087 5265
5088 EXPECT_FALSE(req.was_cached()); 5266 EXPECT_FALSE(req.was_cached());
5089 5267
5090 LoadTimingInfo load_timing_info; 5268 LoadTimingInfo load_timing_info;
5091 req.GetLoadTimingInfo(&load_timing_info); 5269 req.GetLoadTimingInfo(&load_timing_info);
5092 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5270 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5093 } 5271 }
5094 } 5272 }
5095 5273
5096 TEST_F(URLRequestTestHTTP, BasicAuth) { 5274 TEST_F(URLRequestTestHTTP, BasicAuth) {
5097 ASSERT_TRUE(test_server_.Start()); 5275 ASSERT_TRUE(test_server_.Start());
5098 5276
5099 // populate the cache 5277 // populate the cache
5100 { 5278 {
5101 TestDelegate d; 5279 TestDelegate d;
5102 d.set_credentials(AuthCredentials(kUser, kSecret)); 5280 d.set_credentials(AuthCredentials(kUser, kSecret));
5103 5281
5104 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); 5282 URLRequest r(test_server_.GetURL("auth-basic"),
5283 DEFAULT_PRIORITY,
5284 &d,
5285 &default_context_);
5105 r.Start(); 5286 r.Start();
5106 5287
5107 base::RunLoop().Run(); 5288 base::RunLoop().Run();
5108 5289
5109 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5290 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5110 } 5291 }
5111 5292
5112 // repeat request with end-to-end validation. since auth-basic results in a 5293 // repeat request with end-to-end validation. since auth-basic results in a
5113 // cachable page, we expect this test to result in a 304. in which case, the 5294 // cachable page, we expect this test to result in a 304. in which case, the
5114 // response should be fetched from the cache. 5295 // response should be fetched from the cache.
5115 { 5296 {
5116 TestDelegate d; 5297 TestDelegate d;
5117 d.set_credentials(AuthCredentials(kUser, kSecret)); 5298 d.set_credentials(AuthCredentials(kUser, kSecret));
5118 5299
5119 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); 5300 URLRequest r(test_server_.GetURL("auth-basic"),
5301 DEFAULT_PRIORITY,
5302 &d,
5303 &default_context_);
5120 r.set_load_flags(LOAD_VALIDATE_CACHE); 5304 r.set_load_flags(LOAD_VALIDATE_CACHE);
5121 r.Start(); 5305 r.Start();
5122 5306
5123 base::RunLoop().Run(); 5307 base::RunLoop().Run();
5124 5308
5125 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5309 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5126 5310
5127 // Should be the same cached document. 5311 // Should be the same cached document.
5128 EXPECT_TRUE(r.was_cached()); 5312 EXPECT_TRUE(r.was_cached());
5129 } 5313 }
(...skipping 11 matching lines...) Expand all
5141 // Verify that when the transaction is restarted, it includes the new cookie. 5325 // Verify that when the transaction is restarted, it includes the new cookie.
5142 { 5326 {
5143 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5327 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5144 TestURLRequestContext context(true); 5328 TestURLRequestContext context(true);
5145 context.set_network_delegate(&network_delegate); 5329 context.set_network_delegate(&network_delegate);
5146 context.Init(); 5330 context.Init();
5147 5331
5148 TestDelegate d; 5332 TestDelegate d;
5149 d.set_credentials(AuthCredentials(kUser, kSecret)); 5333 d.set_credentials(AuthCredentials(kUser, kSecret));
5150 5334
5151 URLRequest r(url_requiring_auth, &d, &context); 5335 URLRequest r(url_requiring_auth, DEFAULT_PRIORITY, &d, &context);
5152 r.Start(); 5336 r.Start();
5153 5337
5154 base::RunLoop().Run(); 5338 base::RunLoop().Run();
5155 5339
5156 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5340 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5157 5341
5158 // Make sure we sent the cookie in the restarted transaction. 5342 // Make sure we sent the cookie in the restarted transaction.
5159 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 5343 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
5160 != std::string::npos); 5344 != std::string::npos);
5161 } 5345 }
5162 5346
5163 // Same test as above, except this time the restart is initiated earlier 5347 // Same test as above, except this time the restart is initiated earlier
5164 // (without user intervention since identity is embedded in the URL). 5348 // (without user intervention since identity is embedded in the URL).
5165 { 5349 {
5166 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 5350 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
5167 TestURLRequestContext context(true); 5351 TestURLRequestContext context(true);
5168 context.set_network_delegate(&network_delegate); 5352 context.set_network_delegate(&network_delegate);
5169 context.Init(); 5353 context.Init();
5170 5354
5171 TestDelegate d; 5355 TestDelegate d;
5172 5356
5173 GURL::Replacements replacements; 5357 GURL::Replacements replacements;
5174 std::string username("user2"); 5358 std::string username("user2");
5175 std::string password("secret"); 5359 std::string password("secret");
5176 replacements.SetUsernameStr(username); 5360 replacements.SetUsernameStr(username);
5177 replacements.SetPasswordStr(password); 5361 replacements.SetPasswordStr(password);
5178 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); 5362 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements);
5179 5363
5180 URLRequest r(url_with_identity, &d, &context); 5364 URLRequest r(url_with_identity, DEFAULT_PRIORITY, &d, &context);
5181 r.Start(); 5365 r.Start();
5182 5366
5183 base::RunLoop().Run(); 5367 base::RunLoop().Run();
5184 5368
5185 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); 5369 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos);
5186 5370
5187 // Make sure we sent the cookie in the restarted transaction. 5371 // Make sure we sent the cookie in the restarted transaction.
5188 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 5372 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
5189 != std::string::npos); 5373 != std::string::npos);
5190 } 5374 }
5191 } 5375 }
5192 5376
5193 // Tests that load timing works as expected with auth and the cache. 5377 // Tests that load timing works as expected with auth and the cache.
5194 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { 5378 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) {
5195 ASSERT_TRUE(test_server_.Start()); 5379 ASSERT_TRUE(test_server_.Start());
5196 5380
5197 // populate the cache 5381 // populate the cache
5198 { 5382 {
5199 TestDelegate d; 5383 TestDelegate d;
5200 d.set_credentials(AuthCredentials(kUser, kSecret)); 5384 d.set_credentials(AuthCredentials(kUser, kSecret));
5201 5385
5202 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); 5386 URLRequest r(test_server_.GetURL("auth-basic"),
5387 DEFAULT_PRIORITY,
5388 &d,
5389 &default_context_);
5203 r.Start(); 5390 r.Start();
5204 5391
5205 base::RunLoop().Run(); 5392 base::RunLoop().Run();
5206 5393
5207 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5394 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5208 5395
5209 LoadTimingInfo load_timing_info_before_auth; 5396 LoadTimingInfo load_timing_info_before_auth;
5210 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( 5397 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth(
5211 &load_timing_info_before_auth)); 5398 &load_timing_info_before_auth));
5212 TestLoadTimingNotReused(load_timing_info_before_auth, 5399 TestLoadTimingNotReused(load_timing_info_before_auth,
(...skipping 10 matching lines...) Expand all
5223 load_timing_info.connect_timing.connect_start); 5410 load_timing_info.connect_timing.connect_start);
5224 } 5411 }
5225 5412
5226 // Repeat request with end-to-end validation. Since auth-basic results in a 5413 // Repeat request with end-to-end validation. Since auth-basic results in a
5227 // cachable page, we expect this test to result in a 304. In which case, the 5414 // cachable page, we expect this test to result in a 304. In which case, the
5228 // response should be fetched from the cache. 5415 // response should be fetched from the cache.
5229 { 5416 {
5230 TestDelegate d; 5417 TestDelegate d;
5231 d.set_credentials(AuthCredentials(kUser, kSecret)); 5418 d.set_credentials(AuthCredentials(kUser, kSecret));
5232 5419
5233 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); 5420 URLRequest r(test_server_.GetURL("auth-basic"),
5421 DEFAULT_PRIORITY,
5422 &d,
5423 &default_context_);
5234 r.set_load_flags(LOAD_VALIDATE_CACHE); 5424 r.set_load_flags(LOAD_VALIDATE_CACHE);
5235 r.Start(); 5425 r.Start();
5236 5426
5237 base::RunLoop().Run(); 5427 base::RunLoop().Run();
5238 5428
5239 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 5429 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
5240 5430
5241 // Should be the same cached document. 5431 // Should be the same cached document.
5242 EXPECT_TRUE(r.was_cached()); 5432 EXPECT_TRUE(r.was_cached());
5243 5433
5244 // Since there was a request that went over the wire, the load timing 5434 // Since there was a request that went over the wire, the load timing
5245 // information should include connection times. 5435 // information should include connection times.
5246 LoadTimingInfo load_timing_info; 5436 LoadTimingInfo load_timing_info;
5247 r.GetLoadTimingInfo(&load_timing_info); 5437 r.GetLoadTimingInfo(&load_timing_info);
5248 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5438 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5249 } 5439 }
5250 } 5440 }
5251 5441
5252 // In this test, we do a POST which the server will 302 redirect. 5442 // In this test, we do a POST which the server will 302 redirect.
5253 // The subsequent transaction should use GET, and should not send the 5443 // The subsequent transaction should use GET, and should not send the
5254 // Content-Type header. 5444 // Content-Type header.
5255 // http://code.google.com/p/chromium/issues/detail?id=843 5445 // http://code.google.com/p/chromium/issues/detail?id=843
5256 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 5446 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
5257 ASSERT_TRUE(test_server_.Start()); 5447 ASSERT_TRUE(test_server_.Start());
5258 5448
5259 const char kData[] = "hello world"; 5449 const char kData[] = "hello world";
5260 5450
5261 TestDelegate d; 5451 TestDelegate d;
5262 URLRequest req( 5452 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"),
5263 test_server_.GetURL("files/redirect-to-echoall"), &d, &default_context_); 5453 DEFAULT_PRIORITY,
5454 &d,
5455 &default_context_);
5264 req.set_method("POST"); 5456 req.set_method("POST");
5265 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 5457 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
5266 5458
5267 // Set headers (some of which are specific to the POST). 5459 // Set headers (some of which are specific to the POST).
5268 HttpRequestHeaders headers; 5460 HttpRequestHeaders headers;
5269 headers.AddHeadersFromString( 5461 headers.AddHeadersFromString(
5270 "Content-Type: multipart/form-data; " 5462 "Content-Type: multipart/form-data; "
5271 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" 5463 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
5272 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," 5464 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
5273 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" 5465 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5339 HTTPRedirectMethodTest(url, "PUT", "PUT", true); 5531 HTTPRedirectMethodTest(url, "PUT", "PUT", true);
5340 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); 5532 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
5341 } 5533 }
5342 5534
5343 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 5535 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
5344 ASSERT_TRUE(test_server_.Start()); 5536 ASSERT_TRUE(test_server_.Start());
5345 5537
5346 const char kData[] = "hello world"; 5538 const char kData[] = "hello world";
5347 5539
5348 TestDelegate d; 5540 TestDelegate d;
5349 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); 5541 URLRequest req(test_server_.GetURL("empty.html"),
5542 DEFAULT_PRIORITY,
5543 &d,
5544 &default_context_);
5350 req.set_method("POST"); 5545 req.set_method("POST");
5351 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 5546 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
5352 HttpRequestHeaders headers; 5547 HttpRequestHeaders headers;
5353 headers.SetHeader(HttpRequestHeaders::kContentLength, 5548 headers.SetHeader(HttpRequestHeaders::kContentLength,
5354 base::UintToString(arraysize(kData) - 1)); 5549 base::UintToString(arraysize(kData) - 1));
5355 req.SetExtraRequestHeaders(headers); 5550 req.SetExtraRequestHeaders(headers);
5356 5551
5357 URLRequestRedirectJob* job = new URLRequestRedirectJob( 5552 URLRequestRedirectJob* job = new URLRequestRedirectJob(
5358 &req, &default_network_delegate_, test_server_.GetURL("echo"), 5553 &req, &default_network_delegate_, test_server_.GetURL("echo"),
5359 URLRequestRedirectJob::REDIRECT_302_FOUND); 5554 URLRequestRedirectJob::REDIRECT_302_FOUND);
5360 AddTestInterceptor()->set_main_intercept_job(job); 5555 AddTestInterceptor()->set_main_intercept_job(job);
5361 5556
5362 req.Start(); 5557 req.Start();
5363 base::RunLoop().Run(); 5558 base::RunLoop().Run();
5364 EXPECT_EQ("GET", req.method()); 5559 EXPECT_EQ("GET", req.method());
5365 } 5560 }
5366 5561
5367 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 5562 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
5368 ASSERT_TRUE(test_server_.Start()); 5563 ASSERT_TRUE(test_server_.Start());
5369 5564
5370 const char kData[] = "hello world"; 5565 const char kData[] = "hello world";
5371 5566
5372 TestDelegate d; 5567 TestDelegate d;
5373 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); 5568 URLRequest req(test_server_.GetURL("empty.html"),
5569 DEFAULT_PRIORITY,
5570 &d,
5571 &default_context_);
5374 req.set_method("POST"); 5572 req.set_method("POST");
5375 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 5573 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
5376 HttpRequestHeaders headers; 5574 HttpRequestHeaders headers;
5377 headers.SetHeader(HttpRequestHeaders::kContentLength, 5575 headers.SetHeader(HttpRequestHeaders::kContentLength,
5378 base::UintToString(arraysize(kData) - 1)); 5576 base::UintToString(arraysize(kData) - 1));
5379 req.SetExtraRequestHeaders(headers); 5577 req.SetExtraRequestHeaders(headers);
5380 5578
5381 URLRequestRedirectJob* job = new URLRequestRedirectJob( 5579 URLRequestRedirectJob* job = new URLRequestRedirectJob(
5382 &req, &default_network_delegate_, test_server_.GetURL("echo"), 5580 &req, &default_network_delegate_, test_server_.GetURL("echo"),
5383 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); 5581 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT);
(...skipping 10 matching lines...) Expand all
5394 ASSERT_TRUE(test_server_.Start()); 5592 ASSERT_TRUE(test_server_.Start());
5395 5593
5396 StaticHttpUserAgentSettings settings("en", EmptyString()); 5594 StaticHttpUserAgentSettings settings("en", EmptyString());
5397 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 5595 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
5398 TestURLRequestContext context(true); 5596 TestURLRequestContext context(true);
5399 context.set_network_delegate(&network_delegate); 5597 context.set_network_delegate(&network_delegate);
5400 context.set_http_user_agent_settings(&settings); 5598 context.set_http_user_agent_settings(&settings);
5401 context.Init(); 5599 context.Init();
5402 5600
5403 TestDelegate d; 5601 TestDelegate d;
5404 URLRequest req( 5602 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"),
5405 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); 5603 DEFAULT_PRIORITY,
5604 &d,
5605 &context);
5406 req.Start(); 5606 req.Start();
5407 base::RunLoop().Run(); 5607 base::RunLoop().Run();
5408 EXPECT_EQ("en", d.data_received()); 5608 EXPECT_EQ("en", d.data_received());
5409 } 5609 }
5410 5610
5411 // Check that an empty A-L header is not sent. http://crbug.com/77365. 5611 // Check that an empty A-L header is not sent. http://crbug.com/77365.
5412 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { 5612 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) {
5413 ASSERT_TRUE(test_server_.Start()); 5613 ASSERT_TRUE(test_server_.Start());
5414 5614
5415 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString()); 5615 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString());
5416 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 5616 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
5417 TestURLRequestContext context(true); 5617 TestURLRequestContext context(true);
5418 context.set_network_delegate(&network_delegate); 5618 context.set_network_delegate(&network_delegate);
5419 context.Init(); 5619 context.Init();
5420 // We override the language after initialization because empty entries 5620 // We override the language after initialization because empty entries
5421 // get overridden by Init(). 5621 // get overridden by Init().
5422 context.set_http_user_agent_settings(&settings); 5622 context.set_http_user_agent_settings(&settings);
5423 5623
5424 TestDelegate d; 5624 TestDelegate d;
5425 URLRequest req( 5625 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"),
5426 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); 5626 DEFAULT_PRIORITY,
5627 &d,
5628 &context);
5427 req.Start(); 5629 req.Start();
5428 base::RunLoop().Run(); 5630 base::RunLoop().Run();
5429 EXPECT_EQ("None", d.data_received()); 5631 EXPECT_EQ("None", d.data_received());
5430 } 5632 }
5431 5633
5432 // Check that if request overrides the A-L header, the default is not appended. 5634 // Check that if request overrides the A-L header, the default is not appended.
5433 // See http://crbug.com/20894 5635 // See http://crbug.com/20894
5434 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { 5636 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
5435 ASSERT_TRUE(test_server_.Start()); 5637 ASSERT_TRUE(test_server_.Start());
5436 5638
5437 TestDelegate d; 5639 TestDelegate d;
5438 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), 5640 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"),
5641 DEFAULT_PRIORITY,
5439 &d, 5642 &d,
5440 &default_context_); 5643 &default_context_);
5441 HttpRequestHeaders headers; 5644 HttpRequestHeaders headers;
5442 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); 5645 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru");
5443 req.SetExtraRequestHeaders(headers); 5646 req.SetExtraRequestHeaders(headers);
5444 req.Start(); 5647 req.Start();
5445 base::RunLoop().Run(); 5648 base::RunLoop().Run();
5446 EXPECT_EQ(std::string("ru"), d.data_received()); 5649 EXPECT_EQ(std::string("ru"), d.data_received());
5447 } 5650 }
5448 5651
5449 // Check that default A-E header is sent. 5652 // Check that default A-E header is sent.
5450 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { 5653 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) {
5451 ASSERT_TRUE(test_server_.Start()); 5654 ASSERT_TRUE(test_server_.Start());
5452 5655
5453 TestDelegate d; 5656 TestDelegate d;
5454 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), 5657 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"),
5658 DEFAULT_PRIORITY,
5455 &d, 5659 &d,
5456 &default_context_); 5660 &default_context_);
5457 HttpRequestHeaders headers; 5661 HttpRequestHeaders headers;
5458 req.SetExtraRequestHeaders(headers); 5662 req.SetExtraRequestHeaders(headers);
5459 req.Start(); 5663 req.Start();
5460 base::RunLoop().Run(); 5664 base::RunLoop().Run();
5461 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); 5665 EXPECT_TRUE(ContainsString(d.data_received(), "gzip"));
5462 } 5666 }
5463 5667
5464 // Check that if request overrides the A-E header, the default is not appended. 5668 // Check that if request overrides the A-E header, the default is not appended.
5465 // See http://crbug.com/47381 5669 // See http://crbug.com/47381
5466 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { 5670 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) {
5467 ASSERT_TRUE(test_server_.Start()); 5671 ASSERT_TRUE(test_server_.Start());
5468 5672
5469 TestDelegate d; 5673 TestDelegate d;
5470 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), 5674 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"),
5675 DEFAULT_PRIORITY,
5471 &d, 5676 &d,
5472 &default_context_); 5677 &default_context_);
5473 HttpRequestHeaders headers; 5678 HttpRequestHeaders headers;
5474 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); 5679 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity");
5475 req.SetExtraRequestHeaders(headers); 5680 req.SetExtraRequestHeaders(headers);
5476 req.Start(); 5681 req.Start();
5477 base::RunLoop().Run(); 5682 base::RunLoop().Run();
5478 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 5683 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
5479 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 5684 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
5480 } 5685 }
5481 5686
5482 // Check that setting the A-C header sends the proper header. 5687 // Check that setting the A-C header sends the proper header.
5483 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { 5688 TEST_F(URLRequestTestHTTP, SetAcceptCharset) {
5484 ASSERT_TRUE(test_server_.Start()); 5689 ASSERT_TRUE(test_server_.Start());
5485 5690
5486 TestDelegate d; 5691 TestDelegate d;
5487 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), 5692 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"),
5693 DEFAULT_PRIORITY,
5488 &d, 5694 &d,
5489 &default_context_); 5695 &default_context_);
5490 HttpRequestHeaders headers; 5696 HttpRequestHeaders headers;
5491 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); 5697 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r");
5492 req.SetExtraRequestHeaders(headers); 5698 req.SetExtraRequestHeaders(headers);
5493 req.Start(); 5699 req.Start();
5494 base::RunLoop().Run(); 5700 base::RunLoop().Run();
5495 EXPECT_EQ(std::string("koi-8r"), d.data_received()); 5701 EXPECT_EQ(std::string("koi-8r"), d.data_received());
5496 } 5702 }
5497 5703
5498 // Check that default User-Agent header is sent. 5704 // Check that default User-Agent header is sent.
5499 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { 5705 TEST_F(URLRequestTestHTTP, DefaultUserAgent) {
5500 ASSERT_TRUE(test_server_.Start()); 5706 ASSERT_TRUE(test_server_.Start());
5501 5707
5502 TestDelegate d; 5708 TestDelegate d;
5503 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), 5709 URLRequest req(test_server_.GetURL("echoheader?User-Agent"),
5710 DEFAULT_PRIORITY,
5504 &d, 5711 &d,
5505 &default_context_); 5712 &default_context_);
5506 req.Start(); 5713 req.Start();
5507 base::RunLoop().Run(); 5714 base::RunLoop().Run();
5508 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); 5715 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received());
5509 } 5716 }
5510 5717
5511 // Check that if request overrides the User-Agent header, 5718 // Check that if request overrides the User-Agent header,
5512 // the default is not appended. 5719 // the default is not appended.
5513 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { 5720 TEST_F(URLRequestTestHTTP, OverrideUserAgent) {
5514 ASSERT_TRUE(test_server_.Start()); 5721 ASSERT_TRUE(test_server_.Start());
5515 5722
5516 TestDelegate d; 5723 TestDelegate d;
5517 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), 5724 URLRequest req(test_server_.GetURL("echoheader?User-Agent"),
5725 DEFAULT_PRIORITY,
5518 &d, 5726 &d,
5519 &default_context_); 5727 &default_context_);
5520 HttpRequestHeaders headers; 5728 HttpRequestHeaders headers;
5521 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 5729 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
5522 req.SetExtraRequestHeaders(headers); 5730 req.SetExtraRequestHeaders(headers);
5523 req.Start(); 5731 req.Start();
5524 base::RunLoop().Run(); 5732 base::RunLoop().Run();
5525 // If the net tests are being run with ChromeFrame then we need to allow for 5733 // If the net tests are being run with ChromeFrame then we need to allow for
5526 // the 'chromeframe' suffix which is added to the user agent before the 5734 // the 'chromeframe' suffix which is added to the user agent before the
5527 // closing parentheses. 5735 // closing parentheses.
(...skipping 16 matching lines...) Expand all
5544 5752
5545 struct { 5753 struct {
5546 const char* request; 5754 const char* request;
5547 const char* expected_response; 5755 const char* expected_response;
5548 } tests[] = { { "echoheader?Accept-Language", "None" }, 5756 } tests[] = { { "echoheader?Accept-Language", "None" },
5549 { "echoheader?Accept-Charset", "None" }, 5757 { "echoheader?Accept-Charset", "None" },
5550 { "echoheader?User-Agent", "" } }; 5758 { "echoheader?User-Agent", "" } };
5551 5759
5552 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { 5760 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
5553 TestDelegate d; 5761 TestDelegate d;
5554 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); 5762 URLRequest req(
5763 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, &context);
5555 req.Start(); 5764 req.Start();
5556 base::RunLoop().Run(); 5765 base::RunLoop().Run();
5557 EXPECT_EQ(tests[i].expected_response, d.data_received()) 5766 EXPECT_EQ(tests[i].expected_response, d.data_received())
5558 << " Request = \"" << tests[i].request << "\""; 5767 << " Request = \"" << tests[i].request << "\"";
5559 } 5768 }
5560 } 5769 }
5561 5770
5562 // Make sure that URLRequest passes on its priority updates to 5771 // Make sure that URLRequest passes on its priority updates to
5563 // newly-created jobs after the first one. 5772 // newly-created jobs after the first one.
5564 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { 5773 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
5565 ASSERT_TRUE(test_server_.Start()); 5774 ASSERT_TRUE(test_server_.Start());
5566 5775
5567 TestDelegate d; 5776 TestDelegate d;
5568 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); 5777 URLRequest req(test_server_.GetURL("empty.html"),
5778 DEFAULT_PRIORITY,
5779 &d,
5780 &default_context_);
5569 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); 5781 EXPECT_EQ(DEFAULT_PRIORITY, req.priority());
5570 5782
5571 scoped_refptr<URLRequestRedirectJob> redirect_job = 5783 scoped_refptr<URLRequestRedirectJob> redirect_job =
5572 new URLRequestRedirectJob( 5784 new URLRequestRedirectJob(
5573 &req, &default_network_delegate_, test_server_.GetURL("echo"), 5785 &req, &default_network_delegate_, test_server_.GetURL("echo"),
5574 URLRequestRedirectJob::REDIRECT_302_FOUND); 5786 URLRequestRedirectJob::REDIRECT_302_FOUND);
5575 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); 5787 AddTestInterceptor()->set_main_intercept_job(redirect_job.get());
5576 5788
5577 req.SetPriority(LOW); 5789 req.SetPriority(LOW);
5578 req.Start(); 5790 req.Start();
(...skipping 23 matching lines...) Expand all
5602 5814
5603 TEST_F(HTTPSRequestTest, HTTPSGetTest) { 5815 TEST_F(HTTPSRequestTest, HTTPSGetTest) {
5604 SpawnedTestServer test_server( 5816 SpawnedTestServer test_server(
5605 SpawnedTestServer::TYPE_HTTPS, 5817 SpawnedTestServer::TYPE_HTTPS,
5606 SpawnedTestServer::kLocalhost, 5818 SpawnedTestServer::kLocalhost,
5607 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 5819 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5608 ASSERT_TRUE(test_server.Start()); 5820 ASSERT_TRUE(test_server.Start());
5609 5821
5610 TestDelegate d; 5822 TestDelegate d;
5611 { 5823 {
5612 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); 5824 URLRequest r(test_server.GetURL(std::string()),
5825 DEFAULT_PRIORITY,
5826 &d,
5827 &default_context_);
5613 r.Start(); 5828 r.Start();
5614 EXPECT_TRUE(r.is_pending()); 5829 EXPECT_TRUE(r.is_pending());
5615 5830
5616 base::RunLoop().Run(); 5831 base::RunLoop().Run();
5617 5832
5618 EXPECT_EQ(1, d.response_started_count()); 5833 EXPECT_EQ(1, d.response_started_count());
5619 EXPECT_FALSE(d.received_data_before_response()); 5834 EXPECT_FALSE(d.received_data_before_response());
5620 EXPECT_NE(0, d.bytes_received()); 5835 EXPECT_NE(0, d.bytes_received());
5621 CheckSSLInfo(r.ssl_info()); 5836 CheckSSLInfo(r.ssl_info());
5622 EXPECT_EQ(test_server.host_port_pair().host(), 5837 EXPECT_EQ(test_server.host_port_pair().host(),
(...skipping 10 matching lines...) Expand all
5633 SpawnedTestServer::TYPE_HTTPS, 5848 SpawnedTestServer::TYPE_HTTPS,
5634 ssl_options, 5849 ssl_options,
5635 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 5850 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5636 ASSERT_TRUE(test_server.Start()); 5851 ASSERT_TRUE(test_server.Start());
5637 5852
5638 bool err_allowed = true; 5853 bool err_allowed = true;
5639 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 5854 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
5640 TestDelegate d; 5855 TestDelegate d;
5641 { 5856 {
5642 d.set_allow_certificate_errors(err_allowed); 5857 d.set_allow_certificate_errors(err_allowed);
5643 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); 5858 URLRequest r(test_server.GetURL(std::string()),
5859 DEFAULT_PRIORITY,
5860 &d,
5861 &default_context_);
5644 5862
5645 r.Start(); 5863 r.Start();
5646 EXPECT_TRUE(r.is_pending()); 5864 EXPECT_TRUE(r.is_pending());
5647 5865
5648 base::RunLoop().Run(); 5866 base::RunLoop().Run();
5649 5867
5650 EXPECT_EQ(1, d.response_started_count()); 5868 EXPECT_EQ(1, d.response_started_count());
5651 EXPECT_FALSE(d.received_data_before_response()); 5869 EXPECT_FALSE(d.received_data_before_response());
5652 EXPECT_TRUE(d.have_certificate_errors()); 5870 EXPECT_TRUE(d.have_certificate_errors());
5653 if (err_allowed) { 5871 if (err_allowed) {
(...skipping 15 matching lines...) Expand all
5669 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 5887 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5670 ASSERT_TRUE(test_server.Start()); 5888 ASSERT_TRUE(test_server.Start());
5671 5889
5672 // Iterate from false to true, just so that we do the opposite of the 5890 // Iterate from false to true, just so that we do the opposite of the
5673 // previous test in order to increase test coverage. 5891 // previous test in order to increase test coverage.
5674 bool err_allowed = false; 5892 bool err_allowed = false;
5675 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 5893 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
5676 TestDelegate d; 5894 TestDelegate d;
5677 { 5895 {
5678 d.set_allow_certificate_errors(err_allowed); 5896 d.set_allow_certificate_errors(err_allowed);
5679 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); 5897 URLRequest r(test_server.GetURL(std::string()),
5898 DEFAULT_PRIORITY,
5899 &d,
5900 &default_context_);
5680 5901
5681 r.Start(); 5902 r.Start();
5682 EXPECT_TRUE(r.is_pending()); 5903 EXPECT_TRUE(r.is_pending());
5683 5904
5684 base::RunLoop().Run(); 5905 base::RunLoop().Run();
5685 5906
5686 EXPECT_EQ(1, d.response_started_count()); 5907 EXPECT_EQ(1, d.response_started_count());
5687 EXPECT_FALSE(d.received_data_before_response()); 5908 EXPECT_FALSE(d.received_data_before_response());
5688 EXPECT_TRUE(d.have_certificate_errors()); 5909 EXPECT_TRUE(d.have_certificate_errors());
5689 if (err_allowed) { 5910 if (err_allowed) {
(...skipping 24 matching lines...) Expand all
5714 SpawnedTestServer test_server( 5935 SpawnedTestServer test_server(
5715 SpawnedTestServer::TYPE_HTTPS, 5936 SpawnedTestServer::TYPE_HTTPS,
5716 ssl_options, 5937 ssl_options,
5717 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 5938 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5718 ASSERT_TRUE(test_server.Start()); 5939 ASSERT_TRUE(test_server.Start());
5719 5940
5720 TestDelegate d; 5941 TestDelegate d;
5721 TestURLRequestContext context(true); 5942 TestURLRequestContext context(true);
5722 context.Init(); 5943 context.Init();
5723 d.set_allow_certificate_errors(true); 5944 d.set_allow_certificate_errors(true);
5724 URLRequest r(test_server.GetURL(std::string()), &d, &context); 5945 URLRequest r(
5946 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
5725 r.Start(); 5947 r.Start();
5726 5948
5727 base::RunLoop().Run(); 5949 base::RunLoop().Run();
5728 5950
5729 EXPECT_EQ(1, d.response_started_count()); 5951 EXPECT_EQ(1, d.response_started_count());
5730 EXPECT_NE(0, d.bytes_received()); 5952 EXPECT_NE(0, d.bytes_received());
5731 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), 5953 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1),
5732 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); 5954 SSLConnectionStatusToVersion(r.ssl_info().connection_status));
5733 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); 5955 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK);
5734 } 5956 }
(...skipping 20 matching lines...) Expand all
5755 TestURLRequestContext context(true); 5977 TestURLRequestContext context(true);
5756 context.set_network_delegate(&network_delegate); 5978 context.set_network_delegate(&network_delegate);
5757 context.set_host_resolver(&host_resolver); 5979 context.set_host_resolver(&host_resolver);
5758 TransportSecurityState transport_security_state; 5980 TransportSecurityState transport_security_state;
5759 context.set_transport_security_state(&transport_security_state); 5981 context.set_transport_security_state(&transport_security_state);
5760 context.Init(); 5982 context.Init();
5761 5983
5762 TestDelegate d; 5984 TestDelegate d;
5763 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 5985 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d",
5764 test_server.host_port_pair().port())), 5986 test_server.host_port_pair().port())),
5987 DEFAULT_PRIORITY,
5765 &d, 5988 &d,
5766 &context); 5989 &context);
5767 5990
5768 r.Start(); 5991 r.Start();
5769 EXPECT_TRUE(r.is_pending()); 5992 EXPECT_TRUE(r.is_pending());
5770 5993
5771 base::RunLoop().Run(); 5994 base::RunLoop().Run();
5772 5995
5773 EXPECT_EQ(1, d.response_started_count()); 5996 EXPECT_EQ(1, d.response_started_count());
5774 EXPECT_FALSE(d.received_data_before_response()); 5997 EXPECT_FALSE(d.received_data_before_response());
(...skipping 28 matching lines...) Expand all
5803 TransportSecurityState transport_security_state; 6026 TransportSecurityState transport_security_state;
5804 TransportSecurityState::DomainState domain_state; 6027 TransportSecurityState::DomainState domain_state;
5805 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 6028 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
5806 &domain_state)); 6029 &domain_state));
5807 context.set_transport_security_state(&transport_security_state); 6030 context.set_transport_security_state(&transport_security_state);
5808 context.Init(); 6031 context.Init();
5809 6032
5810 TestDelegate d; 6033 TestDelegate d;
5811 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", 6034 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d",
5812 test_server.host_port_pair().port())), 6035 test_server.host_port_pair().port())),
6036 DEFAULT_PRIORITY,
5813 &d, 6037 &d,
5814 &context); 6038 &context);
5815 6039
5816 r.Start(); 6040 r.Start();
5817 EXPECT_TRUE(r.is_pending()); 6041 EXPECT_TRUE(r.is_pending());
5818 6042
5819 base::RunLoop().Run(); 6043 base::RunLoop().Run();
5820 6044
5821 EXPECT_EQ(1, d.response_started_count()); 6045 EXPECT_EQ(1, d.response_started_count());
5822 EXPECT_FALSE(d.received_data_before_response()); 6046 EXPECT_FALSE(d.received_data_before_response());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
5874 context.set_network_delegate(&network_delegate); 6098 context.set_network_delegate(&network_delegate);
5875 context.Init(); 6099 context.Init();
5876 6100
5877 TestDelegate d; 6101 TestDelegate d;
5878 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will 6102 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will
5879 // cause a certificate error. Ignore the error. 6103 // cause a certificate error. Ignore the error.
5880 d.set_allow_certificate_errors(true); 6104 d.set_allow_certificate_errors(true);
5881 6105
5882 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", 6106 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo",
5883 test_server.host_port_pair().port())), 6107 test_server.host_port_pair().port())),
6108 DEFAULT_PRIORITY,
5884 &d, 6109 &d,
5885 &context); 6110 &context);
5886 req.set_method("POST"); 6111 req.set_method("POST");
5887 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); 6112 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
5888 6113
5889 req.Start(); 6114 req.Start();
5890 base::RunLoop().Run(); 6115 base::RunLoop().Run();
5891 6116
5892 EXPECT_EQ("https", req.url().scheme()); 6117 EXPECT_EQ("https", req.url().scheme());
5893 EXPECT_EQ("POST", req.method()); 6118 EXPECT_EQ("POST", req.method());
(...skipping 13 matching lines...) Expand all
5907 SpawnedTestServer test_server( 6132 SpawnedTestServer test_server(
5908 SpawnedTestServer::TYPE_HTTPS, 6133 SpawnedTestServer::TYPE_HTTPS,
5909 ssl_options, 6134 ssl_options,
5910 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6135 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5911 ASSERT_TRUE(test_server.Start()); 6136 ASSERT_TRUE(test_server.Start());
5912 6137
5913 TestDelegate d; 6138 TestDelegate d;
5914 TestURLRequestContext context(true); 6139 TestURLRequestContext context(true);
5915 context.Init(); 6140 context.Init();
5916 d.set_allow_certificate_errors(true); 6141 d.set_allow_certificate_errors(true);
5917 URLRequest r(test_server.GetURL(std::string()), &d, &context); 6142 URLRequest r(
6143 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context);
5918 r.Start(); 6144 r.Start();
5919 6145
5920 base::RunLoop().Run(); 6146 base::RunLoop().Run();
5921 6147
5922 EXPECT_EQ(1, d.response_started_count()); 6148 EXPECT_EQ(1, d.response_started_count());
5923 EXPECT_NE(0, d.bytes_received()); 6149 EXPECT_NE(0, d.bytes_received());
5924 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), 6150 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3),
5925 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); 6151 SSLConnectionStatusToVersion(r.ssl_info().connection_status));
5926 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); 6152 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK);
5927 } 6153 }
(...skipping 28 matching lines...) Expand all
5956 SpawnedTestServer::SSLOptions ssl_options; 6182 SpawnedTestServer::SSLOptions ssl_options;
5957 ssl_options.request_client_certificate = true; 6183 ssl_options.request_client_certificate = true;
5958 SpawnedTestServer test_server( 6184 SpawnedTestServer test_server(
5959 SpawnedTestServer::TYPE_HTTPS, 6185 SpawnedTestServer::TYPE_HTTPS,
5960 ssl_options, 6186 ssl_options,
5961 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6187 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5962 ASSERT_TRUE(test_server.Start()); 6188 ASSERT_TRUE(test_server.Start());
5963 6189
5964 SSLClientAuthTestDelegate d; 6190 SSLClientAuthTestDelegate d;
5965 { 6191 {
5966 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); 6192 URLRequest r(test_server.GetURL(std::string()),
6193 DEFAULT_PRIORITY,
6194 &d,
6195 &default_context_);
5967 6196
5968 r.Start(); 6197 r.Start();
5969 EXPECT_TRUE(r.is_pending()); 6198 EXPECT_TRUE(r.is_pending());
5970 6199
5971 base::RunLoop().Run(); 6200 base::RunLoop().Run();
5972 6201
5973 EXPECT_EQ(1, d.on_certificate_requested_count()); 6202 EXPECT_EQ(1, d.on_certificate_requested_count());
5974 EXPECT_FALSE(d.received_data_before_response()); 6203 EXPECT_FALSE(d.received_data_before_response());
5975 EXPECT_EQ(0, d.bytes_received()); 6204 EXPECT_EQ(0, d.bytes_received());
5976 6205
(...skipping 18 matching lines...) Expand all
5995 SpawnedTestServer test_server( 6224 SpawnedTestServer test_server(
5996 SpawnedTestServer::TYPE_HTTPS, 6225 SpawnedTestServer::TYPE_HTTPS,
5997 ssl_options, 6226 ssl_options,
5998 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6227 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
5999 ASSERT_TRUE(test_server.Start()); 6228 ASSERT_TRUE(test_server.Start());
6000 6229
6001 SSLClientSocket::ClearSessionCache(); 6230 SSLClientSocket::ClearSessionCache();
6002 6231
6003 { 6232 {
6004 TestDelegate d; 6233 TestDelegate d;
6005 URLRequest r( 6234 URLRequest r(test_server.GetURL("ssl-session-cache"),
6006 test_server.GetURL("ssl-session-cache"), &d, &default_context_); 6235 DEFAULT_PRIORITY,
6236 &d,
6237 &default_context_);
6007 6238
6008 r.Start(); 6239 r.Start();
6009 EXPECT_TRUE(r.is_pending()); 6240 EXPECT_TRUE(r.is_pending());
6010 6241
6011 base::RunLoop().Run(); 6242 base::RunLoop().Run();
6012 6243
6013 EXPECT_EQ(1, d.response_started_count()); 6244 EXPECT_EQ(1, d.response_started_count());
6014 } 6245 }
6015 6246
6016 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> 6247 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
6017 CloseAllConnections(); 6248 CloseAllConnections();
6018 6249
6019 { 6250 {
6020 TestDelegate d; 6251 TestDelegate d;
6021 URLRequest r( 6252 URLRequest r(test_server.GetURL("ssl-session-cache"),
6022 test_server.GetURL("ssl-session-cache"), &d, &default_context_); 6253 DEFAULT_PRIORITY,
6254 &d,
6255 &default_context_);
6023 6256
6024 r.Start(); 6257 r.Start();
6025 EXPECT_TRUE(r.is_pending()); 6258 EXPECT_TRUE(r.is_pending());
6026 6259
6027 base::RunLoop().Run(); 6260 base::RunLoop().Run();
6028 6261
6029 // The response will look like; 6262 // The response will look like;
6030 // insert abc 6263 // insert abc
6031 // lookup abc 6264 // lookup abc
6032 // insert xyz 6265 // insert xyz
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6064 SpawnedTestServer test_server( 6297 SpawnedTestServer test_server(
6065 SpawnedTestServer::TYPE_HTTPS, 6298 SpawnedTestServer::TYPE_HTTPS,
6066 ssl_options, 6299 ssl_options,
6067 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6300 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6068 ASSERT_TRUE(test_server.Start()); 6301 ASSERT_TRUE(test_server.Start());
6069 6302
6070 SSLClientSocket::ClearSessionCache(); 6303 SSLClientSocket::ClearSessionCache();
6071 6304
6072 { 6305 {
6073 TestDelegate d; 6306 TestDelegate d;
6074 URLRequest r( 6307 URLRequest r(test_server.GetURL("ssl-session-cache"),
6075 test_server.GetURL("ssl-session-cache"), &d, &default_context_); 6308 DEFAULT_PRIORITY,
6309 &d,
6310 &default_context_);
6076 6311
6077 r.Start(); 6312 r.Start();
6078 EXPECT_TRUE(r.is_pending()); 6313 EXPECT_TRUE(r.is_pending());
6079 6314
6080 base::RunLoop().Run(); 6315 base::RunLoop().Run();
6081 6316
6082 EXPECT_EQ(1, d.response_started_count()); 6317 EXPECT_EQ(1, d.response_started_count());
6083 } 6318 }
6084 6319
6085 // Now create a new HttpCache with a different ssl_session_cache_shard value. 6320 // Now create a new HttpCache with a different ssl_session_cache_shard value.
(...skipping 10 matching lines...) Expand all
6096 params.ssl_session_cache_shard = "alternate"; 6331 params.ssl_session_cache_shard = "alternate";
6097 6332
6098 scoped_ptr<net::HttpCache> cache(new net::HttpCache( 6333 scoped_ptr<net::HttpCache> cache(new net::HttpCache(
6099 new net::HttpNetworkSession(params), 6334 new net::HttpNetworkSession(params),
6100 net::HttpCache::DefaultBackend::InMemory(0))); 6335 net::HttpCache::DefaultBackend::InMemory(0)));
6101 6336
6102 default_context_.set_http_transaction_factory(cache.get()); 6337 default_context_.set_http_transaction_factory(cache.get());
6103 6338
6104 { 6339 {
6105 TestDelegate d; 6340 TestDelegate d;
6106 URLRequest r( 6341 URLRequest r(test_server.GetURL("ssl-session-cache"),
6107 test_server.GetURL("ssl-session-cache"), &d, &default_context_); 6342 DEFAULT_PRIORITY,
6343 &d,
6344 &default_context_);
6108 6345
6109 r.Start(); 6346 r.Start();
6110 EXPECT_TRUE(r.is_pending()); 6347 EXPECT_TRUE(r.is_pending());
6111 6348
6112 base::RunLoop().Run(); 6349 base::RunLoop().Run();
6113 6350
6114 // The response will look like; 6351 // The response will look like;
6115 // insert abc 6352 // insert abc
6116 // insert xyz 6353 // insert xyz
6117 // 6354 //
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
6215 // We always overwrite out_cert_status. 6452 // We always overwrite out_cert_status.
6216 *out_cert_status = 0; 6453 *out_cert_status = 0;
6217 SpawnedTestServer test_server( 6454 SpawnedTestServer test_server(
6218 SpawnedTestServer::TYPE_HTTPS, 6455 SpawnedTestServer::TYPE_HTTPS,
6219 ssl_options, 6456 ssl_options,
6220 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 6457 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
6221 ASSERT_TRUE(test_server.Start()); 6458 ASSERT_TRUE(test_server.Start());
6222 6459
6223 TestDelegate d; 6460 TestDelegate d;
6224 d.set_allow_certificate_errors(true); 6461 d.set_allow_certificate_errors(true);
6225 URLRequest r(test_server.GetURL(std::string()), &d, &context_); 6462 URLRequest r(
6463 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context_);
6226 r.Start(); 6464 r.Start();
6227 6465
6228 base::RunLoop().Run(); 6466 base::RunLoop().Run();
6229 6467
6230 EXPECT_EQ(1, d.response_started_count()); 6468 EXPECT_EQ(1, d.response_started_count());
6231 *out_cert_status = r.ssl_info().cert_status; 6469 *out_cert_status = r.ssl_info().cert_status;
6232 } 6470 }
6233 6471
6234 virtual ~HTTPSOCSPTest() { 6472 virtual ~HTTPSOCSPTest() {
6235 #if defined(USE_NSS) || defined(OS_IOS) 6473 #if defined(USE_NSS) || defined(OS_IOS)
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
6670 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); 6908 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver());
6671 6909
6672 GURL url("ftp://127.0.0.1:7"); 6910 GURL url("ftp://127.0.0.1:7");
6673 job_factory.SetProtocolHandler( 6911 job_factory.SetProtocolHandler(
6674 "ftp", 6912 "ftp",
6675 new FtpProtocolHandler(&ftp_transaction_factory)); 6913 new FtpProtocolHandler(&ftp_transaction_factory));
6676 default_context_.set_job_factory(&job_factory); 6914 default_context_.set_job_factory(&job_factory);
6677 6915
6678 TestDelegate d; 6916 TestDelegate d;
6679 { 6917 {
6680 URLRequest r(url, &d, &default_context_); 6918 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_);
6681 r.Start(); 6919 r.Start();
6682 EXPECT_TRUE(r.is_pending()); 6920 EXPECT_TRUE(r.is_pending());
6683 6921
6684 base::RunLoop().Run(); 6922 base::RunLoop().Run();
6685 6923
6686 EXPECT_FALSE(r.is_pending()); 6924 EXPECT_FALSE(r.is_pending());
6687 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 6925 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
6688 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); 6926 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error());
6689 } 6927 }
6690 } 6928 }
6691 6929
6692 // Flaky, see http://crbug.com/25045. 6930 // Flaky, see http://crbug.com/25045.
6693 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { 6931 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) {
6694 ASSERT_TRUE(test_server_.Start()); 6932 ASSERT_TRUE(test_server_.Start());
6695 6933
6696 TestDelegate d; 6934 TestDelegate d;
6697 { 6935 {
6698 URLRequest r(test_server_.GetURL("/"), &d, &default_context_); 6936 URLRequest r(
6937 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, &default_context_);
6699 r.Start(); 6938 r.Start();
6700 EXPECT_TRUE(r.is_pending()); 6939 EXPECT_TRUE(r.is_pending());
6701 6940
6702 base::RunLoop().Run(); 6941 base::RunLoop().Run();
6703 6942
6704 EXPECT_FALSE(r.is_pending()); 6943 EXPECT_FALSE(r.is_pending());
6705 EXPECT_EQ(1, d.response_started_count()); 6944 EXPECT_EQ(1, d.response_started_count());
6706 EXPECT_FALSE(d.received_data_before_response()); 6945 EXPECT_FALSE(d.received_data_before_response());
6707 EXPECT_LT(0, d.bytes_received()); 6946 EXPECT_LT(0, d.bytes_received());
6708 EXPECT_EQ(test_server_.host_port_pair().host(), 6947 EXPECT_EQ(test_server_.host_port_pair().host(),
6709 r.GetSocketAddress().host()); 6948 r.GetSocketAddress().host());
6710 EXPECT_EQ(test_server_.host_port_pair().port(), 6949 EXPECT_EQ(test_server_.host_port_pair().port(),
6711 r.GetSocketAddress().port()); 6950 r.GetSocketAddress().port());
6712 } 6951 }
6713 } 6952 }
6714 6953
6715 // Flaky, see http://crbug.com/25045. 6954 // Flaky, see http://crbug.com/25045.
6716 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { 6955 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) {
6717 ASSERT_TRUE(test_server_.Start()); 6956 ASSERT_TRUE(test_server_.Start());
6718 6957
6719 base::FilePath app_path; 6958 base::FilePath app_path;
6720 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 6959 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6721 app_path = app_path.AppendASCII("LICENSE"); 6960 app_path = app_path.AppendASCII("LICENSE");
6722 TestDelegate d; 6961 TestDelegate d;
6723 { 6962 {
6724 URLRequest r(test_server_.GetURL("/LICENSE"), &d, &default_context_); 6963 URLRequest r(test_server_.GetURL("/LICENSE"),
6964 DEFAULT_PRIORITY,
6965 &d,
6966 &default_context_);
6725 r.Start(); 6967 r.Start();
6726 EXPECT_TRUE(r.is_pending()); 6968 EXPECT_TRUE(r.is_pending());
6727 6969
6728 base::RunLoop().Run(); 6970 base::RunLoop().Run();
6729 6971
6730 int64 file_size = 0; 6972 int64 file_size = 0;
6731 file_util::GetFileSize(app_path, &file_size); 6973 file_util::GetFileSize(app_path, &file_size);
6732 6974
6733 EXPECT_FALSE(r.is_pending()); 6975 EXPECT_FALSE(r.is_pending());
6734 EXPECT_EQ(1, d.response_started_count()); 6976 EXPECT_EQ(1, d.response_started_count());
(...skipping 10 matching lines...) Expand all
6745 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { 6987 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) {
6746 ASSERT_TRUE(test_server_.Start()); 6988 ASSERT_TRUE(test_server_.Start());
6747 6989
6748 base::FilePath app_path; 6990 base::FilePath app_path;
6749 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 6991 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6750 app_path = app_path.AppendASCII("LICENSE"); 6992 app_path = app_path.AppendASCII("LICENSE");
6751 TestDelegate d; 6993 TestDelegate d;
6752 { 6994 {
6753 URLRequest r( 6995 URLRequest r(
6754 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 6996 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
6997 DEFAULT_PRIORITY,
6755 &d, 6998 &d,
6756 &default_context_); 6999 &default_context_);
6757 r.Start(); 7000 r.Start();
6758 EXPECT_TRUE(r.is_pending()); 7001 EXPECT_TRUE(r.is_pending());
6759 7002
6760 base::RunLoop().Run(); 7003 base::RunLoop().Run();
6761 7004
6762 int64 file_size = 0; 7005 int64 file_size = 0;
6763 file_util::GetFileSize(app_path, &file_size); 7006 file_util::GetFileSize(app_path, &file_size);
6764 7007
(...skipping 14 matching lines...) Expand all
6779 7022
6780 // Flaky, see http://crbug.com/25045. 7023 // Flaky, see http://crbug.com/25045.
6781 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { 7024 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) {
6782 ASSERT_TRUE(test_server_.Start()); 7025 ASSERT_TRUE(test_server_.Start());
6783 7026
6784 base::FilePath app_path; 7027 base::FilePath app_path;
6785 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7028 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6786 app_path = app_path.AppendASCII("LICENSE"); 7029 app_path = app_path.AppendASCII("LICENSE");
6787 TestDelegate d; 7030 TestDelegate d;
6788 { 7031 {
6789 URLRequest r( 7032 URLRequest r(test_server_.GetURLWithUserAndPassword(
6790 test_server_.GetURLWithUserAndPassword("/LICENSE", 7033 "/LICENSE", "chrome", "wrong_password"),
6791 "chrome", 7034 DEFAULT_PRIORITY,
6792 "wrong_password"), 7035 &d,
6793 &d, 7036 &default_context_);
6794 &default_context_);
6795 r.Start(); 7037 r.Start();
6796 EXPECT_TRUE(r.is_pending()); 7038 EXPECT_TRUE(r.is_pending());
6797 7039
6798 base::RunLoop().Run(); 7040 base::RunLoop().Run();
6799 7041
6800 int64 file_size = 0; 7042 int64 file_size = 0;
6801 file_util::GetFileSize(app_path, &file_size); 7043 file_util::GetFileSize(app_path, &file_size);
6802 7044
6803 EXPECT_FALSE(r.is_pending()); 7045 EXPECT_FALSE(r.is_pending());
6804 EXPECT_EQ(1, d.response_started_count()); 7046 EXPECT_EQ(1, d.response_started_count());
6805 EXPECT_FALSE(d.received_data_before_response()); 7047 EXPECT_FALSE(d.received_data_before_response());
6806 EXPECT_EQ(d.bytes_received(), 0); 7048 EXPECT_EQ(d.bytes_received(), 0);
6807 } 7049 }
6808 } 7050 }
6809 7051
6810 // Flaky, see http://crbug.com/25045. 7052 // Flaky, see http://crbug.com/25045.
6811 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { 7053 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) {
6812 ASSERT_TRUE(test_server_.Start()); 7054 ASSERT_TRUE(test_server_.Start());
6813 7055
6814 base::FilePath app_path; 7056 base::FilePath app_path;
6815 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7057 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6816 app_path = app_path.AppendASCII("LICENSE"); 7058 app_path = app_path.AppendASCII("LICENSE");
6817 TestDelegate d; 7059 TestDelegate d;
6818 // Set correct login credentials. The delegate will be asked for them when 7060 // Set correct login credentials. The delegate will be asked for them when
6819 // the initial login with wrong credentials will fail. 7061 // the initial login with wrong credentials will fail.
6820 d.set_credentials(AuthCredentials(kChrome, kChrome)); 7062 d.set_credentials(AuthCredentials(kChrome, kChrome));
6821 { 7063 {
6822 URLRequest r( 7064 URLRequest r(test_server_.GetURLWithUserAndPassword(
6823 test_server_.GetURLWithUserAndPassword("/LICENSE", 7065 "/LICENSE", "chrome", "wrong_password"),
6824 "chrome", 7066 DEFAULT_PRIORITY,
6825 "wrong_password"), 7067 &d,
6826 &d, 7068 &default_context_);
6827 &default_context_);
6828 r.Start(); 7069 r.Start();
6829 EXPECT_TRUE(r.is_pending()); 7070 EXPECT_TRUE(r.is_pending());
6830 7071
6831 base::RunLoop().Run(); 7072 base::RunLoop().Run();
6832 7073
6833 int64 file_size = 0; 7074 int64 file_size = 0;
6834 file_util::GetFileSize(app_path, &file_size); 7075 file_util::GetFileSize(app_path, &file_size);
6835 7076
6836 EXPECT_FALSE(r.is_pending()); 7077 EXPECT_FALSE(r.is_pending());
6837 EXPECT_EQ(1, d.response_started_count()); 7078 EXPECT_EQ(1, d.response_started_count());
6838 EXPECT_FALSE(d.received_data_before_response()); 7079 EXPECT_FALSE(d.received_data_before_response());
6839 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7080 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
6840 } 7081 }
6841 } 7082 }
6842 7083
6843 // Flaky, see http://crbug.com/25045. 7084 // Flaky, see http://crbug.com/25045.
6844 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { 7085 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) {
6845 ASSERT_TRUE(test_server_.Start()); 7086 ASSERT_TRUE(test_server_.Start());
6846 7087
6847 base::FilePath app_path; 7088 base::FilePath app_path;
6848 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7089 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6849 app_path = app_path.AppendASCII("LICENSE"); 7090 app_path = app_path.AppendASCII("LICENSE");
6850 TestDelegate d; 7091 TestDelegate d;
6851 { 7092 {
6852 URLRequest r( 7093 URLRequest r(test_server_.GetURLWithUserAndPassword(
6853 test_server_.GetURLWithUserAndPassword("/LICENSE", 7094 "/LICENSE", "wrong_user", "chrome"),
6854 "wrong_user", 7095 DEFAULT_PRIORITY,
6855 "chrome"), 7096 &d,
6856 &d, 7097 &default_context_);
6857 &default_context_);
6858 r.Start(); 7098 r.Start();
6859 EXPECT_TRUE(r.is_pending()); 7099 EXPECT_TRUE(r.is_pending());
6860 7100
6861 base::RunLoop().Run(); 7101 base::RunLoop().Run();
6862 7102
6863 int64 file_size = 0; 7103 int64 file_size = 0;
6864 file_util::GetFileSize(app_path, &file_size); 7104 file_util::GetFileSize(app_path, &file_size);
6865 7105
6866 EXPECT_FALSE(r.is_pending()); 7106 EXPECT_FALSE(r.is_pending());
6867 EXPECT_EQ(1, d.response_started_count()); 7107 EXPECT_EQ(1, d.response_started_count());
6868 EXPECT_FALSE(d.received_data_before_response()); 7108 EXPECT_FALSE(d.received_data_before_response());
6869 EXPECT_EQ(d.bytes_received(), 0); 7109 EXPECT_EQ(d.bytes_received(), 0);
6870 } 7110 }
6871 } 7111 }
6872 7112
6873 // Flaky, see http://crbug.com/25045. 7113 // Flaky, see http://crbug.com/25045.
6874 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { 7114 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) {
6875 ASSERT_TRUE(test_server_.Start()); 7115 ASSERT_TRUE(test_server_.Start());
6876 7116
6877 base::FilePath app_path; 7117 base::FilePath app_path;
6878 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7118 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6879 app_path = app_path.AppendASCII("LICENSE"); 7119 app_path = app_path.AppendASCII("LICENSE");
6880 TestDelegate d; 7120 TestDelegate d;
6881 // Set correct login credentials. The delegate will be asked for them when 7121 // Set correct login credentials. The delegate will be asked for them when
6882 // the initial login with wrong credentials will fail. 7122 // the initial login with wrong credentials will fail.
6883 d.set_credentials(AuthCredentials(kChrome, kChrome)); 7123 d.set_credentials(AuthCredentials(kChrome, kChrome));
6884 { 7124 {
6885 URLRequest r( 7125 URLRequest r(test_server_.GetURLWithUserAndPassword(
6886 test_server_.GetURLWithUserAndPassword("/LICENSE", 7126 "/LICENSE", "wrong_user", "chrome"),
6887 "wrong_user", 7127 DEFAULT_PRIORITY,
6888 "chrome"), 7128 &d,
6889 &d, 7129 &default_context_);
6890 &default_context_);
6891 r.Start(); 7130 r.Start();
6892 EXPECT_TRUE(r.is_pending()); 7131 EXPECT_TRUE(r.is_pending());
6893 7132
6894 base::RunLoop().Run(); 7133 base::RunLoop().Run();
6895 7134
6896 int64 file_size = 0; 7135 int64 file_size = 0;
6897 file_util::GetFileSize(app_path, &file_size); 7136 file_util::GetFileSize(app_path, &file_size);
6898 7137
6899 EXPECT_FALSE(r.is_pending()); 7138 EXPECT_FALSE(r.is_pending());
6900 EXPECT_EQ(1, d.response_started_count()); 7139 EXPECT_EQ(1, d.response_started_count());
6901 EXPECT_FALSE(d.received_data_before_response()); 7140 EXPECT_FALSE(d.received_data_before_response());
6902 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 7141 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
6903 } 7142 }
6904 } 7143 }
6905 7144
6906 // Flaky, see http://crbug.com/25045. 7145 // Flaky, see http://crbug.com/25045.
6907 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { 7146 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) {
6908 ASSERT_TRUE(test_server_.Start()); 7147 ASSERT_TRUE(test_server_.Start());
6909 7148
6910 base::FilePath app_path; 7149 base::FilePath app_path;
6911 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7150 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6912 app_path = app_path.AppendASCII("LICENSE"); 7151 app_path = app_path.AppendASCII("LICENSE");
6913 7152
6914 scoped_ptr<TestDelegate> d(new TestDelegate); 7153 scoped_ptr<TestDelegate> d(new TestDelegate);
6915 { 7154 {
6916 // Pass correct login identity in the URL. 7155 // Pass correct login identity in the URL.
6917 URLRequest r( 7156 URLRequest r(
6918 test_server_.GetURLWithUserAndPassword("/LICENSE", 7157 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
6919 "chrome", 7158 DEFAULT_PRIORITY,
6920 "chrome"),
6921 d.get(), 7159 d.get(),
6922 &default_context_); 7160 &default_context_);
6923 r.Start(); 7161 r.Start();
6924 EXPECT_TRUE(r.is_pending()); 7162 EXPECT_TRUE(r.is_pending());
6925 7163
6926 base::RunLoop().Run(); 7164 base::RunLoop().Run();
6927 7165
6928 int64 file_size = 0; 7166 int64 file_size = 0;
6929 file_util::GetFileSize(app_path, &file_size); 7167 file_util::GetFileSize(app_path, &file_size);
6930 7168
6931 EXPECT_FALSE(r.is_pending()); 7169 EXPECT_FALSE(r.is_pending());
6932 EXPECT_EQ(1, d->response_started_count()); 7170 EXPECT_EQ(1, d->response_started_count());
6933 EXPECT_FALSE(d->received_data_before_response()); 7171 EXPECT_FALSE(d->received_data_before_response());
6934 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7172 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6935 } 7173 }
6936 7174
6937 d.reset(new TestDelegate); 7175 d.reset(new TestDelegate);
6938 { 7176 {
6939 // This request should use cached identity from previous request. 7177 // This request should use cached identity from previous request.
6940 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); 7178 URLRequest r(test_server_.GetURL("/LICENSE"),
7179 DEFAULT_PRIORITY,
7180 d.get(),
7181 &default_context_);
6941 r.Start(); 7182 r.Start();
6942 EXPECT_TRUE(r.is_pending()); 7183 EXPECT_TRUE(r.is_pending());
6943 7184
6944 base::RunLoop().Run(); 7185 base::RunLoop().Run();
6945 7186
6946 int64 file_size = 0; 7187 int64 file_size = 0;
6947 file_util::GetFileSize(app_path, &file_size); 7188 file_util::GetFileSize(app_path, &file_size);
6948 7189
6949 EXPECT_FALSE(r.is_pending()); 7190 EXPECT_FALSE(r.is_pending());
6950 EXPECT_EQ(1, d->response_started_count()); 7191 EXPECT_EQ(1, d->response_started_count());
6951 EXPECT_FALSE(d->received_data_before_response()); 7192 EXPECT_FALSE(d->received_data_before_response());
6952 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7193 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6953 } 7194 }
6954 } 7195 }
6955 7196
6956 // Flaky, see http://crbug.com/25045. 7197 // Flaky, see http://crbug.com/25045.
6957 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { 7198 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) {
6958 ASSERT_TRUE(test_server_.Start()); 7199 ASSERT_TRUE(test_server_.Start());
6959 7200
6960 base::FilePath app_path; 7201 base::FilePath app_path;
6961 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 7202 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
6962 app_path = app_path.AppendASCII("LICENSE"); 7203 app_path = app_path.AppendASCII("LICENSE");
6963 7204
6964 scoped_ptr<TestDelegate> d(new TestDelegate); 7205 scoped_ptr<TestDelegate> d(new TestDelegate);
6965 // Set correct login credentials. The delegate will be asked for them when 7206 // Set correct login credentials. The delegate will be asked for them when
6966 // the initial login with wrong credentials will fail. 7207 // the initial login with wrong credentials will fail.
6967 d->set_credentials(AuthCredentials(kChrome, kChrome)); 7208 d->set_credentials(AuthCredentials(kChrome, kChrome));
6968 { 7209 {
6969 URLRequest r( 7210 URLRequest r(test_server_.GetURLWithUserAndPassword(
6970 test_server_.GetURLWithUserAndPassword("/LICENSE", 7211 "/LICENSE", "chrome", "wrong_password"),
6971 "chrome", 7212 DEFAULT_PRIORITY,
6972 "wrong_password"), 7213 d.get(),
6973 d.get(), 7214 &default_context_);
6974 &default_context_);
6975 r.Start(); 7215 r.Start();
6976 EXPECT_TRUE(r.is_pending()); 7216 EXPECT_TRUE(r.is_pending());
6977 7217
6978 base::RunLoop().Run(); 7218 base::RunLoop().Run();
6979 7219
6980 int64 file_size = 0; 7220 int64 file_size = 0;
6981 file_util::GetFileSize(app_path, &file_size); 7221 file_util::GetFileSize(app_path, &file_size);
6982 7222
6983 EXPECT_FALSE(r.is_pending()); 7223 EXPECT_FALSE(r.is_pending());
6984 EXPECT_EQ(1, d->response_started_count()); 7224 EXPECT_EQ(1, d->response_started_count());
6985 EXPECT_FALSE(d->received_data_before_response()); 7225 EXPECT_FALSE(d->received_data_before_response());
6986 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7226 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
6987 } 7227 }
6988 7228
6989 // Use a new delegate without explicit credentials. The cached ones should be 7229 // Use a new delegate without explicit credentials. The cached ones should be
6990 // used. 7230 // used.
6991 d.reset(new TestDelegate); 7231 d.reset(new TestDelegate);
6992 { 7232 {
6993 // Don't pass wrong credentials in the URL, they would override valid cached 7233 // Don't pass wrong credentials in the URL, they would override valid cached
6994 // ones. 7234 // ones.
6995 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); 7235 URLRequest r(test_server_.GetURL("/LICENSE"),
7236 DEFAULT_PRIORITY,
7237 d.get(),
7238 &default_context_);
6996 r.Start(); 7239 r.Start();
6997 EXPECT_TRUE(r.is_pending()); 7240 EXPECT_TRUE(r.is_pending());
6998 7241
6999 base::RunLoop().Run(); 7242 base::RunLoop().Run();
7000 7243
7001 int64 file_size = 0; 7244 int64 file_size = 0;
7002 file_util::GetFileSize(app_path, &file_size); 7245 file_util::GetFileSize(app_path, &file_size);
7003 7246
7004 EXPECT_FALSE(r.is_pending()); 7247 EXPECT_FALSE(r.is_pending());
7005 EXPECT_EQ(1, d->response_started_count()); 7248 EXPECT_EQ(1, d->response_started_count());
7006 EXPECT_FALSE(d->received_data_before_response()); 7249 EXPECT_FALSE(d->received_data_before_response());
7007 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 7250 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
7008 } 7251 }
7009 } 7252 }
7010 #endif // !defined(DISABLE_FTP_SUPPORT) 7253 #endif // !defined(DISABLE_FTP_SUPPORT)
7011 7254
7012 } // namespace net 7255 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_unittest.cc ('k') | webkit/browser/appcache/appcache_request_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698