| 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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 protected: | 627 protected: |
| 628 CapturingNetLog net_log_; | 628 CapturingNetLog net_log_; |
| 629 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 629 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 630 URLRequestJobFactoryImpl job_factory_; | 630 URLRequestJobFactoryImpl job_factory_; |
| 631 TestURLRequestContext default_context_; | 631 TestURLRequestContext default_context_; |
| 632 }; | 632 }; |
| 633 | 633 |
| 634 TEST_F(URLRequestTest, AboutBlankTest) { | 634 TEST_F(URLRequestTest, AboutBlankTest) { |
| 635 TestDelegate d; | 635 TestDelegate d; |
| 636 { | 636 { |
| 637 URLRequest r(GURL("about:blank"), DEFAULT_PRIORITY, &d, &default_context_); | 637 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 638 GURL("about:blank"), DEFAULT_PRIORITY, &d, NULL)); |
| 638 | 639 |
| 639 r.Start(); | 640 r->Start(); |
| 640 EXPECT_TRUE(r.is_pending()); | 641 EXPECT_TRUE(r->is_pending()); |
| 641 | 642 |
| 642 base::RunLoop().Run(); | 643 base::RunLoop().Run(); |
| 643 | 644 |
| 644 EXPECT_TRUE(!r.is_pending()); | 645 EXPECT_TRUE(!r->is_pending()); |
| 645 EXPECT_FALSE(d.received_data_before_response()); | 646 EXPECT_FALSE(d.received_data_before_response()); |
| 646 EXPECT_EQ(d.bytes_received(), 0); | 647 EXPECT_EQ(d.bytes_received(), 0); |
| 647 EXPECT_EQ("", r.GetSocketAddress().host()); | 648 EXPECT_EQ("", r->GetSocketAddress().host()); |
| 648 EXPECT_EQ(0, r.GetSocketAddress().port()); | 649 EXPECT_EQ(0, r->GetSocketAddress().port()); |
| 649 | 650 |
| 650 HttpRequestHeaders headers; | 651 HttpRequestHeaders headers; |
| 651 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 652 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 652 } | 653 } |
| 653 } | 654 } |
| 654 | 655 |
| 655 TEST_F(URLRequestTest, DataURLImageTest) { | 656 TEST_F(URLRequestTest, DataURLImageTest) { |
| 656 TestDelegate d; | 657 TestDelegate d; |
| 657 { | 658 { |
| 658 // Use our nice little Chrome logo. | 659 // Use our nice little Chrome logo. |
| 659 URLRequest r( | 660 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 660 GURL( | 661 GURL( |
| 661 "data:image/png;base64," | 662 "data:image/png;base64," |
| 662 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" | 663 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" |
| 663 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" | 664 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" |
| 664 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" | 665 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" |
| 665 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" | 666 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" |
| 666 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" | 667 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" |
| 667 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" | 668 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" |
| 668 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" | 669 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" |
| 669 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" | 670 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" |
| 670 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" | 671 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" |
| 671 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" | 672 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" |
| 672 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | 673 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" |
| 673 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | 674 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" |
| 674 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" | 675 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" |
| 675 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | 676 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" |
| 676 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 677 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" |
| 677 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 678 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" |
| 678 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 679 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" |
| 679 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 680 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
| 680 DEFAULT_PRIORITY, | 681 DEFAULT_PRIORITY, &d, NULL)); |
| 681 &d, | |
| 682 &default_context_); | |
| 683 | 682 |
| 684 r.Start(); | 683 r->Start(); |
| 685 EXPECT_TRUE(r.is_pending()); | 684 EXPECT_TRUE(r->is_pending()); |
| 686 | 685 |
| 687 base::RunLoop().Run(); | 686 base::RunLoop().Run(); |
| 688 | 687 |
| 689 EXPECT_TRUE(!r.is_pending()); | 688 EXPECT_TRUE(!r->is_pending()); |
| 690 EXPECT_FALSE(d.received_data_before_response()); | 689 EXPECT_FALSE(d.received_data_before_response()); |
| 691 EXPECT_EQ(d.bytes_received(), 911); | 690 EXPECT_EQ(d.bytes_received(), 911); |
| 692 EXPECT_EQ("", r.GetSocketAddress().host()); | 691 EXPECT_EQ("", r->GetSocketAddress().host()); |
| 693 EXPECT_EQ(0, r.GetSocketAddress().port()); | 692 EXPECT_EQ(0, r->GetSocketAddress().port()); |
| 694 | 693 |
| 695 HttpRequestHeaders headers; | 694 HttpRequestHeaders headers; |
| 696 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 695 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 697 } | 696 } |
| 698 } | 697 } |
| 699 | 698 |
| 700 #if !defined(DISABLE_FILE_SUPPORT) | 699 #if !defined(DISABLE_FILE_SUPPORT) |
| 701 TEST_F(URLRequestTest, FileTest) { | 700 TEST_F(URLRequestTest, FileTest) { |
| 702 base::FilePath app_path; | 701 base::FilePath app_path; |
| 703 PathService::Get(base::FILE_EXE, &app_path); | 702 PathService::Get(base::FILE_EXE, &app_path); |
| 704 GURL app_url = FilePathToFileURL(app_path); | 703 GURL app_url = FilePathToFileURL(app_path); |
| 705 | 704 |
| 706 TestDelegate d; | 705 TestDelegate d; |
| 707 { | 706 { |
| 708 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_); | 707 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 708 app_url, DEFAULT_PRIORITY, &d, NULL)); |
| 709 | 709 |
| 710 r.Start(); | 710 r->Start(); |
| 711 EXPECT_TRUE(r.is_pending()); | 711 EXPECT_TRUE(r->is_pending()); |
| 712 | 712 |
| 713 base::RunLoop().Run(); | 713 base::RunLoop().Run(); |
| 714 | 714 |
| 715 int64 file_size = -1; | 715 int64 file_size = -1; |
| 716 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); | 716 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); |
| 717 | 717 |
| 718 EXPECT_TRUE(!r.is_pending()); | 718 EXPECT_TRUE(!r->is_pending()); |
| 719 EXPECT_EQ(1, d.response_started_count()); | 719 EXPECT_EQ(1, d.response_started_count()); |
| 720 EXPECT_FALSE(d.received_data_before_response()); | 720 EXPECT_FALSE(d.received_data_before_response()); |
| 721 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 721 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 722 EXPECT_EQ("", r.GetSocketAddress().host()); | 722 EXPECT_EQ("", r->GetSocketAddress().host()); |
| 723 EXPECT_EQ(0, r.GetSocketAddress().port()); | 723 EXPECT_EQ(0, r->GetSocketAddress().port()); |
| 724 | 724 |
| 725 HttpRequestHeaders headers; | 725 HttpRequestHeaders headers; |
| 726 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 726 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 727 } | 727 } |
| 728 } | 728 } |
| 729 | 729 |
| 730 TEST_F(URLRequestTest, FileTestCancel) { | 730 TEST_F(URLRequestTest, FileTestCancel) { |
| 731 base::FilePath app_path; | 731 base::FilePath app_path; |
| 732 PathService::Get(base::FILE_EXE, &app_path); | 732 PathService::Get(base::FILE_EXE, &app_path); |
| 733 GURL app_url = FilePathToFileURL(app_path); | 733 GURL app_url = FilePathToFileURL(app_path); |
| 734 | 734 |
| 735 TestDelegate d; | 735 TestDelegate d; |
| 736 { | 736 { |
| 737 URLRequest r(app_url, DEFAULT_PRIORITY, &d, &default_context_); | 737 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 738 app_url, DEFAULT_PRIORITY, &d, NULL)); |
| 738 | 739 |
| 739 r.Start(); | 740 r->Start(); |
| 740 EXPECT_TRUE(r.is_pending()); | 741 EXPECT_TRUE(r->is_pending()); |
| 741 r.Cancel(); | 742 r->Cancel(); |
| 742 } | 743 } |
| 743 // Async cancellation should be safe even when URLRequest has been already | 744 // Async cancellation should be safe even when URLRequest has been already |
| 744 // destroyed. | 745 // destroyed. |
| 745 base::RunLoop().RunUntilIdle(); | 746 base::RunLoop().RunUntilIdle(); |
| 746 } | 747 } |
| 747 | 748 |
| 748 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { | 749 TEST_F(URLRequestTest, FileTestFullSpecifiedRange) { |
| 749 const size_t buffer_size = 4000; | 750 const size_t buffer_size = 4000; |
| 750 scoped_ptr<char[]> buffer(new char[buffer_size]); | 751 scoped_ptr<char[]> buffer(new char[buffer_size]); |
| 751 FillBuffer(buffer.get(), buffer_size); | 752 FillBuffer(buffer.get(), buffer_size); |
| 752 | 753 |
| 753 base::FilePath temp_path; | 754 base::FilePath temp_path; |
| 754 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 755 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 755 GURL temp_url = FilePathToFileURL(temp_path); | 756 GURL temp_url = FilePathToFileURL(temp_path); |
| 756 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); | 757 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 757 | 758 |
| 758 int64 file_size; | 759 int64 file_size; |
| 759 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 760 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 760 | 761 |
| 761 const size_t first_byte_position = 500; | 762 const size_t first_byte_position = 500; |
| 762 const size_t last_byte_position = buffer_size - first_byte_position; | 763 const size_t last_byte_position = buffer_size - first_byte_position; |
| 763 const size_t content_length = last_byte_position - first_byte_position + 1; | 764 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 764 std::string partial_buffer_string(buffer.get() + first_byte_position, | 765 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 765 buffer.get() + last_byte_position + 1); | 766 buffer.get() + last_byte_position + 1); |
| 766 | 767 |
| 767 TestDelegate d; | 768 TestDelegate d; |
| 768 { | 769 { |
| 769 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 770 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 771 temp_url, DEFAULT_PRIORITY, &d, NULL)); |
| 770 | 772 |
| 771 HttpRequestHeaders headers; | 773 HttpRequestHeaders headers; |
| 772 headers.SetHeader( | 774 headers.SetHeader( |
| 773 HttpRequestHeaders::kRange, | 775 HttpRequestHeaders::kRange, |
| 774 net::HttpByteRange::Bounded( | 776 net::HttpByteRange::Bounded( |
| 775 first_byte_position, last_byte_position).GetHeaderValue()); | 777 first_byte_position, last_byte_position).GetHeaderValue()); |
| 776 r.SetExtraRequestHeaders(headers); | 778 r->SetExtraRequestHeaders(headers); |
| 777 r.Start(); | 779 r->Start(); |
| 778 EXPECT_TRUE(r.is_pending()); | 780 EXPECT_TRUE(r->is_pending()); |
| 779 | 781 |
| 780 base::RunLoop().Run(); | 782 base::RunLoop().Run(); |
| 781 EXPECT_TRUE(!r.is_pending()); | 783 EXPECT_TRUE(!r->is_pending()); |
| 782 EXPECT_EQ(1, d.response_started_count()); | 784 EXPECT_EQ(1, d.response_started_count()); |
| 783 EXPECT_FALSE(d.received_data_before_response()); | 785 EXPECT_FALSE(d.received_data_before_response()); |
| 784 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 786 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 785 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 787 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| 786 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 788 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
| 787 } | 789 } |
| 788 | 790 |
| 789 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 791 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 790 } | 792 } |
| 791 | 793 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 803 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 805 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 804 | 806 |
| 805 const size_t first_byte_position = 500; | 807 const size_t first_byte_position = 500; |
| 806 const size_t last_byte_position = buffer_size - 1; | 808 const size_t last_byte_position = buffer_size - 1; |
| 807 const size_t content_length = last_byte_position - first_byte_position + 1; | 809 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 808 std::string partial_buffer_string(buffer.get() + first_byte_position, | 810 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 809 buffer.get() + last_byte_position + 1); | 811 buffer.get() + last_byte_position + 1); |
| 810 | 812 |
| 811 TestDelegate d; | 813 TestDelegate d; |
| 812 { | 814 { |
| 813 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 815 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 816 temp_url, DEFAULT_PRIORITY, &d, NULL)); |
| 814 | 817 |
| 815 HttpRequestHeaders headers; | 818 HttpRequestHeaders headers; |
| 816 headers.SetHeader(HttpRequestHeaders::kRange, | 819 headers.SetHeader(HttpRequestHeaders::kRange, |
| 817 net::HttpByteRange::RightUnbounded( | 820 net::HttpByteRange::RightUnbounded( |
| 818 first_byte_position).GetHeaderValue()); | 821 first_byte_position).GetHeaderValue()); |
| 819 r.SetExtraRequestHeaders(headers); | 822 r->SetExtraRequestHeaders(headers); |
| 820 r.Start(); | 823 r->Start(); |
| 821 EXPECT_TRUE(r.is_pending()); | 824 EXPECT_TRUE(r->is_pending()); |
| 822 | 825 |
| 823 base::RunLoop().Run(); | 826 base::RunLoop().Run(); |
| 824 EXPECT_TRUE(!r.is_pending()); | 827 EXPECT_TRUE(!r->is_pending()); |
| 825 EXPECT_EQ(1, d.response_started_count()); | 828 EXPECT_EQ(1, d.response_started_count()); |
| 826 EXPECT_FALSE(d.received_data_before_response()); | 829 EXPECT_FALSE(d.received_data_before_response()); |
| 827 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); | 830 EXPECT_EQ(static_cast<int>(content_length), d.bytes_received()); |
| 828 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. | 831 // Don't use EXPECT_EQ, it will print out a lot of garbage if check failed. |
| 829 EXPECT_TRUE(partial_buffer_string == d.data_received()); | 832 EXPECT_TRUE(partial_buffer_string == d.data_received()); |
| 830 } | 833 } |
| 831 | 834 |
| 832 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 835 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 833 } | 836 } |
| 834 | 837 |
| 835 TEST_F(URLRequestTest, FileTestMultipleRanges) { | 838 TEST_F(URLRequestTest, FileTestMultipleRanges) { |
| 836 const size_t buffer_size = 400000; | 839 const size_t buffer_size = 400000; |
| 837 scoped_ptr<char[]> buffer(new char[buffer_size]); | 840 scoped_ptr<char[]> buffer(new char[buffer_size]); |
| 838 FillBuffer(buffer.get(), buffer_size); | 841 FillBuffer(buffer.get(), buffer_size); |
| 839 | 842 |
| 840 base::FilePath temp_path; | 843 base::FilePath temp_path; |
| 841 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 844 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 842 GURL temp_url = FilePathToFileURL(temp_path); | 845 GURL temp_url = FilePathToFileURL(temp_path); |
| 843 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); | 846 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 844 | 847 |
| 845 int64 file_size; | 848 int64 file_size; |
| 846 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 849 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 847 | 850 |
| 848 TestDelegate d; | 851 TestDelegate d; |
| 849 { | 852 { |
| 850 URLRequest r(temp_url, DEFAULT_PRIORITY, &d, &default_context_); | 853 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 854 temp_url, DEFAULT_PRIORITY, &d, NULL)); |
| 851 | 855 |
| 852 HttpRequestHeaders headers; | 856 HttpRequestHeaders headers; |
| 853 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); | 857 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); |
| 854 r.SetExtraRequestHeaders(headers); | 858 r->SetExtraRequestHeaders(headers); |
| 855 r.Start(); | 859 r->Start(); |
| 856 EXPECT_TRUE(r.is_pending()); | 860 EXPECT_TRUE(r->is_pending()); |
| 857 | 861 |
| 858 base::RunLoop().Run(); | 862 base::RunLoop().Run(); |
| 859 EXPECT_TRUE(d.request_failed()); | 863 EXPECT_TRUE(d.request_failed()); |
| 860 } | 864 } |
| 861 | 865 |
| 862 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 866 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 863 } | 867 } |
| 864 | 868 |
| 865 TEST_F(URLRequestTest, AllowFileURLs) { | 869 TEST_F(URLRequestTest, AllowFileURLs) { |
| 866 base::ScopedTempDir temp_dir; | 870 base::ScopedTempDir temp_dir; |
| 867 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 871 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 868 base::FilePath test_file; | 872 base::FilePath test_file; |
| 869 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); | 873 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); |
| 870 std::string test_data("monkey"); | 874 std::string test_data("monkey"); |
| 871 base::WriteFile(test_file, test_data.data(), test_data.size()); | 875 base::WriteFile(test_file, test_data.data(), test_data.size()); |
| 872 GURL test_file_url = net::FilePathToFileURL(test_file); | 876 GURL test_file_url = net::FilePathToFileURL(test_file); |
| 873 | 877 |
| 874 { | 878 { |
| 875 TestDelegate d; | 879 TestDelegate d; |
| 876 TestNetworkDelegate network_delegate; | 880 TestNetworkDelegate network_delegate; |
| 877 network_delegate.set_can_access_files(true); | 881 network_delegate.set_can_access_files(true); |
| 878 default_context_.set_network_delegate(&network_delegate); | 882 default_context_.set_network_delegate(&network_delegate); |
| 879 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); | 883 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 880 r.Start(); | 884 test_file_url, DEFAULT_PRIORITY, &d, NULL)); |
| 885 r->Start(); |
| 881 base::RunLoop().Run(); | 886 base::RunLoop().Run(); |
| 882 EXPECT_FALSE(d.request_failed()); | 887 EXPECT_FALSE(d.request_failed()); |
| 883 EXPECT_EQ(test_data, d.data_received()); | 888 EXPECT_EQ(test_data, d.data_received()); |
| 884 } | 889 } |
| 885 | 890 |
| 886 { | 891 { |
| 887 TestDelegate d; | 892 TestDelegate d; |
| 888 TestNetworkDelegate network_delegate; | 893 TestNetworkDelegate network_delegate; |
| 889 network_delegate.set_can_access_files(false); | 894 network_delegate.set_can_access_files(false); |
| 890 default_context_.set_network_delegate(&network_delegate); | 895 default_context_.set_network_delegate(&network_delegate); |
| 891 URLRequest r(test_file_url, DEFAULT_PRIORITY, &d, &default_context_); | 896 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 892 r.Start(); | 897 test_file_url, DEFAULT_PRIORITY, &d, NULL)); |
| 898 r->Start(); |
| 893 base::RunLoop().Run(); | 899 base::RunLoop().Run(); |
| 894 EXPECT_TRUE(d.request_failed()); | 900 EXPECT_TRUE(d.request_failed()); |
| 895 EXPECT_EQ("", d.data_received()); | 901 EXPECT_EQ("", d.data_received()); |
| 896 } | 902 } |
| 897 } | 903 } |
| 898 | 904 |
| 899 | 905 |
| 900 TEST_F(URLRequestTest, FileDirCancelTest) { | 906 TEST_F(URLRequestTest, FileDirCancelTest) { |
| 901 // Put in mock resource provider. | 907 // Put in mock resource provider. |
| 902 NetModule::SetResourceProvider(TestNetResourceProvider); | 908 NetModule::SetResourceProvider(TestNetResourceProvider); |
| 903 | 909 |
| 904 TestDelegate d; | 910 TestDelegate d; |
| 905 { | 911 { |
| 906 base::FilePath file_path; | 912 base::FilePath file_path; |
| 907 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 913 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
| 908 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 914 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
| 909 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 915 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
| 910 | 916 |
| 911 URLRequest req( | 917 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 912 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, &default_context_); | 918 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, NULL)); |
| 913 req.Start(); | 919 req->Start(); |
| 914 EXPECT_TRUE(req.is_pending()); | 920 EXPECT_TRUE(req->is_pending()); |
| 915 | 921 |
| 916 d.set_cancel_in_received_data_pending(true); | 922 d.set_cancel_in_received_data_pending(true); |
| 917 | 923 |
| 918 base::RunLoop().Run(); | 924 base::RunLoop().Run(); |
| 919 } | 925 } |
| 920 | 926 |
| 921 // Take out mock resource provider. | 927 // Take out mock resource provider. |
| 922 NetModule::SetResourceProvider(NULL); | 928 NetModule::SetResourceProvider(NULL); |
| 923 } | 929 } |
| 924 | 930 |
| 925 TEST_F(URLRequestTest, FileDirOutputSanity) { | 931 TEST_F(URLRequestTest, FileDirOutputSanity) { |
| 926 // Verify the general sanity of the the output of the file: | 932 // Verify the general sanity of the the output of the file: |
| 927 // directory lister by checking for the output of a known existing | 933 // directory lister by checking for the output of a known existing |
| 928 // file. | 934 // file. |
| 929 const char sentinel_name[] = "filedir-sentinel"; | 935 const char sentinel_name[] = "filedir-sentinel"; |
| 930 | 936 |
| 931 base::FilePath path; | 937 base::FilePath path; |
| 932 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 938 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 933 path = path.Append(FILE_PATH_LITERAL("net")); | 939 path = path.Append(FILE_PATH_LITERAL("net")); |
| 934 path = path.Append(FILE_PATH_LITERAL("data")); | 940 path = path.Append(FILE_PATH_LITERAL("data")); |
| 935 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 941 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 936 | 942 |
| 937 TestDelegate d; | 943 TestDelegate d; |
| 938 URLRequest req( | 944 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 939 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_); | 945 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL)); |
| 940 req.Start(); | 946 req->Start(); |
| 941 base::RunLoop().Run(); | 947 base::RunLoop().Run(); |
| 942 | 948 |
| 943 // Generate entry for the sentinel file. | 949 // Generate entry for the sentinel file. |
| 944 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); | 950 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); |
| 945 base::File::Info info; | 951 base::File::Info info; |
| 946 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); | 952 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); |
| 947 EXPECT_GT(info.size, 0); | 953 EXPECT_GT(info.size, 0); |
| 948 std::string sentinel_output = GetDirectoryListingEntry( | 954 std::string sentinel_output = GetDirectoryListingEntry( |
| 949 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), | 955 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), |
| 950 std::string(sentinel_name), | 956 std::string(sentinel_name), |
| 951 false /* is_dir */, | 957 false /* is_dir */, |
| 952 info.size, | 958 info.size, |
| 953 info.last_modified); | 959 info.last_modified); |
| 954 | 960 |
| 955 ASSERT_LT(0, d.bytes_received()); | 961 ASSERT_LT(0, d.bytes_received()); |
| 956 ASSERT_FALSE(d.request_failed()); | 962 ASSERT_FALSE(d.request_failed()); |
| 957 ASSERT_TRUE(req.status().is_success()); | 963 ASSERT_TRUE(req->status().is_success()); |
| 958 // Check for the entry generated for the "sentinel" file. | 964 // Check for the entry generated for the "sentinel" file. |
| 959 const std::string& data = d.data_received(); | 965 const std::string& data = d.data_received(); |
| 960 ASSERT_NE(data.find(sentinel_output), std::string::npos); | 966 ASSERT_NE(data.find(sentinel_output), std::string::npos); |
| 961 } | 967 } |
| 962 | 968 |
| 963 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 969 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 964 // There is an implicit redirect when loading a file path that matches a | 970 // There is an implicit redirect when loading a file path that matches a |
| 965 // directory and does not end with a slash. Ensure that following such | 971 // directory and does not end with a slash. Ensure that following such |
| 966 // redirects does not crash. See http://crbug.com/18686. | 972 // redirects does not crash. See http://crbug.com/18686. |
| 967 | 973 |
| 968 base::FilePath path; | 974 base::FilePath path; |
| 969 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 975 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 970 path = path.Append(FILE_PATH_LITERAL("net")); | 976 path = path.Append(FILE_PATH_LITERAL("net")); |
| 971 path = path.Append(FILE_PATH_LITERAL("data")); | 977 path = path.Append(FILE_PATH_LITERAL("data")); |
| 972 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 978 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 973 | 979 |
| 974 TestDelegate d; | 980 TestDelegate d; |
| 975 URLRequest req( | 981 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 976 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, &default_context_); | 982 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL)); |
| 977 req.Start(); | 983 req->Start(); |
| 978 base::RunLoop().Run(); | 984 base::RunLoop().Run(); |
| 979 | 985 |
| 980 ASSERT_EQ(1, d.received_redirect_count()); | 986 ASSERT_EQ(1, d.received_redirect_count()); |
| 981 ASSERT_LT(0, d.bytes_received()); | 987 ASSERT_LT(0, d.bytes_received()); |
| 982 ASSERT_FALSE(d.request_failed()); | 988 ASSERT_FALSE(d.request_failed()); |
| 983 ASSERT_TRUE(req.status().is_success()); | 989 ASSERT_TRUE(req->status().is_success()); |
| 984 } | 990 } |
| 985 | 991 |
| 986 #if defined(OS_WIN) | 992 #if defined(OS_WIN) |
| 987 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 993 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 988 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 994 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 989 TestDelegate d; | 995 TestDelegate d; |
| 990 URLRequest req(GURL("file:///"), DEFAULT_PRIORITY, &d, &default_context_); | 996 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 991 req.Start(); | 997 GURL("file:///"), DEFAULT_PRIORITY, &d, NULL)); |
| 998 req->Start(); |
| 992 base::RunLoop().Run(); | 999 base::RunLoop().Run(); |
| 993 | 1000 |
| 994 ASSERT_EQ(1, d.received_redirect_count()); | 1001 ASSERT_EQ(1, d.received_redirect_count()); |
| 995 ASSERT_FALSE(req.status().is_success()); | 1002 ASSERT_FALSE(req->status().is_success()); |
| 996 } | 1003 } |
| 997 #endif // defined(OS_WIN) | 1004 #endif // defined(OS_WIN) |
| 998 | 1005 |
| 999 #endif // !defined(DISABLE_FILE_SUPPORT) | 1006 #endif // !defined(DISABLE_FILE_SUPPORT) |
| 1000 | 1007 |
| 1001 TEST_F(URLRequestTest, InvalidUrlTest) { | 1008 TEST_F(URLRequestTest, InvalidUrlTest) { |
| 1002 TestDelegate d; | 1009 TestDelegate d; |
| 1003 { | 1010 { |
| 1004 URLRequest r(GURL("invalid url"), DEFAULT_PRIORITY, &d, &default_context_); | 1011 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1012 GURL("invalid url"), DEFAULT_PRIORITY, &d, NULL)); |
| 1005 | 1013 |
| 1006 r.Start(); | 1014 r->Start(); |
| 1007 EXPECT_TRUE(r.is_pending()); | 1015 EXPECT_TRUE(r->is_pending()); |
| 1008 | 1016 |
| 1009 base::RunLoop().Run(); | 1017 base::RunLoop().Run(); |
| 1010 EXPECT_TRUE(d.request_failed()); | 1018 EXPECT_TRUE(d.request_failed()); |
| 1011 } | 1019 } |
| 1012 } | 1020 } |
| 1013 | 1021 |
| 1014 #if defined(OS_WIN) | 1022 #if defined(OS_WIN) |
| 1015 TEST_F(URLRequestTest, ResolveShortcutTest) { | 1023 TEST_F(URLRequestTest, ResolveShortcutTest) { |
| 1016 base::FilePath app_path; | 1024 base::FilePath app_path; |
| 1017 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 1025 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1031 CLSCTX_INPROC_SERVER))); | 1039 CLSCTX_INPROC_SERVER))); |
| 1032 base::win::ScopedComPtr<IPersistFile> persist; | 1040 base::win::ScopedComPtr<IPersistFile> persist; |
| 1033 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); | 1041 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); |
| 1034 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); | 1042 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); |
| 1035 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); | 1043 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); |
| 1036 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); | 1044 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); |
| 1037 } | 1045 } |
| 1038 | 1046 |
| 1039 TestDelegate d; | 1047 TestDelegate d; |
| 1040 { | 1048 { |
| 1041 URLRequest r(FilePathToFileURL(base::FilePath(lnk_path)), | 1049 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1042 DEFAULT_PRIORITY, | 1050 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d, |
| 1043 &d, | 1051 NULL)); |
| 1044 &default_context_); | |
| 1045 | 1052 |
| 1046 r.Start(); | 1053 r->Start(); |
| 1047 EXPECT_TRUE(r.is_pending()); | 1054 EXPECT_TRUE(r->is_pending()); |
| 1048 | 1055 |
| 1049 base::RunLoop().Run(); | 1056 base::RunLoop().Run(); |
| 1050 | 1057 |
| 1051 WIN32_FILE_ATTRIBUTE_DATA data; | 1058 WIN32_FILE_ATTRIBUTE_DATA data; |
| 1052 GetFileAttributesEx(app_path.value().c_str(), | 1059 GetFileAttributesEx(app_path.value().c_str(), |
| 1053 GetFileExInfoStandard, &data); | 1060 GetFileExInfoStandard, &data); |
| 1054 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 1061 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
| 1055 FILE_SHARE_READ, NULL, OPEN_EXISTING, | 1062 FILE_SHARE_READ, NULL, OPEN_EXISTING, |
| 1056 FILE_ATTRIBUTE_NORMAL, NULL); | 1063 FILE_ATTRIBUTE_NORMAL, NULL); |
| 1057 EXPECT_NE(INVALID_HANDLE_VALUE, file); | 1064 EXPECT_NE(INVALID_HANDLE_VALUE, file); |
| 1058 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); | 1065 scoped_ptr<char[]> buffer(new char[data.nFileSizeLow]); |
| 1059 DWORD read_size; | 1066 DWORD read_size; |
| 1060 BOOL result; | 1067 BOOL result; |
| 1061 result = ReadFile(file, buffer.get(), data.nFileSizeLow, | 1068 result = ReadFile(file, buffer.get(), data.nFileSizeLow, |
| 1062 &read_size, NULL); | 1069 &read_size, NULL); |
| 1063 std::string content(buffer.get(), read_size); | 1070 std::string content(buffer.get(), read_size); |
| 1064 CloseHandle(file); | 1071 CloseHandle(file); |
| 1065 | 1072 |
| 1066 EXPECT_TRUE(!r.is_pending()); | 1073 EXPECT_TRUE(!r->is_pending()); |
| 1067 EXPECT_EQ(1, d.received_redirect_count()); | 1074 EXPECT_EQ(1, d.received_redirect_count()); |
| 1068 EXPECT_EQ(content, d.data_received()); | 1075 EXPECT_EQ(content, d.data_received()); |
| 1069 } | 1076 } |
| 1070 | 1077 |
| 1071 // Clean the shortcut | 1078 // Clean the shortcut |
| 1072 DeleteFile(lnk_path.c_str()); | 1079 DeleteFile(lnk_path.c_str()); |
| 1073 } | 1080 } |
| 1074 #endif // defined(OS_WIN) | 1081 #endif // defined(OS_WIN) |
| 1075 | 1082 |
| 1076 // Custom URLRequestJobs for use with interceptor tests | 1083 // Custom URLRequestJobs for use with interceptor tests |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 | 1285 |
| 1279 TEST_F(URLRequestTest, Intercept) { | 1286 TEST_F(URLRequestTest, Intercept) { |
| 1280 TestInterceptor interceptor; | 1287 TestInterceptor interceptor; |
| 1281 | 1288 |
| 1282 // intercept the main request and respond with a simple response | 1289 // intercept the main request and respond with a simple response |
| 1283 interceptor.intercept_main_request_ = true; | 1290 interceptor.intercept_main_request_ = true; |
| 1284 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 1291 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 1285 interceptor.main_data_ = TestInterceptor::ok_data(); | 1292 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 1286 | 1293 |
| 1287 TestDelegate d; | 1294 TestDelegate d; |
| 1288 URLRequest req(GURL("http://test_intercept/foo"), | 1295 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1289 DEFAULT_PRIORITY, | 1296 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1290 &d, | |
| 1291 &default_context_); | |
| 1292 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 1297 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
| 1293 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 1298 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
| 1294 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 1299 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
| 1295 req.SetUserData(NULL, user_data0); | 1300 req->SetUserData(NULL, user_data0); |
| 1296 req.SetUserData(&user_data1, user_data1); | 1301 req->SetUserData(&user_data1, user_data1); |
| 1297 req.SetUserData(&user_data2, user_data2); | 1302 req->SetUserData(&user_data2, user_data2); |
| 1298 req.set_method("GET"); | 1303 req->set_method("GET"); |
| 1299 req.Start(); | 1304 req->Start(); |
| 1300 base::RunLoop().Run(); | 1305 base::RunLoop().Run(); |
| 1301 | 1306 |
| 1302 // Make sure we can retrieve our specific user data | 1307 // Make sure we can retrieve our specific user data |
| 1303 EXPECT_EQ(user_data0, req.GetUserData(NULL)); | 1308 EXPECT_EQ(user_data0, req->GetUserData(NULL)); |
| 1304 EXPECT_EQ(user_data1, req.GetUserData(&user_data1)); | 1309 EXPECT_EQ(user_data1, req->GetUserData(&user_data1)); |
| 1305 EXPECT_EQ(user_data2, req.GetUserData(&user_data2)); | 1310 EXPECT_EQ(user_data2, req->GetUserData(&user_data2)); |
| 1306 | 1311 |
| 1307 // Check the interceptor got called as expected | 1312 // Check the interceptor got called as expected |
| 1308 EXPECT_TRUE(interceptor.did_intercept_main_); | 1313 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1309 | 1314 |
| 1310 // Check we got one good response | 1315 // Check we got one good response |
| 1311 EXPECT_TRUE(req.status().is_success()); | 1316 EXPECT_TRUE(req->status().is_success()); |
| 1312 EXPECT_EQ(200, req.response_headers()->response_code()); | 1317 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1313 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1318 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1314 EXPECT_EQ(1, d.response_started_count()); | 1319 EXPECT_EQ(1, d.response_started_count()); |
| 1315 EXPECT_EQ(0, d.received_redirect_count()); | 1320 EXPECT_EQ(0, d.received_redirect_count()); |
| 1316 } | 1321 } |
| 1317 | 1322 |
| 1318 TEST_F(URLRequestTest, InterceptRedirect) { | 1323 TEST_F(URLRequestTest, InterceptRedirect) { |
| 1319 TestInterceptor interceptor; | 1324 TestInterceptor interceptor; |
| 1320 | 1325 |
| 1321 // intercept the main request and respond with a redirect | 1326 // intercept the main request and respond with a redirect |
| 1322 interceptor.intercept_main_request_ = true; | 1327 interceptor.intercept_main_request_ = true; |
| 1323 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 1328 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 1324 interceptor.main_data_ = TestInterceptor::redirect_data(); | 1329 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 1325 | 1330 |
| 1326 // intercept that redirect and respond a final OK response | 1331 // intercept that redirect and respond a final OK response |
| 1327 interceptor.intercept_redirect_ = true; | 1332 interceptor.intercept_redirect_ = true; |
| 1328 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 1333 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
| 1329 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 1334 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
| 1330 | 1335 |
| 1331 TestDelegate d; | 1336 TestDelegate d; |
| 1332 URLRequest req(GURL("http://test_intercept/foo"), | 1337 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1333 DEFAULT_PRIORITY, | 1338 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1334 &d, | 1339 req->set_method("GET"); |
| 1335 &default_context_); | 1340 req->Start(); |
| 1336 req.set_method("GET"); | |
| 1337 req.Start(); | |
| 1338 base::RunLoop().Run(); | 1341 base::RunLoop().Run(); |
| 1339 | 1342 |
| 1340 // Check the interceptor got called as expected | 1343 // Check the interceptor got called as expected |
| 1341 EXPECT_TRUE(interceptor.did_intercept_main_); | 1344 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1342 EXPECT_TRUE(interceptor.did_intercept_redirect_); | 1345 EXPECT_TRUE(interceptor.did_intercept_redirect_); |
| 1343 | 1346 |
| 1344 // Check we got one good response | 1347 // Check we got one good response |
| 1345 EXPECT_TRUE(req.status().is_success()); | 1348 EXPECT_TRUE(req->status().is_success()); |
| 1346 if (req.status().is_success()) { | 1349 if (req->status().is_success()) { |
| 1347 EXPECT_EQ(200, req.response_headers()->response_code()); | 1350 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1348 } | 1351 } |
| 1349 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1352 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1350 EXPECT_EQ(1, d.response_started_count()); | 1353 EXPECT_EQ(1, d.response_started_count()); |
| 1351 EXPECT_EQ(0, d.received_redirect_count()); | 1354 EXPECT_EQ(0, d.received_redirect_count()); |
| 1352 } | 1355 } |
| 1353 | 1356 |
| 1354 TEST_F(URLRequestTest, InterceptServerError) { | 1357 TEST_F(URLRequestTest, InterceptServerError) { |
| 1355 TestInterceptor interceptor; | 1358 TestInterceptor interceptor; |
| 1356 | 1359 |
| 1357 // intercept the main request to generate a server error response | 1360 // intercept the main request to generate a server error response |
| 1358 interceptor.intercept_main_request_ = true; | 1361 interceptor.intercept_main_request_ = true; |
| 1359 interceptor.main_headers_ = TestInterceptor::error_headers(); | 1362 interceptor.main_headers_ = TestInterceptor::error_headers(); |
| 1360 interceptor.main_data_ = TestInterceptor::error_data(); | 1363 interceptor.main_data_ = TestInterceptor::error_data(); |
| 1361 | 1364 |
| 1362 // intercept that error and respond with an OK response | 1365 // intercept that error and respond with an OK response |
| 1363 interceptor.intercept_final_response_ = true; | 1366 interceptor.intercept_final_response_ = true; |
| 1364 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1367 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1365 interceptor.final_data_ = TestInterceptor::ok_data(); | 1368 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1366 | 1369 |
| 1367 TestDelegate d; | 1370 TestDelegate d; |
| 1368 URLRequest req(GURL("http://test_intercept/foo"), | 1371 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1369 DEFAULT_PRIORITY, | 1372 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1370 &d, | 1373 req->set_method("GET"); |
| 1371 &default_context_); | 1374 req->Start(); |
| 1372 req.set_method("GET"); | |
| 1373 req.Start(); | |
| 1374 base::RunLoop().Run(); | 1375 base::RunLoop().Run(); |
| 1375 | 1376 |
| 1376 // Check the interceptor got called as expected | 1377 // Check the interceptor got called as expected |
| 1377 EXPECT_TRUE(interceptor.did_intercept_main_); | 1378 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1378 EXPECT_TRUE(interceptor.did_intercept_final_); | 1379 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 1379 | 1380 |
| 1380 // Check we got one good response | 1381 // Check we got one good response |
| 1381 EXPECT_TRUE(req.status().is_success()); | 1382 EXPECT_TRUE(req->status().is_success()); |
| 1382 EXPECT_EQ(200, req.response_headers()->response_code()); | 1383 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1383 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1384 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1384 EXPECT_EQ(1, d.response_started_count()); | 1385 EXPECT_EQ(1, d.response_started_count()); |
| 1385 EXPECT_EQ(0, d.received_redirect_count()); | 1386 EXPECT_EQ(0, d.received_redirect_count()); |
| 1386 } | 1387 } |
| 1387 | 1388 |
| 1388 TEST_F(URLRequestTest, InterceptNetworkError) { | 1389 TEST_F(URLRequestTest, InterceptNetworkError) { |
| 1389 TestInterceptor interceptor; | 1390 TestInterceptor interceptor; |
| 1390 | 1391 |
| 1391 // intercept the main request to simulate a network error | 1392 // intercept the main request to simulate a network error |
| 1392 interceptor.simulate_main_network_error_ = true; | 1393 interceptor.simulate_main_network_error_ = true; |
| 1393 | 1394 |
| 1394 // intercept that error and respond with an OK response | 1395 // intercept that error and respond with an OK response |
| 1395 interceptor.intercept_final_response_ = true; | 1396 interceptor.intercept_final_response_ = true; |
| 1396 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1397 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1397 interceptor.final_data_ = TestInterceptor::ok_data(); | 1398 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1398 | 1399 |
| 1399 TestDelegate d; | 1400 TestDelegate d; |
| 1400 URLRequest req(GURL("http://test_intercept/foo"), | 1401 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1401 DEFAULT_PRIORITY, | 1402 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1402 &d, | 1403 req->set_method("GET"); |
| 1403 &default_context_); | 1404 req->Start(); |
| 1404 req.set_method("GET"); | |
| 1405 req.Start(); | |
| 1406 base::RunLoop().Run(); | 1405 base::RunLoop().Run(); |
| 1407 | 1406 |
| 1408 // Check the interceptor got called as expected | 1407 // Check the interceptor got called as expected |
| 1409 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1408 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 1410 EXPECT_TRUE(interceptor.did_intercept_final_); | 1409 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 1411 | 1410 |
| 1412 // Check we received one good response | 1411 // Check we received one good response |
| 1413 EXPECT_TRUE(req.status().is_success()); | 1412 EXPECT_TRUE(req->status().is_success()); |
| 1414 EXPECT_EQ(200, req.response_headers()->response_code()); | 1413 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1415 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1414 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1416 EXPECT_EQ(1, d.response_started_count()); | 1415 EXPECT_EQ(1, d.response_started_count()); |
| 1417 EXPECT_EQ(0, d.received_redirect_count()); | 1416 EXPECT_EQ(0, d.received_redirect_count()); |
| 1418 } | 1417 } |
| 1419 | 1418 |
| 1420 TEST_F(URLRequestTest, InterceptRestartRequired) { | 1419 TEST_F(URLRequestTest, InterceptRestartRequired) { |
| 1421 TestInterceptor interceptor; | 1420 TestInterceptor interceptor; |
| 1422 | 1421 |
| 1423 // restart the main request | 1422 // restart the main request |
| 1424 interceptor.restart_main_request_ = true; | 1423 interceptor.restart_main_request_ = true; |
| 1425 | 1424 |
| 1426 // then intercept the new main request and respond with an OK response | 1425 // then intercept the new main request and respond with an OK response |
| 1427 interceptor.intercept_main_request_ = true; | 1426 interceptor.intercept_main_request_ = true; |
| 1428 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 1427 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 1429 interceptor.main_data_ = TestInterceptor::ok_data(); | 1428 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 1430 | 1429 |
| 1431 TestDelegate d; | 1430 TestDelegate d; |
| 1432 URLRequest req(GURL("http://test_intercept/foo"), | 1431 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1433 DEFAULT_PRIORITY, | 1432 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1434 &d, | 1433 req->set_method("GET"); |
| 1435 &default_context_); | 1434 req->Start(); |
| 1436 req.set_method("GET"); | |
| 1437 req.Start(); | |
| 1438 base::RunLoop().Run(); | 1435 base::RunLoop().Run(); |
| 1439 | 1436 |
| 1440 // Check the interceptor got called as expected | 1437 // Check the interceptor got called as expected |
| 1441 EXPECT_TRUE(interceptor.did_restart_main_); | 1438 EXPECT_TRUE(interceptor.did_restart_main_); |
| 1442 EXPECT_TRUE(interceptor.did_intercept_main_); | 1439 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1443 | 1440 |
| 1444 // Check we received one good response | 1441 // Check we received one good response |
| 1445 EXPECT_TRUE(req.status().is_success()); | 1442 EXPECT_TRUE(req->status().is_success()); |
| 1446 if (req.status().is_success()) { | 1443 if (req->status().is_success()) { |
| 1447 EXPECT_EQ(200, req.response_headers()->response_code()); | 1444 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1448 } | 1445 } |
| 1449 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 1446 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 1450 EXPECT_EQ(1, d.response_started_count()); | 1447 EXPECT_EQ(1, d.response_started_count()); |
| 1451 EXPECT_EQ(0, d.received_redirect_count()); | 1448 EXPECT_EQ(0, d.received_redirect_count()); |
| 1452 } | 1449 } |
| 1453 | 1450 |
| 1454 TEST_F(URLRequestTest, InterceptRespectsCancelMain) { | 1451 TEST_F(URLRequestTest, InterceptRespectsCancelMain) { |
| 1455 TestInterceptor interceptor; | 1452 TestInterceptor interceptor; |
| 1456 | 1453 |
| 1457 // intercept the main request and cancel from within the restarted job | 1454 // intercept the main request and cancel from within the restarted job |
| 1458 interceptor.cancel_main_request_ = true; | 1455 interceptor.cancel_main_request_ = true; |
| 1459 | 1456 |
| 1460 // setup to intercept final response and override it with an OK response | 1457 // setup to intercept final response and override it with an OK response |
| 1461 interceptor.intercept_final_response_ = true; | 1458 interceptor.intercept_final_response_ = true; |
| 1462 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1459 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1463 interceptor.final_data_ = TestInterceptor::ok_data(); | 1460 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1464 | 1461 |
| 1465 TestDelegate d; | 1462 TestDelegate d; |
| 1466 URLRequest req(GURL("http://test_intercept/foo"), | 1463 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1467 DEFAULT_PRIORITY, | 1464 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1468 &d, | 1465 req->set_method("GET"); |
| 1469 &default_context_); | 1466 req->Start(); |
| 1470 req.set_method("GET"); | |
| 1471 req.Start(); | |
| 1472 base::RunLoop().Run(); | 1467 base::RunLoop().Run(); |
| 1473 | 1468 |
| 1474 // Check the interceptor got called as expected | 1469 // Check the interceptor got called as expected |
| 1475 EXPECT_TRUE(interceptor.did_cancel_main_); | 1470 EXPECT_TRUE(interceptor.did_cancel_main_); |
| 1476 EXPECT_FALSE(interceptor.did_intercept_final_); | 1471 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1477 | 1472 |
| 1478 // Check we see a canceled request | 1473 // Check we see a canceled request |
| 1479 EXPECT_FALSE(req.status().is_success()); | 1474 EXPECT_FALSE(req->status().is_success()); |
| 1480 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1475 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 1481 } | 1476 } |
| 1482 | 1477 |
| 1483 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { | 1478 TEST_F(URLRequestTest, InterceptRespectsCancelRedirect) { |
| 1484 TestInterceptor interceptor; | 1479 TestInterceptor interceptor; |
| 1485 | 1480 |
| 1486 // intercept the main request and respond with a redirect | 1481 // intercept the main request and respond with a redirect |
| 1487 interceptor.intercept_main_request_ = true; | 1482 interceptor.intercept_main_request_ = true; |
| 1488 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 1483 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 1489 interceptor.main_data_ = TestInterceptor::redirect_data(); | 1484 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 1490 | 1485 |
| 1491 // intercept the redirect and cancel from within that job | 1486 // intercept the redirect and cancel from within that job |
| 1492 interceptor.cancel_redirect_request_ = true; | 1487 interceptor.cancel_redirect_request_ = true; |
| 1493 | 1488 |
| 1494 // setup to intercept final response and override it with an OK response | 1489 // setup to intercept final response and override it with an OK response |
| 1495 interceptor.intercept_final_response_ = true; | 1490 interceptor.intercept_final_response_ = true; |
| 1496 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1491 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1497 interceptor.final_data_ = TestInterceptor::ok_data(); | 1492 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1498 | 1493 |
| 1499 TestDelegate d; | 1494 TestDelegate d; |
| 1500 URLRequest req(GURL("http://test_intercept/foo"), | 1495 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1501 DEFAULT_PRIORITY, | 1496 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1502 &d, | 1497 req->set_method("GET"); |
| 1503 &default_context_); | 1498 req->Start(); |
| 1504 req.set_method("GET"); | |
| 1505 req.Start(); | |
| 1506 base::RunLoop().Run(); | 1499 base::RunLoop().Run(); |
| 1507 | 1500 |
| 1508 // Check the interceptor got called as expected | 1501 // Check the interceptor got called as expected |
| 1509 EXPECT_TRUE(interceptor.did_intercept_main_); | 1502 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 1510 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 1503 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
| 1511 EXPECT_FALSE(interceptor.did_intercept_final_); | 1504 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1512 | 1505 |
| 1513 // Check we see a canceled request | 1506 // Check we see a canceled request |
| 1514 EXPECT_FALSE(req.status().is_success()); | 1507 EXPECT_FALSE(req->status().is_success()); |
| 1515 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 1516 } | 1509 } |
| 1517 | 1510 |
| 1518 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 1511 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
| 1519 TestInterceptor interceptor; | 1512 TestInterceptor interceptor; |
| 1520 | 1513 |
| 1521 // intercept the main request to simulate a network error | 1514 // intercept the main request to simulate a network error |
| 1522 interceptor.simulate_main_network_error_ = true; | 1515 interceptor.simulate_main_network_error_ = true; |
| 1523 | 1516 |
| 1524 // setup to intercept final response and cancel from within that job | 1517 // setup to intercept final response and cancel from within that job |
| 1525 interceptor.cancel_final_request_ = true; | 1518 interceptor.cancel_final_request_ = true; |
| 1526 | 1519 |
| 1527 TestDelegate d; | 1520 TestDelegate d; |
| 1528 URLRequest req(GURL("http://test_intercept/foo"), | 1521 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1529 DEFAULT_PRIORITY, | 1522 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1530 &d, | 1523 req->set_method("GET"); |
| 1531 &default_context_); | 1524 req->Start(); |
| 1532 req.set_method("GET"); | |
| 1533 req.Start(); | |
| 1534 base::RunLoop().Run(); | 1525 base::RunLoop().Run(); |
| 1535 | 1526 |
| 1536 // Check the interceptor got called as expected | 1527 // Check the interceptor got called as expected |
| 1537 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 1528 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 1538 EXPECT_TRUE(interceptor.did_cancel_final_); | 1529 EXPECT_TRUE(interceptor.did_cancel_final_); |
| 1539 | 1530 |
| 1540 // Check we see a canceled request | 1531 // Check we see a canceled request |
| 1541 EXPECT_FALSE(req.status().is_success()); | 1532 EXPECT_FALSE(req->status().is_success()); |
| 1542 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1533 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 1543 } | 1534 } |
| 1544 | 1535 |
| 1545 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 1536 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
| 1546 TestInterceptor interceptor; | 1537 TestInterceptor interceptor; |
| 1547 | 1538 |
| 1548 // intercept the main request and cancel then restart from within that job | 1539 // intercept the main request and cancel then restart from within that job |
| 1549 interceptor.cancel_then_restart_main_request_ = true; | 1540 interceptor.cancel_then_restart_main_request_ = true; |
| 1550 | 1541 |
| 1551 // setup to intercept final response and override it with an OK response | 1542 // setup to intercept final response and override it with an OK response |
| 1552 interceptor.intercept_final_response_ = true; | 1543 interceptor.intercept_final_response_ = true; |
| 1553 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 1544 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 1554 interceptor.final_data_ = TestInterceptor::ok_data(); | 1545 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 1555 | 1546 |
| 1556 TestDelegate d; | 1547 TestDelegate d; |
| 1557 URLRequest req(GURL("http://test_intercept/foo"), | 1548 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1558 DEFAULT_PRIORITY, | 1549 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1559 &d, | 1550 req->set_method("GET"); |
| 1560 &default_context_); | 1551 req->Start(); |
| 1561 req.set_method("GET"); | |
| 1562 req.Start(); | |
| 1563 base::RunLoop().Run(); | 1552 base::RunLoop().Run(); |
| 1564 | 1553 |
| 1565 // Check the interceptor got called as expected | 1554 // Check the interceptor got called as expected |
| 1566 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 1555 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
| 1567 EXPECT_FALSE(interceptor.did_intercept_final_); | 1556 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 1568 | 1557 |
| 1569 // Check we see a canceled request | 1558 // Check we see a canceled request |
| 1570 EXPECT_FALSE(req.status().is_success()); | 1559 EXPECT_FALSE(req->status().is_success()); |
| 1571 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1560 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 1572 } | 1561 } |
| 1573 | 1562 |
| 1574 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, | 1563 LoadTimingInfo RunLoadTimingTest(const LoadTimingInfo& job_load_timing, |
| 1575 URLRequestContext* context) { | 1564 URLRequestContext* context) { |
| 1576 TestInterceptor interceptor; | 1565 TestInterceptor interceptor; |
| 1577 interceptor.intercept_main_request_ = true; | 1566 interceptor.intercept_main_request_ = true; |
| 1578 interceptor.main_request_load_timing_info_ = job_load_timing; | 1567 interceptor.main_request_load_timing_info_ = job_load_timing; |
| 1579 TestDelegate d; | 1568 TestDelegate d; |
| 1580 URLRequest req( | 1569 scoped_ptr<URLRequest> req(context->CreateRequest( |
| 1581 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, context); | 1570 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1582 req.Start(); | 1571 req->Start(); |
| 1583 base::RunLoop().Run(); | 1572 base::RunLoop().Run(); |
| 1584 | 1573 |
| 1585 LoadTimingInfo resulting_load_timing; | 1574 LoadTimingInfo resulting_load_timing; |
| 1586 req.GetLoadTimingInfo(&resulting_load_timing); | 1575 req->GetLoadTimingInfo(&resulting_load_timing); |
| 1587 | 1576 |
| 1588 // None of these should be modified by the URLRequest. | 1577 // None of these should be modified by the URLRequest. |
| 1589 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); | 1578 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); |
| 1590 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); | 1579 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); |
| 1591 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); | 1580 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); |
| 1592 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); | 1581 EXPECT_EQ(job_load_timing.send_end, resulting_load_timing.send_end); |
| 1593 EXPECT_EQ(job_load_timing.receive_headers_end, | 1582 EXPECT_EQ(job_load_timing.receive_headers_end, |
| 1594 resulting_load_timing.receive_headers_end); | 1583 resulting_load_timing.receive_headers_end); |
| 1595 | 1584 |
| 1596 return resulting_load_timing; | 1585 return resulting_load_timing; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1848 // Check that a failure to connect to the proxy is reported to the network | 1837 // Check that a failure to connect to the proxy is reported to the network |
| 1849 // delegate. | 1838 // delegate. |
| 1850 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 1839 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
| 1851 MockHostResolver host_resolver; | 1840 MockHostResolver host_resolver; |
| 1852 host_resolver.rules()->AddSimulatedFailure("*"); | 1841 host_resolver.rules()->AddSimulatedFailure("*"); |
| 1853 | 1842 |
| 1854 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 1843 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 1855 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); | 1844 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); |
| 1856 | 1845 |
| 1857 TestDelegate d; | 1846 TestDelegate d; |
| 1858 URLRequest req(GURL("http://example.com"), DEFAULT_PRIORITY, &d, &context); | 1847 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 1859 req.set_method("GET"); | 1848 GURL("http://example.com"), DEFAULT_PRIORITY, &d, NULL)); |
| 1849 req->set_method("GET"); |
| 1860 | 1850 |
| 1861 req.Start(); | 1851 req->Start(); |
| 1862 base::RunLoop().Run(); | 1852 base::RunLoop().Run(); |
| 1863 | 1853 |
| 1864 // Check we see a failed request. | 1854 // Check we see a failed request. |
| 1865 EXPECT_FALSE(req.status().is_success()); | 1855 EXPECT_FALSE(req->status().is_success()); |
| 1866 // The proxy server is not set before failure. | 1856 // The proxy server is not set before failure. |
| 1867 EXPECT_TRUE(req.proxy_server().IsEmpty()); | 1857 EXPECT_TRUE(req->proxy_server().IsEmpty()); |
| 1868 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 1858 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 1869 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); | 1859 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req->status().error()); |
| 1870 | 1860 |
| 1871 EXPECT_EQ(1, network_delegate.error_count()); | 1861 EXPECT_EQ(1, network_delegate.error_count()); |
| 1872 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); | 1862 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
| 1873 EXPECT_EQ(1, network_delegate.completed_requests()); | 1863 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1874 } | 1864 } |
| 1875 | 1865 |
| 1876 // Make sure that net::NetworkDelegate::NotifyCompleted is called if | 1866 // Make sure that net::NetworkDelegate::NotifyCompleted is called if |
| 1877 // content is empty. | 1867 // content is empty. |
| 1878 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 1868 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
| 1879 TestDelegate d; | 1869 TestDelegate d; |
| 1880 URLRequest req(GURL("data:,"), DEFAULT_PRIORITY, &d, &default_context_); | 1870 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1881 req.Start(); | 1871 GURL("data:,"), DEFAULT_PRIORITY, &d, NULL)); |
| 1872 req->Start(); |
| 1882 base::RunLoop().Run(); | 1873 base::RunLoop().Run(); |
| 1883 EXPECT_EQ("", d.data_received()); | 1874 EXPECT_EQ("", d.data_received()); |
| 1884 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 1875 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 1885 } | 1876 } |
| 1886 | 1877 |
| 1887 // Make sure that SetPriority actually sets the URLRequest's priority | 1878 // Make sure that SetPriority actually sets the URLRequest's priority |
| 1888 // correctly, both before and after start. | 1879 // correctly, both before and after start. |
| 1889 TEST_F(URLRequestTest, SetPriorityBasic) { | 1880 TEST_F(URLRequestTest, SetPriorityBasic) { |
| 1890 TestDelegate d; | 1881 TestDelegate d; |
| 1891 URLRequest req(GURL("http://test_intercept/foo"), | 1882 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1892 DEFAULT_PRIORITY, | 1883 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1893 &d, | 1884 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 1894 &default_context_); | |
| 1895 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | |
| 1896 | 1885 |
| 1897 req.SetPriority(LOW); | 1886 req->SetPriority(LOW); |
| 1898 EXPECT_EQ(LOW, req.priority()); | 1887 EXPECT_EQ(LOW, req->priority()); |
| 1899 | 1888 |
| 1900 req.Start(); | 1889 req->Start(); |
| 1901 EXPECT_EQ(LOW, req.priority()); | 1890 EXPECT_EQ(LOW, req->priority()); |
| 1902 | 1891 |
| 1903 req.SetPriority(MEDIUM); | 1892 req->SetPriority(MEDIUM); |
| 1904 EXPECT_EQ(MEDIUM, req.priority()); | 1893 EXPECT_EQ(MEDIUM, req->priority()); |
| 1905 } | 1894 } |
| 1906 | 1895 |
| 1907 // Make sure that URLRequest calls SetPriority on a job before calling | 1896 // Make sure that URLRequest calls SetPriority on a job before calling |
| 1908 // Start on it. | 1897 // Start on it. |
| 1909 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { | 1898 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
| 1910 TestDelegate d; | 1899 TestDelegate d; |
| 1911 URLRequest req(GURL("http://test_intercept/foo"), | 1900 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1912 DEFAULT_PRIORITY, | 1901 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1913 &d, | 1902 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 1914 &default_context_); | |
| 1915 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | |
| 1916 | 1903 |
| 1917 scoped_refptr<URLRequestTestJob> job = | 1904 scoped_refptr<URLRequestTestJob> job = |
| 1918 new URLRequestTestJob(&req, &default_network_delegate_); | 1905 new URLRequestTestJob(req.get(), &default_network_delegate_); |
| 1919 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1906 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1920 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); | 1907 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); |
| 1921 | 1908 |
| 1922 req.SetPriority(LOW); | 1909 req->SetPriority(LOW); |
| 1923 | 1910 |
| 1924 req.Start(); | 1911 req->Start(); |
| 1925 EXPECT_EQ(LOW, job->priority()); | 1912 EXPECT_EQ(LOW, job->priority()); |
| 1926 } | 1913 } |
| 1927 | 1914 |
| 1928 // Make sure that URLRequest passes on its priority updates to its | 1915 // Make sure that URLRequest passes on its priority updates to its |
| 1929 // job. | 1916 // job. |
| 1930 TEST_F(URLRequestTest, SetJobPriority) { | 1917 TEST_F(URLRequestTest, SetJobPriority) { |
| 1931 TestDelegate d; | 1918 TestDelegate d; |
| 1932 URLRequest req(GURL("http://test_intercept/foo"), | 1919 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1933 DEFAULT_PRIORITY, | 1920 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); |
| 1934 &d, | |
| 1935 &default_context_); | |
| 1936 | 1921 |
| 1937 scoped_refptr<URLRequestTestJob> job = | 1922 scoped_refptr<URLRequestTestJob> job = |
| 1938 new URLRequestTestJob(&req, &default_network_delegate_); | 1923 new URLRequestTestJob(req.get(), &default_network_delegate_); |
| 1939 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1924 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1940 | 1925 |
| 1941 req.SetPriority(LOW); | 1926 req->SetPriority(LOW); |
| 1942 req.Start(); | 1927 req->Start(); |
| 1943 EXPECT_EQ(LOW, job->priority()); | 1928 EXPECT_EQ(LOW, job->priority()); |
| 1944 | 1929 |
| 1945 req.SetPriority(MEDIUM); | 1930 req->SetPriority(MEDIUM); |
| 1946 EXPECT_EQ(MEDIUM, req.priority()); | 1931 EXPECT_EQ(MEDIUM, req->priority()); |
| 1947 EXPECT_EQ(MEDIUM, job->priority()); | 1932 EXPECT_EQ(MEDIUM, job->priority()); |
| 1948 } | 1933 } |
| 1949 | 1934 |
| 1950 // Setting the IGNORE_LIMITS load flag should be okay if the priority | 1935 // Setting the IGNORE_LIMITS load flag should be okay if the priority |
| 1951 // is MAXIMUM_PRIORITY. | 1936 // is MAXIMUM_PRIORITY. |
| 1952 TEST_F(URLRequestTest, PriorityIgnoreLimits) { | 1937 TEST_F(URLRequestTest, PriorityIgnoreLimits) { |
| 1953 TestDelegate d; | 1938 TestDelegate d; |
| 1954 URLRequest req(GURL("http://test_intercept/foo"), | 1939 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1955 MAXIMUM_PRIORITY, | 1940 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d, NULL)); |
| 1956 &d, | 1941 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 1957 &default_context_); | |
| 1958 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); | |
| 1959 | 1942 |
| 1960 scoped_refptr<URLRequestTestJob> job = | 1943 scoped_refptr<URLRequestTestJob> job = |
| 1961 new URLRequestTestJob(&req, &default_network_delegate_); | 1944 new URLRequestTestJob(req.get(), &default_network_delegate_); |
| 1962 AddTestInterceptor()->set_main_intercept_job(job.get()); | 1945 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 1963 | 1946 |
| 1964 req.SetLoadFlags(LOAD_IGNORE_LIMITS); | 1947 req->SetLoadFlags(LOAD_IGNORE_LIMITS); |
| 1965 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); | 1948 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 1966 | 1949 |
| 1967 req.SetPriority(MAXIMUM_PRIORITY); | 1950 req->SetPriority(MAXIMUM_PRIORITY); |
| 1968 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); | 1951 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 1969 | 1952 |
| 1970 req.Start(); | 1953 req->Start(); |
| 1971 EXPECT_EQ(MAXIMUM_PRIORITY, req.priority()); | 1954 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 1972 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); | 1955 EXPECT_EQ(MAXIMUM_PRIORITY, job->priority()); |
| 1973 } | 1956 } |
| 1974 | 1957 |
| 1975 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). | 1958 // TODO(droger): Support SpawnedTestServer on iOS (see http://crbug.com/148666). |
| 1976 #if !defined(OS_IOS) | 1959 #if !defined(OS_IOS) |
| 1977 // A subclass of SpawnedTestServer that uses a statically-configured hostname. | 1960 // A subclass of SpawnedTestServer that uses a statically-configured hostname. |
| 1978 // This is to work around mysterious failures in chrome_frame_net_tests. See: | 1961 // This is to work around mysterious failures in chrome_frame_net_tests. See: |
| 1979 // http://crbug.com/114369 | 1962 // http://crbug.com/114369 |
| 1980 // TODO(erikwright): remove or update as needed; see http://crbug.com/334634. | 1963 // TODO(erikwright): remove or update as needed; see http://crbug.com/334634. |
| 1981 class LocalHttpTestServer : public SpawnedTestServer { | 1964 class LocalHttpTestServer : public SpawnedTestServer { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1998 scoped_refptr<DelayedCookieMonster> delayed_cm = | 1981 scoped_refptr<DelayedCookieMonster> delayed_cm = |
| 1999 new DelayedCookieMonster(); | 1982 new DelayedCookieMonster(); |
| 2000 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 1983 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
| 2001 context.set_cookie_store(delayed_cm.get()); | 1984 context.set_cookie_store(delayed_cm.get()); |
| 2002 | 1985 |
| 2003 // Set up a cookie. | 1986 // Set up a cookie. |
| 2004 { | 1987 { |
| 2005 TestNetworkDelegate network_delegate; | 1988 TestNetworkDelegate network_delegate; |
| 2006 context.set_network_delegate(&network_delegate); | 1989 context.set_network_delegate(&network_delegate); |
| 2007 TestDelegate d; | 1990 TestDelegate d; |
| 2008 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 1991 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2009 DEFAULT_PRIORITY, | 1992 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2010 &d, | 1993 &d, NULL)); |
| 2011 &context); | 1994 req->Start(); |
| 2012 req.Start(); | |
| 2013 base::RunLoop().Run(); | 1995 base::RunLoop().Run(); |
| 2014 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 1996 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2015 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 1997 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2016 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 1998 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2017 } | 1999 } |
| 2018 | 2000 |
| 2019 // Verify that the cookie is set. | 2001 // Verify that the cookie is set. |
| 2020 { | 2002 { |
| 2021 TestNetworkDelegate network_delegate; | 2003 TestNetworkDelegate network_delegate; |
| 2022 context.set_network_delegate(&network_delegate); | 2004 context.set_network_delegate(&network_delegate); |
| 2023 TestDelegate d; | 2005 TestDelegate d; |
| 2024 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2006 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 2025 DEFAULT_PRIORITY, | 2007 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2026 &d, | 2008 req->Start(); |
| 2027 &context); | |
| 2028 req.Start(); | |
| 2029 base::RunLoop().Run(); | 2009 base::RunLoop().Run(); |
| 2030 | 2010 |
| 2031 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2011 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2032 != std::string::npos); | 2012 != std::string::npos); |
| 2033 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2013 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2034 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2014 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2035 } | 2015 } |
| 2036 } | 2016 } |
| 2037 | 2017 |
| 2038 TEST_F(URLRequestTest, DoNotSendCookies) { | 2018 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 2039 LocalHttpTestServer test_server; | 2019 LocalHttpTestServer test_server; |
| 2040 ASSERT_TRUE(test_server.Start()); | 2020 ASSERT_TRUE(test_server.Start()); |
| 2041 | 2021 |
| 2042 // Set up a cookie. | 2022 // Set up a cookie. |
| 2043 { | 2023 { |
| 2044 TestNetworkDelegate network_delegate; | 2024 TestNetworkDelegate network_delegate; |
| 2045 default_context_.set_network_delegate(&network_delegate); | 2025 default_context_.set_network_delegate(&network_delegate); |
| 2046 TestDelegate d; | 2026 TestDelegate d; |
| 2047 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2027 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2048 DEFAULT_PRIORITY, | 2028 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2049 &d, | 2029 &d, NULL)); |
| 2050 &default_context_); | 2030 req->Start(); |
| 2051 req.Start(); | |
| 2052 base::RunLoop().Run(); | 2031 base::RunLoop().Run(); |
| 2053 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2032 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2054 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2033 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2055 } | 2034 } |
| 2056 | 2035 |
| 2057 // Verify that the cookie is set. | 2036 // Verify that the cookie is set. |
| 2058 { | 2037 { |
| 2059 TestNetworkDelegate network_delegate; | 2038 TestNetworkDelegate network_delegate; |
| 2060 default_context_.set_network_delegate(&network_delegate); | 2039 default_context_.set_network_delegate(&network_delegate); |
| 2061 TestDelegate d; | 2040 TestDelegate d; |
| 2062 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2041 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2063 DEFAULT_PRIORITY, | 2042 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2064 &d, | 2043 req->Start(); |
| 2065 &default_context_); | |
| 2066 req.Start(); | |
| 2067 base::RunLoop().Run(); | 2044 base::RunLoop().Run(); |
| 2068 | 2045 |
| 2069 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2046 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2070 != std::string::npos); | 2047 != std::string::npos); |
| 2071 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2048 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2072 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2049 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2073 } | 2050 } |
| 2074 | 2051 |
| 2075 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 2052 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 2076 { | 2053 { |
| 2077 TestNetworkDelegate network_delegate; | 2054 TestNetworkDelegate network_delegate; |
| 2078 default_context_.set_network_delegate(&network_delegate); | 2055 default_context_.set_network_delegate(&network_delegate); |
| 2079 TestDelegate d; | 2056 TestDelegate d; |
| 2080 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2057 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2081 DEFAULT_PRIORITY, | 2058 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2082 &d, | 2059 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
| 2083 &default_context_); | 2060 req->Start(); |
| 2084 req.SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); | |
| 2085 req.Start(); | |
| 2086 base::RunLoop().Run(); | 2061 base::RunLoop().Run(); |
| 2087 | 2062 |
| 2088 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2063 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2089 == std::string::npos); | 2064 == std::string::npos); |
| 2090 | 2065 |
| 2091 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 2066 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 2092 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2067 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2093 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2068 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2094 } | 2069 } |
| 2095 } | 2070 } |
| 2096 | 2071 |
| 2097 TEST_F(URLRequestTest, DoNotSaveCookies) { | 2072 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 2098 LocalHttpTestServer test_server; | 2073 LocalHttpTestServer test_server; |
| 2099 ASSERT_TRUE(test_server.Start()); | 2074 ASSERT_TRUE(test_server.Start()); |
| 2100 | 2075 |
| 2101 // Set up a cookie. | 2076 // Set up a cookie. |
| 2102 { | 2077 { |
| 2103 TestNetworkDelegate network_delegate; | 2078 TestNetworkDelegate network_delegate; |
| 2104 default_context_.set_network_delegate(&network_delegate); | 2079 default_context_.set_network_delegate(&network_delegate); |
| 2105 TestDelegate d; | 2080 TestDelegate d; |
| 2106 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2081 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2107 DEFAULT_PRIORITY, | 2082 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2108 &d, | 2083 &d, NULL)); |
| 2109 &default_context_); | 2084 req->Start(); |
| 2110 req.Start(); | |
| 2111 base::RunLoop().Run(); | 2085 base::RunLoop().Run(); |
| 2112 | 2086 |
| 2113 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2087 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2114 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2088 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2115 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2089 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2116 } | 2090 } |
| 2117 | 2091 |
| 2118 // Try to set-up another cookie and update the previous cookie. | 2092 // Try to set-up another cookie and update the previous cookie. |
| 2119 { | 2093 { |
| 2120 TestNetworkDelegate network_delegate; | 2094 TestNetworkDelegate network_delegate; |
| 2121 default_context_.set_network_delegate(&network_delegate); | 2095 default_context_.set_network_delegate(&network_delegate); |
| 2122 TestDelegate d; | 2096 TestDelegate d; |
| 2123 URLRequest req( | 2097 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2124 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2098 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2125 DEFAULT_PRIORITY, | 2099 DEFAULT_PRIORITY, &d, NULL)); |
| 2126 &d, | 2100 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); |
| 2127 &default_context_); | 2101 req->Start(); |
| 2128 req.SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); | |
| 2129 req.Start(); | |
| 2130 | 2102 |
| 2131 base::RunLoop().Run(); | 2103 base::RunLoop().Run(); |
| 2132 | 2104 |
| 2133 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 2105 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 2134 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2106 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2135 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2107 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2136 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2108 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2137 } | 2109 } |
| 2138 | 2110 |
| 2139 // Verify the cookies weren't saved or updated. | 2111 // Verify the cookies weren't saved or updated. |
| 2140 { | 2112 { |
| 2141 TestNetworkDelegate network_delegate; | 2113 TestNetworkDelegate network_delegate; |
| 2142 default_context_.set_network_delegate(&network_delegate); | 2114 default_context_.set_network_delegate(&network_delegate); |
| 2143 TestDelegate d; | 2115 TestDelegate d; |
| 2144 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2116 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2145 DEFAULT_PRIORITY, | 2117 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2146 &d, | 2118 req->Start(); |
| 2147 &default_context_); | |
| 2148 req.Start(); | |
| 2149 base::RunLoop().Run(); | 2119 base::RunLoop().Run(); |
| 2150 | 2120 |
| 2151 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2121 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2152 == std::string::npos); | 2122 == std::string::npos); |
| 2153 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2123 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2154 != std::string::npos); | 2124 != std::string::npos); |
| 2155 | 2125 |
| 2156 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2126 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2157 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2127 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2158 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2128 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2159 } | 2129 } |
| 2160 } | 2130 } |
| 2161 | 2131 |
| 2162 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 2132 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 2163 LocalHttpTestServer test_server; | 2133 LocalHttpTestServer test_server; |
| 2164 ASSERT_TRUE(test_server.Start()); | 2134 ASSERT_TRUE(test_server.Start()); |
| 2165 | 2135 |
| 2166 // Set up a cookie. | 2136 // Set up a cookie. |
| 2167 { | 2137 { |
| 2168 TestNetworkDelegate network_delegate; | 2138 TestNetworkDelegate network_delegate; |
| 2169 default_context_.set_network_delegate(&network_delegate); | 2139 default_context_.set_network_delegate(&network_delegate); |
| 2170 TestDelegate d; | 2140 TestDelegate d; |
| 2171 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2141 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2172 DEFAULT_PRIORITY, | 2142 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2173 &d, | 2143 &d, NULL)); |
| 2174 &default_context_); | 2144 req->Start(); |
| 2175 req.Start(); | |
| 2176 base::RunLoop().Run(); | 2145 base::RunLoop().Run(); |
| 2177 | 2146 |
| 2178 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2147 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2179 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2148 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2180 } | 2149 } |
| 2181 | 2150 |
| 2182 // Verify that the cookie is set. | 2151 // Verify that the cookie is set. |
| 2183 { | 2152 { |
| 2184 TestNetworkDelegate network_delegate; | 2153 TestNetworkDelegate network_delegate; |
| 2185 default_context_.set_network_delegate(&network_delegate); | 2154 default_context_.set_network_delegate(&network_delegate); |
| 2186 TestDelegate d; | 2155 TestDelegate d; |
| 2187 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2156 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2188 DEFAULT_PRIORITY, | 2157 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2189 &d, | 2158 req->Start(); |
| 2190 &default_context_); | |
| 2191 req.Start(); | |
| 2192 base::RunLoop().Run(); | 2159 base::RunLoop().Run(); |
| 2193 | 2160 |
| 2194 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2161 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2195 != std::string::npos); | 2162 != std::string::npos); |
| 2196 | 2163 |
| 2197 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2164 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2198 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2165 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2199 } | 2166 } |
| 2200 | 2167 |
| 2201 // Verify that the cookie isn't sent. | 2168 // Verify that the cookie isn't sent. |
| 2202 { | 2169 { |
| 2203 TestNetworkDelegate network_delegate; | 2170 TestNetworkDelegate network_delegate; |
| 2204 default_context_.set_network_delegate(&network_delegate); | 2171 default_context_.set_network_delegate(&network_delegate); |
| 2205 TestDelegate d; | 2172 TestDelegate d; |
| 2206 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2173 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2207 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2174 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2208 DEFAULT_PRIORITY, | 2175 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2209 &d, | 2176 req->Start(); |
| 2210 &default_context_); | |
| 2211 req.Start(); | |
| 2212 base::RunLoop().Run(); | 2177 base::RunLoop().Run(); |
| 2213 | 2178 |
| 2214 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2179 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2215 == std::string::npos); | 2180 == std::string::npos); |
| 2216 | 2181 |
| 2217 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2182 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2218 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2183 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2219 } | 2184 } |
| 2220 } | 2185 } |
| 2221 | 2186 |
| 2222 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2187 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 2223 LocalHttpTestServer test_server; | 2188 LocalHttpTestServer test_server; |
| 2224 ASSERT_TRUE(test_server.Start()); | 2189 ASSERT_TRUE(test_server.Start()); |
| 2225 | 2190 |
| 2226 // Set up a cookie. | 2191 // Set up a cookie. |
| 2227 { | 2192 { |
| 2228 TestNetworkDelegate network_delegate; | 2193 TestNetworkDelegate network_delegate; |
| 2229 default_context_.set_network_delegate(&network_delegate); | 2194 default_context_.set_network_delegate(&network_delegate); |
| 2230 TestDelegate d; | 2195 TestDelegate d; |
| 2231 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2196 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2232 DEFAULT_PRIORITY, | 2197 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2233 &d, | 2198 &d, NULL)); |
| 2234 &default_context_); | 2199 req->Start(); |
| 2235 req.Start(); | |
| 2236 base::RunLoop().Run(); | 2200 base::RunLoop().Run(); |
| 2237 | 2201 |
| 2238 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2202 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2239 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2203 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2240 } | 2204 } |
| 2241 | 2205 |
| 2242 // Try to set-up another cookie and update the previous cookie. | 2206 // Try to set-up another cookie and update the previous cookie. |
| 2243 { | 2207 { |
| 2244 TestNetworkDelegate network_delegate; | 2208 TestNetworkDelegate network_delegate; |
| 2245 default_context_.set_network_delegate(&network_delegate); | 2209 default_context_.set_network_delegate(&network_delegate); |
| 2246 TestDelegate d; | 2210 TestDelegate d; |
| 2247 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2211 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2248 URLRequest req( | 2212 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2249 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2213 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2250 DEFAULT_PRIORITY, | 2214 DEFAULT_PRIORITY, &d, NULL)); |
| 2251 &d, | 2215 req->Start(); |
| 2252 &default_context_); | |
| 2253 req.Start(); | |
| 2254 | 2216 |
| 2255 base::RunLoop().Run(); | 2217 base::RunLoop().Run(); |
| 2256 | 2218 |
| 2257 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2219 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2258 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2220 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2259 } | 2221 } |
| 2260 | 2222 |
| 2261 // Verify the cookies weren't saved or updated. | 2223 // Verify the cookies weren't saved or updated. |
| 2262 { | 2224 { |
| 2263 TestNetworkDelegate network_delegate; | 2225 TestNetworkDelegate network_delegate; |
| 2264 default_context_.set_network_delegate(&network_delegate); | 2226 default_context_.set_network_delegate(&network_delegate); |
| 2265 TestDelegate d; | 2227 TestDelegate d; |
| 2266 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2228 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2267 DEFAULT_PRIORITY, | 2229 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2268 &d, | 2230 req->Start(); |
| 2269 &default_context_); | |
| 2270 req.Start(); | |
| 2271 base::RunLoop().Run(); | 2231 base::RunLoop().Run(); |
| 2272 | 2232 |
| 2273 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2233 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2274 == std::string::npos); | 2234 == std::string::npos); |
| 2275 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2235 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2276 != std::string::npos); | 2236 != std::string::npos); |
| 2277 | 2237 |
| 2278 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2238 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2279 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2239 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2280 } | 2240 } |
| 2281 } | 2241 } |
| 2282 | 2242 |
| 2283 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2243 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 2284 LocalHttpTestServer test_server; | 2244 LocalHttpTestServer test_server; |
| 2285 ASSERT_TRUE(test_server.Start()); | 2245 ASSERT_TRUE(test_server.Start()); |
| 2286 | 2246 |
| 2287 // Set up an empty cookie. | 2247 // Set up an empty cookie. |
| 2288 { | 2248 { |
| 2289 TestNetworkDelegate network_delegate; | 2249 TestNetworkDelegate network_delegate; |
| 2290 default_context_.set_network_delegate(&network_delegate); | 2250 default_context_.set_network_delegate(&network_delegate); |
| 2291 TestDelegate d; | 2251 TestDelegate d; |
| 2292 URLRequest req(test_server.GetURL("set-cookie"), | 2252 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2293 DEFAULT_PRIORITY, | 2253 test_server.GetURL("set-cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2294 &d, | 2254 req->Start(); |
| 2295 &default_context_); | |
| 2296 req.Start(); | |
| 2297 base::RunLoop().Run(); | 2255 base::RunLoop().Run(); |
| 2298 | 2256 |
| 2299 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2257 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2300 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2258 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2301 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2259 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2302 } | 2260 } |
| 2303 } | 2261 } |
| 2304 | 2262 |
| 2305 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 2263 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 2306 LocalHttpTestServer test_server; | 2264 LocalHttpTestServer test_server; |
| 2307 ASSERT_TRUE(test_server.Start()); | 2265 ASSERT_TRUE(test_server.Start()); |
| 2308 | 2266 |
| 2309 // Set up a cookie. | 2267 // Set up a cookie. |
| 2310 { | 2268 { |
| 2311 TestNetworkDelegate network_delegate; | 2269 TestNetworkDelegate network_delegate; |
| 2312 default_context_.set_network_delegate(&network_delegate); | 2270 default_context_.set_network_delegate(&network_delegate); |
| 2313 TestDelegate d; | 2271 TestDelegate d; |
| 2314 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), | 2272 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2315 DEFAULT_PRIORITY, | 2273 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2316 &d, | 2274 &d, NULL)); |
| 2317 &default_context_); | 2275 req->Start(); |
| 2318 req.Start(); | |
| 2319 base::RunLoop().Run(); | 2276 base::RunLoop().Run(); |
| 2320 | 2277 |
| 2321 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2278 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2322 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2279 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2323 } | 2280 } |
| 2324 | 2281 |
| 2325 // Verify that the cookie is set. | 2282 // Verify that the cookie is set. |
| 2326 { | 2283 { |
| 2327 TestNetworkDelegate network_delegate; | 2284 TestNetworkDelegate network_delegate; |
| 2328 default_context_.set_network_delegate(&network_delegate); | 2285 default_context_.set_network_delegate(&network_delegate); |
| 2329 TestDelegate d; | 2286 TestDelegate d; |
| 2330 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2287 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2331 DEFAULT_PRIORITY, | 2288 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2332 &d, | 2289 req->Start(); |
| 2333 &default_context_); | |
| 2334 req.Start(); | |
| 2335 base::RunLoop().Run(); | 2290 base::RunLoop().Run(); |
| 2336 | 2291 |
| 2337 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2292 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2338 != std::string::npos); | 2293 != std::string::npos); |
| 2339 | 2294 |
| 2340 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2295 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2341 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2296 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2342 } | 2297 } |
| 2343 | 2298 |
| 2344 // Verify that the cookie isn't sent. | 2299 // Verify that the cookie isn't sent. |
| 2345 { | 2300 { |
| 2346 TestNetworkDelegate network_delegate; | 2301 TestNetworkDelegate network_delegate; |
| 2347 default_context_.set_network_delegate(&network_delegate); | 2302 default_context_.set_network_delegate(&network_delegate); |
| 2348 TestDelegate d; | 2303 TestDelegate d; |
| 2349 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2304 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2350 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2305 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2351 DEFAULT_PRIORITY, | 2306 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2352 &d, | 2307 req->Start(); |
| 2353 &default_context_); | |
| 2354 req.Start(); | |
| 2355 base::RunLoop().Run(); | 2308 base::RunLoop().Run(); |
| 2356 | 2309 |
| 2357 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2310 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2358 == std::string::npos); | 2311 == std::string::npos); |
| 2359 | 2312 |
| 2360 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2313 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2361 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2314 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2362 } | 2315 } |
| 2363 } | 2316 } |
| 2364 | 2317 |
| 2365 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2318 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 2366 LocalHttpTestServer test_server; | 2319 LocalHttpTestServer test_server; |
| 2367 ASSERT_TRUE(test_server.Start()); | 2320 ASSERT_TRUE(test_server.Start()); |
| 2368 | 2321 |
| 2369 // Set up a cookie. | 2322 // Set up a cookie. |
| 2370 { | 2323 { |
| 2371 TestNetworkDelegate network_delegate; | 2324 TestNetworkDelegate network_delegate; |
| 2372 default_context_.set_network_delegate(&network_delegate); | 2325 default_context_.set_network_delegate(&network_delegate); |
| 2373 TestDelegate d; | 2326 TestDelegate d; |
| 2374 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 2327 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2375 DEFAULT_PRIORITY, | 2328 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2376 &d, | 2329 &d, NULL)); |
| 2377 &default_context_); | 2330 req->Start(); |
| 2378 req.Start(); | |
| 2379 base::RunLoop().Run(); | 2331 base::RunLoop().Run(); |
| 2380 | 2332 |
| 2381 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2333 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2382 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2334 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2383 } | 2335 } |
| 2384 | 2336 |
| 2385 // Try to set-up another cookie and update the previous cookie. | 2337 // Try to set-up another cookie and update the previous cookie. |
| 2386 { | 2338 { |
| 2387 TestNetworkDelegate network_delegate; | 2339 TestNetworkDelegate network_delegate; |
| 2388 default_context_.set_network_delegate(&network_delegate); | 2340 default_context_.set_network_delegate(&network_delegate); |
| 2389 TestDelegate d; | 2341 TestDelegate d; |
| 2390 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2342 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2391 URLRequest req( | 2343 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2392 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2344 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2393 DEFAULT_PRIORITY, | 2345 DEFAULT_PRIORITY, &d, NULL)); |
| 2394 &d, | 2346 req->Start(); |
| 2395 &default_context_); | |
| 2396 req.Start(); | |
| 2397 | 2347 |
| 2398 base::RunLoop().Run(); | 2348 base::RunLoop().Run(); |
| 2399 | 2349 |
| 2400 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2350 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2401 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2351 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2402 } | 2352 } |
| 2403 | 2353 |
| 2404 // Verify the cookies weren't saved or updated. | 2354 // Verify the cookies weren't saved or updated. |
| 2405 { | 2355 { |
| 2406 TestNetworkDelegate network_delegate; | 2356 TestNetworkDelegate network_delegate; |
| 2407 default_context_.set_network_delegate(&network_delegate); | 2357 default_context_.set_network_delegate(&network_delegate); |
| 2408 TestDelegate d; | 2358 TestDelegate d; |
| 2409 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2359 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2410 DEFAULT_PRIORITY, | 2360 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2411 &d, | 2361 req->Start(); |
| 2412 &default_context_); | |
| 2413 req.Start(); | |
| 2414 base::RunLoop().Run(); | 2362 base::RunLoop().Run(); |
| 2415 | 2363 |
| 2416 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2364 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2417 == std::string::npos); | 2365 == std::string::npos); |
| 2418 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2366 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2419 != std::string::npos); | 2367 != std::string::npos); |
| 2420 | 2368 |
| 2421 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2369 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2422 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2370 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2423 } | 2371 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2470 // headers by defaulting to GMT. (crbug.com/135131) | 2418 // headers by defaulting to GMT. (crbug.com/135131) |
| 2471 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { | 2419 TEST_F(URLRequestTest, AcceptClockSkewCookieWithWrongDateTimezone) { |
| 2472 LocalHttpTestServer test_server; | 2420 LocalHttpTestServer test_server; |
| 2473 ASSERT_TRUE(test_server.Start()); | 2421 ASSERT_TRUE(test_server.Start()); |
| 2474 | 2422 |
| 2475 // Set up an expired cookie. | 2423 // Set up an expired cookie. |
| 2476 { | 2424 { |
| 2477 TestNetworkDelegate network_delegate; | 2425 TestNetworkDelegate network_delegate; |
| 2478 default_context_.set_network_delegate(&network_delegate); | 2426 default_context_.set_network_delegate(&network_delegate); |
| 2479 TestDelegate d; | 2427 TestDelegate d; |
| 2480 URLRequest req( | 2428 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2481 test_server.GetURL( | 2429 test_server.GetURL( |
| 2482 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2430 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 2483 DEFAULT_PRIORITY, | 2431 DEFAULT_PRIORITY, &d, NULL)); |
| 2484 &d, | 2432 req->Start(); |
| 2485 &default_context_); | |
| 2486 req.Start(); | |
| 2487 base::RunLoop().Run(); | 2433 base::RunLoop().Run(); |
| 2488 } | 2434 } |
| 2489 // Verify that the cookie is not set. | 2435 // Verify that the cookie is not set. |
| 2490 { | 2436 { |
| 2491 TestNetworkDelegate network_delegate; | 2437 TestNetworkDelegate network_delegate; |
| 2492 default_context_.set_network_delegate(&network_delegate); | 2438 default_context_.set_network_delegate(&network_delegate); |
| 2493 TestDelegate d; | 2439 TestDelegate d; |
| 2494 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2440 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2495 DEFAULT_PRIORITY, | 2441 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2496 &d, | 2442 req->Start(); |
| 2497 &default_context_); | |
| 2498 req.Start(); | |
| 2499 base::RunLoop().Run(); | 2443 base::RunLoop().Run(); |
| 2500 | 2444 |
| 2501 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | 2445 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); |
| 2502 } | 2446 } |
| 2503 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | 2447 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. |
| 2504 { | 2448 { |
| 2505 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | 2449 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); |
| 2506 default_context_.set_network_delegate(&network_delegate); | 2450 default_context_.set_network_delegate(&network_delegate); |
| 2507 TestDelegate d; | 2451 TestDelegate d; |
| 2508 URLRequest req( | 2452 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2509 test_server.GetURL( | 2453 test_server.GetURL( |
| 2510 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 2454 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 2511 DEFAULT_PRIORITY, | 2455 DEFAULT_PRIORITY, &d, NULL)); |
| 2512 &d, | 2456 req->Start(); |
| 2513 &default_context_); | |
| 2514 req.Start(); | |
| 2515 base::RunLoop().Run(); | 2457 base::RunLoop().Run(); |
| 2516 } | 2458 } |
| 2517 // Verify that the cookie is set. | 2459 // Verify that the cookie is set. |
| 2518 { | 2460 { |
| 2519 TestNetworkDelegate network_delegate; | 2461 TestNetworkDelegate network_delegate; |
| 2520 default_context_.set_network_delegate(&network_delegate); | 2462 default_context_.set_network_delegate(&network_delegate); |
| 2521 TestDelegate d; | 2463 TestDelegate d; |
| 2522 URLRequest req(test_server.GetURL("echoheader?Cookie"), | 2464 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2523 DEFAULT_PRIORITY, | 2465 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2524 &d, | 2466 req->Start(); |
| 2525 &default_context_); | |
| 2526 req.Start(); | |
| 2527 base::RunLoop().Run(); | 2467 base::RunLoop().Run(); |
| 2528 | 2468 |
| 2529 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 2469 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
| 2530 } | 2470 } |
| 2531 } | 2471 } |
| 2532 | 2472 |
| 2533 | 2473 |
| 2534 // Check that it is impossible to change the referrer in the extra headers of | 2474 // Check that it is impossible to change the referrer in the extra headers of |
| 2535 // an URLRequest. | 2475 // an URLRequest. |
| 2536 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 2476 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 2537 LocalHttpTestServer test_server; | 2477 LocalHttpTestServer test_server; |
| 2538 ASSERT_TRUE(test_server.Start()); | 2478 ASSERT_TRUE(test_server.Start()); |
| 2539 | 2479 |
| 2540 // If extra headers contain referer and the request contains a referer, | 2480 // If extra headers contain referer and the request contains a referer, |
| 2541 // only the latter shall be respected. | 2481 // only the latter shall be respected. |
| 2542 { | 2482 { |
| 2543 TestDelegate d; | 2483 TestDelegate d; |
| 2544 URLRequest req(test_server.GetURL("echoheader?Referer"), | 2484 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2545 DEFAULT_PRIORITY, | 2485 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); |
| 2546 &d, | 2486 req->SetReferrer("http://foo.com/"); |
| 2547 &default_context_); | |
| 2548 req.SetReferrer("http://foo.com/"); | |
| 2549 | 2487 |
| 2550 HttpRequestHeaders headers; | 2488 HttpRequestHeaders headers; |
| 2551 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2489 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 2552 req.SetExtraRequestHeaders(headers); | 2490 req->SetExtraRequestHeaders(headers); |
| 2553 | 2491 |
| 2554 req.Start(); | 2492 req->Start(); |
| 2555 base::RunLoop().Run(); | 2493 base::RunLoop().Run(); |
| 2556 | 2494 |
| 2557 EXPECT_EQ("http://foo.com/", d.data_received()); | 2495 EXPECT_EQ("http://foo.com/", d.data_received()); |
| 2558 } | 2496 } |
| 2559 | 2497 |
| 2560 // If extra headers contain a referer but the request does not, no referer | 2498 // If extra headers contain a referer but the request does not, no referer |
| 2561 // shall be sent in the header. | 2499 // shall be sent in the header. |
| 2562 { | 2500 { |
| 2563 TestDelegate d; | 2501 TestDelegate d; |
| 2564 URLRequest req(test_server.GetURL("echoheader?Referer"), | 2502 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2565 DEFAULT_PRIORITY, | 2503 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); |
| 2566 &d, | |
| 2567 &default_context_); | |
| 2568 | 2504 |
| 2569 HttpRequestHeaders headers; | 2505 HttpRequestHeaders headers; |
| 2570 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 2506 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 2571 req.SetExtraRequestHeaders(headers); | 2507 req->SetExtraRequestHeaders(headers); |
| 2572 req.SetLoadFlags(LOAD_VALIDATE_CACHE); | 2508 req->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 2573 | 2509 |
| 2574 req.Start(); | 2510 req->Start(); |
| 2575 base::RunLoop().Run(); | 2511 base::RunLoop().Run(); |
| 2576 | 2512 |
| 2577 EXPECT_EQ("None", d.data_received()); | 2513 EXPECT_EQ("None", d.data_received()); |
| 2578 } | 2514 } |
| 2579 } | 2515 } |
| 2580 | 2516 |
| 2581 class URLRequestTestHTTP : public URLRequestTest { | 2517 class URLRequestTestHTTP : public URLRequestTest { |
| 2582 public: | 2518 public: |
| 2583 URLRequestTestHTTP() | 2519 URLRequestTestHTTP() |
| 2584 : test_server_(base::FilePath(FILE_PATH_LITERAL( | 2520 : test_server_(base::FilePath(FILE_PATH_LITERAL( |
| 2585 "net/data/url_request_unittest"))) { | 2521 "net/data/url_request_unittest"))) { |
| 2586 } | 2522 } |
| 2587 | 2523 |
| 2588 protected: | 2524 protected: |
| 2589 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | 2525 // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
| 2590 // |request_method| is the method to use for the initial request. | 2526 // |request_method| is the method to use for the initial request. |
| 2591 // |redirect_method| is the method that is expected to be used for the second | 2527 // |redirect_method| is the method that is expected to be used for the second |
| 2592 // request, after redirection. | 2528 // request, after redirection. |
| 2593 // If |include_data| is true, data is uploaded with the request. The | 2529 // If |include_data| is true, data is uploaded with the request. The |
| 2594 // response body is expected to match it exactly, if and only if | 2530 // response body is expected to match it exactly, if and only if |
| 2595 // |request_method| == |redirect_method|. | 2531 // |request_method| == |redirect_method|. |
| 2596 void HTTPRedirectMethodTest(const GURL& redirect_url, | 2532 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 2597 const std::string& request_method, | 2533 const std::string& request_method, |
| 2598 const std::string& redirect_method, | 2534 const std::string& redirect_method, |
| 2599 bool include_data) { | 2535 bool include_data) { |
| 2600 static const char kData[] = "hello world"; | 2536 static const char kData[] = "hello world"; |
| 2601 TestDelegate d; | 2537 TestDelegate d; |
| 2602 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); | 2538 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2603 req.set_method(request_method); | 2539 redirect_url, DEFAULT_PRIORITY, &d, NULL)); |
| 2540 req->set_method(request_method); |
| 2604 if (include_data) { | 2541 if (include_data) { |
| 2605 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 2542 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 2606 HttpRequestHeaders headers; | 2543 HttpRequestHeaders headers; |
| 2607 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2544 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 2608 base::UintToString(arraysize(kData) - 1)); | 2545 base::UintToString(arraysize(kData) - 1)); |
| 2609 req.SetExtraRequestHeaders(headers); | 2546 req->SetExtraRequestHeaders(headers); |
| 2610 } | 2547 } |
| 2611 req.Start(); | 2548 req->Start(); |
| 2612 base::RunLoop().Run(); | 2549 base::RunLoop().Run(); |
| 2613 EXPECT_EQ(redirect_method, req.method()); | 2550 EXPECT_EQ(redirect_method, req->method()); |
| 2614 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 2551 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 2615 EXPECT_EQ(OK, req.status().error()); | 2552 EXPECT_EQ(OK, req->status().error()); |
| 2616 if (include_data) { | 2553 if (include_data) { |
| 2617 if (request_method == redirect_method) { | 2554 if (request_method == redirect_method) { |
| 2618 EXPECT_EQ(kData, d.data_received()); | 2555 EXPECT_EQ(kData, d.data_received()); |
| 2619 } else { | 2556 } else { |
| 2620 EXPECT_NE(kData, d.data_received()); | 2557 EXPECT_NE(kData, d.data_received()); |
| 2621 } | 2558 } |
| 2622 } | 2559 } |
| 2623 if (HasFailure()) | 2560 if (HasFailure()) |
| 2624 LOG(WARNING) << "Request method was: " << request_method; | 2561 LOG(WARNING) << "Request method was: " << request_method; |
| 2625 } | 2562 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2637 ptr--; | 2574 ptr--; |
| 2638 *ptr++ = marker; | 2575 *ptr++ = marker; |
| 2639 if (++marker > 'z') | 2576 if (++marker > 'z') |
| 2640 marker = 'a'; | 2577 marker = 'a'; |
| 2641 } | 2578 } |
| 2642 } | 2579 } |
| 2643 uploadBytes[kMsgSize] = '\0'; | 2580 uploadBytes[kMsgSize] = '\0'; |
| 2644 | 2581 |
| 2645 for (int i = 0; i < kIterations; ++i) { | 2582 for (int i = 0; i < kIterations; ++i) { |
| 2646 TestDelegate d; | 2583 TestDelegate d; |
| 2647 URLRequest r( | 2584 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 2648 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 2585 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 2649 r.set_method(method.c_str()); | 2586 r->set_method(method.c_str()); |
| 2650 | 2587 |
| 2651 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); | 2588 r->set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes))); |
| 2652 | 2589 |
| 2653 r.Start(); | 2590 r->Start(); |
| 2654 EXPECT_TRUE(r.is_pending()); | 2591 EXPECT_TRUE(r->is_pending()); |
| 2655 | 2592 |
| 2656 base::RunLoop().Run(); | 2593 base::RunLoop().Run(); |
| 2657 | 2594 |
| 2658 ASSERT_EQ(1, d.response_started_count()) | 2595 ASSERT_EQ(1, d.response_started_count()) |
| 2659 << "request failed: " << r.status().status() | 2596 << "request failed: " << r->status().status() |
| 2660 << ", os error: " << r.status().error(); | 2597 << ", os error: " << r->status().error(); |
| 2661 | 2598 |
| 2662 EXPECT_FALSE(d.received_data_before_response()); | 2599 EXPECT_FALSE(d.received_data_before_response()); |
| 2663 EXPECT_EQ(uploadBytes, d.data_received()); | 2600 EXPECT_EQ(uploadBytes, d.data_received()); |
| 2664 } | 2601 } |
| 2665 delete[] uploadBytes; | 2602 delete[] uploadBytes; |
| 2666 } | 2603 } |
| 2667 | 2604 |
| 2668 void AddChunksToUpload(URLRequest* r) { | 2605 void AddChunksToUpload(URLRequest* r) { |
| 2669 r->AppendChunkToUpload("a", 1, false); | 2606 r->AppendChunkToUpload("a", 1, false); |
| 2670 r->AppendChunkToUpload("bcd", 3, false); | 2607 r->AppendChunkToUpload("bcd", 3, false); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2684 << ", os error: " << r->status().error(); | 2621 << ", os error: " << r->status().error(); |
| 2685 | 2622 |
| 2686 EXPECT_FALSE(d->received_data_before_response()); | 2623 EXPECT_FALSE(d->received_data_before_response()); |
| 2687 | 2624 |
| 2688 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); | 2625 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); |
| 2689 EXPECT_EQ(expected_data, d->data_received()); | 2626 EXPECT_EQ(expected_data, d->data_received()); |
| 2690 } | 2627 } |
| 2691 | 2628 |
| 2692 bool DoManyCookiesRequest(int num_cookies) { | 2629 bool DoManyCookiesRequest(int num_cookies) { |
| 2693 TestDelegate d; | 2630 TestDelegate d; |
| 2694 URLRequest r(test_server_.GetURL("set-many-cookies?" + | 2631 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 2695 base::IntToString(num_cookies)), | 2632 test_server_.GetURL("set-many-cookies?" + |
| 2696 DEFAULT_PRIORITY, | 2633 base::IntToString(num_cookies)), |
| 2697 &d, | 2634 DEFAULT_PRIORITY, &d, NULL)); |
| 2698 &default_context_); | |
| 2699 | 2635 |
| 2700 r.Start(); | 2636 r->Start(); |
| 2701 EXPECT_TRUE(r.is_pending()); | 2637 EXPECT_TRUE(r->is_pending()); |
| 2702 | 2638 |
| 2703 base::RunLoop().Run(); | 2639 base::RunLoop().Run(); |
| 2704 | 2640 |
| 2705 bool is_success = r.status().is_success(); | 2641 bool is_success = r->status().is_success(); |
| 2706 | 2642 |
| 2707 if (!is_success) { | 2643 if (!is_success) { |
| 2708 EXPECT_TRUE(r.status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); | 2644 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); |
| 2709 // The test server appears to be unable to handle subsequent requests | 2645 // The test server appears to be unable to handle subsequent requests |
| 2710 // after this error is triggered. Force it to restart. | 2646 // after this error is triggered. Force it to restart. |
| 2711 EXPECT_TRUE(test_server_.Stop()); | 2647 EXPECT_TRUE(test_server_.Stop()); |
| 2712 EXPECT_TRUE(test_server_.Start()); | 2648 EXPECT_TRUE(test_server_.Start()); |
| 2713 } | 2649 } |
| 2714 | 2650 |
| 2715 return is_success; | 2651 return is_success; |
| 2716 } | 2652 } |
| 2717 | 2653 |
| 2718 LocalHttpTestServer test_server_; | 2654 LocalHttpTestServer test_server_; |
| 2719 }; | 2655 }; |
| 2720 | 2656 |
| 2721 // In this unit test, we're using the HTTPTestServer as a proxy server and | 2657 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 2722 // issuing a CONNECT request with the magic host name "www.redirect.com". | 2658 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 2723 // The HTTPTestServer will return a 302 response, which we should not | 2659 // The HTTPTestServer will return a 302 response, which we should not |
| 2724 // follow. | 2660 // follow. |
| 2725 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 2661 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 2726 ASSERT_TRUE(test_server_.Start()); | 2662 ASSERT_TRUE(test_server_.Start()); |
| 2727 | 2663 |
| 2728 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2664 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 2729 TestURLRequestContextWithProxy context( | 2665 TestURLRequestContextWithProxy context( |
| 2730 test_server_.host_port_pair().ToString(), &network_delegate); | 2666 test_server_.host_port_pair().ToString(), &network_delegate); |
| 2731 | 2667 |
| 2732 TestDelegate d; | 2668 TestDelegate d; |
| 2733 { | 2669 { |
| 2734 URLRequest r( | 2670 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2735 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context); | 2671 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL)); |
| 2736 r.Start(); | 2672 r->Start(); |
| 2737 EXPECT_TRUE(r.is_pending()); | 2673 EXPECT_TRUE(r->is_pending()); |
| 2738 | 2674 |
| 2739 base::RunLoop().Run(); | 2675 base::RunLoop().Run(); |
| 2740 | 2676 |
| 2741 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2677 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 2742 // The proxy server is not set before failure. | 2678 // The proxy server is not set before failure. |
| 2743 EXPECT_TRUE(r.proxy_server().IsEmpty()); | 2679 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 2744 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2680 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 2745 EXPECT_EQ(1, d.response_started_count()); | 2681 EXPECT_EQ(1, d.response_started_count()); |
| 2746 // We should not have followed the redirect. | 2682 // We should not have followed the redirect. |
| 2747 EXPECT_EQ(0, d.received_redirect_count()); | 2683 EXPECT_EQ(0, d.received_redirect_count()); |
| 2748 } | 2684 } |
| 2749 } | 2685 } |
| 2750 | 2686 |
| 2751 // This is the same as the previous test, but checks that the network delegate | 2687 // This is the same as the previous test, but checks that the network delegate |
| 2752 // registers the error. | 2688 // registers the error. |
| 2753 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 2689 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 2754 ASSERT_TRUE(test_server_.Start()); | 2690 ASSERT_TRUE(test_server_.Start()); |
| 2755 | 2691 |
| 2756 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 2692 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 2757 TestURLRequestContextWithProxy context( | 2693 TestURLRequestContextWithProxy context( |
| 2758 test_server_.host_port_pair().ToString(), &network_delegate); | 2694 test_server_.host_port_pair().ToString(), &network_delegate); |
| 2759 | 2695 |
| 2760 TestDelegate d; | 2696 TestDelegate d; |
| 2761 { | 2697 { |
| 2762 URLRequest r( | 2698 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2763 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, &context); | 2699 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL)); |
| 2764 r.Start(); | 2700 r->Start(); |
| 2765 EXPECT_TRUE(r.is_pending()); | 2701 EXPECT_TRUE(r->is_pending()); |
| 2766 | 2702 |
| 2767 base::RunLoop().Run(); | 2703 base::RunLoop().Run(); |
| 2768 | 2704 |
| 2769 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2705 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 2770 // The proxy server is not set before failure. | 2706 // The proxy server is not set before failure. |
| 2771 EXPECT_TRUE(r.proxy_server().IsEmpty()); | 2707 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 2772 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 2708 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 2773 EXPECT_EQ(1, d.response_started_count()); | 2709 EXPECT_EQ(1, d.response_started_count()); |
| 2774 // We should not have followed the redirect. | 2710 // We should not have followed the redirect. |
| 2775 EXPECT_EQ(0, d.received_redirect_count()); | 2711 EXPECT_EQ(0, d.received_redirect_count()); |
| 2776 | 2712 |
| 2777 EXPECT_EQ(1, network_delegate.error_count()); | 2713 EXPECT_EQ(1, network_delegate.error_count()); |
| 2778 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); | 2714 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
| 2779 } | 2715 } |
| 2780 } | 2716 } |
| 2781 | 2717 |
| 2782 // Tests that we can block and asynchronously return OK in various stages. | 2718 // Tests that we can block and asynchronously return OK in various stages. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2796 network_delegate.set_block_on( | 2732 network_delegate.set_block_on( |
| 2797 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | | 2733 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | |
| 2798 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | | 2734 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | |
| 2799 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 2735 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 2800 | 2736 |
| 2801 TestURLRequestContext context(true); | 2737 TestURLRequestContext context(true); |
| 2802 context.set_network_delegate(&network_delegate); | 2738 context.set_network_delegate(&network_delegate); |
| 2803 context.Init(); | 2739 context.Init(); |
| 2804 | 2740 |
| 2805 { | 2741 { |
| 2806 URLRequest r( | 2742 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2807 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, &context); | 2743 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); |
| 2808 | 2744 |
| 2809 r.Start(); | 2745 r->Start(); |
| 2810 for (size_t i = 0; i < blocking_stages_length; ++i) { | 2746 for (size_t i = 0; i < blocking_stages_length; ++i) { |
| 2811 base::RunLoop().Run(); | 2747 base::RunLoop().Run(); |
| 2812 EXPECT_EQ(blocking_stages[i], | 2748 EXPECT_EQ(blocking_stages[i], |
| 2813 network_delegate.stage_blocked_for_callback()); | 2749 network_delegate.stage_blocked_for_callback()); |
| 2814 network_delegate.DoCallback(OK); | 2750 network_delegate.DoCallback(OK); |
| 2815 } | 2751 } |
| 2816 base::RunLoop().Run(); | 2752 base::RunLoop().Run(); |
| 2817 EXPECT_EQ(200, r.GetResponseCode()); | 2753 EXPECT_EQ(200, r->GetResponseCode()); |
| 2818 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2754 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 2819 EXPECT_EQ(1, network_delegate.created_requests()); | 2755 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2820 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2756 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2821 } | 2757 } |
| 2822 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2758 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2823 } | 2759 } |
| 2824 | 2760 |
| 2825 // Tests that the network delegate can block and cancel a request. | 2761 // Tests that the network delegate can block and cancel a request. |
| 2826 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 2762 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
| 2827 ASSERT_TRUE(test_server_.Start()); | 2763 ASSERT_TRUE(test_server_.Start()); |
| 2828 | 2764 |
| 2829 TestDelegate d; | 2765 TestDelegate d; |
| 2830 BlockingNetworkDelegate network_delegate( | 2766 BlockingNetworkDelegate network_delegate( |
| 2831 BlockingNetworkDelegate::AUTO_CALLBACK); | 2767 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 2832 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2768 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2833 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 2769 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 2834 | 2770 |
| 2835 TestURLRequestContextWithProxy context( | 2771 TestURLRequestContextWithProxy context( |
| 2836 test_server_.host_port_pair().ToString(), &network_delegate); | 2772 test_server_.host_port_pair().ToString(), &network_delegate); |
| 2837 | 2773 |
| 2838 { | 2774 { |
| 2839 URLRequest r( | 2775 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2840 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); | 2776 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 2841 | 2777 |
| 2842 r.Start(); | 2778 r->Start(); |
| 2843 base::RunLoop().Run(); | 2779 base::RunLoop().Run(); |
| 2844 | 2780 |
| 2845 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2781 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 2846 // The proxy server is not set before cancellation. | 2782 // The proxy server is not set before cancellation. |
| 2847 EXPECT_TRUE(r.proxy_server().IsEmpty()); | 2783 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 2848 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 2784 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error()); |
| 2849 EXPECT_EQ(1, network_delegate.created_requests()); | 2785 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2850 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2786 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2851 } | 2787 } |
| 2852 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2788 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2853 } | 2789 } |
| 2854 | 2790 |
| 2855 // Helper function for NetworkDelegateCancelRequestAsynchronously and | 2791 // Helper function for NetworkDelegateCancelRequestAsynchronously and |
| 2856 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network | 2792 // NetworkDelegateCancelRequestSynchronously. Sets up a blocking network |
| 2857 // delegate operating in |block_mode| and a request for |url|. It blocks the | 2793 // delegate operating in |block_mode| and a request for |url|. It blocks the |
| 2858 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. | 2794 // request in |stage| and cancels it with ERR_BLOCKED_BY_CLIENT. |
| 2859 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, | 2795 void NetworkDelegateCancelRequest(BlockingNetworkDelegate::BlockMode block_mode, |
| 2860 BlockingNetworkDelegate::Stage stage, | 2796 BlockingNetworkDelegate::Stage stage, |
| 2861 const GURL& url) { | 2797 const GURL& url) { |
| 2862 TestDelegate d; | 2798 TestDelegate d; |
| 2863 BlockingNetworkDelegate network_delegate(block_mode); | 2799 BlockingNetworkDelegate network_delegate(block_mode); |
| 2864 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); | 2800 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); |
| 2865 network_delegate.set_block_on(stage); | 2801 network_delegate.set_block_on(stage); |
| 2866 | 2802 |
| 2867 TestURLRequestContext context(true); | 2803 TestURLRequestContext context(true); |
| 2868 context.set_network_delegate(&network_delegate); | 2804 context.set_network_delegate(&network_delegate); |
| 2869 context.Init(); | 2805 context.Init(); |
| 2870 | 2806 |
| 2871 { | 2807 { |
| 2872 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 2808 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2809 url, DEFAULT_PRIORITY, &d, NULL)); |
| 2873 | 2810 |
| 2874 r.Start(); | 2811 r->Start(); |
| 2875 base::RunLoop().Run(); | 2812 base::RunLoop().Run(); |
| 2876 | 2813 |
| 2877 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 2814 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 2878 // The proxy server is not set before cancellation. | 2815 // The proxy server is not set before cancellation. |
| 2879 EXPECT_TRUE(r.proxy_server().IsEmpty()); | 2816 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 2880 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r.status().error()); | 2817 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error()); |
| 2881 EXPECT_EQ(1, network_delegate.created_requests()); | 2818 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2882 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2819 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2883 } | 2820 } |
| 2884 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2821 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2885 } | 2822 } |
| 2886 | 2823 |
| 2887 // The following 3 tests check that the network delegate can cancel a request | 2824 // The following 3 tests check that the network delegate can cancel a request |
| 2888 // synchronously in various stages of the request. | 2825 // synchronously in various stages of the request. |
| 2889 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { | 2826 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously1) { |
| 2890 ASSERT_TRUE(test_server_.Start()); | 2827 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 BlockingNetworkDelegate::AUTO_CALLBACK); | 2877 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 2941 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2878 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 2942 GURL redirect_url(test_server_.GetURL("simple.html")); | 2879 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 2943 network_delegate.set_redirect_url(redirect_url); | 2880 network_delegate.set_redirect_url(redirect_url); |
| 2944 | 2881 |
| 2945 TestURLRequestContextWithProxy context( | 2882 TestURLRequestContextWithProxy context( |
| 2946 test_server_.host_port_pair().ToString(), &network_delegate); | 2883 test_server_.host_port_pair().ToString(), &network_delegate); |
| 2947 | 2884 |
| 2948 { | 2885 { |
| 2949 GURL original_url(test_server_.GetURL("empty.html")); | 2886 GURL original_url(test_server_.GetURL("empty.html")); |
| 2950 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); | 2887 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2888 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 2951 | 2889 |
| 2952 r.Start(); | 2890 r->Start(); |
| 2953 base::RunLoop().Run(); | 2891 base::RunLoop().Run(); |
| 2954 | 2892 |
| 2955 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2893 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 2956 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); | 2894 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); |
| 2957 EXPECT_EQ( | 2895 EXPECT_EQ( |
| 2958 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 2896 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 2959 EXPECT_TRUE( | 2897 EXPECT_TRUE( |
| 2960 network_delegate.last_observed_proxy().Equals( | 2898 network_delegate.last_observed_proxy().Equals( |
| 2961 test_server_.host_port_pair())); | 2899 test_server_.host_port_pair())); |
| 2962 | 2900 |
| 2963 EXPECT_EQ(0, r.status().error()); | 2901 EXPECT_EQ(0, r->status().error()); |
| 2964 EXPECT_EQ(redirect_url, r.url()); | 2902 EXPECT_EQ(redirect_url, r->url()); |
| 2965 EXPECT_EQ(original_url, r.original_url()); | 2903 EXPECT_EQ(original_url, r->original_url()); |
| 2966 EXPECT_EQ(2U, r.url_chain().size()); | 2904 EXPECT_EQ(2U, r->url_chain().size()); |
| 2967 EXPECT_EQ(1, network_delegate.created_requests()); | 2905 EXPECT_EQ(1, network_delegate.created_requests()); |
| 2968 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2906 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 2969 } | 2907 } |
| 2970 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2908 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 2971 } | 2909 } |
| 2972 | 2910 |
| 2973 // Tests that the network delegate can block and redirect a request to a new | 2911 // Tests that the network delegate can block and redirect a request to a new |
| 2974 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. | 2912 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. |
| 2975 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { | 2913 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { |
| 2976 ASSERT_TRUE(test_server_.Start()); | 2914 ASSERT_TRUE(test_server_.Start()); |
| 2977 | 2915 |
| 2978 TestDelegate d; | 2916 TestDelegate d; |
| 2979 BlockingNetworkDelegate network_delegate( | 2917 BlockingNetworkDelegate network_delegate( |
| 2980 BlockingNetworkDelegate::SYNCHRONOUS); | 2918 BlockingNetworkDelegate::SYNCHRONOUS); |
| 2981 GURL redirect_url(test_server_.GetURL("simple.html")); | 2919 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 2982 network_delegate.set_redirect_url(redirect_url); | 2920 network_delegate.set_redirect_url(redirect_url); |
| 2983 | 2921 |
| 2984 TestURLRequestContextWithProxy context( | 2922 TestURLRequestContextWithProxy context( |
| 2985 test_server_.host_port_pair().ToString(), &network_delegate); | 2923 test_server_.host_port_pair().ToString(), &network_delegate); |
| 2986 | 2924 |
| 2987 { | 2925 { |
| 2988 GURL original_url(test_server_.GetURL("empty.html")); | 2926 GURL original_url(test_server_.GetURL("empty.html")); |
| 2989 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); | 2927 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 2928 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 2990 | 2929 |
| 2991 r.Start(); | 2930 r->Start(); |
| 2992 base::RunLoop().Run(); | 2931 base::RunLoop().Run(); |
| 2993 | 2932 |
| 2994 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2933 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 2995 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); | 2934 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); |
| 2996 EXPECT_EQ( | 2935 EXPECT_EQ( |
| 2997 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 2936 1, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 2998 EXPECT_TRUE( | 2937 EXPECT_TRUE( |
| 2999 network_delegate.last_observed_proxy().Equals( | 2938 network_delegate.last_observed_proxy().Equals( |
| 3000 test_server_.host_port_pair())); | 2939 test_server_.host_port_pair())); |
| 3001 EXPECT_EQ(0, r.status().error()); | 2940 EXPECT_EQ(0, r->status().error()); |
| 3002 EXPECT_EQ(redirect_url, r.url()); | 2941 EXPECT_EQ(redirect_url, r->url()); |
| 3003 EXPECT_EQ(original_url, r.original_url()); | 2942 EXPECT_EQ(original_url, r->original_url()); |
| 3004 EXPECT_EQ(2U, r.url_chain().size()); | 2943 EXPECT_EQ(2U, r->url_chain().size()); |
| 3005 EXPECT_EQ(1, network_delegate.created_requests()); | 2944 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3006 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2945 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3007 } | 2946 } |
| 3008 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2947 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3009 } | 2948 } |
| 3010 | 2949 |
| 3011 // Tests that redirects caused by the network delegate preserve POST data. | 2950 // Tests that redirects caused by the network delegate preserve POST data. |
| 3012 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { | 2951 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { |
| 3013 ASSERT_TRUE(test_server_.Start()); | 2952 ASSERT_TRUE(test_server_.Start()); |
| 3014 | 2953 |
| 3015 const char kData[] = "hello world"; | 2954 const char kData[] = "hello world"; |
| 3016 | 2955 |
| 3017 TestDelegate d; | 2956 TestDelegate d; |
| 3018 BlockingNetworkDelegate network_delegate( | 2957 BlockingNetworkDelegate network_delegate( |
| 3019 BlockingNetworkDelegate::AUTO_CALLBACK); | 2958 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3020 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 2959 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3021 GURL redirect_url(test_server_.GetURL("echo")); | 2960 GURL redirect_url(test_server_.GetURL("echo")); |
| 3022 network_delegate.set_redirect_url(redirect_url); | 2961 network_delegate.set_redirect_url(redirect_url); |
| 3023 | 2962 |
| 3024 TestURLRequestContext context(true); | 2963 TestURLRequestContext context(true); |
| 3025 context.set_network_delegate(&network_delegate); | 2964 context.set_network_delegate(&network_delegate); |
| 3026 context.Init(); | 2965 context.Init(); |
| 3027 | 2966 |
| 3028 { | 2967 { |
| 3029 GURL original_url(test_server_.GetURL("empty.html")); | 2968 GURL original_url(test_server_.GetURL("empty.html")); |
| 3030 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); | 2969 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3031 r.set_method("POST"); | 2970 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 3032 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | 2971 r->set_method("POST"); |
| 2972 r->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 3033 HttpRequestHeaders headers; | 2973 HttpRequestHeaders headers; |
| 3034 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2974 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3035 base::UintToString(arraysize(kData) - 1)); | 2975 base::UintToString(arraysize(kData) - 1)); |
| 3036 r.SetExtraRequestHeaders(headers); | 2976 r->SetExtraRequestHeaders(headers); |
| 3037 r.Start(); | 2977 r->Start(); |
| 3038 base::RunLoop().Run(); | 2978 base::RunLoop().Run(); |
| 3039 | 2979 |
| 3040 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2980 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3041 EXPECT_EQ(0, r.status().error()); | 2981 EXPECT_EQ(0, r->status().error()); |
| 3042 EXPECT_EQ(redirect_url, r.url()); | 2982 EXPECT_EQ(redirect_url, r->url()); |
| 3043 EXPECT_EQ(original_url, r.original_url()); | 2983 EXPECT_EQ(original_url, r->original_url()); |
| 3044 EXPECT_EQ(2U, r.url_chain().size()); | 2984 EXPECT_EQ(2U, r->url_chain().size()); |
| 3045 EXPECT_EQ(1, network_delegate.created_requests()); | 2985 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3046 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 2986 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3047 EXPECT_EQ("POST", r.method()); | 2987 EXPECT_EQ("POST", r->method()); |
| 3048 EXPECT_EQ(kData, d.data_received()); | 2988 EXPECT_EQ(kData, d.data_received()); |
| 3049 } | 2989 } |
| 3050 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 2990 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3051 } | 2991 } |
| 3052 | 2992 |
| 3053 // Tests that the network delegate can block and redirect a request to a new | 2993 // Tests that the network delegate can block and redirect a request to a new |
| 3054 // URL during OnHeadersReceived. | 2994 // URL during OnHeadersReceived. |
| 3055 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { | 2995 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestOnHeadersReceived) { |
| 3056 ASSERT_TRUE(test_server_.Start()); | 2996 ASSERT_TRUE(test_server_.Start()); |
| 3057 | 2997 |
| 3058 TestDelegate d; | 2998 TestDelegate d; |
| 3059 BlockingNetworkDelegate network_delegate( | 2999 BlockingNetworkDelegate network_delegate( |
| 3060 BlockingNetworkDelegate::AUTO_CALLBACK); | 3000 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3061 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3001 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3062 GURL redirect_url(test_server_.GetURL("simple.html")); | 3002 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 3063 network_delegate.set_redirect_on_headers_received_url(redirect_url); | 3003 network_delegate.set_redirect_on_headers_received_url(redirect_url); |
| 3064 | 3004 |
| 3065 TestURLRequestContextWithProxy context( | 3005 TestURLRequestContextWithProxy context( |
| 3066 test_server_.host_port_pair().ToString(), &network_delegate); | 3006 test_server_.host_port_pair().ToString(), &network_delegate); |
| 3067 | 3007 |
| 3068 { | 3008 { |
| 3069 GURL original_url(test_server_.GetURL("empty.html")); | 3009 GURL original_url(test_server_.GetURL("empty.html")); |
| 3070 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &context); | 3010 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3011 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 3071 | 3012 |
| 3072 r.Start(); | 3013 r->Start(); |
| 3073 base::RunLoop().Run(); | 3014 base::RunLoop().Run(); |
| 3074 | 3015 |
| 3075 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3016 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3076 EXPECT_TRUE(r.proxy_server().Equals(test_server_.host_port_pair())); | 3017 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); |
| 3077 EXPECT_EQ( | 3018 EXPECT_EQ( |
| 3078 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); | 3019 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); |
| 3079 EXPECT_TRUE( | 3020 EXPECT_TRUE( |
| 3080 network_delegate.last_observed_proxy().Equals( | 3021 network_delegate.last_observed_proxy().Equals( |
| 3081 test_server_.host_port_pair())); | 3022 test_server_.host_port_pair())); |
| 3082 EXPECT_EQ(net::OK, r.status().error()); | 3023 EXPECT_EQ(net::OK, r->status().error()); |
| 3083 EXPECT_EQ(redirect_url, r.url()); | 3024 EXPECT_EQ(redirect_url, r->url()); |
| 3084 EXPECT_EQ(original_url, r.original_url()); | 3025 EXPECT_EQ(original_url, r->original_url()); |
| 3085 EXPECT_EQ(2U, r.url_chain().size()); | 3026 EXPECT_EQ(2U, r->url_chain().size()); |
| 3086 EXPECT_EQ(2, network_delegate.created_requests()); | 3027 EXPECT_EQ(2, network_delegate.created_requests()); |
| 3087 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3028 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3088 } | 3029 } |
| 3089 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3030 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3090 } | 3031 } |
| 3091 | 3032 |
| 3092 // Tests that the network delegate can synchronously complete OnAuthRequired | 3033 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3093 // by taking no action. This indicates that the NetworkDelegate does not want to | 3034 // by taking no action. This indicates that the NetworkDelegate does not want to |
| 3094 // handle the challenge, and is passing the buck along to the | 3035 // handle the challenge, and is passing the buck along to the |
| 3095 // URLRequest::Delegate. | 3036 // URLRequest::Delegate. |
| 3096 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { | 3037 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { |
| 3097 ASSERT_TRUE(test_server_.Start()); | 3038 ASSERT_TRUE(test_server_.Start()); |
| 3098 | 3039 |
| 3099 TestDelegate d; | 3040 TestDelegate d; |
| 3100 BlockingNetworkDelegate network_delegate( | 3041 BlockingNetworkDelegate network_delegate( |
| 3101 BlockingNetworkDelegate::SYNCHRONOUS); | 3042 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3102 | 3043 |
| 3103 TestURLRequestContext context(true); | 3044 TestURLRequestContext context(true); |
| 3104 context.set_network_delegate(&network_delegate); | 3045 context.set_network_delegate(&network_delegate); |
| 3105 context.Init(); | 3046 context.Init(); |
| 3106 | 3047 |
| 3107 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3048 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3108 | 3049 |
| 3109 { | 3050 { |
| 3110 GURL url(test_server_.GetURL("auth-basic")); | 3051 GURL url(test_server_.GetURL("auth-basic")); |
| 3111 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3052 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3112 r.Start(); | 3053 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3054 r->Start(); |
| 3113 | 3055 |
| 3114 base::RunLoop().Run(); | 3056 base::RunLoop().Run(); |
| 3115 | 3057 |
| 3116 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3058 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3117 EXPECT_EQ(0, r.status().error()); | 3059 EXPECT_EQ(0, r->status().error()); |
| 3118 EXPECT_EQ(200, r.GetResponseCode()); | 3060 EXPECT_EQ(200, r->GetResponseCode()); |
| 3119 EXPECT_TRUE(d.auth_required_called()); | 3061 EXPECT_TRUE(d.auth_required_called()); |
| 3120 EXPECT_EQ(1, network_delegate.created_requests()); | 3062 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3121 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3063 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3122 } | 3064 } |
| 3123 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3065 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3124 } | 3066 } |
| 3125 | 3067 |
| 3126 TEST_F(URLRequestTestHTTP, | 3068 TEST_F(URLRequestTestHTTP, |
| 3127 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { | 3069 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { |
| 3128 ASSERT_TRUE(test_server_.Start()); | 3070 ASSERT_TRUE(test_server_.Start()); |
| 3129 | 3071 |
| 3130 TestDelegate d; | 3072 TestDelegate d; |
| 3131 BlockingNetworkDelegate network_delegate( | 3073 BlockingNetworkDelegate network_delegate( |
| 3132 BlockingNetworkDelegate::SYNCHRONOUS); | 3074 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3133 | 3075 |
| 3134 TestURLRequestContext context(true); | 3076 TestURLRequestContext context(true); |
| 3135 context.set_network_delegate(&network_delegate); | 3077 context.set_network_delegate(&network_delegate); |
| 3136 context.Init(); | 3078 context.Init(); |
| 3137 | 3079 |
| 3138 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3080 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3139 | 3081 |
| 3140 { | 3082 { |
| 3141 GURL url(test_server_.GetURL("auth-basic")); | 3083 GURL url(test_server_.GetURL("auth-basic")); |
| 3142 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3084 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3143 r.Start(); | 3085 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3086 r->Start(); |
| 3144 | 3087 |
| 3145 { | 3088 { |
| 3146 HttpRequestHeaders headers; | 3089 HttpRequestHeaders headers; |
| 3147 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); | 3090 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| 3148 EXPECT_FALSE(headers.HasHeader("Authorization")); | 3091 EXPECT_FALSE(headers.HasHeader("Authorization")); |
| 3149 } | 3092 } |
| 3150 | 3093 |
| 3151 base::RunLoop().Run(); | 3094 base::RunLoop().Run(); |
| 3152 | 3095 |
| 3153 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3096 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3154 EXPECT_EQ(0, r.status().error()); | 3097 EXPECT_EQ(0, r->status().error()); |
| 3155 EXPECT_EQ(200, r.GetResponseCode()); | 3098 EXPECT_EQ(200, r->GetResponseCode()); |
| 3156 EXPECT_TRUE(d.auth_required_called()); | 3099 EXPECT_TRUE(d.auth_required_called()); |
| 3157 EXPECT_EQ(1, network_delegate.created_requests()); | 3100 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3158 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3101 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3159 } | 3102 } |
| 3160 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3103 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3161 } | 3104 } |
| 3162 | 3105 |
| 3163 // Tests that the network delegate can synchronously complete OnAuthRequired | 3106 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3164 // by setting credentials. | 3107 // by setting credentials. |
| 3165 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { | 3108 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { |
| 3166 ASSERT_TRUE(test_server_.Start()); | 3109 ASSERT_TRUE(test_server_.Start()); |
| 3167 | 3110 |
| 3168 TestDelegate d; | 3111 TestDelegate d; |
| 3169 BlockingNetworkDelegate network_delegate( | 3112 BlockingNetworkDelegate network_delegate( |
| 3170 BlockingNetworkDelegate::SYNCHRONOUS); | 3113 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3171 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3114 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3172 network_delegate.set_auth_retval( | 3115 network_delegate.set_auth_retval( |
| 3173 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3116 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3174 | 3117 |
| 3175 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3118 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 3176 | 3119 |
| 3177 TestURLRequestContext context(true); | 3120 TestURLRequestContext context(true); |
| 3178 context.set_network_delegate(&network_delegate); | 3121 context.set_network_delegate(&network_delegate); |
| 3179 context.Init(); | 3122 context.Init(); |
| 3180 | 3123 |
| 3181 { | 3124 { |
| 3182 GURL url(test_server_.GetURL("auth-basic")); | 3125 GURL url(test_server_.GetURL("auth-basic")); |
| 3183 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3126 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3184 r.Start(); | 3127 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3128 r->Start(); |
| 3185 base::RunLoop().Run(); | 3129 base::RunLoop().Run(); |
| 3186 | 3130 |
| 3187 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3131 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3188 EXPECT_EQ(0, r.status().error()); | 3132 EXPECT_EQ(0, r->status().error()); |
| 3189 EXPECT_EQ(200, r.GetResponseCode()); | 3133 EXPECT_EQ(200, r->GetResponseCode()); |
| 3190 EXPECT_FALSE(d.auth_required_called()); | 3134 EXPECT_FALSE(d.auth_required_called()); |
| 3191 EXPECT_EQ(1, network_delegate.created_requests()); | 3135 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3192 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3136 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3193 } | 3137 } |
| 3194 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3138 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3195 } | 3139 } |
| 3196 | 3140 |
| 3197 // Same as above, but also tests that GetFullRequestHeaders returns the proper | 3141 // Same as above, but also tests that GetFullRequestHeaders returns the proper |
| 3198 // headers (for the first or second request) when called at the proper times. | 3142 // headers (for the first or second request) when called at the proper times. |
| 3199 TEST_F(URLRequestTestHTTP, | 3143 TEST_F(URLRequestTestHTTP, |
| 3200 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { | 3144 NetworkDelegateOnAuthRequiredSyncSetAuth_GetFullRequestHeaders) { |
| 3201 ASSERT_TRUE(test_server_.Start()); | 3145 ASSERT_TRUE(test_server_.Start()); |
| 3202 | 3146 |
| 3203 TestDelegate d; | 3147 TestDelegate d; |
| 3204 BlockingNetworkDelegate network_delegate( | 3148 BlockingNetworkDelegate network_delegate( |
| 3205 BlockingNetworkDelegate::SYNCHRONOUS); | 3149 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3206 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3150 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3207 network_delegate.set_auth_retval( | 3151 network_delegate.set_auth_retval( |
| 3208 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3152 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3209 | 3153 |
| 3210 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 3154 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 3211 | 3155 |
| 3212 TestURLRequestContext context(true); | 3156 TestURLRequestContext context(true); |
| 3213 context.set_network_delegate(&network_delegate); | 3157 context.set_network_delegate(&network_delegate); |
| 3214 context.Init(); | 3158 context.Init(); |
| 3215 | 3159 |
| 3216 { | 3160 { |
| 3217 GURL url(test_server_.GetURL("auth-basic")); | 3161 GURL url(test_server_.GetURL("auth-basic")); |
| 3218 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3162 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3219 r.Start(); | 3163 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3164 r->Start(); |
| 3220 base::RunLoop().Run(); | 3165 base::RunLoop().Run(); |
| 3221 | 3166 |
| 3222 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3167 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3223 EXPECT_EQ(0, r.status().error()); | 3168 EXPECT_EQ(0, r->status().error()); |
| 3224 EXPECT_EQ(200, r.GetResponseCode()); | 3169 EXPECT_EQ(200, r->GetResponseCode()); |
| 3225 EXPECT_FALSE(d.auth_required_called()); | 3170 EXPECT_FALSE(d.auth_required_called()); |
| 3226 EXPECT_EQ(1, network_delegate.created_requests()); | 3171 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3227 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3172 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3228 | 3173 |
| 3229 { | 3174 { |
| 3230 HttpRequestHeaders headers; | 3175 HttpRequestHeaders headers; |
| 3231 EXPECT_TRUE(r.GetFullRequestHeaders(&headers)); | 3176 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| 3232 EXPECT_TRUE(headers.HasHeader("Authorization")); | 3177 EXPECT_TRUE(headers.HasHeader("Authorization")); |
| 3233 } | 3178 } |
| 3234 } | 3179 } |
| 3235 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3180 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3236 } | 3181 } |
| 3237 | 3182 |
| 3238 // Tests that the network delegate can synchronously complete OnAuthRequired | 3183 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 3239 // by cancelling authentication. | 3184 // by cancelling authentication. |
| 3240 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { | 3185 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { |
| 3241 ASSERT_TRUE(test_server_.Start()); | 3186 ASSERT_TRUE(test_server_.Start()); |
| 3242 | 3187 |
| 3243 TestDelegate d; | 3188 TestDelegate d; |
| 3244 BlockingNetworkDelegate network_delegate( | 3189 BlockingNetworkDelegate network_delegate( |
| 3245 BlockingNetworkDelegate::SYNCHRONOUS); | 3190 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3246 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3191 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3247 network_delegate.set_auth_retval( | 3192 network_delegate.set_auth_retval( |
| 3248 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3193 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 3249 | 3194 |
| 3250 TestURLRequestContext context(true); | 3195 TestURLRequestContext context(true); |
| 3251 context.set_network_delegate(&network_delegate); | 3196 context.set_network_delegate(&network_delegate); |
| 3252 context.Init(); | 3197 context.Init(); |
| 3253 | 3198 |
| 3254 { | 3199 { |
| 3255 GURL url(test_server_.GetURL("auth-basic")); | 3200 GURL url(test_server_.GetURL("auth-basic")); |
| 3256 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3201 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3257 r.Start(); | 3202 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3203 r->Start(); |
| 3258 base::RunLoop().Run(); | 3204 base::RunLoop().Run(); |
| 3259 | 3205 |
| 3260 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3206 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3261 EXPECT_EQ(OK, r.status().error()); | 3207 EXPECT_EQ(OK, r->status().error()); |
| 3262 EXPECT_EQ(401, r.GetResponseCode()); | 3208 EXPECT_EQ(401, r->GetResponseCode()); |
| 3263 EXPECT_FALSE(d.auth_required_called()); | 3209 EXPECT_FALSE(d.auth_required_called()); |
| 3264 EXPECT_EQ(1, network_delegate.created_requests()); | 3210 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3265 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3211 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3266 } | 3212 } |
| 3267 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3213 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3268 } | 3214 } |
| 3269 | 3215 |
| 3270 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3216 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3271 // by taking no action. This indicates that the NetworkDelegate does not want | 3217 // by taking no action. This indicates that the NetworkDelegate does not want |
| 3272 // to handle the challenge, and is passing the buck along to the | 3218 // to handle the challenge, and is passing the buck along to the |
| 3273 // URLRequest::Delegate. | 3219 // URLRequest::Delegate. |
| 3274 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { | 3220 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { |
| 3275 ASSERT_TRUE(test_server_.Start()); | 3221 ASSERT_TRUE(test_server_.Start()); |
| 3276 | 3222 |
| 3277 TestDelegate d; | 3223 TestDelegate d; |
| 3278 BlockingNetworkDelegate network_delegate( | 3224 BlockingNetworkDelegate network_delegate( |
| 3279 BlockingNetworkDelegate::AUTO_CALLBACK); | 3225 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3280 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3226 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3281 | 3227 |
| 3282 TestURLRequestContext context(true); | 3228 TestURLRequestContext context(true); |
| 3283 context.set_network_delegate(&network_delegate); | 3229 context.set_network_delegate(&network_delegate); |
| 3284 context.Init(); | 3230 context.Init(); |
| 3285 | 3231 |
| 3286 d.set_credentials(AuthCredentials(kUser, kSecret)); | 3232 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 3287 | 3233 |
| 3288 { | 3234 { |
| 3289 GURL url(test_server_.GetURL("auth-basic")); | 3235 GURL url(test_server_.GetURL("auth-basic")); |
| 3290 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3236 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3291 r.Start(); | 3237 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3238 r->Start(); |
| 3292 base::RunLoop().Run(); | 3239 base::RunLoop().Run(); |
| 3293 | 3240 |
| 3294 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3241 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3295 EXPECT_EQ(0, r.status().error()); | 3242 EXPECT_EQ(0, r->status().error()); |
| 3296 EXPECT_EQ(200, r.GetResponseCode()); | 3243 EXPECT_EQ(200, r->GetResponseCode()); |
| 3297 EXPECT_TRUE(d.auth_required_called()); | 3244 EXPECT_TRUE(d.auth_required_called()); |
| 3298 EXPECT_EQ(1, network_delegate.created_requests()); | 3245 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3299 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3246 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3300 } | 3247 } |
| 3301 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3248 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3302 } | 3249 } |
| 3303 | 3250 |
| 3304 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3251 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3305 // by setting credentials. | 3252 // by setting credentials. |
| 3306 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { | 3253 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { |
| 3307 ASSERT_TRUE(test_server_.Start()); | 3254 ASSERT_TRUE(test_server_.Start()); |
| 3308 | 3255 |
| 3309 TestDelegate d; | 3256 TestDelegate d; |
| 3310 BlockingNetworkDelegate network_delegate( | 3257 BlockingNetworkDelegate network_delegate( |
| 3311 BlockingNetworkDelegate::AUTO_CALLBACK); | 3258 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3312 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3259 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3313 network_delegate.set_auth_retval( | 3260 network_delegate.set_auth_retval( |
| 3314 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 3261 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 3315 | 3262 |
| 3316 AuthCredentials auth_credentials(kUser, kSecret); | 3263 AuthCredentials auth_credentials(kUser, kSecret); |
| 3317 network_delegate.set_auth_credentials(auth_credentials); | 3264 network_delegate.set_auth_credentials(auth_credentials); |
| 3318 | 3265 |
| 3319 TestURLRequestContext context(true); | 3266 TestURLRequestContext context(true); |
| 3320 context.set_network_delegate(&network_delegate); | 3267 context.set_network_delegate(&network_delegate); |
| 3321 context.Init(); | 3268 context.Init(); |
| 3322 | 3269 |
| 3323 { | 3270 { |
| 3324 GURL url(test_server_.GetURL("auth-basic")); | 3271 GURL url(test_server_.GetURL("auth-basic")); |
| 3325 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3272 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3326 r.Start(); | 3273 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3274 r->Start(); |
| 3327 base::RunLoop().Run(); | 3275 base::RunLoop().Run(); |
| 3328 | 3276 |
| 3329 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3277 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3330 EXPECT_EQ(0, r.status().error()); | 3278 EXPECT_EQ(0, r->status().error()); |
| 3331 | 3279 |
| 3332 EXPECT_EQ(200, r.GetResponseCode()); | 3280 EXPECT_EQ(200, r->GetResponseCode()); |
| 3333 EXPECT_FALSE(d.auth_required_called()); | 3281 EXPECT_FALSE(d.auth_required_called()); |
| 3334 EXPECT_EQ(1, network_delegate.created_requests()); | 3282 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3335 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3283 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3336 } | 3284 } |
| 3337 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3285 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3338 } | 3286 } |
| 3339 | 3287 |
| 3340 // Tests that the network delegate can asynchronously complete OnAuthRequired | 3288 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 3341 // by cancelling authentication. | 3289 // by cancelling authentication. |
| 3342 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { | 3290 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { |
| 3343 ASSERT_TRUE(test_server_.Start()); | 3291 ASSERT_TRUE(test_server_.Start()); |
| 3344 | 3292 |
| 3345 TestDelegate d; | 3293 TestDelegate d; |
| 3346 BlockingNetworkDelegate network_delegate( | 3294 BlockingNetworkDelegate network_delegate( |
| 3347 BlockingNetworkDelegate::AUTO_CALLBACK); | 3295 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3348 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3296 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3349 network_delegate.set_auth_retval( | 3297 network_delegate.set_auth_retval( |
| 3350 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 3298 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 3351 | 3299 |
| 3352 TestURLRequestContext context(true); | 3300 TestURLRequestContext context(true); |
| 3353 context.set_network_delegate(&network_delegate); | 3301 context.set_network_delegate(&network_delegate); |
| 3354 context.Init(); | 3302 context.Init(); |
| 3355 | 3303 |
| 3356 { | 3304 { |
| 3357 GURL url(test_server_.GetURL("auth-basic")); | 3305 GURL url(test_server_.GetURL("auth-basic")); |
| 3358 URLRequest r(url, DEFAULT_PRIORITY, &d, &context); | 3306 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3359 r.Start(); | 3307 url, DEFAULT_PRIORITY, &d, NULL)); |
| 3308 r->Start(); |
| 3360 base::RunLoop().Run(); | 3309 base::RunLoop().Run(); |
| 3361 | 3310 |
| 3362 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 3311 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 3363 EXPECT_EQ(OK, r.status().error()); | 3312 EXPECT_EQ(OK, r->status().error()); |
| 3364 EXPECT_EQ(401, r.GetResponseCode()); | 3313 EXPECT_EQ(401, r->GetResponseCode()); |
| 3365 EXPECT_FALSE(d.auth_required_called()); | 3314 EXPECT_FALSE(d.auth_required_called()); |
| 3366 EXPECT_EQ(1, network_delegate.created_requests()); | 3315 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3367 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3316 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3368 } | 3317 } |
| 3369 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3318 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3370 } | 3319 } |
| 3371 | 3320 |
| 3372 // Tests that we can handle when a network request was canceled while we were | 3321 // Tests that we can handle when a network request was canceled while we were |
| 3373 // waiting for the network delegate. | 3322 // waiting for the network delegate. |
| 3374 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 3323 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
| 3375 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 3324 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
| 3376 ASSERT_TRUE(test_server_.Start()); | 3325 ASSERT_TRUE(test_server_.Start()); |
| 3377 | 3326 |
| 3378 TestDelegate d; | 3327 TestDelegate d; |
| 3379 BlockingNetworkDelegate network_delegate( | 3328 BlockingNetworkDelegate network_delegate( |
| 3380 BlockingNetworkDelegate::USER_CALLBACK); | 3329 BlockingNetworkDelegate::USER_CALLBACK); |
| 3381 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3330 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3382 | 3331 |
| 3383 TestURLRequestContext context(true); | 3332 TestURLRequestContext context(true); |
| 3384 context.set_network_delegate(&network_delegate); | 3333 context.set_network_delegate(&network_delegate); |
| 3385 context.Init(); | 3334 context.Init(); |
| 3386 | 3335 |
| 3387 { | 3336 { |
| 3388 URLRequest r( | 3337 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3389 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); | 3338 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3390 | 3339 |
| 3391 r.Start(); | 3340 r->Start(); |
| 3392 base::RunLoop().Run(); | 3341 base::RunLoop().Run(); |
| 3393 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 3342 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 3394 network_delegate.stage_blocked_for_callback()); | 3343 network_delegate.stage_blocked_for_callback()); |
| 3395 EXPECT_EQ(0, network_delegate.completed_requests()); | 3344 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3396 // Cancel before callback. | 3345 // Cancel before callback. |
| 3397 r.Cancel(); | 3346 r->Cancel(); |
| 3398 // Ensure that network delegate is notified. | 3347 // Ensure that network delegate is notified. |
| 3399 EXPECT_EQ(1, network_delegate.completed_requests()); | 3348 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 3400 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3349 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 3401 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3350 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 3402 EXPECT_EQ(1, network_delegate.created_requests()); | 3351 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3403 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3352 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3404 } | 3353 } |
| 3405 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3354 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3406 } | 3355 } |
| 3407 | 3356 |
| 3408 // Tests that we can handle when a network request was canceled while we were | 3357 // Tests that we can handle when a network request was canceled while we were |
| 3409 // waiting for the network delegate. | 3358 // waiting for the network delegate. |
| 3410 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. | 3359 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. |
| 3411 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { | 3360 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { |
| 3412 ASSERT_TRUE(test_server_.Start()); | 3361 ASSERT_TRUE(test_server_.Start()); |
| 3413 | 3362 |
| 3414 TestDelegate d; | 3363 TestDelegate d; |
| 3415 BlockingNetworkDelegate network_delegate( | 3364 BlockingNetworkDelegate network_delegate( |
| 3416 BlockingNetworkDelegate::USER_CALLBACK); | 3365 BlockingNetworkDelegate::USER_CALLBACK); |
| 3417 network_delegate.set_block_on( | 3366 network_delegate.set_block_on( |
| 3418 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); | 3367 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); |
| 3419 | 3368 |
| 3420 TestURLRequestContext context(true); | 3369 TestURLRequestContext context(true); |
| 3421 context.set_network_delegate(&network_delegate); | 3370 context.set_network_delegate(&network_delegate); |
| 3422 context.Init(); | 3371 context.Init(); |
| 3423 | 3372 |
| 3424 { | 3373 { |
| 3425 URLRequest r( | 3374 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3426 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); | 3375 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3427 | 3376 |
| 3428 r.Start(); | 3377 r->Start(); |
| 3429 base::RunLoop().Run(); | 3378 base::RunLoop().Run(); |
| 3430 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 3379 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 3431 network_delegate.stage_blocked_for_callback()); | 3380 network_delegate.stage_blocked_for_callback()); |
| 3432 EXPECT_EQ(0, network_delegate.completed_requests()); | 3381 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3433 // Cancel before callback. | 3382 // Cancel before callback. |
| 3434 r.Cancel(); | 3383 r->Cancel(); |
| 3435 // Ensure that network delegate is notified. | 3384 // Ensure that network delegate is notified. |
| 3436 EXPECT_EQ(1, network_delegate.completed_requests()); | 3385 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 3437 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3386 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 3438 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3387 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 3439 EXPECT_EQ(1, network_delegate.created_requests()); | 3388 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3440 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3389 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3441 } | 3390 } |
| 3442 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3391 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3443 } | 3392 } |
| 3444 | 3393 |
| 3445 // Tests that we can handle when a network request was canceled while we were | 3394 // Tests that we can handle when a network request was canceled while we were |
| 3446 // waiting for the network delegate. | 3395 // waiting for the network delegate. |
| 3447 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. | 3396 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. |
| 3448 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { | 3397 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { |
| 3449 ASSERT_TRUE(test_server_.Start()); | 3398 ASSERT_TRUE(test_server_.Start()); |
| 3450 | 3399 |
| 3451 TestDelegate d; | 3400 TestDelegate d; |
| 3452 BlockingNetworkDelegate network_delegate( | 3401 BlockingNetworkDelegate network_delegate( |
| 3453 BlockingNetworkDelegate::USER_CALLBACK); | 3402 BlockingNetworkDelegate::USER_CALLBACK); |
| 3454 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3403 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3455 | 3404 |
| 3456 TestURLRequestContext context(true); | 3405 TestURLRequestContext context(true); |
| 3457 context.set_network_delegate(&network_delegate); | 3406 context.set_network_delegate(&network_delegate); |
| 3458 context.Init(); | 3407 context.Init(); |
| 3459 | 3408 |
| 3460 { | 3409 { |
| 3461 URLRequest r( | 3410 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3462 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context); | 3411 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3463 | 3412 |
| 3464 r.Start(); | 3413 r->Start(); |
| 3465 base::RunLoop().Run(); | 3414 base::RunLoop().Run(); |
| 3466 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 3415 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 3467 network_delegate.stage_blocked_for_callback()); | 3416 network_delegate.stage_blocked_for_callback()); |
| 3468 EXPECT_EQ(0, network_delegate.completed_requests()); | 3417 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3469 // Cancel before callback. | 3418 // Cancel before callback. |
| 3470 r.Cancel(); | 3419 r->Cancel(); |
| 3471 // Ensure that network delegate is notified. | 3420 // Ensure that network delegate is notified. |
| 3472 EXPECT_EQ(1, network_delegate.completed_requests()); | 3421 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 3473 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3422 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 3474 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3423 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 3475 EXPECT_EQ(1, network_delegate.created_requests()); | 3424 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3476 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3425 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3477 } | 3426 } |
| 3478 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3427 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3479 } | 3428 } |
| 3480 | 3429 |
| 3481 // Tests that we can handle when a network request was canceled while we were | 3430 // Tests that we can handle when a network request was canceled while we were |
| 3482 // waiting for the network delegate. | 3431 // waiting for the network delegate. |
| 3483 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. | 3432 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. |
| 3484 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { | 3433 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { |
| 3485 ASSERT_TRUE(test_server_.Start()); | 3434 ASSERT_TRUE(test_server_.Start()); |
| 3486 | 3435 |
| 3487 TestDelegate d; | 3436 TestDelegate d; |
| 3488 BlockingNetworkDelegate network_delegate( | 3437 BlockingNetworkDelegate network_delegate( |
| 3489 BlockingNetworkDelegate::USER_CALLBACK); | 3438 BlockingNetworkDelegate::USER_CALLBACK); |
| 3490 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 3439 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 3491 | 3440 |
| 3492 TestURLRequestContext context(true); | 3441 TestURLRequestContext context(true); |
| 3493 context.set_network_delegate(&network_delegate); | 3442 context.set_network_delegate(&network_delegate); |
| 3494 context.Init(); | 3443 context.Init(); |
| 3495 | 3444 |
| 3496 { | 3445 { |
| 3497 URLRequest r( | 3446 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3498 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, &context); | 3447 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); |
| 3499 | 3448 |
| 3500 r.Start(); | 3449 r->Start(); |
| 3501 base::RunLoop().Run(); | 3450 base::RunLoop().Run(); |
| 3502 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, | 3451 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, |
| 3503 network_delegate.stage_blocked_for_callback()); | 3452 network_delegate.stage_blocked_for_callback()); |
| 3504 EXPECT_EQ(0, network_delegate.completed_requests()); | 3453 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 3505 // Cancel before callback. | 3454 // Cancel before callback. |
| 3506 r.Cancel(); | 3455 r->Cancel(); |
| 3507 // Ensure that network delegate is notified. | 3456 // Ensure that network delegate is notified. |
| 3508 EXPECT_EQ(1, network_delegate.completed_requests()); | 3457 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 3509 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 3458 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 3510 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 3459 EXPECT_EQ(ERR_ABORTED, r->status().error()); |
| 3511 EXPECT_EQ(1, network_delegate.created_requests()); | 3460 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3512 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3461 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3513 } | 3462 } |
| 3514 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 3463 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 3515 } | 3464 } |
| 3516 | 3465 |
| 3517 // In this unit test, we're using the HTTPTestServer as a proxy server and | 3466 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 3518 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 3467 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 3519 // The HTTPTestServer will return a 401 response, which we should balk at. | 3468 // The HTTPTestServer will return a 401 response, which we should balk at. |
| 3520 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 3469 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 3521 ASSERT_TRUE(test_server_.Start()); | 3470 ASSERT_TRUE(test_server_.Start()); |
| 3522 | 3471 |
| 3523 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3472 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3524 TestURLRequestContextWithProxy context( | 3473 TestURLRequestContextWithProxy context( |
| 3525 test_server_.host_port_pair().ToString(), &network_delegate); | 3474 test_server_.host_port_pair().ToString(), &network_delegate); |
| 3526 | 3475 |
| 3527 TestDelegate d; | 3476 TestDelegate d; |
| 3528 { | 3477 { |
| 3529 URLRequest r( | 3478 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3530 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, &context); | 3479 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, NULL)); |
| 3531 | 3480 |
| 3532 r.Start(); | 3481 r->Start(); |
| 3533 EXPECT_TRUE(r.is_pending()); | 3482 EXPECT_TRUE(r->is_pending()); |
| 3534 | 3483 |
| 3535 base::RunLoop().Run(); | 3484 base::RunLoop().Run(); |
| 3536 | 3485 |
| 3537 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 3486 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3538 // The proxy server is not set before failure. | 3487 // The proxy server is not set before failure. |
| 3539 EXPECT_TRUE(r.proxy_server().IsEmpty()); | 3488 EXPECT_TRUE(r->proxy_server().IsEmpty()); |
| 3540 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 3489 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); |
| 3541 } | 3490 } |
| 3542 } | 3491 } |
| 3543 | 3492 |
| 3544 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 3493 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 3545 ASSERT_TRUE(test_server_.Start()); | 3494 ASSERT_TRUE(test_server_.Start()); |
| 3546 | 3495 |
| 3547 TestDelegate d; | 3496 TestDelegate d; |
| 3548 { | 3497 { |
| 3549 URLRequest r(test_server_.GetURL(std::string()), | 3498 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3550 DEFAULT_PRIORITY, | 3499 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3551 &d, | |
| 3552 &default_context_); | |
| 3553 | 3500 |
| 3554 r.Start(); | 3501 r->Start(); |
| 3555 EXPECT_TRUE(r.is_pending()); | 3502 EXPECT_TRUE(r->is_pending()); |
| 3556 | 3503 |
| 3557 base::RunLoop().Run(); | 3504 base::RunLoop().Run(); |
| 3558 | 3505 |
| 3559 EXPECT_EQ(1, d.response_started_count()); | 3506 EXPECT_EQ(1, d.response_started_count()); |
| 3560 EXPECT_FALSE(d.received_data_before_response()); | 3507 EXPECT_FALSE(d.received_data_before_response()); |
| 3561 EXPECT_NE(0, d.bytes_received()); | 3508 EXPECT_NE(0, d.bytes_received()); |
| 3562 EXPECT_EQ(test_server_.host_port_pair().host(), | 3509 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3563 r.GetSocketAddress().host()); | 3510 r->GetSocketAddress().host()); |
| 3564 EXPECT_EQ(test_server_.host_port_pair().port(), | 3511 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3565 r.GetSocketAddress().port()); | 3512 r->GetSocketAddress().port()); |
| 3566 | 3513 |
| 3567 // TODO(eroman): Add back the NetLog tests... | 3514 // TODO(eroman): Add back the NetLog tests... |
| 3568 } | 3515 } |
| 3569 } | 3516 } |
| 3570 | 3517 |
| 3571 // This test has the server send a large number of cookies to the client. | 3518 // This test has the server send a large number of cookies to the client. |
| 3572 // To ensure that no number of cookies causes a crash, a galloping binary | 3519 // To ensure that no number of cookies causes a crash, a galloping binary |
| 3573 // search is used to estimate that maximum number of cookies that are accepted | 3520 // search is used to estimate that maximum number of cookies that are accepted |
| 3574 // by the browser. Beyond the maximum number, the request will fail with | 3521 // by the browser. Beyond the maximum number, the request will fail with |
| 3575 // ERR_RESPONSE_HEADERS_TOO_BIG. | 3522 // ERR_RESPONSE_HEADERS_TOO_BIG. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3608 upper_bound = num_cookies; | 3555 upper_bound = num_cookies; |
| 3609 } | 3556 } |
| 3610 // Success: the test did not crash. | 3557 // Success: the test did not crash. |
| 3611 } | 3558 } |
| 3612 | 3559 |
| 3613 TEST_F(URLRequestTestHTTP, GetTest) { | 3560 TEST_F(URLRequestTestHTTP, GetTest) { |
| 3614 ASSERT_TRUE(test_server_.Start()); | 3561 ASSERT_TRUE(test_server_.Start()); |
| 3615 | 3562 |
| 3616 TestDelegate d; | 3563 TestDelegate d; |
| 3617 { | 3564 { |
| 3618 URLRequest r(test_server_.GetURL(std::string()), | 3565 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3619 DEFAULT_PRIORITY, | 3566 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3620 &d, | |
| 3621 &default_context_); | |
| 3622 | 3567 |
| 3623 r.Start(); | 3568 r->Start(); |
| 3624 EXPECT_TRUE(r.is_pending()); | 3569 EXPECT_TRUE(r->is_pending()); |
| 3625 | 3570 |
| 3626 base::RunLoop().Run(); | 3571 base::RunLoop().Run(); |
| 3627 | 3572 |
| 3628 EXPECT_EQ(1, d.response_started_count()); | 3573 EXPECT_EQ(1, d.response_started_count()); |
| 3629 EXPECT_FALSE(d.received_data_before_response()); | 3574 EXPECT_FALSE(d.received_data_before_response()); |
| 3630 EXPECT_NE(0, d.bytes_received()); | 3575 EXPECT_NE(0, d.bytes_received()); |
| 3631 EXPECT_EQ(test_server_.host_port_pair().host(), | 3576 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3632 r.GetSocketAddress().host()); | 3577 r->GetSocketAddress().host()); |
| 3633 EXPECT_EQ(test_server_.host_port_pair().port(), | 3578 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3634 r.GetSocketAddress().port()); | 3579 r->GetSocketAddress().port()); |
| 3635 } | 3580 } |
| 3636 } | 3581 } |
| 3637 | 3582 |
| 3638 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { | 3583 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { |
| 3639 ASSERT_TRUE(test_server_.Start()); | 3584 ASSERT_TRUE(test_server_.Start()); |
| 3640 | 3585 |
| 3641 TestDelegate d; | 3586 TestDelegate d; |
| 3642 { | 3587 { |
| 3643 GURL test_url(test_server_.GetURL(std::string())); | 3588 GURL test_url(test_server_.GetURL(std::string())); |
| 3644 URLRequest r(test_url, DEFAULT_PRIORITY, &d, &default_context_); | 3589 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3590 test_url, DEFAULT_PRIORITY, &d, NULL)); |
| 3645 | 3591 |
| 3646 HttpRequestHeaders headers; | 3592 HttpRequestHeaders headers; |
| 3647 EXPECT_FALSE(r.GetFullRequestHeaders(&headers)); | 3593 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 3648 | 3594 |
| 3649 r.Start(); | 3595 r->Start(); |
| 3650 EXPECT_TRUE(r.is_pending()); | 3596 EXPECT_TRUE(r->is_pending()); |
| 3651 | 3597 |
| 3652 base::RunLoop().Run(); | 3598 base::RunLoop().Run(); |
| 3653 | 3599 |
| 3654 EXPECT_EQ(1, d.response_started_count()); | 3600 EXPECT_EQ(1, d.response_started_count()); |
| 3655 EXPECT_FALSE(d.received_data_before_response()); | 3601 EXPECT_FALSE(d.received_data_before_response()); |
| 3656 EXPECT_NE(0, d.bytes_received()); | 3602 EXPECT_NE(0, d.bytes_received()); |
| 3657 EXPECT_EQ(test_server_.host_port_pair().host(), | 3603 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3658 r.GetSocketAddress().host()); | 3604 r->GetSocketAddress().host()); |
| 3659 EXPECT_EQ(test_server_.host_port_pair().port(), | 3605 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3660 r.GetSocketAddress().port()); | 3606 r->GetSocketAddress().port()); |
| 3661 | 3607 |
| 3662 EXPECT_TRUE(d.have_full_request_headers()); | 3608 EXPECT_TRUE(d.have_full_request_headers()); |
| 3663 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 3609 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 3664 } | 3610 } |
| 3665 } | 3611 } |
| 3666 | 3612 |
| 3667 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { | 3613 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { |
| 3668 ASSERT_TRUE(test_server_.Start()); | 3614 ASSERT_TRUE(test_server_.Start()); |
| 3669 | 3615 |
| 3670 TestDelegate d; | 3616 TestDelegate d; |
| 3671 { | 3617 { |
| 3672 URLRequest r(test_server_.GetURL(std::string()), | 3618 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3673 DEFAULT_PRIORITY, | 3619 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 3674 &d, | |
| 3675 &default_context_); | |
| 3676 | 3620 |
| 3677 r.Start(); | 3621 r->Start(); |
| 3678 EXPECT_TRUE(r.is_pending()); | 3622 EXPECT_TRUE(r->is_pending()); |
| 3679 | 3623 |
| 3680 base::RunLoop().Run(); | 3624 base::RunLoop().Run(); |
| 3681 | 3625 |
| 3682 LoadTimingInfo load_timing_info; | 3626 LoadTimingInfo load_timing_info; |
| 3683 r.GetLoadTimingInfo(&load_timing_info); | 3627 r->GetLoadTimingInfo(&load_timing_info); |
| 3684 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 3628 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 3685 | 3629 |
| 3686 EXPECT_EQ(1, d.response_started_count()); | 3630 EXPECT_EQ(1, d.response_started_count()); |
| 3687 EXPECT_FALSE(d.received_data_before_response()); | 3631 EXPECT_FALSE(d.received_data_before_response()); |
| 3688 EXPECT_NE(0, d.bytes_received()); | 3632 EXPECT_NE(0, d.bytes_received()); |
| 3689 EXPECT_EQ(test_server_.host_port_pair().host(), | 3633 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 3690 r.GetSocketAddress().host()); | 3634 r->GetSocketAddress().host()); |
| 3691 EXPECT_EQ(test_server_.host_port_pair().port(), | 3635 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 3692 r.GetSocketAddress().port()); | 3636 r->GetSocketAddress().port()); |
| 3693 } | 3637 } |
| 3694 } | 3638 } |
| 3695 | 3639 |
| 3696 TEST_F(URLRequestTestHTTP, GetZippedTest) { | 3640 TEST_F(URLRequestTestHTTP, GetZippedTest) { |
| 3697 ASSERT_TRUE(test_server_.Start()); | 3641 ASSERT_TRUE(test_server_.Start()); |
| 3698 | 3642 |
| 3699 // Parameter that specifies the Content-Length field in the response: | 3643 // Parameter that specifies the Content-Length field in the response: |
| 3700 // C - Compressed length. | 3644 // C - Compressed length. |
| 3701 // U - Uncompressed length. | 3645 // U - Uncompressed length. |
| 3702 // L - Large length (larger than both C & U). | 3646 // L - Large length (larger than both C & U). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3715 { | 3659 { |
| 3716 std::string test_file = | 3660 std::string test_file = |
| 3717 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 3661 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
| 3718 test_parameters[i]); | 3662 test_parameters[i]); |
| 3719 | 3663 |
| 3720 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3664 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3721 TestURLRequestContext context(true); | 3665 TestURLRequestContext context(true); |
| 3722 context.set_network_delegate(&network_delegate); | 3666 context.set_network_delegate(&network_delegate); |
| 3723 context.Init(); | 3667 context.Init(); |
| 3724 | 3668 |
| 3725 URLRequest r( | 3669 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 3726 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, &context); | 3670 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, NULL)); |
| 3727 r.Start(); | 3671 r->Start(); |
| 3728 EXPECT_TRUE(r.is_pending()); | 3672 EXPECT_TRUE(r->is_pending()); |
| 3729 | 3673 |
| 3730 base::RunLoop().Run(); | 3674 base::RunLoop().Run(); |
| 3731 | 3675 |
| 3732 EXPECT_EQ(1, d.response_started_count()); | 3676 EXPECT_EQ(1, d.response_started_count()); |
| 3733 EXPECT_FALSE(d.received_data_before_response()); | 3677 EXPECT_FALSE(d.received_data_before_response()); |
| 3734 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 3678 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 3735 << " status = " << r.status().status() | 3679 << " status = " << r->status().status() |
| 3736 << " error = " << r.status().error(); | 3680 << " error = " << r->status().error(); |
| 3737 if (test_expect_success[i]) { | 3681 if (test_expect_success[i]) { |
| 3738 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()) | 3682 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) |
| 3739 << " Parameter = \"" << test_file << "\""; | 3683 << " Parameter = \"" << test_file << "\""; |
| 3740 } else { | 3684 } else { |
| 3741 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 3685 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3742 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r.status().error()) | 3686 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
| 3743 << " Parameter = \"" << test_file << "\""; | 3687 << " Parameter = \"" << test_file << "\""; |
| 3744 } | 3688 } |
| 3745 } | 3689 } |
| 3746 } | 3690 } |
| 3747 } | 3691 } |
| 3748 | 3692 |
| 3749 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 3693 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { |
| 3750 ASSERT_TRUE(test_server_.Start()); | 3694 ASSERT_TRUE(test_server_.Start()); |
| 3751 | 3695 |
| 3752 SpawnedTestServer https_test_server( | 3696 SpawnedTestServer https_test_server( |
| 3753 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 3697 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, |
| 3754 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 3698 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 3755 ASSERT_TRUE(https_test_server.Start()); | 3699 ASSERT_TRUE(https_test_server.Start()); |
| 3756 | 3700 |
| 3757 // An https server is sent a request with an https referer, | 3701 // An https server is sent a request with an https referer, |
| 3758 // and responds with a redirect to an http url. The http | 3702 // and responds with a redirect to an http url. The http |
| 3759 // server should not be sent the referer. | 3703 // server should not be sent the referer. |
| 3760 GURL http_destination = test_server_.GetURL(std::string()); | 3704 GURL http_destination = test_server_.GetURL(std::string()); |
| 3761 TestDelegate d; | 3705 TestDelegate d; |
| 3762 URLRequest req( | 3706 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3763 https_test_server.GetURL("server-redirect?" + http_destination.spec()), | 3707 https_test_server.GetURL("server-redirect?" + http_destination.spec()), |
| 3764 DEFAULT_PRIORITY, | 3708 DEFAULT_PRIORITY, &d, NULL)); |
| 3765 &d, | 3709 req->SetReferrer("https://www.referrer.com/"); |
| 3766 &default_context_); | 3710 req->Start(); |
| 3767 req.SetReferrer("https://www.referrer.com/"); | |
| 3768 req.Start(); | |
| 3769 base::RunLoop().Run(); | 3711 base::RunLoop().Run(); |
| 3770 | 3712 |
| 3771 EXPECT_EQ(1, d.response_started_count()); | 3713 EXPECT_EQ(1, d.response_started_count()); |
| 3772 EXPECT_EQ(1, d.received_redirect_count()); | 3714 EXPECT_EQ(1, d.received_redirect_count()); |
| 3773 EXPECT_EQ(http_destination, req.url()); | 3715 EXPECT_EQ(http_destination, req->url()); |
| 3774 EXPECT_EQ(std::string(), req.referrer()); | 3716 EXPECT_EQ(std::string(), req->referrer()); |
| 3775 } | 3717 } |
| 3776 | 3718 |
| 3777 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 3719 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
| 3778 ASSERT_TRUE(test_server_.Start()); | 3720 ASSERT_TRUE(test_server_.Start()); |
| 3779 | 3721 |
| 3780 GURL destination_url = test_server_.GetURL(std::string()); | 3722 GURL destination_url = test_server_.GetURL(std::string()); |
| 3781 GURL original_url = | 3723 GURL original_url = |
| 3782 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3724 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3783 TestDelegate d; | 3725 TestDelegate d; |
| 3784 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 3726 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3785 req.Start(); | 3727 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 3728 req->Start(); |
| 3786 base::RunLoop().Run(); | 3729 base::RunLoop().Run(); |
| 3787 | 3730 |
| 3788 EXPECT_EQ(1, d.response_started_count()); | 3731 EXPECT_EQ(1, d.response_started_count()); |
| 3789 EXPECT_EQ(1, d.received_redirect_count()); | 3732 EXPECT_EQ(1, d.received_redirect_count()); |
| 3790 EXPECT_EQ(destination_url, req.url()); | 3733 EXPECT_EQ(destination_url, req->url()); |
| 3791 EXPECT_EQ(original_url, req.original_url()); | 3734 EXPECT_EQ(original_url, req->original_url()); |
| 3792 ASSERT_EQ(2U, req.url_chain().size()); | 3735 ASSERT_EQ(2U, req->url_chain().size()); |
| 3793 EXPECT_EQ(original_url, req.url_chain()[0]); | 3736 EXPECT_EQ(original_url, req->url_chain()[0]); |
| 3794 EXPECT_EQ(destination_url, req.url_chain()[1]); | 3737 EXPECT_EQ(destination_url, req->url_chain()[1]); |
| 3795 | 3738 |
| 3796 LoadTimingInfo load_timing_info_before_redirect; | 3739 LoadTimingInfo load_timing_info_before_redirect; |
| 3797 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeRedirect( | 3740 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeRedirect( |
| 3798 &load_timing_info_before_redirect)); | 3741 &load_timing_info_before_redirect)); |
| 3799 TestLoadTimingNotReused(load_timing_info_before_redirect, | 3742 TestLoadTimingNotReused(load_timing_info_before_redirect, |
| 3800 CONNECT_TIMING_HAS_DNS_TIMES); | 3743 CONNECT_TIMING_HAS_DNS_TIMES); |
| 3801 | 3744 |
| 3802 LoadTimingInfo load_timing_info; | 3745 LoadTimingInfo load_timing_info; |
| 3803 req.GetLoadTimingInfo(&load_timing_info); | 3746 req->GetLoadTimingInfo(&load_timing_info); |
| 3804 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 3747 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 3805 | 3748 |
| 3806 // Check that a new socket was used on redirect, since the server does not | 3749 // Check that a new socket was used on redirect, since the server does not |
| 3807 // supposed keep-alive sockets, and that the times before the redirect are | 3750 // supposed keep-alive sockets, and that the times before the redirect are |
| 3808 // before the ones recorded for the second request. | 3751 // before the ones recorded for the second request. |
| 3809 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, | 3752 EXPECT_NE(load_timing_info_before_redirect.socket_log_id, |
| 3810 load_timing_info.socket_log_id); | 3753 load_timing_info.socket_log_id); |
| 3811 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, | 3754 EXPECT_LE(load_timing_info_before_redirect.receive_headers_end, |
| 3812 load_timing_info.connect_timing.connect_start); | 3755 load_timing_info.connect_timing.connect_start); |
| 3813 } | 3756 } |
| 3814 | 3757 |
| 3815 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 3758 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 3816 ASSERT_TRUE(test_server_.Start()); | 3759 ASSERT_TRUE(test_server_.Start()); |
| 3817 | 3760 |
| 3818 GURL destination_url = test_server_.GetURL(std::string()); | 3761 GURL destination_url = test_server_.GetURL(std::string()); |
| 3819 GURL middle_redirect_url = | 3762 GURL middle_redirect_url = |
| 3820 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3763 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3821 GURL original_url = test_server_.GetURL( | 3764 GURL original_url = test_server_.GetURL( |
| 3822 "server-redirect?" + middle_redirect_url.spec()); | 3765 "server-redirect?" + middle_redirect_url.spec()); |
| 3823 TestDelegate d; | 3766 TestDelegate d; |
| 3824 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 3767 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3825 req.Start(); | 3768 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 3769 req->Start(); |
| 3826 base::RunLoop().Run(); | 3770 base::RunLoop().Run(); |
| 3827 | 3771 |
| 3828 EXPECT_EQ(1, d.response_started_count()); | 3772 EXPECT_EQ(1, d.response_started_count()); |
| 3829 EXPECT_EQ(2, d.received_redirect_count()); | 3773 EXPECT_EQ(2, d.received_redirect_count()); |
| 3830 EXPECT_EQ(destination_url, req.url()); | 3774 EXPECT_EQ(destination_url, req->url()); |
| 3831 EXPECT_EQ(original_url, req.original_url()); | 3775 EXPECT_EQ(original_url, req->original_url()); |
| 3832 ASSERT_EQ(3U, req.url_chain().size()); | 3776 ASSERT_EQ(3U, req->url_chain().size()); |
| 3833 EXPECT_EQ(original_url, req.url_chain()[0]); | 3777 EXPECT_EQ(original_url, req->url_chain()[0]); |
| 3834 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 3778 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]); |
| 3835 EXPECT_EQ(destination_url, req.url_chain()[2]); | 3779 EXPECT_EQ(destination_url, req->url_chain()[2]); |
| 3836 } | 3780 } |
| 3837 | 3781 |
| 3838 // First and second pieces of information logged by delegates to URLRequests. | 3782 // First and second pieces of information logged by delegates to URLRequests. |
| 3839 const char kFirstDelegateInfo[] = "Wonderful delegate"; | 3783 const char kFirstDelegateInfo[] = "Wonderful delegate"; |
| 3840 const char kSecondDelegateInfo[] = "Exciting delegate"; | 3784 const char kSecondDelegateInfo[] = "Exciting delegate"; |
| 3841 | 3785 |
| 3842 // Logs delegate information to a URLRequest. The first string is logged | 3786 // Logs delegate information to a URLRequest. The first string is logged |
| 3843 // synchronously on Start(), using DELEGATE_INFO_DEBUG_ONLY. The second is | 3787 // synchronously on Start(), using DELEGATE_INFO_DEBUG_ONLY. The second is |
| 3844 // logged asynchronously, using DELEGATE_INFO_DISPLAY_TO_USER. Then | 3788 // logged asynchronously, using DELEGATE_INFO_DISPLAY_TO_USER. Then |
| 3845 // another asynchronous call is used to clear the delegate information | 3789 // another asynchronous call is used to clear the delegate information |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4145 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { | 4089 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { |
| 4146 ASSERT_TRUE(test_server_.Start()); | 4090 ASSERT_TRUE(test_server_.Start()); |
| 4147 | 4091 |
| 4148 TestDelegate request_delegate; | 4092 TestDelegate request_delegate; |
| 4149 TestURLRequestContext context(true); | 4093 TestURLRequestContext context(true); |
| 4150 context.set_network_delegate(NULL); | 4094 context.set_network_delegate(NULL); |
| 4151 context.set_net_log(&net_log_); | 4095 context.set_net_log(&net_log_); |
| 4152 context.Init(); | 4096 context.Init(); |
| 4153 | 4097 |
| 4154 { | 4098 { |
| 4155 URLRequest r(test_server_.GetURL("empty.html"), | 4099 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4156 DEFAULT_PRIORITY, | 4100 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &request_delegate, |
| 4157 &request_delegate, | 4101 NULL)); |
| 4158 &context); | 4102 LoadStateWithParam load_state = r->GetLoadState(); |
| 4159 LoadStateWithParam load_state = r.GetLoadState(); | |
| 4160 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4103 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4161 EXPECT_EQ(base::string16(), load_state.param); | 4104 EXPECT_EQ(base::string16(), load_state.param); |
| 4162 | 4105 |
| 4163 AsyncDelegateLogger::Run( | 4106 AsyncDelegateLogger::Run( |
| 4164 &r, | 4107 r.get(), |
| 4165 LOAD_STATE_WAITING_FOR_DELEGATE, | 4108 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4166 LOAD_STATE_WAITING_FOR_DELEGATE, | 4109 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 4167 LOAD_STATE_IDLE, | 4110 LOAD_STATE_IDLE, |
| 4168 base::Bind(&URLRequest::Start, base::Unretained(&r))); | 4111 base::Bind(&URLRequest::Start, base::Unretained(r.get()))); |
| 4169 | 4112 |
| 4170 base::RunLoop().Run(); | 4113 base::RunLoop().Run(); |
| 4171 | 4114 |
| 4172 EXPECT_EQ(200, r.GetResponseCode()); | 4115 EXPECT_EQ(200, r->GetResponseCode()); |
| 4173 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4116 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4174 } | 4117 } |
| 4175 | 4118 |
| 4176 CapturingNetLog::CapturedEntryList entries; | 4119 CapturingNetLog::CapturedEntryList entries; |
| 4177 net_log_.GetEntries(&entries); | 4120 net_log_.GetEntries(&entries); |
| 4178 size_t log_position = ExpectLogContainsSomewhereAfter( | 4121 size_t log_position = ExpectLogContainsSomewhereAfter( |
| 4179 entries, | 4122 entries, |
| 4180 0, | 4123 0, |
| 4181 NetLog::TYPE_DELEGATE_INFO, | 4124 NetLog::TYPE_DELEGATE_INFO, |
| 4182 NetLog::PHASE_BEGIN); | 4125 NetLog::PHASE_BEGIN); |
| 4183 | 4126 |
| 4184 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); | 4127 log_position = AsyncDelegateLogger::CheckDelegateInfo(entries, log_position); |
| 4185 | 4128 |
| 4186 // Nothing else should add any delegate info to the request. | 4129 // Nothing else should add any delegate info to the request. |
| 4187 EXPECT_FALSE(LogContainsEntryWithTypeAfter( | 4130 EXPECT_FALSE(LogContainsEntryWithTypeAfter( |
| 4188 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); | 4131 entries, log_position + 1, NetLog::TYPE_DELEGATE_INFO)); |
| 4189 } | 4132 } |
| 4190 | 4133 |
| 4191 // Tests handling of delegate info from a network delegate. | 4134 // Tests handling of delegate info from a network delegate. |
| 4192 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { | 4135 TEST_F(URLRequestTestHTTP, NetworkDelegateInfo) { |
| 4193 ASSERT_TRUE(test_server_.Start()); | 4136 ASSERT_TRUE(test_server_.Start()); |
| 4194 | 4137 |
| 4195 TestDelegate request_delegate; | 4138 TestDelegate request_delegate; |
| 4196 AsyncLoggingNetworkDelegate network_delegate; | 4139 AsyncLoggingNetworkDelegate network_delegate; |
| 4197 TestURLRequestContext context(true); | 4140 TestURLRequestContext context(true); |
| 4198 context.set_network_delegate(&network_delegate); | 4141 context.set_network_delegate(&network_delegate); |
| 4199 context.set_net_log(&net_log_); | 4142 context.set_net_log(&net_log_); |
| 4200 context.Init(); | 4143 context.Init(); |
| 4201 | 4144 |
| 4202 { | 4145 { |
| 4203 URLRequest r(test_server_.GetURL("simple.html"), | 4146 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4204 DEFAULT_PRIORITY, | 4147 test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &request_delegate, |
| 4205 &request_delegate, | 4148 NULL)); |
| 4206 &context); | 4149 LoadStateWithParam load_state = r->GetLoadState(); |
| 4207 LoadStateWithParam load_state = r.GetLoadState(); | |
| 4208 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4150 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4209 EXPECT_EQ(base::string16(), load_state.param); | 4151 EXPECT_EQ(base::string16(), load_state.param); |
| 4210 | 4152 |
| 4211 r.Start(); | 4153 r->Start(); |
| 4212 base::RunLoop().Run(); | 4154 base::RunLoop().Run(); |
| 4213 | 4155 |
| 4214 EXPECT_EQ(200, r.GetResponseCode()); | 4156 EXPECT_EQ(200, r->GetResponseCode()); |
| 4215 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4157 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4216 EXPECT_EQ(1, network_delegate.created_requests()); | 4158 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4217 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4159 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4218 } | 4160 } |
| 4219 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4161 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4220 | 4162 |
| 4221 size_t log_position = 0; | 4163 size_t log_position = 0; |
| 4222 CapturingNetLog::CapturedEntryList entries; | 4164 CapturingNetLog::CapturedEntryList entries; |
| 4223 net_log_.GetEntries(&entries); | 4165 net_log_.GetEntries(&entries); |
| 4224 for (size_t i = 0; i < 3; ++i) { | 4166 for (size_t i = 0; i < 3; ++i) { |
| 4225 log_position = ExpectLogContainsSomewhereAfter( | 4167 log_position = ExpectLogContainsSomewhereAfter( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4251 ASSERT_TRUE(test_server_.Start()); | 4193 ASSERT_TRUE(test_server_.Start()); |
| 4252 | 4194 |
| 4253 TestDelegate request_delegate; | 4195 TestDelegate request_delegate; |
| 4254 AsyncLoggingNetworkDelegate network_delegate; | 4196 AsyncLoggingNetworkDelegate network_delegate; |
| 4255 TestURLRequestContext context(true); | 4197 TestURLRequestContext context(true); |
| 4256 context.set_network_delegate(&network_delegate); | 4198 context.set_network_delegate(&network_delegate); |
| 4257 context.set_net_log(&net_log_); | 4199 context.set_net_log(&net_log_); |
| 4258 context.Init(); | 4200 context.Init(); |
| 4259 | 4201 |
| 4260 { | 4202 { |
| 4261 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4203 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4262 DEFAULT_PRIORITY, | 4204 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, |
| 4263 &request_delegate, | 4205 &request_delegate, NULL)); |
| 4264 &context); | 4206 LoadStateWithParam load_state = r->GetLoadState(); |
| 4265 LoadStateWithParam load_state = r.GetLoadState(); | |
| 4266 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4207 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4267 EXPECT_EQ(base::string16(), load_state.param); | 4208 EXPECT_EQ(base::string16(), load_state.param); |
| 4268 | 4209 |
| 4269 r.Start(); | 4210 r->Start(); |
| 4270 base::RunLoop().Run(); | 4211 base::RunLoop().Run(); |
| 4271 | 4212 |
| 4272 EXPECT_EQ(200, r.GetResponseCode()); | 4213 EXPECT_EQ(200, r->GetResponseCode()); |
| 4273 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4214 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4274 EXPECT_EQ(2, network_delegate.created_requests()); | 4215 EXPECT_EQ(2, network_delegate.created_requests()); |
| 4275 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4216 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4276 } | 4217 } |
| 4277 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4218 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4278 | 4219 |
| 4279 size_t log_position = 0; | 4220 size_t log_position = 0; |
| 4280 CapturingNetLog::CapturedEntryList entries; | 4221 CapturingNetLog::CapturedEntryList entries; |
| 4281 net_log_.GetEntries(&entries); | 4222 net_log_.GetEntries(&entries); |
| 4282 // The NetworkDelegate logged information in OnBeforeURLRequest, | 4223 // The NetworkDelegate logged information in OnBeforeURLRequest, |
| 4283 // OnBeforeSendHeaders, and OnHeadersReceived. | 4224 // OnBeforeSendHeaders, and OnHeadersReceived. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4334 ASSERT_TRUE(test_server_.Start()); | 4275 ASSERT_TRUE(test_server_.Start()); |
| 4335 | 4276 |
| 4336 TestDelegate request_delegate; | 4277 TestDelegate request_delegate; |
| 4337 AsyncLoggingNetworkDelegate network_delegate; | 4278 AsyncLoggingNetworkDelegate network_delegate; |
| 4338 TestURLRequestContext context(true); | 4279 TestURLRequestContext context(true); |
| 4339 context.set_network_delegate(&network_delegate); | 4280 context.set_network_delegate(&network_delegate); |
| 4340 context.set_net_log(&net_log_); | 4281 context.set_net_log(&net_log_); |
| 4341 context.Init(); | 4282 context.Init(); |
| 4342 | 4283 |
| 4343 { | 4284 { |
| 4344 URLRequest r(test_server_.GetURL("auth-basic"), | 4285 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4345 DEFAULT_PRIORITY, | 4286 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &request_delegate, |
| 4346 &request_delegate, | 4287 NULL)); |
| 4347 &context); | 4288 LoadStateWithParam load_state = r->GetLoadState(); |
| 4348 LoadStateWithParam load_state = r.GetLoadState(); | |
| 4349 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 4289 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 4350 EXPECT_EQ(base::string16(), load_state.param); | 4290 EXPECT_EQ(base::string16(), load_state.param); |
| 4351 | 4291 |
| 4352 r.Start(); | 4292 r->Start(); |
| 4353 base::RunLoop().Run(); | 4293 base::RunLoop().Run(); |
| 4354 | 4294 |
| 4355 EXPECT_EQ(200, r.GetResponseCode()); | 4295 EXPECT_EQ(200, r->GetResponseCode()); |
| 4356 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4296 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4357 EXPECT_EQ(1, network_delegate.created_requests()); | 4297 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4358 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4298 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4359 } | 4299 } |
| 4360 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4300 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4361 | 4301 |
| 4362 size_t log_position = 0; | 4302 size_t log_position = 0; |
| 4363 CapturingNetLog::CapturedEntryList entries; | 4303 CapturingNetLog::CapturedEntryList entries; |
| 4364 net_log_.GetEntries(&entries); | 4304 net_log_.GetEntries(&entries); |
| 4365 // The NetworkDelegate should have logged information in OnBeforeURLRequest, | 4305 // The NetworkDelegate should have logged information in OnBeforeURLRequest, |
| 4366 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in | 4306 // OnBeforeSendHeaders, OnHeadersReceived, OnAuthRequired, and then again in |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4399 context.set_network_delegate(NULL); | 4339 context.set_network_delegate(NULL); |
| 4400 context.set_net_log(&net_log_); | 4340 context.set_net_log(&net_log_); |
| 4401 context.Init(); | 4341 context.Init(); |
| 4402 | 4342 |
| 4403 { | 4343 { |
| 4404 // A chunked response with delays between chunks is used to make sure that | 4344 // A chunked response with delays between chunks is used to make sure that |
| 4405 // attempts by the URLRequest delegate to log information while reading the | 4345 // attempts by the URLRequest delegate to log information while reading the |
| 4406 // body are ignored. Since they are ignored, this test is robust against | 4346 // body are ignored. Since they are ignored, this test is robust against |
| 4407 // the possibility of multiple reads being combined in the unlikely event | 4347 // the possibility of multiple reads being combined in the unlikely event |
| 4408 // that it occurs. | 4348 // that it occurs. |
| 4409 URLRequest r(test_server_.GetURL("chunked?waitBetweenChunks=20"), | 4349 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4410 DEFAULT_PRIORITY, | 4350 test_server_.GetURL("chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, |
| 4411 &request_delegate, | 4351 &request_delegate, NULL)); |
| 4412 &context); | 4352 LoadStateWithParam load_state = r->GetLoadState(); |
| 4413 LoadStateWithParam load_state = r.GetLoadState(); | 4353 r->Start(); |
| 4414 r.Start(); | |
| 4415 base::RunLoop().Run(); | 4354 base::RunLoop().Run(); |
| 4416 | 4355 |
| 4417 EXPECT_EQ(200, r.GetResponseCode()); | 4356 EXPECT_EQ(200, r->GetResponseCode()); |
| 4418 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4357 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4419 } | 4358 } |
| 4420 | 4359 |
| 4421 CapturingNetLog::CapturedEntryList entries; | 4360 CapturingNetLog::CapturedEntryList entries; |
| 4422 net_log_.GetEntries(&entries); | 4361 net_log_.GetEntries(&entries); |
| 4423 | 4362 |
| 4424 size_t log_position = 0; | 4363 size_t log_position = 0; |
| 4425 | 4364 |
| 4426 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( | 4365 log_position = AsyncDelegateLogger::ExpectBeforeNetworkEvents( |
| 4427 entries, log_position); | 4366 entries, log_position); |
| 4428 | 4367 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4453 ASSERT_TRUE(test_server_.Start()); | 4392 ASSERT_TRUE(test_server_.Start()); |
| 4454 | 4393 |
| 4455 AsyncLoggingUrlRequestDelegate request_delegate( | 4394 AsyncLoggingUrlRequestDelegate request_delegate( |
| 4456 AsyncLoggingUrlRequestDelegate::NO_CANCEL); | 4395 AsyncLoggingUrlRequestDelegate::NO_CANCEL); |
| 4457 TestURLRequestContext context(true); | 4396 TestURLRequestContext context(true); |
| 4458 context.set_network_delegate(NULL); | 4397 context.set_network_delegate(NULL); |
| 4459 context.set_net_log(&net_log_); | 4398 context.set_net_log(&net_log_); |
| 4460 context.Init(); | 4399 context.Init(); |
| 4461 | 4400 |
| 4462 { | 4401 { |
| 4463 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4402 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4464 DEFAULT_PRIORITY, | 4403 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, |
| 4465 &request_delegate, | 4404 &request_delegate, NULL)); |
| 4466 &context); | 4405 LoadStateWithParam load_state = r->GetLoadState(); |
| 4467 LoadStateWithParam load_state = r.GetLoadState(); | 4406 r->Start(); |
| 4468 r.Start(); | |
| 4469 base::RunLoop().Run(); | 4407 base::RunLoop().Run(); |
| 4470 | 4408 |
| 4471 EXPECT_EQ(200, r.GetResponseCode()); | 4409 EXPECT_EQ(200, r->GetResponseCode()); |
| 4472 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4410 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4473 } | 4411 } |
| 4474 | 4412 |
| 4475 CapturingNetLog::CapturedEntryList entries; | 4413 CapturingNetLog::CapturedEntryList entries; |
| 4476 net_log_.GetEntries(&entries); | 4414 net_log_.GetEntries(&entries); |
| 4477 | 4415 |
| 4478 // Delegate info should only have been logged in OnReceivedRedirect and | 4416 // Delegate info should only have been logged in OnReceivedRedirect and |
| 4479 // OnResponseStarted. | 4417 // OnResponseStarted. |
| 4480 size_t log_position = 0; | 4418 size_t log_position = 0; |
| 4481 for (int i = 0; i < 2; ++i) { | 4419 for (int i = 0; i < 2; ++i) { |
| 4482 if (i == 0) { | 4420 if (i == 0) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4518 for (size_t test_case = 0; test_case < arraysize(kCancelStages); | 4456 for (size_t test_case = 0; test_case < arraysize(kCancelStages); |
| 4519 ++test_case) { | 4457 ++test_case) { |
| 4520 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); | 4458 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); |
| 4521 TestURLRequestContext context(true); | 4459 TestURLRequestContext context(true); |
| 4522 CapturingNetLog net_log; | 4460 CapturingNetLog net_log; |
| 4523 context.set_network_delegate(NULL); | 4461 context.set_network_delegate(NULL); |
| 4524 context.set_net_log(&net_log); | 4462 context.set_net_log(&net_log); |
| 4525 context.Init(); | 4463 context.Init(); |
| 4526 | 4464 |
| 4527 { | 4465 { |
| 4528 URLRequest r(test_server_.GetURL("server-redirect?simple.html"), | 4466 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 4529 DEFAULT_PRIORITY, | 4467 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, |
| 4530 &request_delegate, | 4468 &request_delegate, NULL)); |
| 4531 &context); | 4469 LoadStateWithParam load_state = r->GetLoadState(); |
| 4532 LoadStateWithParam load_state = r.GetLoadState(); | 4470 r->Start(); |
| 4533 r.Start(); | |
| 4534 base::RunLoop().Run(); | 4471 base::RunLoop().Run(); |
| 4535 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4472 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4536 } | 4473 } |
| 4537 | 4474 |
| 4538 CapturingNetLog::CapturedEntryList entries; | 4475 CapturingNetLog::CapturedEntryList entries; |
| 4539 net_log.GetEntries(&entries); | 4476 net_log.GetEntries(&entries); |
| 4540 | 4477 |
| 4541 // Delegate info is always logged in both OnReceivedRedirect and | 4478 // Delegate info is always logged in both OnReceivedRedirect and |
| 4542 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the | 4479 // OnResponseStarted. In the CANCEL_ON_RECEIVED_REDIRECT, the |
| 4543 // OnResponseStarted delegate call is after cancellation, but logging is | 4480 // OnResponseStarted delegate call is after cancellation, but logging is |
| 4544 // still currently supported in that call. | 4481 // still currently supported in that call. |
| 4545 size_t log_position = 0; | 4482 size_t log_position = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4587 } // namespace | 4524 } // namespace |
| 4588 | 4525 |
| 4589 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 4526 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
| 4590 ASSERT_TRUE(test_server_.Start()); | 4527 ASSERT_TRUE(test_server_.Start()); |
| 4591 | 4528 |
| 4592 GURL destination_url = test_server_.GetURL( | 4529 GURL destination_url = test_server_.GetURL( |
| 4593 "echoheader?" + std::string(kExtraHeader)); | 4530 "echoheader?" + std::string(kExtraHeader)); |
| 4594 GURL original_url = test_server_.GetURL( | 4531 GURL original_url = test_server_.GetURL( |
| 4595 "server-redirect?" + destination_url.spec()); | 4532 "server-redirect?" + destination_url.spec()); |
| 4596 RedirectWithAdditionalHeadersDelegate d; | 4533 RedirectWithAdditionalHeadersDelegate d; |
| 4597 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 4534 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 4598 req.Start(); | 4535 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 4536 req->Start(); |
| 4599 base::RunLoop().Run(); | 4537 base::RunLoop().Run(); |
| 4600 | 4538 |
| 4601 std::string value; | 4539 std::string value; |
| 4602 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4540 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 4603 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 4541 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
| 4604 EXPECT_EQ(kExtraValue, value); | 4542 EXPECT_EQ(kExtraValue, value); |
| 4605 EXPECT_FALSE(req.is_pending()); | 4543 EXPECT_FALSE(req->is_pending()); |
| 4606 EXPECT_FALSE(req.is_redirecting()); | 4544 EXPECT_FALSE(req->is_redirecting()); |
| 4607 EXPECT_EQ(kExtraValue, d.data_received()); | 4545 EXPECT_EQ(kExtraValue, d.data_received()); |
| 4608 } | 4546 } |
| 4609 | 4547 |
| 4610 namespace { | 4548 namespace { |
| 4611 | 4549 |
| 4612 const char kExtraHeaderToRemove[] = "To-Be-Removed"; | 4550 const char kExtraHeaderToRemove[] = "To-Be-Removed"; |
| 4613 | 4551 |
| 4614 class RedirectWithHeaderRemovalDelegate : public TestDelegate { | 4552 class RedirectWithHeaderRemovalDelegate : public TestDelegate { |
| 4615 virtual void OnReceivedRedirect(net::URLRequest* request, | 4553 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 4616 const GURL& new_url, | 4554 const GURL& new_url, |
| 4617 bool* defer_redirect) OVERRIDE { | 4555 bool* defer_redirect) OVERRIDE { |
| 4618 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); | 4556 TestDelegate::OnReceivedRedirect(request, new_url, defer_redirect); |
| 4619 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); | 4557 request->RemoveRequestHeaderByName(kExtraHeaderToRemove); |
| 4620 } | 4558 } |
| 4621 }; | 4559 }; |
| 4622 | 4560 |
| 4623 } // namespace | 4561 } // namespace |
| 4624 | 4562 |
| 4625 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { | 4563 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { |
| 4626 ASSERT_TRUE(test_server_.Start()); | 4564 ASSERT_TRUE(test_server_.Start()); |
| 4627 | 4565 |
| 4628 GURL destination_url = test_server_.GetURL( | 4566 GURL destination_url = test_server_.GetURL( |
| 4629 "echoheader?" + std::string(kExtraHeaderToRemove)); | 4567 "echoheader?" + std::string(kExtraHeaderToRemove)); |
| 4630 GURL original_url = test_server_.GetURL( | 4568 GURL original_url = test_server_.GetURL( |
| 4631 "server-redirect?" + destination_url.spec()); | 4569 "server-redirect?" + destination_url.spec()); |
| 4632 RedirectWithHeaderRemovalDelegate d; | 4570 RedirectWithHeaderRemovalDelegate d; |
| 4633 URLRequest req(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 4571 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 4634 req.SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 4572 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 4635 req.Start(); | 4573 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
| 4574 req->Start(); |
| 4636 base::RunLoop().Run(); | 4575 base::RunLoop().Run(); |
| 4637 | 4576 |
| 4638 std::string value; | 4577 std::string value; |
| 4639 const HttpRequestHeaders& headers = req.extra_request_headers(); | 4578 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 4640 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 4579 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| 4641 EXPECT_FALSE(req.is_pending()); | 4580 EXPECT_FALSE(req->is_pending()); |
| 4642 EXPECT_FALSE(req.is_redirecting()); | 4581 EXPECT_FALSE(req->is_redirecting()); |
| 4643 EXPECT_EQ("None", d.data_received()); | 4582 EXPECT_EQ("None", d.data_received()); |
| 4644 } | 4583 } |
| 4645 | 4584 |
| 4646 TEST_F(URLRequestTestHTTP, CancelTest) { | 4585 TEST_F(URLRequestTestHTTP, CancelTest) { |
| 4647 TestDelegate d; | 4586 TestDelegate d; |
| 4648 { | 4587 { |
| 4649 URLRequest r(GURL("http://www.google.com/"), | 4588 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4650 DEFAULT_PRIORITY, | 4589 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d, NULL)); |
| 4651 &d, | |
| 4652 &default_context_); | |
| 4653 | 4590 |
| 4654 r.Start(); | 4591 r->Start(); |
| 4655 EXPECT_TRUE(r.is_pending()); | 4592 EXPECT_TRUE(r->is_pending()); |
| 4656 | 4593 |
| 4657 r.Cancel(); | 4594 r->Cancel(); |
| 4658 | 4595 |
| 4659 base::RunLoop().Run(); | 4596 base::RunLoop().Run(); |
| 4660 | 4597 |
| 4661 // We expect to receive OnResponseStarted even though the request has been | 4598 // We expect to receive OnResponseStarted even though the request has been |
| 4662 // cancelled. | 4599 // cancelled. |
| 4663 EXPECT_EQ(1, d.response_started_count()); | 4600 EXPECT_EQ(1, d.response_started_count()); |
| 4664 EXPECT_EQ(0, d.bytes_received()); | 4601 EXPECT_EQ(0, d.bytes_received()); |
| 4665 EXPECT_FALSE(d.received_data_before_response()); | 4602 EXPECT_FALSE(d.received_data_before_response()); |
| 4666 } | 4603 } |
| 4667 } | 4604 } |
| 4668 | 4605 |
| 4669 TEST_F(URLRequestTestHTTP, CancelTest2) { | 4606 TEST_F(URLRequestTestHTTP, CancelTest2) { |
| 4670 ASSERT_TRUE(test_server_.Start()); | 4607 ASSERT_TRUE(test_server_.Start()); |
| 4671 | 4608 |
| 4672 TestDelegate d; | 4609 TestDelegate d; |
| 4673 { | 4610 { |
| 4674 URLRequest r(test_server_.GetURL(std::string()), | 4611 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4675 DEFAULT_PRIORITY, | 4612 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 4676 &d, | |
| 4677 &default_context_); | |
| 4678 | 4613 |
| 4679 d.set_cancel_in_response_started(true); | 4614 d.set_cancel_in_response_started(true); |
| 4680 | 4615 |
| 4681 r.Start(); | 4616 r->Start(); |
| 4682 EXPECT_TRUE(r.is_pending()); | 4617 EXPECT_TRUE(r->is_pending()); |
| 4683 | 4618 |
| 4684 base::RunLoop().Run(); | 4619 base::RunLoop().Run(); |
| 4685 | 4620 |
| 4686 EXPECT_EQ(1, d.response_started_count()); | 4621 EXPECT_EQ(1, d.response_started_count()); |
| 4687 EXPECT_EQ(0, d.bytes_received()); | 4622 EXPECT_EQ(0, d.bytes_received()); |
| 4688 EXPECT_FALSE(d.received_data_before_response()); | 4623 EXPECT_FALSE(d.received_data_before_response()); |
| 4689 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4624 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4690 } | 4625 } |
| 4691 } | 4626 } |
| 4692 | 4627 |
| 4693 TEST_F(URLRequestTestHTTP, CancelTest3) { | 4628 TEST_F(URLRequestTestHTTP, CancelTest3) { |
| 4694 ASSERT_TRUE(test_server_.Start()); | 4629 ASSERT_TRUE(test_server_.Start()); |
| 4695 | 4630 |
| 4696 TestDelegate d; | 4631 TestDelegate d; |
| 4697 { | 4632 { |
| 4698 URLRequest r(test_server_.GetURL(std::string()), | 4633 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4699 DEFAULT_PRIORITY, | 4634 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 4700 &d, | |
| 4701 &default_context_); | |
| 4702 | 4635 |
| 4703 d.set_cancel_in_received_data(true); | 4636 d.set_cancel_in_received_data(true); |
| 4704 | 4637 |
| 4705 r.Start(); | 4638 r->Start(); |
| 4706 EXPECT_TRUE(r.is_pending()); | 4639 EXPECT_TRUE(r->is_pending()); |
| 4707 | 4640 |
| 4708 base::RunLoop().Run(); | 4641 base::RunLoop().Run(); |
| 4709 | 4642 |
| 4710 EXPECT_EQ(1, d.response_started_count()); | 4643 EXPECT_EQ(1, d.response_started_count()); |
| 4711 // There is no guarantee about how much data was received | 4644 // There is no guarantee about how much data was received |
| 4712 // before the cancel was issued. It could have been 0 bytes, | 4645 // before the cancel was issued. It could have been 0 bytes, |
| 4713 // or it could have been all the bytes. | 4646 // or it could have been all the bytes. |
| 4714 // EXPECT_EQ(0, d.bytes_received()); | 4647 // EXPECT_EQ(0, d.bytes_received()); |
| 4715 EXPECT_FALSE(d.received_data_before_response()); | 4648 EXPECT_FALSE(d.received_data_before_response()); |
| 4716 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4649 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4717 } | 4650 } |
| 4718 } | 4651 } |
| 4719 | 4652 |
| 4720 TEST_F(URLRequestTestHTTP, CancelTest4) { | 4653 TEST_F(URLRequestTestHTTP, CancelTest4) { |
| 4721 ASSERT_TRUE(test_server_.Start()); | 4654 ASSERT_TRUE(test_server_.Start()); |
| 4722 | 4655 |
| 4723 TestDelegate d; | 4656 TestDelegate d; |
| 4724 { | 4657 { |
| 4725 URLRequest r(test_server_.GetURL(std::string()), | 4658 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4726 DEFAULT_PRIORITY, | 4659 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 4727 &d, | |
| 4728 &default_context_); | |
| 4729 | 4660 |
| 4730 r.Start(); | 4661 r->Start(); |
| 4731 EXPECT_TRUE(r.is_pending()); | 4662 EXPECT_TRUE(r->is_pending()); |
| 4732 | 4663 |
| 4733 // The request will be implicitly canceled when it is destroyed. The | 4664 // The request will be implicitly canceled when it is destroyed. The |
| 4734 // test delegate must not post a quit message when this happens because | 4665 // test delegate must not post a quit message when this happens because |
| 4735 // this test doesn't actually have a message loop. The quit message would | 4666 // this test doesn't actually have a message loop. The quit message would |
| 4736 // get put on this thread's message queue and the next test would exit | 4667 // get put on this thread's message queue and the next test would exit |
| 4737 // early, causing problems. | 4668 // early, causing problems. |
| 4738 d.set_quit_on_complete(false); | 4669 d.set_quit_on_complete(false); |
| 4739 } | 4670 } |
| 4740 // expect things to just cleanup properly. | 4671 // expect things to just cleanup properly. |
| 4741 | 4672 |
| 4742 // we won't actually get a received reponse here because we've never run the | 4673 // we won't actually get a received reponse here because we've never run the |
| 4743 // message loop | 4674 // message loop |
| 4744 EXPECT_FALSE(d.received_data_before_response()); | 4675 EXPECT_FALSE(d.received_data_before_response()); |
| 4745 EXPECT_EQ(0, d.bytes_received()); | 4676 EXPECT_EQ(0, d.bytes_received()); |
| 4746 } | 4677 } |
| 4747 | 4678 |
| 4748 TEST_F(URLRequestTestHTTP, CancelTest5) { | 4679 TEST_F(URLRequestTestHTTP, CancelTest5) { |
| 4749 ASSERT_TRUE(test_server_.Start()); | 4680 ASSERT_TRUE(test_server_.Start()); |
| 4750 | 4681 |
| 4751 // populate cache | 4682 // populate cache |
| 4752 { | 4683 { |
| 4753 TestDelegate d; | 4684 TestDelegate d; |
| 4754 URLRequest r(test_server_.GetURL("cachetime"), | 4685 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4755 DEFAULT_PRIORITY, | 4686 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL)); |
| 4756 &d, | 4687 r->Start(); |
| 4757 &default_context_); | |
| 4758 r.Start(); | |
| 4759 base::RunLoop().Run(); | 4688 base::RunLoop().Run(); |
| 4760 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 4689 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 4761 } | 4690 } |
| 4762 | 4691 |
| 4763 // cancel read from cache (see bug 990242) | 4692 // cancel read from cache (see bug 990242) |
| 4764 { | 4693 { |
| 4765 TestDelegate d; | 4694 TestDelegate d; |
| 4766 URLRequest r(test_server_.GetURL("cachetime"), | 4695 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4767 DEFAULT_PRIORITY, | 4696 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL)); |
| 4768 &d, | 4697 r->Start(); |
| 4769 &default_context_); | 4698 r->Cancel(); |
| 4770 r.Start(); | |
| 4771 r.Cancel(); | |
| 4772 base::RunLoop().Run(); | 4699 base::RunLoop().Run(); |
| 4773 | 4700 |
| 4774 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 4701 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); |
| 4775 EXPECT_EQ(1, d.response_started_count()); | 4702 EXPECT_EQ(1, d.response_started_count()); |
| 4776 EXPECT_EQ(0, d.bytes_received()); | 4703 EXPECT_EQ(0, d.bytes_received()); |
| 4777 EXPECT_FALSE(d.received_data_before_response()); | 4704 EXPECT_FALSE(d.received_data_before_response()); |
| 4778 } | 4705 } |
| 4779 } | 4706 } |
| 4780 | 4707 |
| 4781 TEST_F(URLRequestTestHTTP, PostTest) { | 4708 TEST_F(URLRequestTestHTTP, PostTest) { |
| 4782 ASSERT_TRUE(test_server_.Start()); | 4709 ASSERT_TRUE(test_server_.Start()); |
| 4783 HTTPUploadDataOperationTest("POST"); | 4710 HTTPUploadDataOperationTest("POST"); |
| 4784 } | 4711 } |
| 4785 | 4712 |
| 4786 TEST_F(URLRequestTestHTTP, PutTest) { | 4713 TEST_F(URLRequestTestHTTP, PutTest) { |
| 4787 ASSERT_TRUE(test_server_.Start()); | 4714 ASSERT_TRUE(test_server_.Start()); |
| 4788 HTTPUploadDataOperationTest("PUT"); | 4715 HTTPUploadDataOperationTest("PUT"); |
| 4789 } | 4716 } |
| 4790 | 4717 |
| 4791 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 4718 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
| 4792 ASSERT_TRUE(test_server_.Start()); | 4719 ASSERT_TRUE(test_server_.Start()); |
| 4793 | 4720 |
| 4794 TestDelegate d; | 4721 TestDelegate d; |
| 4795 { | 4722 { |
| 4796 URLRequest r( | 4723 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4797 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4724 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4798 r.set_method("POST"); | 4725 r->set_method("POST"); |
| 4799 | 4726 |
| 4800 r.Start(); | 4727 r->Start(); |
| 4801 EXPECT_TRUE(r.is_pending()); | 4728 EXPECT_TRUE(r->is_pending()); |
| 4802 | 4729 |
| 4803 base::RunLoop().Run(); | 4730 base::RunLoop().Run(); |
| 4804 | 4731 |
| 4805 ASSERT_EQ(1, d.response_started_count()) | 4732 ASSERT_EQ(1, d.response_started_count()) |
| 4806 << "request failed: " << r.status().status() | 4733 << "request failed: " << r->status().status() |
| 4807 << ", error: " << r.status().error(); | 4734 << ", error: " << r->status().error(); |
| 4808 | 4735 |
| 4809 EXPECT_FALSE(d.received_data_before_response()); | 4736 EXPECT_FALSE(d.received_data_before_response()); |
| 4810 EXPECT_TRUE(d.data_received().empty()); | 4737 EXPECT_TRUE(d.data_received().empty()); |
| 4811 } | 4738 } |
| 4812 } | 4739 } |
| 4813 | 4740 |
| 4814 TEST_F(URLRequestTestHTTP, PostFileTest) { | 4741 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 4815 ASSERT_TRUE(test_server_.Start()); | 4742 ASSERT_TRUE(test_server_.Start()); |
| 4816 | 4743 |
| 4817 TestDelegate d; | 4744 TestDelegate d; |
| 4818 { | 4745 { |
| 4819 URLRequest r( | 4746 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4820 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4747 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4821 r.set_method("POST"); | 4748 r->set_method("POST"); |
| 4822 | 4749 |
| 4823 base::FilePath dir; | 4750 base::FilePath dir; |
| 4824 PathService::Get(base::DIR_EXE, &dir); | 4751 PathService::Get(base::DIR_EXE, &dir); |
| 4825 base::SetCurrentDirectory(dir); | 4752 base::SetCurrentDirectory(dir); |
| 4826 | 4753 |
| 4827 ScopedVector<UploadElementReader> element_readers; | 4754 ScopedVector<UploadElementReader> element_readers; |
| 4828 | 4755 |
| 4829 base::FilePath path; | 4756 base::FilePath path; |
| 4830 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 4757 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 4831 path = path.Append(FILE_PATH_LITERAL("net")); | 4758 path = path.Append(FILE_PATH_LITERAL("net")); |
| 4832 path = path.Append(FILE_PATH_LITERAL("data")); | 4759 path = path.Append(FILE_PATH_LITERAL("data")); |
| 4833 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 4760 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 4834 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 4761 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 4835 element_readers.push_back( | 4762 element_readers.push_back( |
| 4836 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 4763 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 4837 path, | 4764 path, |
| 4838 0, | 4765 0, |
| 4839 kuint64max, | 4766 kuint64max, |
| 4840 base::Time())); | 4767 base::Time())); |
| 4841 r.set_upload(make_scoped_ptr( | 4768 r->set_upload(make_scoped_ptr( |
| 4842 new UploadDataStream(element_readers.Pass(), 0))); | 4769 new UploadDataStream(element_readers.Pass(), 0))); |
| 4843 | 4770 |
| 4844 r.Start(); | 4771 r->Start(); |
| 4845 EXPECT_TRUE(r.is_pending()); | 4772 EXPECT_TRUE(r->is_pending()); |
| 4846 | 4773 |
| 4847 base::RunLoop().Run(); | 4774 base::RunLoop().Run(); |
| 4848 | 4775 |
| 4849 int64 size = 0; | 4776 int64 size = 0; |
| 4850 ASSERT_EQ(true, base::GetFileSize(path, &size)); | 4777 ASSERT_EQ(true, base::GetFileSize(path, &size)); |
| 4851 scoped_ptr<char[]> buf(new char[size]); | 4778 scoped_ptr<char[]> buf(new char[size]); |
| 4852 | 4779 |
| 4853 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); | 4780 ASSERT_EQ(size, base::ReadFile(path, buf.get(), size)); |
| 4854 | 4781 |
| 4855 ASSERT_EQ(1, d.response_started_count()) | 4782 ASSERT_EQ(1, d.response_started_count()) |
| 4856 << "request failed: " << r.status().status() | 4783 << "request failed: " << r->status().status() |
| 4857 << ", error: " << r.status().error(); | 4784 << ", error: " << r->status().error(); |
| 4858 | 4785 |
| 4859 EXPECT_FALSE(d.received_data_before_response()); | 4786 EXPECT_FALSE(d.received_data_before_response()); |
| 4860 | 4787 |
| 4861 EXPECT_EQ(size, d.bytes_received()); | 4788 EXPECT_EQ(size, d.bytes_received()); |
| 4862 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 4789 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
| 4863 } | 4790 } |
| 4864 } | 4791 } |
| 4865 | 4792 |
| 4866 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | 4793 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { |
| 4867 ASSERT_TRUE(test_server_.Start()); | 4794 ASSERT_TRUE(test_server_.Start()); |
| 4868 | 4795 |
| 4869 TestDelegate d; | 4796 TestDelegate d; |
| 4870 { | 4797 { |
| 4871 URLRequest r(test_server_.GetURL("echo"), DEFAULT_PRIORITY, | 4798 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4872 &d, &default_context_); | 4799 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4873 r.set_method("POST"); | 4800 r->set_method("POST"); |
| 4874 | 4801 |
| 4875 ScopedVector<UploadElementReader> element_readers; | 4802 ScopedVector<UploadElementReader> element_readers; |
| 4876 | 4803 |
| 4877 element_readers.push_back(new UploadFileElementReader( | 4804 element_readers.push_back(new UploadFileElementReader( |
| 4878 base::MessageLoopProxy::current().get(), | 4805 base::MessageLoopProxy::current().get(), |
| 4879 base::FilePath(FILE_PATH_LITERAL( | 4806 base::FilePath(FILE_PATH_LITERAL( |
| 4880 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 4807 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
| 4881 0, | 4808 0, |
| 4882 kuint64max, | 4809 kuint64max, |
| 4883 base::Time())); | 4810 base::Time())); |
| 4884 r.set_upload(make_scoped_ptr( | 4811 r->set_upload(make_scoped_ptr( |
| 4885 new UploadDataStream(element_readers.Pass(), 0))); | 4812 new UploadDataStream(element_readers.Pass(), 0))); |
| 4886 | 4813 |
| 4887 r.Start(); | 4814 r->Start(); |
| 4888 EXPECT_TRUE(r.is_pending()); | 4815 EXPECT_TRUE(r->is_pending()); |
| 4889 | 4816 |
| 4890 base::RunLoop().Run(); | 4817 base::RunLoop().Run(); |
| 4891 | 4818 |
| 4892 EXPECT_TRUE(d.request_failed()); | 4819 EXPECT_TRUE(d.request_failed()); |
| 4893 EXPECT_FALSE(d.received_data_before_response()); | 4820 EXPECT_FALSE(d.received_data_before_response()); |
| 4894 EXPECT_EQ(0, d.bytes_received()); | 4821 EXPECT_EQ(0, d.bytes_received()); |
| 4895 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 4822 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 4896 EXPECT_EQ(ERR_FILE_NOT_FOUND, r.status().error()); | 4823 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); |
| 4897 } | 4824 } |
| 4898 } | 4825 } |
| 4899 | 4826 |
| 4900 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 4827 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 4901 ASSERT_TRUE(test_server_.Start()); | 4828 ASSERT_TRUE(test_server_.Start()); |
| 4902 | 4829 |
| 4903 TestDelegate d; | 4830 TestDelegate d; |
| 4904 { | 4831 { |
| 4905 URLRequest r( | 4832 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4906 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4833 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4907 r.EnableChunkedUpload(); | 4834 r->EnableChunkedUpload(); |
| 4908 r.set_method("POST"); | 4835 r->set_method("POST"); |
| 4909 AddChunksToUpload(&r); | 4836 AddChunksToUpload(r.get()); |
| 4910 r.Start(); | 4837 r->Start(); |
| 4911 EXPECT_TRUE(r.is_pending()); | 4838 EXPECT_TRUE(r->is_pending()); |
| 4912 | 4839 |
| 4913 base::RunLoop().Run(); | 4840 base::RunLoop().Run(); |
| 4914 | 4841 |
| 4915 VerifyReceivedDataMatchesChunks(&r, &d); | 4842 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 4916 } | 4843 } |
| 4917 } | 4844 } |
| 4918 | 4845 |
| 4919 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 4846 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
| 4920 ASSERT_TRUE(test_server_.Start()); | 4847 ASSERT_TRUE(test_server_.Start()); |
| 4921 | 4848 |
| 4922 TestDelegate d; | 4849 TestDelegate d; |
| 4923 { | 4850 { |
| 4924 URLRequest r( | 4851 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4925 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4852 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4926 r.EnableChunkedUpload(); | 4853 r->EnableChunkedUpload(); |
| 4927 r.set_method("POST"); | 4854 r->set_method("POST"); |
| 4928 r.Start(); | 4855 r->Start(); |
| 4929 EXPECT_TRUE(r.is_pending()); | 4856 EXPECT_TRUE(r->is_pending()); |
| 4930 AddChunksToUpload(&r); | 4857 AddChunksToUpload(r.get()); |
| 4931 base::RunLoop().Run(); | 4858 base::RunLoop().Run(); |
| 4932 | 4859 |
| 4933 VerifyReceivedDataMatchesChunks(&r, &d); | 4860 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 4934 } | 4861 } |
| 4935 } | 4862 } |
| 4936 | 4863 |
| 4937 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 4864 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 4938 ASSERT_TRUE(test_server_.Start()); | 4865 ASSERT_TRUE(test_server_.Start()); |
| 4939 | 4866 |
| 4940 TestDelegate d; | 4867 TestDelegate d; |
| 4941 { | 4868 { |
| 4942 URLRequest r( | 4869 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4943 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, &default_context_); | 4870 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); |
| 4944 r.EnableChunkedUpload(); | 4871 r->EnableChunkedUpload(); |
| 4945 r.set_method("POST"); | 4872 r->set_method("POST"); |
| 4946 r.Start(); | 4873 r->Start(); |
| 4947 EXPECT_TRUE(r.is_pending()); | 4874 EXPECT_TRUE(r->is_pending()); |
| 4948 | 4875 |
| 4949 base::RunLoop().RunUntilIdle(); | 4876 base::RunLoop().RunUntilIdle(); |
| 4950 AddChunksToUpload(&r); | 4877 AddChunksToUpload(r.get()); |
| 4951 base::RunLoop().Run(); | 4878 base::RunLoop().Run(); |
| 4952 | 4879 |
| 4953 VerifyReceivedDataMatchesChunks(&r, &d); | 4880 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 4954 } | 4881 } |
| 4955 } | 4882 } |
| 4956 | 4883 |
| 4957 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 4884 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 4958 ASSERT_TRUE(test_server_.Start()); | 4885 ASSERT_TRUE(test_server_.Start()); |
| 4959 | 4886 |
| 4960 TestDelegate d; | 4887 TestDelegate d; |
| 4961 URLRequest req(test_server_.GetURL("files/with-headers.html"), | 4888 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 4962 DEFAULT_PRIORITY, | 4889 test_server_.GetURL("files/with-headers.html"), DEFAULT_PRIORITY, &d, |
| 4963 &d, | 4890 NULL)); |
| 4964 &default_context_); | 4891 req->Start(); |
| 4965 req.Start(); | |
| 4966 base::RunLoop().Run(); | 4892 base::RunLoop().Run(); |
| 4967 | 4893 |
| 4968 const HttpResponseHeaders* headers = req.response_headers(); | 4894 const HttpResponseHeaders* headers = req->response_headers(); |
| 4969 | 4895 |
| 4970 // Simple sanity check that response_info() accesses the same data. | 4896 // Simple sanity check that response_info() accesses the same data. |
| 4971 EXPECT_EQ(headers, req.response_info().headers.get()); | 4897 EXPECT_EQ(headers, req->response_info().headers.get()); |
| 4972 | 4898 |
| 4973 std::string header; | 4899 std::string header; |
| 4974 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 4900 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| 4975 EXPECT_EQ("private", header); | 4901 EXPECT_EQ("private", header); |
| 4976 | 4902 |
| 4977 header.clear(); | 4903 header.clear(); |
| 4978 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); | 4904 EXPECT_TRUE(headers->GetNormalizedHeader("content-type", &header)); |
| 4979 EXPECT_EQ("text/html; charset=ISO-8859-1", header); | 4905 EXPECT_EQ("text/html; charset=ISO-8859-1", header); |
| 4980 | 4906 |
| 4981 // The response has two "X-Multiple-Entries" headers. | 4907 // The response has two "X-Multiple-Entries" headers. |
| 4982 // This verfies our output has them concatenated together. | 4908 // This verfies our output has them concatenated together. |
| 4983 header.clear(); | 4909 header.clear(); |
| 4984 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 4910 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
| 4985 EXPECT_EQ("a, b", header); | 4911 EXPECT_EQ("a, b", header); |
| 4986 } | 4912 } |
| 4987 | 4913 |
| 4988 TEST_F(URLRequestTestHTTP, ProcessSTS) { | 4914 TEST_F(URLRequestTestHTTP, ProcessSTS) { |
| 4989 SpawnedTestServer::SSLOptions ssl_options; | 4915 SpawnedTestServer::SSLOptions ssl_options; |
| 4990 SpawnedTestServer https_test_server( | 4916 SpawnedTestServer https_test_server( |
| 4991 SpawnedTestServer::TYPE_HTTPS, | 4917 SpawnedTestServer::TYPE_HTTPS, |
| 4992 ssl_options, | 4918 ssl_options, |
| 4993 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4919 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 4994 ASSERT_TRUE(https_test_server.Start()); | 4920 ASSERT_TRUE(https_test_server.Start()); |
| 4995 | 4921 |
| 4996 TestDelegate d; | 4922 TestDelegate d; |
| 4997 URLRequest request(https_test_server.GetURL("files/hsts-headers.html"), | 4923 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 4998 DEFAULT_PRIORITY, | 4924 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, &d, |
| 4999 &d, | 4925 NULL)); |
| 5000 &default_context_); | 4926 request->Start(); |
| 5001 request.Start(); | |
| 5002 base::RunLoop().Run(); | 4927 base::RunLoop().Run(); |
| 5003 | 4928 |
| 5004 TransportSecurityState* security_state = | 4929 TransportSecurityState* security_state = |
| 5005 default_context_.transport_security_state(); | 4930 default_context_.transport_security_state(); |
| 5006 TransportSecurityState::DomainState domain_state; | 4931 TransportSecurityState::DomainState domain_state; |
| 5007 EXPECT_TRUE(security_state->GetDynamicDomainState( | 4932 EXPECT_TRUE(security_state->GetDynamicDomainState( |
| 5008 SpawnedTestServer::kLocalhost, &domain_state)); | 4933 SpawnedTestServer::kLocalhost, &domain_state)); |
| 5009 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 4934 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5010 domain_state.sts.upgrade_mode); | 4935 domain_state.sts.upgrade_mode); |
| 5011 EXPECT_TRUE(domain_state.sts.include_subdomains); | 4936 EXPECT_TRUE(domain_state.sts.include_subdomains); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5030 // validity/expiration. | 4955 // validity/expiration. |
| 5031 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 4956 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { |
| 5032 SpawnedTestServer::SSLOptions ssl_options; | 4957 SpawnedTestServer::SSLOptions ssl_options; |
| 5033 SpawnedTestServer https_test_server( | 4958 SpawnedTestServer https_test_server( |
| 5034 SpawnedTestServer::TYPE_HTTPS, | 4959 SpawnedTestServer::TYPE_HTTPS, |
| 5035 ssl_options, | 4960 ssl_options, |
| 5036 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4961 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 5037 ASSERT_TRUE(https_test_server.Start()); | 4962 ASSERT_TRUE(https_test_server.Start()); |
| 5038 | 4963 |
| 5039 TestDelegate d; | 4964 TestDelegate d; |
| 5040 URLRequest request(https_test_server.GetURL("files/hpkp-headers.html"), | 4965 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5041 DEFAULT_PRIORITY, | 4966 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, &d, |
| 5042 &d, | 4967 NULL)); |
| 5043 &default_context_); | 4968 request->Start(); |
| 5044 request.Start(); | |
| 5045 base::RunLoop().Run(); | 4969 base::RunLoop().Run(); |
| 5046 | 4970 |
| 5047 TransportSecurityState* security_state = | 4971 TransportSecurityState* security_state = |
| 5048 default_context_.transport_security_state(); | 4972 default_context_.transport_security_state(); |
| 5049 TransportSecurityState::DomainState domain_state; | 4973 TransportSecurityState::DomainState domain_state; |
| 5050 EXPECT_TRUE(security_state->GetDynamicDomainState( | 4974 EXPECT_TRUE(security_state->GetDynamicDomainState( |
| 5051 SpawnedTestServer::kLocalhost, &domain_state)); | 4975 SpawnedTestServer::kLocalhost, &domain_state)); |
| 5052 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, | 4976 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
| 5053 domain_state.sts.upgrade_mode); | 4977 domain_state.sts.upgrade_mode); |
| 5054 EXPECT_FALSE(domain_state.sts.include_subdomains); | 4978 EXPECT_FALSE(domain_state.sts.include_subdomains); |
| 5055 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 4979 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5056 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 4980 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 5057 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 4981 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
| 5058 } | 4982 } |
| 5059 | 4983 |
| 5060 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 4984 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
| 5061 SpawnedTestServer::SSLOptions ssl_options; | 4985 SpawnedTestServer::SSLOptions ssl_options; |
| 5062 SpawnedTestServer https_test_server( | 4986 SpawnedTestServer https_test_server( |
| 5063 SpawnedTestServer::TYPE_HTTPS, | 4987 SpawnedTestServer::TYPE_HTTPS, |
| 5064 ssl_options, | 4988 ssl_options, |
| 5065 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 4989 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 5066 ASSERT_TRUE(https_test_server.Start()); | 4990 ASSERT_TRUE(https_test_server.Start()); |
| 5067 | 4991 |
| 5068 TestDelegate d; | 4992 TestDelegate d; |
| 5069 URLRequest request( | 4993 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5070 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 4994 https_test_server.GetURL("files/hsts-multiple-headers.html"), |
| 5071 DEFAULT_PRIORITY, | 4995 DEFAULT_PRIORITY, &d, NULL)); |
| 5072 &d, | 4996 request->Start(); |
| 5073 &default_context_); | |
| 5074 request.Start(); | |
| 5075 base::RunLoop().Run(); | 4997 base::RunLoop().Run(); |
| 5076 | 4998 |
| 5077 // We should have set parameters from the first header, not the second. | 4999 // We should have set parameters from the first header, not the second. |
| 5078 TransportSecurityState* security_state = | 5000 TransportSecurityState* security_state = |
| 5079 default_context_.transport_security_state(); | 5001 default_context_.transport_security_state(); |
| 5080 TransportSecurityState::DomainState domain_state; | 5002 TransportSecurityState::DomainState domain_state; |
| 5081 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5003 EXPECT_TRUE(security_state->GetDynamicDomainState( |
| 5082 SpawnedTestServer::kLocalhost, &domain_state)); | 5004 SpawnedTestServer::kLocalhost, &domain_state)); |
| 5083 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5005 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5084 domain_state.sts.upgrade_mode); | 5006 domain_state.sts.upgrade_mode); |
| 5085 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5007 EXPECT_FALSE(domain_state.sts.include_subdomains); |
| 5086 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5008 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5087 } | 5009 } |
| 5088 | 5010 |
| 5089 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 5011 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
| 5090 SpawnedTestServer::SSLOptions ssl_options; | 5012 SpawnedTestServer::SSLOptions ssl_options; |
| 5091 SpawnedTestServer https_test_server( | 5013 SpawnedTestServer https_test_server( |
| 5092 SpawnedTestServer::TYPE_HTTPS, | 5014 SpawnedTestServer::TYPE_HTTPS, |
| 5093 ssl_options, | 5015 ssl_options, |
| 5094 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5016 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 5095 ASSERT_TRUE(https_test_server.Start()); | 5017 ASSERT_TRUE(https_test_server.Start()); |
| 5096 | 5018 |
| 5097 TestDelegate d; | 5019 TestDelegate d; |
| 5098 URLRequest request( | 5020 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5099 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 5021 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), |
| 5100 DEFAULT_PRIORITY, | 5022 DEFAULT_PRIORITY, &d, NULL)); |
| 5101 &d, | 5023 request->Start(); |
| 5102 &default_context_); | |
| 5103 request.Start(); | |
| 5104 base::RunLoop().Run(); | 5024 base::RunLoop().Run(); |
| 5105 | 5025 |
| 5106 // We should have set parameters from the first header, not the second. | 5026 // We should have set parameters from the first header, not the second. |
| 5107 TransportSecurityState* security_state = | 5027 TransportSecurityState* security_state = |
| 5108 default_context_.transport_security_state(); | 5028 default_context_.transport_security_state(); |
| 5109 TransportSecurityState::DomainState domain_state; | 5029 TransportSecurityState::DomainState domain_state; |
| 5110 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5030 EXPECT_TRUE(security_state->GetDynamicDomainState( |
| 5111 SpawnedTestServer::kLocalhost, &domain_state)); | 5031 SpawnedTestServer::kLocalhost, &domain_state)); |
| 5112 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5032 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5113 domain_state.sts.upgrade_mode); | 5033 domain_state.sts.upgrade_mode); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5129 // policies, that only the first such policy is processed. | 5049 // policies, that only the first such policy is processed. |
| 5130 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { | 5050 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { |
| 5131 SpawnedTestServer::SSLOptions ssl_options; | 5051 SpawnedTestServer::SSLOptions ssl_options; |
| 5132 SpawnedTestServer https_test_server( | 5052 SpawnedTestServer https_test_server( |
| 5133 SpawnedTestServer::TYPE_HTTPS, | 5053 SpawnedTestServer::TYPE_HTTPS, |
| 5134 ssl_options, | 5054 ssl_options, |
| 5135 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5055 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 5136 ASSERT_TRUE(https_test_server.Start()); | 5056 ASSERT_TRUE(https_test_server.Start()); |
| 5137 | 5057 |
| 5138 TestDelegate d; | 5058 TestDelegate d; |
| 5139 URLRequest request( | 5059 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5140 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 5060 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), |
| 5141 DEFAULT_PRIORITY, | 5061 DEFAULT_PRIORITY, &d, NULL)); |
| 5142 &d, | 5062 request->Start(); |
| 5143 &default_context_); | |
| 5144 request.Start(); | |
| 5145 base::RunLoop().Run(); | 5063 base::RunLoop().Run(); |
| 5146 | 5064 |
| 5147 TransportSecurityState* security_state = | 5065 TransportSecurityState* security_state = |
| 5148 default_context_.transport_security_state(); | 5066 default_context_.transport_security_state(); |
| 5149 TransportSecurityState::DomainState domain_state; | 5067 TransportSecurityState::DomainState domain_state; |
| 5150 EXPECT_TRUE(security_state->GetDynamicDomainState( | 5068 EXPECT_TRUE(security_state->GetDynamicDomainState( |
| 5151 SpawnedTestServer::kLocalhost, &domain_state)); | 5069 SpawnedTestServer::kLocalhost, &domain_state)); |
| 5152 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5070 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5153 domain_state.sts.upgrade_mode); | 5071 domain_state.sts.upgrade_mode); |
| 5154 #if defined(OS_ANDROID) | 5072 #if defined(OS_ANDROID) |
| 5155 // Android's CertVerifyProc does not (yet) handle pins. | 5073 // Android's CertVerifyProc does not (yet) handle pins. |
| 5156 #else | 5074 #else |
| 5157 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5075 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 5158 #endif | 5076 #endif |
| 5159 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 5077 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
| 5160 | 5078 |
| 5161 EXPECT_TRUE(domain_state.sts.include_subdomains); | 5079 EXPECT_TRUE(domain_state.sts.include_subdomains); |
| 5162 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5080 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5163 } | 5081 } |
| 5164 | 5082 |
| 5165 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 5083 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
| 5166 ASSERT_TRUE(test_server_.Start()); | 5084 ASSERT_TRUE(test_server_.Start()); |
| 5167 | 5085 |
| 5168 TestDelegate d; | 5086 TestDelegate d; |
| 5169 URLRequest req(test_server_.GetURL("files/content-type-normalization.html"), | 5087 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5170 DEFAULT_PRIORITY, | 5088 test_server_.GetURL("files/content-type-normalization.html"), |
| 5171 &d, | 5089 DEFAULT_PRIORITY, &d, NULL)); |
| 5172 &default_context_); | 5090 req->Start(); |
| 5173 req.Start(); | |
| 5174 base::RunLoop().Run(); | 5091 base::RunLoop().Run(); |
| 5175 | 5092 |
| 5176 std::string mime_type; | 5093 std::string mime_type; |
| 5177 req.GetMimeType(&mime_type); | 5094 req->GetMimeType(&mime_type); |
| 5178 EXPECT_EQ("text/html", mime_type); | 5095 EXPECT_EQ("text/html", mime_type); |
| 5179 | 5096 |
| 5180 std::string charset; | 5097 std::string charset; |
| 5181 req.GetCharset(&charset); | 5098 req->GetCharset(&charset); |
| 5182 EXPECT_EQ("utf-8", charset); | 5099 EXPECT_EQ("utf-8", charset); |
| 5183 req.Cancel(); | 5100 req->Cancel(); |
| 5184 } | 5101 } |
| 5185 | 5102 |
| 5186 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) { | 5103 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictDataRedirects) { |
| 5187 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). | 5104 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
| 5188 GURL data_url("data:,foo"); | 5105 GURL data_url("data:,foo"); |
| 5189 DataProtocolHandler data_protocol_handler; | 5106 DataProtocolHandler data_protocol_handler; |
| 5190 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); | 5107 EXPECT_FALSE(data_protocol_handler.IsSafeRedirectTarget(data_url)); |
| 5191 | 5108 |
| 5192 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 5109 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 5193 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); | 5110 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(data_url)); |
| 5194 } | 5111 } |
| 5195 | 5112 |
| 5196 #if !defined(DISABLE_FILE_SUPPORT) | 5113 #if !defined(DISABLE_FILE_SUPPORT) |
| 5197 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { | 5114 TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictFileRedirects) { |
| 5198 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). | 5115 // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(). |
| 5199 GURL file_url("file:///foo.txt"); | 5116 GURL file_url("file:///foo.txt"); |
| 5200 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); | 5117 FileProtocolHandler file_protocol_handler(base::MessageLoopProxy::current()); |
| 5201 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); | 5118 EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url)); |
| 5202 | 5119 |
| 5203 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 5120 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 5204 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); | 5121 EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url)); |
| 5205 } | 5122 } |
| 5206 | 5123 |
| 5207 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { | 5124 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { |
| 5208 ASSERT_TRUE(test_server_.Start()); | 5125 ASSERT_TRUE(test_server_.Start()); |
| 5209 | 5126 |
| 5210 TestDelegate d; | 5127 TestDelegate d; |
| 5211 URLRequest req(test_server_.GetURL("files/redirect-to-file.html"), | 5128 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5212 DEFAULT_PRIORITY, | 5129 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, &d, |
| 5213 &d, | 5130 NULL)); |
| 5214 &default_context_); | 5131 req->Start(); |
| 5215 req.Start(); | |
| 5216 base::RunLoop().Run(); | 5132 base::RunLoop().Run(); |
| 5217 | 5133 |
| 5218 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5134 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 5219 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 5135 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); |
| 5220 } | 5136 } |
| 5221 #endif // !defined(DISABLE_FILE_SUPPORT) | 5137 #endif // !defined(DISABLE_FILE_SUPPORT) |
| 5222 | 5138 |
| 5223 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { | 5139 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { |
| 5224 ASSERT_TRUE(test_server_.Start()); | 5140 ASSERT_TRUE(test_server_.Start()); |
| 5225 | 5141 |
| 5226 TestDelegate d; | 5142 TestDelegate d; |
| 5227 URLRequest req(test_server_.GetURL("files/redirect-to-data.html"), | 5143 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5228 DEFAULT_PRIORITY, | 5144 test_server_.GetURL("files/redirect-to-data.html"), DEFAULT_PRIORITY, &d, |
| 5229 &d, | 5145 NULL)); |
| 5230 &default_context_); | 5146 req->Start(); |
| 5231 req.Start(); | |
| 5232 base::MessageLoop::current()->Run(); | 5147 base::MessageLoop::current()->Run(); |
| 5233 | 5148 |
| 5234 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5149 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 5235 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 5150 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); |
| 5236 } | 5151 } |
| 5237 | 5152 |
| 5238 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 5153 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 5239 ASSERT_TRUE(test_server_.Start()); | 5154 ASSERT_TRUE(test_server_.Start()); |
| 5240 | 5155 |
| 5241 TestDelegate d; | 5156 TestDelegate d; |
| 5242 URLRequest req(test_server_.GetURL("files/redirect-to-invalid-url.html"), | 5157 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5243 DEFAULT_PRIORITY, | 5158 test_server_.GetURL("files/redirect-to-invalid-url.html"), |
| 5244 &d, | 5159 DEFAULT_PRIORITY, &d, NULL)); |
| 5245 &default_context_); | 5160 req->Start(); |
| 5246 req.Start(); | |
| 5247 base::RunLoop().Run(); | 5161 base::RunLoop().Run(); |
| 5248 | 5162 |
| 5249 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 5163 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 5250 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); | 5164 EXPECT_EQ(ERR_INVALID_URL, req->status().error()); |
| 5251 } | 5165 } |
| 5252 | 5166 |
| 5253 // Make sure redirects are cached, despite not reading their bodies. | 5167 // Make sure redirects are cached, despite not reading their bodies. |
| 5254 TEST_F(URLRequestTestHTTP, CacheRedirect) { | 5168 TEST_F(URLRequestTestHTTP, CacheRedirect) { |
| 5255 ASSERT_TRUE(test_server_.Start()); | 5169 ASSERT_TRUE(test_server_.Start()); |
| 5256 GURL redirect_url = | 5170 GURL redirect_url = |
| 5257 test_server_.GetURL("files/redirect302-to-echo-cacheable"); | 5171 test_server_.GetURL("files/redirect302-to-echo-cacheable"); |
| 5258 | 5172 |
| 5259 { | 5173 { |
| 5260 TestDelegate d; | 5174 TestDelegate d; |
| 5261 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); | 5175 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5262 req.Start(); | 5176 redirect_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5177 req->Start(); |
| 5263 base::RunLoop().Run(); | 5178 base::RunLoop().Run(); |
| 5264 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5179 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5265 EXPECT_EQ(1, d.received_redirect_count()); | 5180 EXPECT_EQ(1, d.received_redirect_count()); |
| 5266 EXPECT_EQ(test_server_.GetURL("echo"), req.url()); | 5181 EXPECT_EQ(test_server_.GetURL("echo"), req->url()); |
| 5267 } | 5182 } |
| 5268 | 5183 |
| 5269 { | 5184 { |
| 5270 TestDelegate d; | 5185 TestDelegate d; |
| 5271 d.set_quit_on_redirect(true); | 5186 d.set_quit_on_redirect(true); |
| 5272 URLRequest req(redirect_url, DEFAULT_PRIORITY, &d, &default_context_); | 5187 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5273 req.Start(); | 5188 redirect_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5189 req->Start(); |
| 5274 base::RunLoop().Run(); | 5190 base::RunLoop().Run(); |
| 5275 | 5191 |
| 5276 EXPECT_EQ(1, d.received_redirect_count()); | 5192 EXPECT_EQ(1, d.received_redirect_count()); |
| 5277 EXPECT_EQ(0, d.response_started_count()); | 5193 EXPECT_EQ(0, d.response_started_count()); |
| 5278 EXPECT_TRUE(req.was_cached()); | 5194 EXPECT_TRUE(req->was_cached()); |
| 5279 | 5195 |
| 5280 req.FollowDeferredRedirect(); | 5196 req->FollowDeferredRedirect(); |
| 5281 base::RunLoop().Run(); | 5197 base::RunLoop().Run(); |
| 5282 EXPECT_EQ(1, d.received_redirect_count()); | 5198 EXPECT_EQ(1, d.received_redirect_count()); |
| 5283 EXPECT_EQ(1, d.response_started_count()); | 5199 EXPECT_EQ(1, d.response_started_count()); |
| 5284 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5200 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5285 EXPECT_EQ(test_server_.GetURL("echo"), req.url()); | 5201 EXPECT_EQ(test_server_.GetURL("echo"), req->url()); |
| 5286 } | 5202 } |
| 5287 } | 5203 } |
| 5288 | 5204 |
| 5289 // Make sure a request isn't cached when a NetworkDelegate forces a redirect | 5205 // Make sure a request isn't cached when a NetworkDelegate forces a redirect |
| 5290 // when the headers are read, since the body won't have been read. | 5206 // when the headers are read, since the body won't have been read. |
| 5291 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { | 5207 TEST_F(URLRequestTestHTTP, NoCacheOnNetworkDelegateRedirect) { |
| 5292 ASSERT_TRUE(test_server_.Start()); | 5208 ASSERT_TRUE(test_server_.Start()); |
| 5293 // URL that is normally cached. | 5209 // URL that is normally cached. |
| 5294 GURL initial_url = test_server_.GetURL("cachetime"); | 5210 GURL initial_url = test_server_.GetURL("cachetime"); |
| 5295 | 5211 |
| 5296 { | 5212 { |
| 5297 // Set up the TestNetworkDelegate tp force a redirect. | 5213 // Set up the TestNetworkDelegate tp force a redirect. |
| 5298 GURL redirect_to_url = test_server_.GetURL("echo"); | 5214 GURL redirect_to_url = test_server_.GetURL("echo"); |
| 5299 default_network_delegate_.set_redirect_on_headers_received_url( | 5215 default_network_delegate_.set_redirect_on_headers_received_url( |
| 5300 redirect_to_url); | 5216 redirect_to_url); |
| 5301 | 5217 |
| 5302 TestDelegate d; | 5218 TestDelegate d; |
| 5303 URLRequest req(initial_url, DEFAULT_PRIORITY, &d, &default_context_); | 5219 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5304 req.Start(); | 5220 initial_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5221 req->Start(); |
| 5305 base::RunLoop().Run(); | 5222 base::RunLoop().Run(); |
| 5306 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5223 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5307 EXPECT_EQ(1, d.received_redirect_count()); | 5224 EXPECT_EQ(1, d.received_redirect_count()); |
| 5308 EXPECT_EQ(redirect_to_url, req.url()); | 5225 EXPECT_EQ(redirect_to_url, req->url()); |
| 5309 } | 5226 } |
| 5310 | 5227 |
| 5311 { | 5228 { |
| 5312 TestDelegate d; | 5229 TestDelegate d; |
| 5313 URLRequest req(initial_url, DEFAULT_PRIORITY, &d, &default_context_); | 5230 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5314 req.Start(); | 5231 initial_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5232 req->Start(); |
| 5315 base::RunLoop().Run(); | 5233 base::RunLoop().Run(); |
| 5316 | 5234 |
| 5317 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5235 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5318 EXPECT_FALSE(req.was_cached()); | 5236 EXPECT_FALSE(req->was_cached()); |
| 5319 EXPECT_EQ(0, d.received_redirect_count()); | 5237 EXPECT_EQ(0, d.received_redirect_count()); |
| 5320 EXPECT_EQ(initial_url, req.url()); | 5238 EXPECT_EQ(initial_url, req->url()); |
| 5321 } | 5239 } |
| 5322 } | 5240 } |
| 5323 | 5241 |
| 5324 // Tests that redirection to an unsafe URL is allowed when it has been marked as | 5242 // Tests that redirection to an unsafe URL is allowed when it has been marked as |
| 5325 // safe. | 5243 // safe. |
| 5326 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { | 5244 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { |
| 5327 ASSERT_TRUE(test_server_.Start()); | 5245 ASSERT_TRUE(test_server_.Start()); |
| 5328 | 5246 |
| 5329 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); | 5247 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); |
| 5330 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 5248 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 5331 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 5249 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 5332 | 5250 |
| 5333 TestDelegate d; | 5251 TestDelegate d; |
| 5334 { | 5252 { |
| 5335 URLRequest r(test_server_.GetURL("whatever"), | 5253 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5336 DEFAULT_PRIORITY, | 5254 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL)); |
| 5337 &d, | |
| 5338 &default_context_); | |
| 5339 | 5255 |
| 5340 r.Start(); | 5256 r->Start(); |
| 5341 base::RunLoop().Run(); | 5257 base::RunLoop().Run(); |
| 5342 | 5258 |
| 5343 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5259 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5344 | 5260 |
| 5345 EXPECT_EQ(2U, r.url_chain().size()); | 5261 EXPECT_EQ(2U, r->url_chain().size()); |
| 5346 EXPECT_EQ(net::OK, r.status().error()); | 5262 EXPECT_EQ(net::OK, r->status().error()); |
| 5347 EXPECT_EQ(unsafe_url, r.url()); | 5263 EXPECT_EQ(unsafe_url, r->url()); |
| 5348 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); | 5264 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); |
| 5349 } | 5265 } |
| 5350 } | 5266 } |
| 5351 | 5267 |
| 5352 // Tests that a redirect to a different unsafe URL is blocked, even after adding | 5268 // Tests that a redirect to a different unsafe URL is blocked, even after adding |
| 5353 // some other URL to the whitelist. | 5269 // some other URL to the whitelist. |
| 5354 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { | 5270 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { |
| 5355 ASSERT_TRUE(test_server_.Start()); | 5271 ASSERT_TRUE(test_server_.Start()); |
| 5356 | 5272 |
| 5357 GURL unsafe_url("data:text/html,something"); | 5273 GURL unsafe_url("data:text/html,something"); |
| 5358 GURL different_unsafe_url("data:text/html,something-else"); | 5274 GURL different_unsafe_url("data:text/html,something-else"); |
| 5359 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 5275 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 5360 default_network_delegate_.set_allowed_unsafe_redirect_url( | 5276 default_network_delegate_.set_allowed_unsafe_redirect_url( |
| 5361 different_unsafe_url); | 5277 different_unsafe_url); |
| 5362 | 5278 |
| 5363 TestDelegate d; | 5279 TestDelegate d; |
| 5364 { | 5280 { |
| 5365 URLRequest r(test_server_.GetURL("whatever"), | 5281 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5366 DEFAULT_PRIORITY, | 5282 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL)); |
| 5367 &d, | |
| 5368 &default_context_); | |
| 5369 | 5283 |
| 5370 r.Start(); | 5284 r->Start(); |
| 5371 base::RunLoop().Run(); | 5285 base::RunLoop().Run(); |
| 5372 | 5286 |
| 5373 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 5287 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 5374 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r.status().error()); | 5288 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error()); |
| 5375 } | 5289 } |
| 5376 } | 5290 } |
| 5377 | 5291 |
| 5378 // Redirects from an URL with fragment to an unsafe URL with fragment should | 5292 // Redirects from an URL with fragment to an unsafe URL with fragment should |
| 5379 // be allowed, and the reference fragment of the target URL should be preserved. | 5293 // be allowed, and the reference fragment of the target URL should be preserved. |
| 5380 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { | 5294 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { |
| 5381 ASSERT_TRUE(test_server_.Start()); | 5295 ASSERT_TRUE(test_server_.Start()); |
| 5382 | 5296 |
| 5383 GURL original_url(test_server_.GetURL("original#fragment1")); | 5297 GURL original_url(test_server_.GetURL("original#fragment1")); |
| 5384 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 5298 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 5385 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 5299 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 5386 | 5300 |
| 5387 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 5301 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 5388 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 5302 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 5389 | 5303 |
| 5390 TestDelegate d; | 5304 TestDelegate d; |
| 5391 { | 5305 { |
| 5392 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5306 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5307 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5393 | 5308 |
| 5394 r.Start(); | 5309 r->Start(); |
| 5395 base::RunLoop().Run(); | 5310 base::RunLoop().Run(); |
| 5396 | 5311 |
| 5397 EXPECT_EQ(2U, r.url_chain().size()); | 5312 EXPECT_EQ(2U, r->url_chain().size()); |
| 5398 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5313 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5399 EXPECT_EQ(net::OK, r.status().error()); | 5314 EXPECT_EQ(net::OK, r->status().error()); |
| 5400 EXPECT_EQ(original_url, r.original_url()); | 5315 EXPECT_EQ(original_url, r->original_url()); |
| 5401 EXPECT_EQ(expected_url, r.url()); | 5316 EXPECT_EQ(expected_url, r->url()); |
| 5402 } | 5317 } |
| 5403 } | 5318 } |
| 5404 | 5319 |
| 5405 // When a delegate has specified a safe redirect URL, but it does not match the | 5320 // When a delegate has specified a safe redirect URL, but it does not match the |
| 5406 // redirect target, then do not prevent the reference fragment from being added. | 5321 // redirect target, then do not prevent the reference fragment from being added. |
| 5407 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { | 5322 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { |
| 5408 ASSERT_TRUE(test_server_.Start()); | 5323 ASSERT_TRUE(test_server_.Start()); |
| 5409 | 5324 |
| 5410 GURL original_url(test_server_.GetURL("original#expected-fragment")); | 5325 GURL original_url(test_server_.GetURL("original#expected-fragment")); |
| 5411 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); | 5326 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); |
| 5412 GURL redirect_url(test_server_.GetURL("target")); | 5327 GURL redirect_url(test_server_.GetURL("target")); |
| 5413 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); | 5328 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); |
| 5414 | 5329 |
| 5415 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 5330 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 5416 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 5331 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 5417 | 5332 |
| 5418 TestDelegate d; | 5333 TestDelegate d; |
| 5419 { | 5334 { |
| 5420 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5335 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5336 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5421 | 5337 |
| 5422 r.Start(); | 5338 r->Start(); |
| 5423 base::RunLoop().Run(); | 5339 base::RunLoop().Run(); |
| 5424 | 5340 |
| 5425 EXPECT_EQ(2U, r.url_chain().size()); | 5341 EXPECT_EQ(2U, r->url_chain().size()); |
| 5426 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5342 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5427 EXPECT_EQ(net::OK, r.status().error()); | 5343 EXPECT_EQ(net::OK, r->status().error()); |
| 5428 EXPECT_EQ(original_url, r.original_url()); | 5344 EXPECT_EQ(original_url, r->original_url()); |
| 5429 EXPECT_EQ(expected_redirect_url, r.url()); | 5345 EXPECT_EQ(expected_redirect_url, r->url()); |
| 5430 } | 5346 } |
| 5431 } | 5347 } |
| 5432 | 5348 |
| 5433 // When a delegate has specified a safe redirect URL, assume that the redirect | 5349 // When a delegate has specified a safe redirect URL, assume that the redirect |
| 5434 // URL should not be changed. In particular, the reference fragment should not | 5350 // URL should not be changed. In particular, the reference fragment should not |
| 5435 // be modified. | 5351 // be modified. |
| 5436 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { | 5352 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { |
| 5437 ASSERT_TRUE(test_server_.Start()); | 5353 ASSERT_TRUE(test_server_.Start()); |
| 5438 | 5354 |
| 5439 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); | 5355 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); |
| 5440 GURL redirect_url("data:text/html,expect-no-reference-fragment"); | 5356 GURL redirect_url("data:text/html,expect-no-reference-fragment"); |
| 5441 | 5357 |
| 5442 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 5358 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 5443 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); | 5359 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); |
| 5444 | 5360 |
| 5445 TestDelegate d; | 5361 TestDelegate d; |
| 5446 { | 5362 { |
| 5447 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5363 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5364 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5448 | 5365 |
| 5449 r.Start(); | 5366 r->Start(); |
| 5450 base::RunLoop().Run(); | 5367 base::RunLoop().Run(); |
| 5451 | 5368 |
| 5452 EXPECT_EQ(2U, r.url_chain().size()); | 5369 EXPECT_EQ(2U, r->url_chain().size()); |
| 5453 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5370 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5454 EXPECT_EQ(net::OK, r.status().error()); | 5371 EXPECT_EQ(net::OK, r->status().error()); |
| 5455 EXPECT_EQ(original_url, r.original_url()); | 5372 EXPECT_EQ(original_url, r->original_url()); |
| 5456 EXPECT_EQ(redirect_url, r.url()); | 5373 EXPECT_EQ(redirect_url, r->url()); |
| 5457 } | 5374 } |
| 5458 } | 5375 } |
| 5459 | 5376 |
| 5460 // When a URLRequestRedirectJob is created, the redirection must be followed and | 5377 // When a URLRequestRedirectJob is created, the redirection must be followed and |
| 5461 // the reference fragment of the target URL must not be modified. | 5378 // the reference fragment of the target URL must not be modified. |
| 5462 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { | 5379 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { |
| 5463 ASSERT_TRUE(test_server_.Start()); | 5380 ASSERT_TRUE(test_server_.Start()); |
| 5464 | 5381 |
| 5465 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); | 5382 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); |
| 5466 GURL redirect_url(test_server_.GetURL("echo")); | 5383 GURL redirect_url(test_server_.GetURL("echo")); |
| 5467 | 5384 |
| 5468 TestDelegate d; | 5385 TestDelegate d; |
| 5469 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5386 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5387 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5470 | 5388 |
| 5471 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 5389 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 5472 &r, &default_network_delegate_, redirect_url, | 5390 r.get(), &default_network_delegate_, redirect_url, |
| 5473 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 5391 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 5474 AddTestInterceptor()->set_main_intercept_job(job); | 5392 AddTestInterceptor()->set_main_intercept_job(job); |
| 5475 | 5393 |
| 5476 r.Start(); | 5394 r->Start(); |
| 5477 base::RunLoop().Run(); | 5395 base::RunLoop().Run(); |
| 5478 | 5396 |
| 5479 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5397 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 5480 EXPECT_EQ(net::OK, r.status().error()); | 5398 EXPECT_EQ(net::OK, r->status().error()); |
| 5481 EXPECT_EQ(original_url, r.original_url()); | 5399 EXPECT_EQ(original_url, r->original_url()); |
| 5482 EXPECT_EQ(redirect_url, r.url()); | 5400 EXPECT_EQ(redirect_url, r->url()); |
| 5483 } | 5401 } |
| 5484 | 5402 |
| 5485 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 5403 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 5486 ASSERT_TRUE(test_server_.Start()); | 5404 ASSERT_TRUE(test_server_.Start()); |
| 5487 | 5405 |
| 5488 TestDelegate d; | 5406 TestDelegate d; |
| 5489 URLRequest req(test_server_.GetURL("echoheader?Referer"), | 5407 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5490 DEFAULT_PRIORITY, | 5408 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); |
| 5491 &d, | 5409 req->SetReferrer("http://user:pass@foo.com/"); |
| 5492 &default_context_); | 5410 req->Start(); |
| 5493 req.SetReferrer("http://user:pass@foo.com/"); | |
| 5494 req.Start(); | |
| 5495 base::RunLoop().Run(); | 5411 base::RunLoop().Run(); |
| 5496 | 5412 |
| 5497 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 5413 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 5498 } | 5414 } |
| 5499 | 5415 |
| 5500 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { | 5416 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { |
| 5501 ASSERT_TRUE(test_server_.Start()); | 5417 ASSERT_TRUE(test_server_.Start()); |
| 5502 | 5418 |
| 5503 TestDelegate d; | 5419 TestDelegate d; |
| 5504 URLRequest req(test_server_.GetURL("echoheader?Referer"), | 5420 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5505 DEFAULT_PRIORITY, | 5421 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); |
| 5506 &d, | 5422 req->SetReferrer("http://foo.com/test#fragment"); |
| 5507 &default_context_); | 5423 req->Start(); |
| 5508 req.SetReferrer("http://foo.com/test#fragment"); | |
| 5509 req.Start(); | |
| 5510 base::RunLoop().Run(); | 5424 base::RunLoop().Run(); |
| 5511 | 5425 |
| 5512 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); | 5426 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); |
| 5513 } | 5427 } |
| 5514 | 5428 |
| 5515 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { | 5429 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { |
| 5516 ASSERT_TRUE(test_server_.Start()); | 5430 ASSERT_TRUE(test_server_.Start()); |
| 5517 | 5431 |
| 5518 TestDelegate d; | 5432 TestDelegate d; |
| 5519 URLRequest req(test_server_.GetURL("echoheader?Referer"), | 5433 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5520 DEFAULT_PRIORITY, | 5434 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); |
| 5521 &d, | 5435 req->SetReferrer("http://foo.com/test#fragment"); |
| 5522 &default_context_); | 5436 req->SetReferrer(""); |
| 5523 req.SetReferrer("http://foo.com/test#fragment"); | 5437 req->Start(); |
| 5524 req.SetReferrer(""); | |
| 5525 req.Start(); | |
| 5526 base::RunLoop().Run(); | 5438 base::RunLoop().Run(); |
| 5527 | 5439 |
| 5528 EXPECT_EQ(std::string("None"), d.data_received()); | 5440 EXPECT_EQ(std::string("None"), d.data_received()); |
| 5529 } | 5441 } |
| 5530 | 5442 |
| 5531 // Defer network start and then resume, checking that the request was a success | 5443 // Defer network start and then resume, checking that the request was a success |
| 5532 // and bytes were received. | 5444 // and bytes were received. |
| 5533 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { | 5445 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { |
| 5534 ASSERT_TRUE(test_server_.Start()); | 5446 ASSERT_TRUE(test_server_.Start()); |
| 5535 | 5447 |
| 5536 TestDelegate d; | 5448 TestDelegate d; |
| 5537 { | 5449 { |
| 5538 d.set_quit_on_network_start(true); | 5450 d.set_quit_on_network_start(true); |
| 5539 GURL test_url(test_server_.GetURL("echo")); | 5451 GURL test_url(test_server_.GetURL("echo")); |
| 5540 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); | 5452 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5453 test_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5541 | 5454 |
| 5542 req.Start(); | 5455 req->Start(); |
| 5543 base::RunLoop().Run(); | 5456 base::RunLoop().Run(); |
| 5544 | 5457 |
| 5545 EXPECT_EQ(1, d.received_before_network_start_count()); | 5458 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 5546 EXPECT_EQ(0, d.response_started_count()); | 5459 EXPECT_EQ(0, d.response_started_count()); |
| 5547 | 5460 |
| 5548 req.ResumeNetworkStart(); | 5461 req->ResumeNetworkStart(); |
| 5549 base::RunLoop().Run(); | 5462 base::RunLoop().Run(); |
| 5550 | 5463 |
| 5551 EXPECT_EQ(1, d.response_started_count()); | 5464 EXPECT_EQ(1, d.response_started_count()); |
| 5552 EXPECT_NE(0, d.bytes_received()); | 5465 EXPECT_NE(0, d.bytes_received()); |
| 5553 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5466 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5554 } | 5467 } |
| 5555 } | 5468 } |
| 5556 | 5469 |
| 5557 // Check that OnBeforeNetworkStart is only called once even if there is a | 5470 // Check that OnBeforeNetworkStart is only called once even if there is a |
| 5558 // redirect. | 5471 // redirect. |
| 5559 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { | 5472 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { |
| 5560 ASSERT_TRUE(test_server_.Start()); | 5473 ASSERT_TRUE(test_server_.Start()); |
| 5561 | 5474 |
| 5562 TestDelegate d; | 5475 TestDelegate d; |
| 5563 { | 5476 { |
| 5564 d.set_quit_on_redirect(true); | 5477 d.set_quit_on_redirect(true); |
| 5565 d.set_quit_on_network_start(true); | 5478 d.set_quit_on_network_start(true); |
| 5566 URLRequest req(test_server_.GetURL("server-redirect?echo"), | 5479 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5567 DEFAULT_PRIORITY, | 5480 test_server_.GetURL("server-redirect?echo"), DEFAULT_PRIORITY, &d, |
| 5568 &d, | 5481 NULL)); |
| 5569 &default_context_); | |
| 5570 | 5482 |
| 5571 req.Start(); | 5483 req->Start(); |
| 5572 base::RunLoop().Run(); | 5484 base::RunLoop().Run(); |
| 5573 | 5485 |
| 5574 EXPECT_EQ(1, d.received_before_network_start_count()); | 5486 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 5575 EXPECT_EQ(0, d.response_started_count()); | 5487 EXPECT_EQ(0, d.response_started_count()); |
| 5576 EXPECT_EQ(0, d.received_redirect_count()); | 5488 EXPECT_EQ(0, d.received_redirect_count()); |
| 5577 | 5489 |
| 5578 req.ResumeNetworkStart(); | 5490 req->ResumeNetworkStart(); |
| 5579 base::RunLoop().Run(); | 5491 base::RunLoop().Run(); |
| 5580 | 5492 |
| 5581 EXPECT_EQ(1, d.received_redirect_count()); | 5493 EXPECT_EQ(1, d.received_redirect_count()); |
| 5582 req.FollowDeferredRedirect(); | 5494 req->FollowDeferredRedirect(); |
| 5583 base::RunLoop().Run(); | 5495 base::RunLoop().Run(); |
| 5584 | 5496 |
| 5585 // Check that the redirect's new network transaction does not get propagated | 5497 // Check that the redirect's new network transaction does not get propagated |
| 5586 // to a second OnBeforeNetworkStart() notification. | 5498 // to a second OnBeforeNetworkStart() notification. |
| 5587 EXPECT_EQ(1, d.received_before_network_start_count()); | 5499 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 5588 | 5500 |
| 5589 EXPECT_EQ(1, d.response_started_count()); | 5501 EXPECT_EQ(1, d.response_started_count()); |
| 5590 EXPECT_NE(0, d.bytes_received()); | 5502 EXPECT_NE(0, d.bytes_received()); |
| 5591 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5503 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5592 } | 5504 } |
| 5593 } | 5505 } |
| 5594 | 5506 |
| 5595 // Cancel the request after learning that the request would use the network. | 5507 // Cancel the request after learning that the request would use the network. |
| 5596 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { | 5508 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { |
| 5597 ASSERT_TRUE(test_server_.Start()); | 5509 ASSERT_TRUE(test_server_.Start()); |
| 5598 | 5510 |
| 5599 TestDelegate d; | 5511 TestDelegate d; |
| 5600 { | 5512 { |
| 5601 d.set_quit_on_network_start(true); | 5513 d.set_quit_on_network_start(true); |
| 5602 GURL test_url(test_server_.GetURL("echo")); | 5514 GURL test_url(test_server_.GetURL("echo")); |
| 5603 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); | 5515 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5516 test_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5604 | 5517 |
| 5605 req.Start(); | 5518 req->Start(); |
| 5606 base::RunLoop().Run(); | 5519 base::RunLoop().Run(); |
| 5607 | 5520 |
| 5608 EXPECT_EQ(1, d.received_before_network_start_count()); | 5521 EXPECT_EQ(1, d.received_before_network_start_count()); |
| 5609 EXPECT_EQ(0, d.response_started_count()); | 5522 EXPECT_EQ(0, d.response_started_count()); |
| 5610 | 5523 |
| 5611 req.Cancel(); | 5524 req->Cancel(); |
| 5612 base::RunLoop().Run(); | 5525 base::RunLoop().Run(); |
| 5613 | 5526 |
| 5614 EXPECT_EQ(1, d.response_started_count()); | 5527 EXPECT_EQ(1, d.response_started_count()); |
| 5615 EXPECT_EQ(0, d.bytes_received()); | 5528 EXPECT_EQ(0, d.bytes_received()); |
| 5616 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 5529 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 5617 } | 5530 } |
| 5618 } | 5531 } |
| 5619 | 5532 |
| 5620 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 5533 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 5621 ASSERT_TRUE(test_server_.Start()); | 5534 ASSERT_TRUE(test_server_.Start()); |
| 5622 | 5535 |
| 5623 TestDelegate d; | 5536 TestDelegate d; |
| 5624 { | 5537 { |
| 5625 d.set_cancel_in_received_redirect(true); | 5538 d.set_cancel_in_received_redirect(true); |
| 5626 URLRequest req(test_server_.GetURL("files/redirect-test.html"), | 5539 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5627 DEFAULT_PRIORITY, | 5540 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d, |
| 5628 &d, | 5541 NULL)); |
| 5629 &default_context_); | 5542 req->Start(); |
| 5630 req.Start(); | |
| 5631 base::RunLoop().Run(); | 5543 base::RunLoop().Run(); |
| 5632 | 5544 |
| 5633 EXPECT_EQ(1, d.response_started_count()); | 5545 EXPECT_EQ(1, d.response_started_count()); |
| 5634 EXPECT_EQ(0, d.bytes_received()); | 5546 EXPECT_EQ(0, d.bytes_received()); |
| 5635 EXPECT_FALSE(d.received_data_before_response()); | 5547 EXPECT_FALSE(d.received_data_before_response()); |
| 5636 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 5548 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 5637 } | 5549 } |
| 5638 } | 5550 } |
| 5639 | 5551 |
| 5640 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 5552 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 5641 ASSERT_TRUE(test_server_.Start()); | 5553 ASSERT_TRUE(test_server_.Start()); |
| 5642 | 5554 |
| 5643 TestDelegate d; | 5555 TestDelegate d; |
| 5644 { | 5556 { |
| 5645 d.set_quit_on_redirect(true); | 5557 d.set_quit_on_redirect(true); |
| 5646 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 5558 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
| 5647 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); | 5559 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5560 test_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5648 | 5561 |
| 5649 req.Start(); | 5562 req->Start(); |
| 5650 base::RunLoop().Run(); | 5563 base::RunLoop().Run(); |
| 5651 | 5564 |
| 5652 EXPECT_EQ(1, d.received_redirect_count()); | 5565 EXPECT_EQ(1, d.received_redirect_count()); |
| 5653 | 5566 |
| 5654 req.FollowDeferredRedirect(); | 5567 req->FollowDeferredRedirect(); |
| 5655 base::RunLoop().Run(); | 5568 base::RunLoop().Run(); |
| 5656 | 5569 |
| 5657 EXPECT_EQ(1, d.response_started_count()); | 5570 EXPECT_EQ(1, d.response_started_count()); |
| 5658 EXPECT_FALSE(d.received_data_before_response()); | 5571 EXPECT_FALSE(d.received_data_before_response()); |
| 5659 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5572 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5660 | 5573 |
| 5661 base::FilePath path; | 5574 base::FilePath path; |
| 5662 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5575 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 5663 path = path.Append(FILE_PATH_LITERAL("net")); | 5576 path = path.Append(FILE_PATH_LITERAL("net")); |
| 5664 path = path.Append(FILE_PATH_LITERAL("data")); | 5577 path = path.Append(FILE_PATH_LITERAL("data")); |
| 5665 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 5578 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 5666 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 5579 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 5667 | 5580 |
| 5668 std::string contents; | 5581 std::string contents; |
| 5669 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 5582 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 5670 EXPECT_EQ(contents, d.data_received()); | 5583 EXPECT_EQ(contents, d.data_received()); |
| 5671 } | 5584 } |
| 5672 } | 5585 } |
| 5673 | 5586 |
| 5674 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { | 5587 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { |
| 5675 ASSERT_TRUE(test_server_.Start()); | 5588 ASSERT_TRUE(test_server_.Start()); |
| 5676 | 5589 |
| 5677 TestDelegate d; | 5590 TestDelegate d; |
| 5678 { | 5591 { |
| 5679 d.set_quit_on_redirect(true); | 5592 d.set_quit_on_redirect(true); |
| 5680 GURL test_url(test_server_.GetURL("files/redirect-test.html")); | 5593 GURL test_url(test_server_.GetURL("files/redirect-test.html")); |
| 5681 URLRequest req(test_url, DEFAULT_PRIORITY, &d, &default_context_); | 5594 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5595 test_url, DEFAULT_PRIORITY, &d, NULL)); |
| 5682 | 5596 |
| 5683 EXPECT_FALSE(d.have_full_request_headers()); | 5597 EXPECT_FALSE(d.have_full_request_headers()); |
| 5684 | 5598 |
| 5685 req.Start(); | 5599 req->Start(); |
| 5686 base::RunLoop().Run(); | 5600 base::RunLoop().Run(); |
| 5687 | 5601 |
| 5688 EXPECT_EQ(1, d.received_redirect_count()); | 5602 EXPECT_EQ(1, d.received_redirect_count()); |
| 5689 EXPECT_TRUE(d.have_full_request_headers()); | 5603 EXPECT_TRUE(d.have_full_request_headers()); |
| 5690 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 5604 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 5691 d.ClearFullRequestHeaders(); | 5605 d.ClearFullRequestHeaders(); |
| 5692 | 5606 |
| 5693 req.FollowDeferredRedirect(); | 5607 req->FollowDeferredRedirect(); |
| 5694 base::RunLoop().Run(); | 5608 base::RunLoop().Run(); |
| 5695 | 5609 |
| 5696 GURL target_url(test_server_.GetURL("files/with-headers.html")); | 5610 GURL target_url(test_server_.GetURL("files/with-headers.html")); |
| 5697 EXPECT_EQ(1, d.response_started_count()); | 5611 EXPECT_EQ(1, d.response_started_count()); |
| 5698 EXPECT_TRUE(d.have_full_request_headers()); | 5612 EXPECT_TRUE(d.have_full_request_headers()); |
| 5699 CheckFullRequestHeaders(d.full_request_headers(), target_url); | 5613 CheckFullRequestHeaders(d.full_request_headers(), target_url); |
| 5700 EXPECT_FALSE(d.received_data_before_response()); | 5614 EXPECT_FALSE(d.received_data_before_response()); |
| 5701 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 5615 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 5702 | 5616 |
| 5703 base::FilePath path; | 5617 base::FilePath path; |
| 5704 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5618 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 5705 path = path.Append(FILE_PATH_LITERAL("net")); | 5619 path = path.Append(FILE_PATH_LITERAL("net")); |
| 5706 path = path.Append(FILE_PATH_LITERAL("data")); | 5620 path = path.Append(FILE_PATH_LITERAL("data")); |
| 5707 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 5621 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 5708 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 5622 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 5709 | 5623 |
| 5710 std::string contents; | 5624 std::string contents; |
| 5711 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 5625 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 5712 EXPECT_EQ(contents, d.data_received()); | 5626 EXPECT_EQ(contents, d.data_received()); |
| 5713 } | 5627 } |
| 5714 } | 5628 } |
| 5715 | 5629 |
| 5716 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 5630 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 5717 ASSERT_TRUE(test_server_.Start()); | 5631 ASSERT_TRUE(test_server_.Start()); |
| 5718 | 5632 |
| 5719 TestDelegate d; | 5633 TestDelegate d; |
| 5720 { | 5634 { |
| 5721 d.set_quit_on_redirect(true); | 5635 d.set_quit_on_redirect(true); |
| 5722 URLRequest req(test_server_.GetURL("files/redirect-test.html"), | 5636 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5723 DEFAULT_PRIORITY, | 5637 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d, |
| 5724 &d, | 5638 NULL)); |
| 5725 &default_context_); | 5639 req->Start(); |
| 5726 req.Start(); | |
| 5727 base::RunLoop().Run(); | 5640 base::RunLoop().Run(); |
| 5728 | 5641 |
| 5729 EXPECT_EQ(1, d.received_redirect_count()); | 5642 EXPECT_EQ(1, d.received_redirect_count()); |
| 5730 | 5643 |
| 5731 req.Cancel(); | 5644 req->Cancel(); |
| 5732 base::RunLoop().Run(); | 5645 base::RunLoop().Run(); |
| 5733 | 5646 |
| 5734 EXPECT_EQ(1, d.response_started_count()); | 5647 EXPECT_EQ(1, d.response_started_count()); |
| 5735 EXPECT_EQ(0, d.bytes_received()); | 5648 EXPECT_EQ(0, d.bytes_received()); |
| 5736 EXPECT_FALSE(d.received_data_before_response()); | 5649 EXPECT_FALSE(d.received_data_before_response()); |
| 5737 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 5650 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 5738 } | 5651 } |
| 5739 } | 5652 } |
| 5740 | 5653 |
| 5741 TEST_F(URLRequestTestHTTP, VaryHeader) { | 5654 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 5742 ASSERT_TRUE(test_server_.Start()); | 5655 ASSERT_TRUE(test_server_.Start()); |
| 5743 | 5656 |
| 5744 // Populate the cache. | 5657 // Populate the cache. |
| 5745 { | 5658 { |
| 5746 TestDelegate d; | 5659 TestDelegate d; |
| 5747 URLRequest req(test_server_.GetURL("echoheadercache?foo"), | 5660 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5748 DEFAULT_PRIORITY, | 5661 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, |
| 5749 &d, | 5662 NULL)); |
| 5750 &default_context_); | |
| 5751 HttpRequestHeaders headers; | 5663 HttpRequestHeaders headers; |
| 5752 headers.SetHeader("foo", "1"); | 5664 headers.SetHeader("foo", "1"); |
| 5753 req.SetExtraRequestHeaders(headers); | 5665 req->SetExtraRequestHeaders(headers); |
| 5754 req.Start(); | 5666 req->Start(); |
| 5755 base::RunLoop().Run(); | 5667 base::RunLoop().Run(); |
| 5756 | 5668 |
| 5757 LoadTimingInfo load_timing_info; | 5669 LoadTimingInfo load_timing_info; |
| 5758 req.GetLoadTimingInfo(&load_timing_info); | 5670 req->GetLoadTimingInfo(&load_timing_info); |
| 5759 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5671 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5760 } | 5672 } |
| 5761 | 5673 |
| 5762 // Expect a cache hit. | 5674 // Expect a cache hit. |
| 5763 { | 5675 { |
| 5764 TestDelegate d; | 5676 TestDelegate d; |
| 5765 URLRequest req(test_server_.GetURL("echoheadercache?foo"), | 5677 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5766 DEFAULT_PRIORITY, | 5678 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, |
| 5767 &d, | 5679 NULL)); |
| 5768 &default_context_); | |
| 5769 HttpRequestHeaders headers; | 5680 HttpRequestHeaders headers; |
| 5770 headers.SetHeader("foo", "1"); | 5681 headers.SetHeader("foo", "1"); |
| 5771 req.SetExtraRequestHeaders(headers); | 5682 req->SetExtraRequestHeaders(headers); |
| 5772 req.Start(); | 5683 req->Start(); |
| 5773 base::RunLoop().Run(); | 5684 base::RunLoop().Run(); |
| 5774 | 5685 |
| 5775 EXPECT_TRUE(req.was_cached()); | 5686 EXPECT_TRUE(req->was_cached()); |
| 5776 | 5687 |
| 5777 LoadTimingInfo load_timing_info; | 5688 LoadTimingInfo load_timing_info; |
| 5778 req.GetLoadTimingInfo(&load_timing_info); | 5689 req->GetLoadTimingInfo(&load_timing_info); |
| 5779 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 5690 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 5780 } | 5691 } |
| 5781 | 5692 |
| 5782 // Expect a cache miss. | 5693 // Expect a cache miss. |
| 5783 { | 5694 { |
| 5784 TestDelegate d; | 5695 TestDelegate d; |
| 5785 URLRequest req(test_server_.GetURL("echoheadercache?foo"), | 5696 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5786 DEFAULT_PRIORITY, | 5697 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, |
| 5787 &d, | 5698 NULL)); |
| 5788 &default_context_); | |
| 5789 HttpRequestHeaders headers; | 5699 HttpRequestHeaders headers; |
| 5790 headers.SetHeader("foo", "2"); | 5700 headers.SetHeader("foo", "2"); |
| 5791 req.SetExtraRequestHeaders(headers); | 5701 req->SetExtraRequestHeaders(headers); |
| 5792 req.Start(); | 5702 req->Start(); |
| 5793 base::RunLoop().Run(); | 5703 base::RunLoop().Run(); |
| 5794 | 5704 |
| 5795 EXPECT_FALSE(req.was_cached()); | 5705 EXPECT_FALSE(req->was_cached()); |
| 5796 | 5706 |
| 5797 LoadTimingInfo load_timing_info; | 5707 LoadTimingInfo load_timing_info; |
| 5798 req.GetLoadTimingInfo(&load_timing_info); | 5708 req->GetLoadTimingInfo(&load_timing_info); |
| 5799 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5709 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5800 } | 5710 } |
| 5801 } | 5711 } |
| 5802 | 5712 |
| 5803 TEST_F(URLRequestTestHTTP, BasicAuth) { | 5713 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 5804 ASSERT_TRUE(test_server_.Start()); | 5714 ASSERT_TRUE(test_server_.Start()); |
| 5805 | 5715 |
| 5806 // populate the cache | 5716 // populate the cache |
| 5807 { | 5717 { |
| 5808 TestDelegate d; | 5718 TestDelegate d; |
| 5809 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5719 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5810 | 5720 |
| 5811 URLRequest r(test_server_.GetURL("auth-basic"), | 5721 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5812 DEFAULT_PRIORITY, | 5722 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); |
| 5813 &d, | 5723 r->Start(); |
| 5814 &default_context_); | |
| 5815 r.Start(); | |
| 5816 | 5724 |
| 5817 base::RunLoop().Run(); | 5725 base::RunLoop().Run(); |
| 5818 | 5726 |
| 5819 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5727 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5820 } | 5728 } |
| 5821 | 5729 |
| 5822 // repeat request with end-to-end validation. since auth-basic results in a | 5730 // repeat request with end-to-end validation. since auth-basic results in a |
| 5823 // cachable page, we expect this test to result in a 304. in which case, the | 5731 // cachable page, we expect this test to result in a 304. in which case, the |
| 5824 // response should be fetched from the cache. | 5732 // response should be fetched from the cache. |
| 5825 { | 5733 { |
| 5826 TestDelegate d; | 5734 TestDelegate d; |
| 5827 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5735 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5828 | 5736 |
| 5829 URLRequest r(test_server_.GetURL("auth-basic"), | 5737 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5830 DEFAULT_PRIORITY, | 5738 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); |
| 5831 &d, | 5739 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 5832 &default_context_); | 5740 r->Start(); |
| 5833 r.SetLoadFlags(LOAD_VALIDATE_CACHE); | |
| 5834 r.Start(); | |
| 5835 | 5741 |
| 5836 base::RunLoop().Run(); | 5742 base::RunLoop().Run(); |
| 5837 | 5743 |
| 5838 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5744 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5839 | 5745 |
| 5840 // Should be the same cached document. | 5746 // Should be the same cached document. |
| 5841 EXPECT_TRUE(r.was_cached()); | 5747 EXPECT_TRUE(r->was_cached()); |
| 5842 } | 5748 } |
| 5843 } | 5749 } |
| 5844 | 5750 |
| 5845 // Check that Set-Cookie headers in 401 responses are respected. | 5751 // Check that Set-Cookie headers in 401 responses are respected. |
| 5846 // http://crbug.com/6450 | 5752 // http://crbug.com/6450 |
| 5847 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 5753 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
| 5848 ASSERT_TRUE(test_server_.Start()); | 5754 ASSERT_TRUE(test_server_.Start()); |
| 5849 | 5755 |
| 5850 GURL url_requiring_auth = | 5756 GURL url_requiring_auth = |
| 5851 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 5757 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
| 5852 | 5758 |
| 5853 // Request a page that will give a 401 containing a Set-Cookie header. | 5759 // Request a page that will give a 401 containing a Set-Cookie header. |
| 5854 // Verify that when the transaction is restarted, it includes the new cookie. | 5760 // Verify that when the transaction is restarted, it includes the new cookie. |
| 5855 { | 5761 { |
| 5856 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 5762 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 5857 TestURLRequestContext context(true); | 5763 TestURLRequestContext context(true); |
| 5858 context.set_network_delegate(&network_delegate); | 5764 context.set_network_delegate(&network_delegate); |
| 5859 context.Init(); | 5765 context.Init(); |
| 5860 | 5766 |
| 5861 TestDelegate d; | 5767 TestDelegate d; |
| 5862 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5768 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5863 | 5769 |
| 5864 URLRequest r(url_requiring_auth, DEFAULT_PRIORITY, &d, &context); | 5770 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 5865 r.Start(); | 5771 url_requiring_auth, DEFAULT_PRIORITY, &d, NULL)); |
| 5772 r->Start(); |
| 5866 | 5773 |
| 5867 base::RunLoop().Run(); | 5774 base::RunLoop().Run(); |
| 5868 | 5775 |
| 5869 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5776 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5870 | 5777 |
| 5871 // Make sure we sent the cookie in the restarted transaction. | 5778 // Make sure we sent the cookie in the restarted transaction. |
| 5872 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5779 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 5873 != std::string::npos); | 5780 != std::string::npos); |
| 5874 } | 5781 } |
| 5875 | 5782 |
| 5876 // Same test as above, except this time the restart is initiated earlier | 5783 // Same test as above, except this time the restart is initiated earlier |
| 5877 // (without user intervention since identity is embedded in the URL). | 5784 // (without user intervention since identity is embedded in the URL). |
| 5878 { | 5785 { |
| 5879 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 5786 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 5880 TestURLRequestContext context(true); | 5787 TestURLRequestContext context(true); |
| 5881 context.set_network_delegate(&network_delegate); | 5788 context.set_network_delegate(&network_delegate); |
| 5882 context.Init(); | 5789 context.Init(); |
| 5883 | 5790 |
| 5884 TestDelegate d; | 5791 TestDelegate d; |
| 5885 | 5792 |
| 5886 GURL::Replacements replacements; | 5793 GURL::Replacements replacements; |
| 5887 std::string username("user2"); | 5794 std::string username("user2"); |
| 5888 std::string password("secret"); | 5795 std::string password("secret"); |
| 5889 replacements.SetUsernameStr(username); | 5796 replacements.SetUsernameStr(username); |
| 5890 replacements.SetPasswordStr(password); | 5797 replacements.SetPasswordStr(password); |
| 5891 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 5798 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
| 5892 | 5799 |
| 5893 URLRequest r(url_with_identity, DEFAULT_PRIORITY, &d, &context); | 5800 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 5894 r.Start(); | 5801 url_with_identity, DEFAULT_PRIORITY, &d, NULL)); |
| 5802 r->Start(); |
| 5895 | 5803 |
| 5896 base::RunLoop().Run(); | 5804 base::RunLoop().Run(); |
| 5897 | 5805 |
| 5898 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 5806 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 5899 | 5807 |
| 5900 // Make sure we sent the cookie in the restarted transaction. | 5808 // Make sure we sent the cookie in the restarted transaction. |
| 5901 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 5809 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 5902 != std::string::npos); | 5810 != std::string::npos); |
| 5903 } | 5811 } |
| 5904 } | 5812 } |
| 5905 | 5813 |
| 5906 // Tests that load timing works as expected with auth and the cache. | 5814 // Tests that load timing works as expected with auth and the cache. |
| 5907 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 5815 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
| 5908 ASSERT_TRUE(test_server_.Start()); | 5816 ASSERT_TRUE(test_server_.Start()); |
| 5909 | 5817 |
| 5910 // populate the cache | 5818 // populate the cache |
| 5911 { | 5819 { |
| 5912 TestDelegate d; | 5820 TestDelegate d; |
| 5913 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5821 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5914 | 5822 |
| 5915 URLRequest r(test_server_.GetURL("auth-basic"), | 5823 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5916 DEFAULT_PRIORITY, | 5824 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); |
| 5917 &d, | 5825 r->Start(); |
| 5918 &default_context_); | |
| 5919 r.Start(); | |
| 5920 | 5826 |
| 5921 base::RunLoop().Run(); | 5827 base::RunLoop().Run(); |
| 5922 | 5828 |
| 5923 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5829 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5924 | 5830 |
| 5925 LoadTimingInfo load_timing_info_before_auth; | 5831 LoadTimingInfo load_timing_info_before_auth; |
| 5926 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( | 5832 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( |
| 5927 &load_timing_info_before_auth)); | 5833 &load_timing_info_before_auth)); |
| 5928 TestLoadTimingNotReused(load_timing_info_before_auth, | 5834 TestLoadTimingNotReused(load_timing_info_before_auth, |
| 5929 CONNECT_TIMING_HAS_DNS_TIMES); | 5835 CONNECT_TIMING_HAS_DNS_TIMES); |
| 5930 | 5836 |
| 5931 LoadTimingInfo load_timing_info; | 5837 LoadTimingInfo load_timing_info; |
| 5932 r.GetLoadTimingInfo(&load_timing_info); | 5838 r->GetLoadTimingInfo(&load_timing_info); |
| 5933 // The test server does not support keep alive sockets, so the second | 5839 // The test server does not support keep alive sockets, so the second |
| 5934 // request with auth should use a new socket. | 5840 // request with auth should use a new socket. |
| 5935 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5841 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5936 EXPECT_NE(load_timing_info_before_auth.socket_log_id, | 5842 EXPECT_NE(load_timing_info_before_auth.socket_log_id, |
| 5937 load_timing_info.socket_log_id); | 5843 load_timing_info.socket_log_id); |
| 5938 EXPECT_LE(load_timing_info_before_auth.receive_headers_end, | 5844 EXPECT_LE(load_timing_info_before_auth.receive_headers_end, |
| 5939 load_timing_info.connect_timing.connect_start); | 5845 load_timing_info.connect_timing.connect_start); |
| 5940 } | 5846 } |
| 5941 | 5847 |
| 5942 // Repeat request with end-to-end validation. Since auth-basic results in a | 5848 // Repeat request with end-to-end validation. Since auth-basic results in a |
| 5943 // cachable page, we expect this test to result in a 304. In which case, the | 5849 // cachable page, we expect this test to result in a 304. In which case, the |
| 5944 // response should be fetched from the cache. | 5850 // response should be fetched from the cache. |
| 5945 { | 5851 { |
| 5946 TestDelegate d; | 5852 TestDelegate d; |
| 5947 d.set_credentials(AuthCredentials(kUser, kSecret)); | 5853 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 5948 | 5854 |
| 5949 URLRequest r(test_server_.GetURL("auth-basic"), | 5855 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5950 DEFAULT_PRIORITY, | 5856 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); |
| 5951 &d, | 5857 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 5952 &default_context_); | 5858 r->Start(); |
| 5953 r.SetLoadFlags(LOAD_VALIDATE_CACHE); | |
| 5954 r.Start(); | |
| 5955 | 5859 |
| 5956 base::RunLoop().Run(); | 5860 base::RunLoop().Run(); |
| 5957 | 5861 |
| 5958 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 5862 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 5959 | 5863 |
| 5960 // Should be the same cached document. | 5864 // Should be the same cached document. |
| 5961 EXPECT_TRUE(r.was_cached()); | 5865 EXPECT_TRUE(r->was_cached()); |
| 5962 | 5866 |
| 5963 // Since there was a request that went over the wire, the load timing | 5867 // Since there was a request that went over the wire, the load timing |
| 5964 // information should include connection times. | 5868 // information should include connection times. |
| 5965 LoadTimingInfo load_timing_info; | 5869 LoadTimingInfo load_timing_info; |
| 5966 r.GetLoadTimingInfo(&load_timing_info); | 5870 r->GetLoadTimingInfo(&load_timing_info); |
| 5967 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 5871 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 5968 } | 5872 } |
| 5969 } | 5873 } |
| 5970 | 5874 |
| 5971 // In this test, we do a POST which the server will 302 redirect. | 5875 // In this test, we do a POST which the server will 302 redirect. |
| 5972 // The subsequent transaction should use GET, and should not send the | 5876 // The subsequent transaction should use GET, and should not send the |
| 5973 // Content-Type header. | 5877 // Content-Type header. |
| 5974 // http://code.google.com/p/chromium/issues/detail?id=843 | 5878 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 5975 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 5879 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 5976 ASSERT_TRUE(test_server_.Start()); | 5880 ASSERT_TRUE(test_server_.Start()); |
| 5977 | 5881 |
| 5978 const char kData[] = "hello world"; | 5882 const char kData[] = "hello world"; |
| 5979 | 5883 |
| 5980 TestDelegate d; | 5884 TestDelegate d; |
| 5981 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), | 5885 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5982 DEFAULT_PRIORITY, | 5886 test_server_.GetURL("files/redirect-to-echoall"), DEFAULT_PRIORITY, &d, |
| 5983 &d, | 5887 NULL)); |
| 5984 &default_context_); | 5888 req->set_method("POST"); |
| 5985 req.set_method("POST"); | 5889 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 5986 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | |
| 5987 | 5890 |
| 5988 // Set headers (some of which are specific to the POST). | 5891 // Set headers (some of which are specific to the POST). |
| 5989 HttpRequestHeaders headers; | 5892 HttpRequestHeaders headers; |
| 5990 headers.AddHeadersFromString( | 5893 headers.AddHeadersFromString( |
| 5991 "Content-Type: multipart/form-data; " | 5894 "Content-Type: multipart/form-data; " |
| 5992 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 5895 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 5993 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 5896 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 5994 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 5897 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| 5995 "Accept-Language: en-US,en\r\n" | 5898 "Accept-Language: en-US,en\r\n" |
| 5996 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" | 5899 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" |
| 5997 "Content-Length: 11\r\n" | 5900 "Content-Length: 11\r\n" |
| 5998 "Origin: http://localhost:1337/"); | 5901 "Origin: http://localhost:1337/"); |
| 5999 req.SetExtraRequestHeaders(headers); | 5902 req->SetExtraRequestHeaders(headers); |
| 6000 req.Start(); | 5903 req->Start(); |
| 6001 base::RunLoop().Run(); | 5904 base::RunLoop().Run(); |
| 6002 | 5905 |
| 6003 std::string mime_type; | 5906 std::string mime_type; |
| 6004 req.GetMimeType(&mime_type); | 5907 req->GetMimeType(&mime_type); |
| 6005 EXPECT_EQ("text/html", mime_type); | 5908 EXPECT_EQ("text/html", mime_type); |
| 6006 | 5909 |
| 6007 const std::string& data = d.data_received(); | 5910 const std::string& data = d.data_received(); |
| 6008 | 5911 |
| 6009 // Check that the post-specific headers were stripped: | 5912 // Check that the post-specific headers were stripped: |
| 6010 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 5913 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
| 6011 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 5914 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
| 6012 EXPECT_FALSE(ContainsString(data, "Origin:")); | 5915 EXPECT_FALSE(ContainsString(data, "Origin:")); |
| 6013 | 5916 |
| 6014 // These extra request headers should not have been stripped. | 5917 // These extra request headers should not have been stripped. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6073 | 5976 |
| 6074 // Make sure that 308 responses without bodies are not treated as redirects. | 5977 // Make sure that 308 responses without bodies are not treated as redirects. |
| 6075 // Certain legacy apis that pre-date the response code expect this behavior | 5978 // Certain legacy apis that pre-date the response code expect this behavior |
| 6076 // (Like Google Drive). | 5979 // (Like Google Drive). |
| 6077 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { | 5980 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { |
| 6078 ASSERT_TRUE(test_server_.Start()); | 5981 ASSERT_TRUE(test_server_.Start()); |
| 6079 | 5982 |
| 6080 TestDelegate d; | 5983 TestDelegate d; |
| 6081 const GURL url = test_server_.GetURL("files/308-without-location-header"); | 5984 const GURL url = test_server_.GetURL("files/308-without-location-header"); |
| 6082 | 5985 |
| 6083 URLRequest request(url, DEFAULT_PRIORITY, &d, &default_context_); | 5986 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5987 url, DEFAULT_PRIORITY, &d, NULL)); |
| 6084 | 5988 |
| 6085 request.Start(); | 5989 request->Start(); |
| 6086 base::RunLoop().Run(); | 5990 base::RunLoop().Run(); |
| 6087 EXPECT_EQ(URLRequestStatus::SUCCESS, request.status().status()); | 5991 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); |
| 6088 EXPECT_EQ(OK, request.status().error()); | 5992 EXPECT_EQ(OK, request->status().error()); |
| 6089 EXPECT_EQ(0, d.received_redirect_count()); | 5993 EXPECT_EQ(0, d.received_redirect_count()); |
| 6090 EXPECT_EQ(308, request.response_headers()->response_code()); | 5994 EXPECT_EQ(308, request->response_headers()->response_code()); |
| 6091 EXPECT_EQ("This is not a redirect.", d.data_received()); | 5995 EXPECT_EQ("This is not a redirect.", d.data_received()); |
| 6092 } | 5996 } |
| 6093 | 5997 |
| 6094 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { | 5998 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { |
| 6095 ASSERT_TRUE(test_server_.Start()); | 5999 ASSERT_TRUE(test_server_.Start()); |
| 6096 | 6000 |
| 6097 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); | 6001 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); |
| 6098 GURL expected_url(test_server_.GetURL("echo#fragment")); | 6002 GURL expected_url(test_server_.GetURL("echo#fragment")); |
| 6099 | 6003 |
| 6100 TestDelegate d; | 6004 TestDelegate d; |
| 6101 { | 6005 { |
| 6102 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 6006 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6007 original_url, DEFAULT_PRIORITY, &d, NULL)); |
| 6103 | 6008 |
| 6104 r.Start(); | 6009 r->Start(); |
| 6105 base::RunLoop().Run(); | 6010 base::RunLoop().Run(); |
| 6106 | 6011 |
| 6107 EXPECT_EQ(2U, r.url_chain().size()); | 6012 EXPECT_EQ(2U, r->url_chain().size()); |
| 6108 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 6013 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
| 6109 EXPECT_EQ(net::OK, r.status().error()); | 6014 EXPECT_EQ(net::OK, r->status().error()); |
| 6110 EXPECT_EQ(original_url, r.original_url()); | 6015 EXPECT_EQ(original_url, r->original_url()); |
| 6111 EXPECT_EQ(expected_url, r.url()); | 6016 EXPECT_EQ(expected_url, r->url()); |
| 6112 } | 6017 } |
| 6113 } | 6018 } |
| 6114 | 6019 |
| 6115 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 6020 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 6116 ASSERT_TRUE(test_server_.Start()); | 6021 ASSERT_TRUE(test_server_.Start()); |
| 6117 | 6022 |
| 6118 const char kData[] = "hello world"; | 6023 const char kData[] = "hello world"; |
| 6119 | 6024 |
| 6120 TestDelegate d; | 6025 TestDelegate d; |
| 6121 URLRequest req(test_server_.GetURL("empty.html"), | 6026 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6122 DEFAULT_PRIORITY, | 6027 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); |
| 6123 &d, | 6028 req->set_method("POST"); |
| 6124 &default_context_); | 6029 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 6125 req.set_method("POST"); | |
| 6126 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | |
| 6127 HttpRequestHeaders headers; | 6030 HttpRequestHeaders headers; |
| 6128 headers.SetHeader(HttpRequestHeaders::kContentLength, | 6031 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 6129 base::UintToString(arraysize(kData) - 1)); | 6032 base::UintToString(arraysize(kData) - 1)); |
| 6130 req.SetExtraRequestHeaders(headers); | 6033 req->SetExtraRequestHeaders(headers); |
| 6131 | 6034 |
| 6132 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 6035 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 6133 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6036 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), |
| 6134 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 6037 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 6135 AddTestInterceptor()->set_main_intercept_job(job); | 6038 AddTestInterceptor()->set_main_intercept_job(job); |
| 6136 | 6039 |
| 6137 req.Start(); | 6040 req->Start(); |
| 6138 base::RunLoop().Run(); | 6041 base::RunLoop().Run(); |
| 6139 EXPECT_EQ("GET", req.method()); | 6042 EXPECT_EQ("GET", req->method()); |
| 6140 } | 6043 } |
| 6141 | 6044 |
| 6142 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 6045 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 6143 ASSERT_TRUE(test_server_.Start()); | 6046 ASSERT_TRUE(test_server_.Start()); |
| 6144 | 6047 |
| 6145 const char kData[] = "hello world"; | 6048 const char kData[] = "hello world"; |
| 6146 | 6049 |
| 6147 TestDelegate d; | 6050 TestDelegate d; |
| 6148 URLRequest req(test_server_.GetURL("empty.html"), | 6051 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6149 DEFAULT_PRIORITY, | 6052 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); |
| 6150 &d, | 6053 req->set_method("POST"); |
| 6151 &default_context_); | 6054 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 6152 req.set_method("POST"); | |
| 6153 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | |
| 6154 HttpRequestHeaders headers; | 6055 HttpRequestHeaders headers; |
| 6155 headers.SetHeader(HttpRequestHeaders::kContentLength, | 6056 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 6156 base::UintToString(arraysize(kData) - 1)); | 6057 base::UintToString(arraysize(kData) - 1)); |
| 6157 req.SetExtraRequestHeaders(headers); | 6058 req->SetExtraRequestHeaders(headers); |
| 6158 | 6059 |
| 6159 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 6060 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 6160 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6061 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), |
| 6161 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, | 6062 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
| 6162 "Very Good Reason"); | 6063 "Very Good Reason"); |
| 6163 AddTestInterceptor()->set_main_intercept_job(job); | 6064 AddTestInterceptor()->set_main_intercept_job(job); |
| 6164 | 6065 |
| 6165 req.Start(); | 6066 req->Start(); |
| 6166 base::RunLoop().Run(); | 6067 base::RunLoop().Run(); |
| 6167 EXPECT_EQ("POST", req.method()); | 6068 EXPECT_EQ("POST", req->method()); |
| 6168 EXPECT_EQ(kData, d.data_received()); | 6069 EXPECT_EQ(kData, d.data_received()); |
| 6169 } | 6070 } |
| 6170 | 6071 |
| 6171 // Check that default A-L header is sent. | 6072 // Check that default A-L header is sent. |
| 6172 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 6073 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 6173 ASSERT_TRUE(test_server_.Start()); | 6074 ASSERT_TRUE(test_server_.Start()); |
| 6174 | 6075 |
| 6175 StaticHttpUserAgentSettings settings("en", std::string()); | 6076 StaticHttpUserAgentSettings settings("en", std::string()); |
| 6176 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 6077 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 6177 TestURLRequestContext context(true); | 6078 TestURLRequestContext context(true); |
| 6178 context.set_network_delegate(&network_delegate); | 6079 context.set_network_delegate(&network_delegate); |
| 6179 context.set_http_user_agent_settings(&settings); | 6080 context.set_http_user_agent_settings(&settings); |
| 6180 context.Init(); | 6081 context.Init(); |
| 6181 | 6082 |
| 6182 TestDelegate d; | 6083 TestDelegate d; |
| 6183 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 6084 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6184 DEFAULT_PRIORITY, | 6085 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, |
| 6185 &d, | 6086 NULL)); |
| 6186 &context); | 6087 req->Start(); |
| 6187 req.Start(); | |
| 6188 base::RunLoop().Run(); | 6088 base::RunLoop().Run(); |
| 6189 EXPECT_EQ("en", d.data_received()); | 6089 EXPECT_EQ("en", d.data_received()); |
| 6190 } | 6090 } |
| 6191 | 6091 |
| 6192 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 6092 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 6193 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 6093 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 6194 ASSERT_TRUE(test_server_.Start()); | 6094 ASSERT_TRUE(test_server_.Start()); |
| 6195 | 6095 |
| 6196 std::string empty_string; // Avoid most vexing parse on line below. | 6096 std::string empty_string; // Avoid most vexing parse on line below. |
| 6197 StaticHttpUserAgentSettings settings(empty_string, empty_string); | 6097 StaticHttpUserAgentSettings settings(empty_string, empty_string); |
| 6198 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 6098 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 6199 TestURLRequestContext context(true); | 6099 TestURLRequestContext context(true); |
| 6200 context.set_network_delegate(&network_delegate); | 6100 context.set_network_delegate(&network_delegate); |
| 6201 context.Init(); | 6101 context.Init(); |
| 6202 // We override the language after initialization because empty entries | 6102 // We override the language after initialization because empty entries |
| 6203 // get overridden by Init(). | 6103 // get overridden by Init(). |
| 6204 context.set_http_user_agent_settings(&settings); | 6104 context.set_http_user_agent_settings(&settings); |
| 6205 | 6105 |
| 6206 TestDelegate d; | 6106 TestDelegate d; |
| 6207 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 6107 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6208 DEFAULT_PRIORITY, | 6108 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, |
| 6209 &d, | 6109 NULL)); |
| 6210 &context); | 6110 req->Start(); |
| 6211 req.Start(); | |
| 6212 base::RunLoop().Run(); | 6111 base::RunLoop().Run(); |
| 6213 EXPECT_EQ("None", d.data_received()); | 6112 EXPECT_EQ("None", d.data_received()); |
| 6214 } | 6113 } |
| 6215 | 6114 |
| 6216 // Check that if request overrides the A-L header, the default is not appended. | 6115 // Check that if request overrides the A-L header, the default is not appended. |
| 6217 // See http://crbug.com/20894 | 6116 // See http://crbug.com/20894 |
| 6218 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 6117 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 6219 ASSERT_TRUE(test_server_.Start()); | 6118 ASSERT_TRUE(test_server_.Start()); |
| 6220 | 6119 |
| 6221 TestDelegate d; | 6120 TestDelegate d; |
| 6222 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), | 6121 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6223 DEFAULT_PRIORITY, | 6122 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, |
| 6224 &d, | 6123 NULL)); |
| 6225 &default_context_); | |
| 6226 HttpRequestHeaders headers; | 6124 HttpRequestHeaders headers; |
| 6227 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 6125 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 6228 req.SetExtraRequestHeaders(headers); | 6126 req->SetExtraRequestHeaders(headers); |
| 6229 req.Start(); | 6127 req->Start(); |
| 6230 base::RunLoop().Run(); | 6128 base::RunLoop().Run(); |
| 6231 EXPECT_EQ(std::string("ru"), d.data_received()); | 6129 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 6232 } | 6130 } |
| 6233 | 6131 |
| 6234 // Check that default A-E header is sent. | 6132 // Check that default A-E header is sent. |
| 6235 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 6133 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
| 6236 ASSERT_TRUE(test_server_.Start()); | 6134 ASSERT_TRUE(test_server_.Start()); |
| 6237 | 6135 |
| 6238 TestDelegate d; | 6136 TestDelegate d; |
| 6239 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 6137 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6240 DEFAULT_PRIORITY, | 6138 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d, |
| 6241 &d, | 6139 NULL)); |
| 6242 &default_context_); | |
| 6243 HttpRequestHeaders headers; | 6140 HttpRequestHeaders headers; |
| 6244 req.SetExtraRequestHeaders(headers); | 6141 req->SetExtraRequestHeaders(headers); |
| 6245 req.Start(); | 6142 req->Start(); |
| 6246 base::RunLoop().Run(); | 6143 base::RunLoop().Run(); |
| 6247 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 6144 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
| 6248 } | 6145 } |
| 6249 | 6146 |
| 6250 // Check that if request overrides the A-E header, the default is not appended. | 6147 // Check that if request overrides the A-E header, the default is not appended. |
| 6251 // See http://crbug.com/47381 | 6148 // See http://crbug.com/47381 |
| 6252 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 6149 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
| 6253 ASSERT_TRUE(test_server_.Start()); | 6150 ASSERT_TRUE(test_server_.Start()); |
| 6254 | 6151 |
| 6255 TestDelegate d; | 6152 TestDelegate d; |
| 6256 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), | 6153 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6257 DEFAULT_PRIORITY, | 6154 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d, |
| 6258 &d, | 6155 NULL)); |
| 6259 &default_context_); | |
| 6260 HttpRequestHeaders headers; | 6156 HttpRequestHeaders headers; |
| 6261 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 6157 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
| 6262 req.SetExtraRequestHeaders(headers); | 6158 req->SetExtraRequestHeaders(headers); |
| 6263 req.Start(); | 6159 req->Start(); |
| 6264 base::RunLoop().Run(); | 6160 base::RunLoop().Run(); |
| 6265 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 6161 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 6266 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 6162 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 6267 } | 6163 } |
| 6268 | 6164 |
| 6269 // Check that setting the A-C header sends the proper header. | 6165 // Check that setting the A-C header sends the proper header. |
| 6270 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { | 6166 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { |
| 6271 ASSERT_TRUE(test_server_.Start()); | 6167 ASSERT_TRUE(test_server_.Start()); |
| 6272 | 6168 |
| 6273 TestDelegate d; | 6169 TestDelegate d; |
| 6274 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), | 6170 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6275 DEFAULT_PRIORITY, | 6171 test_server_.GetURL("echoheader?Accept-Charset"), DEFAULT_PRIORITY, &d, |
| 6276 &d, | 6172 NULL)); |
| 6277 &default_context_); | |
| 6278 HttpRequestHeaders headers; | 6173 HttpRequestHeaders headers; |
| 6279 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 6174 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 6280 req.SetExtraRequestHeaders(headers); | 6175 req->SetExtraRequestHeaders(headers); |
| 6281 req.Start(); | 6176 req->Start(); |
| 6282 base::RunLoop().Run(); | 6177 base::RunLoop().Run(); |
| 6283 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 6178 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 6284 } | 6179 } |
| 6285 | 6180 |
| 6286 // Check that default User-Agent header is sent. | 6181 // Check that default User-Agent header is sent. |
| 6287 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 6182 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 6288 ASSERT_TRUE(test_server_.Start()); | 6183 ASSERT_TRUE(test_server_.Start()); |
| 6289 | 6184 |
| 6290 TestDelegate d; | 6185 TestDelegate d; |
| 6291 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 6186 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6292 DEFAULT_PRIORITY, | 6187 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d, |
| 6293 &d, | 6188 NULL)); |
| 6294 &default_context_); | 6189 req->Start(); |
| 6295 req.Start(); | |
| 6296 base::RunLoop().Run(); | 6190 base::RunLoop().Run(); |
| 6297 EXPECT_EQ(req.context()->http_user_agent_settings()->GetUserAgent(), | 6191 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), |
| 6298 d.data_received()); | 6192 d.data_received()); |
| 6299 } | 6193 } |
| 6300 | 6194 |
| 6301 // Check that if request overrides the User-Agent header, | 6195 // Check that if request overrides the User-Agent header, |
| 6302 // the default is not appended. | 6196 // the default is not appended. |
| 6303 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 6197 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
| 6304 ASSERT_TRUE(test_server_.Start()); | 6198 ASSERT_TRUE(test_server_.Start()); |
| 6305 | 6199 |
| 6306 TestDelegate d; | 6200 TestDelegate d; |
| 6307 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), | 6201 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6308 DEFAULT_PRIORITY, | 6202 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d, |
| 6309 &d, | 6203 NULL)); |
| 6310 &default_context_); | |
| 6311 HttpRequestHeaders headers; | 6204 HttpRequestHeaders headers; |
| 6312 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 6205 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 6313 req.SetExtraRequestHeaders(headers); | 6206 req->SetExtraRequestHeaders(headers); |
| 6314 req.Start(); | 6207 req->Start(); |
| 6315 base::RunLoop().Run(); | 6208 base::RunLoop().Run(); |
| 6316 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); | 6209 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); |
| 6317 } | 6210 } |
| 6318 | 6211 |
| 6319 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | 6212 // Check that a NULL HttpUserAgentSettings causes the corresponding empty |
| 6320 // User-Agent header to be sent but does not send the Accept-Language and | 6213 // User-Agent header to be sent but does not send the Accept-Language and |
| 6321 // Accept-Charset headers. | 6214 // Accept-Charset headers. |
| 6322 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { | 6215 TEST_F(URLRequestTestHTTP, EmptyHttpUserAgentSettings) { |
| 6323 ASSERT_TRUE(test_server_.Start()); | 6216 ASSERT_TRUE(test_server_.Start()); |
| 6324 | 6217 |
| 6325 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 6218 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 6326 TestURLRequestContext context(true); | 6219 TestURLRequestContext context(true); |
| 6327 context.set_network_delegate(&network_delegate); | 6220 context.set_network_delegate(&network_delegate); |
| 6328 context.Init(); | 6221 context.Init(); |
| 6329 // We override the HttpUserAgentSettings after initialization because empty | 6222 // We override the HttpUserAgentSettings after initialization because empty |
| 6330 // entries get overridden by Init(). | 6223 // entries get overridden by Init(). |
| 6331 context.set_http_user_agent_settings(NULL); | 6224 context.set_http_user_agent_settings(NULL); |
| 6332 | 6225 |
| 6333 struct { | 6226 struct { |
| 6334 const char* request; | 6227 const char* request; |
| 6335 const char* expected_response; | 6228 const char* expected_response; |
| 6336 } tests[] = { { "echoheader?Accept-Language", "None" }, | 6229 } tests[] = { { "echoheader?Accept-Language", "None" }, |
| 6337 { "echoheader?Accept-Charset", "None" }, | 6230 { "echoheader?Accept-Charset", "None" }, |
| 6338 { "echoheader?User-Agent", "" } }; | 6231 { "echoheader?User-Agent", "" } }; |
| 6339 | 6232 |
| 6340 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 6233 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
| 6341 TestDelegate d; | 6234 TestDelegate d; |
| 6342 URLRequest req( | 6235 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6343 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, &context); | 6236 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, NULL)); |
| 6344 req.Start(); | 6237 req->Start(); |
| 6345 base::RunLoop().Run(); | 6238 base::RunLoop().Run(); |
| 6346 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 6239 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
| 6347 << " Request = \"" << tests[i].request << "\""; | 6240 << " Request = \"" << tests[i].request << "\""; |
| 6348 } | 6241 } |
| 6349 } | 6242 } |
| 6350 | 6243 |
| 6351 // Make sure that URLRequest passes on its priority updates to | 6244 // Make sure that URLRequest passes on its priority updates to |
| 6352 // newly-created jobs after the first one. | 6245 // newly-created jobs after the first one. |
| 6353 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 6246 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 6354 ASSERT_TRUE(test_server_.Start()); | 6247 ASSERT_TRUE(test_server_.Start()); |
| 6355 | 6248 |
| 6356 TestDelegate d; | 6249 TestDelegate d; |
| 6357 URLRequest req(test_server_.GetURL("empty.html"), | 6250 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6358 DEFAULT_PRIORITY, | 6251 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); |
| 6359 &d, | 6252 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 6360 &default_context_); | |
| 6361 EXPECT_EQ(DEFAULT_PRIORITY, req.priority()); | |
| 6362 | 6253 |
| 6363 scoped_refptr<URLRequestRedirectJob> redirect_job = | 6254 scoped_refptr<URLRequestRedirectJob> redirect_job = |
| 6364 new URLRequestRedirectJob( | 6255 new URLRequestRedirectJob( |
| 6365 &req, &default_network_delegate_, test_server_.GetURL("echo"), | 6256 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), |
| 6366 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); | 6257 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); |
| 6367 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); | 6258 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); |
| 6368 | 6259 |
| 6369 req.SetPriority(LOW); | 6260 req->SetPriority(LOW); |
| 6370 req.Start(); | 6261 req->Start(); |
| 6371 EXPECT_TRUE(req.is_pending()); | 6262 EXPECT_TRUE(req->is_pending()); |
| 6372 | 6263 |
| 6373 scoped_refptr<URLRequestTestJob> job = | 6264 scoped_refptr<URLRequestTestJob> job = |
| 6374 new URLRequestTestJob(&req, &default_network_delegate_); | 6265 new URLRequestTestJob(req.get(), &default_network_delegate_); |
| 6375 AddTestInterceptor()->set_main_intercept_job(job.get()); | 6266 AddTestInterceptor()->set_main_intercept_job(job.get()); |
| 6376 | 6267 |
| 6377 // Should trigger |job| to be started. | 6268 // Should trigger |job| to be started. |
| 6378 base::RunLoop().Run(); | 6269 base::RunLoop().Run(); |
| 6379 EXPECT_EQ(LOW, job->priority()); | 6270 EXPECT_EQ(LOW, job->priority()); |
| 6380 } | 6271 } |
| 6381 | 6272 |
| 6382 // Check that creating a network request while entering/exiting suspend mode | 6273 // Check that creating a network request while entering/exiting suspend mode |
| 6383 // fails as it should. This is the only case where an HttpTransactionFactory | 6274 // fails as it should. This is the only case where an HttpTransactionFactory |
| 6384 // does not return an HttpTransaction. | 6275 // does not return an HttpTransaction. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6399 network_layer->OnSuspend(); | 6290 network_layer->OnSuspend(); |
| 6400 | 6291 |
| 6401 HttpCache http_cache(network_layer.release(), default_context_.net_log(), | 6292 HttpCache http_cache(network_layer.release(), default_context_.net_log(), |
| 6402 HttpCache::DefaultBackend::InMemory(0)); | 6293 HttpCache::DefaultBackend::InMemory(0)); |
| 6403 | 6294 |
| 6404 TestURLRequestContext context(true); | 6295 TestURLRequestContext context(true); |
| 6405 context.set_http_transaction_factory(&http_cache); | 6296 context.set_http_transaction_factory(&http_cache); |
| 6406 context.Init(); | 6297 context.Init(); |
| 6407 | 6298 |
| 6408 TestDelegate d; | 6299 TestDelegate d; |
| 6409 URLRequest req(GURL("http://127.0.0.1/"), | 6300 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6410 DEFAULT_PRIORITY, | 6301 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL)); |
| 6411 &d, | 6302 req->Start(); |
| 6412 &context); | |
| 6413 req.Start(); | |
| 6414 base::RunLoop().Run(); | 6303 base::RunLoop().Run(); |
| 6415 | 6304 |
| 6416 EXPECT_TRUE(d.request_failed()); | 6305 EXPECT_TRUE(d.request_failed()); |
| 6417 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 6306 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6418 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); | 6307 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); |
| 6419 } | 6308 } |
| 6420 | 6309 |
| 6421 // Check that creating a network request while entering/exiting suspend mode | 6310 // Check that creating a network request while entering/exiting suspend mode |
| 6422 // fails as it should in the case there is no cache. This is the only case | 6311 // fails as it should in the case there is no cache. This is the only case |
| 6423 // where an HttpTransactionFactory does not return an HttpTransaction. | 6312 // where an HttpTransactionFactory does not return an HttpTransaction. |
| 6424 TEST_F(URLRequestTestHTTP, NetworkSuspendTestNoCache) { | 6313 TEST_F(URLRequestTestHTTP, NetworkSuspendTestNoCache) { |
| 6425 // Create a new HttpNetworkLayer that thinks it's suspended. | 6314 // Create a new HttpNetworkLayer that thinks it's suspended. |
| 6426 HttpNetworkSession::Params params; | 6315 HttpNetworkSession::Params params; |
| 6427 params.host_resolver = default_context_.host_resolver(); | 6316 params.host_resolver = default_context_.host_resolver(); |
| 6428 params.cert_verifier = default_context_.cert_verifier(); | 6317 params.cert_verifier = default_context_.cert_verifier(); |
| 6429 params.transport_security_state = default_context_.transport_security_state(); | 6318 params.transport_security_state = default_context_.transport_security_state(); |
| 6430 params.proxy_service = default_context_.proxy_service(); | 6319 params.proxy_service = default_context_.proxy_service(); |
| 6431 params.ssl_config_service = default_context_.ssl_config_service(); | 6320 params.ssl_config_service = default_context_.ssl_config_service(); |
| 6432 params.http_auth_handler_factory = | 6321 params.http_auth_handler_factory = |
| 6433 default_context_.http_auth_handler_factory(); | 6322 default_context_.http_auth_handler_factory(); |
| 6434 params.network_delegate = &default_network_delegate_; | 6323 params.network_delegate = &default_network_delegate_; |
| 6435 params.http_server_properties = default_context_.http_server_properties(); | 6324 params.http_server_properties = default_context_.http_server_properties(); |
| 6436 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); | 6325 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); |
| 6437 network_layer.OnSuspend(); | 6326 network_layer.OnSuspend(); |
| 6438 | 6327 |
| 6439 TestURLRequestContext context(true); | 6328 TestURLRequestContext context(true); |
| 6440 context.set_http_transaction_factory(&network_layer); | 6329 context.set_http_transaction_factory(&network_layer); |
| 6441 context.Init(); | 6330 context.Init(); |
| 6442 | 6331 |
| 6443 TestDelegate d; | 6332 TestDelegate d; |
| 6444 URLRequest req(GURL("http://127.0.0.1/"), | 6333 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6445 DEFAULT_PRIORITY, | 6334 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL)); |
| 6446 &d, | 6335 req->Start(); |
| 6447 &context); | |
| 6448 req.Start(); | |
| 6449 base::RunLoop().Run(); | 6336 base::RunLoop().Run(); |
| 6450 | 6337 |
| 6451 EXPECT_TRUE(d.request_failed()); | 6338 EXPECT_TRUE(d.request_failed()); |
| 6452 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 6339 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6453 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req.status().error()); | 6340 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); |
| 6454 } | 6341 } |
| 6455 | 6342 |
| 6456 class HTTPSRequestTest : public testing::Test { | 6343 class HTTPSRequestTest : public testing::Test { |
| 6457 public: | 6344 public: |
| 6458 HTTPSRequestTest() : default_context_(true) { | 6345 HTTPSRequestTest() : default_context_(true) { |
| 6459 default_context_.set_network_delegate(&default_network_delegate_); | 6346 default_context_.set_network_delegate(&default_network_delegate_); |
| 6460 default_context_.Init(); | 6347 default_context_.Init(); |
| 6461 } | 6348 } |
| 6462 virtual ~HTTPSRequestTest() {} | 6349 virtual ~HTTPSRequestTest() {} |
| 6463 | 6350 |
| 6464 protected: | 6351 protected: |
| 6465 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 6352 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 6466 TestURLRequestContext default_context_; | 6353 TestURLRequestContext default_context_; |
| 6467 }; | 6354 }; |
| 6468 | 6355 |
| 6469 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 6356 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 6470 SpawnedTestServer test_server( | 6357 SpawnedTestServer test_server( |
| 6471 SpawnedTestServer::TYPE_HTTPS, | 6358 SpawnedTestServer::TYPE_HTTPS, |
| 6472 SpawnedTestServer::kLocalhost, | 6359 SpawnedTestServer::kLocalhost, |
| 6473 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6360 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6474 ASSERT_TRUE(test_server.Start()); | 6361 ASSERT_TRUE(test_server.Start()); |
| 6475 | 6362 |
| 6476 TestDelegate d; | 6363 TestDelegate d; |
| 6477 { | 6364 { |
| 6478 URLRequest r(test_server.GetURL(std::string()), | 6365 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6479 DEFAULT_PRIORITY, | 6366 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 6480 &d, | 6367 r->Start(); |
| 6481 &default_context_); | 6368 EXPECT_TRUE(r->is_pending()); |
| 6482 r.Start(); | |
| 6483 EXPECT_TRUE(r.is_pending()); | |
| 6484 | 6369 |
| 6485 base::RunLoop().Run(); | 6370 base::RunLoop().Run(); |
| 6486 | 6371 |
| 6487 EXPECT_EQ(1, d.response_started_count()); | 6372 EXPECT_EQ(1, d.response_started_count()); |
| 6488 EXPECT_FALSE(d.received_data_before_response()); | 6373 EXPECT_FALSE(d.received_data_before_response()); |
| 6489 EXPECT_NE(0, d.bytes_received()); | 6374 EXPECT_NE(0, d.bytes_received()); |
| 6490 CheckSSLInfo(r.ssl_info()); | 6375 CheckSSLInfo(r->ssl_info()); |
| 6491 EXPECT_EQ(test_server.host_port_pair().host(), | 6376 EXPECT_EQ(test_server.host_port_pair().host(), |
| 6492 r.GetSocketAddress().host()); | 6377 r->GetSocketAddress().host()); |
| 6493 EXPECT_EQ(test_server.host_port_pair().port(), | 6378 EXPECT_EQ(test_server.host_port_pair().port(), |
| 6494 r.GetSocketAddress().port()); | 6379 r->GetSocketAddress().port()); |
| 6495 } | 6380 } |
| 6496 } | 6381 } |
| 6497 | 6382 |
| 6498 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 6383 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 6499 SpawnedTestServer::SSLOptions ssl_options( | 6384 SpawnedTestServer::SSLOptions ssl_options( |
| 6500 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); | 6385 SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME); |
| 6501 SpawnedTestServer test_server( | 6386 SpawnedTestServer test_server( |
| 6502 SpawnedTestServer::TYPE_HTTPS, | 6387 SpawnedTestServer::TYPE_HTTPS, |
| 6503 ssl_options, | 6388 ssl_options, |
| 6504 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6389 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6505 ASSERT_TRUE(test_server.Start()); | 6390 ASSERT_TRUE(test_server.Start()); |
| 6506 | 6391 |
| 6507 bool err_allowed = true; | 6392 bool err_allowed = true; |
| 6508 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6393 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 6509 TestDelegate d; | 6394 TestDelegate d; |
| 6510 { | 6395 { |
| 6511 d.set_allow_certificate_errors(err_allowed); | 6396 d.set_allow_certificate_errors(err_allowed); |
| 6512 URLRequest r(test_server.GetURL(std::string()), | 6397 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6513 DEFAULT_PRIORITY, | 6398 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 6514 &d, | |
| 6515 &default_context_); | |
| 6516 | 6399 |
| 6517 r.Start(); | 6400 r->Start(); |
| 6518 EXPECT_TRUE(r.is_pending()); | 6401 EXPECT_TRUE(r->is_pending()); |
| 6519 | 6402 |
| 6520 base::RunLoop().Run(); | 6403 base::RunLoop().Run(); |
| 6521 | 6404 |
| 6522 EXPECT_EQ(1, d.response_started_count()); | 6405 EXPECT_EQ(1, d.response_started_count()); |
| 6523 EXPECT_FALSE(d.received_data_before_response()); | 6406 EXPECT_FALSE(d.received_data_before_response()); |
| 6524 EXPECT_TRUE(d.have_certificate_errors()); | 6407 EXPECT_TRUE(d.have_certificate_errors()); |
| 6525 if (err_allowed) { | 6408 if (err_allowed) { |
| 6526 EXPECT_NE(0, d.bytes_received()); | 6409 EXPECT_NE(0, d.bytes_received()); |
| 6527 CheckSSLInfo(r.ssl_info()); | 6410 CheckSSLInfo(r->ssl_info()); |
| 6528 } else { | 6411 } else { |
| 6529 EXPECT_EQ(0, d.bytes_received()); | 6412 EXPECT_EQ(0, d.bytes_received()); |
| 6530 } | 6413 } |
| 6531 } | 6414 } |
| 6532 } | 6415 } |
| 6533 } | 6416 } |
| 6534 | 6417 |
| 6535 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { | 6418 TEST_F(HTTPSRequestTest, HTTPSExpiredTest) { |
| 6536 SpawnedTestServer::SSLOptions ssl_options( | 6419 SpawnedTestServer::SSLOptions ssl_options( |
| 6537 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 6420 SpawnedTestServer::SSLOptions::CERT_EXPIRED); |
| 6538 SpawnedTestServer test_server( | 6421 SpawnedTestServer test_server( |
| 6539 SpawnedTestServer::TYPE_HTTPS, | 6422 SpawnedTestServer::TYPE_HTTPS, |
| 6540 ssl_options, | 6423 ssl_options, |
| 6541 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6424 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6542 ASSERT_TRUE(test_server.Start()); | 6425 ASSERT_TRUE(test_server.Start()); |
| 6543 | 6426 |
| 6544 // Iterate from false to true, just so that we do the opposite of the | 6427 // Iterate from false to true, just so that we do the opposite of the |
| 6545 // previous test in order to increase test coverage. | 6428 // previous test in order to increase test coverage. |
| 6546 bool err_allowed = false; | 6429 bool err_allowed = false; |
| 6547 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 6430 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 6548 TestDelegate d; | 6431 TestDelegate d; |
| 6549 { | 6432 { |
| 6550 d.set_allow_certificate_errors(err_allowed); | 6433 d.set_allow_certificate_errors(err_allowed); |
| 6551 URLRequest r(test_server.GetURL(std::string()), | 6434 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6552 DEFAULT_PRIORITY, | 6435 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 6553 &d, | |
| 6554 &default_context_); | |
| 6555 | 6436 |
| 6556 r.Start(); | 6437 r->Start(); |
| 6557 EXPECT_TRUE(r.is_pending()); | 6438 EXPECT_TRUE(r->is_pending()); |
| 6558 | 6439 |
| 6559 base::RunLoop().Run(); | 6440 base::RunLoop().Run(); |
| 6560 | 6441 |
| 6561 EXPECT_EQ(1, d.response_started_count()); | 6442 EXPECT_EQ(1, d.response_started_count()); |
| 6562 EXPECT_FALSE(d.received_data_before_response()); | 6443 EXPECT_FALSE(d.received_data_before_response()); |
| 6563 EXPECT_TRUE(d.have_certificate_errors()); | 6444 EXPECT_TRUE(d.have_certificate_errors()); |
| 6564 if (err_allowed) { | 6445 if (err_allowed) { |
| 6565 EXPECT_NE(0, d.bytes_received()); | 6446 EXPECT_NE(0, d.bytes_received()); |
| 6566 CheckSSLInfo(r.ssl_info()); | 6447 CheckSSLInfo(r->ssl_info()); |
| 6567 } else { | 6448 } else { |
| 6568 EXPECT_EQ(0, d.bytes_received()); | 6449 EXPECT_EQ(0, d.bytes_received()); |
| 6569 } | 6450 } |
| 6570 } | 6451 } |
| 6571 } | 6452 } |
| 6572 } | 6453 } |
| 6573 | 6454 |
| 6574 // This tests that a load of www.google.com with a certificate error sets | 6455 // This tests that a load of www.google.com with a certificate error sets |
| 6575 // the |certificate_errors_are_fatal| flag correctly. This flag will cause | 6456 // the |certificate_errors_are_fatal| flag correctly. This flag will cause |
| 6576 // the interstitial to be fatal. | 6457 // the interstitial to be fatal. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6591 MockHostResolver host_resolver; | 6472 MockHostResolver host_resolver; |
| 6592 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 6473 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 6593 TestURLRequestContext context(true); | 6474 TestURLRequestContext context(true); |
| 6594 context.set_network_delegate(&network_delegate); | 6475 context.set_network_delegate(&network_delegate); |
| 6595 context.set_host_resolver(&host_resolver); | 6476 context.set_host_resolver(&host_resolver); |
| 6596 TransportSecurityState transport_security_state; | 6477 TransportSecurityState transport_security_state; |
| 6597 context.set_transport_security_state(&transport_security_state); | 6478 context.set_transport_security_state(&transport_security_state); |
| 6598 context.Init(); | 6479 context.Init(); |
| 6599 | 6480 |
| 6600 TestDelegate d; | 6481 TestDelegate d; |
| 6601 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 6482 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 6602 test_server.host_port_pair().port())), | 6483 GURL(base::StringPrintf("https://www.google.com:%d", |
| 6603 DEFAULT_PRIORITY, | 6484 test_server.host_port_pair().port())), |
| 6604 &d, | 6485 DEFAULT_PRIORITY, &d, NULL)); |
| 6605 &context); | |
| 6606 | 6486 |
| 6607 r.Start(); | 6487 r->Start(); |
| 6608 EXPECT_TRUE(r.is_pending()); | 6488 EXPECT_TRUE(r->is_pending()); |
| 6609 | 6489 |
| 6610 base::RunLoop().Run(); | 6490 base::RunLoop().Run(); |
| 6611 | 6491 |
| 6612 EXPECT_EQ(1, d.response_started_count()); | 6492 EXPECT_EQ(1, d.response_started_count()); |
| 6613 EXPECT_FALSE(d.received_data_before_response()); | 6493 EXPECT_FALSE(d.received_data_before_response()); |
| 6614 EXPECT_TRUE(d.have_certificate_errors()); | 6494 EXPECT_TRUE(d.have_certificate_errors()); |
| 6615 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 6495 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| 6616 } | 6496 } |
| 6617 | 6497 |
| 6618 // This tests that cached HTTPS page loads do not cause any updates to the | 6498 // This tests that cached HTTPS page loads do not cause any updates to the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6644 EXPECT_TRUE(transport_security_state.GetStaticDomainState( | 6524 EXPECT_TRUE(transport_security_state.GetStaticDomainState( |
| 6645 "www.google.com", true, &static_domain_state)); | 6525 "www.google.com", true, &static_domain_state)); |
| 6646 context.set_transport_security_state(&transport_security_state); | 6526 context.set_transport_security_state(&transport_security_state); |
| 6647 context.Init(); | 6527 context.Init(); |
| 6648 | 6528 |
| 6649 TransportSecurityState::DomainState dynamic_domain_state; | 6529 TransportSecurityState::DomainState dynamic_domain_state; |
| 6650 EXPECT_FALSE(transport_security_state.GetDynamicDomainState( | 6530 EXPECT_FALSE(transport_security_state.GetDynamicDomainState( |
| 6651 "www.google.com", &dynamic_domain_state)); | 6531 "www.google.com", &dynamic_domain_state)); |
| 6652 | 6532 |
| 6653 TestDelegate d; | 6533 TestDelegate d; |
| 6654 URLRequest r(GURL(base::StringPrintf("https://www.google.com:%d", | 6534 scoped_ptr<URLRequest> r(context.CreateRequest( |
| 6655 test_server.host_port_pair().port())), | 6535 GURL(base::StringPrintf("https://www.google.com:%d", |
| 6656 DEFAULT_PRIORITY, | 6536 test_server.host_port_pair().port())), |
| 6657 &d, | 6537 DEFAULT_PRIORITY, &d, NULL)); |
| 6658 &context); | |
| 6659 | 6538 |
| 6660 r.Start(); | 6539 r->Start(); |
| 6661 EXPECT_TRUE(r.is_pending()); | 6540 EXPECT_TRUE(r->is_pending()); |
| 6662 | 6541 |
| 6663 base::RunLoop().Run(); | 6542 base::RunLoop().Run(); |
| 6664 | 6543 |
| 6665 EXPECT_EQ(1, d.response_started_count()); | 6544 EXPECT_EQ(1, d.response_started_count()); |
| 6666 EXPECT_FALSE(d.received_data_before_response()); | 6545 EXPECT_FALSE(d.received_data_before_response()); |
| 6667 EXPECT_TRUE(d.have_certificate_errors()); | 6546 EXPECT_TRUE(d.have_certificate_errors()); |
| 6668 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 6547 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| 6669 | 6548 |
| 6670 // Get a fresh copy of the states, and check that they haven't changed. | 6549 // Get a fresh copy of the states, and check that they haven't changed. |
| 6671 TransportSecurityState::DomainState new_static_domain_state; | 6550 TransportSecurityState::DomainState new_static_domain_state; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6719 context.set_host_resolver(&host_resolver); | 6598 context.set_host_resolver(&host_resolver); |
| 6720 context.set_transport_security_state(&transport_security_state); | 6599 context.set_transport_security_state(&transport_security_state); |
| 6721 context.set_network_delegate(&network_delegate); | 6600 context.set_network_delegate(&network_delegate); |
| 6722 context.Init(); | 6601 context.Init(); |
| 6723 | 6602 |
| 6724 TestDelegate d; | 6603 TestDelegate d; |
| 6725 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will | 6604 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will |
| 6726 // cause a certificate error. Ignore the error. | 6605 // cause a certificate error. Ignore the error. |
| 6727 d.set_allow_certificate_errors(true); | 6606 d.set_allow_certificate_errors(true); |
| 6728 | 6607 |
| 6729 URLRequest req(GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", | 6608 scoped_ptr<URLRequest> req(context.CreateRequest( |
| 6730 test_server.host_port_pair().port())), | 6609 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", |
| 6731 DEFAULT_PRIORITY, | 6610 test_server.host_port_pair().port())), |
| 6732 &d, | 6611 DEFAULT_PRIORITY, &d, NULL)); |
| 6733 &context); | 6612 req->set_method("POST"); |
| 6734 req.set_method("POST"); | 6613 req->set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); |
| 6735 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData))); | |
| 6736 | 6614 |
| 6737 req.Start(); | 6615 req->Start(); |
| 6738 base::RunLoop().Run(); | 6616 base::RunLoop().Run(); |
| 6739 | 6617 |
| 6740 EXPECT_EQ("https", req.url().scheme()); | 6618 EXPECT_EQ("https", req->url().scheme()); |
| 6741 EXPECT_EQ("POST", req.method()); | 6619 EXPECT_EQ("POST", req->method()); |
| 6742 EXPECT_EQ(kData, d.data_received()); | 6620 EXPECT_EQ(kData, d.data_received()); |
| 6743 | 6621 |
| 6744 LoadTimingInfo load_timing_info; | 6622 LoadTimingInfo load_timing_info; |
| 6745 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); | 6623 network_delegate.GetLoadTimingInfoBeforeRedirect(&load_timing_info); |
| 6746 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits | 6624 // LoadTimingInfo of HSTS redirects is similar to that of network cache hits |
| 6747 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 6625 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 6748 } | 6626 } |
| 6749 | 6627 |
| 6750 namespace { | 6628 namespace { |
| 6751 | 6629 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 6777 SpawnedTestServer::SSLOptions ssl_options; | 6655 SpawnedTestServer::SSLOptions ssl_options; |
| 6778 ssl_options.request_client_certificate = true; | 6656 ssl_options.request_client_certificate = true; |
| 6779 SpawnedTestServer test_server( | 6657 SpawnedTestServer test_server( |
| 6780 SpawnedTestServer::TYPE_HTTPS, | 6658 SpawnedTestServer::TYPE_HTTPS, |
| 6781 ssl_options, | 6659 ssl_options, |
| 6782 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6660 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6783 ASSERT_TRUE(test_server.Start()); | 6661 ASSERT_TRUE(test_server.Start()); |
| 6784 | 6662 |
| 6785 SSLClientAuthTestDelegate d; | 6663 SSLClientAuthTestDelegate d; |
| 6786 { | 6664 { |
| 6787 URLRequest r(test_server.GetURL(std::string()), | 6665 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6788 DEFAULT_PRIORITY, | 6666 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 6789 &d, | |
| 6790 &default_context_); | |
| 6791 | 6667 |
| 6792 r.Start(); | 6668 r->Start(); |
| 6793 EXPECT_TRUE(r.is_pending()); | 6669 EXPECT_TRUE(r->is_pending()); |
| 6794 | 6670 |
| 6795 base::RunLoop().Run(); | 6671 base::RunLoop().Run(); |
| 6796 | 6672 |
| 6797 EXPECT_EQ(1, d.on_certificate_requested_count()); | 6673 EXPECT_EQ(1, d.on_certificate_requested_count()); |
| 6798 EXPECT_FALSE(d.received_data_before_response()); | 6674 EXPECT_FALSE(d.received_data_before_response()); |
| 6799 EXPECT_EQ(0, d.bytes_received()); | 6675 EXPECT_EQ(0, d.bytes_received()); |
| 6800 | 6676 |
| 6801 // Send no certificate. | 6677 // Send no certificate. |
| 6802 // TODO(davidben): Get temporary client cert import (with keys) working on | 6678 // TODO(davidben): Get temporary client cert import (with keys) working on |
| 6803 // all platforms so we can test sending a cert as well. | 6679 // all platforms so we can test sending a cert as well. |
| 6804 r.ContinueWithCertificate(NULL); | 6680 r->ContinueWithCertificate(NULL); |
| 6805 | 6681 |
| 6806 base::RunLoop().Run(); | 6682 base::RunLoop().Run(); |
| 6807 | 6683 |
| 6808 EXPECT_EQ(1, d.response_started_count()); | 6684 EXPECT_EQ(1, d.response_started_count()); |
| 6809 EXPECT_FALSE(d.received_data_before_response()); | 6685 EXPECT_FALSE(d.received_data_before_response()); |
| 6810 EXPECT_NE(0, d.bytes_received()); | 6686 EXPECT_NE(0, d.bytes_received()); |
| 6811 } | 6687 } |
| 6812 } | 6688 } |
| 6813 | 6689 |
| 6814 TEST_F(HTTPSRequestTest, ResumeTest) { | 6690 TEST_F(HTTPSRequestTest, ResumeTest) { |
| 6815 // Test that we attempt a session resume when making two connections to the | 6691 // Test that we attempt a session resume when making two connections to the |
| 6816 // same host. | 6692 // same host. |
| 6817 SpawnedTestServer::SSLOptions ssl_options; | 6693 SpawnedTestServer::SSLOptions ssl_options; |
| 6818 ssl_options.record_resume = true; | 6694 ssl_options.record_resume = true; |
| 6819 SpawnedTestServer test_server( | 6695 SpawnedTestServer test_server( |
| 6820 SpawnedTestServer::TYPE_HTTPS, | 6696 SpawnedTestServer::TYPE_HTTPS, |
| 6821 ssl_options, | 6697 ssl_options, |
| 6822 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6698 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6823 ASSERT_TRUE(test_server.Start()); | 6699 ASSERT_TRUE(test_server.Start()); |
| 6824 | 6700 |
| 6825 SSLClientSocket::ClearSessionCache(); | 6701 SSLClientSocket::ClearSessionCache(); |
| 6826 | 6702 |
| 6827 { | 6703 { |
| 6828 TestDelegate d; | 6704 TestDelegate d; |
| 6829 URLRequest r(test_server.GetURL("ssl-session-cache"), | 6705 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6830 DEFAULT_PRIORITY, | 6706 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 6831 &d, | |
| 6832 &default_context_); | |
| 6833 | 6707 |
| 6834 r.Start(); | 6708 r->Start(); |
| 6835 EXPECT_TRUE(r.is_pending()); | 6709 EXPECT_TRUE(r->is_pending()); |
| 6836 | 6710 |
| 6837 base::RunLoop().Run(); | 6711 base::RunLoop().Run(); |
| 6838 | 6712 |
| 6839 EXPECT_EQ(1, d.response_started_count()); | 6713 EXPECT_EQ(1, d.response_started_count()); |
| 6840 } | 6714 } |
| 6841 | 6715 |
| 6842 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 6716 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 6843 CloseAllConnections(); | 6717 CloseAllConnections(); |
| 6844 | 6718 |
| 6845 { | 6719 { |
| 6846 TestDelegate d; | 6720 TestDelegate d; |
| 6847 URLRequest r(test_server.GetURL("ssl-session-cache"), | 6721 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6848 DEFAULT_PRIORITY, | 6722 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 6849 &d, | |
| 6850 &default_context_); | |
| 6851 | 6723 |
| 6852 r.Start(); | 6724 r->Start(); |
| 6853 EXPECT_TRUE(r.is_pending()); | 6725 EXPECT_TRUE(r->is_pending()); |
| 6854 | 6726 |
| 6855 base::RunLoop().Run(); | 6727 base::RunLoop().Run(); |
| 6856 | 6728 |
| 6857 // The response will look like; | 6729 // The response will look like; |
| 6858 // insert abc | 6730 // insert abc |
| 6859 // lookup abc | 6731 // lookup abc |
| 6860 // insert xyz | 6732 // insert xyz |
| 6861 // | 6733 // |
| 6862 // With a newline at the end which makes the split think that there are | 6734 // With a newline at the end which makes the split think that there are |
| 6863 // four lines. | 6735 // four lines. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 6892 SpawnedTestServer test_server( | 6764 SpawnedTestServer test_server( |
| 6893 SpawnedTestServer::TYPE_HTTPS, | 6765 SpawnedTestServer::TYPE_HTTPS, |
| 6894 ssl_options, | 6766 ssl_options, |
| 6895 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6767 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6896 ASSERT_TRUE(test_server.Start()); | 6768 ASSERT_TRUE(test_server.Start()); |
| 6897 | 6769 |
| 6898 SSLClientSocket::ClearSessionCache(); | 6770 SSLClientSocket::ClearSessionCache(); |
| 6899 | 6771 |
| 6900 { | 6772 { |
| 6901 TestDelegate d; | 6773 TestDelegate d; |
| 6902 URLRequest r(test_server.GetURL("ssl-session-cache"), | 6774 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6903 DEFAULT_PRIORITY, | 6775 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 6904 &d, | |
| 6905 &default_context_); | |
| 6906 | 6776 |
| 6907 r.Start(); | 6777 r->Start(); |
| 6908 EXPECT_TRUE(r.is_pending()); | 6778 EXPECT_TRUE(r->is_pending()); |
| 6909 | 6779 |
| 6910 base::RunLoop().Run(); | 6780 base::RunLoop().Run(); |
| 6911 | 6781 |
| 6912 EXPECT_EQ(1, d.response_started_count()); | 6782 EXPECT_EQ(1, d.response_started_count()); |
| 6913 } | 6783 } |
| 6914 | 6784 |
| 6915 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 6785 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
| 6916 HttpNetworkSession::Params params; | 6786 HttpNetworkSession::Params params; |
| 6917 params.host_resolver = default_context_.host_resolver(); | 6787 params.host_resolver = default_context_.host_resolver(); |
| 6918 params.cert_verifier = default_context_.cert_verifier(); | 6788 params.cert_verifier = default_context_.cert_verifier(); |
| 6919 params.transport_security_state = default_context_.transport_security_state(); | 6789 params.transport_security_state = default_context_.transport_security_state(); |
| 6920 params.proxy_service = default_context_.proxy_service(); | 6790 params.proxy_service = default_context_.proxy_service(); |
| 6921 params.ssl_config_service = default_context_.ssl_config_service(); | 6791 params.ssl_config_service = default_context_.ssl_config_service(); |
| 6922 params.http_auth_handler_factory = | 6792 params.http_auth_handler_factory = |
| 6923 default_context_.http_auth_handler_factory(); | 6793 default_context_.http_auth_handler_factory(); |
| 6924 params.network_delegate = &default_network_delegate_; | 6794 params.network_delegate = &default_network_delegate_; |
| 6925 params.http_server_properties = default_context_.http_server_properties(); | 6795 params.http_server_properties = default_context_.http_server_properties(); |
| 6926 params.ssl_session_cache_shard = "alternate"; | 6796 params.ssl_session_cache_shard = "alternate"; |
| 6927 | 6797 |
| 6928 scoped_ptr<net::HttpCache> cache(new net::HttpCache( | 6798 scoped_ptr<net::HttpCache> cache(new net::HttpCache( |
| 6929 new net::HttpNetworkSession(params), | 6799 new net::HttpNetworkSession(params), |
| 6930 net::HttpCache::DefaultBackend::InMemory(0))); | 6800 net::HttpCache::DefaultBackend::InMemory(0))); |
| 6931 | 6801 |
| 6932 default_context_.set_http_transaction_factory(cache.get()); | 6802 default_context_.set_http_transaction_factory(cache.get()); |
| 6933 | 6803 |
| 6934 { | 6804 { |
| 6935 TestDelegate d; | 6805 TestDelegate d; |
| 6936 URLRequest r(test_server.GetURL("ssl-session-cache"), | 6806 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6937 DEFAULT_PRIORITY, | 6807 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 6938 &d, | |
| 6939 &default_context_); | |
| 6940 | 6808 |
| 6941 r.Start(); | 6809 r->Start(); |
| 6942 EXPECT_TRUE(r.is_pending()); | 6810 EXPECT_TRUE(r->is_pending()); |
| 6943 | 6811 |
| 6944 base::RunLoop().Run(); | 6812 base::RunLoop().Run(); |
| 6945 | 6813 |
| 6946 // The response will look like; | 6814 // The response will look like; |
| 6947 // insert abc | 6815 // insert abc |
| 6948 // insert xyz | 6816 // insert xyz |
| 6949 // | 6817 // |
| 6950 // With a newline at the end which makes the split think that there are | 6818 // With a newline at the end which makes the split think that there are |
| 6951 // three lines. | 6819 // three lines. |
| 6952 | 6820 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 6980 | 6848 |
| 6981 protected: | 6849 protected: |
| 6982 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) { | 6850 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) { |
| 6983 DCHECK(!request_); | 6851 DCHECK(!request_); |
| 6984 SpawnedTestServer test_server( | 6852 SpawnedTestServer test_server( |
| 6985 SpawnedTestServer::TYPE_HTTPS, | 6853 SpawnedTestServer::TYPE_HTTPS, |
| 6986 ssl_options, | 6854 ssl_options, |
| 6987 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 6855 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 6988 ASSERT_TRUE(test_server.Start()); | 6856 ASSERT_TRUE(test_server.Start()); |
| 6989 | 6857 |
| 6990 request_.reset(new URLRequest( | 6858 request_ = context_.CreateRequest( |
| 6991 test_server.GetURL(std::string()), DEFAULT_PRIORITY, | 6859 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate_, NULL); |
| 6992 &delegate_, &context_)); | |
| 6993 request_->Start(); | 6860 request_->Start(); |
| 6994 | 6861 |
| 6995 base::RunLoop().Run(); | 6862 base::RunLoop().Run(); |
| 6996 } | 6863 } |
| 6997 | 6864 |
| 6998 void ExpectConnection(int version) { | 6865 void ExpectConnection(int version) { |
| 6999 EXPECT_EQ(1, delegate_.response_started_count()); | 6866 EXPECT_EQ(1, delegate_.response_started_count()); |
| 7000 EXPECT_NE(0, delegate_.bytes_received()); | 6867 EXPECT_NE(0, delegate_.bytes_received()); |
| 7001 EXPECT_EQ(version, SSLConnectionStatusToVersion( | 6868 EXPECT_EQ(version, SSLConnectionStatusToVersion( |
| 7002 request_->ssl_info().connection_status)); | 6869 request_->ssl_info().connection_status)); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7165 ssl_options, | 7032 ssl_options, |
| 7166 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 7033 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7167 ASSERT_TRUE(test_server.Start()); | 7034 ASSERT_TRUE(test_server.Start()); |
| 7168 | 7035 |
| 7169 SSLClientSocket::ClearSessionCache(); | 7036 SSLClientSocket::ClearSessionCache(); |
| 7170 | 7037 |
| 7171 // Simulate the certificate being expired and attempt a connection. | 7038 // Simulate the certificate being expired and attempt a connection. |
| 7172 cert_verifier_.set_default_result(net::ERR_CERT_DATE_INVALID); | 7039 cert_verifier_.set_default_result(net::ERR_CERT_DATE_INVALID); |
| 7173 { | 7040 { |
| 7174 TestDelegate d; | 7041 TestDelegate d; |
| 7175 URLRequest r(test_server.GetURL("ssl-session-cache"), | 7042 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7176 DEFAULT_PRIORITY, | 7043 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 7177 &d, | |
| 7178 &default_context_); | |
| 7179 | 7044 |
| 7180 r.Start(); | 7045 r->Start(); |
| 7181 EXPECT_TRUE(r.is_pending()); | 7046 EXPECT_TRUE(r->is_pending()); |
| 7182 | 7047 |
| 7183 base::RunLoop().Run(); | 7048 base::RunLoop().Run(); |
| 7184 | 7049 |
| 7185 EXPECT_EQ(1, d.response_started_count()); | 7050 EXPECT_EQ(1, d.response_started_count()); |
| 7186 } | 7051 } |
| 7187 | 7052 |
| 7188 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 7053 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 7189 CloseAllConnections(); | 7054 CloseAllConnections(); |
| 7190 | 7055 |
| 7191 // Now change the certificate to be acceptable (so that the response is | 7056 // Now change the certificate to be acceptable (so that the response is |
| 7192 // loaded), and ensure that no session id is presented to the peer. | 7057 // loaded), and ensure that no session id is presented to the peer. |
| 7193 cert_verifier_.set_default_result(net::OK); | 7058 cert_verifier_.set_default_result(net::OK); |
| 7194 { | 7059 { |
| 7195 TestDelegate d; | 7060 TestDelegate d; |
| 7196 URLRequest r(test_server.GetURL("ssl-session-cache"), | 7061 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7197 DEFAULT_PRIORITY, | 7062 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); |
| 7198 &d, | |
| 7199 &default_context_); | |
| 7200 | 7063 |
| 7201 r.Start(); | 7064 r->Start(); |
| 7202 EXPECT_TRUE(r.is_pending()); | 7065 EXPECT_TRUE(r->is_pending()); |
| 7203 | 7066 |
| 7204 base::RunLoop().Run(); | 7067 base::RunLoop().Run(); |
| 7205 | 7068 |
| 7206 // The response will look like; | 7069 // The response will look like; |
| 7207 // insert abc | 7070 // insert abc |
| 7208 // insert xyz | 7071 // insert xyz |
| 7209 // | 7072 // |
| 7210 // With a newline at the end which makes the split think that there are | 7073 // With a newline at the end which makes the split think that there are |
| 7211 // three lines. | 7074 // three lines. |
| 7212 // | 7075 // |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7313 // We always overwrite out_cert_status. | 7176 // We always overwrite out_cert_status. |
| 7314 *out_cert_status = 0; | 7177 *out_cert_status = 0; |
| 7315 SpawnedTestServer test_server( | 7178 SpawnedTestServer test_server( |
| 7316 SpawnedTestServer::TYPE_HTTPS, | 7179 SpawnedTestServer::TYPE_HTTPS, |
| 7317 ssl_options, | 7180 ssl_options, |
| 7318 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 7181 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 7319 ASSERT_TRUE(test_server.Start()); | 7182 ASSERT_TRUE(test_server.Start()); |
| 7320 | 7183 |
| 7321 TestDelegate d; | 7184 TestDelegate d; |
| 7322 d.set_allow_certificate_errors(true); | 7185 d.set_allow_certificate_errors(true); |
| 7323 URLRequest r( | 7186 scoped_ptr<URLRequest> r(context_.CreateRequest( |
| 7324 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, &context_); | 7187 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 7325 r.Start(); | 7188 r->Start(); |
| 7326 | 7189 |
| 7327 base::RunLoop().Run(); | 7190 base::RunLoop().Run(); |
| 7328 | 7191 |
| 7329 EXPECT_EQ(1, d.response_started_count()); | 7192 EXPECT_EQ(1, d.response_started_count()); |
| 7330 *out_cert_status = r.ssl_info().cert_status; | 7193 *out_cert_status = r->ssl_info().cert_status; |
| 7331 } | 7194 } |
| 7332 | 7195 |
| 7333 virtual ~HTTPSOCSPTest() { | 7196 virtual ~HTTPSOCSPTest() { |
| 7334 #if defined(USE_NSS) || defined(OS_IOS) | 7197 #if defined(USE_NSS) || defined(OS_IOS) |
| 7335 ShutdownNSSHttpIO(); | 7198 ShutdownNSSHttpIO(); |
| 7336 #endif | 7199 #endif |
| 7337 } | 7200 } |
| 7338 | 7201 |
| 7339 protected: | 7202 protected: |
| 7340 // SetupContext configures the URLRequestContext that will be used for making | 7203 // SetupContext configures the URLRequestContext that will be used for making |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7769 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); | 7632 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); |
| 7770 | 7633 |
| 7771 GURL url("ftp://127.0.0.1:7"); | 7634 GURL url("ftp://127.0.0.1:7"); |
| 7772 job_factory.SetProtocolHandler( | 7635 job_factory.SetProtocolHandler( |
| 7773 "ftp", | 7636 "ftp", |
| 7774 new FtpProtocolHandler(&ftp_transaction_factory)); | 7637 new FtpProtocolHandler(&ftp_transaction_factory)); |
| 7775 default_context_.set_job_factory(&job_factory); | 7638 default_context_.set_job_factory(&job_factory); |
| 7776 | 7639 |
| 7777 TestDelegate d; | 7640 TestDelegate d; |
| 7778 { | 7641 { |
| 7779 URLRequest r(url, DEFAULT_PRIORITY, &d, &default_context_); | 7642 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7780 r.Start(); | 7643 url, DEFAULT_PRIORITY, &d, NULL)); |
| 7781 EXPECT_TRUE(r.is_pending()); | 7644 r->Start(); |
| 7645 EXPECT_TRUE(r->is_pending()); |
| 7782 | 7646 |
| 7783 base::RunLoop().Run(); | 7647 base::RunLoop().Run(); |
| 7784 | 7648 |
| 7785 EXPECT_FALSE(r.is_pending()); | 7649 EXPECT_FALSE(r->is_pending()); |
| 7786 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 7650 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 7787 EXPECT_EQ(ERR_UNSAFE_PORT, r.status().error()); | 7651 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); |
| 7788 } | 7652 } |
| 7789 } | 7653 } |
| 7790 | 7654 |
| 7791 // Flaky, see http://crbug.com/25045. | 7655 // Flaky, see http://crbug.com/25045. |
| 7792 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | 7656 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { |
| 7793 ASSERT_TRUE(test_server_.Start()); | 7657 ASSERT_TRUE(test_server_.Start()); |
| 7794 | 7658 |
| 7795 TestDelegate d; | 7659 TestDelegate d; |
| 7796 { | 7660 { |
| 7797 URLRequest r( | 7661 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7798 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, &default_context_); | 7662 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, NULL)); |
| 7799 r.Start(); | 7663 r->Start(); |
| 7800 EXPECT_TRUE(r.is_pending()); | 7664 EXPECT_TRUE(r->is_pending()); |
| 7801 | 7665 |
| 7802 base::RunLoop().Run(); | 7666 base::RunLoop().Run(); |
| 7803 | 7667 |
| 7804 EXPECT_FALSE(r.is_pending()); | 7668 EXPECT_FALSE(r->is_pending()); |
| 7805 EXPECT_EQ(1, d.response_started_count()); | 7669 EXPECT_EQ(1, d.response_started_count()); |
| 7806 EXPECT_FALSE(d.received_data_before_response()); | 7670 EXPECT_FALSE(d.received_data_before_response()); |
| 7807 EXPECT_LT(0, d.bytes_received()); | 7671 EXPECT_LT(0, d.bytes_received()); |
| 7808 EXPECT_EQ(test_server_.host_port_pair().host(), | 7672 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 7809 r.GetSocketAddress().host()); | 7673 r->GetSocketAddress().host()); |
| 7810 EXPECT_EQ(test_server_.host_port_pair().port(), | 7674 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 7811 r.GetSocketAddress().port()); | 7675 r->GetSocketAddress().port()); |
| 7812 } | 7676 } |
| 7813 } | 7677 } |
| 7814 | 7678 |
| 7815 // Flaky, see http://crbug.com/25045. | 7679 // Flaky, see http://crbug.com/25045. |
| 7816 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | 7680 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { |
| 7817 ASSERT_TRUE(test_server_.Start()); | 7681 ASSERT_TRUE(test_server_.Start()); |
| 7818 | 7682 |
| 7819 base::FilePath app_path; | 7683 base::FilePath app_path; |
| 7820 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7684 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7821 app_path = app_path.AppendASCII("LICENSE"); | 7685 app_path = app_path.AppendASCII("LICENSE"); |
| 7822 TestDelegate d; | 7686 TestDelegate d; |
| 7823 { | 7687 { |
| 7824 URLRequest r(test_server_.GetURL("/LICENSE"), | 7688 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7825 DEFAULT_PRIORITY, | 7689 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, &d, NULL)); |
| 7826 &d, | 7690 r->Start(); |
| 7827 &default_context_); | 7691 EXPECT_TRUE(r->is_pending()); |
| 7828 r.Start(); | |
| 7829 EXPECT_TRUE(r.is_pending()); | |
| 7830 | 7692 |
| 7831 base::RunLoop().Run(); | 7693 base::RunLoop().Run(); |
| 7832 | 7694 |
| 7833 int64 file_size = 0; | 7695 int64 file_size = 0; |
| 7834 base::GetFileSize(app_path, &file_size); | 7696 base::GetFileSize(app_path, &file_size); |
| 7835 | 7697 |
| 7836 EXPECT_FALSE(r.is_pending()); | 7698 EXPECT_FALSE(r->is_pending()); |
| 7837 EXPECT_EQ(1, d.response_started_count()); | 7699 EXPECT_EQ(1, d.response_started_count()); |
| 7838 EXPECT_FALSE(d.received_data_before_response()); | 7700 EXPECT_FALSE(d.received_data_before_response()); |
| 7839 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7701 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 7840 EXPECT_EQ(test_server_.host_port_pair().host(), | 7702 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 7841 r.GetSocketAddress().host()); | 7703 r->GetSocketAddress().host()); |
| 7842 EXPECT_EQ(test_server_.host_port_pair().port(), | 7704 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 7843 r.GetSocketAddress().port()); | 7705 r->GetSocketAddress().port()); |
| 7844 } | 7706 } |
| 7845 } | 7707 } |
| 7846 | 7708 |
| 7847 // Flaky, see http://crbug.com/25045. | 7709 // Flaky, see http://crbug.com/25045. |
| 7848 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { | 7710 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { |
| 7849 ASSERT_TRUE(test_server_.Start()); | 7711 ASSERT_TRUE(test_server_.Start()); |
| 7850 | 7712 |
| 7851 base::FilePath app_path; | 7713 base::FilePath app_path; |
| 7852 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7714 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7853 app_path = app_path.AppendASCII("LICENSE"); | 7715 app_path = app_path.AppendASCII("LICENSE"); |
| 7854 TestDelegate d; | 7716 TestDelegate d; |
| 7855 { | 7717 { |
| 7856 URLRequest r( | 7718 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7857 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 7719 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 7858 DEFAULT_PRIORITY, | 7720 DEFAULT_PRIORITY, &d, NULL)); |
| 7859 &d, | 7721 r->Start(); |
| 7860 &default_context_); | 7722 EXPECT_TRUE(r->is_pending()); |
| 7861 r.Start(); | |
| 7862 EXPECT_TRUE(r.is_pending()); | |
| 7863 | 7723 |
| 7864 base::RunLoop().Run(); | 7724 base::RunLoop().Run(); |
| 7865 | 7725 |
| 7866 int64 file_size = 0; | 7726 int64 file_size = 0; |
| 7867 base::GetFileSize(app_path, &file_size); | 7727 base::GetFileSize(app_path, &file_size); |
| 7868 | 7728 |
| 7869 EXPECT_FALSE(r.is_pending()); | 7729 EXPECT_FALSE(r->is_pending()); |
| 7870 EXPECT_EQ(test_server_.host_port_pair().host(), | 7730 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 7871 r.GetSocketAddress().host()); | 7731 r->GetSocketAddress().host()); |
| 7872 EXPECT_EQ(test_server_.host_port_pair().port(), | 7732 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 7873 r.GetSocketAddress().port()); | 7733 r->GetSocketAddress().port()); |
| 7874 EXPECT_EQ(1, d.response_started_count()); | 7734 EXPECT_EQ(1, d.response_started_count()); |
| 7875 EXPECT_FALSE(d.received_data_before_response()); | 7735 EXPECT_FALSE(d.received_data_before_response()); |
| 7876 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7736 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 7877 | 7737 |
| 7878 LoadTimingInfo load_timing_info; | 7738 LoadTimingInfo load_timing_info; |
| 7879 r.GetLoadTimingInfo(&load_timing_info); | 7739 r->GetLoadTimingInfo(&load_timing_info); |
| 7880 TestLoadTimingNoHttpResponse(load_timing_info); | 7740 TestLoadTimingNoHttpResponse(load_timing_info); |
| 7881 } | 7741 } |
| 7882 } | 7742 } |
| 7883 | 7743 |
| 7884 // Flaky, see http://crbug.com/25045. | 7744 // Flaky, see http://crbug.com/25045. |
| 7885 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { | 7745 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { |
| 7886 ASSERT_TRUE(test_server_.Start()); | 7746 ASSERT_TRUE(test_server_.Start()); |
| 7887 | 7747 |
| 7888 base::FilePath app_path; | 7748 base::FilePath app_path; |
| 7889 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7749 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7890 app_path = app_path.AppendASCII("LICENSE"); | 7750 app_path = app_path.AppendASCII("LICENSE"); |
| 7891 TestDelegate d; | 7751 TestDelegate d; |
| 7892 { | 7752 { |
| 7893 URLRequest r(test_server_.GetURLWithUserAndPassword( | 7753 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7894 "/LICENSE", "chrome", "wrong_password"), | 7754 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", |
| 7895 DEFAULT_PRIORITY, | 7755 "wrong_password"), |
| 7896 &d, | 7756 DEFAULT_PRIORITY, &d, NULL)); |
| 7897 &default_context_); | 7757 r->Start(); |
| 7898 r.Start(); | 7758 EXPECT_TRUE(r->is_pending()); |
| 7899 EXPECT_TRUE(r.is_pending()); | |
| 7900 | 7759 |
| 7901 base::RunLoop().Run(); | 7760 base::RunLoop().Run(); |
| 7902 | 7761 |
| 7903 int64 file_size = 0; | 7762 int64 file_size = 0; |
| 7904 base::GetFileSize(app_path, &file_size); | 7763 base::GetFileSize(app_path, &file_size); |
| 7905 | 7764 |
| 7906 EXPECT_FALSE(r.is_pending()); | 7765 EXPECT_FALSE(r->is_pending()); |
| 7907 EXPECT_EQ(1, d.response_started_count()); | 7766 EXPECT_EQ(1, d.response_started_count()); |
| 7908 EXPECT_FALSE(d.received_data_before_response()); | 7767 EXPECT_FALSE(d.received_data_before_response()); |
| 7909 EXPECT_EQ(d.bytes_received(), 0); | 7768 EXPECT_EQ(d.bytes_received(), 0); |
| 7910 } | 7769 } |
| 7911 } | 7770 } |
| 7912 | 7771 |
| 7913 // Flaky, see http://crbug.com/25045. | 7772 // Flaky, see http://crbug.com/25045. |
| 7914 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { | 7773 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { |
| 7915 ASSERT_TRUE(test_server_.Start()); | 7774 ASSERT_TRUE(test_server_.Start()); |
| 7916 | 7775 |
| 7917 base::FilePath app_path; | 7776 base::FilePath app_path; |
| 7918 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7777 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7919 app_path = app_path.AppendASCII("LICENSE"); | 7778 app_path = app_path.AppendASCII("LICENSE"); |
| 7920 TestDelegate d; | 7779 TestDelegate d; |
| 7921 // Set correct login credentials. The delegate will be asked for them when | 7780 // Set correct login credentials. The delegate will be asked for them when |
| 7922 // the initial login with wrong credentials will fail. | 7781 // the initial login with wrong credentials will fail. |
| 7923 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 7782 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 7924 { | 7783 { |
| 7925 URLRequest r(test_server_.GetURLWithUserAndPassword( | 7784 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7926 "/LICENSE", "chrome", "wrong_password"), | 7785 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", |
| 7927 DEFAULT_PRIORITY, | 7786 "wrong_password"), |
| 7928 &d, | 7787 DEFAULT_PRIORITY, &d, NULL)); |
| 7929 &default_context_); | 7788 r->Start(); |
| 7930 r.Start(); | 7789 EXPECT_TRUE(r->is_pending()); |
| 7931 EXPECT_TRUE(r.is_pending()); | |
| 7932 | 7790 |
| 7933 base::RunLoop().Run(); | 7791 base::RunLoop().Run(); |
| 7934 | 7792 |
| 7935 int64 file_size = 0; | 7793 int64 file_size = 0; |
| 7936 base::GetFileSize(app_path, &file_size); | 7794 base::GetFileSize(app_path, &file_size); |
| 7937 | 7795 |
| 7938 EXPECT_FALSE(r.is_pending()); | 7796 EXPECT_FALSE(r->is_pending()); |
| 7939 EXPECT_EQ(1, d.response_started_count()); | 7797 EXPECT_EQ(1, d.response_started_count()); |
| 7940 EXPECT_FALSE(d.received_data_before_response()); | 7798 EXPECT_FALSE(d.received_data_before_response()); |
| 7941 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7799 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 7942 } | 7800 } |
| 7943 } | 7801 } |
| 7944 | 7802 |
| 7945 // Flaky, see http://crbug.com/25045. | 7803 // Flaky, see http://crbug.com/25045. |
| 7946 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | 7804 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { |
| 7947 ASSERT_TRUE(test_server_.Start()); | 7805 ASSERT_TRUE(test_server_.Start()); |
| 7948 | 7806 |
| 7949 base::FilePath app_path; | 7807 base::FilePath app_path; |
| 7950 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7808 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7951 app_path = app_path.AppendASCII("LICENSE"); | 7809 app_path = app_path.AppendASCII("LICENSE"); |
| 7952 TestDelegate d; | 7810 TestDelegate d; |
| 7953 { | 7811 { |
| 7954 URLRequest r(test_server_.GetURLWithUserAndPassword( | 7812 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7955 "/LICENSE", "wrong_user", "chrome"), | 7813 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", |
| 7956 DEFAULT_PRIORITY, | 7814 "chrome"), |
| 7957 &d, | 7815 DEFAULT_PRIORITY, &d, NULL)); |
| 7958 &default_context_); | 7816 r->Start(); |
| 7959 r.Start(); | 7817 EXPECT_TRUE(r->is_pending()); |
| 7960 EXPECT_TRUE(r.is_pending()); | |
| 7961 | 7818 |
| 7962 base::RunLoop().Run(); | 7819 base::RunLoop().Run(); |
| 7963 | 7820 |
| 7964 int64 file_size = 0; | 7821 int64 file_size = 0; |
| 7965 base::GetFileSize(app_path, &file_size); | 7822 base::GetFileSize(app_path, &file_size); |
| 7966 | 7823 |
| 7967 EXPECT_FALSE(r.is_pending()); | 7824 EXPECT_FALSE(r->is_pending()); |
| 7968 EXPECT_EQ(1, d.response_started_count()); | 7825 EXPECT_EQ(1, d.response_started_count()); |
| 7969 EXPECT_FALSE(d.received_data_before_response()); | 7826 EXPECT_FALSE(d.received_data_before_response()); |
| 7970 EXPECT_EQ(d.bytes_received(), 0); | 7827 EXPECT_EQ(d.bytes_received(), 0); |
| 7971 } | 7828 } |
| 7972 } | 7829 } |
| 7973 | 7830 |
| 7974 // Flaky, see http://crbug.com/25045. | 7831 // Flaky, see http://crbug.com/25045. |
| 7975 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { | 7832 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { |
| 7976 ASSERT_TRUE(test_server_.Start()); | 7833 ASSERT_TRUE(test_server_.Start()); |
| 7977 | 7834 |
| 7978 base::FilePath app_path; | 7835 base::FilePath app_path; |
| 7979 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7836 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 7980 app_path = app_path.AppendASCII("LICENSE"); | 7837 app_path = app_path.AppendASCII("LICENSE"); |
| 7981 TestDelegate d; | 7838 TestDelegate d; |
| 7982 // Set correct login credentials. The delegate will be asked for them when | 7839 // Set correct login credentials. The delegate will be asked for them when |
| 7983 // the initial login with wrong credentials will fail. | 7840 // the initial login with wrong credentials will fail. |
| 7984 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 7841 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 7985 { | 7842 { |
| 7986 URLRequest r(test_server_.GetURLWithUserAndPassword( | 7843 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7987 "/LICENSE", "wrong_user", "chrome"), | 7844 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", |
| 7988 DEFAULT_PRIORITY, | 7845 "chrome"), |
| 7989 &d, | 7846 DEFAULT_PRIORITY, &d, NULL)); |
| 7990 &default_context_); | 7847 r->Start(); |
| 7991 r.Start(); | 7848 EXPECT_TRUE(r->is_pending()); |
| 7992 EXPECT_TRUE(r.is_pending()); | |
| 7993 | 7849 |
| 7994 base::RunLoop().Run(); | 7850 base::RunLoop().Run(); |
| 7995 | 7851 |
| 7996 int64 file_size = 0; | 7852 int64 file_size = 0; |
| 7997 base::GetFileSize(app_path, &file_size); | 7853 base::GetFileSize(app_path, &file_size); |
| 7998 | 7854 |
| 7999 EXPECT_FALSE(r.is_pending()); | 7855 EXPECT_FALSE(r->is_pending()); |
| 8000 EXPECT_EQ(1, d.response_started_count()); | 7856 EXPECT_EQ(1, d.response_started_count()); |
| 8001 EXPECT_FALSE(d.received_data_before_response()); | 7857 EXPECT_FALSE(d.received_data_before_response()); |
| 8002 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 7858 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 8003 } | 7859 } |
| 8004 } | 7860 } |
| 8005 | 7861 |
| 8006 // Flaky, see http://crbug.com/25045. | 7862 // Flaky, see http://crbug.com/25045. |
| 8007 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { | 7863 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { |
| 8008 ASSERT_TRUE(test_server_.Start()); | 7864 ASSERT_TRUE(test_server_.Start()); |
| 8009 | 7865 |
| 8010 base::FilePath app_path; | 7866 base::FilePath app_path; |
| 8011 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7867 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 8012 app_path = app_path.AppendASCII("LICENSE"); | 7868 app_path = app_path.AppendASCII("LICENSE"); |
| 8013 | 7869 |
| 8014 scoped_ptr<TestDelegate> d(new TestDelegate); | 7870 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 8015 { | 7871 { |
| 8016 // Pass correct login identity in the URL. | 7872 // Pass correct login identity in the URL. |
| 8017 URLRequest r( | 7873 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8018 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 7874 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 8019 DEFAULT_PRIORITY, | 7875 DEFAULT_PRIORITY, d.get(), NULL)); |
| 8020 d.get(), | 7876 r->Start(); |
| 8021 &default_context_); | 7877 EXPECT_TRUE(r->is_pending()); |
| 8022 r.Start(); | |
| 8023 EXPECT_TRUE(r.is_pending()); | |
| 8024 | 7878 |
| 8025 base::RunLoop().Run(); | 7879 base::RunLoop().Run(); |
| 8026 | 7880 |
| 8027 int64 file_size = 0; | 7881 int64 file_size = 0; |
| 8028 base::GetFileSize(app_path, &file_size); | 7882 base::GetFileSize(app_path, &file_size); |
| 8029 | 7883 |
| 8030 EXPECT_FALSE(r.is_pending()); | 7884 EXPECT_FALSE(r->is_pending()); |
| 8031 EXPECT_EQ(1, d->response_started_count()); | 7885 EXPECT_EQ(1, d->response_started_count()); |
| 8032 EXPECT_FALSE(d->received_data_before_response()); | 7886 EXPECT_FALSE(d->received_data_before_response()); |
| 8033 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7887 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8034 } | 7888 } |
| 8035 | 7889 |
| 8036 d.reset(new TestDelegate); | 7890 d.reset(new TestDelegate); |
| 8037 { | 7891 { |
| 8038 // This request should use cached identity from previous request. | 7892 // This request should use cached identity from previous request. |
| 8039 URLRequest r(test_server_.GetURL("/LICENSE"), | 7893 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8040 DEFAULT_PRIORITY, | 7894 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL)); |
| 8041 d.get(), | 7895 r->Start(); |
| 8042 &default_context_); | 7896 EXPECT_TRUE(r->is_pending()); |
| 8043 r.Start(); | |
| 8044 EXPECT_TRUE(r.is_pending()); | |
| 8045 | 7897 |
| 8046 base::RunLoop().Run(); | 7898 base::RunLoop().Run(); |
| 8047 | 7899 |
| 8048 int64 file_size = 0; | 7900 int64 file_size = 0; |
| 8049 base::GetFileSize(app_path, &file_size); | 7901 base::GetFileSize(app_path, &file_size); |
| 8050 | 7902 |
| 8051 EXPECT_FALSE(r.is_pending()); | 7903 EXPECT_FALSE(r->is_pending()); |
| 8052 EXPECT_EQ(1, d->response_started_count()); | 7904 EXPECT_EQ(1, d->response_started_count()); |
| 8053 EXPECT_FALSE(d->received_data_before_response()); | 7905 EXPECT_FALSE(d->received_data_before_response()); |
| 8054 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7906 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8055 } | 7907 } |
| 8056 } | 7908 } |
| 8057 | 7909 |
| 8058 // Flaky, see http://crbug.com/25045. | 7910 // Flaky, see http://crbug.com/25045. |
| 8059 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { | 7911 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { |
| 8060 ASSERT_TRUE(test_server_.Start()); | 7912 ASSERT_TRUE(test_server_.Start()); |
| 8061 | 7913 |
| 8062 base::FilePath app_path; | 7914 base::FilePath app_path; |
| 8063 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 7915 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 8064 app_path = app_path.AppendASCII("LICENSE"); | 7916 app_path = app_path.AppendASCII("LICENSE"); |
| 8065 | 7917 |
| 8066 scoped_ptr<TestDelegate> d(new TestDelegate); | 7918 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 8067 // Set correct login credentials. The delegate will be asked for them when | 7919 // Set correct login credentials. The delegate will be asked for them when |
| 8068 // the initial login with wrong credentials will fail. | 7920 // the initial login with wrong credentials will fail. |
| 8069 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 7921 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 8070 { | 7922 { |
| 8071 URLRequest r(test_server_.GetURLWithUserAndPassword( | 7923 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8072 "/LICENSE", "chrome", "wrong_password"), | 7924 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", |
| 8073 DEFAULT_PRIORITY, | 7925 "wrong_password"), |
| 8074 d.get(), | 7926 DEFAULT_PRIORITY, d.get(), NULL)); |
| 8075 &default_context_); | 7927 r->Start(); |
| 8076 r.Start(); | 7928 EXPECT_TRUE(r->is_pending()); |
| 8077 EXPECT_TRUE(r.is_pending()); | |
| 8078 | 7929 |
| 8079 base::RunLoop().Run(); | 7930 base::RunLoop().Run(); |
| 8080 | 7931 |
| 8081 int64 file_size = 0; | 7932 int64 file_size = 0; |
| 8082 base::GetFileSize(app_path, &file_size); | 7933 base::GetFileSize(app_path, &file_size); |
| 8083 | 7934 |
| 8084 EXPECT_FALSE(r.is_pending()); | 7935 EXPECT_FALSE(r->is_pending()); |
| 8085 EXPECT_EQ(1, d->response_started_count()); | 7936 EXPECT_EQ(1, d->response_started_count()); |
| 8086 EXPECT_FALSE(d->received_data_before_response()); | 7937 EXPECT_FALSE(d->received_data_before_response()); |
| 8087 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7938 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8088 } | 7939 } |
| 8089 | 7940 |
| 8090 // Use a new delegate without explicit credentials. The cached ones should be | 7941 // Use a new delegate without explicit credentials. The cached ones should be |
| 8091 // used. | 7942 // used. |
| 8092 d.reset(new TestDelegate); | 7943 d.reset(new TestDelegate); |
| 8093 { | 7944 { |
| 8094 // Don't pass wrong credentials in the URL, they would override valid cached | 7945 // Don't pass wrong credentials in the URL, they would override valid cached |
| 8095 // ones. | 7946 // ones. |
| 8096 URLRequest r(test_server_.GetURL("/LICENSE"), | 7947 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8097 DEFAULT_PRIORITY, | 7948 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL)); |
| 8098 d.get(), | 7949 r->Start(); |
| 8099 &default_context_); | 7950 EXPECT_TRUE(r->is_pending()); |
| 8100 r.Start(); | |
| 8101 EXPECT_TRUE(r.is_pending()); | |
| 8102 | 7951 |
| 8103 base::RunLoop().Run(); | 7952 base::RunLoop().Run(); |
| 8104 | 7953 |
| 8105 int64 file_size = 0; | 7954 int64 file_size = 0; |
| 8106 base::GetFileSize(app_path, &file_size); | 7955 base::GetFileSize(app_path, &file_size); |
| 8107 | 7956 |
| 8108 EXPECT_FALSE(r.is_pending()); | 7957 EXPECT_FALSE(r->is_pending()); |
| 8109 EXPECT_EQ(1, d->response_started_count()); | 7958 EXPECT_EQ(1, d->response_started_count()); |
| 8110 EXPECT_FALSE(d->received_data_before_response()); | 7959 EXPECT_FALSE(d->received_data_before_response()); |
| 8111 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7960 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8112 } | 7961 } |
| 8113 } | 7962 } |
| 8114 #endif // !defined(DISABLE_FTP_SUPPORT) | 7963 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 8115 | 7964 |
| 8116 } // namespace net | 7965 } // namespace net |
| OLD | NEW |