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

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

Powered by Google App Engine
This is Rietveld 408576698