OLD | NEW |
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 |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/message_loop/message_loop_proxy.h" |
22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/run_loop.h" |
23 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
25 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
26 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
27 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
28 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
29 #include "net/base/capturing_net_log.h" | 31 #include "net/base/capturing_net_log.h" |
30 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
31 #include "net/base/load_timing_info.h" | 33 #include "net/base/load_timing_info.h" |
32 #include "net/base/load_timing_info_test_util.h" | 34 #include "net/base/load_timing_info_test_util.h" |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 586 |
585 } // namespace | 587 } // namespace |
586 | 588 |
587 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 589 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
588 class URLRequestTest : public PlatformTest { | 590 class URLRequestTest : public PlatformTest { |
589 public: | 591 public: |
590 URLRequestTest() : default_context_(true) { | 592 URLRequestTest() : default_context_(true) { |
591 default_context_.set_network_delegate(&default_network_delegate_); | 593 default_context_.set_network_delegate(&default_network_delegate_); |
592 default_context_.set_net_log(&net_log_); | 594 default_context_.set_net_log(&net_log_); |
593 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); | 595 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
594 job_factory_.SetProtocolHandler("file", new FileProtocolHandler); | 596 job_factory_.SetProtocolHandler( |
| 597 "file", new FileProtocolHandler(base::MessageLoopProxy::current())); |
595 default_context_.set_job_factory(&job_factory_); | 598 default_context_.set_job_factory(&job_factory_); |
596 default_context_.Init(); | 599 default_context_.Init(); |
597 } | 600 } |
598 virtual ~URLRequestTest() {} | 601 virtual ~URLRequestTest() {} |
599 | 602 |
600 // Adds the TestJobInterceptor to the default context. | 603 // Adds the TestJobInterceptor to the default context. |
601 TestJobInterceptor* AddTestInterceptor() { | 604 TestJobInterceptor* AddTestInterceptor() { |
602 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 605 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
603 job_factory_.SetProtocolHandler("http", NULL); | 606 job_factory_.SetProtocolHandler("http", NULL); |
604 job_factory_.SetProtocolHandler("http", protocol_handler_); | 607 job_factory_.SetProtocolHandler("http", protocol_handler_); |
605 return protocol_handler_; | 608 return protocol_handler_; |
606 } | 609 } |
607 | 610 |
608 protected: | 611 protected: |
609 CapturingNetLog net_log_; | 612 CapturingNetLog net_log_; |
610 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 613 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
611 URLRequestJobFactoryImpl job_factory_; | 614 URLRequestJobFactoryImpl job_factory_; |
612 TestURLRequestContext default_context_; | 615 TestURLRequestContext default_context_; |
613 }; | 616 }; |
614 | 617 |
615 TEST_F(URLRequestTest, AboutBlankTest) { | 618 TEST_F(URLRequestTest, AboutBlankTest) { |
616 TestDelegate d; | 619 TestDelegate d; |
617 { | 620 { |
618 URLRequest r(GURL("about:blank"), &d, &default_context_); | 621 URLRequest r(GURL("about:blank"), &d, &default_context_); |
619 | 622 |
620 r.Start(); | 623 r.Start(); |
621 EXPECT_TRUE(r.is_pending()); | 624 EXPECT_TRUE(r.is_pending()); |
622 | 625 |
623 base::MessageLoop::current()->Run(); | 626 base::RunLoop().Run(); |
624 | 627 |
625 EXPECT_TRUE(!r.is_pending()); | 628 EXPECT_TRUE(!r.is_pending()); |
626 EXPECT_FALSE(d.received_data_before_response()); | 629 EXPECT_FALSE(d.received_data_before_response()); |
627 EXPECT_EQ(d.bytes_received(), 0); | 630 EXPECT_EQ(d.bytes_received(), 0); |
628 EXPECT_EQ("", r.GetSocketAddress().host()); | 631 EXPECT_EQ("", r.GetSocketAddress().host()); |
629 EXPECT_EQ(0, r.GetSocketAddress().port()); | 632 EXPECT_EQ(0, r.GetSocketAddress().port()); |
630 | 633 |
631 HttpRequestHeaders headers; | 634 HttpRequestHeaders headers; |
632 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 635 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
633 } | 636 } |
(...skipping 22 matching lines...) Expand all Loading... |
656 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 659 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" |
657 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 660 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" |
658 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 661 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" |
659 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 662 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
660 &d, | 663 &d, |
661 &default_context_); | 664 &default_context_); |
662 | 665 |
663 r.Start(); | 666 r.Start(); |
664 EXPECT_TRUE(r.is_pending()); | 667 EXPECT_TRUE(r.is_pending()); |
665 | 668 |
666 base::MessageLoop::current()->Run(); | 669 base::RunLoop().Run(); |
667 | 670 |
668 EXPECT_TRUE(!r.is_pending()); | 671 EXPECT_TRUE(!r.is_pending()); |
669 EXPECT_FALSE(d.received_data_before_response()); | 672 EXPECT_FALSE(d.received_data_before_response()); |
670 EXPECT_EQ(d.bytes_received(), 911); | 673 EXPECT_EQ(d.bytes_received(), 911); |
671 EXPECT_EQ("", r.GetSocketAddress().host()); | 674 EXPECT_EQ("", r.GetSocketAddress().host()); |
672 EXPECT_EQ(0, r.GetSocketAddress().port()); | 675 EXPECT_EQ(0, r.GetSocketAddress().port()); |
673 | 676 |
674 HttpRequestHeaders headers; | 677 HttpRequestHeaders headers; |
675 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 678 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
676 } | 679 } |
677 } | 680 } |
678 | 681 |
679 TEST_F(URLRequestTest, FileTest) { | 682 TEST_F(URLRequestTest, FileTest) { |
680 base::FilePath app_path; | 683 base::FilePath app_path; |
681 PathService::Get(base::FILE_EXE, &app_path); | 684 PathService::Get(base::FILE_EXE, &app_path); |
682 GURL app_url = FilePathToFileURL(app_path); | 685 GURL app_url = FilePathToFileURL(app_path); |
683 | 686 |
684 TestDelegate d; | 687 TestDelegate d; |
685 { | 688 { |
686 URLRequest r(app_url, &d, &default_context_); | 689 URLRequest r(app_url, &d, &default_context_); |
687 | 690 |
688 r.Start(); | 691 r.Start(); |
689 EXPECT_TRUE(r.is_pending()); | 692 EXPECT_TRUE(r.is_pending()); |
690 | 693 |
691 base::MessageLoop::current()->Run(); | 694 base::RunLoop().Run(); |
692 | 695 |
693 int64 file_size = -1; | 696 int64 file_size = -1; |
694 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 697 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
695 | 698 |
696 EXPECT_TRUE(!r.is_pending()); | 699 EXPECT_TRUE(!r.is_pending()); |
697 EXPECT_EQ(1, d.response_started_count()); | 700 EXPECT_EQ(1, d.response_started_count()); |
698 EXPECT_FALSE(d.received_data_before_response()); | 701 EXPECT_FALSE(d.received_data_before_response()); |
699 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 702 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
700 EXPECT_EQ("", r.GetSocketAddress().host()); | 703 EXPECT_EQ("", r.GetSocketAddress().host()); |
701 EXPECT_EQ(0, r.GetSocketAddress().port()); | 704 EXPECT_EQ(0, r.GetSocketAddress().port()); |
(...skipping 11 matching lines...) Expand all Loading... |
713 TestDelegate d; | 716 TestDelegate d; |
714 { | 717 { |
715 URLRequest r(app_url, &d, &default_context_); | 718 URLRequest r(app_url, &d, &default_context_); |
716 | 719 |
717 r.Start(); | 720 r.Start(); |
718 EXPECT_TRUE(r.is_pending()); | 721 EXPECT_TRUE(r.is_pending()); |
719 r.Cancel(); | 722 r.Cancel(); |
720 } | 723 } |
721 // Async cancellation should be safe even when URLRequest has been already | 724 // Async cancellation should be safe even when URLRequest has been already |
722 // destroyed. | 725 // destroyed. |
723 base::MessageLoop::current()->RunUntilIdle(); | 726 base::RunLoop().RunUntilIdle(); |
724 } | 727 } |
725 | 728 |
726 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { | 729 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { |
727 const size_t buffer_size = 4000; | 730 const size_t buffer_size = 4000; |
728 scoped_ptr<char[]> buffer(new char[buffer_size]); | 731 scoped_ptr<char[]> buffer(new char[buffer_size]); |
729 FillBuffer(buffer.get(), buffer_size); | 732 FillBuffer(buffer.get(), buffer_size); |
730 | 733 |
731 base::FilePath temp_path; | 734 base::FilePath temp_path; |
732 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 735 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
733 GURL temp_url = FilePathToFileURL(temp_path); | 736 GURL temp_url = FilePathToFileURL(temp_path); |
(...skipping 14 matching lines...) Expand all Loading... |
748 | 751 |
749 HttpRequestHeaders headers; | 752 HttpRequestHeaders headers; |
750 headers.SetHeader(HttpRequestHeaders::kRange, | 753 headers.SetHeader(HttpRequestHeaders::kRange, |
751 base::StringPrintf( | 754 base::StringPrintf( |
752 "bytes=%" PRIuS "-%" PRIuS, | 755 "bytes=%" PRIuS "-%" PRIuS, |
753 first_byte_position, last_byte_position)); | 756 first_byte_position, last_byte_position)); |
754 r.SetExtraRequestHeaders(headers); | 757 r.SetExtraRequestHeaders(headers); |
755 r.Start(); | 758 r.Start(); |
756 EXPECT_TRUE(r.is_pending()); | 759 EXPECT_TRUE(r.is_pending()); |
757 | 760 |
758 base::MessageLoop::current()->Run(); | 761 base::RunLoop().Run(); |
759 EXPECT_TRUE(!r.is_pending()); | 762 EXPECT_TRUE(!r.is_pending()); |
760 EXPECT_EQ(1, d.response_started_count()); | 763 EXPECT_EQ(1, d.response_started_count()); |
761 EXPECT_FALSE(d.received_data_before_response()); | 764 EXPECT_FALSE(d.received_data_before_response()); |
762 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 765 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
763 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 766 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
764 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 767 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
765 } | 768 } |
766 | 769 |
767 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 770 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
768 } | 771 } |
(...skipping 22 matching lines...) Expand all Loading... |
791 URLRequest r(temp_url, &d, &default_context_); | 794 URLRequest r(temp_url, &d, &default_context_); |
792 | 795 |
793 HttpRequestHeaders headers; | 796 HttpRequestHeaders headers; |
794 headers.SetHeader(HttpRequestHeaders::kRange, | 797 headers.SetHeader(HttpRequestHeaders::kRange, |
795 base::StringPrintf("bytes=%" PRIuS "-", | 798 base::StringPrintf("bytes=%" PRIuS "-", |
796 first_byte_position)); | 799 first_byte_position)); |
797 r.SetExtraRequestHeaders(headers); | 800 r.SetExtraRequestHeaders(headers); |
798 r.Start(); | 801 r.Start(); |
799 EXPECT_TRUE(r.is_pending()); | 802 EXPECT_TRUE(r.is_pending()); |
800 | 803 |
801 base::MessageLoop::current()->Run(); | 804 base::RunLoop().Run(); |
802 EXPECT_TRUE(!r.is_pending()); | 805 EXPECT_TRUE(!r.is_pending()); |
803 EXPECT_EQ(1, d.response_started_count()); | 806 EXPECT_EQ(1, d.response_started_count()); |
804 EXPECT_FALSE(d.received_data_before_response()); | 807 EXPECT_FALSE(d.received_data_before_response()); |
805 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 808 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
806 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 809 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
807 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 810 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
808 } | 811 } |
809 | 812 |
810 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 813 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
811 } | 814 } |
(...skipping 15 matching lines...) Expand all Loading... |
827 { | 830 { |
828 URLRequest r(temp_url, &d, &default_context_); | 831 URLRequest r(temp_url, &d, &default_context_); |
829 | 832 |
830 HttpRequestHeaders headers; | 833 HttpRequestHeaders headers; |
831 headers.SetHeader(HttpRequestHeaders::kRange, | 834 headers.SetHeader(HttpRequestHeaders::kRange, |
832 "bytes=0-0,10-200,200-300"); | 835 "bytes=0-0,10-200,200-300"); |
833 r.SetExtraRequestHeaders(headers); | 836 r.SetExtraRequestHeaders(headers); |
834 r.Start(); | 837 r.Start(); |
835 EXPECT_TRUE(r.is_pending()); | 838 EXPECT_TRUE(r.is_pending()); |
836 | 839 |
837 base::MessageLoop::current()->Run(); | 840 base::RunLoop().Run(); |
838 EXPECT_TRUE(d.request_failed()); | 841 EXPECT_TRUE(d.request_failed()); |
839 } | 842 } |
840 | 843 |
841 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 844 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
842 } | 845 } |
843 | 846 |
844 TEST_F(URLRequestTest, InvalidUrlTest) { | 847 TEST_F(URLRequestTest, InvalidUrlTest) { |
845 TestDelegate d; | 848 TestDelegate d; |
846 { | 849 { |
847 URLRequest r(GURL("invalid url"), &d, &default_context_); | 850 URLRequest r(GURL("invalid url"), &d, &default_context_); |
848 | 851 |
849 r.Start(); | 852 r.Start(); |
850 EXPECT_TRUE(r.is_pending()); | 853 EXPECT_TRUE(r.is_pending()); |
851 | 854 |
852 base::MessageLoop::current()->Run(); | 855 base::RunLoop().Run(); |
853 EXPECT_TRUE(d.request_failed()); | 856 EXPECT_TRUE(d.request_failed()); |
854 } | 857 } |
855 } | 858 } |
856 | 859 |
857 #if defined(OS_WIN) | 860 #if defined(OS_WIN) |
858 TEST_F(URLRequestTest, ResolveShortcutTest) { | 861 TEST_F(URLRequestTest, ResolveShortcutTest) { |
859 base::FilePath app_path; | 862 base::FilePath app_path; |
860 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 863 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
861 app_path = app_path.AppendASCII("net"); | 864 app_path = app_path.AppendASCII("net"); |
862 app_path = app_path.AppendASCII("data"); | 865 app_path = app_path.AppendASCII("data"); |
(...skipping 17 matching lines...) Expand all Loading... |
880 } | 883 } |
881 | 884 |
882 TestDelegate d; | 885 TestDelegate d; |
883 { | 886 { |
884 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), &d, | 887 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), &d, |
885 &default_context_); | 888 &default_context_); |
886 | 889 |
887 r.Start(); | 890 r.Start(); |
888 EXPECT_TRUE(r.is_pending()); | 891 EXPECT_TRUE(r.is_pending()); |
889 | 892 |
890 base::MessageLoop::current()->Run(); | 893 base::RunLoop().Run(); |
891 | 894 |
892 WIN32_FILE_ATTRIBUTE_DATA data; | 895 WIN32_FILE_ATTRIBUTE_DATA data; |
893 GetFileAttributesEx(app_path.value().c_str(), | 896 GetFileAttributesEx(app_path.value().c_str(), |
894 GetFileExInfoStandard, &data); | 897 GetFileExInfoStandard, &data); |
895 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 898 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
896 FILE_SHARE_READ, NULL, OPEN_EXISTING, | 899 FILE_SHARE_READ, NULL, OPEN_EXISTING, |
897 FILE_ATTRIBUTE_NORMAL, NULL); | 900 FILE_ATTRIBUTE_NORMAL, NULL); |
898 EXPECT_NE(INVALID_HANDLE_VALUE, file); | 901 EXPECT_NE(INVALID_HANDLE_VALUE, file); |
899 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); | 902 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); |
900 DWORD read_size; | 903 DWORD read_size; |
(...skipping 23 matching lines...) Expand all Loading... |
924 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 927 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
925 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 928 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
926 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 929 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
927 | 930 |
928 URLRequest req(FilePathToFileURL(file_path), &d, &default_context_); | 931 URLRequest req(FilePathToFileURL(file_path), &d, &default_context_); |
929 req.Start(); | 932 req.Start(); |
930 EXPECT_TRUE(req.is_pending()); | 933 EXPECT_TRUE(req.is_pending()); |
931 | 934 |
932 d.set_cancel_in_received_data_pending(true); | 935 d.set_cancel_in_received_data_pending(true); |
933 | 936 |
934 base::MessageLoop::current()->Run(); | 937 base::RunLoop().Run(); |
935 } | 938 } |
936 | 939 |
937 // Take out mock resource provider. | 940 // Take out mock resource provider. |
938 NetModule::SetResourceProvider(NULL); | 941 NetModule::SetResourceProvider(NULL); |
939 } | 942 } |
940 | 943 |
941 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 944 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
942 // There is an implicit redirect when loading a file path that matches a | 945 // There is an implicit redirect when loading a file path that matches a |
943 // directory and does not end with a slash. Ensure that following such | 946 // directory and does not end with a slash. Ensure that following such |
944 // redirects does not crash. See http://crbug.com/18686. | 947 // redirects does not crash. See http://crbug.com/18686. |
945 | 948 |
946 base::FilePath path; | 949 base::FilePath path; |
947 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 950 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
948 path = path.Append(FILE_PATH_LITERAL("net")); | 951 path = path.Append(FILE_PATH_LITERAL("net")); |
949 path = path.Append(FILE_PATH_LITERAL("data")); | 952 path = path.Append(FILE_PATH_LITERAL("data")); |
950 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 953 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
951 | 954 |
952 TestDelegate d; | 955 TestDelegate d; |
953 URLRequest req(FilePathToFileURL(path), &d, &default_context_); | 956 URLRequest req(FilePathToFileURL(path), &d, &default_context_); |
954 req.Start(); | 957 req.Start(); |
955 base::MessageLoop::current()->Run(); | 958 base::RunLoop().Run(); |
956 | 959 |
957 ASSERT_EQ(1, d.received_redirect_count()); | 960 ASSERT_EQ(1, d.received_redirect_count()); |
958 ASSERT_LT(0, d.bytes_received()); | 961 ASSERT_LT(0, d.bytes_received()); |
959 ASSERT_FALSE(d.request_failed()); | 962 ASSERT_FALSE(d.request_failed()); |
960 ASSERT_TRUE(req.status().is_success()); | 963 ASSERT_TRUE(req.status().is_success()); |
961 } | 964 } |
962 | 965 |
963 #if defined(OS_WIN) | 966 #if defined(OS_WIN) |
964 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 967 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
965 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 968 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
966 TestDelegate d; | 969 TestDelegate d; |
967 URLRequest req(GURL("file:///"), &d, &default_context_); | 970 URLRequest req(GURL("file:///"), &d, &default_context_); |
968 req.Start(); | 971 req.Start(); |
969 base::MessageLoop::current()->Run(); | 972 base::RunLoop().Run(); |
970 | 973 |
971 ASSERT_EQ(1, d.received_redirect_count()); | 974 ASSERT_EQ(1, d.received_redirect_count()); |
972 ASSERT_FALSE(req.status().is_success()); | 975 ASSERT_FALSE(req.status().is_success()); |
973 } | 976 } |
974 #endif | 977 #endif |
975 | 978 |
976 // Custom URLRequestJobs for use with interceptor tests | 979 // Custom URLRequestJobs for use with interceptor tests |
977 class RestartTestJob : public URLRequestTestJob { | 980 class RestartTestJob : public URLRequestTestJob { |
978 public: | 981 public: |
979 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate) | 982 RestartTestJob(URLRequest* request, NetworkDelegate* network_delegate) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 TestDelegate d; | 1190 TestDelegate d; |
1188 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1191 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1189 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 1192 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
1190 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 1193 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
1191 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 1194 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
1192 req.SetUserData(NULL, user_data0); | 1195 req.SetUserData(NULL, user_data0); |
1193 req.SetUserData(&user_data1, user_data1); | 1196 req.SetUserData(&user_data1, user_data1); |
1194 req.SetUserData(&user_data2, user_data2); | 1197 req.SetUserData(&user_data2, user_data2); |
1195 req.set_method("GET"); | 1198 req.set_method("GET"); |
1196 req.Start(); | 1199 req.Start(); |
1197 base::MessageLoop::current()->Run(); | 1200 base::RunLoop().Run(); |
1198 | 1201 |
1199 // Make sure we can retrieve our specific user data | 1202 // Make sure we can retrieve our specific user data |
1200 EXPECT_EQ(user_data0, req.GetUserData(NULL)); | 1203 EXPECT_EQ(user_data0, req.GetUserData(NULL)); |
1201 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); | 1204 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); |
1202 EXPECT_EQ(user_data2, req.GetUserData(&user_data2)); | 1205 EXPECT_EQ(user_data2, req.GetUserData(&user_data2)); |
1203 | 1206 |
1204 // Check the interceptor got called as expected | 1207 // Check the interceptor got called as expected |
1205 EXPECT_TRUE(interceptor.did_intercept_main_); | 1208 EXPECT_TRUE(interceptor.did_intercept_main_); |
1206 | 1209 |
1207 // Check we got one good response | 1210 // Check we got one good response |
(...skipping 14 matching lines...) Expand all Loading... |
1222 | 1225 |
1223 // intercept that redirect and respond a final OK response | 1226 // intercept that redirect and respond a final OK response |
1224 interceptor.intercept_redirect_ = true; | 1227 interceptor.intercept_redirect_ = true; |
1225 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 1228 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
1226 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 1229 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
1227 | 1230 |
1228 TestDelegate d; | 1231 TestDelegate d; |
1229 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1232 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1230 req.set_method("GET"); | 1233 req.set_method("GET"); |
1231 req.Start(); | 1234 req.Start(); |
1232 base::MessageLoop::current()->Run(); | 1235 base::RunLoop().Run(); |
1233 | 1236 |
1234 // Check the interceptor got called as expected | 1237 // Check the interceptor got called as expected |
1235 EXPECT_TRUE(interceptor.did_intercept_main_); | 1238 EXPECT_TRUE(interceptor.did_intercept_main_); |
1236 EXPECT_TRUE(interceptor.did_intercept_redirect_); | 1239 EXPECT_TRUE(interceptor.did_intercept_redirect_); |
1237 | 1240 |
1238 // Check we got one good response | 1241 // Check we got one good response |
1239 EXPECT_TRUE(req.status().is_success()); | 1242 EXPECT_TRUE(req.status().is_success()); |
1240 if (req.status().is_success()) { | 1243 if (req.status().is_success()) { |
1241 EXPECT_EQ(200, req.response_headers()->response_code()); | 1244 EXPECT_EQ(200, req.response_headers()->response_code()); |
1242 } | 1245 } |
(...skipping 12 matching lines...) Expand all Loading... |
1255 | 1258 |
1256 // intercept that error and respond with an OK response | 1259 // intercept that error and respond with an OK response |
1257 interceptor.intercept_final_response_ = true; | 1260 interceptor.intercept_final_response_ = true; |
1258 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1261 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
1259 interceptor.final_data_ = TestInterceptor::ok_data(); | 1262 interceptor.final_data_ = TestInterceptor::ok_data(); |
1260 | 1263 |
1261 TestDelegate d; | 1264 TestDelegate d; |
1262 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1265 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1263 req.set_method("GET"); | 1266 req.set_method("GET"); |
1264 req.Start(); | 1267 req.Start(); |
1265 base::MessageLoop::current()->Run(); | 1268 base::RunLoop().Run(); |
1266 | 1269 |
1267 // Check the interceptor got called as expected | 1270 // Check the interceptor got called as expected |
1268 EXPECT_TRUE(interceptor.did_intercept_main_); | 1271 EXPECT_TRUE(interceptor.did_intercept_main_); |
1269 EXPECT_TRUE(interceptor.did_intercept_final_); | 1272 EXPECT_TRUE(interceptor.did_intercept_final_); |
1270 | 1273 |
1271 // Check we got one good response | 1274 // Check we got one good response |
1272 EXPECT_TRUE(req.status().is_success()); | 1275 EXPECT_TRUE(req.status().is_success()); |
1273 EXPECT_EQ(200, req.response_headers()->response_code()); | 1276 EXPECT_EQ(200, req.response_headers()->response_code()); |
1274 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1277 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
1275 EXPECT_EQ(1, d.response_started_count()); | 1278 EXPECT_EQ(1, d.response_started_count()); |
1276 EXPECT_EQ(0, d.received_redirect_count()); | 1279 EXPECT_EQ(0, d.received_redirect_count()); |
1277 } | 1280 } |
1278 | 1281 |
1279 TEST_F(URLRequestTest, InterceptNetworkError) { | 1282 TEST_F(URLRequestTest, InterceptNetworkError) { |
1280 TestInterceptor interceptor; | 1283 TestInterceptor interceptor; |
1281 | 1284 |
1282 // intercept the main request to simulate a network error | 1285 // intercept the main request to simulate a network error |
1283 interceptor.simulate_main_network_error_ = true; | 1286 interceptor.simulate_main_network_error_ = true; |
1284 | 1287 |
1285 // intercept that error and respond with an OK response | 1288 // intercept that error and respond with an OK response |
1286 interceptor.intercept_final_response_ = true; | 1289 interceptor.intercept_final_response_ = true; |
1287 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1290 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
1288 interceptor.final_data_ = TestInterceptor::ok_data(); | 1291 interceptor.final_data_ = TestInterceptor::ok_data(); |
1289 | 1292 |
1290 TestDelegate d; | 1293 TestDelegate d; |
1291 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1294 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1292 req.set_method("GET"); | 1295 req.set_method("GET"); |
1293 req.Start(); | 1296 req.Start(); |
1294 base::MessageLoop::current()->Run(); | 1297 base::RunLoop().Run(); |
1295 | 1298 |
1296 // Check the interceptor got called as expected | 1299 // Check the interceptor got called as expected |
1297 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1300 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
1298 EXPECT_TRUE(interceptor.did_intercept_final_); | 1301 EXPECT_TRUE(interceptor.did_intercept_final_); |
1299 | 1302 |
1300 // Check we received one good response | 1303 // Check we received one good response |
1301 EXPECT_TRUE(req.status().is_success()); | 1304 EXPECT_TRUE(req.status().is_success()); |
1302 EXPECT_EQ(200, req.response_headers()->response_code()); | 1305 EXPECT_EQ(200, req.response_headers()->response_code()); |
1303 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1306 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
1304 EXPECT_EQ(1, d.response_started_count()); | 1307 EXPECT_EQ(1, d.response_started_count()); |
1305 EXPECT_EQ(0, d.received_redirect_count()); | 1308 EXPECT_EQ(0, d.received_redirect_count()); |
1306 } | 1309 } |
1307 | 1310 |
1308 TEST_F(URLRequestTest, InterceptRestartRequired) { | 1311 TEST_F(URLRequestTest, InterceptRestartRequired) { |
1309 TestInterceptor interceptor; | 1312 TestInterceptor interceptor; |
1310 | 1313 |
1311 // restart the main request | 1314 // restart the main request |
1312 interceptor.restart_main_request_ = true; | 1315 interceptor.restart_main_request_ = true; |
1313 | 1316 |
1314 // then intercept the new main request and respond with an OK response | 1317 // then intercept the new main request and respond with an OK response |
1315 interceptor.intercept_main_request_ = true; | 1318 interceptor.intercept_main_request_ = true; |
1316 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 1319 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
1317 interceptor.main_data_ = TestInterceptor::ok_data(); | 1320 interceptor.main_data_ = TestInterceptor::ok_data(); |
1318 | 1321 |
1319 TestDelegate d; | 1322 TestDelegate d; |
1320 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1323 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1321 req.set_method("GET"); | 1324 req.set_method("GET"); |
1322 req.Start(); | 1325 req.Start(); |
1323 base::MessageLoop::current()->Run(); | 1326 base::RunLoop().Run(); |
1324 | 1327 |
1325 // Check the interceptor got called as expected | 1328 // Check the interceptor got called as expected |
1326 EXPECT_TRUE(interceptor.did_restart_main_); | 1329 EXPECT_TRUE(interceptor.did_restart_main_); |
1327 EXPECT_TRUE(interceptor.did_intercept_main_); | 1330 EXPECT_TRUE(interceptor.did_intercept_main_); |
1328 | 1331 |
1329 // Check we received one good response | 1332 // Check we received one good response |
1330 EXPECT_TRUE(req.status().is_success()); | 1333 EXPECT_TRUE(req.status().is_success()); |
1331 if (req.status().is_success()) { | 1334 if (req.status().is_success()) { |
1332 EXPECT_EQ(200, req.response_headers()->response_code()); | 1335 EXPECT_EQ(200, req.response_headers()->response_code()); |
1333 } | 1336 } |
(...skipping 10 matching lines...) Expand all Loading... |
1344 | 1347 |
1345 // setup to intercept final response and override it with an OK response | 1348 // setup to intercept final response and override it with an OK response |
1346 interceptor.intercept_final_response_ = true; | 1349 interceptor.intercept_final_response_ = true; |
1347 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1350 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
1348 interceptor.final_data_ = TestInterceptor::ok_data(); | 1351 interceptor.final_data_ = TestInterceptor::ok_data(); |
1349 | 1352 |
1350 TestDelegate d; | 1353 TestDelegate d; |
1351 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1354 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1352 req.set_method("GET"); | 1355 req.set_method("GET"); |
1353 req.Start(); | 1356 req.Start(); |
1354 base::MessageLoop::current()->Run(); | 1357 base::RunLoop().Run(); |
1355 | 1358 |
1356 // Check the interceptor got called as expected | 1359 // Check the interceptor got called as expected |
1357 EXPECT_TRUE(interceptor.did_cancel_main_); | 1360 EXPECT_TRUE(interceptor.did_cancel_main_); |
1358 EXPECT_FALSE(interceptor.did_intercept_final_); | 1361 EXPECT_FALSE(interceptor.did_intercept_final_); |
1359 | 1362 |
1360 // Check we see a canceled request | 1363 // Check we see a canceled request |
1361 EXPECT_FALSE(req.status().is_success()); | 1364 EXPECT_FALSE(req.status().is_success()); |
1362 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1365 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1363 } | 1366 } |
1364 | 1367 |
(...skipping 10 matching lines...) Expand all Loading... |
1375 | 1378 |
1376 // setup to intercept final response and override it with an OK response | 1379 // setup to intercept final response and override it with an OK response |
1377 interceptor.intercept_final_response_ = true; | 1380 interceptor.intercept_final_response_ = true; |
1378 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1381 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
1379 interceptor.final_data_ = TestInterceptor::ok_data(); | 1382 interceptor.final_data_ = TestInterceptor::ok_data(); |
1380 | 1383 |
1381 TestDelegate d; | 1384 TestDelegate d; |
1382 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1385 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1383 req.set_method("GET"); | 1386 req.set_method("GET"); |
1384 req.Start(); | 1387 req.Start(); |
1385 base::MessageLoop::current()->Run(); | 1388 base::RunLoop().Run(); |
1386 | 1389 |
1387 // Check the interceptor got called as expected | 1390 // Check the interceptor got called as expected |
1388 EXPECT_TRUE(interceptor.did_intercept_main_); | 1391 EXPECT_TRUE(interceptor.did_intercept_main_); |
1389 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 1392 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
1390 EXPECT_FALSE(interceptor.did_intercept_final_); | 1393 EXPECT_FALSE(interceptor.did_intercept_final_); |
1391 | 1394 |
1392 // Check we see a canceled request | 1395 // Check we see a canceled request |
1393 EXPECT_FALSE(req.status().is_success()); | 1396 EXPECT_FALSE(req.status().is_success()); |
1394 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1397 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1395 } | 1398 } |
1396 | 1399 |
1397 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 1400 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
1398 TestInterceptor interceptor; | 1401 TestInterceptor interceptor; |
1399 | 1402 |
1400 // intercept the main request to simulate a network error | 1403 // intercept the main request to simulate a network error |
1401 interceptor.simulate_main_network_error_ = true; | 1404 interceptor.simulate_main_network_error_ = true; |
1402 | 1405 |
1403 // setup to intercept final response and cancel from within that job | 1406 // setup to intercept final response and cancel from within that job |
1404 interceptor.cancel_final_request_ = true; | 1407 interceptor.cancel_final_request_ = true; |
1405 | 1408 |
1406 TestDelegate d; | 1409 TestDelegate d; |
1407 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1410 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1408 req.set_method("GET"); | 1411 req.set_method("GET"); |
1409 req.Start(); | 1412 req.Start(); |
1410 base::MessageLoop::current()->Run(); | 1413 base::RunLoop().Run(); |
1411 | 1414 |
1412 // Check the interceptor got called as expected | 1415 // Check the interceptor got called as expected |
1413 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1416 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
1414 EXPECT_TRUE(interceptor.did_cancel_final_); | 1417 EXPECT_TRUE(interceptor.did_cancel_final_); |
1415 | 1418 |
1416 // Check we see a canceled request | 1419 // Check we see a canceled request |
1417 EXPECT_FALSE(req.status().is_success()); | 1420 EXPECT_FALSE(req.status().is_success()); |
1418 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1421 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1419 } | 1422 } |
1420 | 1423 |
1421 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 1424 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
1422 TestInterceptor interceptor; | 1425 TestInterceptor interceptor; |
1423 | 1426 |
1424 // intercept the main request and cancel then restart from within that job | 1427 // intercept the main request and cancel then restart from within that job |
1425 interceptor.cancel_then_restart_main_request_ = true; | 1428 interceptor.cancel_then_restart_main_request_ = true; |
1426 | 1429 |
1427 // setup to intercept final response and override it with an OK response | 1430 // setup to intercept final response and override it with an OK response |
1428 interceptor.intercept_final_response_ = true; | 1431 interceptor.intercept_final_response_ = true; |
1429 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1432 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
1430 interceptor.final_data_ = TestInterceptor::ok_data(); | 1433 interceptor.final_data_ = TestInterceptor::ok_data(); |
1431 | 1434 |
1432 TestDelegate d; | 1435 TestDelegate d; |
1433 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1436 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1434 req.set_method("GET"); | 1437 req.set_method("GET"); |
1435 req.Start(); | 1438 req.Start(); |
1436 base::MessageLoop::current()->Run(); | 1439 base::RunLoop().Run(); |
1437 | 1440 |
1438 // Check the interceptor got called as expected | 1441 // Check the interceptor got called as expected |
1439 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 1442 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
1440 EXPECT_FALSE(interceptor.did_intercept_final_); | 1443 EXPECT_FALSE(interceptor.did_intercept_final_); |
1441 | 1444 |
1442 // Check we see a canceled request | 1445 // Check we see a canceled request |
1443 EXPECT_FALSE(req.status().is_success()); | 1446 EXPECT_FALSE(req.status().is_success()); |
1444 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1447 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1445 } | 1448 } |
1446 | 1449 |
1447 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, | 1450 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, |
1448 URLRequestContext* context) { | 1451 URLRequestContext* context) { |
1449 TestInterceptor interceptor; | 1452 TestInterceptor interceptor; |
1450 interceptor.intercept_main_request_ = true; | 1453 interceptor.intercept_main_request_ = true; |
1451 interceptor.main_request_load_timing_info_ = job_load_timing; | 1454 interceptor.main_request_load_timing_info_ = job_load_timing; |
1452 TestDelegate d; | 1455 TestDelegate d; |
1453 URLRequest req(GURL("http://test_intercept/foo"), &d, context); | 1456 URLRequest req(GURL("http://test_intercept/foo"), &d, context); |
1454 req.Start(); | 1457 req.Start(); |
1455 base::MessageLoop::current()->Run(); | 1458 base::RunLoop().Run(); |
1456 | 1459 |
1457 LoadTimingInfo resulting_load_timing; | 1460 LoadTimingInfo resulting_load_timing; |
1458 req.GetLoadTimingInfo(&resulting_load_timing); | 1461 req.GetLoadTimingInfo(&resulting_load_timing); |
1459 | 1462 |
1460 // None of these should be modified by the URLRequest. | 1463 // None of these should be modified by the URLRequest. |
1461 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); | 1464 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); |
1462 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); | 1465 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); |
1463 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); | 1466 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); |
1464 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); | 1467 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); |
1465 EXPECT_EQ(job_load_timing.receive_headers_end, | 1468 EXPECT_EQ(job_load_timing.receive_headers_end, |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 host_resolver.rules()->AddSimulatedFailure("*"); | 1725 host_resolver.rules()->AddSimulatedFailure("*"); |
1723 | 1726 |
1724 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 1727 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
1725 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); | 1728 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); |
1726 | 1729 |
1727 TestDelegate d; | 1730 TestDelegate d; |
1728 URLRequest req(GURL("http://example.com"), &d, &context); | 1731 URLRequest req(GURL("http://example.com"), &d, &context); |
1729 req.set_method("GET"); | 1732 req.set_method("GET"); |
1730 | 1733 |
1731 req.Start(); | 1734 req.Start(); |
1732 base::MessageLoop::current()->Run(); | 1735 base::RunLoop().Run(); |
1733 | 1736 |
1734 // Check we see a failed request. | 1737 // Check we see a failed request. |
1735 EXPECT_FALSE(req.status().is_success()); | 1738 EXPECT_FALSE(req.status().is_success()); |
1736 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1739 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
1737 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); | 1740 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); |
1738 | 1741 |
1739 EXPECT_EQ(1, network_delegate.error_count()); | 1742 EXPECT_EQ(1, network_delegate.error_count()); |
1740 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); | 1743 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
1741 EXPECT_EQ(1, network_delegate.completed_requests()); | 1744 EXPECT_EQ(1, network_delegate.completed_requests()); |
1742 } | 1745 } |
1743 | 1746 |
1744 // Make sure that net::NetworkDelegate::NotifyCompleted is called if | 1747 // Make sure that net::NetworkDelegate::NotifyCompleted is called if |
1745 // content is empty. | 1748 // content is empty. |
1746 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 1749 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
1747 TestDelegate d; | 1750 TestDelegate d; |
1748 URLRequest req(GURL("data:,"), &d, &default_context_); | 1751 URLRequest req(GURL("data:,"), &d, &default_context_); |
1749 req.Start(); | 1752 req.Start(); |
1750 base::MessageLoop::current()->Run(); | 1753 base::RunLoop().Run(); |
1751 EXPECT_EQ("", d.data_received()); | 1754 EXPECT_EQ("", d.data_received()); |
1752 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 1755 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
1753 } | 1756 } |
1754 | 1757 |
1755 // Make sure that SetPriority actually sets the URLRequest's priority | 1758 // Make sure that SetPriority actually sets the URLRequest's priority |
1756 // correctly, both before and after start. | 1759 // correctly, both before and after start. |
1757 TEST_F(URLRequestTest, SetPriorityBasic) { | 1760 TEST_F(URLRequestTest, SetPriorityBasic) { |
1758 TestDelegate d; | 1761 TestDelegate d; |
1759 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1762 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
1760 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 1763 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 context.set_cookie_store(delayed_cm.get()); | 1837 context.set_cookie_store(delayed_cm.get()); |
1835 | 1838 |
1836 // Set up a cookie. | 1839 // Set up a cookie. |
1837 { | 1840 { |
1838 TestNetworkDelegate network_delegate; | 1841 TestNetworkDelegate network_delegate; |
1839 context.set_network_delegate(&network_delegate); | 1842 context.set_network_delegate(&network_delegate); |
1840 TestDelegate d; | 1843 TestDelegate d; |
1841 URLRequest req( | 1844 URLRequest req( |
1842 test_server.GetURL("set-cookie?CookieToNotSend=1"), &d, &context); | 1845 test_server.GetURL("set-cookie?CookieToNotSend=1"), &d, &context); |
1843 req.Start(); | 1846 req.Start(); |
1844 base::MessageLoop::current()->Run(); | 1847 base::RunLoop().Run(); |
1845 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1848 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1846 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1849 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1847 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 1850 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
1848 } | 1851 } |
1849 | 1852 |
1850 // Verify that the cookie is set. | 1853 // Verify that the cookie is set. |
1851 { | 1854 { |
1852 TestNetworkDelegate network_delegate; | 1855 TestNetworkDelegate network_delegate; |
1853 context.set_network_delegate(&network_delegate); | 1856 context.set_network_delegate(&network_delegate); |
1854 TestDelegate d; | 1857 TestDelegate d; |
1855 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d, &context); | 1858 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d, &context); |
1856 req.Start(); | 1859 req.Start(); |
1857 base::MessageLoop::current()->Run(); | 1860 base::RunLoop().Run(); |
1858 | 1861 |
1859 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 1862 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
1860 != std::string::npos); | 1863 != std::string::npos); |
1861 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1864 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1862 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1865 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1863 } | 1866 } |
1864 } | 1867 } |
1865 | 1868 |
1866 TEST_F(URLRequestTest, DoNotSendCookies) { | 1869 TEST_F(URLRequestTest, DoNotSendCookies) { |
1867 LocalHttpTestServer test_server; | 1870 LocalHttpTestServer test_server; |
1868 ASSERT_TRUE(test_server.Start()); | 1871 ASSERT_TRUE(test_server.Start()); |
1869 | 1872 |
1870 // Set up a cookie. | 1873 // Set up a cookie. |
1871 { | 1874 { |
1872 TestNetworkDelegate network_delegate; | 1875 TestNetworkDelegate network_delegate; |
1873 default_context_.set_network_delegate(&network_delegate); | 1876 default_context_.set_network_delegate(&network_delegate); |
1874 TestDelegate d; | 1877 TestDelegate d; |
1875 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 1878 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
1876 &d, | 1879 &d, |
1877 &default_context_); | 1880 &default_context_); |
1878 req.Start(); | 1881 req.Start(); |
1879 base::MessageLoop::current()->Run(); | 1882 base::RunLoop().Run(); |
1880 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1883 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1881 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1884 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1882 } | 1885 } |
1883 | 1886 |
1884 // Verify that the cookie is set. | 1887 // Verify that the cookie is set. |
1885 { | 1888 { |
1886 TestNetworkDelegate network_delegate; | 1889 TestNetworkDelegate network_delegate; |
1887 default_context_.set_network_delegate(&network_delegate); | 1890 default_context_.set_network_delegate(&network_delegate); |
1888 TestDelegate d; | 1891 TestDelegate d; |
1889 URLRequest req( | 1892 URLRequest req( |
1890 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 1893 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
1891 req.Start(); | 1894 req.Start(); |
1892 base::MessageLoop::current()->Run(); | 1895 base::RunLoop().Run(); |
1893 | 1896 |
1894 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 1897 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
1895 != std::string::npos); | 1898 != std::string::npos); |
1896 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1899 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1897 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1900 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1898 } | 1901 } |
1899 | 1902 |
1900 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 1903 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
1901 { | 1904 { |
1902 TestNetworkDelegate network_delegate; | 1905 TestNetworkDelegate network_delegate; |
1903 default_context_.set_network_delegate(&network_delegate); | 1906 default_context_.set_network_delegate(&network_delegate); |
1904 TestDelegate d; | 1907 TestDelegate d; |
1905 URLRequest req( | 1908 URLRequest req( |
1906 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 1909 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
1907 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); | 1910 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); |
1908 req.Start(); | 1911 req.Start(); |
1909 base::MessageLoop::current()->Run(); | 1912 base::RunLoop().Run(); |
1910 | 1913 |
1911 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1914 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
1912 == std::string::npos); | 1915 == std::string::npos); |
1913 | 1916 |
1914 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1917 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
1915 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1918 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1916 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1919 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1917 } | 1920 } |
1918 } | 1921 } |
1919 | 1922 |
1920 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1923 TEST_F(URLRequestTest, DoNotSaveCookies) { |
1921 LocalHttpTestServer test_server; | 1924 LocalHttpTestServer test_server; |
1922 ASSERT_TRUE(test_server.Start()); | 1925 ASSERT_TRUE(test_server.Start()); |
1923 | 1926 |
1924 // Set up a cookie. | 1927 // Set up a cookie. |
1925 { | 1928 { |
1926 TestNetworkDelegate network_delegate; | 1929 TestNetworkDelegate network_delegate; |
1927 default_context_.set_network_delegate(&network_delegate); | 1930 default_context_.set_network_delegate(&network_delegate); |
1928 TestDelegate d; | 1931 TestDelegate d; |
1929 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1932 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1930 &d, | 1933 &d, |
1931 &default_context_); | 1934 &default_context_); |
1932 req.Start(); | 1935 req.Start(); |
1933 base::MessageLoop::current()->Run(); | 1936 base::RunLoop().Run(); |
1934 | 1937 |
1935 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1938 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1936 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1939 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1937 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 1940 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
1938 } | 1941 } |
1939 | 1942 |
1940 // Try to set-up another cookie and update the previous cookie. | 1943 // Try to set-up another cookie and update the previous cookie. |
1941 { | 1944 { |
1942 TestNetworkDelegate network_delegate; | 1945 TestNetworkDelegate network_delegate; |
1943 default_context_.set_network_delegate(&network_delegate); | 1946 default_context_.set_network_delegate(&network_delegate); |
1944 TestDelegate d; | 1947 TestDelegate d; |
1945 URLRequest req( | 1948 URLRequest req( |
1946 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 1949 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
1947 &d, | 1950 &d, |
1948 &default_context_); | 1951 &default_context_); |
1949 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); | 1952 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); |
1950 req.Start(); | 1953 req.Start(); |
1951 | 1954 |
1952 base::MessageLoop::current()->Run(); | 1955 base::RunLoop().Run(); |
1953 | 1956 |
1954 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 1957 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
1955 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1958 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1956 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1959 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1957 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 1960 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
1958 } | 1961 } |
1959 | 1962 |
1960 // Verify the cookies weren't saved or updated. | 1963 // Verify the cookies weren't saved or updated. |
1961 { | 1964 { |
1962 TestNetworkDelegate network_delegate; | 1965 TestNetworkDelegate network_delegate; |
1963 default_context_.set_network_delegate(&network_delegate); | 1966 default_context_.set_network_delegate(&network_delegate); |
1964 TestDelegate d; | 1967 TestDelegate d; |
1965 URLRequest req( | 1968 URLRequest req( |
1966 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 1969 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
1967 req.Start(); | 1970 req.Start(); |
1968 base::MessageLoop::current()->Run(); | 1971 base::RunLoop().Run(); |
1969 | 1972 |
1970 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 1973 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
1971 == std::string::npos); | 1974 == std::string::npos); |
1972 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1975 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1973 != std::string::npos); | 1976 != std::string::npos); |
1974 | 1977 |
1975 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1978 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1976 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1979 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1977 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 1980 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
1978 } | 1981 } |
1979 } | 1982 } |
1980 | 1983 |
1981 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1984 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
1982 LocalHttpTestServer test_server; | 1985 LocalHttpTestServer test_server; |
1983 ASSERT_TRUE(test_server.Start()); | 1986 ASSERT_TRUE(test_server.Start()); |
1984 | 1987 |
1985 // Set up a cookie. | 1988 // Set up a cookie. |
1986 { | 1989 { |
1987 TestNetworkDelegate network_delegate; | 1990 TestNetworkDelegate network_delegate; |
1988 default_context_.set_network_delegate(&network_delegate); | 1991 default_context_.set_network_delegate(&network_delegate); |
1989 TestDelegate d; | 1992 TestDelegate d; |
1990 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 1993 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
1991 &d, | 1994 &d, |
1992 &default_context_); | 1995 &default_context_); |
1993 req.Start(); | 1996 req.Start(); |
1994 base::MessageLoop::current()->Run(); | 1997 base::RunLoop().Run(); |
1995 | 1998 |
1996 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1999 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
1997 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2000 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
1998 } | 2001 } |
1999 | 2002 |
2000 // Verify that the cookie is set. | 2003 // Verify that the cookie is set. |
2001 { | 2004 { |
2002 TestNetworkDelegate network_delegate; | 2005 TestNetworkDelegate network_delegate; |
2003 default_context_.set_network_delegate(&network_delegate); | 2006 default_context_.set_network_delegate(&network_delegate); |
2004 TestDelegate d; | 2007 TestDelegate d; |
2005 URLRequest req( | 2008 URLRequest req( |
2006 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2009 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2007 req.Start(); | 2010 req.Start(); |
2008 base::MessageLoop::current()->Run(); | 2011 base::RunLoop().Run(); |
2009 | 2012 |
2010 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2013 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
2011 != std::string::npos); | 2014 != std::string::npos); |
2012 | 2015 |
2013 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2016 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2014 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2017 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2015 } | 2018 } |
2016 | 2019 |
2017 // Verify that the cookie isn't sent. | 2020 // Verify that the cookie isn't sent. |
2018 { | 2021 { |
2019 TestNetworkDelegate network_delegate; | 2022 TestNetworkDelegate network_delegate; |
2020 default_context_.set_network_delegate(&network_delegate); | 2023 default_context_.set_network_delegate(&network_delegate); |
2021 TestDelegate d; | 2024 TestDelegate d; |
2022 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2025 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
2023 URLRequest req( | 2026 URLRequest req( |
2024 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2027 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2025 req.Start(); | 2028 req.Start(); |
2026 base::MessageLoop::current()->Run(); | 2029 base::RunLoop().Run(); |
2027 | 2030 |
2028 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2031 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
2029 == std::string::npos); | 2032 == std::string::npos); |
2030 | 2033 |
2031 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2034 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
2032 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2035 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2033 } | 2036 } |
2034 } | 2037 } |
2035 | 2038 |
2036 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2039 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
2037 LocalHttpTestServer test_server; | 2040 LocalHttpTestServer test_server; |
2038 ASSERT_TRUE(test_server.Start()); | 2041 ASSERT_TRUE(test_server.Start()); |
2039 | 2042 |
2040 // Set up a cookie. | 2043 // Set up a cookie. |
2041 { | 2044 { |
2042 TestNetworkDelegate network_delegate; | 2045 TestNetworkDelegate network_delegate; |
2043 default_context_.set_network_delegate(&network_delegate); | 2046 default_context_.set_network_delegate(&network_delegate); |
2044 TestDelegate d; | 2047 TestDelegate d; |
2045 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2048 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
2046 &d, | 2049 &d, |
2047 &default_context_); | 2050 &default_context_); |
2048 req.Start(); | 2051 req.Start(); |
2049 base::MessageLoop::current()->Run(); | 2052 base::RunLoop().Run(); |
2050 | 2053 |
2051 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2054 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2052 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2055 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2053 } | 2056 } |
2054 | 2057 |
2055 // Try to set-up another cookie and update the previous cookie. | 2058 // Try to set-up another cookie and update the previous cookie. |
2056 { | 2059 { |
2057 TestNetworkDelegate network_delegate; | 2060 TestNetworkDelegate network_delegate; |
2058 default_context_.set_network_delegate(&network_delegate); | 2061 default_context_.set_network_delegate(&network_delegate); |
2059 TestDelegate d; | 2062 TestDelegate d; |
2060 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2063 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
2061 URLRequest req( | 2064 URLRequest req( |
2062 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2065 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
2063 &d, | 2066 &d, |
2064 &default_context_); | 2067 &default_context_); |
2065 req.Start(); | 2068 req.Start(); |
2066 | 2069 |
2067 base::MessageLoop::current()->Run(); | 2070 base::RunLoop().Run(); |
2068 | 2071 |
2069 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2072 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2070 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2073 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
2071 } | 2074 } |
2072 | 2075 |
2073 // Verify the cookies weren't saved or updated. | 2076 // Verify the cookies weren't saved or updated. |
2074 { | 2077 { |
2075 TestNetworkDelegate network_delegate; | 2078 TestNetworkDelegate network_delegate; |
2076 default_context_.set_network_delegate(&network_delegate); | 2079 default_context_.set_network_delegate(&network_delegate); |
2077 TestDelegate d; | 2080 TestDelegate d; |
2078 URLRequest req( | 2081 URLRequest req( |
2079 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2082 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2080 req.Start(); | 2083 req.Start(); |
2081 base::MessageLoop::current()->Run(); | 2084 base::RunLoop().Run(); |
2082 | 2085 |
2083 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2086 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
2084 == std::string::npos); | 2087 == std::string::npos); |
2085 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2088 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
2086 != std::string::npos); | 2089 != std::string::npos); |
2087 | 2090 |
2088 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2091 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2089 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2092 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2090 } | 2093 } |
2091 } | 2094 } |
2092 | 2095 |
2093 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2096 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
2094 LocalHttpTestServer test_server; | 2097 LocalHttpTestServer test_server; |
2095 ASSERT_TRUE(test_server.Start()); | 2098 ASSERT_TRUE(test_server.Start()); |
2096 | 2099 |
2097 // Set up an empty cookie. | 2100 // Set up an empty cookie. |
2098 { | 2101 { |
2099 TestNetworkDelegate network_delegate; | 2102 TestNetworkDelegate network_delegate; |
2100 default_context_.set_network_delegate(&network_delegate); | 2103 default_context_.set_network_delegate(&network_delegate); |
2101 TestDelegate d; | 2104 TestDelegate d; |
2102 URLRequest req(test_server.GetURL("set-cookie"), &d, &default_context_); | 2105 URLRequest req(test_server.GetURL("set-cookie"), &d, &default_context_); |
2103 req.Start(); | 2106 req.Start(); |
2104 base::MessageLoop::current()->Run(); | 2107 base::RunLoop().Run(); |
2105 | 2108 |
2106 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2109 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2107 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2110 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2108 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2111 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
2109 } | 2112 } |
2110 } | 2113 } |
2111 | 2114 |
2112 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 2115 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
2113 LocalHttpTestServer test_server; | 2116 LocalHttpTestServer test_server; |
2114 ASSERT_TRUE(test_server.Start()); | 2117 ASSERT_TRUE(test_server.Start()); |
2115 | 2118 |
2116 // Set up a cookie. | 2119 // Set up a cookie. |
2117 { | 2120 { |
2118 TestNetworkDelegate network_delegate; | 2121 TestNetworkDelegate network_delegate; |
2119 default_context_.set_network_delegate(&network_delegate); | 2122 default_context_.set_network_delegate(&network_delegate); |
2120 TestDelegate d; | 2123 TestDelegate d; |
2121 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2124 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
2122 &d, | 2125 &d, |
2123 &default_context_); | 2126 &default_context_); |
2124 req.Start(); | 2127 req.Start(); |
2125 base::MessageLoop::current()->Run(); | 2128 base::RunLoop().Run(); |
2126 | 2129 |
2127 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2130 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2128 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2131 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2129 } | 2132 } |
2130 | 2133 |
2131 // Verify that the cookie is set. | 2134 // Verify that the cookie is set. |
2132 { | 2135 { |
2133 TestNetworkDelegate network_delegate; | 2136 TestNetworkDelegate network_delegate; |
2134 default_context_.set_network_delegate(&network_delegate); | 2137 default_context_.set_network_delegate(&network_delegate); |
2135 TestDelegate d; | 2138 TestDelegate d; |
2136 URLRequest req( | 2139 URLRequest req( |
2137 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2140 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2138 req.Start(); | 2141 req.Start(); |
2139 base::MessageLoop::current()->Run(); | 2142 base::RunLoop().Run(); |
2140 | 2143 |
2141 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2144 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
2142 != std::string::npos); | 2145 != std::string::npos); |
2143 | 2146 |
2144 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2147 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2145 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2148 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2146 } | 2149 } |
2147 | 2150 |
2148 // Verify that the cookie isn't sent. | 2151 // Verify that the cookie isn't sent. |
2149 { | 2152 { |
2150 TestNetworkDelegate network_delegate; | 2153 TestNetworkDelegate network_delegate; |
2151 default_context_.set_network_delegate(&network_delegate); | 2154 default_context_.set_network_delegate(&network_delegate); |
2152 TestDelegate d; | 2155 TestDelegate d; |
2153 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2156 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
2154 URLRequest req( | 2157 URLRequest req( |
2155 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2158 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2156 req.Start(); | 2159 req.Start(); |
2157 base::MessageLoop::current()->Run(); | 2160 base::RunLoop().Run(); |
2158 | 2161 |
2159 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2162 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
2160 == std::string::npos); | 2163 == std::string::npos); |
2161 | 2164 |
2162 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2165 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
2163 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2166 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2164 } | 2167 } |
2165 } | 2168 } |
2166 | 2169 |
2167 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2170 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
2168 LocalHttpTestServer test_server; | 2171 LocalHttpTestServer test_server; |
2169 ASSERT_TRUE(test_server.Start()); | 2172 ASSERT_TRUE(test_server.Start()); |
2170 | 2173 |
2171 // Set up a cookie. | 2174 // Set up a cookie. |
2172 { | 2175 { |
2173 TestNetworkDelegate network_delegate; | 2176 TestNetworkDelegate network_delegate; |
2174 default_context_.set_network_delegate(&network_delegate); | 2177 default_context_.set_network_delegate(&network_delegate); |
2175 TestDelegate d; | 2178 TestDelegate d; |
2176 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2179 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
2177 &d, | 2180 &d, |
2178 &default_context_); | 2181 &default_context_); |
2179 req.Start(); | 2182 req.Start(); |
2180 base::MessageLoop::current()->Run(); | 2183 base::RunLoop().Run(); |
2181 | 2184 |
2182 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2185 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2183 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2186 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2184 } | 2187 } |
2185 | 2188 |
2186 // Try to set-up another cookie and update the previous cookie. | 2189 // Try to set-up another cookie and update the previous cookie. |
2187 { | 2190 { |
2188 TestNetworkDelegate network_delegate; | 2191 TestNetworkDelegate network_delegate; |
2189 default_context_.set_network_delegate(&network_delegate); | 2192 default_context_.set_network_delegate(&network_delegate); |
2190 TestDelegate d; | 2193 TestDelegate d; |
2191 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2194 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
2192 URLRequest req( | 2195 URLRequest req( |
2193 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2196 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
2194 &d, | 2197 &d, |
2195 &default_context_); | 2198 &default_context_); |
2196 req.Start(); | 2199 req.Start(); |
2197 | 2200 |
2198 base::MessageLoop::current()->Run(); | 2201 base::RunLoop().Run(); |
2199 | 2202 |
2200 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2203 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2201 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2204 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
2202 } | 2205 } |
2203 | 2206 |
2204 // Verify the cookies weren't saved or updated. | 2207 // Verify the cookies weren't saved or updated. |
2205 { | 2208 { |
2206 TestNetworkDelegate network_delegate; | 2209 TestNetworkDelegate network_delegate; |
2207 default_context_.set_network_delegate(&network_delegate); | 2210 default_context_.set_network_delegate(&network_delegate); |
2208 TestDelegate d; | 2211 TestDelegate d; |
2209 URLRequest req( | 2212 URLRequest req( |
2210 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2213 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2211 req.Start(); | 2214 req.Start(); |
2212 base::MessageLoop::current()->Run(); | 2215 base::RunLoop().Run(); |
2213 | 2216 |
2214 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2217 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
2215 == std::string::npos); | 2218 == std::string::npos); |
2216 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2219 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
2217 != std::string::npos); | 2220 != std::string::npos); |
2218 | 2221 |
2219 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2222 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2220 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2223 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2221 } | 2224 } |
2222 } | 2225 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2271 // Set up an expired cookie. | 2274 // Set up an expired cookie. |
2272 { | 2275 { |
2273 TestNetworkDelegate network_delegate; | 2276 TestNetworkDelegate network_delegate; |
2274 default_context_.set_network_delegate(&network_delegate); | 2277 default_context_.set_network_delegate(&network_delegate); |
2275 TestDelegate d; | 2278 TestDelegate d; |
2276 URLRequest req(test_server.GetURL( | 2279 URLRequest req(test_server.GetURL( |
2277 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2280 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
2278 &d, | 2281 &d, |
2279 &default_context_); | 2282 &default_context_); |
2280 req.Start(); | 2283 req.Start(); |
2281 base::MessageLoop::current()->Run(); | 2284 base::RunLoop().Run(); |
2282 } | 2285 } |
2283 // Verify that the cookie is not set. | 2286 // Verify that the cookie is not set. |
2284 { | 2287 { |
2285 TestNetworkDelegate network_delegate; | 2288 TestNetworkDelegate network_delegate; |
2286 default_context_.set_network_delegate(&network_delegate); | 2289 default_context_.set_network_delegate(&network_delegate); |
2287 TestDelegate d; | 2290 TestDelegate d; |
2288 URLRequest req( | 2291 URLRequest req( |
2289 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2292 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2290 req.Start(); | 2293 req.Start(); |
2291 base::MessageLoop::current()->Run(); | 2294 base::RunLoop().Run(); |
2292 | 2295 |
2293 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | 2296 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); |
2294 } | 2297 } |
2295 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | 2298 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. |
2296 { | 2299 { |
2297 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | 2300 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); |
2298 default_context_.set_network_delegate(&network_delegate); | 2301 default_context_.set_network_delegate(&network_delegate); |
2299 TestDelegate d; | 2302 TestDelegate d; |
2300 URLRequest req(test_server.GetURL( | 2303 URLRequest req(test_server.GetURL( |
2301 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2304 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
2302 &d, | 2305 &d, |
2303 &default_context_); | 2306 &default_context_); |
2304 req.Start(); | 2307 req.Start(); |
2305 base::MessageLoop::current()->Run(); | 2308 base::RunLoop().Run(); |
2306 } | 2309 } |
2307 // Verify that the cookie is set. | 2310 // Verify that the cookie is set. |
2308 { | 2311 { |
2309 TestNetworkDelegate network_delegate; | 2312 TestNetworkDelegate network_delegate; |
2310 default_context_.set_network_delegate(&network_delegate); | 2313 default_context_.set_network_delegate(&network_delegate); |
2311 TestDelegate d; | 2314 TestDelegate d; |
2312 URLRequest req( | 2315 URLRequest req( |
2313 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2316 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
2314 req.Start(); | 2317 req.Start(); |
2315 base::MessageLoop::current()->Run(); | 2318 base::RunLoop().Run(); |
2316 | 2319 |
2317 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 2320 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
2318 } | 2321 } |
2319 } | 2322 } |
2320 | 2323 |
2321 | 2324 |
2322 // Check that it is impossible to change the referrer in the extra headers of | 2325 // Check that it is impossible to change the referrer in the extra headers of |
2323 // an URLRequest. | 2326 // an URLRequest. |
2324 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 2327 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
2325 LocalHttpTestServer test_server; | 2328 LocalHttpTestServer test_server; |
2326 ASSERT_TRUE(test_server.Start()); | 2329 ASSERT_TRUE(test_server.Start()); |
2327 | 2330 |
2328 // If extra headers contain referer and the request contains a referer, | 2331 // If extra headers contain referer and the request contains a referer, |
2329 // only the latter shall be respected. | 2332 // only the latter shall be respected. |
2330 { | 2333 { |
2331 TestDelegate d; | 2334 TestDelegate d; |
2332 URLRequest req( | 2335 URLRequest req( |
2333 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | 2336 test_server.GetURL("echoheader?Referer"), &d, &default_context_); |
2334 req.SetReferrer("http://foo.com/"); | 2337 req.SetReferrer("http://foo.com/"); |
2335 | 2338 |
2336 HttpRequestHeaders headers; | 2339 HttpRequestHeaders headers; |
2337 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2340 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
2338 req.SetExtraRequestHeaders(headers); | 2341 req.SetExtraRequestHeaders(headers); |
2339 | 2342 |
2340 req.Start(); | 2343 req.Start(); |
2341 base::MessageLoop::current()->Run(); | 2344 base::RunLoop().Run(); |
2342 | 2345 |
2343 EXPECT_EQ("http://foo.com/", d.data_received()); | 2346 EXPECT_EQ("http://foo.com/", d.data_received()); |
2344 } | 2347 } |
2345 | 2348 |
2346 // If extra headers contain a referer but the request does not, no referer | 2349 // If extra headers contain a referer but the request does not, no referer |
2347 // shall be sent in the header. | 2350 // shall be sent in the header. |
2348 { | 2351 { |
2349 TestDelegate d; | 2352 TestDelegate d; |
2350 URLRequest req( | 2353 URLRequest req( |
2351 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | 2354 test_server.GetURL("echoheader?Referer"), &d, &default_context_); |
2352 | 2355 |
2353 HttpRequestHeaders headers; | 2356 HttpRequestHeaders headers; |
2354 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2357 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
2355 req.SetExtraRequestHeaders(headers); | 2358 req.SetExtraRequestHeaders(headers); |
2356 req.set_load_flags(LOAD_VALIDATE_CACHE); | 2359 req.set_load_flags(LOAD_VALIDATE_CACHE); |
2357 | 2360 |
2358 req.Start(); | 2361 req.Start(); |
2359 base::MessageLoop::current()->Run(); | 2362 base::RunLoop().Run(); |
2360 | 2363 |
2361 EXPECT_EQ("None", d.data_received()); | 2364 EXPECT_EQ("None", d.data_received()); |
2362 } | 2365 } |
2363 } | 2366 } |
2364 | 2367 |
2365 class URLRequestTestHTTP : public URLRequestTest { | 2368 class URLRequestTestHTTP : public URLRequestTest { |
2366 public: | 2369 public: |
2367 URLRequestTestHTTP() | 2370 URLRequestTestHTTP() |
2368 : test_server_(base::FilePath(FILE_PATH_LITERAL( | 2371 : test_server_(base::FilePath(FILE_PATH_LITERAL( |
2369 "net/data/url_request_unittest"))) { | 2372 "net/data/url_request_unittest"))) { |
(...skipping 16 matching lines...) Expand all Loading... |
2386 URLRequest req(redirect_url, &d, &default_context_); | 2389 URLRequest req(redirect_url, &d, &default_context_); |
2387 req.set_method(request_method); | 2390 req.set_method(request_method); |
2388 if (include_data) { | 2391 if (include_data) { |
2389 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 2392 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
2390 HttpRequestHeaders headers; | 2393 HttpRequestHeaders headers; |
2391 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2394 headers.SetHeader(HttpRequestHeaders::kContentLength, |
2392 base::UintToString(arraysize(kData) - 1)); | 2395 base::UintToString(arraysize(kData) - 1)); |
2393 req.SetExtraRequestHeaders(headers); | 2396 req.SetExtraRequestHeaders(headers); |
2394 } | 2397 } |
2395 req.Start(); | 2398 req.Start(); |
2396 base::MessageLoop::current()->Run(); | 2399 base::RunLoop().Run(); |
2397 EXPECT_EQ(redirect_method, req.method()); | 2400 EXPECT_EQ(redirect_method, req.method()); |
2398 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 2401 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
2399 EXPECT_EQ(OK, req.status().error()); | 2402 EXPECT_EQ(OK, req.status().error()); |
2400 if (include_data) { | 2403 if (include_data) { |
2401 if (request_method == redirect_method) { | 2404 if (request_method == redirect_method) { |
2402 EXPECT_EQ(kData, d.data_received()); | 2405 EXPECT_EQ(kData, d.data_received()); |
2403 } else { | 2406 } else { |
2404 EXPECT_NE(kData, d.data_received()); | 2407 EXPECT_NE(kData, d.data_received()); |
2405 } | 2408 } |
2406 } | 2409 } |
(...skipping 22 matching lines...) Expand all Loading... |
2429 for (int i = 0; i < kIterations; ++i) { | 2432 for (int i = 0; i < kIterations; ++i) { |
2430 TestDelegate d; | 2433 TestDelegate d; |
2431 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 2434 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
2432 r.set_method(method.c_str()); | 2435 r.set_method(method.c_str()); |
2433 | 2436 |
2434 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); | 2437 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); |
2435 | 2438 |
2436 r.Start(); | 2439 r.Start(); |
2437 EXPECT_TRUE(r.is_pending()); | 2440 EXPECT_TRUE(r.is_pending()); |
2438 | 2441 |
2439 base::MessageLoop::current()->Run(); | 2442 base::RunLoop().Run(); |
2440 | 2443 |
2441 ASSERT_EQ(1, d.response_started_count()) | 2444 ASSERT_EQ(1, d.response_started_count()) |
2442 << "request failed: " << r.status().status() | 2445 << "request failed: " << r.status().status() |
2443 << ", os error: " << r.status().error(); | 2446 << ", os error: " << r.status().error(); |
2444 | 2447 |
2445 EXPECT_FALSE(d.received_data_before_response()); | 2448 EXPECT_FALSE(d.received_data_before_response()); |
2446 EXPECT_EQ(uploadBytes, d.data_received()); | 2449 EXPECT_EQ(uploadBytes, d.data_received()); |
2447 } | 2450 } |
2448 delete[] uploadBytes; | 2451 delete[] uploadBytes; |
2449 } | 2452 } |
(...skipping 25 matching lines...) Expand all Loading... |
2475 bool DoManyCookiesRequest(int num_cookies) { | 2478 bool DoManyCookiesRequest(int num_cookies) { |
2476 TestDelegate d; | 2479 TestDelegate d; |
2477 URLRequest r(test_server_.GetURL("set-many-cookies?" + | 2480 URLRequest r(test_server_.GetURL("set-many-cookies?" + |
2478 base::IntToString(num_cookies)), | 2481 base::IntToString(num_cookies)), |
2479 &d, | 2482 &d, |
2480 &default_context_); | 2483 &default_context_); |
2481 | 2484 |
2482 r.Start(); | 2485 r.Start(); |
2483 EXPECT_TRUE(r.is_pending()); | 2486 EXPECT_TRUE(r.is_pending()); |
2484 | 2487 |
2485 base::MessageLoop::current()->Run(); | 2488 base::RunLoop().Run(); |
2486 | 2489 |
2487 bool is_success = r.status().is_success(); | 2490 bool is_success = r.status().is_success(); |
2488 | 2491 |
2489 if (!is_success) { | 2492 if (!is_success) { |
2490 // Requests handled by ChromeFrame send a less precise error message, | 2493 // Requests handled by ChromeFrame send a less precise error message, |
2491 // ERR_CONNECTION_ABORTED. | 2494 // ERR_CONNECTION_ABORTED. |
2492 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG || | 2495 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG || |
2493 r.status().error() == ERR_CONNECTION_ABORTED); | 2496 r.status().error() == ERR_CONNECTION_ABORTED); |
2494 // The test server appears to be unable to handle subsequent requests | 2497 // The test server appears to be unable to handle subsequent requests |
2495 // after this error is triggered. Force it to restart. | 2498 // after this error is triggered. Force it to restart. |
(...skipping 18 matching lines...) Expand all Loading... |
2514 TestURLRequestContextWithProxy context( | 2517 TestURLRequestContextWithProxy context( |
2515 test_server_.host_port_pair().ToString(), | 2518 test_server_.host_port_pair().ToString(), |
2516 &network_delegate); | 2519 &network_delegate); |
2517 | 2520 |
2518 TestDelegate d; | 2521 TestDelegate d; |
2519 { | 2522 { |
2520 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); | 2523 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); |
2521 r.Start(); | 2524 r.Start(); |
2522 EXPECT_TRUE(r.is_pending()); | 2525 EXPECT_TRUE(r.is_pending()); |
2523 | 2526 |
2524 base::MessageLoop::current()->Run(); | 2527 base::RunLoop().Run(); |
2525 | 2528 |
2526 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2529 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
2527 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2530 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
2528 EXPECT_EQ(1, d.response_started_count()); | 2531 EXPECT_EQ(1, d.response_started_count()); |
2529 // We should not have followed the redirect. | 2532 // We should not have followed the redirect. |
2530 EXPECT_EQ(0, d.received_redirect_count()); | 2533 EXPECT_EQ(0, d.received_redirect_count()); |
2531 } | 2534 } |
2532 } | 2535 } |
2533 | 2536 |
2534 // This is the same as the previous test, but checks that the network delegate | 2537 // This is the same as the previous test, but checks that the network delegate |
2535 // registers the error. | 2538 // registers the error. |
2536 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 2539 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
2537 ASSERT_TRUE(test_server_.Start()); | 2540 ASSERT_TRUE(test_server_.Start()); |
2538 | 2541 |
2539 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2542 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
2540 TestURLRequestContextWithProxy context( | 2543 TestURLRequestContextWithProxy context( |
2541 test_server_.host_port_pair().ToString(), | 2544 test_server_.host_port_pair().ToString(), |
2542 &network_delegate); | 2545 &network_delegate); |
2543 | 2546 |
2544 TestDelegate d; | 2547 TestDelegate d; |
2545 { | 2548 { |
2546 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); | 2549 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); |
2547 r.Start(); | 2550 r.Start(); |
2548 EXPECT_TRUE(r.is_pending()); | 2551 EXPECT_TRUE(r.is_pending()); |
2549 | 2552 |
2550 base::MessageLoop::current()->Run(); | 2553 base::RunLoop().Run(); |
2551 | 2554 |
2552 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2555 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
2553 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2556 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
2554 EXPECT_EQ(1, d.response_started_count()); | 2557 EXPECT_EQ(1, d.response_started_count()); |
2555 // We should not have followed the redirect. | 2558 // We should not have followed the redirect. |
2556 EXPECT_EQ(0, d.received_redirect_count()); | 2559 EXPECT_EQ(0, d.received_redirect_count()); |
2557 | 2560 |
2558 EXPECT_EQ(1, network_delegate.error_count()); | 2561 EXPECT_EQ(1, network_delegate.error_count()); |
2559 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); | 2562 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
2560 } | 2563 } |
(...skipping 20 matching lines...) Expand all Loading... |
2581 | 2584 |
2582 TestURLRequestContext context(true); | 2585 TestURLRequestContext context(true); |
2583 context.set_network_delegate(&network_delegate); | 2586 context.set_network_delegate(&network_delegate); |
2584 context.Init(); | 2587 context.Init(); |
2585 | 2588 |
2586 { | 2589 { |
2587 URLRequest r(test_server_.GetURL("empty.html"), &d, &context); | 2590 URLRequest r(test_server_.GetURL("empty.html"), &d, &context); |
2588 | 2591 |
2589 r.Start(); | 2592 r.Start(); |
2590 for (size_t i = 0; i < blocking_stages_length; ++i) { | 2593 for (size_t i = 0; i < blocking_stages_length; ++i) { |
2591 base::MessageLoop::current()->Run(); | 2594 base::RunLoop().Run(); |
2592 EXPECT_EQ(blocking_stages[i], | 2595 EXPECT_EQ(blocking_stages[i], |
2593 network_delegate.stage_blocked_for_callback()); | 2596 network_delegate.stage_blocked_for_callback()); |
2594 network_delegate.DoCallback(OK); | 2597 network_delegate.DoCallback(OK); |
2595 } | 2598 } |
2596 base::MessageLoop::current()->Run(); | 2599 base::RunLoop().Run(); |
2597 EXPECT_EQ(200, r.GetResponseCode()); | 2600 EXPECT_EQ(200, r.GetResponseCode()); |
2598 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2601 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2599 EXPECT_EQ(1, network_delegate.created_requests()); | 2602 EXPECT_EQ(1, network_delegate.created_requests()); |
2600 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2603 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2601 } | 2604 } |
2602 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2605 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2603 } | 2606 } |
2604 | 2607 |
2605 // Tests that the network delegate can block and cancel a request. | 2608 // Tests that the network delegate can block and cancel a request. |
2606 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 2609 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
2607 ASSERT_TRUE(test_server_.Start()); | 2610 ASSERT_TRUE(test_server_.Start()); |
2608 | 2611 |
2609 TestDelegate d; | 2612 TestDelegate d; |
2610 BlockingNetworkDelegate network_delegate( | 2613 BlockingNetworkDelegate network_delegate( |
2611 BlockingNetworkDelegate::AUTO_CALLBACK); | 2614 BlockingNetworkDelegate::AUTO_CALLBACK); |
2612 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2615 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
2613 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 2616 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
2614 | 2617 |
2615 TestURLRequestContextWithProxy context( | 2618 TestURLRequestContextWithProxy context( |
2616 test_server_.host_port_pair().ToString(), | 2619 test_server_.host_port_pair().ToString(), |
2617 &network_delegate); | 2620 &network_delegate); |
2618 | 2621 |
2619 { | 2622 { |
2620 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 2623 URLRequest r(test_server_.GetURL(std::string()), &d, &context); |
2621 | 2624 |
2622 r.Start(); | 2625 r.Start(); |
2623 base::MessageLoop::current()->Run(); | 2626 base::RunLoop().Run(); |
2624 | 2627 |
2625 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2628 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
2626 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 2629 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
2627 EXPECT_EQ(1, network_delegate.created_requests()); | 2630 EXPECT_EQ(1, network_delegate.created_requests()); |
2628 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2631 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2629 } | 2632 } |
2630 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2633 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2631 } | 2634 } |
2632 | 2635 |
2633 // Helper function for NetworkDelegateCancelRequestAsynchronously and | 2636 // Helper function for NetworkDelegateCancelRequestAsynchronously and |
2634 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network | 2637 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network |
2635 // delegate operating in |block_mode| and a request for |url|. It blocks the | 2638 // delegate operating in |block_mode| and a request for |url|. It blocks the |
2636 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. | 2639 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. |
2637 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, | 2640 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, |
2638 BlockingNetworkDelegate::Stage stage, | 2641 BlockingNetworkDelegate::Stage stage, |
2639 const GURL& url) { | 2642 const GURL& url) { |
2640 TestDelegate d; | 2643 TestDelegate d; |
2641 BlockingNetworkDelegate network_delegate(block_mode); | 2644 BlockingNetworkDelegate network_delegate(block_mode); |
2642 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); | 2645 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); |
2643 network_delegate.set_block_on(stage); | 2646 network_delegate.set_block_on(stage); |
2644 | 2647 |
2645 TestURLRequestContext context(true); | 2648 TestURLRequestContext context(true); |
2646 context.set_network_delegate(&network_delegate); | 2649 context.set_network_delegate(&network_delegate); |
2647 context.Init(); | 2650 context.Init(); |
2648 | 2651 |
2649 { | 2652 { |
2650 URLRequest r(url, &d, &context); | 2653 URLRequest r(url, &d, &context); |
2651 | 2654 |
2652 r.Start(); | 2655 r.Start(); |
2653 base::MessageLoop::current()->Run(); | 2656 base::RunLoop().Run(); |
2654 | 2657 |
2655 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2658 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
2656 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); | 2659 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); |
2657 EXPECT_EQ(1, network_delegate.created_requests()); | 2660 EXPECT_EQ(1, network_delegate.created_requests()); |
2658 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2661 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2659 } | 2662 } |
2660 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2663 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2661 } | 2664 } |
2662 | 2665 |
2663 // The following 3 tests check that the network delegate can cancel a request | 2666 // The following 3 tests check that the network delegate can cancel a request |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2720 | 2723 |
2721 TestURLRequestContextWithProxy context( | 2724 TestURLRequestContextWithProxy context( |
2722 test_server_.host_port_pair().ToString(), | 2725 test_server_.host_port_pair().ToString(), |
2723 &network_delegate); | 2726 &network_delegate); |
2724 | 2727 |
2725 { | 2728 { |
2726 GURL original_url(test_server_.GetURL("empty.html")); | 2729 GURL original_url(test_server_.GetURL("empty.html")); |
2727 URLRequest r(original_url, &d, &context); | 2730 URLRequest r(original_url, &d, &context); |
2728 | 2731 |
2729 r.Start(); | 2732 r.Start(); |
2730 base::MessageLoop::current()->Run(); | 2733 base::RunLoop().Run(); |
2731 | 2734 |
2732 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2735 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2733 EXPECT_EQ(0, r.status().error()); | 2736 EXPECT_EQ(0, r.status().error()); |
2734 EXPECT_EQ(redirect_url, r.url()); | 2737 EXPECT_EQ(redirect_url, r.url()); |
2735 EXPECT_EQ(original_url, r.original_url()); | 2738 EXPECT_EQ(original_url, r.original_url()); |
2736 EXPECT_EQ(2U, r.url_chain().size()); | 2739 EXPECT_EQ(2U, r.url_chain().size()); |
2737 EXPECT_EQ(1, network_delegate.created_requests()); | 2740 EXPECT_EQ(1, network_delegate.created_requests()); |
2738 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2741 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2739 } | 2742 } |
2740 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2743 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
(...skipping 12 matching lines...) Expand all Loading... |
2753 | 2756 |
2754 TestURLRequestContextWithProxy context( | 2757 TestURLRequestContextWithProxy context( |
2755 test_server_.host_port_pair().ToString(), | 2758 test_server_.host_port_pair().ToString(), |
2756 &network_delegate); | 2759 &network_delegate); |
2757 | 2760 |
2758 { | 2761 { |
2759 GURL original_url(test_server_.GetURL("empty.html")); | 2762 GURL original_url(test_server_.GetURL("empty.html")); |
2760 URLRequest r(original_url, &d, &context); | 2763 URLRequest r(original_url, &d, &context); |
2761 | 2764 |
2762 r.Start(); | 2765 r.Start(); |
2763 base::MessageLoop::current()->Run(); | 2766 base::RunLoop().Run(); |
2764 | 2767 |
2765 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2768 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2766 EXPECT_EQ(0, r.status().error()); | 2769 EXPECT_EQ(0, r.status().error()); |
2767 EXPECT_EQ(redirect_url, r.url()); | 2770 EXPECT_EQ(redirect_url, r.url()); |
2768 EXPECT_EQ(original_url, r.original_url()); | 2771 EXPECT_EQ(original_url, r.original_url()); |
2769 EXPECT_EQ(2U, r.url_chain().size()); | 2772 EXPECT_EQ(2U, r.url_chain().size()); |
2770 EXPECT_EQ(1, network_delegate.created_requests()); | 2773 EXPECT_EQ(1, network_delegate.created_requests()); |
2771 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2774 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2772 } | 2775 } |
2773 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2776 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
(...skipping 19 matching lines...) Expand all Loading... |
2793 { | 2796 { |
2794 GURL original_url(test_server_.GetURL("empty.html")); | 2797 GURL original_url(test_server_.GetURL("empty.html")); |
2795 URLRequest r(original_url, &d, &context); | 2798 URLRequest r(original_url, &d, &context); |
2796 r.set_method("POST"); | 2799 r.set_method("POST"); |
2797 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 2800 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
2798 HttpRequestHeaders headers; | 2801 HttpRequestHeaders headers; |
2799 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2802 headers.SetHeader(HttpRequestHeaders::kContentLength, |
2800 base::UintToString(arraysize(kData) - 1)); | 2803 base::UintToString(arraysize(kData) - 1)); |
2801 r.SetExtraRequestHeaders(headers); | 2804 r.SetExtraRequestHeaders(headers); |
2802 r.Start(); | 2805 r.Start(); |
2803 base::MessageLoop::current()->Run(); | 2806 base::RunLoop().Run(); |
2804 | 2807 |
2805 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2808 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2806 EXPECT_EQ(0, r.status().error()); | 2809 EXPECT_EQ(0, r.status().error()); |
2807 EXPECT_EQ(redirect_url, r.url()); | 2810 EXPECT_EQ(redirect_url, r.url()); |
2808 EXPECT_EQ(original_url, r.original_url()); | 2811 EXPECT_EQ(original_url, r.original_url()); |
2809 EXPECT_EQ(2U, r.url_chain().size()); | 2812 EXPECT_EQ(2U, r.url_chain().size()); |
2810 EXPECT_EQ(1, network_delegate.created_requests()); | 2813 EXPECT_EQ(1, network_delegate.created_requests()); |
2811 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2814 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2812 EXPECT_EQ("POST", r.method()); | 2815 EXPECT_EQ("POST", r.method()); |
2813 EXPECT_EQ(kData, d.data_received()); | 2816 EXPECT_EQ(kData, d.data_received()); |
(...skipping 16 matching lines...) Expand all Loading... |
2830 context.set_network_delegate(&network_delegate); | 2833 context.set_network_delegate(&network_delegate); |
2831 context.Init(); | 2834 context.Init(); |
2832 | 2835 |
2833 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2836 d.set_credentials(AuthCredentials(kUser, kSecret)); |
2834 | 2837 |
2835 { | 2838 { |
2836 GURL url(test_server_.GetURL("auth-basic")); | 2839 GURL url(test_server_.GetURL("auth-basic")); |
2837 URLRequest r(url, &d, &context); | 2840 URLRequest r(url, &d, &context); |
2838 r.Start(); | 2841 r.Start(); |
2839 | 2842 |
2840 base::MessageLoop::current()->Run(); | 2843 base::RunLoop().Run(); |
2841 | 2844 |
2842 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2845 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2843 EXPECT_EQ(0, r.status().error()); | 2846 EXPECT_EQ(0, r.status().error()); |
2844 EXPECT_EQ(200, r.GetResponseCode()); | 2847 EXPECT_EQ(200, r.GetResponseCode()); |
2845 EXPECT_TRUE(d.auth_required_called()); | 2848 EXPECT_TRUE(d.auth_required_called()); |
2846 EXPECT_EQ(1, network_delegate.created_requests()); | 2849 EXPECT_EQ(1, network_delegate.created_requests()); |
2847 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2850 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2848 } | 2851 } |
2849 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2852 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2850 } | 2853 } |
(...skipping 16 matching lines...) Expand all Loading... |
2867 GURL url(test_server_.GetURL("auth-basic")); | 2870 GURL url(test_server_.GetURL("auth-basic")); |
2868 URLRequest r(url, &d, &context); | 2871 URLRequest r(url, &d, &context); |
2869 r.Start(); | 2872 r.Start(); |
2870 | 2873 |
2871 { | 2874 { |
2872 HttpRequestHeaders headers; | 2875 HttpRequestHeaders headers; |
2873 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); | 2876 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); |
2874 EXPECT_FALSE(headers.HasHeader("Authorization")); | 2877 EXPECT_FALSE(headers.HasHeader("Authorization")); |
2875 } | 2878 } |
2876 | 2879 |
2877 base::MessageLoop::current()->Run(); | 2880 base::RunLoop().Run(); |
2878 | 2881 |
2879 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2882 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2880 EXPECT_EQ(0, r.status().error()); | 2883 EXPECT_EQ(0, r.status().error()); |
2881 EXPECT_EQ(200, r.GetResponseCode()); | 2884 EXPECT_EQ(200, r.GetResponseCode()); |
2882 EXPECT_TRUE(d.auth_required_called()); | 2885 EXPECT_TRUE(d.auth_required_called()); |
2883 EXPECT_EQ(1, network_delegate.created_requests()); | 2886 EXPECT_EQ(1, network_delegate.created_requests()); |
2884 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2887 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2885 } | 2888 } |
2886 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2889 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2887 } | 2890 } |
(...skipping 13 matching lines...) Expand all Loading... |
2901 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 2904 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
2902 | 2905 |
2903 TestURLRequestContext context(true); | 2906 TestURLRequestContext context(true); |
2904 context.set_network_delegate(&network_delegate); | 2907 context.set_network_delegate(&network_delegate); |
2905 context.Init(); | 2908 context.Init(); |
2906 | 2909 |
2907 { | 2910 { |
2908 GURL url(test_server_.GetURL("auth-basic")); | 2911 GURL url(test_server_.GetURL("auth-basic")); |
2909 URLRequest r(url, &d, &context); | 2912 URLRequest r(url, &d, &context); |
2910 r.Start(); | 2913 r.Start(); |
2911 base::MessageLoop::current()->Run(); | 2914 base::RunLoop().Run(); |
2912 | 2915 |
2913 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2916 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2914 EXPECT_EQ(0, r.status().error()); | 2917 EXPECT_EQ(0, r.status().error()); |
2915 EXPECT_EQ(200, r.GetResponseCode()); | 2918 EXPECT_EQ(200, r.GetResponseCode()); |
2916 EXPECT_FALSE(d.auth_required_called()); | 2919 EXPECT_FALSE(d.auth_required_called()); |
2917 EXPECT_EQ(1, network_delegate.created_requests()); | 2920 EXPECT_EQ(1, network_delegate.created_requests()); |
2918 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2921 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2919 } | 2922 } |
2920 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2923 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2921 } | 2924 } |
(...skipping 14 matching lines...) Expand all Loading... |
2936 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 2939 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
2937 | 2940 |
2938 TestURLRequestContext context(true); | 2941 TestURLRequestContext context(true); |
2939 context.set_network_delegate(&network_delegate); | 2942 context.set_network_delegate(&network_delegate); |
2940 context.Init(); | 2943 context.Init(); |
2941 | 2944 |
2942 { | 2945 { |
2943 GURL url(test_server_.GetURL("auth-basic")); | 2946 GURL url(test_server_.GetURL("auth-basic")); |
2944 URLRequest r(url, &d, &context); | 2947 URLRequest r(url, &d, &context); |
2945 r.Start(); | 2948 r.Start(); |
2946 base::MessageLoop::current()->Run(); | 2949 base::RunLoop().Run(); |
2947 | 2950 |
2948 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2951 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2949 EXPECT_EQ(0, r.status().error()); | 2952 EXPECT_EQ(0, r.status().error()); |
2950 EXPECT_EQ(200, r.GetResponseCode()); | 2953 EXPECT_EQ(200, r.GetResponseCode()); |
2951 EXPECT_FALSE(d.auth_required_called()); | 2954 EXPECT_FALSE(d.auth_required_called()); |
2952 EXPECT_EQ(1, network_delegate.created_requests()); | 2955 EXPECT_EQ(1, network_delegate.created_requests()); |
2953 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2956 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2954 | 2957 |
2955 { | 2958 { |
2956 HttpRequestHeaders headers; | 2959 HttpRequestHeaders headers; |
(...skipping 17 matching lines...) Expand all Loading... |
2974 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 2977 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
2975 | 2978 |
2976 TestURLRequestContext context(true); | 2979 TestURLRequestContext context(true); |
2977 context.set_network_delegate(&network_delegate); | 2980 context.set_network_delegate(&network_delegate); |
2978 context.Init(); | 2981 context.Init(); |
2979 | 2982 |
2980 { | 2983 { |
2981 GURL url(test_server_.GetURL("auth-basic")); | 2984 GURL url(test_server_.GetURL("auth-basic")); |
2982 URLRequest r(url, &d, &context); | 2985 URLRequest r(url, &d, &context); |
2983 r.Start(); | 2986 r.Start(); |
2984 base::MessageLoop::current()->Run(); | 2987 base::RunLoop().Run(); |
2985 | 2988 |
2986 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2989 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2987 EXPECT_EQ(OK, r.status().error()); | 2990 EXPECT_EQ(OK, r.status().error()); |
2988 EXPECT_EQ(401, r.GetResponseCode()); | 2991 EXPECT_EQ(401, r.GetResponseCode()); |
2989 EXPECT_FALSE(d.auth_required_called()); | 2992 EXPECT_FALSE(d.auth_required_called()); |
2990 EXPECT_EQ(1, network_delegate.created_requests()); | 2993 EXPECT_EQ(1, network_delegate.created_requests()); |
2991 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2994 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
2992 } | 2995 } |
2993 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2996 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
2994 } | 2997 } |
(...skipping 13 matching lines...) Expand all Loading... |
3008 TestURLRequestContext context(true); | 3011 TestURLRequestContext context(true); |
3009 context.set_network_delegate(&network_delegate); | 3012 context.set_network_delegate(&network_delegate); |
3010 context.Init(); | 3013 context.Init(); |
3011 | 3014 |
3012 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3015 d.set_credentials(AuthCredentials(kUser, kSecret)); |
3013 | 3016 |
3014 { | 3017 { |
3015 GURL url(test_server_.GetURL("auth-basic")); | 3018 GURL url(test_server_.GetURL("auth-basic")); |
3016 URLRequest r(url, &d, &context); | 3019 URLRequest r(url, &d, &context); |
3017 r.Start(); | 3020 r.Start(); |
3018 base::MessageLoop::current()->Run(); | 3021 base::RunLoop().Run(); |
3019 | 3022 |
3020 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3023 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
3021 EXPECT_EQ(0, r.status().error()); | 3024 EXPECT_EQ(0, r.status().error()); |
3022 EXPECT_EQ(200, r.GetResponseCode()); | 3025 EXPECT_EQ(200, r.GetResponseCode()); |
3023 EXPECT_TRUE(d.auth_required_called()); | 3026 EXPECT_TRUE(d.auth_required_called()); |
3024 EXPECT_EQ(1, network_delegate.created_requests()); | 3027 EXPECT_EQ(1, network_delegate.created_requests()); |
3025 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3028 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
3026 } | 3029 } |
3027 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3030 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
3028 } | 3031 } |
(...skipping 14 matching lines...) Expand all Loading... |
3043 network_delegate.set_auth_credentials(auth_credentials); | 3046 network_delegate.set_auth_credentials(auth_credentials); |
3044 | 3047 |
3045 TestURLRequestContext context(true); | 3048 TestURLRequestContext context(true); |
3046 context.set_network_delegate(&network_delegate); | 3049 context.set_network_delegate(&network_delegate); |
3047 context.Init(); | 3050 context.Init(); |
3048 | 3051 |
3049 { | 3052 { |
3050 GURL url(test_server_.GetURL("auth-basic")); | 3053 GURL url(test_server_.GetURL("auth-basic")); |
3051 URLRequest r(url, &d, &context); | 3054 URLRequest r(url, &d, &context); |
3052 r.Start(); | 3055 r.Start(); |
3053 base::MessageLoop::current()->Run(); | 3056 base::RunLoop().Run(); |
3054 | 3057 |
3055 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3058 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
3056 EXPECT_EQ(0, r.status().error()); | 3059 EXPECT_EQ(0, r.status().error()); |
3057 | 3060 |
3058 EXPECT_EQ(200, r.GetResponseCode()); | 3061 EXPECT_EQ(200, r.GetResponseCode()); |
3059 EXPECT_FALSE(d.auth_required_called()); | 3062 EXPECT_FALSE(d.auth_required_called()); |
3060 EXPECT_EQ(1, network_delegate.created_requests()); | 3063 EXPECT_EQ(1, network_delegate.created_requests()); |
3061 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3064 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
3062 } | 3065 } |
3063 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3066 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
(...skipping 12 matching lines...) Expand all Loading... |
3076 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3079 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
3077 | 3080 |
3078 TestURLRequestContext context(true); | 3081 TestURLRequestContext context(true); |
3079 context.set_network_delegate(&network_delegate); | 3082 context.set_network_delegate(&network_delegate); |
3080 context.Init(); | 3083 context.Init(); |
3081 | 3084 |
3082 { | 3085 { |
3083 GURL url(test_server_.GetURL("auth-basic")); | 3086 GURL url(test_server_.GetURL("auth-basic")); |
3084 URLRequest r(url, &d, &context); | 3087 URLRequest r(url, &d, &context); |
3085 r.Start(); | 3088 r.Start(); |
3086 base::MessageLoop::current()->Run(); | 3089 base::RunLoop().Run(); |
3087 | 3090 |
3088 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3091 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
3089 EXPECT_EQ(OK, r.status().error()); | 3092 EXPECT_EQ(OK, r.status().error()); |
3090 EXPECT_EQ(401, r.GetResponseCode()); | 3093 EXPECT_EQ(401, r.GetResponseCode()); |
3091 EXPECT_FALSE(d.auth_required_called()); | 3094 EXPECT_FALSE(d.auth_required_called()); |
3092 EXPECT_EQ(1, network_delegate.created_requests()); | 3095 EXPECT_EQ(1, network_delegate.created_requests()); |
3093 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3096 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
3094 } | 3097 } |
3095 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3098 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
3096 } | 3099 } |
(...skipping 10 matching lines...) Expand all Loading... |
3107 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3110 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
3108 | 3111 |
3109 TestURLRequestContext context(true); | 3112 TestURLRequestContext context(true); |
3110 context.set_network_delegate(&network_delegate); | 3113 context.set_network_delegate(&network_delegate); |
3111 context.Init(); | 3114 context.Init(); |
3112 | 3115 |
3113 { | 3116 { |
3114 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3117 URLRequest r(test_server_.GetURL(std::string()), &d, &context); |
3115 | 3118 |
3116 r.Start(); | 3119 r.Start(); |
3117 base::MessageLoop::current()->Run(); | 3120 base::RunLoop().Run(); |
3118 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3121 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
3119 network_delegate.stage_blocked_for_callback()); | 3122 network_delegate.stage_blocked_for_callback()); |
3120 EXPECT_EQ(0, network_delegate.completed_requests()); | 3123 EXPECT_EQ(0, network_delegate.completed_requests()); |
3121 // Cancel before callback. | 3124 // Cancel before callback. |
3122 r.Cancel(); | 3125 r.Cancel(); |
3123 // Ensure that network delegate is notified. | 3126 // Ensure that network delegate is notified. |
3124 EXPECT_EQ(1, network_delegate.completed_requests()); | 3127 EXPECT_EQ(1, network_delegate.completed_requests()); |
3125 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3128 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3126 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3129 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
3127 EXPECT_EQ(1, network_delegate.created_requests()); | 3130 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 15 matching lines...) Expand all Loading... |
3143 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); | 3146 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); |
3144 | 3147 |
3145 TestURLRequestContext context(true); | 3148 TestURLRequestContext context(true); |
3146 context.set_network_delegate(&network_delegate); | 3149 context.set_network_delegate(&network_delegate); |
3147 context.Init(); | 3150 context.Init(); |
3148 | 3151 |
3149 { | 3152 { |
3150 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3153 URLRequest r(test_server_.GetURL(std::string()), &d, &context); |
3151 | 3154 |
3152 r.Start(); | 3155 r.Start(); |
3153 base::MessageLoop::current()->Run(); | 3156 base::RunLoop().Run(); |
3154 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3157 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
3155 network_delegate.stage_blocked_for_callback()); | 3158 network_delegate.stage_blocked_for_callback()); |
3156 EXPECT_EQ(0, network_delegate.completed_requests()); | 3159 EXPECT_EQ(0, network_delegate.completed_requests()); |
3157 // Cancel before callback. | 3160 // Cancel before callback. |
3158 r.Cancel(); | 3161 r.Cancel(); |
3159 // Ensure that network delegate is notified. | 3162 // Ensure that network delegate is notified. |
3160 EXPECT_EQ(1, network_delegate.completed_requests()); | 3163 EXPECT_EQ(1, network_delegate.completed_requests()); |
3161 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3164 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3162 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3165 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
3163 EXPECT_EQ(1, network_delegate.created_requests()); | 3166 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 14 matching lines...) Expand all Loading... |
3178 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3181 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
3179 | 3182 |
3180 TestURLRequestContext context(true); | 3183 TestURLRequestContext context(true); |
3181 context.set_network_delegate(&network_delegate); | 3184 context.set_network_delegate(&network_delegate); |
3182 context.Init(); | 3185 context.Init(); |
3183 | 3186 |
3184 { | 3187 { |
3185 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3188 URLRequest r(test_server_.GetURL(std::string()), &d, &context); |
3186 | 3189 |
3187 r.Start(); | 3190 r.Start(); |
3188 base::MessageLoop::current()->Run(); | 3191 base::RunLoop().Run(); |
3189 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 3192 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
3190 network_delegate.stage_blocked_for_callback()); | 3193 network_delegate.stage_blocked_for_callback()); |
3191 EXPECT_EQ(0, network_delegate.completed_requests()); | 3194 EXPECT_EQ(0, network_delegate.completed_requests()); |
3192 // Cancel before callback. | 3195 // Cancel before callback. |
3193 r.Cancel(); | 3196 r.Cancel(); |
3194 // Ensure that network delegate is notified. | 3197 // Ensure that network delegate is notified. |
3195 EXPECT_EQ(1, network_delegate.completed_requests()); | 3198 EXPECT_EQ(1, network_delegate.completed_requests()); |
3196 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3199 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3197 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3200 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
3198 EXPECT_EQ(1, network_delegate.created_requests()); | 3201 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 14 matching lines...) Expand all Loading... |
3213 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3216 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
3214 | 3217 |
3215 TestURLRequestContext context(true); | 3218 TestURLRequestContext context(true); |
3216 context.set_network_delegate(&network_delegate); | 3219 context.set_network_delegate(&network_delegate); |
3217 context.Init(); | 3220 context.Init(); |
3218 | 3221 |
3219 { | 3222 { |
3220 URLRequest r(test_server_.GetURL("auth-basic"), &d, &context); | 3223 URLRequest r(test_server_.GetURL("auth-basic"), &d, &context); |
3221 | 3224 |
3222 r.Start(); | 3225 r.Start(); |
3223 base::MessageLoop::current()->Run(); | 3226 base::RunLoop().Run(); |
3224 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, | 3227 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, |
3225 network_delegate.stage_blocked_for_callback()); | 3228 network_delegate.stage_blocked_for_callback()); |
3226 EXPECT_EQ(0, network_delegate.completed_requests()); | 3229 EXPECT_EQ(0, network_delegate.completed_requests()); |
3227 // Cancel before callback. | 3230 // Cancel before callback. |
3228 r.Cancel(); | 3231 r.Cancel(); |
3229 // Ensure that network delegate is notified. | 3232 // Ensure that network delegate is notified. |
3230 EXPECT_EQ(1, network_delegate.completed_requests()); | 3233 EXPECT_EQ(1, network_delegate.completed_requests()); |
3231 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3234 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3232 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3235 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
3233 EXPECT_EQ(1, network_delegate.created_requests()); | 3236 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 13 matching lines...) Expand all Loading... |
3247 test_server_.host_port_pair().ToString(), | 3250 test_server_.host_port_pair().ToString(), |
3248 &network_delegate); | 3251 &network_delegate); |
3249 | 3252 |
3250 TestDelegate d; | 3253 TestDelegate d; |
3251 { | 3254 { |
3252 URLRequest r(GURL("https://www.server-auth.com/"), &d, &context); | 3255 URLRequest r(GURL("https://www.server-auth.com/"), &d, &context); |
3253 | 3256 |
3254 r.Start(); | 3257 r.Start(); |
3255 EXPECT_TRUE(r.is_pending()); | 3258 EXPECT_TRUE(r.is_pending()); |
3256 | 3259 |
3257 base::MessageLoop::current()->Run(); | 3260 base::RunLoop().Run(); |
3258 | 3261 |
3259 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 3262 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
3260 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 3263 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
3261 } | 3264 } |
3262 } | 3265 } |
3263 | 3266 |
3264 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 3267 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
3265 ASSERT_TRUE(test_server_.Start()); | 3268 ASSERT_TRUE(test_server_.Start()); |
3266 | 3269 |
3267 TestDelegate d; | 3270 TestDelegate d; |
3268 { | 3271 { |
3269 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3272 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); |
3270 | 3273 |
3271 r.Start(); | 3274 r.Start(); |
3272 EXPECT_TRUE(r.is_pending()); | 3275 EXPECT_TRUE(r.is_pending()); |
3273 | 3276 |
3274 base::MessageLoop::current()->Run(); | 3277 base::RunLoop().Run(); |
3275 | 3278 |
3276 EXPECT_EQ(1, d.response_started_count()); | 3279 EXPECT_EQ(1, d.response_started_count()); |
3277 EXPECT_FALSE(d.received_data_before_response()); | 3280 EXPECT_FALSE(d.received_data_before_response()); |
3278 EXPECT_NE(0, d.bytes_received()); | 3281 EXPECT_NE(0, d.bytes_received()); |
3279 EXPECT_EQ(test_server_.host_port_pair().host(), | 3282 EXPECT_EQ(test_server_.host_port_pair().host(), |
3280 r.GetSocketAddress().host()); | 3283 r.GetSocketAddress().host()); |
3281 EXPECT_EQ(test_server_.host_port_pair().port(), | 3284 EXPECT_EQ(test_server_.host_port_pair().port(), |
3282 r.GetSocketAddress().port()); | 3285 r.GetSocketAddress().port()); |
3283 | 3286 |
3284 // TODO(eroman): Add back the NetLog tests... | 3287 // TODO(eroman): Add back the NetLog tests... |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3330 TEST_F(URLRequestTestHTTP, GetTest) { | 3333 TEST_F(URLRequestTestHTTP, GetTest) { |
3331 ASSERT_TRUE(test_server_.Start()); | 3334 ASSERT_TRUE(test_server_.Start()); |
3332 | 3335 |
3333 TestDelegate d; | 3336 TestDelegate d; |
3334 { | 3337 { |
3335 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3338 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); |
3336 | 3339 |
3337 r.Start(); | 3340 r.Start(); |
3338 EXPECT_TRUE(r.is_pending()); | 3341 EXPECT_TRUE(r.is_pending()); |
3339 | 3342 |
3340 base::MessageLoop::current()->Run(); | 3343 base::RunLoop().Run(); |
3341 | 3344 |
3342 EXPECT_EQ(1, d.response_started_count()); | 3345 EXPECT_EQ(1, d.response_started_count()); |
3343 EXPECT_FALSE(d.received_data_before_response()); | 3346 EXPECT_FALSE(d.received_data_before_response()); |
3344 EXPECT_NE(0, d.bytes_received()); | 3347 EXPECT_NE(0, d.bytes_received()); |
3345 EXPECT_EQ(test_server_.host_port_pair().host(), | 3348 EXPECT_EQ(test_server_.host_port_pair().host(), |
3346 r.GetSocketAddress().host()); | 3349 r.GetSocketAddress().host()); |
3347 EXPECT_EQ(test_server_.host_port_pair().port(), | 3350 EXPECT_EQ(test_server_.host_port_pair().port(), |
3348 r.GetSocketAddress().port()); | 3351 r.GetSocketAddress().port()); |
3349 } | 3352 } |
3350 } | 3353 } |
3351 | 3354 |
3352 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { | 3355 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { |
3353 ASSERT_TRUE(test_server_.Start()); | 3356 ASSERT_TRUE(test_server_.Start()); |
3354 | 3357 |
3355 TestDelegate d; | 3358 TestDelegate d; |
3356 { | 3359 { |
3357 GURL test_url(test_server_.GetURL(std::string())); | 3360 GURL test_url(test_server_.GetURL(std::string())); |
3358 URLRequest r(test_url, &d, &default_context_); | 3361 URLRequest r(test_url, &d, &default_context_); |
3359 | 3362 |
3360 HttpRequestHeaders headers; | 3363 HttpRequestHeaders headers; |
3361 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 3364 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
3362 | 3365 |
3363 r.Start(); | 3366 r.Start(); |
3364 EXPECT_TRUE(r.is_pending()); | 3367 EXPECT_TRUE(r.is_pending()); |
3365 | 3368 |
3366 base::MessageLoop::current()->Run(); | 3369 base::RunLoop().Run(); |
3367 | 3370 |
3368 EXPECT_EQ(1, d.response_started_count()); | 3371 EXPECT_EQ(1, d.response_started_count()); |
3369 EXPECT_FALSE(d.received_data_before_response()); | 3372 EXPECT_FALSE(d.received_data_before_response()); |
3370 EXPECT_NE(0, d.bytes_received()); | 3373 EXPECT_NE(0, d.bytes_received()); |
3371 EXPECT_EQ(test_server_.host_port_pair().host(), | 3374 EXPECT_EQ(test_server_.host_port_pair().host(), |
3372 r.GetSocketAddress().host()); | 3375 r.GetSocketAddress().host()); |
3373 EXPECT_EQ(test_server_.host_port_pair().port(), | 3376 EXPECT_EQ(test_server_.host_port_pair().port(), |
3374 r.GetSocketAddress().port()); | 3377 r.GetSocketAddress().port()); |
3375 | 3378 |
3376 EXPECT_TRUE(d.have_full_request_headers()); | 3379 EXPECT_TRUE(d.have_full_request_headers()); |
3377 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 3380 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
3378 } | 3381 } |
3379 } | 3382 } |
3380 | 3383 |
3381 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { | 3384 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { |
3382 ASSERT_TRUE(test_server_.Start()); | 3385 ASSERT_TRUE(test_server_.Start()); |
3383 | 3386 |
3384 TestDelegate d; | 3387 TestDelegate d; |
3385 { | 3388 { |
3386 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3389 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); |
3387 | 3390 |
3388 r.Start(); | 3391 r.Start(); |
3389 EXPECT_TRUE(r.is_pending()); | 3392 EXPECT_TRUE(r.is_pending()); |
3390 | 3393 |
3391 base::MessageLoop::current()->Run(); | 3394 base::RunLoop().Run(); |
3392 | 3395 |
3393 LoadTimingInfo load_timing_info; | 3396 LoadTimingInfo load_timing_info; |
3394 r.GetLoadTimingInfo(&load_timing_info); | 3397 r.GetLoadTimingInfo(&load_timing_info); |
3395 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 3398 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
3396 | 3399 |
3397 EXPECT_EQ(1, d.response_started_count()); | 3400 EXPECT_EQ(1, d.response_started_count()); |
3398 EXPECT_FALSE(d.received_data_before_response()); | 3401 EXPECT_FALSE(d.received_data_before_response()); |
3399 EXPECT_NE(0, d.bytes_received()); | 3402 EXPECT_NE(0, d.bytes_received()); |
3400 EXPECT_EQ(test_server_.host_port_pair().host(), | 3403 EXPECT_EQ(test_server_.host_port_pair().host(), |
3401 r.GetSocketAddress().host()); | 3404 r.GetSocketAddress().host()); |
(...skipping 28 matching lines...) Expand all Loading... |
3430 | 3433 |
3431 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3434 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
3432 TestURLRequestContext context(true); | 3435 TestURLRequestContext context(true); |
3433 context.set_network_delegate(&network_delegate); | 3436 context.set_network_delegate(&network_delegate); |
3434 context.Init(); | 3437 context.Init(); |
3435 | 3438 |
3436 URLRequest r(test_server_.GetURL(test_file), &d, &context); | 3439 URLRequest r(test_server_.GetURL(test_file), &d, &context); |
3437 r.Start(); | 3440 r.Start(); |
3438 EXPECT_TRUE(r.is_pending()); | 3441 EXPECT_TRUE(r.is_pending()); |
3439 | 3442 |
3440 base::MessageLoop::current()->Run(); | 3443 base::RunLoop().Run(); |
3441 | 3444 |
3442 EXPECT_EQ(1, d.response_started_count()); | 3445 EXPECT_EQ(1, d.response_started_count()); |
3443 EXPECT_FALSE(d.received_data_before_response()); | 3446 EXPECT_FALSE(d.received_data_before_response()); |
3444 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 3447 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
3445 << " status = " << r.status().status() | 3448 << " status = " << r.status().status() |
3446 << " error = " << r.status().error(); | 3449 << " error = " << r.status().error(); |
3447 if (test_expect_success[i]) { | 3450 if (test_expect_success[i]) { |
3448 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) | 3451 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) |
3449 << " Parameter = \"" << test_file << "\""; | 3452 << " Parameter = \"" << test_file << "\""; |
3450 } else { | 3453 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
3466 | 3469 |
3467 // An https server is sent a request with an https referer, | 3470 // An https server is sent a request with an https referer, |
3468 // and responds with a redirect to an http url. The http | 3471 // and responds with a redirect to an http url. The http |
3469 // server should not be sent the referer. | 3472 // server should not be sent the referer. |
3470 GURL http_destination = test_server_.GetURL(std::string()); | 3473 GURL http_destination = test_server_.GetURL(std::string()); |
3471 TestDelegate d; | 3474 TestDelegate d; |
3472 URLRequest req(https_test_server.GetURL( | 3475 URLRequest req(https_test_server.GetURL( |
3473 "server-redirect?" + http_destination.spec()), &d, &default_context_); | 3476 "server-redirect?" + http_destination.spec()), &d, &default_context_); |
3474 req.SetReferrer("https://www.referrer.com/"); | 3477 req.SetReferrer("https://www.referrer.com/"); |
3475 req.Start(); | 3478 req.Start(); |
3476 base::MessageLoop::current()->Run(); | 3479 base::RunLoop().Run(); |
3477 | 3480 |
3478 EXPECT_EQ(1, d.response_started_count()); | 3481 EXPECT_EQ(1, d.response_started_count()); |
3479 EXPECT_EQ(1, d.received_redirect_count()); | 3482 EXPECT_EQ(1, d.received_redirect_count()); |
3480 EXPECT_EQ(http_destination, req.url()); | 3483 EXPECT_EQ(http_destination, req.url()); |
3481 EXPECT_EQ(std::string(), req.referrer()); | 3484 EXPECT_EQ(std::string(), req.referrer()); |
3482 } | 3485 } |
3483 | 3486 |
3484 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 3487 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
3485 ASSERT_TRUE(test_server_.Start()); | 3488 ASSERT_TRUE(test_server_.Start()); |
3486 | 3489 |
3487 GURL destination_url = test_server_.GetURL(std::string()); | 3490 GURL destination_url = test_server_.GetURL(std::string()); |
3488 GURL original_url = | 3491 GURL original_url = |
3489 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3492 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
3490 TestDelegate d; | 3493 TestDelegate d; |
3491 URLRequest req(original_url, &d, &default_context_); | 3494 URLRequest req(original_url, &d, &default_context_); |
3492 req.Start(); | 3495 req.Start(); |
3493 base::MessageLoop::current()->Run(); | 3496 base::RunLoop().Run(); |
3494 | 3497 |
3495 EXPECT_EQ(1, d.response_started_count()); | 3498 EXPECT_EQ(1, d.response_started_count()); |
3496 EXPECT_EQ(1, d.received_redirect_count()); | 3499 EXPECT_EQ(1, d.received_redirect_count()); |
3497 EXPECT_EQ(destination_url, req.url()); | 3500 EXPECT_EQ(destination_url, req.url()); |
3498 EXPECT_EQ(original_url, req.original_url()); | 3501 EXPECT_EQ(original_url, req.original_url()); |
3499 ASSERT_EQ(2U, req.url_chain().size()); | 3502 ASSERT_EQ(2U, req.url_chain().size()); |
3500 EXPECT_EQ(original_url, req.url_chain()[0]); | 3503 EXPECT_EQ(original_url, req.url_chain()[0]); |
3501 EXPECT_EQ(destination_url, req.url_chain()[1]); | 3504 EXPECT_EQ(destination_url, req.url_chain()[1]); |
3502 | 3505 |
3503 LoadTimingInfo load_timing_info_before_redirect; | 3506 LoadTimingInfo load_timing_info_before_redirect; |
(...skipping 19 matching lines...) Expand all Loading... |
3523 ASSERT_TRUE(test_server_.Start()); | 3526 ASSERT_TRUE(test_server_.Start()); |
3524 | 3527 |
3525 GURL destination_url = test_server_.GetURL(std::string()); | 3528 GURL destination_url = test_server_.GetURL(std::string()); |
3526 GURL middle_redirect_url = | 3529 GURL middle_redirect_url = |
3527 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3530 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
3528 GURL original_url = test_server_.GetURL( | 3531 GURL original_url = test_server_.GetURL( |
3529 "server-redirect?" + middle_redirect_url.spec()); | 3532 "server-redirect?" + middle_redirect_url.spec()); |
3530 TestDelegate d; | 3533 TestDelegate d; |
3531 URLRequest req(original_url, &d, &default_context_); | 3534 URLRequest req(original_url, &d, &default_context_); |
3532 req.Start(); | 3535 req.Start(); |
3533 base::MessageLoop::current()->Run(); | 3536 base::RunLoop().Run(); |
3534 | 3537 |
3535 EXPECT_EQ(1, d.response_started_count()); | 3538 EXPECT_EQ(1, d.response_started_count()); |
3536 EXPECT_EQ(2, d.received_redirect_count()); | 3539 EXPECT_EQ(2, d.received_redirect_count()); |
3537 EXPECT_EQ(destination_url, req.url()); | 3540 EXPECT_EQ(destination_url, req.url()); |
3538 EXPECT_EQ(original_url, req.original_url()); | 3541 EXPECT_EQ(original_url, req.original_url()); |
3539 ASSERT_EQ(3U, req.url_chain().size()); | 3542 ASSERT_EQ(3U, req.url_chain().size()); |
3540 EXPECT_EQ(original_url, req.url_chain()[0]); | 3543 EXPECT_EQ(original_url, req.url_chain()[0]); |
3541 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 3544 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
3542 EXPECT_EQ(destination_url, req.url_chain()[2]); | 3545 EXPECT_EQ(destination_url, req.url_chain()[2]); |
3543 } | 3546 } |
(...skipping 17 matching lines...) Expand all Loading... |
3561 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 3564 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
3562 ASSERT_TRUE(test_server_.Start()); | 3565 ASSERT_TRUE(test_server_.Start()); |
3563 | 3566 |
3564 GURL destination_url = test_server_.GetURL( | 3567 GURL destination_url = test_server_.GetURL( |
3565 "echoheader?" + std::string(kExtraHeader)); | 3568 "echoheader?" + std::string(kExtraHeader)); |
3566 GURL original_url = test_server_.GetURL( | 3569 GURL original_url = test_server_.GetURL( |
3567 "server-redirect?" + destination_url.spec()); | 3570 "server-redirect?" + destination_url.spec()); |
3568 RedirectWithAdditionalHeadersDelegate d; | 3571 RedirectWithAdditionalHeadersDelegate d; |
3569 URLRequest req(original_url, &d, &default_context_); | 3572 URLRequest req(original_url, &d, &default_context_); |
3570 req.Start(); | 3573 req.Start(); |
3571 base::MessageLoop::current()->Run(); | 3574 base::RunLoop().Run(); |
3572 | 3575 |
3573 std::string value; | 3576 std::string value; |
3574 const HttpRequestHeaders& headers = req.extra_request_headers(); | 3577 const HttpRequestHeaders& headers = req.extra_request_headers(); |
3575 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 3578 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
3576 EXPECT_EQ(kExtraValue, value); | 3579 EXPECT_EQ(kExtraValue, value); |
3577 EXPECT_FALSE(req.is_pending()); | 3580 EXPECT_FALSE(req.is_pending()); |
3578 EXPECT_FALSE(req.is_redirecting()); | 3581 EXPECT_FALSE(req.is_redirecting()); |
3579 EXPECT_EQ(kExtraValue, d.data_received()); | 3582 EXPECT_EQ(kExtraValue, d.data_received()); |
3580 } | 3583 } |
3581 | 3584 |
(...skipping 16 matching lines...) Expand all Loading... |
3598 ASSERT_TRUE(test_server_.Start()); | 3601 ASSERT_TRUE(test_server_.Start()); |
3599 | 3602 |
3600 GURL destination_url = test_server_.GetURL( | 3603 GURL destination_url = test_server_.GetURL( |
3601 "echoheader?" + std::string(kExtraHeaderToRemove)); | 3604 "echoheader?" + std::string(kExtraHeaderToRemove)); |
3602 GURL original_url = test_server_.GetURL( | 3605 GURL original_url = test_server_.GetURL( |
3603 "server-redirect?" + destination_url.spec()); | 3606 "server-redirect?" + destination_url.spec()); |
3604 RedirectWithHeaderRemovalDelegate d; | 3607 RedirectWithHeaderRemovalDelegate d; |
3605 URLRequest req(original_url, &d, &default_context_); | 3608 URLRequest req(original_url, &d, &default_context_); |
3606 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 3609 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
3607 req.Start(); | 3610 req.Start(); |
3608 base::MessageLoop::current()->Run(); | 3611 base::RunLoop().Run(); |
3609 | 3612 |
3610 std::string value; | 3613 std::string value; |
3611 const HttpRequestHeaders& headers = req.extra_request_headers(); | 3614 const HttpRequestHeaders& headers = req.extra_request_headers(); |
3612 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 3615 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
3613 EXPECT_FALSE(req.is_pending()); | 3616 EXPECT_FALSE(req.is_pending()); |
3614 EXPECT_FALSE(req.is_redirecting()); | 3617 EXPECT_FALSE(req.is_redirecting()); |
3615 EXPECT_EQ("None", d.data_received()); | 3618 EXPECT_EQ("None", d.data_received()); |
3616 } | 3619 } |
3617 | 3620 |
3618 TEST_F(URLRequestTestHTTP, CancelTest) { | 3621 TEST_F(URLRequestTestHTTP, CancelTest) { |
3619 TestDelegate d; | 3622 TestDelegate d; |
3620 { | 3623 { |
3621 URLRequest r(GURL("http://www.google.com/"), &d, &default_context_); | 3624 URLRequest r(GURL("http://www.google.com/"), &d, &default_context_); |
3622 | 3625 |
3623 r.Start(); | 3626 r.Start(); |
3624 EXPECT_TRUE(r.is_pending()); | 3627 EXPECT_TRUE(r.is_pending()); |
3625 | 3628 |
3626 r.Cancel(); | 3629 r.Cancel(); |
3627 | 3630 |
3628 base::MessageLoop::current()->Run(); | 3631 base::RunLoop().Run(); |
3629 | 3632 |
3630 // We expect to receive OnResponseStarted even though the request has been | 3633 // We expect to receive OnResponseStarted even though the request has been |
3631 // cancelled. | 3634 // cancelled. |
3632 EXPECT_EQ(1, d.response_started_count()); | 3635 EXPECT_EQ(1, d.response_started_count()); |
3633 EXPECT_EQ(0, d.bytes_received()); | 3636 EXPECT_EQ(0, d.bytes_received()); |
3634 EXPECT_FALSE(d.received_data_before_response()); | 3637 EXPECT_FALSE(d.received_data_before_response()); |
3635 } | 3638 } |
3636 } | 3639 } |
3637 | 3640 |
3638 TEST_F(URLRequestTestHTTP, CancelTest2) { | 3641 TEST_F(URLRequestTestHTTP, CancelTest2) { |
3639 ASSERT_TRUE(test_server_.Start()); | 3642 ASSERT_TRUE(test_server_.Start()); |
3640 | 3643 |
3641 TestDelegate d; | 3644 TestDelegate d; |
3642 { | 3645 { |
3643 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3646 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); |
3644 | 3647 |
3645 d.set_cancel_in_response_started(true); | 3648 d.set_cancel_in_response_started(true); |
3646 | 3649 |
3647 r.Start(); | 3650 r.Start(); |
3648 EXPECT_TRUE(r.is_pending()); | 3651 EXPECT_TRUE(r.is_pending()); |
3649 | 3652 |
3650 base::MessageLoop::current()->Run(); | 3653 base::RunLoop().Run(); |
3651 | 3654 |
3652 EXPECT_EQ(1, d.response_started_count()); | 3655 EXPECT_EQ(1, d.response_started_count()); |
3653 EXPECT_EQ(0, d.bytes_received()); | 3656 EXPECT_EQ(0, d.bytes_received()); |
3654 EXPECT_FALSE(d.received_data_before_response()); | 3657 EXPECT_FALSE(d.received_data_before_response()); |
3655 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3658 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3656 } | 3659 } |
3657 } | 3660 } |
3658 | 3661 |
3659 TEST_F(URLRequestTestHTTP, CancelTest3) { | 3662 TEST_F(URLRequestTestHTTP, CancelTest3) { |
3660 ASSERT_TRUE(test_server_.Start()); | 3663 ASSERT_TRUE(test_server_.Start()); |
3661 | 3664 |
3662 TestDelegate d; | 3665 TestDelegate d; |
3663 { | 3666 { |
3664 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3667 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); |
3665 | 3668 |
3666 d.set_cancel_in_received_data(true); | 3669 d.set_cancel_in_received_data(true); |
3667 | 3670 |
3668 r.Start(); | 3671 r.Start(); |
3669 EXPECT_TRUE(r.is_pending()); | 3672 EXPECT_TRUE(r.is_pending()); |
3670 | 3673 |
3671 base::MessageLoop::current()->Run(); | 3674 base::RunLoop().Run(); |
3672 | 3675 |
3673 EXPECT_EQ(1, d.response_started_count()); | 3676 EXPECT_EQ(1, d.response_started_count()); |
3674 // There is no guarantee about how much data was received | 3677 // There is no guarantee about how much data was received |
3675 // before the cancel was issued. It could have been 0 bytes, | 3678 // before the cancel was issued. It could have been 0 bytes, |
3676 // or it could have been all the bytes. | 3679 // or it could have been all the bytes. |
3677 // EXPECT_EQ(0, d.bytes_received()); | 3680 // EXPECT_EQ(0, d.bytes_received()); |
3678 EXPECT_FALSE(d.received_data_before_response()); | 3681 EXPECT_FALSE(d.received_data_before_response()); |
3679 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3682 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3680 } | 3683 } |
3681 } | 3684 } |
(...skipping 24 matching lines...) Expand all Loading... |
3706 } | 3709 } |
3707 | 3710 |
3708 TEST_F(URLRequestTestHTTP, CancelTest5) { | 3711 TEST_F(URLRequestTestHTTP, CancelTest5) { |
3709 ASSERT_TRUE(test_server_.Start()); | 3712 ASSERT_TRUE(test_server_.Start()); |
3710 | 3713 |
3711 // populate cache | 3714 // populate cache |
3712 { | 3715 { |
3713 TestDelegate d; | 3716 TestDelegate d; |
3714 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); | 3717 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); |
3715 r.Start(); | 3718 r.Start(); |
3716 base::MessageLoop::current()->Run(); | 3719 base::RunLoop().Run(); |
3717 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3720 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
3718 } | 3721 } |
3719 | 3722 |
3720 // cancel read from cache (see bug 990242) | 3723 // cancel read from cache (see bug 990242) |
3721 { | 3724 { |
3722 TestDelegate d; | 3725 TestDelegate d; |
3723 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); | 3726 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); |
3724 r.Start(); | 3727 r.Start(); |
3725 r.Cancel(); | 3728 r.Cancel(); |
3726 base::MessageLoop::current()->Run(); | 3729 base::RunLoop().Run(); |
3727 | 3730 |
3728 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3731 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
3729 EXPECT_EQ(1, d.response_started_count()); | 3732 EXPECT_EQ(1, d.response_started_count()); |
3730 EXPECT_EQ(0, d.bytes_received()); | 3733 EXPECT_EQ(0, d.bytes_received()); |
3731 EXPECT_FALSE(d.received_data_before_response()); | 3734 EXPECT_FALSE(d.received_data_before_response()); |
3732 } | 3735 } |
3733 } | 3736 } |
3734 | 3737 |
3735 TEST_F(URLRequestTestHTTP, PostTest) { | 3738 TEST_F(URLRequestTestHTTP, PostTest) { |
3736 ASSERT_TRUE(test_server_.Start()); | 3739 ASSERT_TRUE(test_server_.Start()); |
3737 HTTPUploadDataOperationTest("POST"); | 3740 HTTPUploadDataOperationTest("POST"); |
3738 } | 3741 } |
3739 | 3742 |
3740 TEST_F(URLRequestTestHTTP, PutTest) { | 3743 TEST_F(URLRequestTestHTTP, PutTest) { |
3741 ASSERT_TRUE(test_server_.Start()); | 3744 ASSERT_TRUE(test_server_.Start()); |
3742 HTTPUploadDataOperationTest("PUT"); | 3745 HTTPUploadDataOperationTest("PUT"); |
3743 } | 3746 } |
3744 | 3747 |
3745 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 3748 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
3746 ASSERT_TRUE(test_server_.Start()); | 3749 ASSERT_TRUE(test_server_.Start()); |
3747 | 3750 |
3748 TestDelegate d; | 3751 TestDelegate d; |
3749 { | 3752 { |
3750 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 3753 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
3751 r.set_method("POST"); | 3754 r.set_method("POST"); |
3752 | 3755 |
3753 r.Start(); | 3756 r.Start(); |
3754 EXPECT_TRUE(r.is_pending()); | 3757 EXPECT_TRUE(r.is_pending()); |
3755 | 3758 |
3756 base::MessageLoop::current()->Run(); | 3759 base::RunLoop().Run(); |
3757 | 3760 |
3758 ASSERT_EQ(1, d.response_started_count()) | 3761 ASSERT_EQ(1, d.response_started_count()) |
3759 << "request failed: " << r.status().status() | 3762 << "request failed: " << r.status().status() |
3760 << ", error: " << r.status().error(); | 3763 << ", error: " << r.status().error(); |
3761 | 3764 |
3762 EXPECT_FALSE(d.received_data_before_response()); | 3765 EXPECT_FALSE(d.received_data_before_response()); |
3763 EXPECT_TRUE(d.data_received().empty()); | 3766 EXPECT_TRUE(d.data_received().empty()); |
3764 } | 3767 } |
3765 } | 3768 } |
3766 | 3769 |
(...skipping 30 matching lines...) Expand all Loading... |
3797 base::FilePath(FILE_PATH_LITERAL( | 3800 base::FilePath(FILE_PATH_LITERAL( |
3798 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 3801 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
3799 0, | 3802 0, |
3800 kuint64max, | 3803 kuint64max, |
3801 base::Time())); | 3804 base::Time())); |
3802 r.set_upload(make_scoped_ptr(new UploadDataStream(&element_readers, 0))); | 3805 r.set_upload(make_scoped_ptr(new UploadDataStream(&element_readers, 0))); |
3803 | 3806 |
3804 r.Start(); | 3807 r.Start(); |
3805 EXPECT_TRUE(r.is_pending()); | 3808 EXPECT_TRUE(r.is_pending()); |
3806 | 3809 |
3807 base::MessageLoop::current()->Run(); | 3810 base::RunLoop().Run(); |
3808 | 3811 |
3809 int64 size = 0; | 3812 int64 size = 0; |
3810 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); | 3813 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); |
3811 scoped_ptr<char[]> buf(new char[size]); | 3814 scoped_ptr<char[]> buf(new char[size]); |
3812 | 3815 |
3813 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); | 3816 ASSERT_EQ(size, file_util::ReadFile(path, buf.get(), size)); |
3814 | 3817 |
3815 ASSERT_EQ(1, d.response_started_count()) | 3818 ASSERT_EQ(1, d.response_started_count()) |
3816 << "request failed: " << r.status().status() | 3819 << "request failed: " << r.status().status() |
3817 << ", error: " << r.status().error(); | 3820 << ", error: " << r.status().error(); |
(...skipping 10 matching lines...) Expand all Loading... |
3828 | 3831 |
3829 TestDelegate d; | 3832 TestDelegate d; |
3830 { | 3833 { |
3831 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 3834 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
3832 r.EnableChunkedUpload(); | 3835 r.EnableChunkedUpload(); |
3833 r.set_method("POST"); | 3836 r.set_method("POST"); |
3834 AddChunksToUpload(&r); | 3837 AddChunksToUpload(&r); |
3835 r.Start(); | 3838 r.Start(); |
3836 EXPECT_TRUE(r.is_pending()); | 3839 EXPECT_TRUE(r.is_pending()); |
3837 | 3840 |
3838 base::MessageLoop::current()->Run(); | 3841 base::RunLoop().Run(); |
3839 | 3842 |
3840 VerifyReceivedDataMatchesChunks(&r, &d); | 3843 VerifyReceivedDataMatchesChunks(&r, &d); |
3841 } | 3844 } |
3842 } | 3845 } |
3843 | 3846 |
3844 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 3847 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
3845 ASSERT_TRUE(test_server_.Start()); | 3848 ASSERT_TRUE(test_server_.Start()); |
3846 | 3849 |
3847 TestDelegate d; | 3850 TestDelegate d; |
3848 { | 3851 { |
3849 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 3852 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
3850 r.EnableChunkedUpload(); | 3853 r.EnableChunkedUpload(); |
3851 r.set_method("POST"); | 3854 r.set_method("POST"); |
3852 r.Start(); | 3855 r.Start(); |
3853 EXPECT_TRUE(r.is_pending()); | 3856 EXPECT_TRUE(r.is_pending()); |
3854 AddChunksToUpload(&r); | 3857 AddChunksToUpload(&r); |
3855 base::MessageLoop::current()->Run(); | 3858 base::RunLoop().Run(); |
3856 | 3859 |
3857 VerifyReceivedDataMatchesChunks(&r, &d); | 3860 VerifyReceivedDataMatchesChunks(&r, &d); |
3858 } | 3861 } |
3859 } | 3862 } |
3860 | 3863 |
3861 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 3864 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
3862 ASSERT_TRUE(test_server_.Start()); | 3865 ASSERT_TRUE(test_server_.Start()); |
3863 | 3866 |
3864 TestDelegate d; | 3867 TestDelegate d; |
3865 { | 3868 { |
3866 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 3869 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
3867 r.EnableChunkedUpload(); | 3870 r.EnableChunkedUpload(); |
3868 r.set_method("POST"); | 3871 r.set_method("POST"); |
3869 r.Start(); | 3872 r.Start(); |
3870 EXPECT_TRUE(r.is_pending()); | 3873 EXPECT_TRUE(r.is_pending()); |
3871 | 3874 |
3872 base::MessageLoop::current()->RunUntilIdle(); | 3875 base::RunLoop().RunUntilIdle(); |
3873 AddChunksToUpload(&r); | 3876 AddChunksToUpload(&r); |
3874 base::MessageLoop::current()->Run(); | 3877 base::RunLoop().Run(); |
3875 | 3878 |
3876 VerifyReceivedDataMatchesChunks(&r, &d); | 3879 VerifyReceivedDataMatchesChunks(&r, &d); |
3877 } | 3880 } |
3878 } | 3881 } |
3879 | 3882 |
3880 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 3883 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
3881 ASSERT_TRUE(test_server_.Start()); | 3884 ASSERT_TRUE(test_server_.Start()); |
3882 | 3885 |
3883 TestDelegate d; | 3886 TestDelegate d; |
3884 URLRequest req( | 3887 URLRequest req( |
3885 test_server_.GetURL("files/with-headers.html"), &d, &default_context_); | 3888 test_server_.GetURL("files/with-headers.html"), &d, &default_context_); |
3886 req.Start(); | 3889 req.Start(); |
3887 base::MessageLoop::current()->Run(); | 3890 base::RunLoop().Run(); |
3888 | 3891 |
3889 const HttpResponseHeaders* headers = req.response_headers(); | 3892 const HttpResponseHeaders* headers = req.response_headers(); |
3890 | 3893 |
3891 // Simple sanity check that response_info() accesses the same data. | 3894 // Simple sanity check that response_info() accesses the same data. |
3892 EXPECT_EQ(headers, req.response_info().headers.get()); | 3895 EXPECT_EQ(headers, req.response_info().headers.get()); |
3893 | 3896 |
3894 std::string header; | 3897 std::string header; |
3895 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 3898 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
3896 EXPECT_EQ("private", header); | 3899 EXPECT_EQ("private", header); |
3897 | 3900 |
(...skipping 15 matching lines...) Expand all Loading... |
3913 ssl_options, | 3916 ssl_options, |
3914 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 3917 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
3915 ASSERT_TRUE(https_test_server.Start()); | 3918 ASSERT_TRUE(https_test_server.Start()); |
3916 | 3919 |
3917 TestDelegate d; | 3920 TestDelegate d; |
3918 URLRequest request( | 3921 URLRequest request( |
3919 https_test_server.GetURL("files/hsts-headers.html"), | 3922 https_test_server.GetURL("files/hsts-headers.html"), |
3920 &d, | 3923 &d, |
3921 &default_context_); | 3924 &default_context_); |
3922 request.Start(); | 3925 request.Start(); |
3923 base::MessageLoop::current()->Run(); | 3926 base::RunLoop().Run(); |
3924 | 3927 |
3925 TransportSecurityState* security_state = | 3928 TransportSecurityState* security_state = |
3926 default_context_.transport_security_state(); | 3929 default_context_.transport_security_state(); |
3927 bool sni_available = true; | 3930 bool sni_available = true; |
3928 TransportSecurityState::DomainState domain_state; | 3931 TransportSecurityState::DomainState domain_state; |
3929 EXPECT_TRUE(security_state->GetDomainState( | 3932 EXPECT_TRUE(security_state->GetDomainState( |
3930 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 3933 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
3931 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 3934 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
3932 domain_state.upgrade_mode); | 3935 domain_state.upgrade_mode); |
3933 EXPECT_TRUE(domain_state.sts_include_subdomains); | 3936 EXPECT_TRUE(domain_state.sts_include_subdomains); |
(...skipping 23 matching lines...) Expand all Loading... |
3957 ssl_options, | 3960 ssl_options, |
3958 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 3961 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
3959 ASSERT_TRUE(https_test_server.Start()); | 3962 ASSERT_TRUE(https_test_server.Start()); |
3960 | 3963 |
3961 TestDelegate d; | 3964 TestDelegate d; |
3962 URLRequest request( | 3965 URLRequest request( |
3963 https_test_server.GetURL("files/hpkp-headers.html"), | 3966 https_test_server.GetURL("files/hpkp-headers.html"), |
3964 &d, | 3967 &d, |
3965 &default_context_); | 3968 &default_context_); |
3966 request.Start(); | 3969 request.Start(); |
3967 base::MessageLoop::current()->Run(); | 3970 base::RunLoop().Run(); |
3968 | 3971 |
3969 TransportSecurityState* security_state = | 3972 TransportSecurityState* security_state = |
3970 default_context_.transport_security_state(); | 3973 default_context_.transport_security_state(); |
3971 bool sni_available = true; | 3974 bool sni_available = true; |
3972 TransportSecurityState::DomainState domain_state; | 3975 TransportSecurityState::DomainState domain_state; |
3973 EXPECT_TRUE(security_state->GetDomainState( | 3976 EXPECT_TRUE(security_state->GetDomainState( |
3974 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 3977 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
3975 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, | 3978 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
3976 domain_state.upgrade_mode); | 3979 domain_state.upgrade_mode); |
3977 EXPECT_FALSE(domain_state.sts_include_subdomains); | 3980 EXPECT_FALSE(domain_state.sts_include_subdomains); |
(...skipping 10 matching lines...) Expand all Loading... |
3988 ssl_options, | 3991 ssl_options, |
3989 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 3992 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
3990 ASSERT_TRUE(https_test_server.Start()); | 3993 ASSERT_TRUE(https_test_server.Start()); |
3991 | 3994 |
3992 TestDelegate d; | 3995 TestDelegate d; |
3993 URLRequest request( | 3996 URLRequest request( |
3994 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 3997 https_test_server.GetURL("files/hsts-multiple-headers.html"), |
3995 &d, | 3998 &d, |
3996 &default_context_); | 3999 &default_context_); |
3997 request.Start(); | 4000 request.Start(); |
3998 base::MessageLoop::current()->Run(); | 4001 base::RunLoop().Run(); |
3999 | 4002 |
4000 // We should have set parameters from the first header, not the second. | 4003 // We should have set parameters from the first header, not the second. |
4001 TransportSecurityState* security_state = | 4004 TransportSecurityState* security_state = |
4002 default_context_.transport_security_state(); | 4005 default_context_.transport_security_state(); |
4003 bool sni_available = true; | 4006 bool sni_available = true; |
4004 TransportSecurityState::DomainState domain_state; | 4007 TransportSecurityState::DomainState domain_state; |
4005 EXPECT_TRUE(security_state->GetDomainState( | 4008 EXPECT_TRUE(security_state->GetDomainState( |
4006 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 4009 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
4007 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4010 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
4008 domain_state.upgrade_mode); | 4011 domain_state.upgrade_mode); |
4009 EXPECT_FALSE(domain_state.sts_include_subdomains); | 4012 EXPECT_FALSE(domain_state.sts_include_subdomains); |
4010 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 4013 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
4011 } | 4014 } |
4012 | 4015 |
4013 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 4016 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
4014 SpawnedTestServer::SSLOptions ssl_options; | 4017 SpawnedTestServer::SSLOptions ssl_options; |
4015 SpawnedTestServer https_test_server( | 4018 SpawnedTestServer https_test_server( |
4016 SpawnedTestServer::TYPE_HTTPS, | 4019 SpawnedTestServer::TYPE_HTTPS, |
4017 ssl_options, | 4020 ssl_options, |
4018 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4021 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
4019 ASSERT_TRUE(https_test_server.Start()); | 4022 ASSERT_TRUE(https_test_server.Start()); |
4020 | 4023 |
4021 TestDelegate d; | 4024 TestDelegate d; |
4022 URLRequest request( | 4025 URLRequest request( |
4023 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 4026 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), |
4024 &d, | 4027 &d, |
4025 &default_context_); | 4028 &default_context_); |
4026 request.Start(); | 4029 request.Start(); |
4027 base::MessageLoop::current()->Run(); | 4030 base::RunLoop().Run(); |
4028 | 4031 |
4029 // We should have set parameters from the first header, not the second. | 4032 // We should have set parameters from the first header, not the second. |
4030 TransportSecurityState* security_state = | 4033 TransportSecurityState* security_state = |
4031 default_context_.transport_security_state(); | 4034 default_context_.transport_security_state(); |
4032 bool sni_available = true; | 4035 bool sni_available = true; |
4033 TransportSecurityState::DomainState domain_state; | 4036 TransportSecurityState::DomainState domain_state; |
4034 EXPECT_TRUE(security_state->GetDomainState( | 4037 EXPECT_TRUE(security_state->GetDomainState( |
4035 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 4038 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
4036 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4039 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
4037 domain_state.upgrade_mode); | 4040 domain_state.upgrade_mode); |
(...skipping 21 matching lines...) Expand all Loading... |
4059 ssl_options, | 4062 ssl_options, |
4060 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4063 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
4061 ASSERT_TRUE(https_test_server.Start()); | 4064 ASSERT_TRUE(https_test_server.Start()); |
4062 | 4065 |
4063 TestDelegate d; | 4066 TestDelegate d; |
4064 URLRequest request( | 4067 URLRequest request( |
4065 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 4068 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), |
4066 &d, | 4069 &d, |
4067 &default_context_); | 4070 &default_context_); |
4068 request.Start(); | 4071 request.Start(); |
4069 base::MessageLoop::current()->Run(); | 4072 base::RunLoop().Run(); |
4070 | 4073 |
4071 TransportSecurityState* security_state = | 4074 TransportSecurityState* security_state = |
4072 default_context_.transport_security_state(); | 4075 default_context_.transport_security_state(); |
4073 bool sni_available = true; | 4076 bool sni_available = true; |
4074 TransportSecurityState::DomainState domain_state; | 4077 TransportSecurityState::DomainState domain_state; |
4075 EXPECT_TRUE(security_state->GetDomainState( | 4078 EXPECT_TRUE(security_state->GetDomainState( |
4076 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 4079 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
4077 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4080 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
4078 domain_state.upgrade_mode); | 4081 domain_state.upgrade_mode); |
4079 #if defined(OS_ANDROID) | 4082 #if defined(OS_ANDROID) |
4080 // Android's CertVerifyProc does not (yet) handle pins. | 4083 // Android's CertVerifyProc does not (yet) handle pins. |
4081 #else | 4084 #else |
4082 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 4085 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
4083 #endif | 4086 #endif |
4084 EXPECT_NE(domain_state.upgrade_expiry, | 4087 EXPECT_NE(domain_state.upgrade_expiry, |
4085 domain_state.dynamic_spki_hashes_expiry); | 4088 domain_state.dynamic_spki_hashes_expiry); |
4086 | 4089 |
4087 EXPECT_TRUE(domain_state.sts_include_subdomains); | 4090 EXPECT_TRUE(domain_state.sts_include_subdomains); |
4088 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 4091 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
4089 } | 4092 } |
4090 | 4093 |
4091 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 4094 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
4092 ASSERT_TRUE(test_server_.Start()); | 4095 ASSERT_TRUE(test_server_.Start()); |
4093 | 4096 |
4094 TestDelegate d; | 4097 TestDelegate d; |
4095 URLRequest req(test_server_.GetURL( | 4098 URLRequest req(test_server_.GetURL( |
4096 "files/content-type-normalization.html"), &d, &default_context_); | 4099 "files/content-type-normalization.html"), &d, &default_context_); |
4097 req.Start(); | 4100 req.Start(); |
4098 base::MessageLoop::current()->Run(); | 4101 base::RunLoop().Run(); |
4099 | 4102 |
4100 std::string mime_type; | 4103 std::string mime_type; |
4101 req.GetMimeType(&mime_type); | 4104 req.GetMimeType(&mime_type); |
4102 EXPECT_EQ("text/html", mime_type); | 4105 EXPECT_EQ("text/html", mime_type); |
4103 | 4106 |
4104 std::string charset; | 4107 std::string charset; |
4105 req.GetCharset(&charset); | 4108 req.GetCharset(&charset); |
4106 EXPECT_EQ("utf-8", charset); | 4109 EXPECT_EQ("utf-8", charset); |
4107 req.Cancel(); | 4110 req.Cancel(); |
4108 } | 4111 } |
4109 | 4112 |
4110 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { | 4113 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) { |
4111 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). | 4114 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
4112 GURL file_url("file:///foo.txt"); | 4115 GURL file_url("file:///foo.txt"); |
4113 GURL data_url("data:,foo"); | 4116 GURL data_url("data:,foo"); |
4114 FileProtocolHandler file_protocol_handler; | 4117 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); |
4115 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); | 4118 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
4116 DataProtocolHandler data_protocol_handler; | 4119 DataProtocolHandler data_protocol_handler; |
4117 EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url)); | 4120 EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
4118 | 4121 |
4119 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 4122 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
4120 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); | 4123 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
4121 EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url)); | 4124 EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url)); |
4122 } | 4125 } |
4123 | 4126 |
4124 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 4127 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
4125 ASSERT_TRUE(test_server_.Start()); | 4128 ASSERT_TRUE(test_server_.Start()); |
4126 | 4129 |
4127 TestDelegate d; | 4130 TestDelegate d; |
4128 URLRequest req(test_server_.GetURL( | 4131 URLRequest req(test_server_.GetURL( |
4129 "files/redirect-to-file.html"), &d, &default_context_); | 4132 "files/redirect-to-file.html"), &d, &default_context_); |
4130 req.Start(); | 4133 req.Start(); |
4131 base::MessageLoop::current()->Run(); | 4134 base::RunLoop().Run(); |
4132 | 4135 |
4133 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 4136 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
4134 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 4137 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
4135 } | 4138 } |
4136 | 4139 |
4137 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 4140 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
4138 ASSERT_TRUE(test_server_.Start()); | 4141 ASSERT_TRUE(test_server_.Start()); |
4139 | 4142 |
4140 TestDelegate d; | 4143 TestDelegate d; |
4141 URLRequest req(test_server_.GetURL( | 4144 URLRequest req(test_server_.GetURL( |
4142 "files/redirect-to-invalid-url.html"), &d, &default_context_); | 4145 "files/redirect-to-invalid-url.html"), &d, &default_context_); |
4143 req.Start(); | 4146 req.Start(); |
4144 base::MessageLoop::current()->Run(); | 4147 base::RunLoop().Run(); |
4145 | 4148 |
4146 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 4149 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
4147 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); | 4150 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); |
4148 } | 4151 } |
4149 | 4152 |
4150 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 4153 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
4151 ASSERT_TRUE(test_server_.Start()); | 4154 ASSERT_TRUE(test_server_.Start()); |
4152 | 4155 |
4153 TestDelegate d; | 4156 TestDelegate d; |
4154 URLRequest req( | 4157 URLRequest req( |
4155 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 4158 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); |
4156 req.SetReferrer("http://user:pass@foo.com/"); | 4159 req.SetReferrer("http://user:pass@foo.com/"); |
4157 req.Start(); | 4160 req.Start(); |
4158 base::MessageLoop::current()->Run(); | 4161 base::RunLoop().Run(); |
4159 | 4162 |
4160 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 4163 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
4161 } | 4164 } |
4162 | 4165 |
4163 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { | 4166 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { |
4164 ASSERT_TRUE(test_server_.Start()); | 4167 ASSERT_TRUE(test_server_.Start()); |
4165 | 4168 |
4166 TestDelegate d; | 4169 TestDelegate d; |
4167 URLRequest req( | 4170 URLRequest req( |
4168 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 4171 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); |
4169 req.SetReferrer("http://foo.com/test#fragment"); | 4172 req.SetReferrer("http://foo.com/test#fragment"); |
4170 req.Start(); | 4173 req.Start(); |
4171 base::MessageLoop::current()->Run(); | 4174 base::RunLoop().Run(); |
4172 | 4175 |
4173 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); | 4176 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); |
4174 } | 4177 } |
4175 | 4178 |
4176 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { | 4179 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { |
4177 ASSERT_TRUE(test_server_.Start()); | 4180 ASSERT_TRUE(test_server_.Start()); |
4178 | 4181 |
4179 TestDelegate d; | 4182 TestDelegate d; |
4180 URLRequest req( | 4183 URLRequest req( |
4181 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 4184 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); |
4182 req.SetReferrer("http://foo.com/test#fragment"); | 4185 req.SetReferrer("http://foo.com/test#fragment"); |
4183 req.SetReferrer(""); | 4186 req.SetReferrer(""); |
4184 req.Start(); | 4187 req.Start(); |
4185 base::MessageLoop::current()->Run(); | 4188 base::RunLoop().Run(); |
4186 | 4189 |
4187 EXPECT_EQ(std::string("None"), d.data_received()); | 4190 EXPECT_EQ(std::string("None"), d.data_received()); |
4188 } | 4191 } |
4189 | 4192 |
4190 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 4193 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
4191 ASSERT_TRUE(test_server_.Start()); | 4194 ASSERT_TRUE(test_server_.Start()); |
4192 | 4195 |
4193 TestDelegate d; | 4196 TestDelegate d; |
4194 { | 4197 { |
4195 d.set_cancel_in_received_redirect(true); | 4198 d.set_cancel_in_received_redirect(true); |
4196 URLRequest req( | 4199 URLRequest req( |
4197 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 4200 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
4198 req.Start(); | 4201 req.Start(); |
4199 base::MessageLoop::current()->Run(); | 4202 base::RunLoop().Run(); |
4200 | 4203 |
4201 EXPECT_EQ(1, d.response_started_count()); | 4204 EXPECT_EQ(1, d.response_started_count()); |
4202 EXPECT_EQ(0, d.bytes_received()); | 4205 EXPECT_EQ(0, d.bytes_received()); |
4203 EXPECT_FALSE(d.received_data_before_response()); | 4206 EXPECT_FALSE(d.received_data_before_response()); |
4204 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 4207 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
4205 } | 4208 } |
4206 } | 4209 } |
4207 | 4210 |
4208 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 4211 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
4209 ASSERT_TRUE(test_server_.Start()); | 4212 ASSERT_TRUE(test_server_.Start()); |
4210 | 4213 |
4211 TestDelegate d; | 4214 TestDelegate d; |
4212 { | 4215 { |
4213 d.set_quit_on_redirect(true); | 4216 d.set_quit_on_redirect(true); |
4214 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 4217 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
4215 URLRequest req(test_url, &d, &default_context_); | 4218 URLRequest req(test_url, &d, &default_context_); |
4216 | 4219 |
4217 req.Start(); | 4220 req.Start(); |
4218 base::MessageLoop::current()->Run(); | 4221 base::RunLoop().Run(); |
4219 | 4222 |
4220 EXPECT_EQ(1, d.received_redirect_count()); | 4223 EXPECT_EQ(1, d.received_redirect_count()); |
4221 | 4224 |
4222 req.FollowDeferredRedirect(); | 4225 req.FollowDeferredRedirect(); |
4223 base::MessageLoop::current()->Run(); | 4226 base::RunLoop().Run(); |
4224 | 4227 |
4225 EXPECT_EQ(1, d.response_started_count()); | 4228 EXPECT_EQ(1, d.response_started_count()); |
4226 EXPECT_FALSE(d.received_data_before_response()); | 4229 EXPECT_FALSE(d.received_data_before_response()); |
4227 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 4230 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
4228 | 4231 |
4229 base::FilePath path; | 4232 base::FilePath path; |
4230 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 4233 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
4231 path = path.Append(FILE_PATH_LITERAL("net")); | 4234 path = path.Append(FILE_PATH_LITERAL("net")); |
4232 path = path.Append(FILE_PATH_LITERAL("data")); | 4235 path = path.Append(FILE_PATH_LITERAL("data")); |
4233 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4236 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
(...skipping 10 matching lines...) Expand all Loading... |
4244 | 4247 |
4245 TestDelegate d; | 4248 TestDelegate d; |
4246 { | 4249 { |
4247 d.set_quit_on_redirect(true); | 4250 d.set_quit_on_redirect(true); |
4248 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 4251 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
4249 URLRequest req(test_url, &d, &default_context_); | 4252 URLRequest req(test_url, &d, &default_context_); |
4250 | 4253 |
4251 EXPECT_FALSE(d.have_full_request_headers()); | 4254 EXPECT_FALSE(d.have_full_request_headers()); |
4252 | 4255 |
4253 req.Start(); | 4256 req.Start(); |
4254 base::MessageLoop::current()->Run(); | 4257 base::RunLoop().Run(); |
4255 | 4258 |
4256 EXPECT_EQ(1, d.received_redirect_count()); | 4259 EXPECT_EQ(1, d.received_redirect_count()); |
4257 EXPECT_TRUE(d.have_full_request_headers()); | 4260 EXPECT_TRUE(d.have_full_request_headers()); |
4258 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 4261 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
4259 d.ClearFullRequestHeaders(); | 4262 d.ClearFullRequestHeaders(); |
4260 | 4263 |
4261 req.FollowDeferredRedirect(); | 4264 req.FollowDeferredRedirect(); |
4262 base::MessageLoop::current()->Run(); | 4265 base::RunLoop().Run(); |
4263 | 4266 |
4264 GURL target_url(test_server_.GetURL("files/with-headers.html")); | 4267 GURL target_url(test_server_.GetURL("files/with-headers.html")); |
4265 EXPECT_EQ(1, d.response_started_count()); | 4268 EXPECT_EQ(1, d.response_started_count()); |
4266 EXPECT_TRUE(d.have_full_request_headers()); | 4269 EXPECT_TRUE(d.have_full_request_headers()); |
4267 CheckFullRequestHeaders(d.full_request_headers(), target_url); | 4270 CheckFullRequestHeaders(d.full_request_headers(), target_url); |
4268 EXPECT_FALSE(d.received_data_before_response()); | 4271 EXPECT_FALSE(d.received_data_before_response()); |
4269 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 4272 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
4270 | 4273 |
4271 base::FilePath path; | 4274 base::FilePath path; |
4272 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 4275 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
(...skipping 10 matching lines...) Expand all Loading... |
4283 | 4286 |
4284 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 4287 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
4285 ASSERT_TRUE(test_server_.Start()); | 4288 ASSERT_TRUE(test_server_.Start()); |
4286 | 4289 |
4287 TestDelegate d; | 4290 TestDelegate d; |
4288 { | 4291 { |
4289 d.set_quit_on_redirect(true); | 4292 d.set_quit_on_redirect(true); |
4290 URLRequest req( | 4293 URLRequest req( |
4291 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 4294 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
4292 req.Start(); | 4295 req.Start(); |
4293 base::MessageLoop::current()->Run(); | 4296 base::RunLoop().Run(); |
4294 | 4297 |
4295 EXPECT_EQ(1, d.received_redirect_count()); | 4298 EXPECT_EQ(1, d.received_redirect_count()); |
4296 | 4299 |
4297 req.Cancel(); | 4300 req.Cancel(); |
4298 base::MessageLoop::current()->Run(); | 4301 base::RunLoop().Run(); |
4299 | 4302 |
4300 EXPECT_EQ(1, d.response_started_count()); | 4303 EXPECT_EQ(1, d.response_started_count()); |
4301 EXPECT_EQ(0, d.bytes_received()); | 4304 EXPECT_EQ(0, d.bytes_received()); |
4302 EXPECT_FALSE(d.received_data_before_response()); | 4305 EXPECT_FALSE(d.received_data_before_response()); |
4303 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 4306 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
4304 } | 4307 } |
4305 } | 4308 } |
4306 | 4309 |
4307 TEST_F(URLRequestTestHTTP, VaryHeader) { | 4310 TEST_F(URLRequestTestHTTP, VaryHeader) { |
4308 ASSERT_TRUE(test_server_.Start()); | 4311 ASSERT_TRUE(test_server_.Start()); |
4309 | 4312 |
4310 // Populate the cache. | 4313 // Populate the cache. |
4311 { | 4314 { |
4312 TestDelegate d; | 4315 TestDelegate d; |
4313 URLRequest req( | 4316 URLRequest req( |
4314 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 4317 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
4315 HttpRequestHeaders headers; | 4318 HttpRequestHeaders headers; |
4316 headers.SetHeader("foo", "1"); | 4319 headers.SetHeader("foo", "1"); |
4317 req.SetExtraRequestHeaders(headers); | 4320 req.SetExtraRequestHeaders(headers); |
4318 req.Start(); | 4321 req.Start(); |
4319 base::MessageLoop::current()->Run(); | 4322 base::RunLoop().Run(); |
4320 | 4323 |
4321 LoadTimingInfo load_timing_info; | 4324 LoadTimingInfo load_timing_info; |
4322 req.GetLoadTimingInfo(&load_timing_info); | 4325 req.GetLoadTimingInfo(&load_timing_info); |
4323 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 4326 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
4324 } | 4327 } |
4325 | 4328 |
4326 // Expect a cache hit. | 4329 // Expect a cache hit. |
4327 { | 4330 { |
4328 TestDelegate d; | 4331 TestDelegate d; |
4329 URLRequest req( | 4332 URLRequest req( |
4330 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 4333 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
4331 HttpRequestHeaders headers; | 4334 HttpRequestHeaders headers; |
4332 headers.SetHeader("foo", "1"); | 4335 headers.SetHeader("foo", "1"); |
4333 req.SetExtraRequestHeaders(headers); | 4336 req.SetExtraRequestHeaders(headers); |
4334 req.Start(); | 4337 req.Start(); |
4335 base::MessageLoop::current()->Run(); | 4338 base::RunLoop().Run(); |
4336 | 4339 |
4337 EXPECT_TRUE(req.was_cached()); | 4340 EXPECT_TRUE(req.was_cached()); |
4338 | 4341 |
4339 LoadTimingInfo load_timing_info; | 4342 LoadTimingInfo load_timing_info; |
4340 req.GetLoadTimingInfo(&load_timing_info); | 4343 req.GetLoadTimingInfo(&load_timing_info); |
4341 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 4344 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
4342 } | 4345 } |
4343 | 4346 |
4344 // Expect a cache miss. | 4347 // Expect a cache miss. |
4345 { | 4348 { |
4346 TestDelegate d; | 4349 TestDelegate d; |
4347 URLRequest req( | 4350 URLRequest req( |
4348 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 4351 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
4349 HttpRequestHeaders headers; | 4352 HttpRequestHeaders headers; |
4350 headers.SetHeader("foo", "2"); | 4353 headers.SetHeader("foo", "2"); |
4351 req.SetExtraRequestHeaders(headers); | 4354 req.SetExtraRequestHeaders(headers); |
4352 req.Start(); | 4355 req.Start(); |
4353 base::MessageLoop::current()->Run(); | 4356 base::RunLoop().Run(); |
4354 | 4357 |
4355 EXPECT_FALSE(req.was_cached()); | 4358 EXPECT_FALSE(req.was_cached()); |
4356 | 4359 |
4357 LoadTimingInfo load_timing_info; | 4360 LoadTimingInfo load_timing_info; |
4358 req.GetLoadTimingInfo(&load_timing_info); | 4361 req.GetLoadTimingInfo(&load_timing_info); |
4359 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 4362 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
4360 } | 4363 } |
4361 } | 4364 } |
4362 | 4365 |
4363 TEST_F(URLRequestTestHTTP, BasicAuth) { | 4366 TEST_F(URLRequestTestHTTP, BasicAuth) { |
4364 ASSERT_TRUE(test_server_.Start()); | 4367 ASSERT_TRUE(test_server_.Start()); |
4365 | 4368 |
4366 // populate the cache | 4369 // populate the cache |
4367 { | 4370 { |
4368 TestDelegate d; | 4371 TestDelegate d; |
4369 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4372 d.set_credentials(AuthCredentials(kUser, kSecret)); |
4370 | 4373 |
4371 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 4374 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
4372 r.Start(); | 4375 r.Start(); |
4373 | 4376 |
4374 base::MessageLoop::current()->Run(); | 4377 base::RunLoop().Run(); |
4375 | 4378 |
4376 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 4379 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
4377 } | 4380 } |
4378 | 4381 |
4379 // repeat request with end-to-end validation. since auth-basic results in a | 4382 // repeat request with end-to-end validation. since auth-basic results in a |
4380 // cachable page, we expect this test to result in a 304. in which case, the | 4383 // cachable page, we expect this test to result in a 304. in which case, the |
4381 // response should be fetched from the cache. | 4384 // response should be fetched from the cache. |
4382 { | 4385 { |
4383 TestDelegate d; | 4386 TestDelegate d; |
4384 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4387 d.set_credentials(AuthCredentials(kUser, kSecret)); |
4385 | 4388 |
4386 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 4389 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
4387 r.set_load_flags(LOAD_VALIDATE_CACHE); | 4390 r.set_load_flags(LOAD_VALIDATE_CACHE); |
4388 r.Start(); | 4391 r.Start(); |
4389 | 4392 |
4390 base::MessageLoop::current()->Run(); | 4393 base::RunLoop().Run(); |
4391 | 4394 |
4392 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 4395 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
4393 | 4396 |
4394 // Should be the same cached document. | 4397 // Should be the same cached document. |
4395 EXPECT_TRUE(r.was_cached()); | 4398 EXPECT_TRUE(r.was_cached()); |
4396 } | 4399 } |
4397 } | 4400 } |
4398 | 4401 |
4399 // Check that Set-Cookie headers in 401 responses are respected. | 4402 // Check that Set-Cookie headers in 401 responses are respected. |
4400 // http://crbug.com/6450 | 4403 // http://crbug.com/6450 |
(...skipping 10 matching lines...) Expand all Loading... |
4411 TestURLRequestContext context(true); | 4414 TestURLRequestContext context(true); |
4412 context.set_network_delegate(&network_delegate); | 4415 context.set_network_delegate(&network_delegate); |
4413 context.Init(); | 4416 context.Init(); |
4414 | 4417 |
4415 TestDelegate d; | 4418 TestDelegate d; |
4416 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4419 d.set_credentials(AuthCredentials(kUser, kSecret)); |
4417 | 4420 |
4418 URLRequest r(url_requiring_auth, &d, &context); | 4421 URLRequest r(url_requiring_auth, &d, &context); |
4419 r.Start(); | 4422 r.Start(); |
4420 | 4423 |
4421 base::MessageLoop::current()->Run(); | 4424 base::RunLoop().Run(); |
4422 | 4425 |
4423 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 4426 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
4424 | 4427 |
4425 // Make sure we sent the cookie in the restarted transaction. | 4428 // Make sure we sent the cookie in the restarted transaction. |
4426 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 4429 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
4427 != std::string::npos); | 4430 != std::string::npos); |
4428 } | 4431 } |
4429 | 4432 |
4430 // Same test as above, except this time the restart is initiated earlier | 4433 // Same test as above, except this time the restart is initiated earlier |
4431 // (without user intervention since identity is embedded in the URL). | 4434 // (without user intervention since identity is embedded in the URL). |
4432 { | 4435 { |
4433 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4436 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
4434 TestURLRequestContext context(true); | 4437 TestURLRequestContext context(true); |
4435 context.set_network_delegate(&network_delegate); | 4438 context.set_network_delegate(&network_delegate); |
4436 context.Init(); | 4439 context.Init(); |
4437 | 4440 |
4438 TestDelegate d; | 4441 TestDelegate d; |
4439 | 4442 |
4440 GURL::Replacements replacements; | 4443 GURL::Replacements replacements; |
4441 std::string username("user2"); | 4444 std::string username("user2"); |
4442 std::string password("secret"); | 4445 std::string password("secret"); |
4443 replacements.SetUsernameStr(username); | 4446 replacements.SetUsernameStr(username); |
4444 replacements.SetPasswordStr(password); | 4447 replacements.SetPasswordStr(password); |
4445 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 4448 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
4446 | 4449 |
4447 URLRequest r(url_with_identity, &d, &context); | 4450 URLRequest r(url_with_identity, &d, &context); |
4448 r.Start(); | 4451 r.Start(); |
4449 | 4452 |
4450 base::MessageLoop::current()->Run(); | 4453 base::RunLoop().Run(); |
4451 | 4454 |
4452 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 4455 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
4453 | 4456 |
4454 // Make sure we sent the cookie in the restarted transaction. | 4457 // Make sure we sent the cookie in the restarted transaction. |
4455 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 4458 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
4456 != std::string::npos); | 4459 != std::string::npos); |
4457 } | 4460 } |
4458 } | 4461 } |
4459 | 4462 |
4460 // Tests that load timing works as expected with auth and the cache. | 4463 // Tests that load timing works as expected with auth and the cache. |
4461 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 4464 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
4462 ASSERT_TRUE(test_server_.Start()); | 4465 ASSERT_TRUE(test_server_.Start()); |
4463 | 4466 |
4464 // populate the cache | 4467 // populate the cache |
4465 { | 4468 { |
4466 TestDelegate d; | 4469 TestDelegate d; |
4467 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4470 d.set_credentials(AuthCredentials(kUser, kSecret)); |
4468 | 4471 |
4469 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 4472 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
4470 r.Start(); | 4473 r.Start(); |
4471 | 4474 |
4472 base::MessageLoop::current()->Run(); | 4475 base::RunLoop().Run(); |
4473 | 4476 |
4474 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 4477 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
4475 | 4478 |
4476 LoadTimingInfo load_timing_info_before_auth; | 4479 LoadTimingInfo load_timing_info_before_auth; |
4477 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( | 4480 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( |
4478 &load_timing_info_before_auth)); | 4481 &load_timing_info_before_auth)); |
4479 TestLoadTimingNotReused(load_timing_info_before_auth, | 4482 TestLoadTimingNotReused(load_timing_info_before_auth, |
4480 CONNECT_TIMING_HAS_DNS_TIMES); | 4483 CONNECT_TIMING_HAS_DNS_TIMES); |
4481 | 4484 |
4482 LoadTimingInfo load_timing_info; | 4485 LoadTimingInfo load_timing_info; |
(...skipping 11 matching lines...) Expand all Loading... |
4494 // cachable page, we expect this test to result in a 304. In which case, the | 4497 // cachable page, we expect this test to result in a 304. In which case, the |
4495 // response should be fetched from the cache. | 4498 // response should be fetched from the cache. |
4496 { | 4499 { |
4497 TestDelegate d; | 4500 TestDelegate d; |
4498 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4501 d.set_credentials(AuthCredentials(kUser, kSecret)); |
4499 | 4502 |
4500 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 4503 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
4501 r.set_load_flags(LOAD_VALIDATE_CACHE); | 4504 r.set_load_flags(LOAD_VALIDATE_CACHE); |
4502 r.Start(); | 4505 r.Start(); |
4503 | 4506 |
4504 base::MessageLoop::current()->Run(); | 4507 base::RunLoop().Run(); |
4505 | 4508 |
4506 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 4509 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
4507 | 4510 |
4508 // Should be the same cached document. | 4511 // Should be the same cached document. |
4509 EXPECT_TRUE(r.was_cached()); | 4512 EXPECT_TRUE(r.was_cached()); |
4510 | 4513 |
4511 // Since there was a request that went over the wire, the load timing | 4514 // Since there was a request that went over the wire, the load timing |
4512 // information should include connection times. | 4515 // information should include connection times. |
4513 LoadTimingInfo load_timing_info; | 4516 LoadTimingInfo load_timing_info; |
4514 r.GetLoadTimingInfo(&load_timing_info); | 4517 r.GetLoadTimingInfo(&load_timing_info); |
(...skipping 22 matching lines...) Expand all Loading... |
4537 "Content-Type: multipart/form-data; " | 4540 "Content-Type: multipart/form-data; " |
4538 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 4541 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
4539 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 4542 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
4540 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 4543 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
4541 "Accept-Language: en-US,en\r\n" | 4544 "Accept-Language: en-US,en\r\n" |
4542 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 4545 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
4543 "Content-Length: 11\r\n" | 4546 "Content-Length: 11\r\n" |
4544 "Origin: http://localhost:1337/"); | 4547 "Origin: http://localhost:1337/"); |
4545 req.SetExtraRequestHeaders(headers); | 4548 req.SetExtraRequestHeaders(headers); |
4546 req.Start(); | 4549 req.Start(); |
4547 base::MessageLoop::current()->Run(); | 4550 base::RunLoop().Run(); |
4548 | 4551 |
4549 std::string mime_type; | 4552 std::string mime_type; |
4550 req.GetMimeType(&mime_type); | 4553 req.GetMimeType(&mime_type); |
4551 EXPECT_EQ("text/html", mime_type); | 4554 EXPECT_EQ("text/html", mime_type); |
4552 | 4555 |
4553 const std::string& data = d.data_received(); | 4556 const std::string& data = d.data_received(); |
4554 | 4557 |
4555 // Check that the post-specific headers were stripped: | 4558 // Check that the post-specific headers were stripped: |
4556 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 4559 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
4557 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 4560 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4620 headers.SetHeader(HttpRequestHeaders::kContentLength, | 4623 headers.SetHeader(HttpRequestHeaders::kContentLength, |
4621 base::UintToString(arraysize(kData) - 1)); | 4624 base::UintToString(arraysize(kData) - 1)); |
4622 req.SetExtraRequestHeaders(headers); | 4625 req.SetExtraRequestHeaders(headers); |
4623 | 4626 |
4624 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 4627 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
4625 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 4628 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
4626 URLRequestRedirectJob::REDIRECT_302_FOUND); | 4629 URLRequestRedirectJob::REDIRECT_302_FOUND); |
4627 AddTestInterceptor()->set_main_intercept_job(job); | 4630 AddTestInterceptor()->set_main_intercept_job(job); |
4628 | 4631 |
4629 req.Start(); | 4632 req.Start(); |
4630 base::MessageLoop::current()->Run(); | 4633 base::RunLoop().Run(); |
4631 EXPECT_EQ("GET", req.method()); | 4634 EXPECT_EQ("GET", req.method()); |
4632 } | 4635 } |
4633 | 4636 |
4634 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 4637 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
4635 ASSERT_TRUE(test_server_.Start()); | 4638 ASSERT_TRUE(test_server_.Start()); |
4636 | 4639 |
4637 const char kData[] = "hello world"; | 4640 const char kData[] = "hello world"; |
4638 | 4641 |
4639 TestDelegate d; | 4642 TestDelegate d; |
4640 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 4643 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
4641 req.set_method("POST"); | 4644 req.set_method("POST"); |
4642 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 4645 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
4643 HttpRequestHeaders headers; | 4646 HttpRequestHeaders headers; |
4644 headers.SetHeader(HttpRequestHeaders::kContentLength, | 4647 headers.SetHeader(HttpRequestHeaders::kContentLength, |
4645 base::UintToString(arraysize(kData) - 1)); | 4648 base::UintToString(arraysize(kData) - 1)); |
4646 req.SetExtraRequestHeaders(headers); | 4649 req.SetExtraRequestHeaders(headers); |
4647 | 4650 |
4648 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 4651 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
4649 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 4652 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
4650 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 4653 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
4651 AddTestInterceptor()->set_main_intercept_job(job); | 4654 AddTestInterceptor()->set_main_intercept_job(job); |
4652 | 4655 |
4653 req.Start(); | 4656 req.Start(); |
4654 base::MessageLoop::current()->Run(); | 4657 base::RunLoop().Run(); |
4655 EXPECT_EQ("POST", req.method()); | 4658 EXPECT_EQ("POST", req.method()); |
4656 EXPECT_EQ(kData, d.data_received()); | 4659 EXPECT_EQ(kData, d.data_received()); |
4657 } | 4660 } |
4658 | 4661 |
4659 // Check that default A-L header is sent. | 4662 // Check that default A-L header is sent. |
4660 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 4663 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
4661 ASSERT_TRUE(test_server_.Start()); | 4664 ASSERT_TRUE(test_server_.Start()); |
4662 | 4665 |
4663 StaticHttpUserAgentSettings settings("en", EmptyString()); | 4666 StaticHttpUserAgentSettings settings("en", EmptyString()); |
4664 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 4667 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
4665 TestURLRequestContext context(true); | 4668 TestURLRequestContext context(true); |
4666 context.set_network_delegate(&network_delegate); | 4669 context.set_network_delegate(&network_delegate); |
4667 context.set_http_user_agent_settings(&settings); | 4670 context.set_http_user_agent_settings(&settings); |
4668 context.Init(); | 4671 context.Init(); |
4669 | 4672 |
4670 TestDelegate d; | 4673 TestDelegate d; |
4671 URLRequest req( | 4674 URLRequest req( |
4672 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 4675 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
4673 req.Start(); | 4676 req.Start(); |
4674 base::MessageLoop::current()->Run(); | 4677 base::RunLoop().Run(); |
4675 EXPECT_EQ("en", d.data_received()); | 4678 EXPECT_EQ("en", d.data_received()); |
4676 } | 4679 } |
4677 | 4680 |
4678 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 4681 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
4679 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 4682 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
4680 ASSERT_TRUE(test_server_.Start()); | 4683 ASSERT_TRUE(test_server_.Start()); |
4681 | 4684 |
4682 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString()); | 4685 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString()); |
4683 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 4686 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
4684 TestURLRequestContext context(true); | 4687 TestURLRequestContext context(true); |
4685 context.set_network_delegate(&network_delegate); | 4688 context.set_network_delegate(&network_delegate); |
4686 context.Init(); | 4689 context.Init(); |
4687 // We override the language after initialization because empty entries | 4690 // We override the language after initialization because empty entries |
4688 // get overridden by Init(). | 4691 // get overridden by Init(). |
4689 context.set_http_user_agent_settings(&settings); | 4692 context.set_http_user_agent_settings(&settings); |
4690 | 4693 |
4691 TestDelegate d; | 4694 TestDelegate d; |
4692 URLRequest req( | 4695 URLRequest req( |
4693 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 4696 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
4694 req.Start(); | 4697 req.Start(); |
4695 base::MessageLoop::current()->Run(); | 4698 base::RunLoop().Run(); |
4696 EXPECT_EQ("None", d.data_received()); | 4699 EXPECT_EQ("None", d.data_received()); |
4697 } | 4700 } |
4698 | 4701 |
4699 // Check that if request overrides the A-L header, the default is not appended. | 4702 // Check that if request overrides the A-L header, the default is not appended. |
4700 // See http://crbug.com/20894 | 4703 // See http://crbug.com/20894 |
4701 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 4704 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
4702 ASSERT_TRUE(test_server_.Start()); | 4705 ASSERT_TRUE(test_server_.Start()); |
4703 | 4706 |
4704 TestDelegate d; | 4707 TestDelegate d; |
4705 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 4708 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
4706 &d, | 4709 &d, |
4707 &default_context_); | 4710 &default_context_); |
4708 HttpRequestHeaders headers; | 4711 HttpRequestHeaders headers; |
4709 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 4712 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
4710 req.SetExtraRequestHeaders(headers); | 4713 req.SetExtraRequestHeaders(headers); |
4711 req.Start(); | 4714 req.Start(); |
4712 base::MessageLoop::current()->Run(); | 4715 base::RunLoop().Run(); |
4713 EXPECT_EQ(std::string("ru"), d.data_received()); | 4716 EXPECT_EQ(std::string("ru"), d.data_received()); |
4714 } | 4717 } |
4715 | 4718 |
4716 // Check that default A-E header is sent. | 4719 // Check that default A-E header is sent. |
4717 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 4720 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
4718 ASSERT_TRUE(test_server_.Start()); | 4721 ASSERT_TRUE(test_server_.Start()); |
4719 | 4722 |
4720 TestDelegate d; | 4723 TestDelegate d; |
4721 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 4724 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
4722 &d, | 4725 &d, |
4723 &default_context_); | 4726 &default_context_); |
4724 HttpRequestHeaders headers; | 4727 HttpRequestHeaders headers; |
4725 req.SetExtraRequestHeaders(headers); | 4728 req.SetExtraRequestHeaders(headers); |
4726 req.Start(); | 4729 req.Start(); |
4727 base::MessageLoop::current()->Run(); | 4730 base::RunLoop().Run(); |
4728 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 4731 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
4729 } | 4732 } |
4730 | 4733 |
4731 // Check that if request overrides the A-E header, the default is not appended. | 4734 // Check that if request overrides the A-E header, the default is not appended. |
4732 // See http://crbug.com/47381 | 4735 // See http://crbug.com/47381 |
4733 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 4736 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
4734 ASSERT_TRUE(test_server_.Start()); | 4737 ASSERT_TRUE(test_server_.Start()); |
4735 | 4738 |
4736 TestDelegate d; | 4739 TestDelegate d; |
4737 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 4740 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
4738 &d, | 4741 &d, |
4739 &default_context_); | 4742 &default_context_); |
4740 HttpRequestHeaders headers; | 4743 HttpRequestHeaders headers; |
4741 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 4744 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
4742 req.SetExtraRequestHeaders(headers); | 4745 req.SetExtraRequestHeaders(headers); |
4743 req.Start(); | 4746 req.Start(); |
4744 base::MessageLoop::current()->Run(); | 4747 base::RunLoop().Run(); |
4745 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 4748 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
4746 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 4749 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
4747 } | 4750 } |
4748 | 4751 |
4749 // Check that setting the A-C header sends the proper header. | 4752 // Check that setting the A-C header sends the proper header. |
4750 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { | 4753 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { |
4751 ASSERT_TRUE(test_server_.Start()); | 4754 ASSERT_TRUE(test_server_.Start()); |
4752 | 4755 |
4753 TestDelegate d; | 4756 TestDelegate d; |
4754 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 4757 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
4755 &d, | 4758 &d, |
4756 &default_context_); | 4759 &default_context_); |
4757 HttpRequestHeaders headers; | 4760 HttpRequestHeaders headers; |
4758 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 4761 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
4759 req.SetExtraRequestHeaders(headers); | 4762 req.SetExtraRequestHeaders(headers); |
4760 req.Start(); | 4763 req.Start(); |
4761 base::MessageLoop::current()->Run(); | 4764 base::RunLoop().Run(); |
4762 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 4765 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
4763 } | 4766 } |
4764 | 4767 |
4765 // Check that default User-Agent header is sent. | 4768 // Check that default User-Agent header is sent. |
4766 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 4769 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
4767 ASSERT_TRUE(test_server_.Start()); | 4770 ASSERT_TRUE(test_server_.Start()); |
4768 | 4771 |
4769 TestDelegate d; | 4772 TestDelegate d; |
4770 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 4773 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
4771 &d, | 4774 &d, |
4772 &default_context_); | 4775 &default_context_); |
4773 req.Start(); | 4776 req.Start(); |
4774 base::MessageLoop::current()->Run(); | 4777 base::RunLoop().Run(); |
4775 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); | 4778 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); |
4776 } | 4779 } |
4777 | 4780 |
4778 // Check that if request overrides the User-Agent header, | 4781 // Check that if request overrides the User-Agent header, |
4779 // the default is not appended. | 4782 // the default is not appended. |
4780 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 4783 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
4781 ASSERT_TRUE(test_server_.Start()); | 4784 ASSERT_TRUE(test_server_.Start()); |
4782 | 4785 |
4783 TestDelegate d; | 4786 TestDelegate d; |
4784 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 4787 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
4785 &d, | 4788 &d, |
4786 &default_context_); | 4789 &default_context_); |
4787 HttpRequestHeaders headers; | 4790 HttpRequestHeaders headers; |
4788 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 4791 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
4789 req.SetExtraRequestHeaders(headers); | 4792 req.SetExtraRequestHeaders(headers); |
4790 req.Start(); | 4793 req.Start(); |
4791 base::MessageLoop::current()->Run(); | 4794 base::RunLoop().Run(); |
4792 // If the net tests are being run with ChromeFrame then we need to allow for | 4795 // If the net tests are being run with ChromeFrame then we need to allow for |
4793 // the 'chromeframe' suffix which is added to the user agent before the | 4796 // the 'chromeframe' suffix which is added to the user agent before the |
4794 // closing parentheses. | 4797 // closing parentheses. |
4795 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4798 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
4796 } | 4799 } |
4797 | 4800 |
4798 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | 4801 // Check that a NULL HttpUserAgentSettings causes the corresponding empty |
4799 // User-Agent header to be sent but does not send the Accept-Language and | 4802 // User-Agent header to be sent but does not send the Accept-Language and |
4800 // Accept-Charset headers. | 4803 // Accept-Charset headers. |
4801 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { | 4804 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { |
(...skipping 11 matching lines...) Expand all Loading... |
4813 const char* request; | 4816 const char* request; |
4814 const char* expected_response; | 4817 const char* expected_response; |
4815 } tests[] = { { "echoheader?Accept-Language", "None" }, | 4818 } tests[] = { { "echoheader?Accept-Language", "None" }, |
4816 { "echoheader?Accept-Charset", "None" }, | 4819 { "echoheader?Accept-Charset", "None" }, |
4817 { "echoheader?User-Agent", "" } }; | 4820 { "echoheader?User-Agent", "" } }; |
4818 | 4821 |
4819 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 4822 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
4820 TestDelegate d; | 4823 TestDelegate d; |
4821 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); | 4824 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); |
4822 req.Start(); | 4825 req.Start(); |
4823 base::MessageLoop::current()->Run(); | 4826 base::RunLoop().Run(); |
4824 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 4827 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
4825 << " Request = \"" << tests[i].request << "\""; | 4828 << " Request = \"" << tests[i].request << "\""; |
4826 } | 4829 } |
4827 } | 4830 } |
4828 | 4831 |
4829 // Make sure that URLRequest passes on its priority updates to | 4832 // Make sure that URLRequest passes on its priority updates to |
4830 // newly-created jobs after the first one. | 4833 // newly-created jobs after the first one. |
4831 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 4834 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
4832 ASSERT_TRUE(test_server_.Start()); | 4835 ASSERT_TRUE(test_server_.Start()); |
4833 | 4836 |
4834 TestDelegate d; | 4837 TestDelegate d; |
4835 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 4838 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
4836 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 4839 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
4837 | 4840 |
4838 scoped_refptr<URLRequestRedirectJob> redirect_job = | 4841 scoped_refptr<URLRequestRedirectJob> redirect_job = |
4839 new URLRequestRedirectJob( | 4842 new URLRequestRedirectJob( |
4840 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 4843 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
4841 URLRequestRedirectJob::REDIRECT_302_FOUND); | 4844 URLRequestRedirectJob::REDIRECT_302_FOUND); |
4842 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 4845 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
4843 | 4846 |
4844 req.SetPriority(LOW); | 4847 req.SetPriority(LOW); |
4845 req.Start(); | 4848 req.Start(); |
4846 EXPECT_TRUE(req.is_pending()); | 4849 EXPECT_TRUE(req.is_pending()); |
4847 | 4850 |
4848 scoped_refptr<URLRequestTestJob> job = | 4851 scoped_refptr<URLRequestTestJob> job = |
4849 new URLRequestTestJob(&req, &default_network_delegate_); | 4852 new URLRequestTestJob(&req, &default_network_delegate_); |
4850 AddTestInterceptor()->set_main_intercept_job(job.get()); | 4853 AddTestInterceptor()->set_main_intercept_job(job.get()); |
4851 | 4854 |
4852 // Should trigger |job| to be started. | 4855 // Should trigger |job| to be started. |
4853 base::MessageLoop::current()->Run(); | 4856 base::RunLoop().Run(); |
4854 EXPECT_EQ(LOW, job->priority()); | 4857 EXPECT_EQ(LOW, job->priority()); |
4855 } | 4858 } |
4856 | 4859 |
4857 class HTTPSRequestTest : public testing::Test { | 4860 class HTTPSRequestTest : public testing::Test { |
4858 public: | 4861 public: |
4859 HTTPSRequestTest() : default_context_(true) { | 4862 HTTPSRequestTest() : default_context_(true) { |
4860 default_context_.set_network_delegate(&default_network_delegate_); | 4863 default_context_.set_network_delegate(&default_network_delegate_); |
4861 default_context_.Init(); | 4864 default_context_.Init(); |
4862 } | 4865 } |
4863 virtual ~HTTPSRequestTest() {} | 4866 virtual ~HTTPSRequestTest() {} |
4864 | 4867 |
4865 protected: | 4868 protected: |
4866 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 4869 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
4867 TestURLRequestContext default_context_; | 4870 TestURLRequestContext default_context_; |
4868 }; | 4871 }; |
4869 | 4872 |
4870 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 4873 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
4871 SpawnedTestServer test_server( | 4874 SpawnedTestServer test_server( |
4872 SpawnedTestServer::TYPE_HTTPS, | 4875 SpawnedTestServer::TYPE_HTTPS, |
4873 SpawnedTestServer::kLocalhost, | 4876 SpawnedTestServer::kLocalhost, |
4874 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 4877 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
4875 ASSERT_TRUE(test_server.Start()); | 4878 ASSERT_TRUE(test_server.Start()); |
4876 | 4879 |
4877 TestDelegate d; | 4880 TestDelegate d; |
4878 { | 4881 { |
4879 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 4882 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); |
4880 r.Start(); | 4883 r.Start(); |
4881 EXPECT_TRUE(r.is_pending()); | 4884 EXPECT_TRUE(r.is_pending()); |
4882 | 4885 |
4883 base::MessageLoop::current()->Run(); | 4886 base::RunLoop().Run(); |
4884 | 4887 |
4885 EXPECT_EQ(1, d.response_started_count()); | 4888 EXPECT_EQ(1, d.response_started_count()); |
4886 EXPECT_FALSE(d.received_data_before_response()); | 4889 EXPECT_FALSE(d.received_data_before_response()); |
4887 EXPECT_NE(0, d.bytes_received()); | 4890 EXPECT_NE(0, d.bytes_received()); |
4888 CheckSSLInfo(r.ssl_info()); | 4891 CheckSSLInfo(r.ssl_info()); |
4889 EXPECT_EQ(test_server.host_port_pair().host(), | 4892 EXPECT_EQ(test_server.host_port_pair().host(), |
4890 r.GetSocketAddress().host()); | 4893 r.GetSocketAddress().host()); |
4891 EXPECT_EQ(test_server.host_port_pair().port(), | 4894 EXPECT_EQ(test_server.host_port_pair().port(), |
4892 r.GetSocketAddress().port()); | 4895 r.GetSocketAddress().port()); |
4893 } | 4896 } |
(...skipping 11 matching lines...) Expand all Loading... |
4905 bool err_allowed = true; | 4908 bool err_allowed = true; |
4906 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 4909 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
4907 TestDelegate d; | 4910 TestDelegate d; |
4908 { | 4911 { |
4909 d.set_allow_certificate_errors(err_allowed); | 4912 d.set_allow_certificate_errors(err_allowed); |
4910 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 4913 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); |
4911 | 4914 |
4912 r.Start(); | 4915 r.Start(); |
4913 EXPECT_TRUE(r.is_pending()); | 4916 EXPECT_TRUE(r.is_pending()); |
4914 | 4917 |
4915 base::MessageLoop::current()->Run(); | 4918 base::RunLoop().Run(); |
4916 | 4919 |
4917 EXPECT_EQ(1, d.response_started_count()); | 4920 EXPECT_EQ(1, d.response_started_count()); |
4918 EXPECT_FALSE(d.received_data_before_response()); | 4921 EXPECT_FALSE(d.received_data_before_response()); |
4919 EXPECT_TRUE(d.have_certificate_errors()); | 4922 EXPECT_TRUE(d.have_certificate_errors()); |
4920 if (err_allowed) { | 4923 if (err_allowed) { |
4921 EXPECT_NE(0, d.bytes_received()); | 4924 EXPECT_NE(0, d.bytes_received()); |
4922 CheckSSLInfo(r.ssl_info()); | 4925 CheckSSLInfo(r.ssl_info()); |
4923 } else { | 4926 } else { |
4924 EXPECT_EQ(0, d.bytes_received()); | 4927 EXPECT_EQ(0, d.bytes_received()); |
4925 } | 4928 } |
(...skipping 15 matching lines...) Expand all Loading... |
4941 bool err_allowed = false; | 4944 bool err_allowed = false; |
4942 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 4945 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
4943 TestDelegate d; | 4946 TestDelegate d; |
4944 { | 4947 { |
4945 d.set_allow_certificate_errors(err_allowed); | 4948 d.set_allow_certificate_errors(err_allowed); |
4946 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 4949 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); |
4947 | 4950 |
4948 r.Start(); | 4951 r.Start(); |
4949 EXPECT_TRUE(r.is_pending()); | 4952 EXPECT_TRUE(r.is_pending()); |
4950 | 4953 |
4951 base::MessageLoop::current()->Run(); | 4954 base::RunLoop().Run(); |
4952 | 4955 |
4953 EXPECT_EQ(1, d.response_started_count()); | 4956 EXPECT_EQ(1, d.response_started_count()); |
4954 EXPECT_FALSE(d.received_data_before_response()); | 4957 EXPECT_FALSE(d.received_data_before_response()); |
4955 EXPECT_TRUE(d.have_certificate_errors()); | 4958 EXPECT_TRUE(d.have_certificate_errors()); |
4956 if (err_allowed) { | 4959 if (err_allowed) { |
4957 EXPECT_NE(0, d.bytes_received()); | 4960 EXPECT_NE(0, d.bytes_received()); |
4958 CheckSSLInfo(r.ssl_info()); | 4961 CheckSSLInfo(r.ssl_info()); |
4959 } else { | 4962 } else { |
4960 EXPECT_EQ(0, d.bytes_received()); | 4963 EXPECT_EQ(0, d.bytes_received()); |
4961 } | 4964 } |
(...skipping 22 matching lines...) Expand all Loading... |
4984 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 4987 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
4985 ASSERT_TRUE(test_server.Start()); | 4988 ASSERT_TRUE(test_server.Start()); |
4986 | 4989 |
4987 TestDelegate d; | 4990 TestDelegate d; |
4988 TestURLRequestContext context(true); | 4991 TestURLRequestContext context(true); |
4989 context.Init(); | 4992 context.Init(); |
4990 d.set_allow_certificate_errors(true); | 4993 d.set_allow_certificate_errors(true); |
4991 URLRequest r(test_server.GetURL(std::string()), &d, &context); | 4994 URLRequest r(test_server.GetURL(std::string()), &d, &context); |
4992 r.Start(); | 4995 r.Start(); |
4993 | 4996 |
4994 base::MessageLoop::current()->Run(); | 4997 base::RunLoop().Run(); |
4995 | 4998 |
4996 EXPECT_EQ(1, d.response_started_count()); | 4999 EXPECT_EQ(1, d.response_started_count()); |
4997 EXPECT_NE(0, d.bytes_received()); | 5000 EXPECT_NE(0, d.bytes_received()); |
4998 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), | 5001 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), |
4999 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 5002 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
5000 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 5003 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
5001 } | 5004 } |
5002 | 5005 |
5003 // This tests that a load of www.google.com with a certificate error sets | 5006 // This tests that a load of www.google.com with a certificate error sets |
5004 // the |certificate_errors_are_fatal| flag correctly. This flag will cause | 5007 // the |certificate_errors_are_fatal| flag correctly. This flag will cause |
(...skipping 23 matching lines...) Expand all Loading... |
5028 | 5031 |
5029 TestDelegate d; | 5032 TestDelegate d; |
5030 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 5033 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", |
5031 test_server.host_port_pair().port())), | 5034 test_server.host_port_pair().port())), |
5032 &d, | 5035 &d, |
5033 &context); | 5036 &context); |
5034 | 5037 |
5035 r.Start(); | 5038 r.Start(); |
5036 EXPECT_TRUE(r.is_pending()); | 5039 EXPECT_TRUE(r.is_pending()); |
5037 | 5040 |
5038 base::MessageLoop::current()->Run(); | 5041 base::RunLoop().Run(); |
5039 | 5042 |
5040 EXPECT_EQ(1, d.response_started_count()); | 5043 EXPECT_EQ(1, d.response_started_count()); |
5041 EXPECT_FALSE(d.received_data_before_response()); | 5044 EXPECT_FALSE(d.received_data_before_response()); |
5042 EXPECT_TRUE(d.have_certificate_errors()); | 5045 EXPECT_TRUE(d.have_certificate_errors()); |
5043 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 5046 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
5044 } | 5047 } |
5045 | 5048 |
5046 // This tests that cached HTTPS page loads do not cause any updates to the | 5049 // This tests that cached HTTPS page loads do not cause any updates to the |
5047 // TransportSecurityState. | 5050 // TransportSecurityState. |
5048 TEST_F(HTTPSRequestTest, HTTPSErrorsNoClobberTSSTest) { | 5051 TEST_F(HTTPSRequestTest, HTTPSErrorsNoClobberTSSTest) { |
(...skipping 27 matching lines...) Expand all Loading... |
5076 | 5079 |
5077 TestDelegate d; | 5080 TestDelegate d; |
5078 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 5081 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", |
5079 test_server.host_port_pair().port())), | 5082 test_server.host_port_pair().port())), |
5080 &d, | 5083 &d, |
5081 &context); | 5084 &context); |
5082 | 5085 |
5083 r.Start(); | 5086 r.Start(); |
5084 EXPECT_TRUE(r.is_pending()); | 5087 EXPECT_TRUE(r.is_pending()); |
5085 | 5088 |
5086 base::MessageLoop::current()->Run(); | 5089 base::RunLoop().Run(); |
5087 | 5090 |
5088 EXPECT_EQ(1, d.response_started_count()); | 5091 EXPECT_EQ(1, d.response_started_count()); |
5089 EXPECT_FALSE(d.received_data_before_response()); | 5092 EXPECT_FALSE(d.received_data_before_response()); |
5090 EXPECT_TRUE(d.have_certificate_errors()); | 5093 EXPECT_TRUE(d.have_certificate_errors()); |
5091 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 5094 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
5092 | 5095 |
5093 // Get a fresh copy of the state, and check that it hasn't been updated. | 5096 // Get a fresh copy of the state, and check that it hasn't been updated. |
5094 TransportSecurityState::DomainState new_domain_state; | 5097 TransportSecurityState::DomainState new_domain_state; |
5095 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 5098 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
5096 &new_domain_state)); | 5099 &new_domain_state)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5147 d.set_allow_certificate_errors(true); | 5150 d.set_allow_certificate_errors(true); |
5148 | 5151 |
5149 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", | 5152 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", |
5150 test_server.host_port_pair().port())), | 5153 test_server.host_port_pair().port())), |
5151 &d, | 5154 &d, |
5152 &context); | 5155 &context); |
5153 req.set_method("POST"); | 5156 req.set_method("POST"); |
5154 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 5157 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
5155 | 5158 |
5156 req.Start(); | 5159 req.Start(); |
5157 base::MessageLoop::current()->Run(); | 5160 base::RunLoop().Run(); |
5158 | 5161 |
5159 EXPECT_EQ("https", req.url().scheme()); | 5162 EXPECT_EQ("https", req.url().scheme()); |
5160 EXPECT_EQ("POST", req.method()); | 5163 EXPECT_EQ("POST", req.method()); |
5161 EXPECT_EQ(kData, d.data_received()); | 5164 EXPECT_EQ(kData, d.data_received()); |
5162 | 5165 |
5163 LoadTimingInfo load_timing_info; | 5166 LoadTimingInfo load_timing_info; |
5164 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); | 5167 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); |
5165 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits | 5168 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits |
5166 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 5169 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
5167 } | 5170 } |
5168 | 5171 |
5169 TEST_F(HTTPSRequestTest, SSLv3Fallback) { | 5172 TEST_F(HTTPSRequestTest, SSLv3Fallback) { |
5170 SpawnedTestServer::SSLOptions ssl_options( | 5173 SpawnedTestServer::SSLOptions ssl_options( |
5171 SpawnedTestServer::SSLOptions::CERT_OK); | 5174 SpawnedTestServer::SSLOptions::CERT_OK); |
5172 ssl_options.tls_intolerant = | 5175 ssl_options.tls_intolerant = |
5173 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_ALL; | 5176 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_ALL; |
5174 SpawnedTestServer test_server( | 5177 SpawnedTestServer test_server( |
5175 SpawnedTestServer::TYPE_HTTPS, | 5178 SpawnedTestServer::TYPE_HTTPS, |
5176 ssl_options, | 5179 ssl_options, |
5177 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 5180 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
5178 ASSERT_TRUE(test_server.Start()); | 5181 ASSERT_TRUE(test_server.Start()); |
5179 | 5182 |
5180 TestDelegate d; | 5183 TestDelegate d; |
5181 TestURLRequestContext context(true); | 5184 TestURLRequestContext context(true); |
5182 context.Init(); | 5185 context.Init(); |
5183 d.set_allow_certificate_errors(true); | 5186 d.set_allow_certificate_errors(true); |
5184 URLRequest r(test_server.GetURL(std::string()), &d, &context); | 5187 URLRequest r(test_server.GetURL(std::string()), &d, &context); |
5185 r.Start(); | 5188 r.Start(); |
5186 | 5189 |
5187 base::MessageLoop::current()->Run(); | 5190 base::RunLoop().Run(); |
5188 | 5191 |
5189 EXPECT_EQ(1, d.response_started_count()); | 5192 EXPECT_EQ(1, d.response_started_count()); |
5190 EXPECT_NE(0, d.bytes_received()); | 5193 EXPECT_NE(0, d.bytes_received()); |
5191 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), | 5194 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), |
5192 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 5195 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
5193 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 5196 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
5194 } | 5197 } |
5195 | 5198 |
5196 namespace { | 5199 namespace { |
5197 | 5200 |
(...skipping 30 matching lines...) Expand all Loading... |
5228 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 5231 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
5229 ASSERT_TRUE(test_server.Start()); | 5232 ASSERT_TRUE(test_server.Start()); |
5230 | 5233 |
5231 SSLClientAuthTestDelegate d; | 5234 SSLClientAuthTestDelegate d; |
5232 { | 5235 { |
5233 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 5236 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); |
5234 | 5237 |
5235 r.Start(); | 5238 r.Start(); |
5236 EXPECT_TRUE(r.is_pending()); | 5239 EXPECT_TRUE(r.is_pending()); |
5237 | 5240 |
5238 base::MessageLoop::current()->Run(); | 5241 base::RunLoop().Run(); |
5239 | 5242 |
5240 EXPECT_EQ(1, d.on_certificate_requested_count()); | 5243 EXPECT_EQ(1, d.on_certificate_requested_count()); |
5241 EXPECT_FALSE(d.received_data_before_response()); | 5244 EXPECT_FALSE(d.received_data_before_response()); |
5242 EXPECT_EQ(0, d.bytes_received()); | 5245 EXPECT_EQ(0, d.bytes_received()); |
5243 | 5246 |
5244 // Send no certificate. | 5247 // Send no certificate. |
5245 // TODO(davidben): Get temporary client cert import (with keys) working on | 5248 // TODO(davidben): Get temporary client cert import (with keys) working on |
5246 // all platforms so we can test sending a cert as well. | 5249 // all platforms so we can test sending a cert as well. |
5247 r.ContinueWithCertificate(NULL); | 5250 r.ContinueWithCertificate(NULL); |
5248 | 5251 |
5249 base::MessageLoop::current()->Run(); | 5252 base::RunLoop().Run(); |
5250 | 5253 |
5251 EXPECT_EQ(1, d.response_started_count()); | 5254 EXPECT_EQ(1, d.response_started_count()); |
5252 EXPECT_FALSE(d.received_data_before_response()); | 5255 EXPECT_FALSE(d.received_data_before_response()); |
5253 EXPECT_NE(0, d.bytes_received()); | 5256 EXPECT_NE(0, d.bytes_received()); |
5254 } | 5257 } |
5255 } | 5258 } |
5256 | 5259 |
5257 TEST_F(HTTPSRequestTest, ResumeTest) { | 5260 TEST_F(HTTPSRequestTest, ResumeTest) { |
5258 // Test that we attempt a session resume when making two connections to the | 5261 // Test that we attempt a session resume when making two connections to the |
5259 // same host. | 5262 // same host. |
5260 SpawnedTestServer::SSLOptions ssl_options; | 5263 SpawnedTestServer::SSLOptions ssl_options; |
5261 ssl_options.record_resume = true; | 5264 ssl_options.record_resume = true; |
5262 SpawnedTestServer test_server( | 5265 SpawnedTestServer test_server( |
5263 SpawnedTestServer::TYPE_HTTPS, | 5266 SpawnedTestServer::TYPE_HTTPS, |
5264 ssl_options, | 5267 ssl_options, |
5265 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 5268 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
5266 ASSERT_TRUE(test_server.Start()); | 5269 ASSERT_TRUE(test_server.Start()); |
5267 | 5270 |
5268 SSLClientSocket::ClearSessionCache(); | 5271 SSLClientSocket::ClearSessionCache(); |
5269 | 5272 |
5270 { | 5273 { |
5271 TestDelegate d; | 5274 TestDelegate d; |
5272 URLRequest r( | 5275 URLRequest r( |
5273 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 5276 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
5274 | 5277 |
5275 r.Start(); | 5278 r.Start(); |
5276 EXPECT_TRUE(r.is_pending()); | 5279 EXPECT_TRUE(r.is_pending()); |
5277 | 5280 |
5278 base::MessageLoop::current()->Run(); | 5281 base::RunLoop().Run(); |
5279 | 5282 |
5280 EXPECT_EQ(1, d.response_started_count()); | 5283 EXPECT_EQ(1, d.response_started_count()); |
5281 } | 5284 } |
5282 | 5285 |
5283 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 5286 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
5284 CloseAllConnections(); | 5287 CloseAllConnections(); |
5285 | 5288 |
5286 { | 5289 { |
5287 TestDelegate d; | 5290 TestDelegate d; |
5288 URLRequest r( | 5291 URLRequest r( |
5289 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 5292 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
5290 | 5293 |
5291 r.Start(); | 5294 r.Start(); |
5292 EXPECT_TRUE(r.is_pending()); | 5295 EXPECT_TRUE(r.is_pending()); |
5293 | 5296 |
5294 base::MessageLoop::current()->Run(); | 5297 base::RunLoop().Run(); |
5295 | 5298 |
5296 // The response will look like; | 5299 // The response will look like; |
5297 // insert abc | 5300 // insert abc |
5298 // lookup abc | 5301 // lookup abc |
5299 // insert xyz | 5302 // insert xyz |
5300 // | 5303 // |
5301 // With a newline at the end which makes the split think that there are | 5304 // With a newline at the end which makes the split think that there are |
5302 // four lines. | 5305 // four lines. |
5303 | 5306 |
5304 EXPECT_EQ(1, d.response_started_count()); | 5307 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5337 SSLClientSocket::ClearSessionCache(); | 5340 SSLClientSocket::ClearSessionCache(); |
5338 | 5341 |
5339 { | 5342 { |
5340 TestDelegate d; | 5343 TestDelegate d; |
5341 URLRequest r( | 5344 URLRequest r( |
5342 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 5345 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
5343 | 5346 |
5344 r.Start(); | 5347 r.Start(); |
5345 EXPECT_TRUE(r.is_pending()); | 5348 EXPECT_TRUE(r.is_pending()); |
5346 | 5349 |
5347 base::MessageLoop::current()->Run(); | 5350 base::RunLoop().Run(); |
5348 | 5351 |
5349 EXPECT_EQ(1, d.response_started_count()); | 5352 EXPECT_EQ(1, d.response_started_count()); |
5350 } | 5353 } |
5351 | 5354 |
5352 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 5355 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
5353 HttpNetworkSession::Params params; | 5356 HttpNetworkSession::Params params; |
5354 params.host_resolver = default_context_.host_resolver(); | 5357 params.host_resolver = default_context_.host_resolver(); |
5355 params.cert_verifier = default_context_.cert_verifier(); | 5358 params.cert_verifier = default_context_.cert_verifier(); |
5356 params.transport_security_state = default_context_.transport_security_state(); | 5359 params.transport_security_state = default_context_.transport_security_state(); |
5357 params.proxy_service = default_context_.proxy_service(); | 5360 params.proxy_service = default_context_.proxy_service(); |
(...skipping 11 matching lines...) Expand all Loading... |
5369 default_context_.set_http_transaction_factory(cache.get()); | 5372 default_context_.set_http_transaction_factory(cache.get()); |
5370 | 5373 |
5371 { | 5374 { |
5372 TestDelegate d; | 5375 TestDelegate d; |
5373 URLRequest r( | 5376 URLRequest r( |
5374 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 5377 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
5375 | 5378 |
5376 r.Start(); | 5379 r.Start(); |
5377 EXPECT_TRUE(r.is_pending()); | 5380 EXPECT_TRUE(r.is_pending()); |
5378 | 5381 |
5379 base::MessageLoop::current()->Run(); | 5382 base::RunLoop().Run(); |
5380 | 5383 |
5381 // The response will look like; | 5384 // The response will look like; |
5382 // insert abc | 5385 // insert abc |
5383 // insert xyz | 5386 // insert xyz |
5384 // | 5387 // |
5385 // With a newline at the end which makes the split think that there are | 5388 // With a newline at the end which makes the split think that there are |
5386 // three lines. | 5389 // three lines. |
5387 | 5390 |
5388 EXPECT_EQ(1, d.response_started_count()); | 5391 EXPECT_EQ(1, d.response_started_count()); |
5389 std::vector<std::string> lines; | 5392 std::vector<std::string> lines; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5485 SpawnedTestServer::TYPE_HTTPS, | 5488 SpawnedTestServer::TYPE_HTTPS, |
5486 ssl_options, | 5489 ssl_options, |
5487 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 5490 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
5488 ASSERT_TRUE(test_server.Start()); | 5491 ASSERT_TRUE(test_server.Start()); |
5489 | 5492 |
5490 TestDelegate d; | 5493 TestDelegate d; |
5491 d.set_allow_certificate_errors(true); | 5494 d.set_allow_certificate_errors(true); |
5492 URLRequest r(test_server.GetURL(std::string()), &d, &context_); | 5495 URLRequest r(test_server.GetURL(std::string()), &d, &context_); |
5493 r.Start(); | 5496 r.Start(); |
5494 | 5497 |
5495 base::MessageLoop::current()->Run(); | 5498 base::RunLoop().Run(); |
5496 | 5499 |
5497 EXPECT_EQ(1, d.response_started_count()); | 5500 EXPECT_EQ(1, d.response_started_count()); |
5498 *out_cert_status = r.ssl_info().cert_status; | 5501 *out_cert_status = r.ssl_info().cert_status; |
5499 } | 5502 } |
5500 | 5503 |
5501 virtual ~HTTPSOCSPTest() { | 5504 virtual ~HTTPSOCSPTest() { |
5502 #if defined(USE_NSS) || defined(OS_IOS) | 5505 #if defined(USE_NSS) || defined(OS_IOS) |
5503 ShutdownNSSHttpIO(); | 5506 ShutdownNSSHttpIO(); |
5504 #endif | 5507 #endif |
5505 } | 5508 } |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5913 "ftp", | 5916 "ftp", |
5914 new FtpProtocolHandler(&ftp_transaction_factory)); | 5917 new FtpProtocolHandler(&ftp_transaction_factory)); |
5915 default_context_.set_job_factory(&job_factory); | 5918 default_context_.set_job_factory(&job_factory); |
5916 | 5919 |
5917 TestDelegate d; | 5920 TestDelegate d; |
5918 { | 5921 { |
5919 URLRequest r(url, &d, &default_context_); | 5922 URLRequest r(url, &d, &default_context_); |
5920 r.Start(); | 5923 r.Start(); |
5921 EXPECT_TRUE(r.is_pending()); | 5924 EXPECT_TRUE(r.is_pending()); |
5922 | 5925 |
5923 base::MessageLoop::current()->Run(); | 5926 base::RunLoop().Run(); |
5924 | 5927 |
5925 EXPECT_FALSE(r.is_pending()); | 5928 EXPECT_FALSE(r.is_pending()); |
5926 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 5929 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
5927 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); | 5930 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); |
5928 } | 5931 } |
5929 } | 5932 } |
5930 | 5933 |
5931 // Flaky, see http://crbug.com/25045. | 5934 // Flaky, see http://crbug.com/25045. |
5932 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | 5935 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { |
5933 ASSERT_TRUE(test_server_.Start()); | 5936 ASSERT_TRUE(test_server_.Start()); |
5934 | 5937 |
5935 TestDelegate d; | 5938 TestDelegate d; |
5936 { | 5939 { |
5937 URLRequest r(test_server_.GetURL("/"), &d, &default_context_); | 5940 URLRequest r(test_server_.GetURL("/"), &d, &default_context_); |
5938 r.Start(); | 5941 r.Start(); |
5939 EXPECT_TRUE(r.is_pending()); | 5942 EXPECT_TRUE(r.is_pending()); |
5940 | 5943 |
5941 base::MessageLoop::current()->Run(); | 5944 base::RunLoop().Run(); |
5942 | 5945 |
5943 EXPECT_FALSE(r.is_pending()); | 5946 EXPECT_FALSE(r.is_pending()); |
5944 EXPECT_EQ(1, d.response_started_count()); | 5947 EXPECT_EQ(1, d.response_started_count()); |
5945 EXPECT_FALSE(d.received_data_before_response()); | 5948 EXPECT_FALSE(d.received_data_before_response()); |
5946 EXPECT_LT(0, d.bytes_received()); | 5949 EXPECT_LT(0, d.bytes_received()); |
5947 EXPECT_EQ(test_server_.host_port_pair().host(), | 5950 EXPECT_EQ(test_server_.host_port_pair().host(), |
5948 r.GetSocketAddress().host()); | 5951 r.GetSocketAddress().host()); |
5949 EXPECT_EQ(test_server_.host_port_pair().port(), | 5952 EXPECT_EQ(test_server_.host_port_pair().port(), |
5950 r.GetSocketAddress().port()); | 5953 r.GetSocketAddress().port()); |
5951 } | 5954 } |
5952 } | 5955 } |
5953 | 5956 |
5954 // Flaky, see http://crbug.com/25045. | 5957 // Flaky, see http://crbug.com/25045. |
5955 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | 5958 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { |
5956 ASSERT_TRUE(test_server_.Start()); | 5959 ASSERT_TRUE(test_server_.Start()); |
5957 | 5960 |
5958 base::FilePath app_path; | 5961 base::FilePath app_path; |
5959 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 5962 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
5960 app_path = app_path.AppendASCII("LICENSE"); | 5963 app_path = app_path.AppendASCII("LICENSE"); |
5961 TestDelegate d; | 5964 TestDelegate d; |
5962 { | 5965 { |
5963 URLRequest r(test_server_.GetURL("/LICENSE"), &d, &default_context_); | 5966 URLRequest r(test_server_.GetURL("/LICENSE"), &d, &default_context_); |
5964 r.Start(); | 5967 r.Start(); |
5965 EXPECT_TRUE(r.is_pending()); | 5968 EXPECT_TRUE(r.is_pending()); |
5966 | 5969 |
5967 base::MessageLoop::current()->Run(); | 5970 base::RunLoop().Run(); |
5968 | 5971 |
5969 int64 file_size = 0; | 5972 int64 file_size = 0; |
5970 file_util::GetFileSize(app_path, &file_size); | 5973 file_util::GetFileSize(app_path, &file_size); |
5971 | 5974 |
5972 EXPECT_FALSE(r.is_pending()); | 5975 EXPECT_FALSE(r.is_pending()); |
5973 EXPECT_EQ(1, d.response_started_count()); | 5976 EXPECT_EQ(1, d.response_started_count()); |
5974 EXPECT_FALSE(d.received_data_before_response()); | 5977 EXPECT_FALSE(d.received_data_before_response()); |
5975 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 5978 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
5976 EXPECT_EQ(test_server_.host_port_pair().host(), | 5979 EXPECT_EQ(test_server_.host_port_pair().host(), |
5977 r.GetSocketAddress().host()); | 5980 r.GetSocketAddress().host()); |
(...skipping 11 matching lines...) Expand all Loading... |
5989 app_path = app_path.AppendASCII("LICENSE"); | 5992 app_path = app_path.AppendASCII("LICENSE"); |
5990 TestDelegate d; | 5993 TestDelegate d; |
5991 { | 5994 { |
5992 URLRequest r( | 5995 URLRequest r( |
5993 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 5996 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
5994 &d, | 5997 &d, |
5995 &default_context_); | 5998 &default_context_); |
5996 r.Start(); | 5999 r.Start(); |
5997 EXPECT_TRUE(r.is_pending()); | 6000 EXPECT_TRUE(r.is_pending()); |
5998 | 6001 |
5999 base::MessageLoop::current()->Run(); | 6002 base::RunLoop().Run(); |
6000 | 6003 |
6001 int64 file_size = 0; | 6004 int64 file_size = 0; |
6002 file_util::GetFileSize(app_path, &file_size); | 6005 file_util::GetFileSize(app_path, &file_size); |
6003 | 6006 |
6004 EXPECT_FALSE(r.is_pending()); | 6007 EXPECT_FALSE(r.is_pending()); |
6005 EXPECT_EQ(test_server_.host_port_pair().host(), | 6008 EXPECT_EQ(test_server_.host_port_pair().host(), |
6006 r.GetSocketAddress().host()); | 6009 r.GetSocketAddress().host()); |
6007 EXPECT_EQ(test_server_.host_port_pair().port(), | 6010 EXPECT_EQ(test_server_.host_port_pair().port(), |
6008 r.GetSocketAddress().port()); | 6011 r.GetSocketAddress().port()); |
6009 EXPECT_EQ(1, d.response_started_count()); | 6012 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 17 matching lines...) Expand all Loading... |
6027 { | 6030 { |
6028 URLRequest r( | 6031 URLRequest r( |
6029 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6032 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6030 "chrome", | 6033 "chrome", |
6031 "wrong_password"), | 6034 "wrong_password"), |
6032 &d, | 6035 &d, |
6033 &default_context_); | 6036 &default_context_); |
6034 r.Start(); | 6037 r.Start(); |
6035 EXPECT_TRUE(r.is_pending()); | 6038 EXPECT_TRUE(r.is_pending()); |
6036 | 6039 |
6037 base::MessageLoop::current()->Run(); | 6040 base::RunLoop().Run(); |
6038 | 6041 |
6039 int64 file_size = 0; | 6042 int64 file_size = 0; |
6040 file_util::GetFileSize(app_path, &file_size); | 6043 file_util::GetFileSize(app_path, &file_size); |
6041 | 6044 |
6042 EXPECT_FALSE(r.is_pending()); | 6045 EXPECT_FALSE(r.is_pending()); |
6043 EXPECT_EQ(1, d.response_started_count()); | 6046 EXPECT_EQ(1, d.response_started_count()); |
6044 EXPECT_FALSE(d.received_data_before_response()); | 6047 EXPECT_FALSE(d.received_data_before_response()); |
6045 EXPECT_EQ(d.bytes_received(), 0); | 6048 EXPECT_EQ(d.bytes_received(), 0); |
6046 } | 6049 } |
6047 } | 6050 } |
(...skipping 12 matching lines...) Expand all Loading... |
6060 { | 6063 { |
6061 URLRequest r( | 6064 URLRequest r( |
6062 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6065 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6063 "chrome", | 6066 "chrome", |
6064 "wrong_password"), | 6067 "wrong_password"), |
6065 &d, | 6068 &d, |
6066 &default_context_); | 6069 &default_context_); |
6067 r.Start(); | 6070 r.Start(); |
6068 EXPECT_TRUE(r.is_pending()); | 6071 EXPECT_TRUE(r.is_pending()); |
6069 | 6072 |
6070 base::MessageLoop::current()->Run(); | 6073 base::RunLoop().Run(); |
6071 | 6074 |
6072 int64 file_size = 0; | 6075 int64 file_size = 0; |
6073 file_util::GetFileSize(app_path, &file_size); | 6076 file_util::GetFileSize(app_path, &file_size); |
6074 | 6077 |
6075 EXPECT_FALSE(r.is_pending()); | 6078 EXPECT_FALSE(r.is_pending()); |
6076 EXPECT_EQ(1, d.response_started_count()); | 6079 EXPECT_EQ(1, d.response_started_count()); |
6077 EXPECT_FALSE(d.received_data_before_response()); | 6080 EXPECT_FALSE(d.received_data_before_response()); |
6078 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 6081 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
6079 } | 6082 } |
6080 } | 6083 } |
6081 | 6084 |
6082 // Flaky, see http://crbug.com/25045. | 6085 // Flaky, see http://crbug.com/25045. |
6083 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | 6086 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { |
6084 ASSERT_TRUE(test_server_.Start()); | 6087 ASSERT_TRUE(test_server_.Start()); |
6085 | 6088 |
6086 base::FilePath app_path; | 6089 base::FilePath app_path; |
6087 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 6090 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
6088 app_path = app_path.AppendASCII("LICENSE"); | 6091 app_path = app_path.AppendASCII("LICENSE"); |
6089 TestDelegate d; | 6092 TestDelegate d; |
6090 { | 6093 { |
6091 URLRequest r( | 6094 URLRequest r( |
6092 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6095 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6093 "wrong_user", | 6096 "wrong_user", |
6094 "chrome"), | 6097 "chrome"), |
6095 &d, | 6098 &d, |
6096 &default_context_); | 6099 &default_context_); |
6097 r.Start(); | 6100 r.Start(); |
6098 EXPECT_TRUE(r.is_pending()); | 6101 EXPECT_TRUE(r.is_pending()); |
6099 | 6102 |
6100 base::MessageLoop::current()->Run(); | 6103 base::RunLoop().Run(); |
6101 | 6104 |
6102 int64 file_size = 0; | 6105 int64 file_size = 0; |
6103 file_util::GetFileSize(app_path, &file_size); | 6106 file_util::GetFileSize(app_path, &file_size); |
6104 | 6107 |
6105 EXPECT_FALSE(r.is_pending()); | 6108 EXPECT_FALSE(r.is_pending()); |
6106 EXPECT_EQ(1, d.response_started_count()); | 6109 EXPECT_EQ(1, d.response_started_count()); |
6107 EXPECT_FALSE(d.received_data_before_response()); | 6110 EXPECT_FALSE(d.received_data_before_response()); |
6108 EXPECT_EQ(d.bytes_received(), 0); | 6111 EXPECT_EQ(d.bytes_received(), 0); |
6109 } | 6112 } |
6110 } | 6113 } |
(...skipping 12 matching lines...) Expand all Loading... |
6123 { | 6126 { |
6124 URLRequest r( | 6127 URLRequest r( |
6125 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6128 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6126 "wrong_user", | 6129 "wrong_user", |
6127 "chrome"), | 6130 "chrome"), |
6128 &d, | 6131 &d, |
6129 &default_context_); | 6132 &default_context_); |
6130 r.Start(); | 6133 r.Start(); |
6131 EXPECT_TRUE(r.is_pending()); | 6134 EXPECT_TRUE(r.is_pending()); |
6132 | 6135 |
6133 base::MessageLoop::current()->Run(); | 6136 base::RunLoop().Run(); |
6134 | 6137 |
6135 int64 file_size = 0; | 6138 int64 file_size = 0; |
6136 file_util::GetFileSize(app_path, &file_size); | 6139 file_util::GetFileSize(app_path, &file_size); |
6137 | 6140 |
6138 EXPECT_FALSE(r.is_pending()); | 6141 EXPECT_FALSE(r.is_pending()); |
6139 EXPECT_EQ(1, d.response_started_count()); | 6142 EXPECT_EQ(1, d.response_started_count()); |
6140 EXPECT_FALSE(d.received_data_before_response()); | 6143 EXPECT_FALSE(d.received_data_before_response()); |
6141 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 6144 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
6142 } | 6145 } |
6143 } | 6146 } |
(...skipping 11 matching lines...) Expand all Loading... |
6155 // Pass correct login identity in the URL. | 6158 // Pass correct login identity in the URL. |
6156 URLRequest r( | 6159 URLRequest r( |
6157 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6160 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6158 "chrome", | 6161 "chrome", |
6159 "chrome"), | 6162 "chrome"), |
6160 d.get(), | 6163 d.get(), |
6161 &default_context_); | 6164 &default_context_); |
6162 r.Start(); | 6165 r.Start(); |
6163 EXPECT_TRUE(r.is_pending()); | 6166 EXPECT_TRUE(r.is_pending()); |
6164 | 6167 |
6165 base::MessageLoop::current()->Run(); | 6168 base::RunLoop().Run(); |
6166 | 6169 |
6167 int64 file_size = 0; | 6170 int64 file_size = 0; |
6168 file_util::GetFileSize(app_path, &file_size); | 6171 file_util::GetFileSize(app_path, &file_size); |
6169 | 6172 |
6170 EXPECT_FALSE(r.is_pending()); | 6173 EXPECT_FALSE(r.is_pending()); |
6171 EXPECT_EQ(1, d->response_started_count()); | 6174 EXPECT_EQ(1, d->response_started_count()); |
6172 EXPECT_FALSE(d->received_data_before_response()); | 6175 EXPECT_FALSE(d->received_data_before_response()); |
6173 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6176 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6174 } | 6177 } |
6175 | 6178 |
6176 d.reset(new TestDelegate); | 6179 d.reset(new TestDelegate); |
6177 { | 6180 { |
6178 // This request should use cached identity from previous request. | 6181 // This request should use cached identity from previous request. |
6179 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); | 6182 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); |
6180 r.Start(); | 6183 r.Start(); |
6181 EXPECT_TRUE(r.is_pending()); | 6184 EXPECT_TRUE(r.is_pending()); |
6182 | 6185 |
6183 base::MessageLoop::current()->Run(); | 6186 base::RunLoop().Run(); |
6184 | 6187 |
6185 int64 file_size = 0; | 6188 int64 file_size = 0; |
6186 file_util::GetFileSize(app_path, &file_size); | 6189 file_util::GetFileSize(app_path, &file_size); |
6187 | 6190 |
6188 EXPECT_FALSE(r.is_pending()); | 6191 EXPECT_FALSE(r.is_pending()); |
6189 EXPECT_EQ(1, d->response_started_count()); | 6192 EXPECT_EQ(1, d->response_started_count()); |
6190 EXPECT_FALSE(d->received_data_before_response()); | 6193 EXPECT_FALSE(d->received_data_before_response()); |
6191 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6194 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6192 } | 6195 } |
6193 } | 6196 } |
(...skipping 13 matching lines...) Expand all Loading... |
6207 { | 6210 { |
6208 URLRequest r( | 6211 URLRequest r( |
6209 test_server_.GetURLWithUserAndPassword("/LICENSE", | 6212 test_server_.GetURLWithUserAndPassword("/LICENSE", |
6210 "chrome", | 6213 "chrome", |
6211 "wrong_password"), | 6214 "wrong_password"), |
6212 d.get(), | 6215 d.get(), |
6213 &default_context_); | 6216 &default_context_); |
6214 r.Start(); | 6217 r.Start(); |
6215 EXPECT_TRUE(r.is_pending()); | 6218 EXPECT_TRUE(r.is_pending()); |
6216 | 6219 |
6217 base::MessageLoop::current()->Run(); | 6220 base::RunLoop().Run(); |
6218 | 6221 |
6219 int64 file_size = 0; | 6222 int64 file_size = 0; |
6220 file_util::GetFileSize(app_path, &file_size); | 6223 file_util::GetFileSize(app_path, &file_size); |
6221 | 6224 |
6222 EXPECT_FALSE(r.is_pending()); | 6225 EXPECT_FALSE(r.is_pending()); |
6223 EXPECT_EQ(1, d->response_started_count()); | 6226 EXPECT_EQ(1, d->response_started_count()); |
6224 EXPECT_FALSE(d->received_data_before_response()); | 6227 EXPECT_FALSE(d->received_data_before_response()); |
6225 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6228 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6226 } | 6229 } |
6227 | 6230 |
6228 // Use a new delegate without explicit credentials. The cached ones should be | 6231 // Use a new delegate without explicit credentials. The cached ones should be |
6229 // used. | 6232 // used. |
6230 d.reset(new TestDelegate); | 6233 d.reset(new TestDelegate); |
6231 { | 6234 { |
6232 // Don't pass wrong credentials in the URL, they would override valid cached | 6235 // Don't pass wrong credentials in the URL, they would override valid cached |
6233 // ones. | 6236 // ones. |
6234 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); | 6237 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); |
6235 r.Start(); | 6238 r.Start(); |
6236 EXPECT_TRUE(r.is_pending()); | 6239 EXPECT_TRUE(r.is_pending()); |
6237 | 6240 |
6238 base::MessageLoop::current()->Run(); | 6241 base::RunLoop().Run(); |
6239 | 6242 |
6240 int64 file_size = 0; | 6243 int64 file_size = 0; |
6241 file_util::GetFileSize(app_path, &file_size); | 6244 file_util::GetFileSize(app_path, &file_size); |
6242 | 6245 |
6243 EXPECT_FALSE(r.is_pending()); | 6246 EXPECT_FALSE(r.is_pending()); |
6244 EXPECT_EQ(1, d->response_started_count()); | 6247 EXPECT_EQ(1, d->response_started_count()); |
6245 EXPECT_FALSE(d->received_data_before_response()); | 6248 EXPECT_FALSE(d->received_data_before_response()); |
6246 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 6249 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
6247 } | 6250 } |
6248 } | 6251 } |
6249 #endif // !defined(DISABLE_FTP_SUPPORT) | 6252 #endif // !defined(DISABLE_FTP_SUPPORT) |
6250 | 6253 |
6251 } // namespace net | 6254 } // namespace net |
OLD | NEW |