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 3895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3906 << " Parameter = \"" << test_file << "\""; | 3906 << " Parameter = \"" << test_file << "\""; |
3907 } else { | 3907 } else { |
3908 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3908 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
3909 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) | 3909 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
3910 << " Parameter = \"" << test_file << "\""; | 3910 << " Parameter = \"" << test_file << "\""; |
3911 } | 3911 } |
3912 } | 3912 } |
3913 } | 3913 } |
3914 } | 3914 } |
3915 | 3915 |
3916 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | |
3917 ASSERT_TRUE(test_server_.Start()); | |
3918 | |
3919 SpawnedTestServer https_test_server( | |
3920 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
3921 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
3922 ASSERT_TRUE(https_test_server.Start()); | |
3923 | |
3924 // An https server is sent a request with an https referer, | |
3925 // and responds with a redirect to an http url. The http | |
3926 // server should not be sent the referer. | |
3927 GURL http_destination = test_server_.GetURL(std::string()); | |
3928 TestDelegate d; | |
3929 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
3930 https_test_server.GetURL("server-redirect?" + http_destination.spec()), | |
3931 DEFAULT_PRIORITY, &d, NULL)); | |
3932 req->SetReferrer("https://www.referrer.com/"); | |
3933 req->Start(); | |
3934 base::RunLoop().Run(); | |
3935 | |
3936 EXPECT_EQ(1, d.response_started_count()); | |
3937 EXPECT_EQ(1, d.received_redirect_count()); | |
3938 EXPECT_EQ(http_destination, req->url()); | |
3939 EXPECT_EQ(std::string(), req->referrer()); | |
3940 } | |
3941 | |
3942 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 3916 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
3943 ASSERT_TRUE(test_server_.Start()); | 3917 ASSERT_TRUE(test_server_.Start()); |
3944 | 3918 |
3945 GURL destination_url = test_server_.GetURL(std::string()); | 3919 GURL destination_url = test_server_.GetURL(std::string()); |
3946 GURL original_url = | 3920 GURL original_url = |
3947 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 3921 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
3948 TestDelegate d; | 3922 TestDelegate d; |
3949 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 3923 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
3950 original_url, DEFAULT_PRIORITY, &d, NULL)); | 3924 original_url, DEFAULT_PRIORITY, &d, NULL)); |
3951 req->Start(); | 3925 req->Start(); |
(...skipping 2768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6720 EXPECT_EQ(200, req->response_headers()->response_code()); | 6694 EXPECT_EQ(200, req->response_headers()->response_code()); |
6721 EXPECT_EQ("hello", d.data_received()); | 6695 EXPECT_EQ("hello", d.data_received()); |
6722 EXPECT_EQ(1, d.response_started_count()); | 6696 EXPECT_EQ(1, d.response_started_count()); |
6723 EXPECT_EQ(0, d.received_redirect_count()); | 6697 EXPECT_EQ(0, d.received_redirect_count()); |
6724 | 6698 |
6725 EXPECT_EQ(1, default_network_delegate()->created_requests()); | 6699 EXPECT_EQ(1, default_network_delegate()->created_requests()); |
6726 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); | 6700 EXPECT_EQ(2, default_network_delegate()->before_send_headers_count()); |
6727 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); | 6701 EXPECT_EQ(2, default_network_delegate()->headers_received_count()); |
6728 } | 6702 } |
6729 | 6703 |
6704 class URLRequestTestReferrerPolicy : public URLRequestTest { | |
6705 public: | |
6706 URLRequestTestReferrerPolicy() {} | |
6707 | |
6708 void InstantiateServers(SpawnedTestServer::Type origin_type, | |
6709 const char* origin_hostname, | |
6710 SpawnedTestServer::Type destination_type, | |
6711 const char* destination_hostname) { | |
6712 origin_server_.reset(new SpawnedTestServer( | |
6713 origin_type, origin_hostname, | |
6714 origin_type == SpawnedTestServer::TYPE_HTTPS | |
6715 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | |
6716 : base::FilePath( | |
6717 FILE_PATH_LITERAL("net/data/url_request_unittest")))); | |
6718 ASSERT_TRUE(origin_server_->Start()); | |
6719 | |
6720 if (origin_type != destination_type || | |
6721 origin_hostname != destination_hostname) { | |
6722 destination_server_.reset(new SpawnedTestServer( | |
6723 destination_type, destination_hostname, | |
6724 destination_type == SpawnedTestServer::TYPE_HTTPS | |
6725 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | |
6726 : base::FilePath( | |
6727 FILE_PATH_LITERAL("net/data/url_request_unittest")))); | |
6728 ASSERT_TRUE(destination_server_->Start()); | |
6729 } | |
6730 } | |
6731 | |
6732 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, | |
6733 const GURL& referrer, | |
6734 const GURL& expected) { | |
6735 // Create and execute the request: we'll only have a |destination_server_| | |
6736 // if the origins are meant to be distinct. Otherwise, we'll use the | |
6737 // |origin_server_| for both endpoints. | |
6738 GURL destination_url = destination_server_ | |
6739 ? destination_server_->GetURL(std::string()) | |
6740 : origin_server_->GetURL(std::string()); | |
mmenke
2014/11/20 16:23:45
Maybe use GetURL("/echoheader?Referrer"), and then
Mike West
2014/11/21 09:29:29
Good idea! Done.
| |
6741 GURL origin_url = | |
6742 origin_server_->GetURL("server-redirect?" + destination_url.spec()); | |
6743 | |
6744 TestDelegate d; | |
6745 scoped_ptr<URLRequest> req( | |
6746 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d, NULL)); | |
6747 req->set_referrer_policy(policy); | |
6748 req->SetReferrer(referrer.spec()); | |
6749 req->Start(); | |
6750 base::RunLoop().Run(); | |
6751 | |
6752 EXPECT_EQ(1, d.response_started_count()); | |
6753 EXPECT_EQ(1, d.received_redirect_count()); | |
6754 EXPECT_EQ(destination_url, req->url()); | |
mmenke
2014/11/20 16:23:45
Maybe add "EXPECT_EQ(200, req->response_headers()-
Mike West
2014/11/21 09:29:29
The paranoia was justified! HTTPS SpawnedTestServe
| |
6755 | |
6756 EXPECT_EQ(expected.spec(), req->referrer()); | |
6757 } | |
6758 | |
6759 protected: | |
mmenke
2014/11/20 16:23:45
Style guide requires all class variables be privat
Mike West
2014/11/21 09:29:29
Done.
| |
6760 scoped_ptr<SpawnedTestServer> origin_server_; | |
6761 scoped_ptr<SpawnedTestServer> destination_server_; | |
6762 }; | |
6763 | |
6764 TEST_F(URLRequestTestReferrerPolicy, HTTPToSameOriginHTTP) { | |
6765 InstantiateServers(SpawnedTestServer::TYPE_HTTP, "127.0.0.1", | |
6766 SpawnedTestServer::TYPE_HTTP, "127.0.0.1"); | |
6767 | |
6768 VerifyReferrerAfterRedirect( | |
6769 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6770 origin_server_->GetURL("path/to/file.html"), | |
6771 origin_server_->GetURL("path/to/file.html")); | |
6772 | |
6773 VerifyReferrerAfterRedirect( | |
6774 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6775 origin_server_->GetURL("path/to/file.html"), | |
6776 origin_server_->GetURL("path/to/file.html")); | |
6777 | |
6778 VerifyReferrerAfterRedirect( | |
6779 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6780 origin_server_->GetURL("path/to/file.html"), | |
6781 origin_server_->GetURL("path/to/file.html")); | |
6782 | |
6783 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6784 origin_server_->GetURL("path/to/file.html"), | |
6785 origin_server_->GetURL("path/to/file.html")); | |
6786 } | |
6787 | |
6788 TEST_F(URLRequestTestReferrerPolicy, HTTPToCrossOriginHTTP) { | |
6789 InstantiateServers(SpawnedTestServer::TYPE_HTTP, "127.0.0.1", | |
6790 SpawnedTestServer::TYPE_HTTP, "localhost"); | |
6791 | |
6792 VerifyReferrerAfterRedirect( | |
6793 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6794 origin_server_->GetURL("path/to/file.html"), | |
6795 origin_server_->GetURL("path/to/file.html")); | |
6796 | |
6797 VerifyReferrerAfterRedirect( | |
6798 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6799 origin_server_->GetURL("path/to/file.html"), | |
6800 origin_server_->GetURL(std::string())); | |
6801 | |
6802 VerifyReferrerAfterRedirect( | |
6803 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6804 origin_server_->GetURL("path/to/file.html"), | |
6805 origin_server_->GetURL(std::string())); | |
6806 | |
6807 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6808 origin_server_->GetURL("path/to/file.html"), | |
6809 origin_server_->GetURL("path/to/file.html")); | |
6810 } | |
6811 | |
6812 TEST_F(URLRequestTestReferrerPolicy, HTTPSToSameOriginHTTPS) { | |
6813 InstantiateServers(SpawnedTestServer::TYPE_HTTPS, "127.0.0.1", | |
6814 SpawnedTestServer::TYPE_HTTPS, "127.0.0.1"); | |
6815 | |
6816 VerifyReferrerAfterRedirect( | |
6817 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6818 origin_server_->GetURL("path/to/file.html"), | |
6819 origin_server_->GetURL("path/to/file.html")); | |
6820 | |
6821 VerifyReferrerAfterRedirect( | |
6822 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6823 origin_server_->GetURL("path/to/file.html"), | |
6824 origin_server_->GetURL("path/to/file.html")); | |
6825 | |
6826 VerifyReferrerAfterRedirect( | |
6827 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6828 origin_server_->GetURL("path/to/file.html"), | |
6829 origin_server_->GetURL("path/to/file.html")); | |
6830 | |
6831 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6832 origin_server_->GetURL("path/to/file.html"), | |
6833 origin_server_->GetURL("path/to/file.html")); | |
6834 } | |
6835 | |
6836 TEST_F(URLRequestTestReferrerPolicy, HTTPSToCrossOriginHTTPS) { | |
6837 InstantiateServers(SpawnedTestServer::TYPE_HTTPS, "127.0.0.1", | |
6838 SpawnedTestServer::TYPE_HTTPS, "localhost"); | |
6839 | |
6840 VerifyReferrerAfterRedirect( | |
6841 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6842 origin_server_->GetURL("path/to/file.html"), | |
6843 origin_server_->GetURL("path/to/file.html")); | |
6844 | |
6845 VerifyReferrerAfterRedirect( | |
6846 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6847 origin_server_->GetURL("path/to/file.html"), | |
6848 origin_server_->GetURL(std::string())); | |
6849 | |
6850 VerifyReferrerAfterRedirect( | |
6851 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6852 origin_server_->GetURL("path/to/file.html"), | |
6853 origin_server_->GetURL(std::string())); | |
6854 | |
6855 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6856 origin_server_->GetURL("path/to/file.html"), | |
6857 origin_server_->GetURL("path/to/file.html")); | |
6858 } | |
6859 | |
6860 TEST_F(URLRequestTestReferrerPolicy, HTTPToHTTPS) { | |
6861 InstantiateServers(SpawnedTestServer::TYPE_HTTP, "127.0.0.1", | |
6862 SpawnedTestServer::TYPE_HTTPS, "localhost"); | |
6863 | |
6864 VerifyReferrerAfterRedirect( | |
6865 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6866 origin_server_->GetURL("path/to/file.html"), | |
6867 origin_server_->GetURL("path/to/file.html")); | |
6868 | |
6869 VerifyReferrerAfterRedirect( | |
6870 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6871 origin_server_->GetURL("path/to/file.html"), | |
6872 origin_server_->GetURL(std::string())); | |
6873 | |
6874 VerifyReferrerAfterRedirect( | |
6875 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6876 origin_server_->GetURL("path/to/file.html"), | |
6877 origin_server_->GetURL(std::string())); | |
6878 | |
6879 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6880 origin_server_->GetURL("path/to/file.html"), | |
6881 origin_server_->GetURL("path/to/file.html")); | |
6882 } | |
6883 | |
6884 TEST_F(URLRequestTestReferrerPolicy, HTTPSToHTTP) { | |
6885 InstantiateServers(SpawnedTestServer::TYPE_HTTPS, "127.0.0.1", | |
6886 SpawnedTestServer::TYPE_HTTP, "localhost"); | |
6887 | |
6888 VerifyReferrerAfterRedirect( | |
6889 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
6890 origin_server_->GetURL("path/to/file.html"), GURL()); | |
6891 | |
6892 VerifyReferrerAfterRedirect( | |
6893 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
6894 origin_server_->GetURL("path/to/file.html"), GURL()); | |
6895 | |
6896 VerifyReferrerAfterRedirect( | |
6897 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
6898 origin_server_->GetURL("path/to/file.html"), | |
6899 origin_server_->GetURL(std::string())); | |
6900 | |
6901 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | |
6902 origin_server_->GetURL("path/to/file.html"), | |
6903 origin_server_->GetURL("path/to/file.html")); | |
6904 } | |
6905 | |
6730 class HTTPSRequestTest : public testing::Test { | 6906 class HTTPSRequestTest : public testing::Test { |
6731 public: | 6907 public: |
6732 HTTPSRequestTest() : default_context_(true) { | 6908 HTTPSRequestTest() : default_context_(true) { |
6733 default_context_.set_network_delegate(&default_network_delegate_); | 6909 default_context_.set_network_delegate(&default_network_delegate_); |
6734 default_context_.Init(); | 6910 default_context_.Init(); |
6735 } | 6911 } |
6736 ~HTTPSRequestTest() override {} | 6912 ~HTTPSRequestTest() override {} |
6737 | 6913 |
6738 protected: | 6914 protected: |
6739 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 6915 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
(...skipping 1882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8622 | 8798 |
8623 EXPECT_FALSE(r->is_pending()); | 8799 EXPECT_FALSE(r->is_pending()); |
8624 EXPECT_EQ(1, d->response_started_count()); | 8800 EXPECT_EQ(1, d->response_started_count()); |
8625 EXPECT_FALSE(d->received_data_before_response()); | 8801 EXPECT_FALSE(d->received_data_before_response()); |
8626 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8802 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8627 } | 8803 } |
8628 } | 8804 } |
8629 #endif // !defined(DISABLE_FTP_SUPPORT) | 8805 #endif // !defined(DISABLE_FTP_SUPPORT) |
8630 | 8806 |
8631 } // namespace net | 8807 } // namespace net |
OLD | NEW |