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