Chromium Code Reviews| 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 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 31 #include "net/base/capturing_net_log.h" | 31 #include "net/base/capturing_net_log.h" |
| 32 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 33 #include "net/base/load_timing_info.h" | 33 #include "net/base/load_timing_info.h" |
| 34 #include "net/base/load_timing_info_test_util.h" | 34 #include "net/base/load_timing_info_test_util.h" |
| 35 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 36 #include "net/base/net_log.h" | 36 #include "net/base/net_log.h" |
| 37 #include "net/base/net_log_unittest.h" | 37 #include "net/base/net_log_unittest.h" |
| 38 #include "net/base/net_module.h" | 38 #include "net/base/net_module.h" |
| 39 #include "net/base/net_util.h" | 39 #include "net/base/net_util.h" |
| 40 #include "net/base/request_priority.h" | |
| 40 #include "net/base/test_data_directory.h" | 41 #include "net/base/test_data_directory.h" |
| 41 #include "net/base/upload_bytes_element_reader.h" | 42 #include "net/base/upload_bytes_element_reader.h" |
| 42 #include "net/base/upload_data_stream.h" | 43 #include "net/base/upload_data_stream.h" |
| 43 #include "net/base/upload_file_element_reader.h" | 44 #include "net/base/upload_file_element_reader.h" |
| 44 #include "net/cert/ev_root_ca_metadata.h" | 45 #include "net/cert/ev_root_ca_metadata.h" |
| 45 #include "net/cert/test_root_certs.h" | 46 #include "net/cert/test_root_certs.h" |
| 46 #include "net/cookies/cookie_monster.h" | 47 #include "net/cookies/cookie_monster.h" |
| 47 #include "net/cookies/cookie_store_test_helpers.h" | 48 #include "net/cookies/cookie_store_test_helpers.h" |
| 48 #include "net/disk_cache/disk_cache.h" | 49 #include "net/disk_cache/disk_cache.h" |
| 49 #include "net/dns/mock_host_resolver.h" | 50 #include "net/dns/mock_host_resolver.h" |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 protected: | 615 protected: |
| 615 CapturingNetLog net_log_; | 616 CapturingNetLog net_log_; |
| 616 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 617 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 617 URLRequestJobFactoryImpl job_factory_; | 618 URLRequestJobFactoryImpl job_factory_; |
| 618 TestURLRequestContext default_context_; | 619 TestURLRequestContext default_context_; |
| 619 }; | 620 }; |
| 620 | 621 |
| 621 TEST_F(URLRequestTest, AboutBlankTest) { | 622 TEST_F(URLRequestTest, AboutBlankTest) { |
| 622 TestDelegate d; | 623 TestDelegate d; |
| 623 { | 624 { |
| 624 URLRequest r(GURL("about:blank"), &d, &default_context_); | 625 URLRequest r(GURL("about:blank"), |
| 626 DEFAULT_PRIORITY, | |
| 627 &d, | |
| 628 &default_context_, | |
| 629 &default_network_delegate_); | |
| 625 | 630 |
| 626 r.Start(); | 631 r.Start(); |
| 627 EXPECT_TRUE(r.is_pending()); | 632 EXPECT_TRUE(r.is_pending()); |
| 628 | 633 |
| 629 base::RunLoop().Run(); | 634 base::RunLoop().Run(); |
| 630 | 635 |
| 631 EXPECT_TRUE(!r.is_pending()); | 636 EXPECT_TRUE(!r.is_pending()); |
| 632 EXPECT_FALSE(d.received_data_before_response()); | 637 EXPECT_FALSE(d.received_data_before_response()); |
| 633 EXPECT_EQ(d.bytes_received(), 0); | 638 EXPECT_EQ(d.bytes_received(), 0); |
| 634 EXPECT_EQ("", r.GetSocketAddress().host()); | 639 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 635 EXPECT_EQ(0, r.GetSocketAddress().port()); | 640 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 636 | 641 |
| 637 HttpRequestHeaders headers; | 642 HttpRequestHeaders headers; |
| 638 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 643 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
| 639 } | 644 } |
| 640 } | 645 } |
| 641 | 646 |
| 642 TEST_F(URLRequestTest, DataURLImageTest) { | 647 TEST_F(URLRequestTest, DataURLImageTest) { |
| 643 TestDelegate d; | 648 TestDelegate d; |
| 644 { | 649 { |
| 645 // Use our nice little Chrome logo. | 650 // Use our nice little Chrome logo. |
| 646 URLRequest r(GURL( | 651 URLRequest r( |
| 647 "data:image/png;base64," | 652 GURL( |
| 648 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 653 "data:image/png;base64," |
| 649 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" | 654 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/" |
| 650 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" | 655 "9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| 651 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" | 656 "w1y+" |
| 652 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" | 657 "HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" |
| 653 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" | 658 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/" |
| 654 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" | 659 "P827vnucRmYN0gyF01GI5MpCVdW0gO7t" |
| 655 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" | 660 "vNC+vqSEtbZefk5NuLv1jdJ46p/" |
| 656 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" | 661 "zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" |
| 657 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" | 662 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/" |
| 658 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | 663 "MWq12UctI1" |
| 659 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | 664 "dWWm99ypqSYmRUBdKem8MkrO/" |
| 660 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" | 665 "kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" |
| 661 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | 666 "wbtlLTVMZ3BW+" |
| 662 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 667 "TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" |
| 663 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 668 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/" |
| 664 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 669 "nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" |
| 665 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 670 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4Ioy" |
| 671 "hTb" | |
| 672 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/" | |
| 673 "GwnCHghTja6lPhphezPfO5/5" | |
| 674 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/" | |
| 675 "3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | |
| 676 "Md6q5c8GdosynKmSeRuGzpjyl1/" | |
| 677 "9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | |
| 678 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/" | |
| 679 "sYH7DAbwlgC4J+R2Z7F" | |
| 680 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/" | |
| 681 "SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | |
| 682 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+" | |
| 683 "TGaJM" | |
| 684 "nlm2O34uI4b9tflqp1+QEFGzoW/" | |
| 685 "ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | |
| 686 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/" | |
| 687 "G6W9iLiIyCoReV5En" | |
| 688 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | |
|
mmenke
2013/10/30 15:27:11
I think this was much better before. Assume you u
akalin
2013/10/30 21:44:37
Done.
| |
| 689 DEFAULT_PRIORITY, | |
| 666 &d, | 690 &d, |
| 667 &default_context_); | 691 &default_context_, |
| 692 &default_network_delegate_); | |
| 668 | 693 |
| 669 r.Start(); | 694 r.Start(); |
| 670 EXPECT_TRUE(r.is_pending()); | 695 EXPECT_TRUE(r.is_pending()); |
| 671 | 696 |
| 672 base::RunLoop().Run(); | 697 base::RunLoop().Run(); |
| 673 | 698 |
| 674 EXPECT_TRUE(!r.is_pending()); | 699 EXPECT_TRUE(!r.is_pending()); |
| 675 EXPECT_FALSE(d.received_data_before_response()); | 700 EXPECT_FALSE(d.received_data_before_response()); |
| 676 EXPECT_EQ(d.bytes_received(), 911); | 701 EXPECT_EQ(d.bytes_received(), 911); |
| 677 EXPECT_EQ("", r.GetSocketAddress().host()); | 702 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 678 EXPECT_EQ(0, r.GetSocketAddress().port()); | 703 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 679 | 704 |
| 680 HttpRequestHeaders headers; | 705 HttpRequestHeaders headers; |
| 681 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 706 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
| 682 } | 707 } |
| 683 } | 708 } |
| 684 | 709 |
| 685 TEST_F(URLRequestTest, FileTest) { | 710 TEST_F(URLRequestTest, FileTest) { |
| 686 base::FilePath app_path; | 711 base::FilePath app_path; |
| 687 PathService::Get(base::FILE_EXE, &app_path); | 712 PathService::Get(base::FILE_EXE, &app_path); |
| 688 GURL app_url = FilePathToFileURL(app_path); | 713 GURL app_url = FilePathToFileURL(app_path); |
| 689 | 714 |
| 690 TestDelegate d; | 715 TestDelegate d; |
| 691 { | 716 { |
| 692 URLRequest r(app_url, &d, &default_context_); | 717 URLRequest r(app_url, |
| 718 DEFAULT_PRIORITY, | |
| 719 &d, | |
| 720 &default_context_, | |
| 721 &default_network_delegate_); | |
| 693 | 722 |
| 694 r.Start(); | 723 r.Start(); |
| 695 EXPECT_TRUE(r.is_pending()); | 724 EXPECT_TRUE(r.is_pending()); |
| 696 | 725 |
| 697 base::RunLoop().Run(); | 726 base::RunLoop().Run(); |
| 698 | 727 |
| 699 int64 file_size = -1; | 728 int64 file_size = -1; |
| 700 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 729 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
| 701 | 730 |
| 702 EXPECT_TRUE(!r.is_pending()); | 731 EXPECT_TRUE(!r.is_pending()); |
| 703 EXPECT_EQ(1, d.response_started_count()); | 732 EXPECT_EQ(1, d.response_started_count()); |
| 704 EXPECT_FALSE(d.received_data_before_response()); | 733 EXPECT_FALSE(d.received_data_before_response()); |
| 705 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 734 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 706 EXPECT_EQ("", r.GetSocketAddress().host()); | 735 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 707 EXPECT_EQ(0, r.GetSocketAddress().port()); | 736 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 708 | 737 |
| 709 HttpRequestHeaders headers; | 738 HttpRequestHeaders headers; |
| 710 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 739 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
| 711 } | 740 } |
| 712 } | 741 } |
| 713 | 742 |
| 714 TEST_F(URLRequestTest, FileTestCancel) { | 743 TEST_F(URLRequestTest, FileTestCancel) { |
| 715 base::FilePath app_path; | 744 base::FilePath app_path; |
| 716 PathService::Get(base::FILE_EXE, &app_path); | 745 PathService::Get(base::FILE_EXE, &app_path); |
| 717 GURL app_url = FilePathToFileURL(app_path); | 746 GURL app_url = FilePathToFileURL(app_path); |
| 718 | 747 |
| 719 TestDelegate d; | 748 TestDelegate d; |
| 720 { | 749 { |
| 721 URLRequest r(app_url, &d, &default_context_); | 750 URLRequest r(app_url, |
| 751 DEFAULT_PRIORITY, | |
| 752 &d, | |
| 753 &default_context_, | |
| 754 &default_network_delegate_); | |
| 722 | 755 |
| 723 r.Start(); | 756 r.Start(); |
| 724 EXPECT_TRUE(r.is_pending()); | 757 EXPECT_TRUE(r.is_pending()); |
| 725 r.Cancel(); | 758 r.Cancel(); |
| 726 } | 759 } |
| 727 // Async cancellation should be safe even when URLRequest has been already | 760 // Async cancellation should be safe even when URLRequest has been already |
| 728 // destroyed. | 761 // destroyed. |
| 729 base::RunLoop().RunUntilIdle(); | 762 base::RunLoop().RunUntilIdle(); |
| 730 } | 763 } |
| 731 | 764 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 743 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 776 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 744 | 777 |
| 745 const size_t first_byte_position = 500; | 778 const size_t first_byte_position = 500; |
| 746 const size_t last_byte_position = buffer_size - first_byte_position; | 779 const size_t last_byte_position = buffer_size - first_byte_position; |
| 747 const size_t content_length = last_byte_position - first_byte_position + 1; | 780 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 748 std::string partial_buffer_string(buffer.get() + first_byte_position, | 781 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 749 buffer.get() + last_byte_position + 1); | 782 buffer.get() + last_byte_position + 1); |
| 750 | 783 |
| 751 TestDelegate d; | 784 TestDelegate d; |
| 752 { | 785 { |
| 753 URLRequest r(temp_url, &d, &default_context_); | 786 URLRequest r(temp_url, |
| 787 DEFAULT_PRIORITY, | |
| 788 &d, | |
| 789 &default_context_, | |
| 790 &default_network_delegate_); | |
| 754 | 791 |
| 755 HttpRequestHeaders headers; | 792 HttpRequestHeaders headers; |
| 756 headers.SetHeader(HttpRequestHeaders::kRange, | 793 headers.SetHeader(HttpRequestHeaders::kRange, |
| 757 base::StringPrintf( | 794 base::StringPrintf( |
| 758 "bytes=%" PRIuS "-%" PRIuS, | 795 "bytes=%" PRIuS "-%" PRIuS, |
| 759 first_byte_position, last_byte_position)); | 796 first_byte_position, last_byte_position)); |
| 760 r.SetExtraRequestHeaders(headers); | 797 r.SetExtraRequestHeaders(headers); |
| 761 r.Start(); | 798 r.Start(); |
| 762 EXPECT_TRUE(r.is_pending()); | 799 EXPECT_TRUE(r.is_pending()); |
| 763 | 800 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 787 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 824 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 788 | 825 |
| 789 const size_t first_byte_position = 500; | 826 const size_t first_byte_position = 500; |
| 790 const size_t last_byte_position = buffer_size - 1; | 827 const size_t last_byte_position = buffer_size - 1; |
| 791 const size_t content_length = last_byte_position - first_byte_position + 1; | 828 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 792 std::string partial_buffer_string(buffer.get() + first_byte_position, | 829 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 793 buffer.get() + last_byte_position + 1); | 830 buffer.get() + last_byte_position + 1); |
| 794 | 831 |
| 795 TestDelegate d; | 832 TestDelegate d; |
| 796 { | 833 { |
| 797 URLRequest r(temp_url, &d, &default_context_); | 834 URLRequest r(temp_url, |
| 835 DEFAULT_PRIORITY, | |
| 836 &d, | |
| 837 &default_context_, | |
| 838 &default_network_delegate_); | |
| 798 | 839 |
| 799 HttpRequestHeaders headers; | 840 HttpRequestHeaders headers; |
| 800 headers.SetHeader(HttpRequestHeaders::kRange, | 841 headers.SetHeader(HttpRequestHeaders::kRange, |
| 801 base::StringPrintf("bytes=%" PRIuS "-", | 842 base::StringPrintf("bytes=%" PRIuS "-", |
| 802 first_byte_position)); | 843 first_byte_position)); |
| 803 r.SetExtraRequestHeaders(headers); | 844 r.SetExtraRequestHeaders(headers); |
| 804 r.Start(); | 845 r.Start(); |
| 805 EXPECT_TRUE(r.is_pending()); | 846 EXPECT_TRUE(r.is_pending()); |
| 806 | 847 |
| 807 base::RunLoop().Run(); | 848 base::RunLoop().Run(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 824 base::FilePath temp_path; | 865 base::FilePath temp_path; |
| 825 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 866 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| 826 GURL temp_url = FilePathToFileURL(temp_path); | 867 GURL temp_url = FilePathToFileURL(temp_path); |
| 827 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 868 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 828 | 869 |
| 829 int64 file_size; | 870 int64 file_size; |
| 830 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 871 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 831 | 872 |
| 832 TestDelegate d; | 873 TestDelegate d; |
| 833 { | 874 { |
| 834 URLRequest r(temp_url, &d, &default_context_); | 875 URLRequest r(temp_url, |
| 876 DEFAULT_PRIORITY, | |
| 877 &d, | |
| 878 &default_context_, | |
| 879 &default_network_delegate_); | |
| 835 | 880 |
| 836 HttpRequestHeaders headers; | 881 HttpRequestHeaders headers; |
| 837 headers.SetHeader(HttpRequestHeaders::kRange, | 882 headers.SetHeader(HttpRequestHeaders::kRange, |
| 838 "bytes=0-0,10-200,200-300"); | 883 "bytes=0-0,10-200,200-300"); |
| 839 r.SetExtraRequestHeaders(headers); | 884 r.SetExtraRequestHeaders(headers); |
| 840 r.Start(); | 885 r.Start(); |
| 841 EXPECT_TRUE(r.is_pending()); | 886 EXPECT_TRUE(r.is_pending()); |
| 842 | 887 |
| 843 base::RunLoop().Run(); | 888 base::RunLoop().Run(); |
| 844 EXPECT_TRUE(d.request_failed()); | 889 EXPECT_TRUE(d.request_failed()); |
| 845 } | 890 } |
| 846 | 891 |
| 847 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 892 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 848 } | 893 } |
| 849 | 894 |
| 850 TEST_F(URLRequestTest, InvalidUrlTest) { | 895 TEST_F(URLRequestTest, InvalidUrlTest) { |
| 851 TestDelegate d; | 896 TestDelegate d; |
| 852 { | 897 { |
| 853 URLRequest r(GURL("invalid url"), &d, &default_context_); | 898 URLRequest r(GURL("invalid url"), |
| 899 DEFAULT_PRIORITY, | |
| 900 &d, | |
| 901 &default_context_, | |
| 902 &default_network_delegate_); | |
| 854 | 903 |
| 855 r.Start(); | 904 r.Start(); |
| 856 EXPECT_TRUE(r.is_pending()); | 905 EXPECT_TRUE(r.is_pending()); |
| 857 | 906 |
| 858 base::RunLoop().Run(); | 907 base::RunLoop().Run(); |
| 859 EXPECT_TRUE(d.request_failed()); | 908 EXPECT_TRUE(d.request_failed()); |
| 860 } | 909 } |
| 861 } | 910 } |
| 862 | 911 |
| 863 #if defined(OS_WIN) | 912 #if defined(OS_WIN) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 880 CLSCTX_INPROC_SERVER))); | 929 CLSCTX_INPROC_SERVER))); |
| 881 base::win::ScopedComPtr<IPersistFile> persist; | 930 base::win::ScopedComPtr<IPersistFile> persist; |
| 882 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); | 931 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); |
| 883 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); | 932 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); |
| 884 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); | 933 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); |
| 885 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); | 934 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); |
| 886 } | 935 } |
| 887 | 936 |
| 888 TestDelegate d; | 937 TestDelegate d; |
| 889 { | 938 { |
| 890 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), &d, | 939 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), |
| 891 &default_context_); | 940 DEFAULT_PRIORITY, |
| 941 &d, | |
| 942 &default_context_, | |
| 943 &default_network_delegate_); | |
| 892 | 944 |
| 893 r.Start(); | 945 r.Start(); |
| 894 EXPECT_TRUE(r.is_pending()); | 946 EXPECT_TRUE(r.is_pending()); |
| 895 | 947 |
| 896 base::RunLoop().Run(); | 948 base::RunLoop().Run(); |
| 897 | 949 |
| 898 WIN32_FILE_ATTRIBUTE_DATA data; | 950 WIN32_FILE_ATTRIBUTE_DATA data; |
| 899 GetFileAttributesEx(app_path.value().c_str(), | 951 GetFileAttributesEx(app_path.value().c_str(), |
| 900 GetFileExInfoStandard, &data); | 952 GetFileExInfoStandard, &data); |
| 901 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 953 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 924 // Put in mock resource provider. | 976 // Put in mock resource provider. |
| 925 NetModule::SetResourceProvider(TestNetResourceProvider); | 977 NetModule::SetResourceProvider(TestNetResourceProvider); |
| 926 | 978 |
| 927 TestDelegate d; | 979 TestDelegate d; |
| 928 { | 980 { |
| 929 base::FilePath file_path; | 981 base::FilePath file_path; |
| 930 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 982 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
| 931 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 983 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
| 932 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 984 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
| 933 | 985 |
| 934 URLRequest req(FilePathToFileURL(file_path), &d, &default_context_); | 986 URLRequest req(FilePathToFileURL(file_path), |
| 987 DEFAULT_PRIORITY, | |
| 988 &d, | |
| 989 &default_context_, | |
| 990 &default_network_delegate_); | |
| 935 req.Start(); | 991 req.Start(); |
| 936 EXPECT_TRUE(req.is_pending()); | 992 EXPECT_TRUE(req.is_pending()); |
| 937 | 993 |
| 938 d.set_cancel_in_received_data_pending(true); | 994 d.set_cancel_in_received_data_pending(true); |
| 939 | 995 |
| 940 base::RunLoop().Run(); | 996 base::RunLoop().Run(); |
| 941 } | 997 } |
| 942 | 998 |
| 943 // Take out mock resource provider. | 999 // Take out mock resource provider. |
| 944 NetModule::SetResourceProvider(NULL); | 1000 NetModule::SetResourceProvider(NULL); |
| 945 } | 1001 } |
| 946 | 1002 |
| 947 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 1003 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 948 // There is an implicit redirect when loading a file path that matches a | 1004 // There is an implicit redirect when loading a file path that matches a |
| 949 // directory and does not end with a slash. Ensure that following such | 1005 // directory and does not end with a slash. Ensure that following such |
| 950 // redirects does not crash. See http://crbug.com/18686. | 1006 // redirects does not crash. See http://crbug.com/18686. |
| 951 | 1007 |
| 952 base::FilePath path; | 1008 base::FilePath path; |
| 953 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1009 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 954 path = path.Append(FILE_PATH_LITERAL("net")); | 1010 path = path.Append(FILE_PATH_LITERAL("net")); |
| 955 path = path.Append(FILE_PATH_LITERAL("data")); | 1011 path = path.Append(FILE_PATH_LITERAL("data")); |
| 956 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 1012 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 957 | 1013 |
| 958 TestDelegate d; | 1014 TestDelegate d; |
| 959 URLRequest req(FilePathToFileURL(path), &d, &default_context_); | 1015 URLRequest req(FilePathToFileURL(path), |
| 1016 DEFAULT_PRIORITY, | |
| 1017 &d, | |
| 1018 &default_context_, | |
| 1019 &default_network_delegate_); | |
| 960 req.Start(); | 1020 req.Start(); |
| 961 base::RunLoop().Run(); | 1021 base::RunLoop().Run(); |
| 962 | 1022 |
| 963 ASSERT_EQ(1, d.received_redirect_count()); | 1023 ASSERT_EQ(1, d.received_redirect_count()); |
| 964 ASSERT_LT(0, d.bytes_received()); | 1024 ASSERT_LT(0, d.bytes_received()); |
| 965 ASSERT_FALSE(d.request_failed()); | 1025 ASSERT_FALSE(d.request_failed()); |
| 966 ASSERT_TRUE(req.status().is_success()); | 1026 ASSERT_TRUE(req.status().is_success()); |
| 967 } | 1027 } |
| 968 | 1028 |
| 969 #if defined(OS_WIN) | 1029 #if defined(OS_WIN) |
| 970 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 1030 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 971 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 1031 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 972 TestDelegate d; | 1032 TestDelegate d; |
| 973 URLRequest req(GURL("file:///"), &d, &default_context_); | 1033 URLRequest req(GURL("file:///"), |
| 1034 DEFAULT_PRIORITY, | |
| 1035 &d, | |
| 1036 &default_context_, | |
| 1037 &default_network_delegate_); | |
| 974 req.Start(); | 1038 req.Start(); |
| 975 base::RunLoop().Run(); | 1039 base::RunLoop().Run(); |
| 976 | 1040 |
| 977 ASSERT_EQ(1, d.received_redirect_count()); | 1041 ASSERT_EQ(1, d.received_redirect_count()); |
| 978 ASSERT_FALSE(req.status().is_success()); | 1042 ASSERT_FALSE(req.status().is_success()); |
| 979 } | 1043 } |
| 980 #endif | 1044 #endif |
| 981 | 1045 |
| 982 // Custom URLRequestJobs for use with interceptor tests | 1046 // Custom URLRequestJobs for use with interceptor tests |
| 983 class RestartTestJob : public URLRequestTestJob { | 1047 class RestartTestJob : public URLRequestTestJob { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 | 1248 |
| 1185 TEST_F(URLRequestTest, Intercept) { | 1249 TEST_F(URLRequestTest, Intercept) { |
| 1186 TestInterceptor interceptor; | 1250 TestInterceptor interceptor; |
| 1187 | 1251 |
| 1188 // intercept the main request and respond with a simple response | 1252 // intercept the main request and respond with a simple response |
| 1189 interceptor.intercept_main_request_ = true; | 1253 interceptor.intercept_main_request_ = true; |
| 1190 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 1254 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 1191 interceptor.main_data_ = TestInterceptor::ok_data(); | 1255 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 1192 | 1256 |
| 1193 TestDelegate d; | 1257 TestDelegate d; |
| 1194 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1258 URLRequest req(GURL("http://test_intercept/foo"), |
| 1259 DEFAULT_PRIORITY, | |
| 1260 &d, | |
| 1261 &default_context_, | |
| 1262 &default_network_delegate_); | |
| 1195 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 1263 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
| 1196 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 1264 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
| 1197 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 1265 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
| 1198 req.SetUserData(NULL, user_data0); | 1266 req.SetUserData(NULL, user_data0); |
| 1199 req.SetUserData(&user_data1, user_data1); | 1267 req.SetUserData(&user_data1, user_data1); |
| 1200 req.SetUserData(&user_data2, user_data2); | 1268 req.SetUserData(&user_data2, user_data2); |
| 1201 req.set_method("GET"); | 1269 req.set_method("GET"); |
| 1202 req.Start(); | 1270 req.Start(); |
| 1203 base::RunLoop().Run(); | 1271 base::RunLoop().Run(); |
| 1204 | 1272 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1225 interceptor.intercept_main_request_ = true; | 1293 interceptor.intercept_main_request_ = true; |
| 1226 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 1294 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 1227 interceptor.main_data_ = TestInterceptor::redirect_data(); | 1295 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 1228 | 1296 |
| 1229 // intercept that redirect and respond a final OK response | 1297 // intercept that redirect and respond a final OK response |
| 1230 interceptor.intercept_redirect_ = true; | 1298 interceptor.intercept_redirect_ = true; |
| 1231 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 1299 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
| 1232 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 1300 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
| 1233 | 1301 |
| 1234 TestDelegate d; | 1302 TestDelegate d; |
| 1235 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1303 URLRequest req(GURL("http://test_intercept/foo"), |
| 1304 DEFAULT_PRIORITY, | |
| 1305 &d, | |
| 1306 &default_context_, | |
| 1307 &default_network_delegate_); | |
| 1236 req.set_method("GET"); | 1308 req.set_method("GET"); |
| 1237 req.Start(); | 1309 req.Start(); |
| 1238 base::RunLoop().Run(); | 1310 base::RunLoop().Run(); |
| 1239 | 1311 |
| 1240 // Check the interceptor got called as expected | 1312 // Check the interceptor got called as expected |
| 1241 EXPECT_TRUE(interceptor.did_intercept_main_); | 1313 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1242 EXPECT_TRUE(interceptor.did_intercept_redirect_); | 1314 EXPECT_TRUE(interceptor.did_intercept_redirect_); |
| 1243 | 1315 |
| 1244 // Check we got one good response | 1316 // Check we got one good response |
| 1245 EXPECT_TRUE(req.status().is_success()); | 1317 EXPECT_TRUE(req.status().is_success()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1258 interceptor.intercept_main_request_ = true; | 1330 interceptor.intercept_main_request_ = true; |
| 1259 interceptor.main_headers_ = TestInterceptor::error_headers(); | 1331 interceptor.main_headers_ = TestInterceptor::error_headers(); |
| 1260 interceptor.main_data_ = TestInterceptor::error_data(); | 1332 interceptor.main_data_ = TestInterceptor::error_data(); |
| 1261 | 1333 |
| 1262 // intercept that error and respond with an OK response | 1334 // intercept that error and respond with an OK response |
| 1263 interceptor.intercept_final_response_ = true; | 1335 interceptor.intercept_final_response_ = true; |
| 1264 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1336 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1265 interceptor.final_data_ = TestInterceptor::ok_data(); | 1337 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1266 | 1338 |
| 1267 TestDelegate d; | 1339 TestDelegate d; |
| 1268 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1340 URLRequest req(GURL("http://test_intercept/foo"), |
| 1341 DEFAULT_PRIORITY, | |
| 1342 &d, | |
| 1343 &default_context_, | |
| 1344 &default_network_delegate_); | |
| 1269 req.set_method("GET"); | 1345 req.set_method("GET"); |
| 1270 req.Start(); | 1346 req.Start(); |
| 1271 base::RunLoop().Run(); | 1347 base::RunLoop().Run(); |
| 1272 | 1348 |
| 1273 // Check the interceptor got called as expected | 1349 // Check the interceptor got called as expected |
| 1274 EXPECT_TRUE(interceptor.did_intercept_main_); | 1350 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1275 EXPECT_TRUE(interceptor.did_intercept_final_); | 1351 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 1276 | 1352 |
| 1277 // Check we got one good response | 1353 // Check we got one good response |
| 1278 EXPECT_TRUE(req.status().is_success()); | 1354 EXPECT_TRUE(req.status().is_success()); |
| 1279 EXPECT_EQ(200, req.response_headers()->response_code()); | 1355 EXPECT_EQ(200, req.response_headers()->response_code()); |
| 1280 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1356 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1281 EXPECT_EQ(1, d.response_started_count()); | 1357 EXPECT_EQ(1, d.response_started_count()); |
| 1282 EXPECT_EQ(0, d.received_redirect_count()); | 1358 EXPECT_EQ(0, d.received_redirect_count()); |
| 1283 } | 1359 } |
| 1284 | 1360 |
| 1285 TEST_F(URLRequestTest, InterceptNetworkError) { | 1361 TEST_F(URLRequestTest, InterceptNetworkError) { |
| 1286 TestInterceptor interceptor; | 1362 TestInterceptor interceptor; |
| 1287 | 1363 |
| 1288 // intercept the main request to simulate a network error | 1364 // intercept the main request to simulate a network error |
| 1289 interceptor.simulate_main_network_error_ = true; | 1365 interceptor.simulate_main_network_error_ = true; |
| 1290 | 1366 |
| 1291 // intercept that error and respond with an OK response | 1367 // intercept that error and respond with an OK response |
| 1292 interceptor.intercept_final_response_ = true; | 1368 interceptor.intercept_final_response_ = true; |
| 1293 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1369 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1294 interceptor.final_data_ = TestInterceptor::ok_data(); | 1370 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1295 | 1371 |
| 1296 TestDelegate d; | 1372 TestDelegate d; |
| 1297 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1373 URLRequest req(GURL("http://test_intercept/foo"), |
| 1374 DEFAULT_PRIORITY, | |
| 1375 &d, | |
| 1376 &default_context_, | |
| 1377 &default_network_delegate_); | |
| 1298 req.set_method("GET"); | 1378 req.set_method("GET"); |
| 1299 req.Start(); | 1379 req.Start(); |
| 1300 base::RunLoop().Run(); | 1380 base::RunLoop().Run(); |
| 1301 | 1381 |
| 1302 // Check the interceptor got called as expected | 1382 // Check the interceptor got called as expected |
| 1303 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1383 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 1304 EXPECT_TRUE(interceptor.did_intercept_final_); | 1384 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 1305 | 1385 |
| 1306 // Check we received one good response | 1386 // Check we received one good response |
| 1307 EXPECT_TRUE(req.status().is_success()); | 1387 EXPECT_TRUE(req.status().is_success()); |
| 1308 EXPECT_EQ(200, req.response_headers()->response_code()); | 1388 EXPECT_EQ(200, req.response_headers()->response_code()); |
| 1309 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1389 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1310 EXPECT_EQ(1, d.response_started_count()); | 1390 EXPECT_EQ(1, d.response_started_count()); |
| 1311 EXPECT_EQ(0, d.received_redirect_count()); | 1391 EXPECT_EQ(0, d.received_redirect_count()); |
| 1312 } | 1392 } |
| 1313 | 1393 |
| 1314 TEST_F(URLRequestTest, InterceptRestartRequired) { | 1394 TEST_F(URLRequestTest, InterceptRestartRequired) { |
| 1315 TestInterceptor interceptor; | 1395 TestInterceptor interceptor; |
| 1316 | 1396 |
| 1317 // restart the main request | 1397 // restart the main request |
| 1318 interceptor.restart_main_request_ = true; | 1398 interceptor.restart_main_request_ = true; |
| 1319 | 1399 |
| 1320 // then intercept the new main request and respond with an OK response | 1400 // then intercept the new main request and respond with an OK response |
| 1321 interceptor.intercept_main_request_ = true; | 1401 interceptor.intercept_main_request_ = true; |
| 1322 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 1402 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 1323 interceptor.main_data_ = TestInterceptor::ok_data(); | 1403 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 1324 | 1404 |
| 1325 TestDelegate d; | 1405 TestDelegate d; |
| 1326 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1406 URLRequest req(GURL("http://test_intercept/foo"), |
| 1407 DEFAULT_PRIORITY, | |
| 1408 &d, | |
| 1409 &default_context_, | |
| 1410 &default_network_delegate_); | |
| 1327 req.set_method("GET"); | 1411 req.set_method("GET"); |
| 1328 req.Start(); | 1412 req.Start(); |
| 1329 base::RunLoop().Run(); | 1413 base::RunLoop().Run(); |
| 1330 | 1414 |
| 1331 // Check the interceptor got called as expected | 1415 // Check the interceptor got called as expected |
| 1332 EXPECT_TRUE(interceptor.did_restart_main_); | 1416 EXPECT_TRUE(interceptor.did_restart_main_); |
| 1333 EXPECT_TRUE(interceptor.did_intercept_main_); | 1417 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1334 | 1418 |
| 1335 // Check we received one good response | 1419 // Check we received one good response |
| 1336 EXPECT_TRUE(req.status().is_success()); | 1420 EXPECT_TRUE(req.status().is_success()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1347 | 1431 |
| 1348 // intercept the main request and cancel from within the restarted job | 1432 // intercept the main request and cancel from within the restarted job |
| 1349 interceptor.cancel_main_request_ = true; | 1433 interceptor.cancel_main_request_ = true; |
| 1350 | 1434 |
| 1351 // setup to intercept final response and override it with an OK response | 1435 // setup to intercept final response and override it with an OK response |
| 1352 interceptor.intercept_final_response_ = true; | 1436 interceptor.intercept_final_response_ = true; |
| 1353 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1437 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1354 interceptor.final_data_ = TestInterceptor::ok_data(); | 1438 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1355 | 1439 |
| 1356 TestDelegate d; | 1440 TestDelegate d; |
| 1357 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1441 URLRequest req(GURL("http://test_intercept/foo"), |
| 1442 DEFAULT_PRIORITY, | |
| 1443 &d, | |
| 1444 &default_context_, | |
| 1445 &default_network_delegate_); | |
| 1358 req.set_method("GET"); | 1446 req.set_method("GET"); |
| 1359 req.Start(); | 1447 req.Start(); |
| 1360 base::RunLoop().Run(); | 1448 base::RunLoop().Run(); |
| 1361 | 1449 |
| 1362 // Check the interceptor got called as expected | 1450 // Check the interceptor got called as expected |
| 1363 EXPECT_TRUE(interceptor.did_cancel_main_); | 1451 EXPECT_TRUE(interceptor.did_cancel_main_); |
| 1364 EXPECT_FALSE(interceptor.did_intercept_final_); | 1452 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1365 | 1453 |
| 1366 // Check we see a canceled request | 1454 // Check we see a canceled request |
| 1367 EXPECT_FALSE(req.status().is_success()); | 1455 EXPECT_FALSE(req.status().is_success()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1378 | 1466 |
| 1379 // intercept the redirect and cancel from within that job | 1467 // intercept the redirect and cancel from within that job |
| 1380 interceptor.cancel_redirect_request_ = true; | 1468 interceptor.cancel_redirect_request_ = true; |
| 1381 | 1469 |
| 1382 // setup to intercept final response and override it with an OK response | 1470 // setup to intercept final response and override it with an OK response |
| 1383 interceptor.intercept_final_response_ = true; | 1471 interceptor.intercept_final_response_ = true; |
| 1384 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1472 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1385 interceptor.final_data_ = TestInterceptor::ok_data(); | 1473 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1386 | 1474 |
| 1387 TestDelegate d; | 1475 TestDelegate d; |
| 1388 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1476 URLRequest req(GURL("http://test_intercept/foo"), |
| 1477 DEFAULT_PRIORITY, | |
| 1478 &d, | |
| 1479 &default_context_, | |
| 1480 &default_network_delegate_); | |
| 1389 req.set_method("GET"); | 1481 req.set_method("GET"); |
| 1390 req.Start(); | 1482 req.Start(); |
| 1391 base::RunLoop().Run(); | 1483 base::RunLoop().Run(); |
| 1392 | 1484 |
| 1393 // Check the interceptor got called as expected | 1485 // Check the interceptor got called as expected |
| 1394 EXPECT_TRUE(interceptor.did_intercept_main_); | 1486 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1395 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 1487 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
| 1396 EXPECT_FALSE(interceptor.did_intercept_final_); | 1488 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1397 | 1489 |
| 1398 // Check we see a canceled request | 1490 // Check we see a canceled request |
| 1399 EXPECT_FALSE(req.status().is_success()); | 1491 EXPECT_FALSE(req.status().is_success()); |
| 1400 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1492 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1401 } | 1493 } |
| 1402 | 1494 |
| 1403 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 1495 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
| 1404 TestInterceptor interceptor; | 1496 TestInterceptor interceptor; |
| 1405 | 1497 |
| 1406 // intercept the main request to simulate a network error | 1498 // intercept the main request to simulate a network error |
| 1407 interceptor.simulate_main_network_error_ = true; | 1499 interceptor.simulate_main_network_error_ = true; |
| 1408 | 1500 |
| 1409 // setup to intercept final response and cancel from within that job | 1501 // setup to intercept final response and cancel from within that job |
| 1410 interceptor.cancel_final_request_ = true; | 1502 interceptor.cancel_final_request_ = true; |
| 1411 | 1503 |
| 1412 TestDelegate d; | 1504 TestDelegate d; |
| 1413 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1505 URLRequest req(GURL("http://test_intercept/foo"), |
| 1506 DEFAULT_PRIORITY, | |
| 1507 &d, | |
| 1508 &default_context_, | |
| 1509 &default_network_delegate_); | |
| 1414 req.set_method("GET"); | 1510 req.set_method("GET"); |
| 1415 req.Start(); | 1511 req.Start(); |
| 1416 base::RunLoop().Run(); | 1512 base::RunLoop().Run(); |
| 1417 | 1513 |
| 1418 // Check the interceptor got called as expected | 1514 // Check the interceptor got called as expected |
| 1419 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1515 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 1420 EXPECT_TRUE(interceptor.did_cancel_final_); | 1516 EXPECT_TRUE(interceptor.did_cancel_final_); |
| 1421 | 1517 |
| 1422 // Check we see a canceled request | 1518 // Check we see a canceled request |
| 1423 EXPECT_FALSE(req.status().is_success()); | 1519 EXPECT_FALSE(req.status().is_success()); |
| 1424 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1520 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1425 } | 1521 } |
| 1426 | 1522 |
| 1427 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 1523 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
| 1428 TestInterceptor interceptor; | 1524 TestInterceptor interceptor; |
| 1429 | 1525 |
| 1430 // intercept the main request and cancel then restart from within that job | 1526 // intercept the main request and cancel then restart from within that job |
| 1431 interceptor.cancel_then_restart_main_request_ = true; | 1527 interceptor.cancel_then_restart_main_request_ = true; |
| 1432 | 1528 |
| 1433 // setup to intercept final response and override it with an OK response | 1529 // setup to intercept final response and override it with an OK response |
| 1434 interceptor.intercept_final_response_ = true; | 1530 interceptor.intercept_final_response_ = true; |
| 1435 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1531 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1436 interceptor.final_data_ = TestInterceptor::ok_data(); | 1532 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1437 | 1533 |
| 1438 TestDelegate d; | 1534 TestDelegate d; |
| 1439 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1535 URLRequest req(GURL("http://test_intercept/foo"), |
| 1536 DEFAULT_PRIORITY, | |
| 1537 &d, | |
| 1538 &default_context_, | |
| 1539 &default_network_delegate_); | |
| 1440 req.set_method("GET"); | 1540 req.set_method("GET"); |
| 1441 req.Start(); | 1541 req.Start(); |
| 1442 base::RunLoop().Run(); | 1542 base::RunLoop().Run(); |
| 1443 | 1543 |
| 1444 // Check the interceptor got called as expected | 1544 // Check the interceptor got called as expected |
| 1445 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 1545 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
| 1446 EXPECT_FALSE(interceptor.did_intercept_final_); | 1546 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1447 | 1547 |
| 1448 // Check we see a canceled request | 1548 // Check we see a canceled request |
| 1449 EXPECT_FALSE(req.status().is_success()); | 1549 EXPECT_FALSE(req.status().is_success()); |
| 1450 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1550 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 1451 } | 1551 } |
| 1452 | 1552 |
| 1453 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, | 1553 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, |
| 1454 URLRequestContext* context) { | 1554 URLRequestContext* context, |
| 1555 NetworkDelegate* delegate) { | |
| 1455 TestInterceptor interceptor; | 1556 TestInterceptor interceptor; |
| 1456 interceptor.intercept_main_request_ = true; | 1557 interceptor.intercept_main_request_ = true; |
| 1457 interceptor.main_request_load_timing_info_ = job_load_timing; | 1558 interceptor.main_request_load_timing_info_ = job_load_timing; |
| 1458 TestDelegate d; | 1559 TestDelegate d; |
| 1459 URLRequest req(GURL("http://test_intercept/foo"), &d, context); | 1560 URLRequest req(GURL("http://test_intercept/foo"), |
| 1561 DEFAULT_PRIORITY, | |
| 1562 &d, | |
| 1563 context, | |
| 1564 delegate); | |
| 1460 req.Start(); | 1565 req.Start(); |
| 1461 base::RunLoop().Run(); | 1566 base::RunLoop().Run(); |
| 1462 | 1567 |
| 1463 LoadTimingInfo resulting_load_timing; | 1568 LoadTimingInfo resulting_load_timing; |
| 1464 req.GetLoadTimingInfo(&resulting_load_timing); | 1569 req.GetLoadTimingInfo(&resulting_load_timing); |
| 1465 | 1570 |
| 1466 // None of these should be modified by the URLRequest. | 1571 // None of these should be modified by the URLRequest. |
| 1467 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); | 1572 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); |
| 1468 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); | 1573 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); |
| 1469 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); | 1574 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1523 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11); | 1628 load_timing.receive_headers_end = now + base::TimeDelta::FromDays(11); |
| 1524 return load_timing; | 1629 return load_timing; |
| 1525 } | 1630 } |
| 1526 | 1631 |
| 1527 // Basic test that the intercept + load timing tests work. | 1632 // Basic test that the intercept + load timing tests work. |
| 1528 TEST_F(URLRequestTest, InterceptLoadTiming) { | 1633 TEST_F(URLRequestTest, InterceptLoadTiming) { |
| 1529 base::TimeTicks now = base::TimeTicks::Now(); | 1634 base::TimeTicks now = base::TimeTicks::Now(); |
| 1530 LoadTimingInfo job_load_timing = | 1635 LoadTimingInfo job_load_timing = |
| 1531 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false); | 1636 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, false); |
| 1532 | 1637 |
| 1533 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1638 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1534 &default_context_); | 1639 job_load_timing, &default_context_, &default_network_delegate_); |
| 1535 | 1640 |
| 1536 // Nothing should have been changed by the URLRequest. | 1641 // Nothing should have been changed by the URLRequest. |
| 1537 EXPECT_EQ(job_load_timing.proxy_resolve_start, | 1642 EXPECT_EQ(job_load_timing.proxy_resolve_start, |
| 1538 load_timing_result.proxy_resolve_start); | 1643 load_timing_result.proxy_resolve_start); |
| 1539 EXPECT_EQ(job_load_timing.proxy_resolve_end, | 1644 EXPECT_EQ(job_load_timing.proxy_resolve_end, |
| 1540 load_timing_result.proxy_resolve_end); | 1645 load_timing_result.proxy_resolve_end); |
| 1541 EXPECT_EQ(job_load_timing.connect_timing.dns_start, | 1646 EXPECT_EQ(job_load_timing.connect_timing.dns_start, |
| 1542 load_timing_result.connect_timing.dns_start); | 1647 load_timing_result.connect_timing.dns_start); |
| 1543 EXPECT_EQ(job_load_timing.connect_timing.dns_end, | 1648 EXPECT_EQ(job_load_timing.connect_timing.dns_end, |
| 1544 load_timing_result.connect_timing.dns_end); | 1649 load_timing_result.connect_timing.dns_end); |
| 1545 EXPECT_EQ(job_load_timing.connect_timing.connect_start, | 1650 EXPECT_EQ(job_load_timing.connect_timing.connect_start, |
| 1546 load_timing_result.connect_timing.connect_start); | 1651 load_timing_result.connect_timing.connect_start); |
| 1547 EXPECT_EQ(job_load_timing.connect_timing.connect_end, | 1652 EXPECT_EQ(job_load_timing.connect_timing.connect_end, |
| 1548 load_timing_result.connect_timing.connect_end); | 1653 load_timing_result.connect_timing.connect_end); |
| 1549 EXPECT_EQ(job_load_timing.connect_timing.ssl_start, | 1654 EXPECT_EQ(job_load_timing.connect_timing.ssl_start, |
| 1550 load_timing_result.connect_timing.ssl_start); | 1655 load_timing_result.connect_timing.ssl_start); |
| 1551 EXPECT_EQ(job_load_timing.connect_timing.ssl_end, | 1656 EXPECT_EQ(job_load_timing.connect_timing.ssl_end, |
| 1552 load_timing_result.connect_timing.ssl_end); | 1657 load_timing_result.connect_timing.ssl_end); |
| 1553 | 1658 |
| 1554 // Redundant sanity check. | 1659 // Redundant sanity check. |
| 1555 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES); | 1660 TestLoadTimingNotReused(load_timing_result, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1556 } | 1661 } |
| 1557 | 1662 |
| 1558 // Another basic test, with proxy and SSL times, but no DNS times. | 1663 // Another basic test, with proxy and SSL times, but no DNS times. |
| 1559 TEST_F(URLRequestTest, InterceptLoadTimingProxy) { | 1664 TEST_F(URLRequestTest, InterceptLoadTimingProxy) { |
| 1560 base::TimeTicks now = base::TimeTicks::Now(); | 1665 base::TimeTicks now = base::TimeTicks::Now(); |
| 1561 LoadTimingInfo job_load_timing = | 1666 LoadTimingInfo job_load_timing = |
| 1562 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true); | 1667 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, true); |
| 1563 | 1668 |
| 1564 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1669 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1565 &default_context_); | 1670 job_load_timing, &default_context_, &default_network_delegate_); |
| 1566 | 1671 |
| 1567 // Nothing should have been changed by the URLRequest. | 1672 // Nothing should have been changed by the URLRequest. |
| 1568 EXPECT_EQ(job_load_timing.proxy_resolve_start, | 1673 EXPECT_EQ(job_load_timing.proxy_resolve_start, |
| 1569 load_timing_result.proxy_resolve_start); | 1674 load_timing_result.proxy_resolve_start); |
| 1570 EXPECT_EQ(job_load_timing.proxy_resolve_end, | 1675 EXPECT_EQ(job_load_timing.proxy_resolve_end, |
| 1571 load_timing_result.proxy_resolve_end); | 1676 load_timing_result.proxy_resolve_end); |
| 1572 EXPECT_EQ(job_load_timing.connect_timing.dns_start, | 1677 EXPECT_EQ(job_load_timing.connect_timing.dns_start, |
| 1573 load_timing_result.connect_timing.dns_start); | 1678 load_timing_result.connect_timing.dns_start); |
| 1574 EXPECT_EQ(job_load_timing.connect_timing.dns_end, | 1679 EXPECT_EQ(job_load_timing.connect_timing.dns_end, |
| 1575 load_timing_result.connect_timing.dns_end); | 1680 load_timing_result.connect_timing.dns_end); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1599 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true); | 1704 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_DNS_TIMES, true); |
| 1600 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6); | 1705 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(6); |
| 1601 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5); | 1706 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(5); |
| 1602 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4); | 1707 job_load_timing.connect_timing.dns_start = now - base::TimeDelta::FromDays(4); |
| 1603 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3); | 1708 job_load_timing.connect_timing.dns_end = now - base::TimeDelta::FromDays(3); |
| 1604 job_load_timing.connect_timing.connect_start = | 1709 job_load_timing.connect_timing.connect_start = |
| 1605 now - base::TimeDelta::FromDays(2); | 1710 now - base::TimeDelta::FromDays(2); |
| 1606 job_load_timing.connect_timing.connect_end = | 1711 job_load_timing.connect_timing.connect_end = |
| 1607 now - base::TimeDelta::FromDays(1); | 1712 now - base::TimeDelta::FromDays(1); |
| 1608 | 1713 |
| 1609 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1714 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1610 &default_context_); | 1715 job_load_timing, &default_context_, &default_network_delegate_); |
| 1611 | 1716 |
| 1612 // Proxy times, connect times, and DNS times should all be replaced with | 1717 // Proxy times, connect times, and DNS times should all be replaced with |
| 1613 // request_start. | 1718 // request_start. |
| 1614 EXPECT_EQ(load_timing_result.request_start, | 1719 EXPECT_EQ(load_timing_result.request_start, |
| 1615 load_timing_result.proxy_resolve_start); | 1720 load_timing_result.proxy_resolve_start); |
| 1616 EXPECT_EQ(load_timing_result.request_start, | 1721 EXPECT_EQ(load_timing_result.request_start, |
| 1617 load_timing_result.proxy_resolve_end); | 1722 load_timing_result.proxy_resolve_end); |
| 1618 EXPECT_EQ(load_timing_result.request_start, | 1723 EXPECT_EQ(load_timing_result.request_start, |
| 1619 load_timing_result.connect_timing.dns_start); | 1724 load_timing_result.connect_timing.dns_start); |
| 1620 EXPECT_EQ(load_timing_result.request_start, | 1725 EXPECT_EQ(load_timing_result.request_start, |
| 1621 load_timing_result.connect_timing.dns_end); | 1726 load_timing_result.connect_timing.dns_end); |
| 1622 EXPECT_EQ(load_timing_result.request_start, | 1727 EXPECT_EQ(load_timing_result.request_start, |
| 1623 load_timing_result.connect_timing.connect_start); | 1728 load_timing_result.connect_timing.connect_start); |
| 1624 EXPECT_EQ(load_timing_result.request_start, | 1729 EXPECT_EQ(load_timing_result.request_start, |
| 1625 load_timing_result.connect_timing.connect_end); | 1730 load_timing_result.connect_timing.connect_end); |
| 1626 | 1731 |
| 1627 // Other times should have been left null. | 1732 // Other times should have been left null. |
| 1628 TestLoadTimingNotReusedWithProxy(load_timing_result, | 1733 TestLoadTimingNotReusedWithProxy(load_timing_result, |
| 1629 CONNECT_TIMING_HAS_DNS_TIMES); | 1734 CONNECT_TIMING_HAS_DNS_TIMES); |
| 1630 } | 1735 } |
| 1631 | 1736 |
| 1632 // Same as above, but in the reused case. | 1737 // Same as above, but in the reused case. |
| 1633 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolutionReused) { | 1738 TEST_F(URLRequestTest, InterceptLoadTimingEarlyProxyResolutionReused) { |
| 1634 base::TimeTicks now = base::TimeTicks::Now(); | 1739 base::TimeTicks now = base::TimeTicks::Now(); |
| 1635 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true); | 1740 LoadTimingInfo job_load_timing = NormalLoadTimingInfoReused(now, true); |
| 1636 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4); | 1741 job_load_timing.proxy_resolve_start = now - base::TimeDelta::FromDays(4); |
| 1637 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3); | 1742 job_load_timing.proxy_resolve_end = now - base::TimeDelta::FromDays(3); |
| 1638 | 1743 |
| 1639 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1744 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1640 &default_context_); | 1745 job_load_timing, &default_context_, &default_network_delegate_); |
| 1641 | 1746 |
| 1642 // Proxy times and connect times should all be replaced with request_start. | 1747 // Proxy times and connect times should all be replaced with request_start. |
| 1643 EXPECT_EQ(load_timing_result.request_start, | 1748 EXPECT_EQ(load_timing_result.request_start, |
| 1644 load_timing_result.proxy_resolve_start); | 1749 load_timing_result.proxy_resolve_start); |
| 1645 EXPECT_EQ(load_timing_result.request_start, | 1750 EXPECT_EQ(load_timing_result.request_start, |
| 1646 load_timing_result.proxy_resolve_end); | 1751 load_timing_result.proxy_resolve_end); |
| 1647 | 1752 |
| 1648 // Other times should have been left null. | 1753 // Other times should have been left null. |
| 1649 TestLoadTimingReusedWithProxy(load_timing_result); | 1754 TestLoadTimingReusedWithProxy(load_timing_result); |
| 1650 } | 1755 } |
| 1651 | 1756 |
| 1652 // Make sure that URLRequest correctly adjusts connect times when they're before | 1757 // Make sure that URLRequest correctly adjusts connect times when they're before |
| 1653 // |request_start|, due to reusing a connected socket. The connected socket is | 1758 // |request_start|, due to reusing a connected socket. The connected socket is |
| 1654 // not considered reused in this test (May be a preconnect). | 1759 // not considered reused in this test (May be a preconnect). |
| 1655 // | 1760 // |
| 1656 // To mix things up, the request has SSL times, but no DNS times. | 1761 // To mix things up, the request has SSL times, but no DNS times. |
| 1657 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnect) { | 1762 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnect) { |
| 1658 base::TimeTicks now = base::TimeTicks::Now(); | 1763 base::TimeTicks now = base::TimeTicks::Now(); |
| 1659 LoadTimingInfo job_load_timing = | 1764 LoadTimingInfo job_load_timing = |
| 1660 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false); | 1765 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_SSL_TIMES, false); |
| 1661 job_load_timing.connect_timing.connect_start = | 1766 job_load_timing.connect_timing.connect_start = |
| 1662 now - base::TimeDelta::FromDays(1); | 1767 now - base::TimeDelta::FromDays(1); |
| 1663 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2); | 1768 job_load_timing.connect_timing.ssl_start = now - base::TimeDelta::FromDays(2); |
| 1664 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3); | 1769 job_load_timing.connect_timing.ssl_end = now - base::TimeDelta::FromDays(3); |
| 1665 job_load_timing.connect_timing.connect_end = | 1770 job_load_timing.connect_timing.connect_end = |
| 1666 now - base::TimeDelta::FromDays(4); | 1771 now - base::TimeDelta::FromDays(4); |
| 1667 | 1772 |
| 1668 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1773 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1669 &default_context_); | 1774 job_load_timing, &default_context_, &default_network_delegate_); |
| 1670 | 1775 |
| 1671 // Connect times, and SSL times should be replaced with request_start. | 1776 // Connect times, and SSL times should be replaced with request_start. |
| 1672 EXPECT_EQ(load_timing_result.request_start, | 1777 EXPECT_EQ(load_timing_result.request_start, |
| 1673 load_timing_result.connect_timing.connect_start); | 1778 load_timing_result.connect_timing.connect_start); |
| 1674 EXPECT_EQ(load_timing_result.request_start, | 1779 EXPECT_EQ(load_timing_result.request_start, |
| 1675 load_timing_result.connect_timing.ssl_start); | 1780 load_timing_result.connect_timing.ssl_start); |
| 1676 EXPECT_EQ(load_timing_result.request_start, | 1781 EXPECT_EQ(load_timing_result.request_start, |
| 1677 load_timing_result.connect_timing.ssl_end); | 1782 load_timing_result.connect_timing.ssl_end); |
| 1678 EXPECT_EQ(load_timing_result.request_start, | 1783 EXPECT_EQ(load_timing_result.request_start, |
| 1679 load_timing_result.connect_timing.connect_end); | 1784 load_timing_result.connect_timing.connect_end); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1690 // In this test, there are no SSL or DNS times. | 1795 // In this test, there are no SSL or DNS times. |
| 1691 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnectWithProxy) { | 1796 TEST_F(URLRequestTest, InterceptLoadTimingEarlyConnectWithProxy) { |
| 1692 base::TimeTicks now = base::TimeTicks::Now(); | 1797 base::TimeTicks now = base::TimeTicks::Now(); |
| 1693 LoadTimingInfo job_load_timing = | 1798 LoadTimingInfo job_load_timing = |
| 1694 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true); | 1799 NormalLoadTimingInfo(now, CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY, true); |
| 1695 job_load_timing.connect_timing.connect_start = | 1800 job_load_timing.connect_timing.connect_start = |
| 1696 now - base::TimeDelta::FromDays(1); | 1801 now - base::TimeDelta::FromDays(1); |
| 1697 job_load_timing.connect_timing.connect_end = | 1802 job_load_timing.connect_timing.connect_end = |
| 1698 now - base::TimeDelta::FromDays(2); | 1803 now - base::TimeDelta::FromDays(2); |
| 1699 | 1804 |
| 1700 LoadTimingInfo load_timing_result = RunLoadTimingTest(job_load_timing, | 1805 LoadTimingInfo load_timing_result = RunLoadTimingTest( |
| 1701 &default_context_); | 1806 job_load_timing, &default_context_, &default_network_delegate_); |
| 1702 | 1807 |
| 1703 // Connect times should be replaced with proxy_resolve_end. | 1808 // Connect times should be replaced with proxy_resolve_end. |
| 1704 EXPECT_EQ(load_timing_result.proxy_resolve_end, | 1809 EXPECT_EQ(load_timing_result.proxy_resolve_end, |
| 1705 load_timing_result.connect_timing.connect_start); | 1810 load_timing_result.connect_timing.connect_start); |
| 1706 EXPECT_EQ(load_timing_result.proxy_resolve_end, | 1811 EXPECT_EQ(load_timing_result.proxy_resolve_end, |
| 1707 load_timing_result.connect_timing.connect_end); | 1812 load_timing_result.connect_timing.connect_end); |
| 1708 | 1813 |
| 1709 // Other times should have been left null. | 1814 // Other times should have been left null. |
| 1710 TestLoadTimingNotReusedWithProxy(load_timing_result, | 1815 TestLoadTimingNotReusedWithProxy(load_timing_result, |
| 1711 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 1816 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 1712 } | 1817 } |
| 1713 | 1818 |
| 1714 // Check that two different URL requests have different identifiers. | 1819 // Check that two different URL requests have different identifiers. |
| 1715 TEST_F(URLRequestTest, Identifiers) { | 1820 TEST_F(URLRequestTest, Identifiers) { |
| 1716 TestDelegate d; | 1821 TestDelegate d; |
| 1717 TestURLRequestContext context; | 1822 TestURLRequestContext context; |
| 1718 TestURLRequest req(GURL("http://example.com"), &d, &context, NULL); | 1823 TestURLRequest req( |
| 1719 TestURLRequest other_req(GURL("http://example.com"), &d, &context, NULL); | 1824 GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context, NULL); |
| 1825 TestURLRequest other_req( | |
| 1826 GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context, NULL); | |
| 1720 | 1827 |
| 1721 ASSERT_NE(req.identifier(), other_req.identifier()); | 1828 ASSERT_NE(req.identifier(), other_req.identifier()); |
| 1722 } | 1829 } |
| 1723 | 1830 |
| 1724 // Check that a failure to connect to the proxy is reported to the network | 1831 // Check that a failure to connect to the proxy is reported to the network |
| 1725 // delegate. | 1832 // delegate. |
| 1726 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 1833 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
| 1727 MockHostResolver host_resolver; | 1834 MockHostResolver host_resolver; |
| 1728 host_resolver.rules()->AddSimulatedFailure("*"); | 1835 host_resolver.rules()->AddSimulatedFailure("*"); |
| 1729 | 1836 |
| 1730 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 1837 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 1731 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); | 1838 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); |
| 1732 | 1839 |
| 1733 TestDelegate d; | 1840 TestDelegate d; |
| 1734 URLRequest req(GURL("http://example.com"), &d, &context); | 1841 URLRequest req(GURL("http://example.com"), |
| 1842 DEFAULT_PRIORITY, | |
| 1843 &d, | |
| 1844 &context, | |
| 1845 &network_delegate); | |
| 1735 req.set_method("GET"); | 1846 req.set_method("GET"); |
| 1736 | 1847 |
| 1737 req.Start(); | 1848 req.Start(); |
| 1738 base::RunLoop().Run(); | 1849 base::RunLoop().Run(); |
| 1739 | 1850 |
| 1740 // Check we see a failed request. | 1851 // Check we see a failed request. |
| 1741 EXPECT_FALSE(req.status().is_success()); | 1852 EXPECT_FALSE(req.status().is_success()); |
| 1742 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1853 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 1743 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); | 1854 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); |
| 1744 | 1855 |
| 1745 EXPECT_EQ(1, network_delegate.error_count()); | 1856 EXPECT_EQ(1, network_delegate.error_count()); |
| 1746 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); | 1857 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
| 1747 EXPECT_EQ(1, network_delegate.completed_requests()); | 1858 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1748 } | 1859 } |
| 1749 | 1860 |
| 1750 // Make sure that net::NetworkDelegate::NotifyCompleted is called if | 1861 // Make sure that net::NetworkDelegate::NotifyCompleted is called if |
| 1751 // content is empty. | 1862 // content is empty. |
| 1752 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 1863 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
| 1753 TestDelegate d; | 1864 TestDelegate d; |
| 1754 URLRequest req(GURL("data:,"), &d, &default_context_); | 1865 URLRequest req(GURL("data:,"), |
| 1866 DEFAULT_PRIORITY, | |
| 1867 &d, | |
| 1868 &default_context_, | |
| 1869 &default_network_delegate_); | |
| 1755 req.Start(); | 1870 req.Start(); |
| 1756 base::RunLoop().Run(); | 1871 base::RunLoop().Run(); |
| 1757 EXPECT_EQ("", d.data_received()); | 1872 EXPECT_EQ("", d.data_received()); |
| 1758 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 1873 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 1759 } | 1874 } |
| 1760 | 1875 |
| 1761 // Make sure that SetPriority actually sets the URLRequest's priority | 1876 // Make sure that SetPriority actually sets the URLRequest's priority |
| 1762 // correctly, both before and after start. | 1877 // correctly, both before and after start. |
| 1763 TEST_F(URLRequestTest, SetPriorityBasic) { | 1878 TEST_F(URLRequestTest, SetPriorityBasic) { |
| 1764 TestDelegate d; | 1879 TestDelegate d; |
| 1765 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1880 URLRequest req(GURL("http://test_intercept/foo"), |
| 1881 DEFAULT_PRIORITY, | |
| 1882 &d, | |
| 1883 &default_context_, | |
| 1884 &default_network_delegate_); | |
| 1766 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 1885 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 1767 | 1886 |
| 1768 req.SetPriority(LOW); | 1887 req.SetPriority(LOW); |
| 1769 EXPECT_EQ(LOW, req.priority()); | 1888 EXPECT_EQ(LOW, req.priority()); |
| 1770 | 1889 |
| 1771 req.Start(); | 1890 req.Start(); |
| 1772 EXPECT_EQ(LOW, req.priority()); | 1891 EXPECT_EQ(LOW, req.priority()); |
| 1773 | 1892 |
| 1774 req.SetPriority(MEDIUM); | 1893 req.SetPriority(MEDIUM); |
| 1775 EXPECT_EQ(MEDIUM, req.priority()); | 1894 EXPECT_EQ(MEDIUM, req.priority()); |
| 1776 } | 1895 } |
| 1777 | 1896 |
| 1778 // Make sure that URLRequest calls SetPriority on a job before calling | 1897 // Make sure that URLRequest calls SetPriority on a job before calling |
| 1779 // Start on it. | 1898 // Start on it. |
| 1780 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { | 1899 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
| 1781 TestDelegate d; | 1900 TestDelegate d; |
| 1782 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1901 URLRequest req(GURL("http://test_intercept/foo"), |
| 1902 DEFAULT_PRIORITY, | |
| 1903 &d, | |
| 1904 &default_context_, | |
| 1905 &default_network_delegate_); | |
| 1783 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 1906 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 1784 | 1907 |
| 1785 scoped_refptr<URLRequestTestJob> job = | 1908 scoped_refptr<URLRequestTestJob> job = |
| 1786 new URLRequestTestJob(&req, &default_network_delegate_); | 1909 new URLRequestTestJob(&req, &default_network_delegate_); |
| 1787 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1910 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1788 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 1911 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 1789 | 1912 |
| 1790 req.SetPriority(LOW); | 1913 req.SetPriority(LOW); |
| 1791 | 1914 |
| 1792 req.Start(); | 1915 req.Start(); |
| 1793 EXPECT_EQ(LOW, job->priority()); | 1916 EXPECT_EQ(LOW, job->priority()); |
| 1794 } | 1917 } |
| 1795 | 1918 |
| 1796 // Make sure that URLRequest passes on its priority updates to its | 1919 // Make sure that URLRequest passes on its priority updates to its |
| 1797 // job. | 1920 // job. |
| 1798 TEST_F(URLRequestTest, SetJobPriority) { | 1921 TEST_F(URLRequestTest, SetJobPriority) { |
| 1799 TestDelegate d; | 1922 TestDelegate d; |
| 1800 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); | 1923 URLRequest req(GURL("http://test_intercept/foo"), |
| 1924 DEFAULT_PRIORITY, | |
| 1925 &d, | |
| 1926 &default_context_, | |
| 1927 &default_network_delegate_); | |
| 1801 | 1928 |
| 1802 scoped_refptr<URLRequestTestJob> job = | 1929 scoped_refptr<URLRequestTestJob> job = |
| 1803 new URLRequestTestJob(&req, &default_network_delegate_); | 1930 new URLRequestTestJob(&req, &default_network_delegate_); |
| 1804 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1931 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1805 | 1932 |
| 1806 req.SetPriority(LOW); | 1933 req.SetPriority(LOW); |
| 1807 req.Start(); | 1934 req.Start(); |
| 1808 EXPECT_EQ(LOW, job->priority()); | 1935 EXPECT_EQ(LOW, job->priority()); |
| 1809 | 1936 |
| 1810 req.SetPriority(MEDIUM); | 1937 req.SetPriority(MEDIUM); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1837 scoped_refptr<DelayedCookieMonster> delayed_cm = | 1964 scoped_refptr<DelayedCookieMonster> delayed_cm = |
| 1838 new DelayedCookieMonster(); | 1965 new DelayedCookieMonster(); |
| 1839 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 1966 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
| 1840 context.set_cookie_store(delayed_cm.get()); | 1967 context.set_cookie_store(delayed_cm.get()); |
| 1841 | 1968 |
| 1842 // Set up a cookie. | 1969 // Set up a cookie. |
| 1843 { | 1970 { |
| 1844 TestNetworkDelegate network_delegate; | 1971 TestNetworkDelegate network_delegate; |
| 1845 context.set_network_delegate(&network_delegate); | 1972 context.set_network_delegate(&network_delegate); |
| 1846 TestDelegate d; | 1973 TestDelegate d; |
| 1847 URLRequest req( | 1974 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
| 1848 test_server.GetURL("set-cookie?CookieToNotSend=1"), &d, &context); | 1975 DEFAULT_PRIORITY, |
| 1976 &d, | |
| 1977 &context, | |
| 1978 &network_delegate); | |
| 1849 req.Start(); | 1979 req.Start(); |
| 1850 base::RunLoop().Run(); | 1980 base::RunLoop().Run(); |
| 1851 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1981 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1852 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1982 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1853 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 1983 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 1854 } | 1984 } |
| 1855 | 1985 |
| 1856 // Verify that the cookie is set. | 1986 // Verify that the cookie is set. |
| 1857 { | 1987 { |
| 1858 TestNetworkDelegate network_delegate; | 1988 TestNetworkDelegate network_delegate; |
| 1859 context.set_network_delegate(&network_delegate); | 1989 context.set_network_delegate(&network_delegate); |
| 1860 TestDelegate d; | 1990 TestDelegate d; |
| 1861 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d, &context); | 1991 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 1992 DEFAULT_PRIORITY, | |
| 1993 &d, | |
| 1994 &context, | |
| 1995 &network_delegate); | |
| 1862 req.Start(); | 1996 req.Start(); |
| 1863 base::RunLoop().Run(); | 1997 base::RunLoop().Run(); |
| 1864 | 1998 |
| 1865 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 1999 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 1866 != std::string::npos); | 2000 != std::string::npos); |
| 1867 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2001 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1868 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2002 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1869 } | 2003 } |
| 1870 } | 2004 } |
| 1871 | 2005 |
| 1872 TEST_F(URLRequestTest, DoNotSendCookies) { | 2006 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 1873 LocalHttpTestServer test_server; | 2007 LocalHttpTestServer test_server; |
| 1874 ASSERT_TRUE(test_server.Start()); | 2008 ASSERT_TRUE(test_server.Start()); |
| 1875 | 2009 |
| 1876 // Set up a cookie. | 2010 // Set up a cookie. |
| 1877 { | 2011 { |
| 1878 TestNetworkDelegate network_delegate; | 2012 TestNetworkDelegate network_delegate; |
| 1879 default_context_.set_network_delegate(&network_delegate); | 2013 default_context_.set_network_delegate(&network_delegate); |
| 1880 TestDelegate d; | 2014 TestDelegate d; |
| 1881 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2015 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
| 2016 DEFAULT_PRIORITY, | |
| 1882 &d, | 2017 &d, |
| 1883 &default_context_); | 2018 &default_context_, |
| 2019 &network_delegate); | |
| 1884 req.Start(); | 2020 req.Start(); |
| 1885 base::RunLoop().Run(); | 2021 base::RunLoop().Run(); |
| 1886 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2022 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1887 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2023 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1888 } | 2024 } |
| 1889 | 2025 |
| 1890 // Verify that the cookie is set. | 2026 // Verify that the cookie is set. |
| 1891 { | 2027 { |
| 1892 TestNetworkDelegate network_delegate; | 2028 TestNetworkDelegate network_delegate; |
| 1893 default_context_.set_network_delegate(&network_delegate); | 2029 default_context_.set_network_delegate(&network_delegate); |
| 1894 TestDelegate d; | 2030 TestDelegate d; |
| 1895 URLRequest req( | 2031 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 1896 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2032 DEFAULT_PRIORITY, |
| 2033 &d, | |
| 2034 &default_context_, | |
| 2035 &network_delegate); | |
| 1897 req.Start(); | 2036 req.Start(); |
| 1898 base::RunLoop().Run(); | 2037 base::RunLoop().Run(); |
| 1899 | 2038 |
| 1900 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2039 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 1901 != std::string::npos); | 2040 != std::string::npos); |
| 1902 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2041 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1903 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2042 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1904 } | 2043 } |
| 1905 | 2044 |
| 1906 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 2045 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 1907 { | 2046 { |
| 1908 TestNetworkDelegate network_delegate; | 2047 TestNetworkDelegate network_delegate; |
| 1909 default_context_.set_network_delegate(&network_delegate); | 2048 default_context_.set_network_delegate(&network_delegate); |
| 1910 TestDelegate d; | 2049 TestDelegate d; |
| 1911 URLRequest req( | 2050 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 1912 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2051 DEFAULT_PRIORITY, |
| 2052 &d, | |
| 2053 &default_context_, | |
| 2054 &network_delegate); | |
| 1913 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); | 2055 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); |
| 1914 req.Start(); | 2056 req.Start(); |
| 1915 base::RunLoop().Run(); | 2057 base::RunLoop().Run(); |
| 1916 | 2058 |
| 1917 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2059 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 1918 == std::string::npos); | 2060 == std::string::npos); |
| 1919 | 2061 |
| 1920 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 2062 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 1921 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2063 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1922 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2064 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1923 } | 2065 } |
| 1924 } | 2066 } |
| 1925 | 2067 |
| 1926 TEST_F(URLRequestTest, DoNotSaveCookies) { | 2068 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 1927 LocalHttpTestServer test_server; | 2069 LocalHttpTestServer test_server; |
| 1928 ASSERT_TRUE(test_server.Start()); | 2070 ASSERT_TRUE(test_server.Start()); |
| 1929 | 2071 |
| 1930 // Set up a cookie. | 2072 // Set up a cookie. |
| 1931 { | 2073 { |
| 1932 TestNetworkDelegate network_delegate; | 2074 TestNetworkDelegate network_delegate; |
| 1933 default_context_.set_network_delegate(&network_delegate); | 2075 default_context_.set_network_delegate(&network_delegate); |
| 1934 TestDelegate d; | 2076 TestDelegate d; |
| 1935 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2077 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 2078 DEFAULT_PRIORITY, | |
| 1936 &d, | 2079 &d, |
| 1937 &default_context_); | 2080 &default_context_, |
| 2081 &network_delegate); | |
| 1938 req.Start(); | 2082 req.Start(); |
| 1939 base::RunLoop().Run(); | 2083 base::RunLoop().Run(); |
| 1940 | 2084 |
| 1941 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2085 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1942 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2086 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1943 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2087 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 1944 } | 2088 } |
| 1945 | 2089 |
| 1946 // Try to set-up another cookie and update the previous cookie. | 2090 // Try to set-up another cookie and update the previous cookie. |
| 1947 { | 2091 { |
| 1948 TestNetworkDelegate network_delegate; | 2092 TestNetworkDelegate network_delegate; |
| 1949 default_context_.set_network_delegate(&network_delegate); | 2093 default_context_.set_network_delegate(&network_delegate); |
| 1950 TestDelegate d; | 2094 TestDelegate d; |
| 1951 URLRequest req( | 2095 URLRequest req( |
| 1952 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2096 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2097 DEFAULT_PRIORITY, | |
| 1953 &d, | 2098 &d, |
| 1954 &default_context_); | 2099 &default_context_, |
| 2100 &network_delegate); | |
| 1955 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); | 2101 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); |
| 1956 req.Start(); | 2102 req.Start(); |
| 1957 | 2103 |
| 1958 base::RunLoop().Run(); | 2104 base::RunLoop().Run(); |
| 1959 | 2105 |
| 1960 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 2106 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 1961 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2107 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1962 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2108 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1963 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2109 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 1964 } | 2110 } |
| 1965 | 2111 |
| 1966 // Verify the cookies weren't saved or updated. | 2112 // Verify the cookies weren't saved or updated. |
| 1967 { | 2113 { |
| 1968 TestNetworkDelegate network_delegate; | 2114 TestNetworkDelegate network_delegate; |
| 1969 default_context_.set_network_delegate(&network_delegate); | 2115 default_context_.set_network_delegate(&network_delegate); |
| 1970 TestDelegate d; | 2116 TestDelegate d; |
| 1971 URLRequest req( | 2117 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 1972 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2118 DEFAULT_PRIORITY, |
| 2119 &d, | |
| 2120 &default_context_, | |
| 2121 &network_delegate); | |
| 1973 req.Start(); | 2122 req.Start(); |
| 1974 base::RunLoop().Run(); | 2123 base::RunLoop().Run(); |
| 1975 | 2124 |
| 1976 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2125 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 1977 == std::string::npos); | 2126 == std::string::npos); |
| 1978 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2127 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 1979 != std::string::npos); | 2128 != std::string::npos); |
| 1980 | 2129 |
| 1981 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2130 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 1982 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2131 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 1983 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2132 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 1984 } | 2133 } |
| 1985 } | 2134 } |
| 1986 | 2135 |
| 1987 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 2136 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 1988 LocalHttpTestServer test_server; | 2137 LocalHttpTestServer test_server; |
| 1989 ASSERT_TRUE(test_server.Start()); | 2138 ASSERT_TRUE(test_server.Start()); |
| 1990 | 2139 |
| 1991 // Set up a cookie. | 2140 // Set up a cookie. |
| 1992 { | 2141 { |
| 1993 TestNetworkDelegate network_delegate; | 2142 TestNetworkDelegate network_delegate; |
| 1994 default_context_.set_network_delegate(&network_delegate); | 2143 default_context_.set_network_delegate(&network_delegate); |
| 1995 TestDelegate d; | 2144 TestDelegate d; |
| 1996 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2145 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
| 2146 DEFAULT_PRIORITY, | |
| 1997 &d, | 2147 &d, |
| 1998 &default_context_); | 2148 &default_context_, |
| 2149 &network_delegate); | |
| 1999 req.Start(); | 2150 req.Start(); |
| 2000 base::RunLoop().Run(); | 2151 base::RunLoop().Run(); |
| 2001 | 2152 |
| 2002 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2153 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2003 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2154 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2004 } | 2155 } |
| 2005 | 2156 |
| 2006 // Verify that the cookie is set. | 2157 // Verify that the cookie is set. |
| 2007 { | 2158 { |
| 2008 TestNetworkDelegate network_delegate; | 2159 TestNetworkDelegate network_delegate; |
| 2009 default_context_.set_network_delegate(&network_delegate); | 2160 default_context_.set_network_delegate(&network_delegate); |
| 2010 TestDelegate d; | 2161 TestDelegate d; |
| 2011 URLRequest req( | 2162 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2012 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2163 DEFAULT_PRIORITY, |
| 2164 &d, | |
| 2165 &default_context_, | |
| 2166 &network_delegate); | |
| 2013 req.Start(); | 2167 req.Start(); |
| 2014 base::RunLoop().Run(); | 2168 base::RunLoop().Run(); |
| 2015 | 2169 |
| 2016 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2170 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2017 != std::string::npos); | 2171 != std::string::npos); |
| 2018 | 2172 |
| 2019 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2173 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2020 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2174 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2021 } | 2175 } |
| 2022 | 2176 |
| 2023 // Verify that the cookie isn't sent. | 2177 // Verify that the cookie isn't sent. |
| 2024 { | 2178 { |
| 2025 TestNetworkDelegate network_delegate; | 2179 TestNetworkDelegate network_delegate; |
| 2026 default_context_.set_network_delegate(&network_delegate); | 2180 default_context_.set_network_delegate(&network_delegate); |
| 2027 TestDelegate d; | 2181 TestDelegate d; |
| 2028 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2182 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2029 URLRequest req( | 2183 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2030 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2184 DEFAULT_PRIORITY, |
| 2185 &d, | |
| 2186 &default_context_, | |
| 2187 &network_delegate); | |
| 2031 req.Start(); | 2188 req.Start(); |
| 2032 base::RunLoop().Run(); | 2189 base::RunLoop().Run(); |
| 2033 | 2190 |
| 2034 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2191 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2035 == std::string::npos); | 2192 == std::string::npos); |
| 2036 | 2193 |
| 2037 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2194 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2038 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2195 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2039 } | 2196 } |
| 2040 } | 2197 } |
| 2041 | 2198 |
| 2042 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2199 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 2043 LocalHttpTestServer test_server; | 2200 LocalHttpTestServer test_server; |
| 2044 ASSERT_TRUE(test_server.Start()); | 2201 ASSERT_TRUE(test_server.Start()); |
| 2045 | 2202 |
| 2046 // Set up a cookie. | 2203 // Set up a cookie. |
| 2047 { | 2204 { |
| 2048 TestNetworkDelegate network_delegate; | 2205 TestNetworkDelegate network_delegate; |
| 2049 default_context_.set_network_delegate(&network_delegate); | 2206 default_context_.set_network_delegate(&network_delegate); |
| 2050 TestDelegate d; | 2207 TestDelegate d; |
| 2051 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2208 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 2209 DEFAULT_PRIORITY, | |
| 2052 &d, | 2210 &d, |
| 2053 &default_context_); | 2211 &default_context_, |
| 2212 &network_delegate); | |
| 2054 req.Start(); | 2213 req.Start(); |
| 2055 base::RunLoop().Run(); | 2214 base::RunLoop().Run(); |
| 2056 | 2215 |
| 2057 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2216 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2058 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2217 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2059 } | 2218 } |
| 2060 | 2219 |
| 2061 // Try to set-up another cookie and update the previous cookie. | 2220 // Try to set-up another cookie and update the previous cookie. |
| 2062 { | 2221 { |
| 2063 TestNetworkDelegate network_delegate; | 2222 TestNetworkDelegate network_delegate; |
| 2064 default_context_.set_network_delegate(&network_delegate); | 2223 default_context_.set_network_delegate(&network_delegate); |
| 2065 TestDelegate d; | 2224 TestDelegate d; |
| 2066 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2225 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2067 URLRequest req( | 2226 URLRequest req( |
| 2068 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2227 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2228 DEFAULT_PRIORITY, | |
| 2069 &d, | 2229 &d, |
| 2070 &default_context_); | 2230 &default_context_, |
| 2231 &network_delegate); | |
| 2071 req.Start(); | 2232 req.Start(); |
| 2072 | 2233 |
| 2073 base::RunLoop().Run(); | 2234 base::RunLoop().Run(); |
| 2074 | 2235 |
| 2075 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2236 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2076 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2237 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2077 } | 2238 } |
| 2078 | 2239 |
| 2079 // Verify the cookies weren't saved or updated. | 2240 // Verify the cookies weren't saved or updated. |
| 2080 { | 2241 { |
| 2081 TestNetworkDelegate network_delegate; | 2242 TestNetworkDelegate network_delegate; |
| 2082 default_context_.set_network_delegate(&network_delegate); | 2243 default_context_.set_network_delegate(&network_delegate); |
| 2083 TestDelegate d; | 2244 TestDelegate d; |
| 2084 URLRequest req( | 2245 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2085 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2246 DEFAULT_PRIORITY, |
| 2247 &d, | |
| 2248 &default_context_, | |
| 2249 &network_delegate); | |
| 2086 req.Start(); | 2250 req.Start(); |
| 2087 base::RunLoop().Run(); | 2251 base::RunLoop().Run(); |
| 2088 | 2252 |
| 2089 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2253 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2090 == std::string::npos); | 2254 == std::string::npos); |
| 2091 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2255 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2092 != std::string::npos); | 2256 != std::string::npos); |
| 2093 | 2257 |
| 2094 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2258 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2095 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2259 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2096 } | 2260 } |
| 2097 } | 2261 } |
| 2098 | 2262 |
| 2099 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2263 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 2100 LocalHttpTestServer test_server; | 2264 LocalHttpTestServer test_server; |
| 2101 ASSERT_TRUE(test_server.Start()); | 2265 ASSERT_TRUE(test_server.Start()); |
| 2102 | 2266 |
| 2103 // Set up an empty cookie. | 2267 // Set up an empty cookie. |
| 2104 { | 2268 { |
| 2105 TestNetworkDelegate network_delegate; | 2269 TestNetworkDelegate network_delegate; |
| 2106 default_context_.set_network_delegate(&network_delegate); | 2270 default_context_.set_network_delegate(&network_delegate); |
| 2107 TestDelegate d; | 2271 TestDelegate d; |
| 2108 URLRequest req(test_server.GetURL("set-cookie"), &d, &default_context_); | 2272 URLRequest req(test_server.GetURL("set-cookie"), |
| 2273 DEFAULT_PRIORITY, | |
| 2274 &d, | |
| 2275 &default_context_, | |
| 2276 &network_delegate); | |
| 2109 req.Start(); | 2277 req.Start(); |
| 2110 base::RunLoop().Run(); | 2278 base::RunLoop().Run(); |
| 2111 | 2279 |
| 2112 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2280 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2113 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2281 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2114 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2282 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2115 } | 2283 } |
| 2116 } | 2284 } |
| 2117 | 2285 |
| 2118 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 2286 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 2119 LocalHttpTestServer test_server; | 2287 LocalHttpTestServer test_server; |
| 2120 ASSERT_TRUE(test_server.Start()); | 2288 ASSERT_TRUE(test_server.Start()); |
| 2121 | 2289 |
| 2122 // Set up a cookie. | 2290 // Set up a cookie. |
| 2123 { | 2291 { |
| 2124 TestNetworkDelegate network_delegate; | 2292 TestNetworkDelegate network_delegate; |
| 2125 default_context_.set_network_delegate(&network_delegate); | 2293 default_context_.set_network_delegate(&network_delegate); |
| 2126 TestDelegate d; | 2294 TestDelegate d; |
| 2127 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2295 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
| 2296 DEFAULT_PRIORITY, | |
| 2128 &d, | 2297 &d, |
| 2129 &default_context_); | 2298 &default_context_, |
| 2299 &network_delegate); | |
| 2130 req.Start(); | 2300 req.Start(); |
| 2131 base::RunLoop().Run(); | 2301 base::RunLoop().Run(); |
| 2132 | 2302 |
| 2133 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2303 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2134 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2304 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2135 } | 2305 } |
| 2136 | 2306 |
| 2137 // Verify that the cookie is set. | 2307 // Verify that the cookie is set. |
| 2138 { | 2308 { |
| 2139 TestNetworkDelegate network_delegate; | 2309 TestNetworkDelegate network_delegate; |
| 2140 default_context_.set_network_delegate(&network_delegate); | 2310 default_context_.set_network_delegate(&network_delegate); |
| 2141 TestDelegate d; | 2311 TestDelegate d; |
| 2142 URLRequest req( | 2312 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2143 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2313 DEFAULT_PRIORITY, |
| 2314 &d, | |
| 2315 &default_context_, | |
| 2316 &network_delegate); | |
| 2144 req.Start(); | 2317 req.Start(); |
| 2145 base::RunLoop().Run(); | 2318 base::RunLoop().Run(); |
| 2146 | 2319 |
| 2147 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2320 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2148 != std::string::npos); | 2321 != std::string::npos); |
| 2149 | 2322 |
| 2150 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2323 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2151 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2324 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2152 } | 2325 } |
| 2153 | 2326 |
| 2154 // Verify that the cookie isn't sent. | 2327 // Verify that the cookie isn't sent. |
| 2155 { | 2328 { |
| 2156 TestNetworkDelegate network_delegate; | 2329 TestNetworkDelegate network_delegate; |
| 2157 default_context_.set_network_delegate(&network_delegate); | 2330 default_context_.set_network_delegate(&network_delegate); |
| 2158 TestDelegate d; | 2331 TestDelegate d; |
| 2159 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2332 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2160 URLRequest req( | 2333 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2161 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2334 DEFAULT_PRIORITY, |
| 2335 &d, | |
| 2336 &default_context_, | |
| 2337 &network_delegate); | |
| 2162 req.Start(); | 2338 req.Start(); |
| 2163 base::RunLoop().Run(); | 2339 base::RunLoop().Run(); |
| 2164 | 2340 |
| 2165 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2341 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2166 == std::string::npos); | 2342 == std::string::npos); |
| 2167 | 2343 |
| 2168 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2344 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2169 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2345 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2170 } | 2346 } |
| 2171 } | 2347 } |
| 2172 | 2348 |
| 2173 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2349 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 2174 LocalHttpTestServer test_server; | 2350 LocalHttpTestServer test_server; |
| 2175 ASSERT_TRUE(test_server.Start()); | 2351 ASSERT_TRUE(test_server.Start()); |
| 2176 | 2352 |
| 2177 // Set up a cookie. | 2353 // Set up a cookie. |
| 2178 { | 2354 { |
| 2179 TestNetworkDelegate network_delegate; | 2355 TestNetworkDelegate network_delegate; |
| 2180 default_context_.set_network_delegate(&network_delegate); | 2356 default_context_.set_network_delegate(&network_delegate); |
| 2181 TestDelegate d; | 2357 TestDelegate d; |
| 2182 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2358 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
| 2359 DEFAULT_PRIORITY, | |
| 2183 &d, | 2360 &d, |
| 2184 &default_context_); | 2361 &default_context_, |
| 2362 &network_delegate); | |
| 2185 req.Start(); | 2363 req.Start(); |
| 2186 base::RunLoop().Run(); | 2364 base::RunLoop().Run(); |
| 2187 | 2365 |
| 2188 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2366 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2189 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2367 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2190 } | 2368 } |
| 2191 | 2369 |
| 2192 // Try to set-up another cookie and update the previous cookie. | 2370 // Try to set-up another cookie and update the previous cookie. |
| 2193 { | 2371 { |
| 2194 TestNetworkDelegate network_delegate; | 2372 TestNetworkDelegate network_delegate; |
| 2195 default_context_.set_network_delegate(&network_delegate); | 2373 default_context_.set_network_delegate(&network_delegate); |
| 2196 TestDelegate d; | 2374 TestDelegate d; |
| 2197 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2375 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2198 URLRequest req( | 2376 URLRequest req( |
| 2199 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2377 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2378 DEFAULT_PRIORITY, | |
| 2200 &d, | 2379 &d, |
| 2201 &default_context_); | 2380 &default_context_, |
| 2381 &network_delegate); | |
| 2202 req.Start(); | 2382 req.Start(); |
| 2203 | 2383 |
| 2204 base::RunLoop().Run(); | 2384 base::RunLoop().Run(); |
| 2205 | 2385 |
| 2206 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2386 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2207 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2387 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2208 } | 2388 } |
| 2209 | 2389 |
| 2210 // Verify the cookies weren't saved or updated. | 2390 // Verify the cookies weren't saved or updated. |
| 2211 { | 2391 { |
| 2212 TestNetworkDelegate network_delegate; | 2392 TestNetworkDelegate network_delegate; |
| 2213 default_context_.set_network_delegate(&network_delegate); | 2393 default_context_.set_network_delegate(&network_delegate); |
| 2214 TestDelegate d; | 2394 TestDelegate d; |
| 2215 URLRequest req( | 2395 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2216 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2396 DEFAULT_PRIORITY, |
| 2397 &d, | |
| 2398 &default_context_, | |
| 2399 &network_delegate); | |
| 2217 req.Start(); | 2400 req.Start(); |
| 2218 base::RunLoop().Run(); | 2401 base::RunLoop().Run(); |
| 2219 | 2402 |
| 2220 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2403 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2221 == std::string::npos); | 2404 == std::string::npos); |
| 2222 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2405 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2223 != std::string::npos); | 2406 != std::string::npos); |
| 2224 | 2407 |
| 2225 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2408 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2226 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2409 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2272 // headers by defaulting to GMT. (crbug.com/135131) | 2455 // headers by defaulting to GMT. (crbug.com/135131) |
| 2273 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { | 2456 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { |
| 2274 LocalHttpTestServer test_server; | 2457 LocalHttpTestServer test_server; |
| 2275 ASSERT_TRUE(test_server.Start()); | 2458 ASSERT_TRUE(test_server.Start()); |
| 2276 | 2459 |
| 2277 // Set up an expired cookie. | 2460 // Set up an expired cookie. |
| 2278 { | 2461 { |
| 2279 TestNetworkDelegate network_delegate; | 2462 TestNetworkDelegate network_delegate; |
| 2280 default_context_.set_network_delegate(&network_delegate); | 2463 default_context_.set_network_delegate(&network_delegate); |
| 2281 TestDelegate d; | 2464 TestDelegate d; |
| 2282 URLRequest req(test_server.GetURL( | 2465 URLRequest req( |
| 2283 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2466 test_server.GetURL( |
| 2467 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | |
| 2468 DEFAULT_PRIORITY, | |
| 2284 &d, | 2469 &d, |
| 2285 &default_context_); | 2470 &default_context_, |
| 2471 &network_delegate); | |
| 2286 req.Start(); | 2472 req.Start(); |
| 2287 base::RunLoop().Run(); | 2473 base::RunLoop().Run(); |
| 2288 } | 2474 } |
| 2289 // Verify that the cookie is not set. | 2475 // Verify that the cookie is not set. |
| 2290 { | 2476 { |
| 2291 TestNetworkDelegate network_delegate; | 2477 TestNetworkDelegate network_delegate; |
| 2292 default_context_.set_network_delegate(&network_delegate); | 2478 default_context_.set_network_delegate(&network_delegate); |
| 2293 TestDelegate d; | 2479 TestDelegate d; |
| 2294 URLRequest req( | 2480 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2295 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2481 DEFAULT_PRIORITY, |
| 2482 &d, | |
| 2483 &default_context_, | |
| 2484 &network_delegate); | |
| 2296 req.Start(); | 2485 req.Start(); |
| 2297 base::RunLoop().Run(); | 2486 base::RunLoop().Run(); |
| 2298 | 2487 |
| 2299 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | 2488 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); |
| 2300 } | 2489 } |
| 2301 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | 2490 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. |
| 2302 { | 2491 { |
| 2303 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | 2492 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); |
| 2304 default_context_.set_network_delegate(&network_delegate); | 2493 default_context_.set_network_delegate(&network_delegate); |
| 2305 TestDelegate d; | 2494 TestDelegate d; |
| 2306 URLRequest req(test_server.GetURL( | 2495 URLRequest req( |
| 2307 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2496 test_server.GetURL( |
| 2497 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | |
| 2498 DEFAULT_PRIORITY, | |
| 2308 &d, | 2499 &d, |
| 2309 &default_context_); | 2500 &default_context_, |
| 2501 &network_delegate); | |
| 2310 req.Start(); | 2502 req.Start(); |
| 2311 base::RunLoop().Run(); | 2503 base::RunLoop().Run(); |
| 2312 } | 2504 } |
| 2313 // Verify that the cookie is set. | 2505 // Verify that the cookie is set. |
| 2314 { | 2506 { |
| 2315 TestNetworkDelegate network_delegate; | 2507 TestNetworkDelegate network_delegate; |
| 2316 default_context_.set_network_delegate(&network_delegate); | 2508 default_context_.set_network_delegate(&network_delegate); |
| 2317 TestDelegate d; | 2509 TestDelegate d; |
| 2318 URLRequest req( | 2510 URLRequest req(test_server.GetURL("echoheader?Cookie"), |
| 2319 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | 2511 DEFAULT_PRIORITY, |
| 2512 &d, | |
| 2513 &default_context_, | |
| 2514 &network_delegate); | |
| 2320 req.Start(); | 2515 req.Start(); |
| 2321 base::RunLoop().Run(); | 2516 base::RunLoop().Run(); |
| 2322 | 2517 |
| 2323 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 2518 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
| 2324 } | 2519 } |
| 2325 } | 2520 } |
| 2326 | 2521 |
| 2327 | 2522 |
| 2328 // Check that it is impossible to change the referrer in the extra headers of | 2523 // Check that it is impossible to change the referrer in the extra headers of |
| 2329 // an URLRequest. | 2524 // an URLRequest. |
| 2330 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 2525 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 2331 LocalHttpTestServer test_server; | 2526 LocalHttpTestServer test_server; |
| 2332 ASSERT_TRUE(test_server.Start()); | 2527 ASSERT_TRUE(test_server.Start()); |
| 2333 | 2528 |
| 2334 // If extra headers contain referer and the request contains a referer, | 2529 // If extra headers contain referer and the request contains a referer, |
| 2335 // only the latter shall be respected. | 2530 // only the latter shall be respected. |
| 2336 { | 2531 { |
| 2337 TestDelegate d; | 2532 TestDelegate d; |
| 2338 URLRequest req( | 2533 URLRequest req(test_server.GetURL("echoheader?Referer"), |
| 2339 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | 2534 DEFAULT_PRIORITY, |
| 2535 &d, | |
| 2536 &default_context_, | |
| 2537 &default_network_delegate_); | |
| 2340 req.SetReferrer("http://foo.com/"); | 2538 req.SetReferrer("http://foo.com/"); |
| 2341 | 2539 |
| 2342 HttpRequestHeaders headers; | 2540 HttpRequestHeaders headers; |
| 2343 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2541 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 2344 req.SetExtraRequestHeaders(headers); | 2542 req.SetExtraRequestHeaders(headers); |
| 2345 | 2543 |
| 2346 req.Start(); | 2544 req.Start(); |
| 2347 base::RunLoop().Run(); | 2545 base::RunLoop().Run(); |
| 2348 | 2546 |
| 2349 EXPECT_EQ("http://foo.com/", d.data_received()); | 2547 EXPECT_EQ("http://foo.com/", d.data_received()); |
| 2350 } | 2548 } |
| 2351 | 2549 |
| 2352 // If extra headers contain a referer but the request does not, no referer | 2550 // If extra headers contain a referer but the request does not, no referer |
| 2353 // shall be sent in the header. | 2551 // shall be sent in the header. |
| 2354 { | 2552 { |
| 2355 TestDelegate d; | 2553 TestDelegate d; |
| 2356 URLRequest req( | 2554 URLRequest req(test_server.GetURL("echoheader?Referer"), |
| 2357 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | 2555 DEFAULT_PRIORITY, |
| 2556 &d, | |
| 2557 &default_context_, | |
| 2558 &default_network_delegate_); | |
| 2358 | 2559 |
| 2359 HttpRequestHeaders headers; | 2560 HttpRequestHeaders headers; |
| 2360 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2561 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 2361 req.SetExtraRequestHeaders(headers); | 2562 req.SetExtraRequestHeaders(headers); |
| 2362 req.set_load_flags(LOAD_VALIDATE_CACHE); | 2563 req.set_load_flags(LOAD_VALIDATE_CACHE); |
| 2363 | 2564 |
| 2364 req.Start(); | 2565 req.Start(); |
| 2365 base::RunLoop().Run(); | 2566 base::RunLoop().Run(); |
| 2366 | 2567 |
| 2367 EXPECT_EQ("None", d.data_received()); | 2568 EXPECT_EQ("None", d.data_received()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2382 // request, after redirection. | 2583 // request, after redirection. |
| 2383 // If |include_data| is true, data is uploaded with the request. The | 2584 // If |include_data| is true, data is uploaded with the request. The |
| 2384 // response body is expected to match it exactly, if and only if | 2585 // response body is expected to match it exactly, if and only if |
| 2385 // |request_method| == |redirect_method|. | 2586 // |request_method| == |redirect_method|. |
| 2386 void HTTPRedirectMethodTest(const GURL& redirect_url, | 2587 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 2387 const std::string& request_method, | 2588 const std::string& request_method, |
| 2388 const std::string& redirect_method, | 2589 const std::string& redirect_method, |
| 2389 bool include_data) { | 2590 bool include_data) { |
| 2390 static const char kData[] = "hello world"; | 2591 static const char kData[] = "hello world"; |
| 2391 TestDelegate d; | 2592 TestDelegate d; |
| 2392 URLRequest req(redirect_url, &d, &default_context_); | 2593 URLRequest req(redirect_url, |
| 2594 DEFAULT_PRIORITY, | |
| 2595 &d, | |
| 2596 &default_context_, | |
| 2597 &default_network_delegate_); | |
| 2393 req.set_method(request_method); | 2598 req.set_method(request_method); |
| 2394 if (include_data) { | 2599 if (include_data) { |
| 2395 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 2600 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 2396 HttpRequestHeaders headers; | 2601 HttpRequestHeaders headers; |
| 2397 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2602 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 2398 base::UintToString(arraysize(kData) - 1)); | 2603 base::UintToString(arraysize(kData) - 1)); |
| 2399 req.SetExtraRequestHeaders(headers); | 2604 req.SetExtraRequestHeaders(headers); |
| 2400 } | 2605 } |
| 2401 req.Start(); | 2606 req.Start(); |
| 2402 base::RunLoop().Run(); | 2607 base::RunLoop().Run(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2427 ptr--; | 2632 ptr--; |
| 2428 *ptr++ = marker; | 2633 *ptr++ = marker; |
| 2429 if (++marker > 'z') | 2634 if (++marker > 'z') |
| 2430 marker = 'a'; | 2635 marker = 'a'; |
| 2431 } | 2636 } |
| 2432 } | 2637 } |
| 2433 uploadBytes[kMsgSize] = '\0'; | 2638 uploadBytes[kMsgSize] = '\0'; |
| 2434 | 2639 |
| 2435 for (int i = 0; i < kIterations; ++i) { | 2640 for (int i = 0; i < kIterations; ++i) { |
| 2436 TestDelegate d; | 2641 TestDelegate d; |
| 2437 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 2642 URLRequest r(test_server_.GetURL("echo"), |
| 2643 DEFAULT_PRIORITY, | |
| 2644 &d, | |
| 2645 &default_context_, | |
| 2646 &default_network_delegate_); | |
| 2438 r.set_method(method.c_str()); | 2647 r.set_method(method.c_str()); |
| 2439 | 2648 |
| 2440 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); | 2649 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); |
| 2441 | 2650 |
| 2442 r.Start(); | 2651 r.Start(); |
| 2443 EXPECT_TRUE(r.is_pending()); | 2652 EXPECT_TRUE(r.is_pending()); |
| 2444 | 2653 |
| 2445 base::RunLoop().Run(); | 2654 base::RunLoop().Run(); |
| 2446 | 2655 |
| 2447 ASSERT_EQ(1, d.response_started_count()) | 2656 ASSERT_EQ(1, d.response_started_count()) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2475 EXPECT_FALSE(d->received_data_before_response()); | 2684 EXPECT_FALSE(d->received_data_before_response()); |
| 2476 | 2685 |
| 2477 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); | 2686 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); |
| 2478 EXPECT_EQ(expected_data, d->data_received()); | 2687 EXPECT_EQ(expected_data, d->data_received()); |
| 2479 } | 2688 } |
| 2480 | 2689 |
| 2481 bool DoManyCookiesRequest(int num_cookies) { | 2690 bool DoManyCookiesRequest(int num_cookies) { |
| 2482 TestDelegate d; | 2691 TestDelegate d; |
| 2483 URLRequest r(test_server_.GetURL("set-many-cookies?" + | 2692 URLRequest r(test_server_.GetURL("set-many-cookies?" + |
| 2484 base::IntToString(num_cookies)), | 2693 base::IntToString(num_cookies)), |
| 2485 &d, | 2694 DEFAULT_PRIORITY, |
| 2486 &default_context_); | 2695 &d, |
| 2696 &default_context_, | |
| 2697 &default_network_delegate_); | |
| 2487 | 2698 |
| 2488 r.Start(); | 2699 r.Start(); |
| 2489 EXPECT_TRUE(r.is_pending()); | 2700 EXPECT_TRUE(r.is_pending()); |
| 2490 | 2701 |
| 2491 base::RunLoop().Run(); | 2702 base::RunLoop().Run(); |
| 2492 | 2703 |
| 2493 bool is_success = r.status().is_success(); | 2704 bool is_success = r.status().is_success(); |
| 2494 | 2705 |
| 2495 if (!is_success) { | 2706 if (!is_success) { |
| 2496 // Requests handled by ChromeFrame send a less precise error message, | 2707 // Requests handled by ChromeFrame send a less precise error message, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2516 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 2727 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 2517 ASSERT_TRUE(test_server_.Start()); | 2728 ASSERT_TRUE(test_server_.Start()); |
| 2518 | 2729 |
| 2519 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2730 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 2520 TestURLRequestContextWithProxy context( | 2731 TestURLRequestContextWithProxy context( |
| 2521 test_server_.host_port_pair().ToString(), | 2732 test_server_.host_port_pair().ToString(), |
| 2522 &network_delegate); | 2733 &network_delegate); |
| 2523 | 2734 |
| 2524 TestDelegate d; | 2735 TestDelegate d; |
| 2525 { | 2736 { |
| 2526 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); | 2737 URLRequest r(GURL("https://www.redirect.com/"), |
| 2738 DEFAULT_PRIORITY, | |
| 2739 &d, | |
| 2740 &context, | |
| 2741 &network_delegate); | |
| 2527 r.Start(); | 2742 r.Start(); |
| 2528 EXPECT_TRUE(r.is_pending()); | 2743 EXPECT_TRUE(r.is_pending()); |
| 2529 | 2744 |
| 2530 base::RunLoop().Run(); | 2745 base::RunLoop().Run(); |
| 2531 | 2746 |
| 2532 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2747 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2533 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2748 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 2534 EXPECT_EQ(1, d.response_started_count()); | 2749 EXPECT_EQ(1, d.response_started_count()); |
| 2535 // We should not have followed the redirect. | 2750 // We should not have followed the redirect. |
| 2536 EXPECT_EQ(0, d.received_redirect_count()); | 2751 EXPECT_EQ(0, d.received_redirect_count()); |
| 2537 } | 2752 } |
| 2538 } | 2753 } |
| 2539 | 2754 |
| 2540 // This is the same as the previous test, but checks that the network delegate | 2755 // This is the same as the previous test, but checks that the network delegate |
| 2541 // registers the error. | 2756 // registers the error. |
| 2542 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 2757 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 2543 ASSERT_TRUE(test_server_.Start()); | 2758 ASSERT_TRUE(test_server_.Start()); |
| 2544 | 2759 |
| 2545 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2760 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 2546 TestURLRequestContextWithProxy context( | 2761 TestURLRequestContextWithProxy context( |
| 2547 test_server_.host_port_pair().ToString(), | 2762 test_server_.host_port_pair().ToString(), |
| 2548 &network_delegate); | 2763 &network_delegate); |
| 2549 | 2764 |
| 2550 TestDelegate d; | 2765 TestDelegate d; |
| 2551 { | 2766 { |
| 2552 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); | 2767 URLRequest r(GURL("https://www.redirect.com/"), |
| 2768 DEFAULT_PRIORITY, | |
| 2769 &d, | |
| 2770 &context, | |
| 2771 &network_delegate); | |
| 2553 r.Start(); | 2772 r.Start(); |
| 2554 EXPECT_TRUE(r.is_pending()); | 2773 EXPECT_TRUE(r.is_pending()); |
| 2555 | 2774 |
| 2556 base::RunLoop().Run(); | 2775 base::RunLoop().Run(); |
| 2557 | 2776 |
| 2558 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2777 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2559 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2778 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 2560 EXPECT_EQ(1, d.response_started_count()); | 2779 EXPECT_EQ(1, d.response_started_count()); |
| 2561 // We should not have followed the redirect. | 2780 // We should not have followed the redirect. |
| 2562 EXPECT_EQ(0, d.received_redirect_count()); | 2781 EXPECT_EQ(0, d.received_redirect_count()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2583 network_delegate.set_block_on( | 2802 network_delegate.set_block_on( |
| 2584 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | | 2803 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | |
| 2585 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | | 2804 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | |
| 2586 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 2805 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 2587 | 2806 |
| 2588 TestURLRequestContext context(true); | 2807 TestURLRequestContext context(true); |
| 2589 context.set_network_delegate(&network_delegate); | 2808 context.set_network_delegate(&network_delegate); |
| 2590 context.Init(); | 2809 context.Init(); |
| 2591 | 2810 |
| 2592 { | 2811 { |
| 2593 URLRequest r(test_server_.GetURL("empty.html"), &d, &context); | 2812 URLRequest r(test_server_.GetURL("empty.html"), |
| 2813 DEFAULT_PRIORITY, | |
| 2814 &d, | |
| 2815 &context, | |
| 2816 &network_delegate); | |
| 2594 | 2817 |
| 2595 r.Start(); | 2818 r.Start(); |
| 2596 for (size_t i = 0; i < blocking_stages_length; ++i) { | 2819 for (size_t i = 0; i < blocking_stages_length; ++i) { |
| 2597 base::RunLoop().Run(); | 2820 base::RunLoop().Run(); |
| 2598 EXPECT_EQ(blocking_stages[i], | 2821 EXPECT_EQ(blocking_stages[i], |
| 2599 network_delegate.stage_blocked_for_callback()); | 2822 network_delegate.stage_blocked_for_callback()); |
| 2600 network_delegate.DoCallback(OK); | 2823 network_delegate.DoCallback(OK); |
| 2601 } | 2824 } |
| 2602 base::RunLoop().Run(); | 2825 base::RunLoop().Run(); |
| 2603 EXPECT_EQ(200, r.GetResponseCode()); | 2826 EXPECT_EQ(200, r.GetResponseCode()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2616 BlockingNetworkDelegate network_delegate( | 2839 BlockingNetworkDelegate network_delegate( |
| 2617 BlockingNetworkDelegate::AUTO_CALLBACK); | 2840 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 2618 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2841 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2619 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 2842 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 2620 | 2843 |
| 2621 TestURLRequestContextWithProxy context( | 2844 TestURLRequestContextWithProxy context( |
| 2622 test_server_.host_port_pair().ToString(), | 2845 test_server_.host_port_pair().ToString(), |
| 2623 &network_delegate); | 2846 &network_delegate); |
| 2624 | 2847 |
| 2625 { | 2848 { |
| 2626 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 2849 URLRequest r(test_server_.GetURL(std::string()), |
| 2850 DEFAULT_PRIORITY, | |
| 2851 &d, | |
| 2852 &context, | |
| 2853 &network_delegate); | |
| 2627 | 2854 |
| 2628 r.Start(); | 2855 r.Start(); |
| 2629 base::RunLoop().Run(); | 2856 base::RunLoop().Run(); |
| 2630 | 2857 |
| 2631 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2858 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2632 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 2859 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 2633 EXPECT_EQ(1, network_delegate.created_requests()); | 2860 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2634 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2861 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2635 } | 2862 } |
| 2636 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2863 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2637 } | 2864 } |
| 2638 | 2865 |
| 2639 // Helper function for NetworkDelegateCancelRequestAsynchronously and | 2866 // Helper function for NetworkDelegateCancelRequestAsynchronously and |
| 2640 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network | 2867 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network |
| 2641 // delegate operating in |block_mode| and a request for |url|. It blocks the | 2868 // delegate operating in |block_mode| and a request for |url|. It blocks the |
| 2642 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. | 2869 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. |
| 2643 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, | 2870 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, |
| 2644 BlockingNetworkDelegate::Stage stage, | 2871 BlockingNetworkDelegate::Stage stage, |
| 2645 const GURL& url) { | 2872 const GURL& url) { |
| 2646 TestDelegate d; | 2873 TestDelegate d; |
| 2647 BlockingNetworkDelegate network_delegate(block_mode); | 2874 BlockingNetworkDelegate network_delegate(block_mode); |
| 2648 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); | 2875 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); |
| 2649 network_delegate.set_block_on(stage); | 2876 network_delegate.set_block_on(stage); |
| 2650 | 2877 |
| 2651 TestURLRequestContext context(true); | 2878 TestURLRequestContext context(true); |
| 2652 context.set_network_delegate(&network_delegate); | 2879 context.set_network_delegate(&network_delegate); |
| 2653 context.Init(); | 2880 context.Init(); |
| 2654 | 2881 |
| 2655 { | 2882 { |
| 2656 URLRequest r(url, &d, &context); | 2883 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2657 | 2884 |
| 2658 r.Start(); | 2885 r.Start(); |
| 2659 base::RunLoop().Run(); | 2886 base::RunLoop().Run(); |
| 2660 | 2887 |
| 2661 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2888 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 2662 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); | 2889 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); |
| 2663 EXPECT_EQ(1, network_delegate.created_requests()); | 2890 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2664 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2891 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2665 } | 2892 } |
| 2666 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2893 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2723 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2950 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2724 GURL redirect_url(test_server_.GetURL("simple.html")); | 2951 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 2725 network_delegate.set_redirect_url(redirect_url); | 2952 network_delegate.set_redirect_url(redirect_url); |
| 2726 | 2953 |
| 2727 TestURLRequestContextWithProxy context( | 2954 TestURLRequestContextWithProxy context( |
| 2728 test_server_.host_port_pair().ToString(), | 2955 test_server_.host_port_pair().ToString(), |
| 2729 &network_delegate); | 2956 &network_delegate); |
| 2730 | 2957 |
| 2731 { | 2958 { |
| 2732 GURL original_url(test_server_.GetURL("empty.html")); | 2959 GURL original_url(test_server_.GetURL("empty.html")); |
| 2733 URLRequest r(original_url, &d, &context); | 2960 URLRequest r( |
| 2961 original_url, DEFAULT_PRIORITY, &d, &context, &network_delegate); | |
| 2734 | 2962 |
| 2735 r.Start(); | 2963 r.Start(); |
| 2736 base::RunLoop().Run(); | 2964 base::RunLoop().Run(); |
| 2737 | 2965 |
| 2738 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2966 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2739 EXPECT_EQ(0, r.status().error()); | 2967 EXPECT_EQ(0, r.status().error()); |
| 2740 EXPECT_EQ(redirect_url, r.url()); | 2968 EXPECT_EQ(redirect_url, r.url()); |
| 2741 EXPECT_EQ(original_url, r.original_url()); | 2969 EXPECT_EQ(original_url, r.original_url()); |
| 2742 EXPECT_EQ(2U, r.url_chain().size()); | 2970 EXPECT_EQ(2U, r.url_chain().size()); |
| 2743 EXPECT_EQ(1, network_delegate.created_requests()); | 2971 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2756 BlockingNetworkDelegate::SYNCHRONOUS); | 2984 BlockingNetworkDelegate::SYNCHRONOUS); |
| 2757 GURL redirect_url(test_server_.GetURL("simple.html")); | 2985 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 2758 network_delegate.set_redirect_url(redirect_url); | 2986 network_delegate.set_redirect_url(redirect_url); |
| 2759 | 2987 |
| 2760 TestURLRequestContextWithProxy context( | 2988 TestURLRequestContextWithProxy context( |
| 2761 test_server_.host_port_pair().ToString(), | 2989 test_server_.host_port_pair().ToString(), |
| 2762 &network_delegate); | 2990 &network_delegate); |
| 2763 | 2991 |
| 2764 { | 2992 { |
| 2765 GURL original_url(test_server_.GetURL("empty.html")); | 2993 GURL original_url(test_server_.GetURL("empty.html")); |
| 2766 URLRequest r(original_url, &d, &context); | 2994 URLRequest r( |
| 2995 original_url, DEFAULT_PRIORITY, &d, &context, &network_delegate); | |
| 2767 | 2996 |
| 2768 r.Start(); | 2997 r.Start(); |
| 2769 base::RunLoop().Run(); | 2998 base::RunLoop().Run(); |
| 2770 | 2999 |
| 2771 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3000 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2772 EXPECT_EQ(0, r.status().error()); | 3001 EXPECT_EQ(0, r.status().error()); |
| 2773 EXPECT_EQ(redirect_url, r.url()); | 3002 EXPECT_EQ(redirect_url, r.url()); |
| 2774 EXPECT_EQ(original_url, r.original_url()); | 3003 EXPECT_EQ(original_url, r.original_url()); |
| 2775 EXPECT_EQ(2U, r.url_chain().size()); | 3004 EXPECT_EQ(2U, r.url_chain().size()); |
| 2776 EXPECT_EQ(1, network_delegate.created_requests()); | 3005 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2791 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3020 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2792 GURL redirect_url(test_server_.GetURL("echo")); | 3021 GURL redirect_url(test_server_.GetURL("echo")); |
| 2793 network_delegate.set_redirect_url(redirect_url); | 3022 network_delegate.set_redirect_url(redirect_url); |
| 2794 | 3023 |
| 2795 TestURLRequestContext context(true); | 3024 TestURLRequestContext context(true); |
| 2796 context.set_network_delegate(&network_delegate); | 3025 context.set_network_delegate(&network_delegate); |
| 2797 context.Init(); | 3026 context.Init(); |
| 2798 | 3027 |
| 2799 { | 3028 { |
| 2800 GURL original_url(test_server_.GetURL("empty.html")); | 3029 GURL original_url(test_server_.GetURL("empty.html")); |
| 2801 URLRequest r(original_url, &d, &context); | 3030 URLRequest r( |
| 3031 original_url, DEFAULT_PRIORITY, &d, &context, &network_delegate); | |
| 2802 r.set_method("POST"); | 3032 r.set_method("POST"); |
| 2803 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 3033 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 2804 HttpRequestHeaders headers; | 3034 HttpRequestHeaders headers; |
| 2805 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3035 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 2806 base::UintToString(arraysize(kData) - 1)); | 3036 base::UintToString(arraysize(kData) - 1)); |
| 2807 r.SetExtraRequestHeaders(headers); | 3037 r.SetExtraRequestHeaders(headers); |
| 2808 r.Start(); | 3038 r.Start(); |
| 2809 base::RunLoop().Run(); | 3039 base::RunLoop().Run(); |
| 2810 | 3040 |
| 2811 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3041 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2833 BlockingNetworkDelegate::SYNCHRONOUS); | 3063 BlockingNetworkDelegate::SYNCHRONOUS); |
| 2834 | 3064 |
| 2835 TestURLRequestContext context(true); | 3065 TestURLRequestContext context(true); |
| 2836 context.set_network_delegate(&network_delegate); | 3066 context.set_network_delegate(&network_delegate); |
| 2837 context.Init(); | 3067 context.Init(); |
| 2838 | 3068 |
| 2839 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3069 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 2840 | 3070 |
| 2841 { | 3071 { |
| 2842 GURL url(test_server_.GetURL("auth-basic")); | 3072 GURL url(test_server_.GetURL("auth-basic")); |
| 2843 URLRequest r(url, &d, &context); | 3073 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2844 r.Start(); | 3074 r.Start(); |
| 2845 | 3075 |
| 2846 base::RunLoop().Run(); | 3076 base::RunLoop().Run(); |
| 2847 | 3077 |
| 2848 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3078 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2849 EXPECT_EQ(0, r.status().error()); | 3079 EXPECT_EQ(0, r.status().error()); |
| 2850 EXPECT_EQ(200, r.GetResponseCode()); | 3080 EXPECT_EQ(200, r.GetResponseCode()); |
| 2851 EXPECT_TRUE(d.auth_required_called()); | 3081 EXPECT_TRUE(d.auth_required_called()); |
| 2852 EXPECT_EQ(1, network_delegate.created_requests()); | 3082 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2853 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3083 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2864 BlockingNetworkDelegate::SYNCHRONOUS); | 3094 BlockingNetworkDelegate::SYNCHRONOUS); |
| 2865 | 3095 |
| 2866 TestURLRequestContext context(true); | 3096 TestURLRequestContext context(true); |
| 2867 context.set_network_delegate(&network_delegate); | 3097 context.set_network_delegate(&network_delegate); |
| 2868 context.Init(); | 3098 context.Init(); |
| 2869 | 3099 |
| 2870 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3100 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 2871 | 3101 |
| 2872 { | 3102 { |
| 2873 GURL url(test_server_.GetURL("auth-basic")); | 3103 GURL url(test_server_.GetURL("auth-basic")); |
| 2874 URLRequest r(url, &d, &context); | 3104 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2875 r.Start(); | 3105 r.Start(); |
| 2876 | 3106 |
| 2877 { | 3107 { |
| 2878 HttpRequestHeaders headers; | 3108 HttpRequestHeaders headers; |
| 2879 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); | 3109 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); |
| 2880 EXPECT_FALSE(headers.HasHeader("Authorization")); | 3110 EXPECT_FALSE(headers.HasHeader("Authorization")); |
| 2881 } | 3111 } |
| 2882 | 3112 |
| 2883 base::RunLoop().Run(); | 3113 base::RunLoop().Run(); |
| 2884 | 3114 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2905 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3135 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 2906 | 3136 |
| 2907 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3137 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 2908 | 3138 |
| 2909 TestURLRequestContext context(true); | 3139 TestURLRequestContext context(true); |
| 2910 context.set_network_delegate(&network_delegate); | 3140 context.set_network_delegate(&network_delegate); |
| 2911 context.Init(); | 3141 context.Init(); |
| 2912 | 3142 |
| 2913 { | 3143 { |
| 2914 GURL url(test_server_.GetURL("auth-basic")); | 3144 GURL url(test_server_.GetURL("auth-basic")); |
| 2915 URLRequest r(url, &d, &context); | 3145 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2916 r.Start(); | 3146 r.Start(); |
| 2917 base::RunLoop().Run(); | 3147 base::RunLoop().Run(); |
| 2918 | 3148 |
| 2919 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3149 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2920 EXPECT_EQ(0, r.status().error()); | 3150 EXPECT_EQ(0, r.status().error()); |
| 2921 EXPECT_EQ(200, r.GetResponseCode()); | 3151 EXPECT_EQ(200, r.GetResponseCode()); |
| 2922 EXPECT_FALSE(d.auth_required_called()); | 3152 EXPECT_FALSE(d.auth_required_called()); |
| 2923 EXPECT_EQ(1, network_delegate.created_requests()); | 3153 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2924 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3154 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2925 } | 3155 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2940 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3170 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 2941 | 3171 |
| 2942 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3172 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 2943 | 3173 |
| 2944 TestURLRequestContext context(true); | 3174 TestURLRequestContext context(true); |
| 2945 context.set_network_delegate(&network_delegate); | 3175 context.set_network_delegate(&network_delegate); |
| 2946 context.Init(); | 3176 context.Init(); |
| 2947 | 3177 |
| 2948 { | 3178 { |
| 2949 GURL url(test_server_.GetURL("auth-basic")); | 3179 GURL url(test_server_.GetURL("auth-basic")); |
| 2950 URLRequest r(url, &d, &context); | 3180 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2951 r.Start(); | 3181 r.Start(); |
| 2952 base::RunLoop().Run(); | 3182 base::RunLoop().Run(); |
| 2953 | 3183 |
| 2954 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3184 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2955 EXPECT_EQ(0, r.status().error()); | 3185 EXPECT_EQ(0, r.status().error()); |
| 2956 EXPECT_EQ(200, r.GetResponseCode()); | 3186 EXPECT_EQ(200, r.GetResponseCode()); |
| 2957 EXPECT_FALSE(d.auth_required_called()); | 3187 EXPECT_FALSE(d.auth_required_called()); |
| 2958 EXPECT_EQ(1, network_delegate.created_requests()); | 3188 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2959 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3189 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2960 | 3190 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2978 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3208 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 2979 network_delegate.set_auth_retval( | 3209 network_delegate.set_auth_retval( |
| 2980 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3210 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 2981 | 3211 |
| 2982 TestURLRequestContext context(true); | 3212 TestURLRequestContext context(true); |
| 2983 context.set_network_delegate(&network_delegate); | 3213 context.set_network_delegate(&network_delegate); |
| 2984 context.Init(); | 3214 context.Init(); |
| 2985 | 3215 |
| 2986 { | 3216 { |
| 2987 GURL url(test_server_.GetURL("auth-basic")); | 3217 GURL url(test_server_.GetURL("auth-basic")); |
| 2988 URLRequest r(url, &d, &context); | 3218 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 2989 r.Start(); | 3219 r.Start(); |
| 2990 base::RunLoop().Run(); | 3220 base::RunLoop().Run(); |
| 2991 | 3221 |
| 2992 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3222 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2993 EXPECT_EQ(OK, r.status().error()); | 3223 EXPECT_EQ(OK, r.status().error()); |
| 2994 EXPECT_EQ(401, r.GetResponseCode()); | 3224 EXPECT_EQ(401, r.GetResponseCode()); |
| 2995 EXPECT_FALSE(d.auth_required_called()); | 3225 EXPECT_FALSE(d.auth_required_called()); |
| 2996 EXPECT_EQ(1, network_delegate.created_requests()); | 3226 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2997 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3227 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2998 } | 3228 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3012 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3242 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3013 | 3243 |
| 3014 TestURLRequestContext context(true); | 3244 TestURLRequestContext context(true); |
| 3015 context.set_network_delegate(&network_delegate); | 3245 context.set_network_delegate(&network_delegate); |
| 3016 context.Init(); | 3246 context.Init(); |
| 3017 | 3247 |
| 3018 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3248 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3019 | 3249 |
| 3020 { | 3250 { |
| 3021 GURL url(test_server_.GetURL("auth-basic")); | 3251 GURL url(test_server_.GetURL("auth-basic")); |
| 3022 URLRequest r(url, &d, &context); | 3252 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 3023 r.Start(); | 3253 r.Start(); |
| 3024 base::RunLoop().Run(); | 3254 base::RunLoop().Run(); |
| 3025 | 3255 |
| 3026 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3256 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 3027 EXPECT_EQ(0, r.status().error()); | 3257 EXPECT_EQ(0, r.status().error()); |
| 3028 EXPECT_EQ(200, r.GetResponseCode()); | 3258 EXPECT_EQ(200, r.GetResponseCode()); |
| 3029 EXPECT_TRUE(d.auth_required_called()); | 3259 EXPECT_TRUE(d.auth_required_called()); |
| 3030 EXPECT_EQ(1, network_delegate.created_requests()); | 3260 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3031 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3261 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3032 } | 3262 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3047 | 3277 |
| 3048 AuthCredentials auth_credentials(kUser, kSecret); | 3278 AuthCredentials auth_credentials(kUser, kSecret); |
| 3049 network_delegate.set_auth_credentials(auth_credentials); | 3279 network_delegate.set_auth_credentials(auth_credentials); |
| 3050 | 3280 |
| 3051 TestURLRequestContext context(true); | 3281 TestURLRequestContext context(true); |
| 3052 context.set_network_delegate(&network_delegate); | 3282 context.set_network_delegate(&network_delegate); |
| 3053 context.Init(); | 3283 context.Init(); |
| 3054 | 3284 |
| 3055 { | 3285 { |
| 3056 GURL url(test_server_.GetURL("auth-basic")); | 3286 GURL url(test_server_.GetURL("auth-basic")); |
| 3057 URLRequest r(url, &d, &context); | 3287 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 3058 r.Start(); | 3288 r.Start(); |
| 3059 base::RunLoop().Run(); | 3289 base::RunLoop().Run(); |
| 3060 | 3290 |
| 3061 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3291 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 3062 EXPECT_EQ(0, r.status().error()); | 3292 EXPECT_EQ(0, r.status().error()); |
| 3063 | 3293 |
| 3064 EXPECT_EQ(200, r.GetResponseCode()); | 3294 EXPECT_EQ(200, r.GetResponseCode()); |
| 3065 EXPECT_FALSE(d.auth_required_called()); | 3295 EXPECT_FALSE(d.auth_required_called()); |
| 3066 EXPECT_EQ(1, network_delegate.created_requests()); | 3296 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3067 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3297 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3080 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3310 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3081 network_delegate.set_auth_retval( | 3311 network_delegate.set_auth_retval( |
| 3082 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3312 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 3083 | 3313 |
| 3084 TestURLRequestContext context(true); | 3314 TestURLRequestContext context(true); |
| 3085 context.set_network_delegate(&network_delegate); | 3315 context.set_network_delegate(&network_delegate); |
| 3086 context.Init(); | 3316 context.Init(); |
| 3087 | 3317 |
| 3088 { | 3318 { |
| 3089 GURL url(test_server_.GetURL("auth-basic")); | 3319 GURL url(test_server_.GetURL("auth-basic")); |
| 3090 URLRequest r(url, &d, &context); | 3320 URLRequest r(url, DEFAULT_PRIORITY, &d, &context, &network_delegate); |
| 3091 r.Start(); | 3321 r.Start(); |
| 3092 base::RunLoop().Run(); | 3322 base::RunLoop().Run(); |
| 3093 | 3323 |
| 3094 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3324 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 3095 EXPECT_EQ(OK, r.status().error()); | 3325 EXPECT_EQ(OK, r.status().error()); |
| 3096 EXPECT_EQ(401, r.GetResponseCode()); | 3326 EXPECT_EQ(401, r.GetResponseCode()); |
| 3097 EXPECT_FALSE(d.auth_required_called()); | 3327 EXPECT_FALSE(d.auth_required_called()); |
| 3098 EXPECT_EQ(1, network_delegate.created_requests()); | 3328 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3099 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3329 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3100 } | 3330 } |
| 3101 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3331 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3102 } | 3332 } |
| 3103 | 3333 |
| 3104 // Tests that we can handle when a network request was canceled while we were | 3334 // Tests that we can handle when a network request was canceled while we were |
| 3105 // waiting for the network delegate. | 3335 // waiting for the network delegate. |
| 3106 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 3336 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
| 3107 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 3337 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
| 3108 ASSERT_TRUE(test_server_.Start()); | 3338 ASSERT_TRUE(test_server_.Start()); |
| 3109 | 3339 |
| 3110 TestDelegate d; | 3340 TestDelegate d; |
| 3111 BlockingNetworkDelegate network_delegate( | 3341 BlockingNetworkDelegate network_delegate( |
| 3112 BlockingNetworkDelegate::USER_CALLBACK); | 3342 BlockingNetworkDelegate::USER_CALLBACK); |
| 3113 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3343 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3114 | 3344 |
| 3115 TestURLRequestContext context(true); | 3345 TestURLRequestContext context(true); |
| 3116 context.set_network_delegate(&network_delegate); | 3346 context.set_network_delegate(&network_delegate); |
| 3117 context.Init(); | 3347 context.Init(); |
| 3118 | 3348 |
| 3119 { | 3349 { |
| 3120 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3350 URLRequest r(test_server_.GetURL(std::string()), |
| 3351 DEFAULT_PRIORITY, | |
| 3352 &d, | |
| 3353 &context, | |
| 3354 &network_delegate); | |
| 3121 | 3355 |
| 3122 r.Start(); | 3356 r.Start(); |
| 3123 base::RunLoop().Run(); | 3357 base::RunLoop().Run(); |
| 3124 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3358 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 3125 network_delegate.stage_blocked_for_callback()); | 3359 network_delegate.stage_blocked_for_callback()); |
| 3126 EXPECT_EQ(0, network_delegate.completed_requests()); | 3360 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3127 // Cancel before callback. | 3361 // Cancel before callback. |
| 3128 r.Cancel(); | 3362 r.Cancel(); |
| 3129 // Ensure that network delegate is notified. | 3363 // Ensure that network delegate is notified. |
| 3130 EXPECT_EQ(1, network_delegate.completed_requests()); | 3364 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3146 BlockingNetworkDelegate network_delegate( | 3380 BlockingNetworkDelegate network_delegate( |
| 3147 BlockingNetworkDelegate::USER_CALLBACK); | 3381 BlockingNetworkDelegate::USER_CALLBACK); |
| 3148 network_delegate.set_block_on( | 3382 network_delegate.set_block_on( |
| 3149 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); | 3383 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); |
| 3150 | 3384 |
| 3151 TestURLRequestContext context(true); | 3385 TestURLRequestContext context(true); |
| 3152 context.set_network_delegate(&network_delegate); | 3386 context.set_network_delegate(&network_delegate); |
| 3153 context.Init(); | 3387 context.Init(); |
| 3154 | 3388 |
| 3155 { | 3389 { |
| 3156 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3390 URLRequest r(test_server_.GetURL(std::string()), |
| 3391 DEFAULT_PRIORITY, | |
| 3392 &d, | |
| 3393 &context, | |
| 3394 &network_delegate); | |
| 3157 | 3395 |
| 3158 r.Start(); | 3396 r.Start(); |
| 3159 base::RunLoop().Run(); | 3397 base::RunLoop().Run(); |
| 3160 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3398 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 3161 network_delegate.stage_blocked_for_callback()); | 3399 network_delegate.stage_blocked_for_callback()); |
| 3162 EXPECT_EQ(0, network_delegate.completed_requests()); | 3400 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3163 // Cancel before callback. | 3401 // Cancel before callback. |
| 3164 r.Cancel(); | 3402 r.Cancel(); |
| 3165 // Ensure that network delegate is notified. | 3403 // Ensure that network delegate is notified. |
| 3166 EXPECT_EQ(1, network_delegate.completed_requests()); | 3404 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3181 TestDelegate d; | 3419 TestDelegate d; |
| 3182 BlockingNetworkDelegate network_delegate( | 3420 BlockingNetworkDelegate network_delegate( |
| 3183 BlockingNetworkDelegate::USER_CALLBACK); | 3421 BlockingNetworkDelegate::USER_CALLBACK); |
| 3184 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3422 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3185 | 3423 |
| 3186 TestURLRequestContext context(true); | 3424 TestURLRequestContext context(true); |
| 3187 context.set_network_delegate(&network_delegate); | 3425 context.set_network_delegate(&network_delegate); |
| 3188 context.Init(); | 3426 context.Init(); |
| 3189 | 3427 |
| 3190 { | 3428 { |
| 3191 URLRequest r(test_server_.GetURL(std::string()), &d, &context); | 3429 URLRequest r(test_server_.GetURL(std::string()), |
| 3430 DEFAULT_PRIORITY, | |
| 3431 &d, | |
| 3432 &context, | |
| 3433 &network_delegate); | |
| 3192 | 3434 |
| 3193 r.Start(); | 3435 r.Start(); |
| 3194 base::RunLoop().Run(); | 3436 base::RunLoop().Run(); |
| 3195 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 3437 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 3196 network_delegate.stage_blocked_for_callback()); | 3438 network_delegate.stage_blocked_for_callback()); |
| 3197 EXPECT_EQ(0, network_delegate.completed_requests()); | 3439 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3198 // Cancel before callback. | 3440 // Cancel before callback. |
| 3199 r.Cancel(); | 3441 r.Cancel(); |
| 3200 // Ensure that network delegate is notified. | 3442 // Ensure that network delegate is notified. |
| 3201 EXPECT_EQ(1, network_delegate.completed_requests()); | 3443 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3216 TestDelegate d; | 3458 TestDelegate d; |
| 3217 BlockingNetworkDelegate network_delegate( | 3459 BlockingNetworkDelegate network_delegate( |
| 3218 BlockingNetworkDelegate::USER_CALLBACK); | 3460 BlockingNetworkDelegate::USER_CALLBACK); |
| 3219 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3461 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3220 | 3462 |
| 3221 TestURLRequestContext context(true); | 3463 TestURLRequestContext context(true); |
| 3222 context.set_network_delegate(&network_delegate); | 3464 context.set_network_delegate(&network_delegate); |
| 3223 context.Init(); | 3465 context.Init(); |
| 3224 | 3466 |
| 3225 { | 3467 { |
| 3226 URLRequest r(test_server_.GetURL("auth-basic"), &d, &context); | 3468 URLRequest r(test_server_.GetURL("auth-basic"), |
| 3469 DEFAULT_PRIORITY, | |
| 3470 &d, | |
| 3471 &context, | |
| 3472 &network_delegate); | |
| 3227 | 3473 |
| 3228 r.Start(); | 3474 r.Start(); |
| 3229 base::RunLoop().Run(); | 3475 base::RunLoop().Run(); |
| 3230 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, | 3476 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, |
| 3231 network_delegate.stage_blocked_for_callback()); | 3477 network_delegate.stage_blocked_for_callback()); |
| 3232 EXPECT_EQ(0, network_delegate.completed_requests()); | 3478 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3233 // Cancel before callback. | 3479 // Cancel before callback. |
| 3234 r.Cancel(); | 3480 r.Cancel(); |
| 3235 // Ensure that network delegate is notified. | 3481 // Ensure that network delegate is notified. |
| 3236 EXPECT_EQ(1, network_delegate.completed_requests()); | 3482 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 3248 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 3494 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 3249 ASSERT_TRUE(test_server_.Start()); | 3495 ASSERT_TRUE(test_server_.Start()); |
| 3250 | 3496 |
| 3251 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3497 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3252 TestURLRequestContextWithProxy context( | 3498 TestURLRequestContextWithProxy context( |
| 3253 test_server_.host_port_pair().ToString(), | 3499 test_server_.host_port_pair().ToString(), |
| 3254 &network_delegate); | 3500 &network_delegate); |
| 3255 | 3501 |
| 3256 TestDelegate d; | 3502 TestDelegate d; |
| 3257 { | 3503 { |
| 3258 URLRequest r(GURL("https://www.server-auth.com/"), &d, &context); | 3504 URLRequest r(GURL("https://www.server-auth.com/"), |
| 3505 DEFAULT_PRIORITY, | |
| 3506 &d, | |
| 3507 &context, | |
| 3508 &network_delegate); | |
| 3259 | 3509 |
| 3260 r.Start(); | 3510 r.Start(); |
| 3261 EXPECT_TRUE(r.is_pending()); | 3511 EXPECT_TRUE(r.is_pending()); |
| 3262 | 3512 |
| 3263 base::RunLoop().Run(); | 3513 base::RunLoop().Run(); |
| 3264 | 3514 |
| 3265 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 3515 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 3266 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 3516 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 3267 } | 3517 } |
| 3268 } | 3518 } |
| 3269 | 3519 |
| 3270 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 3520 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 3271 ASSERT_TRUE(test_server_.Start()); | 3521 ASSERT_TRUE(test_server_.Start()); |
| 3272 | 3522 |
| 3273 TestDelegate d; | 3523 TestDelegate d; |
| 3274 { | 3524 { |
| 3275 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3525 URLRequest r(test_server_.GetURL(std::string()), |
| 3526 DEFAULT_PRIORITY, | |
| 3527 &d, | |
| 3528 &default_context_, | |
| 3529 &default_network_delegate_); | |
| 3276 | 3530 |
| 3277 r.Start(); | 3531 r.Start(); |
| 3278 EXPECT_TRUE(r.is_pending()); | 3532 EXPECT_TRUE(r.is_pending()); |
| 3279 | 3533 |
| 3280 base::RunLoop().Run(); | 3534 base::RunLoop().Run(); |
| 3281 | 3535 |
| 3282 EXPECT_EQ(1, d.response_started_count()); | 3536 EXPECT_EQ(1, d.response_started_count()); |
| 3283 EXPECT_FALSE(d.received_data_before_response()); | 3537 EXPECT_FALSE(d.received_data_before_response()); |
| 3284 EXPECT_NE(0, d.bytes_received()); | 3538 EXPECT_NE(0, d.bytes_received()); |
| 3285 EXPECT_EQ(test_server_.host_port_pair().host(), | 3539 EXPECT_EQ(test_server_.host_port_pair().host(), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3331 upper_bound = num_cookies; | 3585 upper_bound = num_cookies; |
| 3332 } | 3586 } |
| 3333 // Success: the test did not crash. | 3587 // Success: the test did not crash. |
| 3334 } | 3588 } |
| 3335 | 3589 |
| 3336 TEST_F(URLRequestTestHTTP, GetTest) { | 3590 TEST_F(URLRequestTestHTTP, GetTest) { |
| 3337 ASSERT_TRUE(test_server_.Start()); | 3591 ASSERT_TRUE(test_server_.Start()); |
| 3338 | 3592 |
| 3339 TestDelegate d; | 3593 TestDelegate d; |
| 3340 { | 3594 { |
| 3341 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3595 URLRequest r(test_server_.GetURL(std::string()), |
| 3596 DEFAULT_PRIORITY, | |
| 3597 &d, | |
| 3598 &default_context_, | |
| 3599 &default_network_delegate_); | |
| 3342 | 3600 |
| 3343 r.Start(); | 3601 r.Start(); |
| 3344 EXPECT_TRUE(r.is_pending()); | 3602 EXPECT_TRUE(r.is_pending()); |
| 3345 | 3603 |
| 3346 base::RunLoop().Run(); | 3604 base::RunLoop().Run(); |
| 3347 | 3605 |
| 3348 EXPECT_EQ(1, d.response_started_count()); | 3606 EXPECT_EQ(1, d.response_started_count()); |
| 3349 EXPECT_FALSE(d.received_data_before_response()); | 3607 EXPECT_FALSE(d.received_data_before_response()); |
| 3350 EXPECT_NE(0, d.bytes_received()); | 3608 EXPECT_NE(0, d.bytes_received()); |
| 3351 EXPECT_EQ(test_server_.host_port_pair().host(), | 3609 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3352 r.GetSocketAddress().host()); | 3610 r.GetSocketAddress().host()); |
| 3353 EXPECT_EQ(test_server_.host_port_pair().port(), | 3611 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3354 r.GetSocketAddress().port()); | 3612 r.GetSocketAddress().port()); |
| 3355 } | 3613 } |
| 3356 } | 3614 } |
| 3357 | 3615 |
| 3358 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { | 3616 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { |
| 3359 ASSERT_TRUE(test_server_.Start()); | 3617 ASSERT_TRUE(test_server_.Start()); |
| 3360 | 3618 |
| 3361 TestDelegate d; | 3619 TestDelegate d; |
| 3362 { | 3620 { |
| 3363 GURL test_url(test_server_.GetURL(std::string())); | 3621 GURL test_url(test_server_.GetURL(std::string())); |
| 3364 URLRequest r(test_url, &d, &default_context_); | 3622 URLRequest r(test_url, |
| 3623 DEFAULT_PRIORITY, | |
| 3624 &d, | |
| 3625 &default_context_, | |
| 3626 &default_network_delegate_); | |
| 3365 | 3627 |
| 3366 HttpRequestHeaders headers; | 3628 HttpRequestHeaders headers; |
| 3367 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 3629 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); |
| 3368 | 3630 |
| 3369 r.Start(); | 3631 r.Start(); |
| 3370 EXPECT_TRUE(r.is_pending()); | 3632 EXPECT_TRUE(r.is_pending()); |
| 3371 | 3633 |
| 3372 base::RunLoop().Run(); | 3634 base::RunLoop().Run(); |
| 3373 | 3635 |
| 3374 EXPECT_EQ(1, d.response_started_count()); | 3636 EXPECT_EQ(1, d.response_started_count()); |
| 3375 EXPECT_FALSE(d.received_data_before_response()); | 3637 EXPECT_FALSE(d.received_data_before_response()); |
| 3376 EXPECT_NE(0, d.bytes_received()); | 3638 EXPECT_NE(0, d.bytes_received()); |
| 3377 EXPECT_EQ(test_server_.host_port_pair().host(), | 3639 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3378 r.GetSocketAddress().host()); | 3640 r.GetSocketAddress().host()); |
| 3379 EXPECT_EQ(test_server_.host_port_pair().port(), | 3641 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3380 r.GetSocketAddress().port()); | 3642 r.GetSocketAddress().port()); |
| 3381 | 3643 |
| 3382 EXPECT_TRUE(d.have_full_request_headers()); | 3644 EXPECT_TRUE(d.have_full_request_headers()); |
| 3383 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 3645 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 3384 } | 3646 } |
| 3385 } | 3647 } |
| 3386 | 3648 |
| 3387 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { | 3649 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { |
| 3388 ASSERT_TRUE(test_server_.Start()); | 3650 ASSERT_TRUE(test_server_.Start()); |
| 3389 | 3651 |
| 3390 TestDelegate d; | 3652 TestDelegate d; |
| 3391 { | 3653 { |
| 3392 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 3654 URLRequest r(test_server_.GetURL(std::string()), |
| 3655 DEFAULT_PRIORITY, | |
| 3656 &d, | |
| 3657 &default_context_, | |
| 3658 &default_network_delegate_); | |
| 3393 | 3659 |
| 3394 r.Start(); | 3660 r.Start(); |
| 3395 EXPECT_TRUE(r.is_pending()); | 3661 EXPECT_TRUE(r.is_pending()); |
| 3396 | 3662 |
| 3397 base::RunLoop().Run(); | 3663 base::RunLoop().Run(); |
| 3398 | 3664 |
| 3399 LoadTimingInfo load_timing_info; | 3665 LoadTimingInfo load_timing_info; |
| 3400 r.GetLoadTimingInfo(&load_timing_info); | 3666 r.GetLoadTimingInfo(&load_timing_info); |
| 3401 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 3667 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 3402 | 3668 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 3432 { | 3698 { |
| 3433 std::string test_file = | 3699 std::string test_file = |
| 3434 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 3700 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
| 3435 test_parameters[i]); | 3701 test_parameters[i]); |
| 3436 | 3702 |
| 3437 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3703 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3438 TestURLRequestContext context(true); | 3704 TestURLRequestContext context(true); |
| 3439 context.set_network_delegate(&network_delegate); | 3705 context.set_network_delegate(&network_delegate); |
| 3440 context.Init(); | 3706 context.Init(); |
| 3441 | 3707 |
| 3442 URLRequest r(test_server_.GetURL(test_file), &d, &context); | 3708 URLRequest r(test_server_.GetURL(test_file), |
| 3709 DEFAULT_PRIORITY, | |
| 3710 &d, | |
| 3711 &context, | |
| 3712 &network_delegate); | |
| 3443 r.Start(); | 3713 r.Start(); |
| 3444 EXPECT_TRUE(r.is_pending()); | 3714 EXPECT_TRUE(r.is_pending()); |
| 3445 | 3715 |
| 3446 base::RunLoop().Run(); | 3716 base::RunLoop().Run(); |
| 3447 | 3717 |
| 3448 EXPECT_EQ(1, d.response_started_count()); | 3718 EXPECT_EQ(1, d.response_started_count()); |
| 3449 EXPECT_FALSE(d.received_data_before_response()); | 3719 EXPECT_FALSE(d.received_data_before_response()); |
| 3450 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 3720 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 3451 << " status = " << r.status().status() | 3721 << " status = " << r.status().status() |
| 3452 << " error = " << r.status().error(); | 3722 << " error = " << r.status().error(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3468 SpawnedTestServer https_test_server( | 3738 SpawnedTestServer https_test_server( |
| 3469 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 3739 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, |
| 3470 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 3740 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 3471 ASSERT_TRUE(https_test_server.Start()); | 3741 ASSERT_TRUE(https_test_server.Start()); |
| 3472 | 3742 |
| 3473 // An https server is sent a request with an https referer, | 3743 // An https server is sent a request with an https referer, |
| 3474 // and responds with a redirect to an http url. The http | 3744 // and responds with a redirect to an http url. The http |
| 3475 // server should not be sent the referer. | 3745 // server should not be sent the referer. |
| 3476 GURL http_destination = test_server_.GetURL(std::string()); | 3746 GURL http_destination = test_server_.GetURL(std::string()); |
| 3477 TestDelegate d; | 3747 TestDelegate d; |
| 3478 URLRequest req(https_test_server.GetURL( | 3748 URLRequest req( |
| 3479 "server-redirect?" + http_destination.spec()), &d, &default_context_); | 3749 https_test_server.GetURL("server-redirect?" + http_destination.spec()), |
| 3750 DEFAULT_PRIORITY, | |
| 3751 &d, | |
| 3752 &default_context_, | |
| 3753 &default_network_delegate_); | |
| 3480 req.SetReferrer("https://www.referrer.com/"); | 3754 req.SetReferrer("https://www.referrer.com/"); |
| 3481 req.Start(); | 3755 req.Start(); |
| 3482 base::RunLoop().Run(); | 3756 base::RunLoop().Run(); |
| 3483 | 3757 |
| 3484 EXPECT_EQ(1, d.response_started_count()); | 3758 EXPECT_EQ(1, d.response_started_count()); |
| 3485 EXPECT_EQ(1, d.received_redirect_count()); | 3759 EXPECT_EQ(1, d.received_redirect_count()); |
| 3486 EXPECT_EQ(http_destination, req.url()); | 3760 EXPECT_EQ(http_destination, req.url()); |
| 3487 EXPECT_EQ(std::string(), req.referrer()); | 3761 EXPECT_EQ(std::string(), req.referrer()); |
| 3488 } | 3762 } |
| 3489 | 3763 |
| 3490 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 3764 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
| 3491 ASSERT_TRUE(test_server_.Start()); | 3765 ASSERT_TRUE(test_server_.Start()); |
| 3492 | 3766 |
| 3493 GURL destination_url = test_server_.GetURL(std::string()); | 3767 GURL destination_url = test_server_.GetURL(std::string()); |
| 3494 GURL original_url = | 3768 GURL original_url = |
| 3495 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3769 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3496 TestDelegate d; | 3770 TestDelegate d; |
| 3497 URLRequest req(original_url, &d, &default_context_); | 3771 URLRequest req(original_url, |
| 3772 DEFAULT_PRIORITY, | |
| 3773 &d, | |
| 3774 &default_context_, | |
| 3775 &default_network_delegate_); | |
| 3498 req.Start(); | 3776 req.Start(); |
| 3499 base::RunLoop().Run(); | 3777 base::RunLoop().Run(); |
| 3500 | 3778 |
| 3501 EXPECT_EQ(1, d.response_started_count()); | 3779 EXPECT_EQ(1, d.response_started_count()); |
| 3502 EXPECT_EQ(1, d.received_redirect_count()); | 3780 EXPECT_EQ(1, d.received_redirect_count()); |
| 3503 EXPECT_EQ(destination_url, req.url()); | 3781 EXPECT_EQ(destination_url, req.url()); |
| 3504 EXPECT_EQ(original_url, req.original_url()); | 3782 EXPECT_EQ(original_url, req.original_url()); |
| 3505 ASSERT_EQ(2U, req.url_chain().size()); | 3783 ASSERT_EQ(2U, req.url_chain().size()); |
| 3506 EXPECT_EQ(original_url, req.url_chain()[0]); | 3784 EXPECT_EQ(original_url, req.url_chain()[0]); |
| 3507 EXPECT_EQ(destination_url, req.url_chain()[1]); | 3785 EXPECT_EQ(destination_url, req.url_chain()[1]); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 3527 | 3805 |
| 3528 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 3806 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 3529 ASSERT_TRUE(test_server_.Start()); | 3807 ASSERT_TRUE(test_server_.Start()); |
| 3530 | 3808 |
| 3531 GURL destination_url = test_server_.GetURL(std::string()); | 3809 GURL destination_url = test_server_.GetURL(std::string()); |
| 3532 GURL middle_redirect_url = | 3810 GURL middle_redirect_url = |
| 3533 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3811 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3534 GURL original_url = test_server_.GetURL( | 3812 GURL original_url = test_server_.GetURL( |
| 3535 "server-redirect?" + middle_redirect_url.spec()); | 3813 "server-redirect?" + middle_redirect_url.spec()); |
| 3536 TestDelegate d; | 3814 TestDelegate d; |
| 3537 URLRequest req(original_url, &d, &default_context_); | 3815 URLRequest req(original_url, |
| 3816 DEFAULT_PRIORITY, | |
| 3817 &d, | |
| 3818 &default_context_, | |
| 3819 &default_network_delegate_); | |
| 3538 req.Start(); | 3820 req.Start(); |
| 3539 base::RunLoop().Run(); | 3821 base::RunLoop().Run(); |
| 3540 | 3822 |
| 3541 EXPECT_EQ(1, d.response_started_count()); | 3823 EXPECT_EQ(1, d.response_started_count()); |
| 3542 EXPECT_EQ(2, d.received_redirect_count()); | 3824 EXPECT_EQ(2, d.received_redirect_count()); |
| 3543 EXPECT_EQ(destination_url, req.url()); | 3825 EXPECT_EQ(destination_url, req.url()); |
| 3544 EXPECT_EQ(original_url, req.original_url()); | 3826 EXPECT_EQ(original_url, req.original_url()); |
| 3545 ASSERT_EQ(3U, req.url_chain().size()); | 3827 ASSERT_EQ(3U, req.url_chain().size()); |
| 3546 EXPECT_EQ(original_url, req.url_chain()[0]); | 3828 EXPECT_EQ(original_url, req.url_chain()[0]); |
| 3547 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 3829 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3843 ASSERT_TRUE(test_server_.Start()); | 4125 ASSERT_TRUE(test_server_.Start()); |
| 3844 | 4126 |
| 3845 TestDelegate request_delegate; | 4127 TestDelegate request_delegate; |
| 3846 TestURLRequestContext context(true); | 4128 TestURLRequestContext context(true); |
| 3847 context.set_network_delegate(NULL); | 4129 context.set_network_delegate(NULL); |
| 3848 context.set_net_log(&net_log_); | 4130 context.set_net_log(&net_log_); |
| 3849 context.Init(); | 4131 context.Init(); |
| 3850 | 4132 |
| 3851 { | 4133 { |
| 3852 URLRequest r(test_server_.GetURL("empty.html"), | 4134 URLRequest r(test_server_.GetURL("empty.html"), |
| 3853 &request_delegate, &context); | 4135 DEFAULT_PRIORITY, |
| 4136 &request_delegate, | |
| 4137 &context, | |
| 4138 NULL); | |
| 3854 LoadStateWithParam load_state = r.GetLoadState(); | 4139 LoadStateWithParam load_state = r.GetLoadState(); |
| 3855 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4140 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 3856 EXPECT_EQ(string16(), load_state.param); | 4141 EXPECT_EQ(string16(), load_state.param); |
| 3857 | 4142 |
| 3858 AsyncDelegateLogger::Run( | 4143 AsyncDelegateLogger::Run( |
| 3859 &r, | 4144 &r, |
| 3860 LOAD_STATE_WAITING_FOR_DELEGATE, | 4145 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3861 LOAD_STATE_WAITING_FOR_DELEGATE, | 4146 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 3862 LOAD_STATE_IDLE, | 4147 LOAD_STATE_IDLE, |
| 3863 base::Bind(&URLRequest::Start, base::Unretained(&r))); | 4148 base::Bind(&URLRequest::Start, base::Unretained(&r))); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 3889 | 4174 |
| 3890 TestDelegate request_delegate; | 4175 TestDelegate request_delegate; |
| 3891 AsyncLoggingNetworkDelegate network_delegate; | 4176 AsyncLoggingNetworkDelegate network_delegate; |
| 3892 TestURLRequestContext context(true); | 4177 TestURLRequestContext context(true); |
| 3893 context.set_network_delegate(&network_delegate); | 4178 context.set_network_delegate(&network_delegate); |
| 3894 context.set_net_log(&net_log_); | 4179 context.set_net_log(&net_log_); |
| 3895 context.Init(); | 4180 context.Init(); |
| 3896 | 4181 |
| 3897 { | 4182 { |
| 3898 URLRequest r(test_server_.GetURL("simple.html"), | 4183 URLRequest r(test_server_.GetURL("simple.html"), |
| 3899 &request_delegate, &context); | 4184 DEFAULT_PRIORITY, |
| 4185 &request_delegate, | |
| 4186 &context, | |
| 4187 &network_delegate); | |
| 3900 LoadStateWithParam load_state = r.GetLoadState(); | 4188 LoadStateWithParam load_state = r.GetLoadState(); |
| 3901 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4189 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 3902 EXPECT_EQ(string16(), load_state.param); | 4190 EXPECT_EQ(string16(), load_state.param); |
| 3903 | 4191 |
| 3904 r.Start(); | 4192 r.Start(); |
| 3905 base::RunLoop().Run(); | 4193 base::RunLoop().Run(); |
| 3906 | 4194 |
| 3907 EXPECT_EQ(200, r.GetResponseCode()); | 4195 EXPECT_EQ(200, r.GetResponseCode()); |
| 3908 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4196 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 3909 EXPECT_EQ(1, network_delegate.created_requests()); | 4197 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 3940 | 4228 |
| 3941 TestDelegate request_delegate; | 4229 TestDelegate request_delegate; |
| 3942 AsyncLoggingNetworkDelegate network_delegate; | 4230 AsyncLoggingNetworkDelegate network_delegate; |
| 3943 TestURLRequestContext context(true); | 4231 TestURLRequestContext context(true); |
| 3944 context.set_network_delegate(&network_delegate); | 4232 context.set_network_delegate(&network_delegate); |
| 3945 context.set_net_log(&net_log_); | 4233 context.set_net_log(&net_log_); |
| 3946 context.Init(); | 4234 context.Init(); |
| 3947 | 4235 |
| 3948 { | 4236 { |
| 3949 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4237 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), |
| 3950 &request_delegate, &context); | 4238 DEFAULT_PRIORITY, |
| 4239 &request_delegate, | |
| 4240 &context, | |
| 4241 &network_delegate); | |
| 3951 LoadStateWithParam load_state = r.GetLoadState(); | 4242 LoadStateWithParam load_state = r.GetLoadState(); |
| 3952 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4243 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 3953 EXPECT_EQ(string16(), load_state.param); | 4244 EXPECT_EQ(string16(), load_state.param); |
| 3954 | 4245 |
| 3955 r.Start(); | 4246 r.Start(); |
| 3956 base::RunLoop().Run(); | 4247 base::RunLoop().Run(); |
| 3957 | 4248 |
| 3958 EXPECT_EQ(200, r.GetResponseCode()); | 4249 EXPECT_EQ(200, r.GetResponseCode()); |
| 3959 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4250 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 3960 EXPECT_EQ(2, network_delegate.created_requests()); | 4251 EXPECT_EQ(2, network_delegate.created_requests()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4016 | 4307 |
| 4017 TestDelegate request_delegate; | 4308 TestDelegate request_delegate; |
| 4018 AsyncLoggingNetworkDelegate network_delegate; | 4309 AsyncLoggingNetworkDelegate network_delegate; |
| 4019 TestURLRequestContext context(true); | 4310 TestURLRequestContext context(true); |
| 4020 context.set_network_delegate(&network_delegate); | 4311 context.set_network_delegate(&network_delegate); |
| 4021 context.set_net_log(&net_log_); | 4312 context.set_net_log(&net_log_); |
| 4022 context.Init(); | 4313 context.Init(); |
| 4023 | 4314 |
| 4024 { | 4315 { |
| 4025 URLRequest r(test_server_.GetURL("auth-basic"), | 4316 URLRequest r(test_server_.GetURL("auth-basic"), |
| 4026 &request_delegate, &context); | 4317 DEFAULT_PRIORITY, |
| 4318 &request_delegate, | |
| 4319 &context, | |
| 4320 &network_delegate); | |
| 4027 LoadStateWithParam load_state = r.GetLoadState(); | 4321 LoadStateWithParam load_state = r.GetLoadState(); |
| 4028 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4322 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4029 EXPECT_EQ(string16(), load_state.param); | 4323 EXPECT_EQ(string16(), load_state.param); |
| 4030 | 4324 |
| 4031 r.Start(); | 4325 r.Start(); |
| 4032 base::RunLoop().Run(); | 4326 base::RunLoop().Run(); |
| 4033 | 4327 |
| 4034 EXPECT_EQ(200, r.GetResponseCode()); | 4328 EXPECT_EQ(200, r.GetResponseCode()); |
| 4035 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4329 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4036 EXPECT_EQ(1, network_delegate.created_requests()); | 4330 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4074 context.set_net_log(&net_log_); | 4368 context.set_net_log(&net_log_); |
| 4075 context.Init(); | 4369 context.Init(); |
| 4076 | 4370 |
| 4077 { | 4371 { |
| 4078 // A chunked response with delays between chunks is used to make sure that | 4372 // A chunked response with delays between chunks is used to make sure that |
| 4079 // attempts by the URLRequest delegate to log information while reading the | 4373 // attempts by the URLRequest delegate to log information while reading the |
| 4080 // body are ignored. Since they are ignored, this test is robust against | 4374 // body are ignored. Since they are ignored, this test is robust against |
| 4081 // the possability of multiple reads being combined in the unlikely event | 4375 // the possability of multiple reads being combined in the unlikely event |
| 4082 // that it occurs. | 4376 // that it occurs. |
| 4083 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"), | 4377 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"), |
| 4084 &request_delegate, &context); | 4378 DEFAULT_PRIORITY, |
| 4379 &request_delegate, | |
| 4380 &context, | |
| 4381 NULL); | |
| 4085 LoadStateWithParam load_state = r.GetLoadState(); | 4382 LoadStateWithParam load_state = r.GetLoadState(); |
| 4086 r.Start(); | 4383 r.Start(); |
| 4087 base::RunLoop().Run(); | 4384 base::RunLoop().Run(); |
| 4088 | 4385 |
| 4089 EXPECT_EQ(200, r.GetResponseCode()); | 4386 EXPECT_EQ(200, r.GetResponseCode()); |
| 4090 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4387 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4091 } | 4388 } |
| 4092 | 4389 |
| 4093 CapturingNetLog::CapturedEntryList entries; | 4390 CapturingNetLog::CapturedEntryList entries; |
| 4094 net_log_.GetEntries(&entries); | 4391 net_log_.GetEntries(&entries); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 4122 | 4419 |
| 4123 AsyncLoggingUrlRequestDelegate request_delegate( | 4420 AsyncLoggingUrlRequestDelegate request_delegate( |
| 4124 AsyncLoggingUrlRequestDelegate::NO_CANCEL); | 4421 AsyncLoggingUrlRequestDelegate::NO_CANCEL); |
| 4125 TestURLRequestContext context(true); | 4422 TestURLRequestContext context(true); |
| 4126 context.set_network_delegate(NULL); | 4423 context.set_network_delegate(NULL); |
| 4127 context.set_net_log(&net_log_); | 4424 context.set_net_log(&net_log_); |
| 4128 context.Init(); | 4425 context.Init(); |
| 4129 | 4426 |
| 4130 { | 4427 { |
| 4131 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4428 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), |
| 4132 &request_delegate, &context); | 4429 DEFAULT_PRIORITY, |
| 4430 &request_delegate, | |
| 4431 &context, | |
| 4432 NULL); | |
| 4133 LoadStateWithParam load_state = r.GetLoadState(); | 4433 LoadStateWithParam load_state = r.GetLoadState(); |
| 4134 r.Start(); | 4434 r.Start(); |
| 4135 base::RunLoop().Run(); | 4435 base::RunLoop().Run(); |
| 4136 | 4436 |
| 4137 EXPECT_EQ(200, r.GetResponseCode()); | 4437 EXPECT_EQ(200, r.GetResponseCode()); |
| 4138 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4438 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4139 } | 4439 } |
| 4140 | 4440 |
| 4141 CapturingNetLog::CapturedEntryList entries; | 4441 CapturingNetLog::CapturedEntryList entries; |
| 4142 net_log_.GetEntries(&entries); | 4442 net_log_.GetEntries(&entries); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4180 ++test_case) { | 4480 ++test_case) { |
| 4181 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); | 4481 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); |
| 4182 TestURLRequestContext context(true); | 4482 TestURLRequestContext context(true); |
| 4183 CapturingNetLog net_log; | 4483 CapturingNetLog net_log; |
| 4184 context.set_network_delegate(NULL); | 4484 context.set_network_delegate(NULL); |
| 4185 context.set_net_log(&net_log); | 4485 context.set_net_log(&net_log); |
| 4186 context.Init(); | 4486 context.Init(); |
| 4187 | 4487 |
| 4188 { | 4488 { |
| 4189 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4489 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), |
| 4190 &request_delegate, &context); | 4490 DEFAULT_PRIORITY, |
| 4491 &request_delegate, | |
| 4492 &context, | |
| 4493 NULL); | |
| 4191 LoadStateWithParam load_state = r.GetLoadState(); | 4494 LoadStateWithParam load_state = r.GetLoadState(); |
| 4192 r.Start(); | 4495 r.Start(); |
| 4193 base::RunLoop().Run(); | 4496 base::RunLoop().Run(); |
| 4194 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4497 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 4195 } | 4498 } |
| 4196 | 4499 |
| 4197 CapturingNetLog::CapturedEntryList entries; | 4500 CapturingNetLog::CapturedEntryList entries; |
| 4198 net_log.GetEntries(&entries); | 4501 net_log.GetEntries(&entries); |
| 4199 | 4502 |
| 4200 // Delegate info is always logged in both OnReceivedRedirect and | 4503 // Delegate info is always logged in both OnReceivedRedirect and |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4241 } // namespace | 4544 } // namespace |
| 4242 | 4545 |
| 4243 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 4546 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
| 4244 ASSERT_TRUE(test_server_.Start()); | 4547 ASSERT_TRUE(test_server_.Start()); |
| 4245 | 4548 |
| 4246 GURL destination_url = test_server_.GetURL( | 4549 GURL destination_url = test_server_.GetURL( |
| 4247 "echoheader?" + std::string(kExtraHeader)); | 4550 "echoheader?" + std::string(kExtraHeader)); |
| 4248 GURL original_url = test_server_.GetURL( | 4551 GURL original_url = test_server_.GetURL( |
| 4249 "server-redirect?" + destination_url.spec()); | 4552 "server-redirect?" + destination_url.spec()); |
| 4250 RedirectWithAdditionalHeadersDelegate d; | 4553 RedirectWithAdditionalHeadersDelegate d; |
| 4251 URLRequest req(original_url, &d, &default_context_); | 4554 URLRequest req(original_url, |
| 4555 DEFAULT_PRIORITY, | |
| 4556 &d, | |
| 4557 &default_context_, | |
| 4558 &default_network_delegate_); | |
| 4252 req.Start(); | 4559 req.Start(); |
| 4253 base::RunLoop().Run(); | 4560 base::RunLoop().Run(); |
| 4254 | 4561 |
| 4255 std::string value; | 4562 std::string value; |
| 4256 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4563 const HttpRequestHeaders& headers = req.extra_request_headers(); |
| 4257 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 4564 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
| 4258 EXPECT_EQ(kExtraValue, value); | 4565 EXPECT_EQ(kExtraValue, value); |
| 4259 EXPECT_FALSE(req.is_pending()); | 4566 EXPECT_FALSE(req.is_pending()); |
| 4260 EXPECT_FALSE(req.is_redirecting()); | 4567 EXPECT_FALSE(req.is_redirecting()); |
| 4261 EXPECT_EQ(kExtraValue, d.data_received()); | 4568 EXPECT_EQ(kExtraValue, d.data_received()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 4277 } // namespace | 4584 } // namespace |
| 4278 | 4585 |
| 4279 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { | 4586 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { |
| 4280 ASSERT_TRUE(test_server_.Start()); | 4587 ASSERT_TRUE(test_server_.Start()); |
| 4281 | 4588 |
| 4282 GURL destination_url = test_server_.GetURL( | 4589 GURL destination_url = test_server_.GetURL( |
| 4283 "echoheader?" + std::string(kExtraHeaderToRemove)); | 4590 "echoheader?" + std::string(kExtraHeaderToRemove)); |
| 4284 GURL original_url = test_server_.GetURL( | 4591 GURL original_url = test_server_.GetURL( |
| 4285 "server-redirect?" + destination_url.spec()); | 4592 "server-redirect?" + destination_url.spec()); |
| 4286 RedirectWithHeaderRemovalDelegate d; | 4593 RedirectWithHeaderRemovalDelegate d; |
| 4287 URLRequest req(original_url, &d, &default_context_); | 4594 URLRequest req(original_url, |
| 4595 DEFAULT_PRIORITY, | |
| 4596 &d, | |
| 4597 &default_context_, | |
| 4598 &default_network_delegate_); | |
| 4288 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 4599 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
| 4289 req.Start(); | 4600 req.Start(); |
| 4290 base::RunLoop().Run(); | 4601 base::RunLoop().Run(); |
| 4291 | 4602 |
| 4292 std::string value; | 4603 std::string value; |
| 4293 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4604 const HttpRequestHeaders& headers = req.extra_request_headers(); |
| 4294 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 4605 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| 4295 EXPECT_FALSE(req.is_pending()); | 4606 EXPECT_FALSE(req.is_pending()); |
| 4296 EXPECT_FALSE(req.is_redirecting()); | 4607 EXPECT_FALSE(req.is_redirecting()); |
| 4297 EXPECT_EQ("None", d.data_received()); | 4608 EXPECT_EQ("None", d.data_received()); |
| 4298 } | 4609 } |
| 4299 | 4610 |
| 4300 TEST_F(URLRequestTestHTTP, CancelTest) { | 4611 TEST_F(URLRequestTestHTTP, CancelTest) { |
| 4301 TestDelegate d; | 4612 TestDelegate d; |
| 4302 { | 4613 { |
| 4303 URLRequest r(GURL("http://www.google.com/"), &d, &default_context_); | 4614 URLRequest r(GURL("http://www.google.com/"), |
| 4615 DEFAULT_PRIORITY, | |
| 4616 &d, | |
| 4617 &default_context_, | |
| 4618 &default_network_delegate_); | |
| 4304 | 4619 |
| 4305 r.Start(); | 4620 r.Start(); |
| 4306 EXPECT_TRUE(r.is_pending()); | 4621 EXPECT_TRUE(r.is_pending()); |
| 4307 | 4622 |
| 4308 r.Cancel(); | 4623 r.Cancel(); |
| 4309 | 4624 |
| 4310 base::RunLoop().Run(); | 4625 base::RunLoop().Run(); |
| 4311 | 4626 |
| 4312 // We expect to receive OnResponseStarted even though the request has been | 4627 // We expect to receive OnResponseStarted even though the request has been |
| 4313 // cancelled. | 4628 // cancelled. |
| 4314 EXPECT_EQ(1, d.response_started_count()); | 4629 EXPECT_EQ(1, d.response_started_count()); |
| 4315 EXPECT_EQ(0, d.bytes_received()); | 4630 EXPECT_EQ(0, d.bytes_received()); |
| 4316 EXPECT_FALSE(d.received_data_before_response()); | 4631 EXPECT_FALSE(d.received_data_before_response()); |
| 4317 } | 4632 } |
| 4318 } | 4633 } |
| 4319 | 4634 |
| 4320 TEST_F(URLRequestTestHTTP, CancelTest2) { | 4635 TEST_F(URLRequestTestHTTP, CancelTest2) { |
| 4321 ASSERT_TRUE(test_server_.Start()); | 4636 ASSERT_TRUE(test_server_.Start()); |
| 4322 | 4637 |
| 4323 TestDelegate d; | 4638 TestDelegate d; |
| 4324 { | 4639 { |
| 4325 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 4640 URLRequest r(test_server_.GetURL(std::string()), |
| 4641 DEFAULT_PRIORITY, | |
| 4642 &d, | |
| 4643 &default_context_, | |
| 4644 &default_network_delegate_); | |
| 4326 | 4645 |
| 4327 d.set_cancel_in_response_started(true); | 4646 d.set_cancel_in_response_started(true); |
| 4328 | 4647 |
| 4329 r.Start(); | 4648 r.Start(); |
| 4330 EXPECT_TRUE(r.is_pending()); | 4649 EXPECT_TRUE(r.is_pending()); |
| 4331 | 4650 |
| 4332 base::RunLoop().Run(); | 4651 base::RunLoop().Run(); |
| 4333 | 4652 |
| 4334 EXPECT_EQ(1, d.response_started_count()); | 4653 EXPECT_EQ(1, d.response_started_count()); |
| 4335 EXPECT_EQ(0, d.bytes_received()); | 4654 EXPECT_EQ(0, d.bytes_received()); |
| 4336 EXPECT_FALSE(d.received_data_before_response()); | 4655 EXPECT_FALSE(d.received_data_before_response()); |
| 4337 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4656 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 4338 } | 4657 } |
| 4339 } | 4658 } |
| 4340 | 4659 |
| 4341 TEST_F(URLRequestTestHTTP, CancelTest3) { | 4660 TEST_F(URLRequestTestHTTP, CancelTest3) { |
| 4342 ASSERT_TRUE(test_server_.Start()); | 4661 ASSERT_TRUE(test_server_.Start()); |
| 4343 | 4662 |
| 4344 TestDelegate d; | 4663 TestDelegate d; |
| 4345 { | 4664 { |
| 4346 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 4665 URLRequest r(test_server_.GetURL(std::string()), |
| 4666 DEFAULT_PRIORITY, | |
| 4667 &d, | |
| 4668 &default_context_, | |
| 4669 &default_network_delegate_); | |
| 4347 | 4670 |
| 4348 d.set_cancel_in_received_data(true); | 4671 d.set_cancel_in_received_data(true); |
| 4349 | 4672 |
| 4350 r.Start(); | 4673 r.Start(); |
| 4351 EXPECT_TRUE(r.is_pending()); | 4674 EXPECT_TRUE(r.is_pending()); |
| 4352 | 4675 |
| 4353 base::RunLoop().Run(); | 4676 base::RunLoop().Run(); |
| 4354 | 4677 |
| 4355 EXPECT_EQ(1, d.response_started_count()); | 4678 EXPECT_EQ(1, d.response_started_count()); |
| 4356 // There is no guarantee about how much data was received | 4679 // There is no guarantee about how much data was received |
| 4357 // before the cancel was issued. It could have been 0 bytes, | 4680 // before the cancel was issued. It could have been 0 bytes, |
| 4358 // or it could have been all the bytes. | 4681 // or it could have been all the bytes. |
| 4359 // EXPECT_EQ(0, d.bytes_received()); | 4682 // EXPECT_EQ(0, d.bytes_received()); |
| 4360 EXPECT_FALSE(d.received_data_before_response()); | 4683 EXPECT_FALSE(d.received_data_before_response()); |
| 4361 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4684 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 4362 } | 4685 } |
| 4363 } | 4686 } |
| 4364 | 4687 |
| 4365 TEST_F(URLRequestTestHTTP, CancelTest4) { | 4688 TEST_F(URLRequestTestHTTP, CancelTest4) { |
| 4366 ASSERT_TRUE(test_server_.Start()); | 4689 ASSERT_TRUE(test_server_.Start()); |
| 4367 | 4690 |
| 4368 TestDelegate d; | 4691 TestDelegate d; |
| 4369 { | 4692 { |
| 4370 URLRequest r(test_server_.GetURL(std::string()), &d, &default_context_); | 4693 URLRequest r(test_server_.GetURL(std::string()), |
| 4694 DEFAULT_PRIORITY, | |
| 4695 &d, | |
| 4696 &default_context_, | |
| 4697 &default_network_delegate_); | |
| 4371 | 4698 |
| 4372 r.Start(); | 4699 r.Start(); |
| 4373 EXPECT_TRUE(r.is_pending()); | 4700 EXPECT_TRUE(r.is_pending()); |
| 4374 | 4701 |
| 4375 // The request will be implicitly canceled when it is destroyed. The | 4702 // The request will be implicitly canceled when it is destroyed. The |
| 4376 // test delegate must not post a quit message when this happens because | 4703 // test delegate must not post a quit message when this happens because |
| 4377 // this test doesn't actually have a message loop. The quit message would | 4704 // this test doesn't actually have a message loop. The quit message would |
| 4378 // get put on this thread's message queue and the next test would exit | 4705 // get put on this thread's message queue and the next test would exit |
| 4379 // early, causing problems. | 4706 // early, causing problems. |
| 4380 d.set_quit_on_complete(false); | 4707 d.set_quit_on_complete(false); |
| 4381 } | 4708 } |
| 4382 // expect things to just cleanup properly. | 4709 // expect things to just cleanup properly. |
| 4383 | 4710 |
| 4384 // we won't actually get a received reponse here because we've never run the | 4711 // we won't actually get a received reponse here because we've never run the |
| 4385 // message loop | 4712 // message loop |
| 4386 EXPECT_FALSE(d.received_data_before_response()); | 4713 EXPECT_FALSE(d.received_data_before_response()); |
| 4387 EXPECT_EQ(0, d.bytes_received()); | 4714 EXPECT_EQ(0, d.bytes_received()); |
| 4388 } | 4715 } |
| 4389 | 4716 |
| 4390 TEST_F(URLRequestTestHTTP, CancelTest5) { | 4717 TEST_F(URLRequestTestHTTP, CancelTest5) { |
| 4391 ASSERT_TRUE(test_server_.Start()); | 4718 ASSERT_TRUE(test_server_.Start()); |
| 4392 | 4719 |
| 4393 // populate cache | 4720 // populate cache |
| 4394 { | 4721 { |
| 4395 TestDelegate d; | 4722 TestDelegate d; |
| 4396 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); | 4723 URLRequest r(test_server_.GetURL("cachetime"), |
| 4724 DEFAULT_PRIORITY, | |
| 4725 &d, | |
| 4726 &default_context_, | |
| 4727 &default_network_delegate_); | |
| 4397 r.Start(); | 4728 r.Start(); |
| 4398 base::RunLoop().Run(); | 4729 base::RunLoop().Run(); |
| 4399 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4730 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 4400 } | 4731 } |
| 4401 | 4732 |
| 4402 // cancel read from cache (see bug 990242) | 4733 // cancel read from cache (see bug 990242) |
| 4403 { | 4734 { |
| 4404 TestDelegate d; | 4735 TestDelegate d; |
| 4405 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); | 4736 URLRequest r(test_server_.GetURL("cachetime"), |
| 4737 DEFAULT_PRIORITY, | |
| 4738 &d, | |
| 4739 &default_context_, | |
| 4740 &default_network_delegate_); | |
| 4406 r.Start(); | 4741 r.Start(); |
| 4407 r.Cancel(); | 4742 r.Cancel(); |
| 4408 base::RunLoop().Run(); | 4743 base::RunLoop().Run(); |
| 4409 | 4744 |
| 4410 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4745 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 4411 EXPECT_EQ(1, d.response_started_count()); | 4746 EXPECT_EQ(1, d.response_started_count()); |
| 4412 EXPECT_EQ(0, d.bytes_received()); | 4747 EXPECT_EQ(0, d.bytes_received()); |
| 4413 EXPECT_FALSE(d.received_data_before_response()); | 4748 EXPECT_FALSE(d.received_data_before_response()); |
| 4414 } | 4749 } |
| 4415 } | 4750 } |
| 4416 | 4751 |
| 4417 TEST_F(URLRequestTestHTTP, PostTest) { | 4752 TEST_F(URLRequestTestHTTP, PostTest) { |
| 4418 ASSERT_TRUE(test_server_.Start()); | 4753 ASSERT_TRUE(test_server_.Start()); |
| 4419 HTTPUploadDataOperationTest("POST"); | 4754 HTTPUploadDataOperationTest("POST"); |
| 4420 } | 4755 } |
| 4421 | 4756 |
| 4422 TEST_F(URLRequestTestHTTP, PutTest) { | 4757 TEST_F(URLRequestTestHTTP, PutTest) { |
| 4423 ASSERT_TRUE(test_server_.Start()); | 4758 ASSERT_TRUE(test_server_.Start()); |
| 4424 HTTPUploadDataOperationTest("PUT"); | 4759 HTTPUploadDataOperationTest("PUT"); |
| 4425 } | 4760 } |
| 4426 | 4761 |
| 4427 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 4762 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
| 4428 ASSERT_TRUE(test_server_.Start()); | 4763 ASSERT_TRUE(test_server_.Start()); |
| 4429 | 4764 |
| 4430 TestDelegate d; | 4765 TestDelegate d; |
| 4431 { | 4766 { |
| 4432 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4767 URLRequest r(test_server_.GetURL("echo"), |
| 4768 DEFAULT_PRIORITY, | |
| 4769 &d, | |
| 4770 &default_context_, | |
| 4771 &default_network_delegate_); | |
| 4433 r.set_method("POST"); | 4772 r.set_method("POST"); |
| 4434 | 4773 |
| 4435 r.Start(); | 4774 r.Start(); |
| 4436 EXPECT_TRUE(r.is_pending()); | 4775 EXPECT_TRUE(r.is_pending()); |
| 4437 | 4776 |
| 4438 base::RunLoop().Run(); | 4777 base::RunLoop().Run(); |
| 4439 | 4778 |
| 4440 ASSERT_EQ(1, d.response_started_count()) | 4779 ASSERT_EQ(1, d.response_started_count()) |
| 4441 << "request failed: " << r.status().status() | 4780 << "request failed: " << r.status().status() |
| 4442 << ", error: " << r.status().error(); | 4781 << ", error: " << r.status().error(); |
| 4443 | 4782 |
| 4444 EXPECT_FALSE(d.received_data_before_response()); | 4783 EXPECT_FALSE(d.received_data_before_response()); |
| 4445 EXPECT_TRUE(d.data_received().empty()); | 4784 EXPECT_TRUE(d.data_received().empty()); |
| 4446 } | 4785 } |
| 4447 } | 4786 } |
| 4448 | 4787 |
| 4449 TEST_F(URLRequestTestHTTP, PostFileTest) { | 4788 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 4450 ASSERT_TRUE(test_server_.Start()); | 4789 ASSERT_TRUE(test_server_.Start()); |
| 4451 | 4790 |
| 4452 TestDelegate d; | 4791 TestDelegate d; |
| 4453 { | 4792 { |
| 4454 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4793 URLRequest r(test_server_.GetURL("echo"), |
| 4794 DEFAULT_PRIORITY, | |
| 4795 &d, | |
| 4796 &default_context_, | |
| 4797 &default_network_delegate_); | |
| 4455 r.set_method("POST"); | 4798 r.set_method("POST"); |
| 4456 | 4799 |
| 4457 base::FilePath dir; | 4800 base::FilePath dir; |
| 4458 PathService::Get(base::DIR_EXE, &dir); | 4801 PathService::Get(base::DIR_EXE, &dir); |
| 4459 file_util::SetCurrentDirectory(dir); | 4802 file_util::SetCurrentDirectory(dir); |
| 4460 | 4803 |
| 4461 ScopedVector<UploadElementReader> element_readers; | 4804 ScopedVector<UploadElementReader> element_readers; |
| 4462 | 4805 |
| 4463 base::FilePath path; | 4806 base::FilePath path; |
| 4464 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 4807 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4504 EXPECT_EQ(size, d.bytes_received()); | 4847 EXPECT_EQ(size, d.bytes_received()); |
| 4505 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 4848 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
| 4506 } | 4849 } |
| 4507 } | 4850 } |
| 4508 | 4851 |
| 4509 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 4852 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 4510 ASSERT_TRUE(test_server_.Start()); | 4853 ASSERT_TRUE(test_server_.Start()); |
| 4511 | 4854 |
| 4512 TestDelegate d; | 4855 TestDelegate d; |
| 4513 { | 4856 { |
| 4514 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4857 URLRequest r(test_server_.GetURL("echo"), |
| 4858 DEFAULT_PRIORITY, | |
| 4859 &d, | |
| 4860 &default_context_, | |
| 4861 &default_network_delegate_); | |
| 4515 r.EnableChunkedUpload(); | 4862 r.EnableChunkedUpload(); |
| 4516 r.set_method("POST"); | 4863 r.set_method("POST"); |
| 4517 AddChunksToUpload(&r); | 4864 AddChunksToUpload(&r); |
| 4518 r.Start(); | 4865 r.Start(); |
| 4519 EXPECT_TRUE(r.is_pending()); | 4866 EXPECT_TRUE(r.is_pending()); |
| 4520 | 4867 |
| 4521 base::RunLoop().Run(); | 4868 base::RunLoop().Run(); |
| 4522 | 4869 |
| 4523 VerifyReceivedDataMatchesChunks(&r, &d); | 4870 VerifyReceivedDataMatchesChunks(&r, &d); |
| 4524 } | 4871 } |
| 4525 } | 4872 } |
| 4526 | 4873 |
| 4527 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 4874 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
| 4528 ASSERT_TRUE(test_server_.Start()); | 4875 ASSERT_TRUE(test_server_.Start()); |
| 4529 | 4876 |
| 4530 TestDelegate d; | 4877 TestDelegate d; |
| 4531 { | 4878 { |
| 4532 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4879 URLRequest r(test_server_.GetURL("echo"), |
| 4880 DEFAULT_PRIORITY, | |
| 4881 &d, | |
| 4882 &default_context_, | |
| 4883 &default_network_delegate_); | |
| 4533 r.EnableChunkedUpload(); | 4884 r.EnableChunkedUpload(); |
| 4534 r.set_method("POST"); | 4885 r.set_method("POST"); |
| 4535 r.Start(); | 4886 r.Start(); |
| 4536 EXPECT_TRUE(r.is_pending()); | 4887 EXPECT_TRUE(r.is_pending()); |
| 4537 AddChunksToUpload(&r); | 4888 AddChunksToUpload(&r); |
| 4538 base::RunLoop().Run(); | 4889 base::RunLoop().Run(); |
| 4539 | 4890 |
| 4540 VerifyReceivedDataMatchesChunks(&r, &d); | 4891 VerifyReceivedDataMatchesChunks(&r, &d); |
| 4541 } | 4892 } |
| 4542 } | 4893 } |
| 4543 | 4894 |
| 4544 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 4895 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 4545 ASSERT_TRUE(test_server_.Start()); | 4896 ASSERT_TRUE(test_server_.Start()); |
| 4546 | 4897 |
| 4547 TestDelegate d; | 4898 TestDelegate d; |
| 4548 { | 4899 { |
| 4549 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 4900 URLRequest r(test_server_.GetURL("echo"), |
| 4901 DEFAULT_PRIORITY, | |
| 4902 &d, | |
| 4903 &default_context_, | |
| 4904 &default_network_delegate_); | |
| 4550 r.EnableChunkedUpload(); | 4905 r.EnableChunkedUpload(); |
| 4551 r.set_method("POST"); | 4906 r.set_method("POST"); |
| 4552 r.Start(); | 4907 r.Start(); |
| 4553 EXPECT_TRUE(r.is_pending()); | 4908 EXPECT_TRUE(r.is_pending()); |
| 4554 | 4909 |
| 4555 base::RunLoop().RunUntilIdle(); | 4910 base::RunLoop().RunUntilIdle(); |
| 4556 AddChunksToUpload(&r); | 4911 AddChunksToUpload(&r); |
| 4557 base::RunLoop().Run(); | 4912 base::RunLoop().Run(); |
| 4558 | 4913 |
| 4559 VerifyReceivedDataMatchesChunks(&r, &d); | 4914 VerifyReceivedDataMatchesChunks(&r, &d); |
| 4560 } | 4915 } |
| 4561 } | 4916 } |
| 4562 | 4917 |
| 4563 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 4918 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 4564 ASSERT_TRUE(test_server_.Start()); | 4919 ASSERT_TRUE(test_server_.Start()); |
| 4565 | 4920 |
| 4566 TestDelegate d; | 4921 TestDelegate d; |
| 4567 URLRequest req( | 4922 URLRequest req(test_server_.GetURL("files/with-headers.html"), |
| 4568 test_server_.GetURL("files/with-headers.html"), &d, &default_context_); | 4923 DEFAULT_PRIORITY, |
| 4924 &d, | |
| 4925 &default_context_, | |
| 4926 &default_network_delegate_); | |
| 4569 req.Start(); | 4927 req.Start(); |
| 4570 base::RunLoop().Run(); | 4928 base::RunLoop().Run(); |
| 4571 | 4929 |
| 4572 const HttpResponseHeaders* headers = req.response_headers(); | 4930 const HttpResponseHeaders* headers = req.response_headers(); |
| 4573 | 4931 |
| 4574 // Simple sanity check that response_info() accesses the same data. | 4932 // Simple sanity check that response_info() accesses the same data. |
| 4575 EXPECT_EQ(headers, req.response_info().headers.get()); | 4933 EXPECT_EQ(headers, req.response_info().headers.get()); |
| 4576 | 4934 |
| 4577 std::string header; | 4935 std::string header; |
| 4578 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 4936 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 4591 | 4949 |
| 4592 TEST_F(URLRequestTestHTTP, ProcessSTS) { | 4950 TEST_F(URLRequestTestHTTP, ProcessSTS) { |
| 4593 SpawnedTestServer::SSLOptions ssl_options; | 4951 SpawnedTestServer::SSLOptions ssl_options; |
| 4594 SpawnedTestServer https_test_server( | 4952 SpawnedTestServer https_test_server( |
| 4595 SpawnedTestServer::TYPE_HTTPS, | 4953 SpawnedTestServer::TYPE_HTTPS, |
| 4596 ssl_options, | 4954 ssl_options, |
| 4597 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4955 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4598 ASSERT_TRUE(https_test_server.Start()); | 4956 ASSERT_TRUE(https_test_server.Start()); |
| 4599 | 4957 |
| 4600 TestDelegate d; | 4958 TestDelegate d; |
| 4601 URLRequest request( | 4959 URLRequest request(https_test_server.GetURL("files/hsts-headers.html"), |
| 4602 https_test_server.GetURL("files/hsts-headers.html"), | 4960 DEFAULT_PRIORITY, |
| 4603 &d, | 4961 &d, |
| 4604 &default_context_); | 4962 &default_context_, |
| 4963 &default_network_delegate_); | |
| 4605 request.Start(); | 4964 request.Start(); |
| 4606 base::RunLoop().Run(); | 4965 base::RunLoop().Run(); |
| 4607 | 4966 |
| 4608 TransportSecurityState* security_state = | 4967 TransportSecurityState* security_state = |
| 4609 default_context_.transport_security_state(); | 4968 default_context_.transport_security_state(); |
| 4610 bool sni_available = true; | 4969 bool sni_available = true; |
| 4611 TransportSecurityState::DomainState domain_state; | 4970 TransportSecurityState::DomainState domain_state; |
| 4612 EXPECT_TRUE(security_state->GetDomainState( | 4971 EXPECT_TRUE(security_state->GetDomainState( |
| 4613 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 4972 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 4614 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4973 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4635 // validity/expiration. | 4994 // validity/expiration. |
| 4636 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 4995 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { |
| 4637 SpawnedTestServer::SSLOptions ssl_options; | 4996 SpawnedTestServer::SSLOptions ssl_options; |
| 4638 SpawnedTestServer https_test_server( | 4997 SpawnedTestServer https_test_server( |
| 4639 SpawnedTestServer::TYPE_HTTPS, | 4998 SpawnedTestServer::TYPE_HTTPS, |
| 4640 ssl_options, | 4999 ssl_options, |
| 4641 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5000 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4642 ASSERT_TRUE(https_test_server.Start()); | 5001 ASSERT_TRUE(https_test_server.Start()); |
| 4643 | 5002 |
| 4644 TestDelegate d; | 5003 TestDelegate d; |
| 4645 URLRequest request( | 5004 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"), |
| 4646 https_test_server.GetURL("files/hpkp-headers.html"), | 5005 DEFAULT_PRIORITY, |
| 4647 &d, | 5006 &d, |
| 4648 &default_context_); | 5007 &default_context_, |
| 5008 &default_network_delegate_); | |
| 4649 request.Start(); | 5009 request.Start(); |
| 4650 base::RunLoop().Run(); | 5010 base::RunLoop().Run(); |
| 4651 | 5011 |
| 4652 TransportSecurityState* security_state = | 5012 TransportSecurityState* security_state = |
| 4653 default_context_.transport_security_state(); | 5013 default_context_.transport_security_state(); |
| 4654 bool sni_available = true; | 5014 bool sni_available = true; |
| 4655 TransportSecurityState::DomainState domain_state; | 5015 TransportSecurityState::DomainState domain_state; |
| 4656 EXPECT_TRUE(security_state->GetDomainState( | 5016 EXPECT_TRUE(security_state->GetDomainState( |
| 4657 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5017 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 4658 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, | 5018 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
| 4659 domain_state.upgrade_mode); | 5019 domain_state.upgrade_mode); |
| 4660 EXPECT_FALSE(domain_state.sts_include_subdomains); | 5020 EXPECT_FALSE(domain_state.sts_include_subdomains); |
| 4661 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 5021 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
| 4662 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5022 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 4663 EXPECT_NE(domain_state.upgrade_expiry, | 5023 EXPECT_NE(domain_state.upgrade_expiry, |
| 4664 domain_state.dynamic_spki_hashes_expiry); | 5024 domain_state.dynamic_spki_hashes_expiry); |
| 4665 } | 5025 } |
| 4666 | 5026 |
| 4667 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 5027 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
| 4668 SpawnedTestServer::SSLOptions ssl_options; | 5028 SpawnedTestServer::SSLOptions ssl_options; |
| 4669 SpawnedTestServer https_test_server( | 5029 SpawnedTestServer https_test_server( |
| 4670 SpawnedTestServer::TYPE_HTTPS, | 5030 SpawnedTestServer::TYPE_HTTPS, |
| 4671 ssl_options, | 5031 ssl_options, |
| 4672 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5032 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4673 ASSERT_TRUE(https_test_server.Start()); | 5033 ASSERT_TRUE(https_test_server.Start()); |
| 4674 | 5034 |
| 4675 TestDelegate d; | 5035 TestDelegate d; |
| 4676 URLRequest request( | 5036 URLRequest request( |
| 4677 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 5037 https_test_server.GetURL("files/hsts-multiple-headers.html"), |
| 5038 DEFAULT_PRIORITY, | |
| 4678 &d, | 5039 &d, |
| 4679 &default_context_); | 5040 &default_context_, |
| 5041 &default_network_delegate_); | |
| 4680 request.Start(); | 5042 request.Start(); |
| 4681 base::RunLoop().Run(); | 5043 base::RunLoop().Run(); |
| 4682 | 5044 |
| 4683 // We should have set parameters from the first header, not the second. | 5045 // We should have set parameters from the first header, not the second. |
| 4684 TransportSecurityState* security_state = | 5046 TransportSecurityState* security_state = |
| 4685 default_context_.transport_security_state(); | 5047 default_context_.transport_security_state(); |
| 4686 bool sni_available = true; | 5048 bool sni_available = true; |
| 4687 TransportSecurityState::DomainState domain_state; | 5049 TransportSecurityState::DomainState domain_state; |
| 4688 EXPECT_TRUE(security_state->GetDomainState( | 5050 EXPECT_TRUE(security_state->GetDomainState( |
| 4689 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5051 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 4690 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5052 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 4691 domain_state.upgrade_mode); | 5053 domain_state.upgrade_mode); |
| 4692 EXPECT_FALSE(domain_state.sts_include_subdomains); | 5054 EXPECT_FALSE(domain_state.sts_include_subdomains); |
| 4693 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 5055 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
| 4694 } | 5056 } |
| 4695 | 5057 |
| 4696 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 5058 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
| 4697 SpawnedTestServer::SSLOptions ssl_options; | 5059 SpawnedTestServer::SSLOptions ssl_options; |
| 4698 SpawnedTestServer https_test_server( | 5060 SpawnedTestServer https_test_server( |
| 4699 SpawnedTestServer::TYPE_HTTPS, | 5061 SpawnedTestServer::TYPE_HTTPS, |
| 4700 ssl_options, | 5062 ssl_options, |
| 4701 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5063 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4702 ASSERT_TRUE(https_test_server.Start()); | 5064 ASSERT_TRUE(https_test_server.Start()); |
| 4703 | 5065 |
| 4704 TestDelegate d; | 5066 TestDelegate d; |
| 4705 URLRequest request( | 5067 URLRequest request( |
| 4706 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 5068 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), |
| 5069 DEFAULT_PRIORITY, | |
| 4707 &d, | 5070 &d, |
| 4708 &default_context_); | 5071 &default_context_, |
| 5072 &default_network_delegate_); | |
| 4709 request.Start(); | 5073 request.Start(); |
| 4710 base::RunLoop().Run(); | 5074 base::RunLoop().Run(); |
| 4711 | 5075 |
| 4712 // We should have set parameters from the first header, not the second. | 5076 // We should have set parameters from the first header, not the second. |
| 4713 TransportSecurityState* security_state = | 5077 TransportSecurityState* security_state = |
| 4714 default_context_.transport_security_state(); | 5078 default_context_.transport_security_state(); |
| 4715 bool sni_available = true; | 5079 bool sni_available = true; |
| 4716 TransportSecurityState::DomainState domain_state; | 5080 TransportSecurityState::DomainState domain_state; |
| 4717 EXPECT_TRUE(security_state->GetDomainState( | 5081 EXPECT_TRUE(security_state->GetDomainState( |
| 4718 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5082 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4739 SpawnedTestServer::SSLOptions ssl_options; | 5103 SpawnedTestServer::SSLOptions ssl_options; |
| 4740 SpawnedTestServer https_test_server( | 5104 SpawnedTestServer https_test_server( |
| 4741 SpawnedTestServer::TYPE_HTTPS, | 5105 SpawnedTestServer::TYPE_HTTPS, |
| 4742 ssl_options, | 5106 ssl_options, |
| 4743 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5107 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4744 ASSERT_TRUE(https_test_server.Start()); | 5108 ASSERT_TRUE(https_test_server.Start()); |
| 4745 | 5109 |
| 4746 TestDelegate d; | 5110 TestDelegate d; |
| 4747 URLRequest request( | 5111 URLRequest request( |
| 4748 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 5112 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), |
| 5113 DEFAULT_PRIORITY, | |
| 4749 &d, | 5114 &d, |
| 4750 &default_context_); | 5115 &default_context_, |
| 5116 &default_network_delegate_); | |
| 4751 request.Start(); | 5117 request.Start(); |
| 4752 base::RunLoop().Run(); | 5118 base::RunLoop().Run(); |
| 4753 | 5119 |
| 4754 TransportSecurityState* security_state = | 5120 TransportSecurityState* security_state = |
| 4755 default_context_.transport_security_state(); | 5121 default_context_.transport_security_state(); |
| 4756 bool sni_available = true; | 5122 bool sni_available = true; |
| 4757 TransportSecurityState::DomainState domain_state; | 5123 TransportSecurityState::DomainState domain_state; |
| 4758 EXPECT_TRUE(security_state->GetDomainState( | 5124 EXPECT_TRUE(security_state->GetDomainState( |
| 4759 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); | 5125 SpawnedTestServer::kLocalhost, sni_available, &domain_state)); |
| 4760 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5126 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 4761 domain_state.upgrade_mode); | 5127 domain_state.upgrade_mode); |
| 4762 #if defined(OS_ANDROID) | 5128 #if defined(OS_ANDROID) |
| 4763 // Android's CertVerifyProc does not (yet) handle pins. | 5129 // Android's CertVerifyProc does not (yet) handle pins. |
| 4764 #else | 5130 #else |
| 4765 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5131 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 4766 #endif | 5132 #endif |
| 4767 EXPECT_NE(domain_state.upgrade_expiry, | 5133 EXPECT_NE(domain_state.upgrade_expiry, |
| 4768 domain_state.dynamic_spki_hashes_expiry); | 5134 domain_state.dynamic_spki_hashes_expiry); |
| 4769 | 5135 |
| 4770 EXPECT_TRUE(domain_state.sts_include_subdomains); | 5136 EXPECT_TRUE(domain_state.sts_include_subdomains); |
| 4771 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 5137 EXPECT_FALSE(domain_state.pkp_include_subdomains); |
| 4772 } | 5138 } |
| 4773 | 5139 |
| 4774 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 5140 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
| 4775 ASSERT_TRUE(test_server_.Start()); | 5141 ASSERT_TRUE(test_server_.Start()); |
| 4776 | 5142 |
| 4777 TestDelegate d; | 5143 TestDelegate d; |
| 4778 URLRequest req(test_server_.GetURL( | 5144 URLRequest req(test_server_.GetURL("files/content-type-normalization.html"), |
| 4779 "files/content-type-normalization.html"), &d, &default_context_); | 5145 DEFAULT_PRIORITY, |
| 5146 &d, | |
| 5147 &default_context_, | |
| 5148 &default_network_delegate_); | |
| 4780 req.Start(); | 5149 req.Start(); |
| 4781 base::RunLoop().Run(); | 5150 base::RunLoop().Run(); |
| 4782 | 5151 |
| 4783 std::string mime_type; | 5152 std::string mime_type; |
| 4784 req.GetMimeType(&mime_type); | 5153 req.GetMimeType(&mime_type); |
| 4785 EXPECT_EQ("text/html", mime_type); | 5154 EXPECT_EQ("text/html", mime_type); |
| 4786 | 5155 |
| 4787 std::string charset; | 5156 std::string charset; |
| 4788 req.GetCharset(&charset); | 5157 req.GetCharset(&charset); |
| 4789 EXPECT_EQ("utf-8", charset); | 5158 EXPECT_EQ("utf-8", charset); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 4801 | 5170 |
| 4802 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 5171 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 4803 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); | 5172 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
| 4804 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); | 5173 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); |
| 4805 } | 5174 } |
| 4806 | 5175 |
| 4807 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { | 5176 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { |
| 4808 ASSERT_TRUE(test_server_.Start()); | 5177 ASSERT_TRUE(test_server_.Start()); |
| 4809 | 5178 |
| 4810 TestDelegate d; | 5179 TestDelegate d; |
| 4811 URLRequest req(test_server_.GetURL( | 5180 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"), |
| 4812 "files/redirect-to-file.html"), &d, &default_context_); | 5181 DEFAULT_PRIORITY, |
| 5182 &d, | |
| 5183 &default_context_, | |
| 5184 &default_network_delegate_); | |
| 4813 req.Start(); | 5185 req.Start(); |
| 4814 base::RunLoop().Run(); | 5186 base::RunLoop().Run(); |
| 4815 | 5187 |
| 4816 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5188 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 4817 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 5189 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 4818 } | 5190 } |
| 4819 | 5191 |
| 4820 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { | 5192 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { |
| 4821 ASSERT_TRUE(test_server_.Start()); | 5193 ASSERT_TRUE(test_server_.Start()); |
| 4822 | 5194 |
| 4823 TestDelegate d; | 5195 TestDelegate d; |
| 4824 URLRequest req(test_server_.GetURL( | 5196 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"), |
| 4825 "files/redirect-to-data.html"), &d, &default_context_); | 5197 DEFAULT_PRIORITY, |
| 5198 &d, | |
| 5199 &default_context_, | |
| 5200 &default_network_delegate_); | |
| 4826 req.Start(); | 5201 req.Start(); |
| 4827 base::MessageLoop::current()->Run(); | 5202 base::MessageLoop::current()->Run(); |
| 4828 | 5203 |
| 4829 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5204 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 4830 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 5205 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 4831 } | 5206 } |
| 4832 | 5207 |
| 4833 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 5208 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 4834 ASSERT_TRUE(test_server_.Start()); | 5209 ASSERT_TRUE(test_server_.Start()); |
| 4835 | 5210 |
| 4836 TestDelegate d; | 5211 TestDelegate d; |
| 4837 URLRequest req(test_server_.GetURL( | 5212 URLRequest req(test_server_.GetURL("files/redirect-to-invalid-url.html"), |
| 4838 "files/redirect-to-invalid-url.html"), &d, &default_context_); | 5213 DEFAULT_PRIORITY, |
| 5214 &d, | |
| 5215 &default_context_, | |
| 5216 &default_network_delegate_); | |
| 4839 req.Start(); | 5217 req.Start(); |
| 4840 base::RunLoop().Run(); | 5218 base::RunLoop().Run(); |
| 4841 | 5219 |
| 4842 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5220 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 4843 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); | 5221 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); |
| 4844 } | 5222 } |
| 4845 | 5223 |
| 4846 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 5224 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 4847 ASSERT_TRUE(test_server_.Start()); | 5225 ASSERT_TRUE(test_server_.Start()); |
| 4848 | 5226 |
| 4849 TestDelegate d; | 5227 TestDelegate d; |
| 4850 URLRequest req( | 5228 URLRequest req(test_server_.GetURL("echoheader?Referer"), |
| 4851 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 5229 DEFAULT_PRIORITY, |
| 5230 &d, | |
| 5231 &default_context_, | |
| 5232 &default_network_delegate_); | |
| 4852 req.SetReferrer("http://user:pass@foo.com/"); | 5233 req.SetReferrer("http://user:pass@foo.com/"); |
| 4853 req.Start(); | 5234 req.Start(); |
| 4854 base::RunLoop().Run(); | 5235 base::RunLoop().Run(); |
| 4855 | 5236 |
| 4856 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 5237 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 4857 } | 5238 } |
| 4858 | 5239 |
| 4859 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { | 5240 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { |
| 4860 ASSERT_TRUE(test_server_.Start()); | 5241 ASSERT_TRUE(test_server_.Start()); |
| 4861 | 5242 |
| 4862 TestDelegate d; | 5243 TestDelegate d; |
| 4863 URLRequest req( | 5244 URLRequest req(test_server_.GetURL("echoheader?Referer"), |
| 4864 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 5245 DEFAULT_PRIORITY, |
| 5246 &d, | |
| 5247 &default_context_, | |
| 5248 &default_network_delegate_); | |
| 4865 req.SetReferrer("http://foo.com/test#fragment"); | 5249 req.SetReferrer("http://foo.com/test#fragment"); |
| 4866 req.Start(); | 5250 req.Start(); |
| 4867 base::RunLoop().Run(); | 5251 base::RunLoop().Run(); |
| 4868 | 5252 |
| 4869 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); | 5253 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); |
| 4870 } | 5254 } |
| 4871 | 5255 |
| 4872 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { | 5256 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { |
| 4873 ASSERT_TRUE(test_server_.Start()); | 5257 ASSERT_TRUE(test_server_.Start()); |
| 4874 | 5258 |
| 4875 TestDelegate d; | 5259 TestDelegate d; |
| 4876 URLRequest req( | 5260 URLRequest req(test_server_.GetURL("echoheader?Referer"), |
| 4877 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); | 5261 DEFAULT_PRIORITY, |
| 5262 &d, | |
| 5263 &default_context_, | |
| 5264 &default_network_delegate_); | |
| 4878 req.SetReferrer("http://foo.com/test#fragment"); | 5265 req.SetReferrer("http://foo.com/test#fragment"); |
| 4879 req.SetReferrer(""); | 5266 req.SetReferrer(""); |
| 4880 req.Start(); | 5267 req.Start(); |
| 4881 base::RunLoop().Run(); | 5268 base::RunLoop().Run(); |
| 4882 | 5269 |
| 4883 EXPECT_EQ(std::string("None"), d.data_received()); | 5270 EXPECT_EQ(std::string("None"), d.data_received()); |
| 4884 } | 5271 } |
| 4885 | 5272 |
| 4886 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 5273 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 4887 ASSERT_TRUE(test_server_.Start()); | 5274 ASSERT_TRUE(test_server_.Start()); |
| 4888 | 5275 |
| 4889 TestDelegate d; | 5276 TestDelegate d; |
| 4890 { | 5277 { |
| 4891 d.set_cancel_in_received_redirect(true); | 5278 d.set_cancel_in_received_redirect(true); |
| 4892 URLRequest req( | 5279 URLRequest req(test_server_.GetURL("files/redirect-test.html"), |
| 4893 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 5280 DEFAULT_PRIORITY, |
| 5281 &d, | |
| 5282 &default_context_, | |
| 5283 &default_network_delegate_); | |
| 4894 req.Start(); | 5284 req.Start(); |
| 4895 base::RunLoop().Run(); | 5285 base::RunLoop().Run(); |
| 4896 | 5286 |
| 4897 EXPECT_EQ(1, d.response_started_count()); | 5287 EXPECT_EQ(1, d.response_started_count()); |
| 4898 EXPECT_EQ(0, d.bytes_received()); | 5288 EXPECT_EQ(0, d.bytes_received()); |
| 4899 EXPECT_FALSE(d.received_data_before_response()); | 5289 EXPECT_FALSE(d.received_data_before_response()); |
| 4900 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 5290 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 4901 } | 5291 } |
| 4902 } | 5292 } |
| 4903 | 5293 |
| 4904 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 5294 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 4905 ASSERT_TRUE(test_server_.Start()); | 5295 ASSERT_TRUE(test_server_.Start()); |
| 4906 | 5296 |
| 4907 TestDelegate d; | 5297 TestDelegate d; |
| 4908 { | 5298 { |
| 4909 d.set_quit_on_redirect(true); | 5299 d.set_quit_on_redirect(true); |
| 4910 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 5300 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
| 4911 URLRequest req(test_url, &d, &default_context_); | 5301 URLRequest req(test_url, |
| 5302 DEFAULT_PRIORITY, | |
| 5303 &d, | |
| 5304 &default_context_, | |
| 5305 &default_network_delegate_); | |
| 4912 | 5306 |
| 4913 req.Start(); | 5307 req.Start(); |
| 4914 base::RunLoop().Run(); | 5308 base::RunLoop().Run(); |
| 4915 | 5309 |
| 4916 EXPECT_EQ(1, d.received_redirect_count()); | 5310 EXPECT_EQ(1, d.received_redirect_count()); |
| 4917 | 5311 |
| 4918 req.FollowDeferredRedirect(); | 5312 req.FollowDeferredRedirect(); |
| 4919 base::RunLoop().Run(); | 5313 base::RunLoop().Run(); |
| 4920 | 5314 |
| 4921 EXPECT_EQ(1, d.response_started_count()); | 5315 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 4935 } | 5329 } |
| 4936 } | 5330 } |
| 4937 | 5331 |
| 4938 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { | 5332 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { |
| 4939 ASSERT_TRUE(test_server_.Start()); | 5333 ASSERT_TRUE(test_server_.Start()); |
| 4940 | 5334 |
| 4941 TestDelegate d; | 5335 TestDelegate d; |
| 4942 { | 5336 { |
| 4943 d.set_quit_on_redirect(true); | 5337 d.set_quit_on_redirect(true); |
| 4944 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 5338 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
| 4945 URLRequest req(test_url, &d, &default_context_); | 5339 URLRequest req(test_url, |
| 5340 DEFAULT_PRIORITY, | |
| 5341 &d, | |
| 5342 &default_context_, | |
| 5343 &default_network_delegate_); | |
| 4946 | 5344 |
| 4947 EXPECT_FALSE(d.have_full_request_headers()); | 5345 EXPECT_FALSE(d.have_full_request_headers()); |
| 4948 | 5346 |
| 4949 req.Start(); | 5347 req.Start(); |
| 4950 base::RunLoop().Run(); | 5348 base::RunLoop().Run(); |
| 4951 | 5349 |
| 4952 EXPECT_EQ(1, d.received_redirect_count()); | 5350 EXPECT_EQ(1, d.received_redirect_count()); |
| 4953 EXPECT_TRUE(d.have_full_request_headers()); | 5351 EXPECT_TRUE(d.have_full_request_headers()); |
| 4954 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 5352 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 4955 d.ClearFullRequestHeaders(); | 5353 d.ClearFullRequestHeaders(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 4976 EXPECT_EQ(contents, d.data_received()); | 5374 EXPECT_EQ(contents, d.data_received()); |
| 4977 } | 5375 } |
| 4978 } | 5376 } |
| 4979 | 5377 |
| 4980 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 5378 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 4981 ASSERT_TRUE(test_server_.Start()); | 5379 ASSERT_TRUE(test_server_.Start()); |
| 4982 | 5380 |
| 4983 TestDelegate d; | 5381 TestDelegate d; |
| 4984 { | 5382 { |
| 4985 d.set_quit_on_redirect(true); | 5383 d.set_quit_on_redirect(true); |
| 4986 URLRequest req( | 5384 URLRequest req(test_server_.GetURL("files/redirect-test.html"), |
| 4987 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); | 5385 DEFAULT_PRIORITY, |
| 5386 &d, | |
| 5387 &default_context_, | |
| 5388 &default_network_delegate_); | |
| 4988 req.Start(); | 5389 req.Start(); |
| 4989 base::RunLoop().Run(); | 5390 base::RunLoop().Run(); |
| 4990 | 5391 |
| 4991 EXPECT_EQ(1, d.received_redirect_count()); | 5392 EXPECT_EQ(1, d.received_redirect_count()); |
| 4992 | 5393 |
| 4993 req.Cancel(); | 5394 req.Cancel(); |
| 4994 base::RunLoop().Run(); | 5395 base::RunLoop().Run(); |
| 4995 | 5396 |
| 4996 EXPECT_EQ(1, d.response_started_count()); | 5397 EXPECT_EQ(1, d.response_started_count()); |
| 4997 EXPECT_EQ(0, d.bytes_received()); | 5398 EXPECT_EQ(0, d.bytes_received()); |
| 4998 EXPECT_FALSE(d.received_data_before_response()); | 5399 EXPECT_FALSE(d.received_data_before_response()); |
| 4999 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 5400 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 5000 } | 5401 } |
| 5001 } | 5402 } |
| 5002 | 5403 |
| 5003 TEST_F(URLRequestTestHTTP, VaryHeader) { | 5404 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 5004 ASSERT_TRUE(test_server_.Start()); | 5405 ASSERT_TRUE(test_server_.Start()); |
| 5005 | 5406 |
| 5006 // Populate the cache. | 5407 // Populate the cache. |
| 5007 { | 5408 { |
| 5008 TestDelegate d; | 5409 TestDelegate d; |
| 5009 URLRequest req( | 5410 URLRequest req(test_server_.GetURL("echoheadercache?foo"), |
| 5010 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 5411 DEFAULT_PRIORITY, |
| 5412 &d, | |
| 5413 &default_context_, | |
| 5414 &default_network_delegate_); | |
| 5011 HttpRequestHeaders headers; | 5415 HttpRequestHeaders headers; |
| 5012 headers.SetHeader("foo", "1"); | 5416 headers.SetHeader("foo", "1"); |
| 5013 req.SetExtraRequestHeaders(headers); | 5417 req.SetExtraRequestHeaders(headers); |
| 5014 req.Start(); | 5418 req.Start(); |
| 5015 base::RunLoop().Run(); | 5419 base::RunLoop().Run(); |
| 5016 | 5420 |
| 5017 LoadTimingInfo load_timing_info; | 5421 LoadTimingInfo load_timing_info; |
| 5018 req.GetLoadTimingInfo(&load_timing_info); | 5422 req.GetLoadTimingInfo(&load_timing_info); |
| 5019 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5423 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5020 } | 5424 } |
| 5021 | 5425 |
| 5022 // Expect a cache hit. | 5426 // Expect a cache hit. |
| 5023 { | 5427 { |
| 5024 TestDelegate d; | 5428 TestDelegate d; |
| 5025 URLRequest req( | 5429 URLRequest req(test_server_.GetURL("echoheadercache?foo"), |
| 5026 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 5430 DEFAULT_PRIORITY, |
| 5431 &d, | |
| 5432 &default_context_, | |
| 5433 &default_network_delegate_); | |
| 5027 HttpRequestHeaders headers; | 5434 HttpRequestHeaders headers; |
| 5028 headers.SetHeader("foo", "1"); | 5435 headers.SetHeader("foo", "1"); |
| 5029 req.SetExtraRequestHeaders(headers); | 5436 req.SetExtraRequestHeaders(headers); |
| 5030 req.Start(); | 5437 req.Start(); |
| 5031 base::RunLoop().Run(); | 5438 base::RunLoop().Run(); |
| 5032 | 5439 |
| 5033 EXPECT_TRUE(req.was_cached()); | 5440 EXPECT_TRUE(req.was_cached()); |
| 5034 | 5441 |
| 5035 LoadTimingInfo load_timing_info; | 5442 LoadTimingInfo load_timing_info; |
| 5036 req.GetLoadTimingInfo(&load_timing_info); | 5443 req.GetLoadTimingInfo(&load_timing_info); |
| 5037 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 5444 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 5038 } | 5445 } |
| 5039 | 5446 |
| 5040 // Expect a cache miss. | 5447 // Expect a cache miss. |
| 5041 { | 5448 { |
| 5042 TestDelegate d; | 5449 TestDelegate d; |
| 5043 URLRequest req( | 5450 URLRequest req(test_server_.GetURL("echoheadercache?foo"), |
| 5044 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); | 5451 DEFAULT_PRIORITY, |
| 5452 &d, | |
| 5453 &default_context_, | |
| 5454 &default_network_delegate_); | |
| 5045 HttpRequestHeaders headers; | 5455 HttpRequestHeaders headers; |
| 5046 headers.SetHeader("foo", "2"); | 5456 headers.SetHeader("foo", "2"); |
| 5047 req.SetExtraRequestHeaders(headers); | 5457 req.SetExtraRequestHeaders(headers); |
| 5048 req.Start(); | 5458 req.Start(); |
| 5049 base::RunLoop().Run(); | 5459 base::RunLoop().Run(); |
| 5050 | 5460 |
| 5051 EXPECT_FALSE(req.was_cached()); | 5461 EXPECT_FALSE(req.was_cached()); |
| 5052 | 5462 |
| 5053 LoadTimingInfo load_timing_info; | 5463 LoadTimingInfo load_timing_info; |
| 5054 req.GetLoadTimingInfo(&load_timing_info); | 5464 req.GetLoadTimingInfo(&load_timing_info); |
| 5055 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5465 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5056 } | 5466 } |
| 5057 } | 5467 } |
| 5058 | 5468 |
| 5059 TEST_F(URLRequestTestHTTP, BasicAuth) { | 5469 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 5060 ASSERT_TRUE(test_server_.Start()); | 5470 ASSERT_TRUE(test_server_.Start()); |
| 5061 | 5471 |
| 5062 // populate the cache | 5472 // populate the cache |
| 5063 { | 5473 { |
| 5064 TestDelegate d; | 5474 TestDelegate d; |
| 5065 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5475 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5066 | 5476 |
| 5067 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5477 URLRequest r(test_server_.GetURL("auth-basic"), |
| 5478 DEFAULT_PRIORITY, | |
| 5479 &d, | |
| 5480 &default_context_, | |
| 5481 &default_network_delegate_); | |
| 5068 r.Start(); | 5482 r.Start(); |
| 5069 | 5483 |
| 5070 base::RunLoop().Run(); | 5484 base::RunLoop().Run(); |
| 5071 | 5485 |
| 5072 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5486 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5073 } | 5487 } |
| 5074 | 5488 |
| 5075 // repeat request with end-to-end validation. since auth-basic results in a | 5489 // repeat request with end-to-end validation. since auth-basic results in a |
| 5076 // cachable page, we expect this test to result in a 304. in which case, the | 5490 // cachable page, we expect this test to result in a 304. in which case, the |
| 5077 // response should be fetched from the cache. | 5491 // response should be fetched from the cache. |
| 5078 { | 5492 { |
| 5079 TestDelegate d; | 5493 TestDelegate d; |
| 5080 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5494 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5081 | 5495 |
| 5082 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5496 URLRequest r(test_server_.GetURL("auth-basic"), |
| 5497 DEFAULT_PRIORITY, | |
| 5498 &d, | |
| 5499 &default_context_, | |
| 5500 &default_network_delegate_); | |
| 5083 r.set_load_flags(LOAD_VALIDATE_CACHE); | 5501 r.set_load_flags(LOAD_VALIDATE_CACHE); |
| 5084 r.Start(); | 5502 r.Start(); |
| 5085 | 5503 |
| 5086 base::RunLoop().Run(); | 5504 base::RunLoop().Run(); |
| 5087 | 5505 |
| 5088 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5506 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5089 | 5507 |
| 5090 // Should be the same cached document. | 5508 // Should be the same cached document. |
| 5091 EXPECT_TRUE(r.was_cached()); | 5509 EXPECT_TRUE(r.was_cached()); |
| 5092 } | 5510 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 5104 // Verify that when the transaction is restarted, it includes the new cookie. | 5522 // Verify that when the transaction is restarted, it includes the new cookie. |
| 5105 { | 5523 { |
| 5106 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 5524 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 5107 TestURLRequestContext context(true); | 5525 TestURLRequestContext context(true); |
| 5108 context.set_network_delegate(&network_delegate); | 5526 context.set_network_delegate(&network_delegate); |
| 5109 context.Init(); | 5527 context.Init(); |
| 5110 | 5528 |
| 5111 TestDelegate d; | 5529 TestDelegate d; |
| 5112 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5530 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5113 | 5531 |
| 5114 URLRequest r(url_requiring_auth, &d, &context); | 5532 URLRequest r( |
| 5533 url_requiring_auth, DEFAULT_PRIORITY, &d, &context, &network_delegate); | |
| 5115 r.Start(); | 5534 r.Start(); |
| 5116 | 5535 |
| 5117 base::RunLoop().Run(); | 5536 base::RunLoop().Run(); |
| 5118 | 5537 |
| 5119 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5538 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5120 | 5539 |
| 5121 // Make sure we sent the cookie in the restarted transaction. | 5540 // Make sure we sent the cookie in the restarted transaction. |
| 5122 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5541 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 5123 != std::string::npos); | 5542 != std::string::npos); |
| 5124 } | 5543 } |
| 5125 | 5544 |
| 5126 // Same test as above, except this time the restart is initiated earlier | 5545 // Same test as above, except this time the restart is initiated earlier |
| 5127 // (without user intervention since identity is embedded in the URL). | 5546 // (without user intervention since identity is embedded in the URL). |
| 5128 { | 5547 { |
| 5129 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 5548 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 5130 TestURLRequestContext context(true); | 5549 TestURLRequestContext context(true); |
| 5131 context.set_network_delegate(&network_delegate); | 5550 context.set_network_delegate(&network_delegate); |
| 5132 context.Init(); | 5551 context.Init(); |
| 5133 | 5552 |
| 5134 TestDelegate d; | 5553 TestDelegate d; |
| 5135 | 5554 |
| 5136 GURL::Replacements replacements; | 5555 GURL::Replacements replacements; |
| 5137 std::string username("user2"); | 5556 std::string username("user2"); |
| 5138 std::string password("secret"); | 5557 std::string password("secret"); |
| 5139 replacements.SetUsernameStr(username); | 5558 replacements.SetUsernameStr(username); |
| 5140 replacements.SetPasswordStr(password); | 5559 replacements.SetPasswordStr(password); |
| 5141 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 5560 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
| 5142 | 5561 |
| 5143 URLRequest r(url_with_identity, &d, &context); | 5562 URLRequest r( |
| 5563 url_with_identity, DEFAULT_PRIORITY, &d, &context, &network_delegate); | |
| 5144 r.Start(); | 5564 r.Start(); |
| 5145 | 5565 |
| 5146 base::RunLoop().Run(); | 5566 base::RunLoop().Run(); |
| 5147 | 5567 |
| 5148 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 5568 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 5149 | 5569 |
| 5150 // Make sure we sent the cookie in the restarted transaction. | 5570 // Make sure we sent the cookie in the restarted transaction. |
| 5151 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5571 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 5152 != std::string::npos); | 5572 != std::string::npos); |
| 5153 } | 5573 } |
| 5154 } | 5574 } |
| 5155 | 5575 |
| 5156 // Tests that load timing works as expected with auth and the cache. | 5576 // Tests that load timing works as expected with auth and the cache. |
| 5157 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 5577 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
| 5158 ASSERT_TRUE(test_server_.Start()); | 5578 ASSERT_TRUE(test_server_.Start()); |
| 5159 | 5579 |
| 5160 // populate the cache | 5580 // populate the cache |
| 5161 { | 5581 { |
| 5162 TestDelegate d; | 5582 TestDelegate d; |
| 5163 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5583 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5164 | 5584 |
| 5165 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5585 URLRequest r(test_server_.GetURL("auth-basic"), |
| 5586 DEFAULT_PRIORITY, | |
| 5587 &d, | |
| 5588 &default_context_, | |
| 5589 &default_network_delegate_); | |
| 5166 r.Start(); | 5590 r.Start(); |
| 5167 | 5591 |
| 5168 base::RunLoop().Run(); | 5592 base::RunLoop().Run(); |
| 5169 | 5593 |
| 5170 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5594 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5171 | 5595 |
| 5172 LoadTimingInfo load_timing_info_before_auth; | 5596 LoadTimingInfo load_timing_info_before_auth; |
| 5173 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( | 5597 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( |
| 5174 &load_timing_info_before_auth)); | 5598 &load_timing_info_before_auth)); |
| 5175 TestLoadTimingNotReused(load_timing_info_before_auth, | 5599 TestLoadTimingNotReused(load_timing_info_before_auth, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5186 load_timing_info.connect_timing.connect_start); | 5610 load_timing_info.connect_timing.connect_start); |
| 5187 } | 5611 } |
| 5188 | 5612 |
| 5189 // Repeat request with end-to-end validation. Since auth-basic results in a | 5613 // Repeat request with end-to-end validation. Since auth-basic results in a |
| 5190 // cachable page, we expect this test to result in a 304. In which case, the | 5614 // cachable page, we expect this test to result in a 304. In which case, the |
| 5191 // response should be fetched from the cache. | 5615 // response should be fetched from the cache. |
| 5192 { | 5616 { |
| 5193 TestDelegate d; | 5617 TestDelegate d; |
| 5194 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5618 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5195 | 5619 |
| 5196 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); | 5620 URLRequest r(test_server_.GetURL("auth-basic"), |
| 5621 DEFAULT_PRIORITY, | |
| 5622 &d, | |
| 5623 &default_context_, | |
| 5624 &default_network_delegate_); | |
| 5197 r.set_load_flags(LOAD_VALIDATE_CACHE); | 5625 r.set_load_flags(LOAD_VALIDATE_CACHE); |
| 5198 r.Start(); | 5626 r.Start(); |
| 5199 | 5627 |
| 5200 base::RunLoop().Run(); | 5628 base::RunLoop().Run(); |
| 5201 | 5629 |
| 5202 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5630 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5203 | 5631 |
| 5204 // Should be the same cached document. | 5632 // Should be the same cached document. |
| 5205 EXPECT_TRUE(r.was_cached()); | 5633 EXPECT_TRUE(r.was_cached()); |
| 5206 | 5634 |
| 5207 // Since there was a request that went over the wire, the load timing | 5635 // Since there was a request that went over the wire, the load timing |
| 5208 // information should include connection times. | 5636 // information should include connection times. |
| 5209 LoadTimingInfo load_timing_info; | 5637 LoadTimingInfo load_timing_info; |
| 5210 r.GetLoadTimingInfo(&load_timing_info); | 5638 r.GetLoadTimingInfo(&load_timing_info); |
| 5211 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5639 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5212 } | 5640 } |
| 5213 } | 5641 } |
| 5214 | 5642 |
| 5215 // In this test, we do a POST which the server will 302 redirect. | 5643 // In this test, we do a POST which the server will 302 redirect. |
| 5216 // The subsequent transaction should use GET, and should not send the | 5644 // The subsequent transaction should use GET, and should not send the |
| 5217 // Content-Type header. | 5645 // Content-Type header. |
| 5218 // http://code.google.com/p/chromium/issues/detail?id=843 | 5646 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 5219 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 5647 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 5220 ASSERT_TRUE(test_server_.Start()); | 5648 ASSERT_TRUE(test_server_.Start()); |
| 5221 | 5649 |
| 5222 const char kData[] = "hello world"; | 5650 const char kData[] = "hello world"; |
| 5223 | 5651 |
| 5224 TestDelegate d; | 5652 TestDelegate d; |
| 5225 URLRequest req( | 5653 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), |
| 5226 test_server_.GetURL("files/redirect-to-echoall"), &d, &default_context_); | 5654 DEFAULT_PRIORITY, |
| 5655 &d, | |
| 5656 &default_context_, | |
| 5657 &default_network_delegate_); | |
| 5227 req.set_method("POST"); | 5658 req.set_method("POST"); |
| 5228 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 5659 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5229 | 5660 |
| 5230 // Set headers (some of which are specific to the POST). | 5661 // Set headers (some of which are specific to the POST). |
| 5231 HttpRequestHeaders headers; | 5662 HttpRequestHeaders headers; |
| 5232 headers.AddHeadersFromString( | 5663 headers.AddHeadersFromString( |
| 5233 "Content-Type: multipart/form-data; " | 5664 "Content-Type: multipart/form-data; " |
| 5234 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 5665 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 5235 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 5666 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 5236 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 5667 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5302 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 5733 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 5303 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 5734 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 5304 } | 5735 } |
| 5305 | 5736 |
| 5306 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 5737 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 5307 ASSERT_TRUE(test_server_.Start()); | 5738 ASSERT_TRUE(test_server_.Start()); |
| 5308 | 5739 |
| 5309 const char kData[] = "hello world"; | 5740 const char kData[] = "hello world"; |
| 5310 | 5741 |
| 5311 TestDelegate d; | 5742 TestDelegate d; |
| 5312 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 5743 URLRequest req(test_server_.GetURL("empty.html"), |
| 5744 DEFAULT_PRIORITY, | |
| 5745 &d, | |
| 5746 &default_context_, | |
| 5747 &default_network_delegate_); | |
| 5313 req.set_method("POST"); | 5748 req.set_method("POST"); |
| 5314 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 5749 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5315 HttpRequestHeaders headers; | 5750 HttpRequestHeaders headers; |
| 5316 headers.SetHeader(HttpRequestHeaders::kContentLength, | 5751 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 5317 base::UintToString(arraysize(kData) - 1)); | 5752 base::UintToString(arraysize(kData) - 1)); |
| 5318 req.SetExtraRequestHeaders(headers); | 5753 req.SetExtraRequestHeaders(headers); |
| 5319 | 5754 |
| 5320 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 5755 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 5321 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 5756 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
| 5322 URLRequestRedirectJob::REDIRECT_302_FOUND); | 5757 URLRequestRedirectJob::REDIRECT_302_FOUND); |
| 5323 AddTestInterceptor()->set_main_intercept_job(job); | 5758 AddTestInterceptor()->set_main_intercept_job(job); |
| 5324 | 5759 |
| 5325 req.Start(); | 5760 req.Start(); |
| 5326 base::RunLoop().Run(); | 5761 base::RunLoop().Run(); |
| 5327 EXPECT_EQ("GET", req.method()); | 5762 EXPECT_EQ("GET", req.method()); |
| 5328 } | 5763 } |
| 5329 | 5764 |
| 5330 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 5765 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 5331 ASSERT_TRUE(test_server_.Start()); | 5766 ASSERT_TRUE(test_server_.Start()); |
| 5332 | 5767 |
| 5333 const char kData[] = "hello world"; | 5768 const char kData[] = "hello world"; |
| 5334 | 5769 |
| 5335 TestDelegate d; | 5770 TestDelegate d; |
| 5336 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 5771 URLRequest req(test_server_.GetURL("empty.html"), |
| 5772 DEFAULT_PRIORITY, | |
| 5773 &d, | |
| 5774 &default_context_, | |
| 5775 &default_network_delegate_); | |
| 5337 req.set_method("POST"); | 5776 req.set_method("POST"); |
| 5338 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 5777 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5339 HttpRequestHeaders headers; | 5778 HttpRequestHeaders headers; |
| 5340 headers.SetHeader(HttpRequestHeaders::kContentLength, | 5779 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 5341 base::UintToString(arraysize(kData) - 1)); | 5780 base::UintToString(arraysize(kData) - 1)); |
| 5342 req.SetExtraRequestHeaders(headers); | 5781 req.SetExtraRequestHeaders(headers); |
| 5343 | 5782 |
| 5344 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 5783 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 5345 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 5784 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
| 5346 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 5785 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5357 ASSERT_TRUE(test_server_.Start()); | 5796 ASSERT_TRUE(test_server_.Start()); |
| 5358 | 5797 |
| 5359 StaticHttpUserAgentSettings settings("en", EmptyString()); | 5798 StaticHttpUserAgentSettings settings("en", EmptyString()); |
| 5360 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 5799 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 5361 TestURLRequestContext context(true); | 5800 TestURLRequestContext context(true); |
| 5362 context.set_network_delegate(&network_delegate); | 5801 context.set_network_delegate(&network_delegate); |
| 5363 context.set_http_user_agent_settings(&settings); | 5802 context.set_http_user_agent_settings(&settings); |
| 5364 context.Init(); | 5803 context.Init(); |
| 5365 | 5804 |
| 5366 TestDelegate d; | 5805 TestDelegate d; |
| 5367 URLRequest req( | 5806 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
| 5368 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 5807 DEFAULT_PRIORITY, |
| 5808 &d, | |
| 5809 &context, | |
| 5810 &network_delegate); | |
| 5369 req.Start(); | 5811 req.Start(); |
| 5370 base::RunLoop().Run(); | 5812 base::RunLoop().Run(); |
| 5371 EXPECT_EQ("en", d.data_received()); | 5813 EXPECT_EQ("en", d.data_received()); |
| 5372 } | 5814 } |
| 5373 | 5815 |
| 5374 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 5816 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 5375 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 5817 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 5376 ASSERT_TRUE(test_server_.Start()); | 5818 ASSERT_TRUE(test_server_.Start()); |
| 5377 | 5819 |
| 5378 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString()); | 5820 StaticHttpUserAgentSettings settings(EmptyString(), EmptyString()); |
| 5379 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 5821 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 5380 TestURLRequestContext context(true); | 5822 TestURLRequestContext context(true); |
| 5381 context.set_network_delegate(&network_delegate); | 5823 context.set_network_delegate(&network_delegate); |
| 5382 context.Init(); | 5824 context.Init(); |
| 5383 // We override the language after initialization because empty entries | 5825 // We override the language after initialization because empty entries |
| 5384 // get overridden by Init(). | 5826 // get overridden by Init(). |
| 5385 context.set_http_user_agent_settings(&settings); | 5827 context.set_http_user_agent_settings(&settings); |
| 5386 | 5828 |
| 5387 TestDelegate d; | 5829 TestDelegate d; |
| 5388 URLRequest req( | 5830 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
| 5389 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); | 5831 DEFAULT_PRIORITY, |
| 5832 &d, | |
| 5833 &context, | |
| 5834 &network_delegate); | |
| 5390 req.Start(); | 5835 req.Start(); |
| 5391 base::RunLoop().Run(); | 5836 base::RunLoop().Run(); |
| 5392 EXPECT_EQ("None", d.data_received()); | 5837 EXPECT_EQ("None", d.data_received()); |
| 5393 } | 5838 } |
| 5394 | 5839 |
| 5395 // Check that if request overrides the A-L header, the default is not appended. | 5840 // Check that if request overrides the A-L header, the default is not appended. |
| 5396 // See http://crbug.com/20894 | 5841 // See http://crbug.com/20894 |
| 5397 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 5842 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 5398 ASSERT_TRUE(test_server_.Start()); | 5843 ASSERT_TRUE(test_server_.Start()); |
| 5399 | 5844 |
| 5400 TestDelegate d; | 5845 TestDelegate d; |
| 5401 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 5846 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
| 5847 DEFAULT_PRIORITY, | |
| 5402 &d, | 5848 &d, |
| 5403 &default_context_); | 5849 &default_context_, |
| 5850 &default_network_delegate_); | |
| 5404 HttpRequestHeaders headers; | 5851 HttpRequestHeaders headers; |
| 5405 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 5852 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 5406 req.SetExtraRequestHeaders(headers); | 5853 req.SetExtraRequestHeaders(headers); |
| 5407 req.Start(); | 5854 req.Start(); |
| 5408 base::RunLoop().Run(); | 5855 base::RunLoop().Run(); |
| 5409 EXPECT_EQ(std::string("ru"), d.data_received()); | 5856 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 5410 } | 5857 } |
| 5411 | 5858 |
| 5412 // Check that default A-E header is sent. | 5859 // Check that default A-E header is sent. |
| 5413 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 5860 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
| 5414 ASSERT_TRUE(test_server_.Start()); | 5861 ASSERT_TRUE(test_server_.Start()); |
| 5415 | 5862 |
| 5416 TestDelegate d; | 5863 TestDelegate d; |
| 5417 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 5864 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
| 5865 DEFAULT_PRIORITY, | |
| 5418 &d, | 5866 &d, |
| 5419 &default_context_); | 5867 &default_context_, |
| 5868 &default_network_delegate_); | |
| 5420 HttpRequestHeaders headers; | 5869 HttpRequestHeaders headers; |
| 5421 req.SetExtraRequestHeaders(headers); | 5870 req.SetExtraRequestHeaders(headers); |
| 5422 req.Start(); | 5871 req.Start(); |
| 5423 base::RunLoop().Run(); | 5872 base::RunLoop().Run(); |
| 5424 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 5873 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
| 5425 } | 5874 } |
| 5426 | 5875 |
| 5427 // Check that if request overrides the A-E header, the default is not appended. | 5876 // Check that if request overrides the A-E header, the default is not appended. |
| 5428 // See http://crbug.com/47381 | 5877 // See http://crbug.com/47381 |
| 5429 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 5878 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
| 5430 ASSERT_TRUE(test_server_.Start()); | 5879 ASSERT_TRUE(test_server_.Start()); |
| 5431 | 5880 |
| 5432 TestDelegate d; | 5881 TestDelegate d; |
| 5433 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 5882 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
| 5883 DEFAULT_PRIORITY, | |
| 5434 &d, | 5884 &d, |
| 5435 &default_context_); | 5885 &default_context_, |
| 5886 &default_network_delegate_); | |
| 5436 HttpRequestHeaders headers; | 5887 HttpRequestHeaders headers; |
| 5437 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 5888 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
| 5438 req.SetExtraRequestHeaders(headers); | 5889 req.SetExtraRequestHeaders(headers); |
| 5439 req.Start(); | 5890 req.Start(); |
| 5440 base::RunLoop().Run(); | 5891 base::RunLoop().Run(); |
| 5441 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 5892 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 5442 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 5893 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 5443 } | 5894 } |
| 5444 | 5895 |
| 5445 // Check that setting the A-C header sends the proper header. | 5896 // Check that setting the A-C header sends the proper header. |
| 5446 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { | 5897 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { |
| 5447 ASSERT_TRUE(test_server_.Start()); | 5898 ASSERT_TRUE(test_server_.Start()); |
| 5448 | 5899 |
| 5449 TestDelegate d; | 5900 TestDelegate d; |
| 5450 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 5901 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
| 5902 DEFAULT_PRIORITY, | |
| 5451 &d, | 5903 &d, |
| 5452 &default_context_); | 5904 &default_context_, |
| 5905 &default_network_delegate_); | |
| 5453 HttpRequestHeaders headers; | 5906 HttpRequestHeaders headers; |
| 5454 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 5907 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 5455 req.SetExtraRequestHeaders(headers); | 5908 req.SetExtraRequestHeaders(headers); |
| 5456 req.Start(); | 5909 req.Start(); |
| 5457 base::RunLoop().Run(); | 5910 base::RunLoop().Run(); |
| 5458 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 5911 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 5459 } | 5912 } |
| 5460 | 5913 |
| 5461 // Check that default User-Agent header is sent. | 5914 // Check that default User-Agent header is sent. |
| 5462 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 5915 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 5463 ASSERT_TRUE(test_server_.Start()); | 5916 ASSERT_TRUE(test_server_.Start()); |
| 5464 | 5917 |
| 5465 TestDelegate d; | 5918 TestDelegate d; |
| 5466 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 5919 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
| 5920 DEFAULT_PRIORITY, | |
| 5467 &d, | 5921 &d, |
| 5468 &default_context_); | 5922 &default_context_, |
| 5923 &default_network_delegate_); | |
| 5469 req.Start(); | 5924 req.Start(); |
| 5470 base::RunLoop().Run(); | 5925 base::RunLoop().Run(); |
| 5471 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); | 5926 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); |
| 5472 } | 5927 } |
| 5473 | 5928 |
| 5474 // Check that if request overrides the User-Agent header, | 5929 // Check that if request overrides the User-Agent header, |
| 5475 // the default is not appended. | 5930 // the default is not appended. |
| 5476 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 5931 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
| 5477 ASSERT_TRUE(test_server_.Start()); | 5932 ASSERT_TRUE(test_server_.Start()); |
| 5478 | 5933 |
| 5479 TestDelegate d; | 5934 TestDelegate d; |
| 5480 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 5935 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
| 5936 DEFAULT_PRIORITY, | |
| 5481 &d, | 5937 &d, |
| 5482 &default_context_); | 5938 &default_context_, |
| 5939 &default_network_delegate_); | |
| 5483 HttpRequestHeaders headers; | 5940 HttpRequestHeaders headers; |
| 5484 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 5941 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 5485 req.SetExtraRequestHeaders(headers); | 5942 req.SetExtraRequestHeaders(headers); |
| 5486 req.Start(); | 5943 req.Start(); |
| 5487 base::RunLoop().Run(); | 5944 base::RunLoop().Run(); |
| 5488 // If the net tests are being run with ChromeFrame then we need to allow for | 5945 // If the net tests are being run with ChromeFrame then we need to allow for |
| 5489 // the 'chromeframe' suffix which is added to the user agent before the | 5946 // the 'chromeframe' suffix which is added to the user agent before the |
| 5490 // closing parentheses. | 5947 // closing parentheses. |
| 5491 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 5948 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 5492 } | 5949 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 5507 | 5964 |
| 5508 struct { | 5965 struct { |
| 5509 const char* request; | 5966 const char* request; |
| 5510 const char* expected_response; | 5967 const char* expected_response; |
| 5511 } tests[] = { { "echoheader?Accept-Language", "None" }, | 5968 } tests[] = { { "echoheader?Accept-Language", "None" }, |
| 5512 { "echoheader?Accept-Charset", "None" }, | 5969 { "echoheader?Accept-Charset", "None" }, |
| 5513 { "echoheader?User-Agent", "" } }; | 5970 { "echoheader?User-Agent", "" } }; |
| 5514 | 5971 |
| 5515 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 5972 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
| 5516 TestDelegate d; | 5973 TestDelegate d; |
| 5517 URLRequest req(test_server_.GetURL(tests[i].request), &d, &context); | 5974 URLRequest req(test_server_.GetURL(tests[i].request), |
| 5975 DEFAULT_PRIORITY, | |
| 5976 &d, | |
| 5977 &context, | |
| 5978 &network_delegate); | |
| 5518 req.Start(); | 5979 req.Start(); |
| 5519 base::RunLoop().Run(); | 5980 base::RunLoop().Run(); |
| 5520 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 5981 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
| 5521 << " Request = \"" << tests[i].request << "\""; | 5982 << " Request = \"" << tests[i].request << "\""; |
| 5522 } | 5983 } |
| 5523 } | 5984 } |
| 5524 | 5985 |
| 5525 // Make sure that URLRequest passes on its priority updates to | 5986 // Make sure that URLRequest passes on its priority updates to |
| 5526 // newly-created jobs after the first one. | 5987 // newly-created jobs after the first one. |
| 5527 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 5988 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 5528 ASSERT_TRUE(test_server_.Start()); | 5989 ASSERT_TRUE(test_server_.Start()); |
| 5529 | 5990 |
| 5530 TestDelegate d; | 5991 TestDelegate d; |
| 5531 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 5992 URLRequest req(test_server_.GetURL("empty.html"), |
| 5993 DEFAULT_PRIORITY, | |
| 5994 &d, | |
| 5995 &default_context_, | |
| 5996 &default_network_delegate_); | |
| 5532 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | 5997 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); |
| 5533 | 5998 |
| 5534 scoped_refptr<URLRequestRedirectJob> redirect_job = | 5999 scoped_refptr<URLRequestRedirectJob> redirect_job = |
| 5535 new URLRequestRedirectJob( | 6000 new URLRequestRedirectJob( |
| 5536 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6001 &req, &default_network_delegate_, test_server_.GetURL("echo"), |
| 5537 URLRequestRedirectJob::REDIRECT_302_FOUND); | 6002 URLRequestRedirectJob::REDIRECT_302_FOUND); |
| 5538 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 6003 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
| 5539 | 6004 |
| 5540 req.SetPriority(LOW); | 6005 req.SetPriority(LOW); |
| 5541 req.Start(); | 6006 req.Start(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 5565 | 6030 |
| 5566 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 6031 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 5567 SpawnedTestServer test_server( | 6032 SpawnedTestServer test_server( |
| 5568 SpawnedTestServer::TYPE_HTTPS, | 6033 SpawnedTestServer::TYPE_HTTPS, |
| 5569 SpawnedTestServer::kLocalhost, | 6034 SpawnedTestServer::kLocalhost, |
| 5570 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6035 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5571 ASSERT_TRUE(test_server.Start()); | 6036 ASSERT_TRUE(test_server.Start()); |
| 5572 | 6037 |
| 5573 TestDelegate d; | 6038 TestDelegate d; |
| 5574 { | 6039 { |
| 5575 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 6040 URLRequest r(test_server.GetURL(std::string()), |
| 6041 DEFAULT_PRIORITY, | |
| 6042 &d, | |
| 6043 &default_context_, | |
| 6044 &default_network_delegate_); | |
| 5576 r.Start(); | 6045 r.Start(); |
| 5577 EXPECT_TRUE(r.is_pending()); | 6046 EXPECT_TRUE(r.is_pending()); |
| 5578 | 6047 |
| 5579 base::RunLoop().Run(); | 6048 base::RunLoop().Run(); |
| 5580 | 6049 |
| 5581 EXPECT_EQ(1, d.response_started_count()); | 6050 EXPECT_EQ(1, d.response_started_count()); |
| 5582 EXPECT_FALSE(d.received_data_before_response()); | 6051 EXPECT_FALSE(d.received_data_before_response()); |
| 5583 EXPECT_NE(0, d.bytes_received()); | 6052 EXPECT_NE(0, d.bytes_received()); |
| 5584 CheckSSLInfo(r.ssl_info()); | 6053 CheckSSLInfo(r.ssl_info()); |
| 5585 EXPECT_EQ(test_server.host_port_pair().host(), | 6054 EXPECT_EQ(test_server.host_port_pair().host(), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5596 SpawnedTestServer::TYPE_HTTPS, | 6065 SpawnedTestServer::TYPE_HTTPS, |
| 5597 ssl_options, | 6066 ssl_options, |
| 5598 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6067 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5599 ASSERT_TRUE(test_server.Start()); | 6068 ASSERT_TRUE(test_server.Start()); |
| 5600 | 6069 |
| 5601 bool err_allowed = true; | 6070 bool err_allowed = true; |
| 5602 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6071 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 5603 TestDelegate d; | 6072 TestDelegate d; |
| 5604 { | 6073 { |
| 5605 d.set_allow_certificate_errors(err_allowed); | 6074 d.set_allow_certificate_errors(err_allowed); |
| 5606 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 6075 URLRequest r(test_server.GetURL(std::string()), |
| 6076 DEFAULT_PRIORITY, | |
| 6077 &d, | |
| 6078 &default_context_, | |
| 6079 &default_network_delegate_); | |
| 5607 | 6080 |
| 5608 r.Start(); | 6081 r.Start(); |
| 5609 EXPECT_TRUE(r.is_pending()); | 6082 EXPECT_TRUE(r.is_pending()); |
| 5610 | 6083 |
| 5611 base::RunLoop().Run(); | 6084 base::RunLoop().Run(); |
| 5612 | 6085 |
| 5613 EXPECT_EQ(1, d.response_started_count()); | 6086 EXPECT_EQ(1, d.response_started_count()); |
| 5614 EXPECT_FALSE(d.received_data_before_response()); | 6087 EXPECT_FALSE(d.received_data_before_response()); |
| 5615 EXPECT_TRUE(d.have_certificate_errors()); | 6088 EXPECT_TRUE(d.have_certificate_errors()); |
| 5616 if (err_allowed) { | 6089 if (err_allowed) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 5632 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6105 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5633 ASSERT_TRUE(test_server.Start()); | 6106 ASSERT_TRUE(test_server.Start()); |
| 5634 | 6107 |
| 5635 // Iterate from false to true, just so that we do the opposite of the | 6108 // Iterate from false to true, just so that we do the opposite of the |
| 5636 // previous test in order to increase test coverage. | 6109 // previous test in order to increase test coverage. |
| 5637 bool err_allowed = false; | 6110 bool err_allowed = false; |
| 5638 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6111 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 5639 TestDelegate d; | 6112 TestDelegate d; |
| 5640 { | 6113 { |
| 5641 d.set_allow_certificate_errors(err_allowed); | 6114 d.set_allow_certificate_errors(err_allowed); |
| 5642 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 6115 URLRequest r(test_server.GetURL(std::string()), |
| 6116 DEFAULT_PRIORITY, | |
| 6117 &d, | |
| 6118 &default_context_, | |
| 6119 &default_network_delegate_); | |
| 5643 | 6120 |
| 5644 r.Start(); | 6121 r.Start(); |
| 5645 EXPECT_TRUE(r.is_pending()); | 6122 EXPECT_TRUE(r.is_pending()); |
| 5646 | 6123 |
| 5647 base::RunLoop().Run(); | 6124 base::RunLoop().Run(); |
| 5648 | 6125 |
| 5649 EXPECT_EQ(1, d.response_started_count()); | 6126 EXPECT_EQ(1, d.response_started_count()); |
| 5650 EXPECT_FALSE(d.received_data_before_response()); | 6127 EXPECT_FALSE(d.received_data_before_response()); |
| 5651 EXPECT_TRUE(d.have_certificate_errors()); | 6128 EXPECT_TRUE(d.have_certificate_errors()); |
| 5652 if (err_allowed) { | 6129 if (err_allowed) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 5677 SpawnedTestServer test_server( | 6154 SpawnedTestServer test_server( |
| 5678 SpawnedTestServer::TYPE_HTTPS, | 6155 SpawnedTestServer::TYPE_HTTPS, |
| 5679 ssl_options, | 6156 ssl_options, |
| 5680 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6157 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5681 ASSERT_TRUE(test_server.Start()); | 6158 ASSERT_TRUE(test_server.Start()); |
| 5682 | 6159 |
| 5683 TestDelegate d; | 6160 TestDelegate d; |
| 5684 TestURLRequestContext context(true); | 6161 TestURLRequestContext context(true); |
| 5685 context.Init(); | 6162 context.Init(); |
| 5686 d.set_allow_certificate_errors(true); | 6163 d.set_allow_certificate_errors(true); |
| 5687 URLRequest r(test_server.GetURL(std::string()), &d, &context); | 6164 URLRequest r( |
| 6165 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context, NULL); | |
| 5688 r.Start(); | 6166 r.Start(); |
| 5689 | 6167 |
| 5690 base::RunLoop().Run(); | 6168 base::RunLoop().Run(); |
| 5691 | 6169 |
| 5692 EXPECT_EQ(1, d.response_started_count()); | 6170 EXPECT_EQ(1, d.response_started_count()); |
| 5693 EXPECT_NE(0, d.bytes_received()); | 6171 EXPECT_NE(0, d.bytes_received()); |
| 5694 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), | 6172 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), |
| 5695 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 6173 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
| 5696 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 6174 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
| 5697 } | 6175 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 5718 TestURLRequestContext context(true); | 6196 TestURLRequestContext context(true); |
| 5719 context.set_network_delegate(&network_delegate); | 6197 context.set_network_delegate(&network_delegate); |
| 5720 context.set_host_resolver(&host_resolver); | 6198 context.set_host_resolver(&host_resolver); |
| 5721 TransportSecurityState transport_security_state; | 6199 TransportSecurityState transport_security_state; |
| 5722 context.set_transport_security_state(&transport_security_state); | 6200 context.set_transport_security_state(&transport_security_state); |
| 5723 context.Init(); | 6201 context.Init(); |
| 5724 | 6202 |
| 5725 TestDelegate d; | 6203 TestDelegate d; |
| 5726 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 6204 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", |
| 5727 test_server.host_port_pair().port())), | 6205 test_server.host_port_pair().port())), |
| 6206 DEFAULT_PRIORITY, | |
| 5728 &d, | 6207 &d, |
| 5729 &context); | 6208 &context, |
| 6209 &network_delegate); | |
| 5730 | 6210 |
| 5731 r.Start(); | 6211 r.Start(); |
| 5732 EXPECT_TRUE(r.is_pending()); | 6212 EXPECT_TRUE(r.is_pending()); |
| 5733 | 6213 |
| 5734 base::RunLoop().Run(); | 6214 base::RunLoop().Run(); |
| 5735 | 6215 |
| 5736 EXPECT_EQ(1, d.response_started_count()); | 6216 EXPECT_EQ(1, d.response_started_count()); |
| 5737 EXPECT_FALSE(d.received_data_before_response()); | 6217 EXPECT_FALSE(d.received_data_before_response()); |
| 5738 EXPECT_TRUE(d.have_certificate_errors()); | 6218 EXPECT_TRUE(d.have_certificate_errors()); |
| 5739 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 6219 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 5766 TransportSecurityState transport_security_state; | 6246 TransportSecurityState transport_security_state; |
| 5767 TransportSecurityState::DomainState domain_state; | 6247 TransportSecurityState::DomainState domain_state; |
| 5768 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 6248 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
| 5769 &domain_state)); | 6249 &domain_state)); |
| 5770 context.set_transport_security_state(&transport_security_state); | 6250 context.set_transport_security_state(&transport_security_state); |
| 5771 context.Init(); | 6251 context.Init(); |
| 5772 | 6252 |
| 5773 TestDelegate d; | 6253 TestDelegate d; |
| 5774 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 6254 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", |
| 5775 test_server.host_port_pair().port())), | 6255 test_server.host_port_pair().port())), |
| 6256 DEFAULT_PRIORITY, | |
| 5776 &d, | 6257 &d, |
| 5777 &context); | 6258 &context, |
| 6259 &network_delegate); | |
| 5778 | 6260 |
| 5779 r.Start(); | 6261 r.Start(); |
| 5780 EXPECT_TRUE(r.is_pending()); | 6262 EXPECT_TRUE(r.is_pending()); |
| 5781 | 6263 |
| 5782 base::RunLoop().Run(); | 6264 base::RunLoop().Run(); |
| 5783 | 6265 |
| 5784 EXPECT_EQ(1, d.response_started_count()); | 6266 EXPECT_EQ(1, d.response_started_count()); |
| 5785 EXPECT_FALSE(d.received_data_before_response()); | 6267 EXPECT_FALSE(d.received_data_before_response()); |
| 5786 EXPECT_TRUE(d.have_certificate_errors()); | 6268 EXPECT_TRUE(d.have_certificate_errors()); |
| 5787 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 6269 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5837 context.set_network_delegate(&network_delegate); | 6319 context.set_network_delegate(&network_delegate); |
| 5838 context.Init(); | 6320 context.Init(); |
| 5839 | 6321 |
| 5840 TestDelegate d; | 6322 TestDelegate d; |
| 5841 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will | 6323 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will |
| 5842 // cause a certificate error. Ignore the error. | 6324 // cause a certificate error. Ignore the error. |
| 5843 d.set_allow_certificate_errors(true); | 6325 d.set_allow_certificate_errors(true); |
| 5844 | 6326 |
| 5845 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", | 6327 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", |
| 5846 test_server.host_port_pair().port())), | 6328 test_server.host_port_pair().port())), |
| 6329 DEFAULT_PRIORITY, | |
| 5847 &d, | 6330 &d, |
| 5848 &context); | 6331 &context, |
| 6332 &network_delegate); | |
| 5849 req.set_method("POST"); | 6333 req.set_method("POST"); |
| 5850 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 6334 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5851 | 6335 |
| 5852 req.Start(); | 6336 req.Start(); |
| 5853 base::RunLoop().Run(); | 6337 base::RunLoop().Run(); |
| 5854 | 6338 |
| 5855 EXPECT_EQ("https", req.url().scheme()); | 6339 EXPECT_EQ("https", req.url().scheme()); |
| 5856 EXPECT_EQ("POST", req.method()); | 6340 EXPECT_EQ("POST", req.method()); |
| 5857 EXPECT_EQ(kData, d.data_received()); | 6341 EXPECT_EQ(kData, d.data_received()); |
| 5858 | 6342 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 5870 SpawnedTestServer test_server( | 6354 SpawnedTestServer test_server( |
| 5871 SpawnedTestServer::TYPE_HTTPS, | 6355 SpawnedTestServer::TYPE_HTTPS, |
| 5872 ssl_options, | 6356 ssl_options, |
| 5873 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6357 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5874 ASSERT_TRUE(test_server.Start()); | 6358 ASSERT_TRUE(test_server.Start()); |
| 5875 | 6359 |
| 5876 TestDelegate d; | 6360 TestDelegate d; |
| 5877 TestURLRequestContext context(true); | 6361 TestURLRequestContext context(true); |
| 5878 context.Init(); | 6362 context.Init(); |
| 5879 d.set_allow_certificate_errors(true); | 6363 d.set_allow_certificate_errors(true); |
| 5880 URLRequest r(test_server.GetURL(std::string()), &d, &context); | 6364 URLRequest r( |
| 6365 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context, NULL); | |
| 5881 r.Start(); | 6366 r.Start(); |
| 5882 | 6367 |
| 5883 base::RunLoop().Run(); | 6368 base::RunLoop().Run(); |
| 5884 | 6369 |
| 5885 EXPECT_EQ(1, d.response_started_count()); | 6370 EXPECT_EQ(1, d.response_started_count()); |
| 5886 EXPECT_NE(0, d.bytes_received()); | 6371 EXPECT_NE(0, d.bytes_received()); |
| 5887 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), | 6372 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), |
| 5888 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 6373 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
| 5889 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 6374 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
| 5890 } | 6375 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 5919 SpawnedTestServer::SSLOptions ssl_options; | 6404 SpawnedTestServer::SSLOptions ssl_options; |
| 5920 ssl_options.request_client_certificate = true; | 6405 ssl_options.request_client_certificate = true; |
| 5921 SpawnedTestServer test_server( | 6406 SpawnedTestServer test_server( |
| 5922 SpawnedTestServer::TYPE_HTTPS, | 6407 SpawnedTestServer::TYPE_HTTPS, |
| 5923 ssl_options, | 6408 ssl_options, |
| 5924 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6409 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5925 ASSERT_TRUE(test_server.Start()); | 6410 ASSERT_TRUE(test_server.Start()); |
| 5926 | 6411 |
| 5927 SSLClientAuthTestDelegate d; | 6412 SSLClientAuthTestDelegate d; |
| 5928 { | 6413 { |
| 5929 URLRequest r(test_server.GetURL(std::string()), &d, &default_context_); | 6414 URLRequest r(test_server.GetURL(std::string()), |
| 6415 DEFAULT_PRIORITY, | |
| 6416 &d, | |
| 6417 &default_context_, | |
| 6418 &default_network_delegate_); | |
| 5930 | 6419 |
| 5931 r.Start(); | 6420 r.Start(); |
| 5932 EXPECT_TRUE(r.is_pending()); | 6421 EXPECT_TRUE(r.is_pending()); |
| 5933 | 6422 |
| 5934 base::RunLoop().Run(); | 6423 base::RunLoop().Run(); |
| 5935 | 6424 |
| 5936 EXPECT_EQ(1, d.on_certificate_requested_count()); | 6425 EXPECT_EQ(1, d.on_certificate_requested_count()); |
| 5937 EXPECT_FALSE(d.received_data_before_response()); | 6426 EXPECT_FALSE(d.received_data_before_response()); |
| 5938 EXPECT_EQ(0, d.bytes_received()); | 6427 EXPECT_EQ(0, d.bytes_received()); |
| 5939 | 6428 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 5958 SpawnedTestServer test_server( | 6447 SpawnedTestServer test_server( |
| 5959 SpawnedTestServer::TYPE_HTTPS, | 6448 SpawnedTestServer::TYPE_HTTPS, |
| 5960 ssl_options, | 6449 ssl_options, |
| 5961 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6450 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 5962 ASSERT_TRUE(test_server.Start()); | 6451 ASSERT_TRUE(test_server.Start()); |
| 5963 | 6452 |
| 5964 SSLClientSocket::ClearSessionCache(); | 6453 SSLClientSocket::ClearSessionCache(); |
| 5965 | 6454 |
| 5966 { | 6455 { |
| 5967 TestDelegate d; | 6456 TestDelegate d; |
| 5968 URLRequest r( | 6457 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 5969 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 6458 DEFAULT_PRIORITY, |
| 6459 &d, | |
| 6460 &default_context_, | |
| 6461 &default_network_delegate_); | |
| 5970 | 6462 |
| 5971 r.Start(); | 6463 r.Start(); |
| 5972 EXPECT_TRUE(r.is_pending()); | 6464 EXPECT_TRUE(r.is_pending()); |
| 5973 | 6465 |
| 5974 base::RunLoop().Run(); | 6466 base::RunLoop().Run(); |
| 5975 | 6467 |
| 5976 EXPECT_EQ(1, d.response_started_count()); | 6468 EXPECT_EQ(1, d.response_started_count()); |
| 5977 } | 6469 } |
| 5978 | 6470 |
| 5979 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 6471 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 5980 CloseAllConnections(); | 6472 CloseAllConnections(); |
| 5981 | 6473 |
| 5982 { | 6474 { |
| 5983 TestDelegate d; | 6475 TestDelegate d; |
| 5984 URLRequest r( | 6476 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 5985 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 6477 DEFAULT_PRIORITY, |
| 6478 &d, | |
| 6479 &default_context_, | |
| 6480 &default_network_delegate_); | |
| 5986 | 6481 |
| 5987 r.Start(); | 6482 r.Start(); |
| 5988 EXPECT_TRUE(r.is_pending()); | 6483 EXPECT_TRUE(r.is_pending()); |
| 5989 | 6484 |
| 5990 base::RunLoop().Run(); | 6485 base::RunLoop().Run(); |
| 5991 | 6486 |
| 5992 // The response will look like; | 6487 // The response will look like; |
| 5993 // insert abc | 6488 // insert abc |
| 5994 // lookup abc | 6489 // lookup abc |
| 5995 // insert xyz | 6490 // insert xyz |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6027 SpawnedTestServer test_server( | 6522 SpawnedTestServer test_server( |
| 6028 SpawnedTestServer::TYPE_HTTPS, | 6523 SpawnedTestServer::TYPE_HTTPS, |
| 6029 ssl_options, | 6524 ssl_options, |
| 6030 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6525 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6031 ASSERT_TRUE(test_server.Start()); | 6526 ASSERT_TRUE(test_server.Start()); |
| 6032 | 6527 |
| 6033 SSLClientSocket::ClearSessionCache(); | 6528 SSLClientSocket::ClearSessionCache(); |
| 6034 | 6529 |
| 6035 { | 6530 { |
| 6036 TestDelegate d; | 6531 TestDelegate d; |
| 6037 URLRequest r( | 6532 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 6038 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 6533 DEFAULT_PRIORITY, |
| 6534 &d, | |
| 6535 &default_context_, | |
| 6536 &default_network_delegate_); | |
| 6039 | 6537 |
| 6040 r.Start(); | 6538 r.Start(); |
| 6041 EXPECT_TRUE(r.is_pending()); | 6539 EXPECT_TRUE(r.is_pending()); |
| 6042 | 6540 |
| 6043 base::RunLoop().Run(); | 6541 base::RunLoop().Run(); |
| 6044 | 6542 |
| 6045 EXPECT_EQ(1, d.response_started_count()); | 6543 EXPECT_EQ(1, d.response_started_count()); |
| 6046 } | 6544 } |
| 6047 | 6545 |
| 6048 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 6546 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 6059 params.ssl_session_cache_shard = "alternate"; | 6557 params.ssl_session_cache_shard = "alternate"; |
| 6060 | 6558 |
| 6061 scoped_ptr<net::HttpCache> cache(new net::HttpCache( | 6559 scoped_ptr<net::HttpCache> cache(new net::HttpCache( |
| 6062 new net::HttpNetworkSession(params), | 6560 new net::HttpNetworkSession(params), |
| 6063 net::HttpCache::DefaultBackend::InMemory(0))); | 6561 net::HttpCache::DefaultBackend::InMemory(0))); |
| 6064 | 6562 |
| 6065 default_context_.set_http_transaction_factory(cache.get()); | 6563 default_context_.set_http_transaction_factory(cache.get()); |
| 6066 | 6564 |
| 6067 { | 6565 { |
| 6068 TestDelegate d; | 6566 TestDelegate d; |
| 6069 URLRequest r( | 6567 URLRequest r(test_server.GetURL("ssl-session-cache"), |
| 6070 test_server.GetURL("ssl-session-cache"), &d, &default_context_); | 6568 DEFAULT_PRIORITY, |
| 6569 &d, | |
| 6570 &default_context_, | |
| 6571 &default_network_delegate_); | |
| 6071 | 6572 |
| 6072 r.Start(); | 6573 r.Start(); |
| 6073 EXPECT_TRUE(r.is_pending()); | 6574 EXPECT_TRUE(r.is_pending()); |
| 6074 | 6575 |
| 6075 base::RunLoop().Run(); | 6576 base::RunLoop().Run(); |
| 6076 | 6577 |
| 6077 // The response will look like; | 6578 // The response will look like; |
| 6078 // insert abc | 6579 // insert abc |
| 6079 // insert xyz | 6580 // insert xyz |
| 6080 // | 6581 // |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6178 // We always overwrite out_cert_status. | 6679 // We always overwrite out_cert_status. |
| 6179 *out_cert_status = 0; | 6680 *out_cert_status = 0; |
| 6180 SpawnedTestServer test_server( | 6681 SpawnedTestServer test_server( |
| 6181 SpawnedTestServer::TYPE_HTTPS, | 6682 SpawnedTestServer::TYPE_HTTPS, |
| 6182 ssl_options, | 6683 ssl_options, |
| 6183 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6684 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6184 ASSERT_TRUE(test_server.Start()); | 6685 ASSERT_TRUE(test_server.Start()); |
| 6185 | 6686 |
| 6186 TestDelegate d; | 6687 TestDelegate d; |
| 6187 d.set_allow_certificate_errors(true); | 6688 d.set_allow_certificate_errors(true); |
| 6188 URLRequest r(test_server.GetURL(std::string()), &d, &context_); | 6689 URLRequest r(test_server.GetURL(std::string()), |
| 6690 DEFAULT_PRIORITY, | |
| 6691 &d, | |
| 6692 &context_, | |
| 6693 NULL); | |
| 6189 r.Start(); | 6694 r.Start(); |
| 6190 | 6695 |
| 6191 base::RunLoop().Run(); | 6696 base::RunLoop().Run(); |
| 6192 | 6697 |
| 6193 EXPECT_EQ(1, d.response_started_count()); | 6698 EXPECT_EQ(1, d.response_started_count()); |
| 6194 *out_cert_status = r.ssl_info().cert_status; | 6699 *out_cert_status = r.ssl_info().cert_status; |
| 6195 } | 6700 } |
| 6196 | 6701 |
| 6197 virtual ~HTTPSOCSPTest() { | 6702 virtual ~HTTPSOCSPTest() { |
| 6198 #if defined(USE_NSS) || defined(OS_IOS) | 6703 #if defined(USE_NSS) || defined(OS_IOS) |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6633 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); | 7138 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
| 6634 | 7139 |
| 6635 GURL url("ftp://127.0.0.1:7"); | 7140 GURL url("ftp://127.0.0.1:7"); |
| 6636 job_factory.SetProtocolHandler( | 7141 job_factory.SetProtocolHandler( |
| 6637 "ftp", | 7142 "ftp", |
| 6638 new FtpProtocolHandler(&ftp_transaction_factory)); | 7143 new FtpProtocolHandler(&ftp_transaction_factory)); |
| 6639 default_context_.set_job_factory(&job_factory); | 7144 default_context_.set_job_factory(&job_factory); |
| 6640 | 7145 |
| 6641 TestDelegate d; | 7146 TestDelegate d; |
| 6642 { | 7147 { |
| 6643 URLRequest r(url, &d, &default_context_); | 7148 URLRequest r(url, |
| 7149 DEFAULT_PRIORITY, | |
| 7150 &d, | |
| 7151 &default_context_, | |
| 7152 &default_network_delegate_); | |
| 6644 r.Start(); | 7153 r.Start(); |
| 6645 EXPECT_TRUE(r.is_pending()); | 7154 EXPECT_TRUE(r.is_pending()); |
| 6646 | 7155 |
| 6647 base::RunLoop().Run(); | 7156 base::RunLoop().Run(); |
| 6648 | 7157 |
| 6649 EXPECT_FALSE(r.is_pending()); | 7158 EXPECT_FALSE(r.is_pending()); |
| 6650 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 7159 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 6651 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); | 7160 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); |
| 6652 } | 7161 } |
| 6653 } | 7162 } |
| 6654 | 7163 |
| 6655 // Flaky, see http://crbug.com/25045. | 7164 // Flaky, see http://crbug.com/25045. |
| 6656 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | 7165 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { |
| 6657 ASSERT_TRUE(test_server_.Start()); | 7166 ASSERT_TRUE(test_server_.Start()); |
| 6658 | 7167 |
| 6659 TestDelegate d; | 7168 TestDelegate d; |
| 6660 { | 7169 { |
| 6661 URLRequest r(test_server_.GetURL("/"), &d, &default_context_); | 7170 URLRequest r(test_server_.GetURL("/"), |
| 7171 DEFAULT_PRIORITY, | |
| 7172 &d, | |
| 7173 &default_context_, | |
| 7174 &default_network_delegate_); | |
| 6662 r.Start(); | 7175 r.Start(); |
| 6663 EXPECT_TRUE(r.is_pending()); | 7176 EXPECT_TRUE(r.is_pending()); |
| 6664 | 7177 |
| 6665 base::RunLoop().Run(); | 7178 base::RunLoop().Run(); |
| 6666 | 7179 |
| 6667 EXPECT_FALSE(r.is_pending()); | 7180 EXPECT_FALSE(r.is_pending()); |
| 6668 EXPECT_EQ(1, d.response_started_count()); | 7181 EXPECT_EQ(1, d.response_started_count()); |
| 6669 EXPECT_FALSE(d.received_data_before_response()); | 7182 EXPECT_FALSE(d.received_data_before_response()); |
| 6670 EXPECT_LT(0, d.bytes_received()); | 7183 EXPECT_LT(0, d.bytes_received()); |
| 6671 EXPECT_EQ(test_server_.host_port_pair().host(), | 7184 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 6672 r.GetSocketAddress().host()); | 7185 r.GetSocketAddress().host()); |
| 6673 EXPECT_EQ(test_server_.host_port_pair().port(), | 7186 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 6674 r.GetSocketAddress().port()); | 7187 r.GetSocketAddress().port()); |
| 6675 } | 7188 } |
| 6676 } | 7189 } |
| 6677 | 7190 |
| 6678 // Flaky, see http://crbug.com/25045. | 7191 // Flaky, see http://crbug.com/25045. |
| 6679 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | 7192 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { |
| 6680 ASSERT_TRUE(test_server_.Start()); | 7193 ASSERT_TRUE(test_server_.Start()); |
| 6681 | 7194 |
| 6682 base::FilePath app_path; | 7195 base::FilePath app_path; |
| 6683 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7196 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6684 app_path = app_path.AppendASCII("LICENSE"); | 7197 app_path = app_path.AppendASCII("LICENSE"); |
| 6685 TestDelegate d; | 7198 TestDelegate d; |
| 6686 { | 7199 { |
| 6687 URLRequest r(test_server_.GetURL("/LICENSE"), &d, &default_context_); | 7200 URLRequest r(test_server_.GetURL("/LICENSE"), |
| 7201 DEFAULT_PRIORITY, | |
| 7202 &d, | |
| 7203 &default_context_, | |
| 7204 &default_network_delegate_); | |
| 6688 r.Start(); | 7205 r.Start(); |
| 6689 EXPECT_TRUE(r.is_pending()); | 7206 EXPECT_TRUE(r.is_pending()); |
| 6690 | 7207 |
| 6691 base::RunLoop().Run(); | 7208 base::RunLoop().Run(); |
| 6692 | 7209 |
| 6693 int64 file_size = 0; | 7210 int64 file_size = 0; |
| 6694 file_util::GetFileSize(app_path, &file_size); | 7211 file_util::GetFileSize(app_path, &file_size); |
| 6695 | 7212 |
| 6696 EXPECT_FALSE(r.is_pending()); | 7213 EXPECT_FALSE(r.is_pending()); |
| 6697 EXPECT_EQ(1, d.response_started_count()); | 7214 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 6708 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { | 7225 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { |
| 6709 ASSERT_TRUE(test_server_.Start()); | 7226 ASSERT_TRUE(test_server_.Start()); |
| 6710 | 7227 |
| 6711 base::FilePath app_path; | 7228 base::FilePath app_path; |
| 6712 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7229 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6713 app_path = app_path.AppendASCII("LICENSE"); | 7230 app_path = app_path.AppendASCII("LICENSE"); |
| 6714 TestDelegate d; | 7231 TestDelegate d; |
| 6715 { | 7232 { |
| 6716 URLRequest r( | 7233 URLRequest r( |
| 6717 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 7234 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 7235 DEFAULT_PRIORITY, | |
| 6718 &d, | 7236 &d, |
| 6719 &default_context_); | 7237 &default_context_, |
| 7238 &default_network_delegate_); | |
| 6720 r.Start(); | 7239 r.Start(); |
| 6721 EXPECT_TRUE(r.is_pending()); | 7240 EXPECT_TRUE(r.is_pending()); |
| 6722 | 7241 |
| 6723 base::RunLoop().Run(); | 7242 base::RunLoop().Run(); |
| 6724 | 7243 |
| 6725 int64 file_size = 0; | 7244 int64 file_size = 0; |
| 6726 file_util::GetFileSize(app_path, &file_size); | 7245 file_util::GetFileSize(app_path, &file_size); |
| 6727 | 7246 |
| 6728 EXPECT_FALSE(r.is_pending()); | 7247 EXPECT_FALSE(r.is_pending()); |
| 6729 EXPECT_EQ(test_server_.host_port_pair().host(), | 7248 EXPECT_EQ(test_server_.host_port_pair().host(), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 6742 | 7261 |
| 6743 // Flaky, see http://crbug.com/25045. | 7262 // Flaky, see http://crbug.com/25045. |
| 6744 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { | 7263 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { |
| 6745 ASSERT_TRUE(test_server_.Start()); | 7264 ASSERT_TRUE(test_server_.Start()); |
| 6746 | 7265 |
| 6747 base::FilePath app_path; | 7266 base::FilePath app_path; |
| 6748 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7267 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6749 app_path = app_path.AppendASCII("LICENSE"); | 7268 app_path = app_path.AppendASCII("LICENSE"); |
| 6750 TestDelegate d; | 7269 TestDelegate d; |
| 6751 { | 7270 { |
| 6752 URLRequest r( | 7271 URLRequest r(test_server_.GetURLWithUserAndPassword( |
| 6753 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7272 "/LICENSE", "chrome", "wrong_password"), |
| 6754 "chrome", | 7273 DEFAULT_PRIORITY, |
| 6755 "wrong_password"), | 7274 &d, |
| 6756 &d, | 7275 &default_context_, |
| 6757 &default_context_); | 7276 &default_network_delegate_); |
| 6758 r.Start(); | 7277 r.Start(); |
| 6759 EXPECT_TRUE(r.is_pending()); | 7278 EXPECT_TRUE(r.is_pending()); |
| 6760 | 7279 |
| 6761 base::RunLoop().Run(); | 7280 base::RunLoop().Run(); |
| 6762 | 7281 |
| 6763 int64 file_size = 0; | 7282 int64 file_size = 0; |
| 6764 file_util::GetFileSize(app_path, &file_size); | 7283 file_util::GetFileSize(app_path, &file_size); |
| 6765 | 7284 |
| 6766 EXPECT_FALSE(r.is_pending()); | 7285 EXPECT_FALSE(r.is_pending()); |
| 6767 EXPECT_EQ(1, d.response_started_count()); | 7286 EXPECT_EQ(1, d.response_started_count()); |
| 6768 EXPECT_FALSE(d.received_data_before_response()); | 7287 EXPECT_FALSE(d.received_data_before_response()); |
| 6769 EXPECT_EQ(d.bytes_received(), 0); | 7288 EXPECT_EQ(d.bytes_received(), 0); |
| 6770 } | 7289 } |
| 6771 } | 7290 } |
| 6772 | 7291 |
| 6773 // Flaky, see http://crbug.com/25045. | 7292 // Flaky, see http://crbug.com/25045. |
| 6774 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { | 7293 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { |
| 6775 ASSERT_TRUE(test_server_.Start()); | 7294 ASSERT_TRUE(test_server_.Start()); |
| 6776 | 7295 |
| 6777 base::FilePath app_path; | 7296 base::FilePath app_path; |
| 6778 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7297 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6779 app_path = app_path.AppendASCII("LICENSE"); | 7298 app_path = app_path.AppendASCII("LICENSE"); |
| 6780 TestDelegate d; | 7299 TestDelegate d; |
| 6781 // Set correct login credentials. The delegate will be asked for them when | 7300 // Set correct login credentials. The delegate will be asked for them when |
| 6782 // the initial login with wrong credentials will fail. | 7301 // the initial login with wrong credentials will fail. |
| 6783 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 7302 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 6784 { | 7303 { |
| 6785 URLRequest r( | 7304 URLRequest r(test_server_.GetURLWithUserAndPassword( |
| 6786 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7305 "/LICENSE", "chrome", "wrong_password"), |
| 6787 "chrome", | 7306 DEFAULT_PRIORITY, |
| 6788 "wrong_password"), | 7307 &d, |
| 6789 &d, | 7308 &default_context_, |
| 6790 &default_context_); | 7309 &default_network_delegate_); |
| 6791 r.Start(); | 7310 r.Start(); |
| 6792 EXPECT_TRUE(r.is_pending()); | 7311 EXPECT_TRUE(r.is_pending()); |
| 6793 | 7312 |
| 6794 base::RunLoop().Run(); | 7313 base::RunLoop().Run(); |
| 6795 | 7314 |
| 6796 int64 file_size = 0; | 7315 int64 file_size = 0; |
| 6797 file_util::GetFileSize(app_path, &file_size); | 7316 file_util::GetFileSize(app_path, &file_size); |
| 6798 | 7317 |
| 6799 EXPECT_FALSE(r.is_pending()); | 7318 EXPECT_FALSE(r.is_pending()); |
| 6800 EXPECT_EQ(1, d.response_started_count()); | 7319 EXPECT_EQ(1, d.response_started_count()); |
| 6801 EXPECT_FALSE(d.received_data_before_response()); | 7320 EXPECT_FALSE(d.received_data_before_response()); |
| 6802 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7321 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 6803 } | 7322 } |
| 6804 } | 7323 } |
| 6805 | 7324 |
| 6806 // Flaky, see http://crbug.com/25045. | 7325 // Flaky, see http://crbug.com/25045. |
| 6807 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | 7326 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { |
| 6808 ASSERT_TRUE(test_server_.Start()); | 7327 ASSERT_TRUE(test_server_.Start()); |
| 6809 | 7328 |
| 6810 base::FilePath app_path; | 7329 base::FilePath app_path; |
| 6811 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7330 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6812 app_path = app_path.AppendASCII("LICENSE"); | 7331 app_path = app_path.AppendASCII("LICENSE"); |
| 6813 TestDelegate d; | 7332 TestDelegate d; |
| 6814 { | 7333 { |
| 6815 URLRequest r( | 7334 URLRequest r(test_server_.GetURLWithUserAndPassword( |
| 6816 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7335 "/LICENSE", "wrong_user", "chrome"), |
| 6817 "wrong_user", | 7336 DEFAULT_PRIORITY, |
| 6818 "chrome"), | 7337 &d, |
| 6819 &d, | 7338 &default_context_, |
| 6820 &default_context_); | 7339 &default_network_delegate_); |
| 6821 r.Start(); | 7340 r.Start(); |
| 6822 EXPECT_TRUE(r.is_pending()); | 7341 EXPECT_TRUE(r.is_pending()); |
| 6823 | 7342 |
| 6824 base::RunLoop().Run(); | 7343 base::RunLoop().Run(); |
| 6825 | 7344 |
| 6826 int64 file_size = 0; | 7345 int64 file_size = 0; |
| 6827 file_util::GetFileSize(app_path, &file_size); | 7346 file_util::GetFileSize(app_path, &file_size); |
| 6828 | 7347 |
| 6829 EXPECT_FALSE(r.is_pending()); | 7348 EXPECT_FALSE(r.is_pending()); |
| 6830 EXPECT_EQ(1, d.response_started_count()); | 7349 EXPECT_EQ(1, d.response_started_count()); |
| 6831 EXPECT_FALSE(d.received_data_before_response()); | 7350 EXPECT_FALSE(d.received_data_before_response()); |
| 6832 EXPECT_EQ(d.bytes_received(), 0); | 7351 EXPECT_EQ(d.bytes_received(), 0); |
| 6833 } | 7352 } |
| 6834 } | 7353 } |
| 6835 | 7354 |
| 6836 // Flaky, see http://crbug.com/25045. | 7355 // Flaky, see http://crbug.com/25045. |
| 6837 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { | 7356 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { |
| 6838 ASSERT_TRUE(test_server_.Start()); | 7357 ASSERT_TRUE(test_server_.Start()); |
| 6839 | 7358 |
| 6840 base::FilePath app_path; | 7359 base::FilePath app_path; |
| 6841 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7360 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6842 app_path = app_path.AppendASCII("LICENSE"); | 7361 app_path = app_path.AppendASCII("LICENSE"); |
| 6843 TestDelegate d; | 7362 TestDelegate d; |
| 6844 // Set correct login credentials. The delegate will be asked for them when | 7363 // Set correct login credentials. The delegate will be asked for them when |
| 6845 // the initial login with wrong credentials will fail. | 7364 // the initial login with wrong credentials will fail. |
| 6846 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 7365 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 6847 { | 7366 { |
| 6848 URLRequest r( | 7367 URLRequest r(test_server_.GetURLWithUserAndPassword( |
| 6849 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7368 "/LICENSE", "wrong_user", "chrome"), |
| 6850 "wrong_user", | 7369 DEFAULT_PRIORITY, |
| 6851 "chrome"), | 7370 &d, |
| 6852 &d, | 7371 &default_context_, |
| 6853 &default_context_); | 7372 &default_network_delegate_); |
| 6854 r.Start(); | 7373 r.Start(); |
| 6855 EXPECT_TRUE(r.is_pending()); | 7374 EXPECT_TRUE(r.is_pending()); |
| 6856 | 7375 |
| 6857 base::RunLoop().Run(); | 7376 base::RunLoop().Run(); |
| 6858 | 7377 |
| 6859 int64 file_size = 0; | 7378 int64 file_size = 0; |
| 6860 file_util::GetFileSize(app_path, &file_size); | 7379 file_util::GetFileSize(app_path, &file_size); |
| 6861 | 7380 |
| 6862 EXPECT_FALSE(r.is_pending()); | 7381 EXPECT_FALSE(r.is_pending()); |
| 6863 EXPECT_EQ(1, d.response_started_count()); | 7382 EXPECT_EQ(1, d.response_started_count()); |
| 6864 EXPECT_FALSE(d.received_data_before_response()); | 7383 EXPECT_FALSE(d.received_data_before_response()); |
| 6865 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7384 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 6866 } | 7385 } |
| 6867 } | 7386 } |
| 6868 | 7387 |
| 6869 // Flaky, see http://crbug.com/25045. | 7388 // Flaky, see http://crbug.com/25045. |
| 6870 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { | 7389 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { |
| 6871 ASSERT_TRUE(test_server_.Start()); | 7390 ASSERT_TRUE(test_server_.Start()); |
| 6872 | 7391 |
| 6873 base::FilePath app_path; | 7392 base::FilePath app_path; |
| 6874 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7393 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6875 app_path = app_path.AppendASCII("LICENSE"); | 7394 app_path = app_path.AppendASCII("LICENSE"); |
| 6876 | 7395 |
| 6877 scoped_ptr<TestDelegate> d(new TestDelegate); | 7396 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 6878 { | 7397 { |
| 6879 // Pass correct login identity in the URL. | 7398 // Pass correct login identity in the URL. |
| 6880 URLRequest r( | 7399 URLRequest r( |
| 6881 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7400 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 6882 "chrome", | 7401 DEFAULT_PRIORITY, |
| 6883 "chrome"), | |
| 6884 d.get(), | 7402 d.get(), |
| 6885 &default_context_); | 7403 &default_context_, |
| 7404 &default_network_delegate_); | |
| 6886 r.Start(); | 7405 r.Start(); |
| 6887 EXPECT_TRUE(r.is_pending()); | 7406 EXPECT_TRUE(r.is_pending()); |
| 6888 | 7407 |
| 6889 base::RunLoop().Run(); | 7408 base::RunLoop().Run(); |
| 6890 | 7409 |
| 6891 int64 file_size = 0; | 7410 int64 file_size = 0; |
| 6892 file_util::GetFileSize(app_path, &file_size); | 7411 file_util::GetFileSize(app_path, &file_size); |
| 6893 | 7412 |
| 6894 EXPECT_FALSE(r.is_pending()); | 7413 EXPECT_FALSE(r.is_pending()); |
| 6895 EXPECT_EQ(1, d->response_started_count()); | 7414 EXPECT_EQ(1, d->response_started_count()); |
| 6896 EXPECT_FALSE(d->received_data_before_response()); | 7415 EXPECT_FALSE(d->received_data_before_response()); |
| 6897 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7416 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 6898 } | 7417 } |
| 6899 | 7418 |
| 6900 d.reset(new TestDelegate); | 7419 d.reset(new TestDelegate); |
| 6901 { | 7420 { |
| 6902 // This request should use cached identity from previous request. | 7421 // This request should use cached identity from previous request. |
| 6903 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); | 7422 URLRequest r(test_server_.GetURL("/LICENSE"), |
| 7423 DEFAULT_PRIORITY, | |
| 7424 d.get(), | |
| 7425 &default_context_, | |
| 7426 &default_network_delegate_); | |
| 6904 r.Start(); | 7427 r.Start(); |
| 6905 EXPECT_TRUE(r.is_pending()); | 7428 EXPECT_TRUE(r.is_pending()); |
| 6906 | 7429 |
| 6907 base::RunLoop().Run(); | 7430 base::RunLoop().Run(); |
| 6908 | 7431 |
| 6909 int64 file_size = 0; | 7432 int64 file_size = 0; |
| 6910 file_util::GetFileSize(app_path, &file_size); | 7433 file_util::GetFileSize(app_path, &file_size); |
| 6911 | 7434 |
| 6912 EXPECT_FALSE(r.is_pending()); | 7435 EXPECT_FALSE(r.is_pending()); |
| 6913 EXPECT_EQ(1, d->response_started_count()); | 7436 EXPECT_EQ(1, d->response_started_count()); |
| 6914 EXPECT_FALSE(d->received_data_before_response()); | 7437 EXPECT_FALSE(d->received_data_before_response()); |
| 6915 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7438 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 6916 } | 7439 } |
| 6917 } | 7440 } |
| 6918 | 7441 |
| 6919 // Flaky, see http://crbug.com/25045. | 7442 // Flaky, see http://crbug.com/25045. |
| 6920 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { | 7443 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { |
| 6921 ASSERT_TRUE(test_server_.Start()); | 7444 ASSERT_TRUE(test_server_.Start()); |
| 6922 | 7445 |
| 6923 base::FilePath app_path; | 7446 base::FilePath app_path; |
| 6924 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7447 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 6925 app_path = app_path.AppendASCII("LICENSE"); | 7448 app_path = app_path.AppendASCII("LICENSE"); |
| 6926 | 7449 |
| 6927 scoped_ptr<TestDelegate> d(new TestDelegate); | 7450 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 6928 // Set correct login credentials. The delegate will be asked for them when | 7451 // Set correct login credentials. The delegate will be asked for them when |
| 6929 // the initial login with wrong credentials will fail. | 7452 // the initial login with wrong credentials will fail. |
| 6930 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 7453 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 6931 { | 7454 { |
| 6932 URLRequest r( | 7455 URLRequest r(test_server_.GetURLWithUserAndPassword( |
| 6933 test_server_.GetURLWithUserAndPassword("/LICENSE", | 7456 "/LICENSE", "chrome", "wrong_password"), |
| 6934 "chrome", | 7457 DEFAULT_PRIORITY, |
| 6935 "wrong_password"), | 7458 d.get(), |
| 6936 d.get(), | 7459 &default_context_, |
| 6937 &default_context_); | 7460 &default_network_delegate_); |
| 6938 r.Start(); | 7461 r.Start(); |
| 6939 EXPECT_TRUE(r.is_pending()); | 7462 EXPECT_TRUE(r.is_pending()); |
| 6940 | 7463 |
| 6941 base::RunLoop().Run(); | 7464 base::RunLoop().Run(); |
| 6942 | 7465 |
| 6943 int64 file_size = 0; | 7466 int64 file_size = 0; |
| 6944 file_util::GetFileSize(app_path, &file_size); | 7467 file_util::GetFileSize(app_path, &file_size); |
| 6945 | 7468 |
| 6946 EXPECT_FALSE(r.is_pending()); | 7469 EXPECT_FALSE(r.is_pending()); |
| 6947 EXPECT_EQ(1, d->response_started_count()); | 7470 EXPECT_EQ(1, d->response_started_count()); |
| 6948 EXPECT_FALSE(d->received_data_before_response()); | 7471 EXPECT_FALSE(d->received_data_before_response()); |
| 6949 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7472 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 6950 } | 7473 } |
| 6951 | 7474 |
| 6952 // Use a new delegate without explicit credentials. The cached ones should be | 7475 // Use a new delegate without explicit credentials. The cached ones should be |
| 6953 // used. | 7476 // used. |
| 6954 d.reset(new TestDelegate); | 7477 d.reset(new TestDelegate); |
| 6955 { | 7478 { |
| 6956 // Don't pass wrong credentials in the URL, they would override valid cached | 7479 // Don't pass wrong credentials in the URL, they would override valid cached |
| 6957 // ones. | 7480 // ones. |
| 6958 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); | 7481 URLRequest r(test_server_.GetURL("/LICENSE"), |
| 7482 DEFAULT_PRIORITY, | |
| 7483 d.get(), | |
| 7484 &default_context_, | |
| 7485 &default_network_delegate_); | |
| 6959 r.Start(); | 7486 r.Start(); |
| 6960 EXPECT_TRUE(r.is_pending()); | 7487 EXPECT_TRUE(r.is_pending()); |
| 6961 | 7488 |
| 6962 base::RunLoop().Run(); | 7489 base::RunLoop().Run(); |
| 6963 | 7490 |
| 6964 int64 file_size = 0; | 7491 int64 file_size = 0; |
| 6965 file_util::GetFileSize(app_path, &file_size); | 7492 file_util::GetFileSize(app_path, &file_size); |
| 6966 | 7493 |
| 6967 EXPECT_FALSE(r.is_pending()); | 7494 EXPECT_FALSE(r.is_pending()); |
| 6968 EXPECT_EQ(1, d->response_started_count()); | 7495 EXPECT_EQ(1, d->response_started_count()); |
| 6969 EXPECT_FALSE(d->received_data_before_response()); | 7496 EXPECT_FALSE(d->received_data_before_response()); |
| 6970 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7497 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 6971 } | 7498 } |
| 6972 } | 7499 } |
| 6973 #endif // !defined(DISABLE_FTP_SUPPORT) | 7500 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 6974 | 7501 |
| 6975 } // namespace net | 7502 } // namespace net |
| OLD | NEW |