Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2820 EXPECT_TRUE(test_server_.Start()); | 2820 EXPECT_TRUE(test_server_.Start()); |
| 2821 } | 2821 } |
| 2822 | 2822 |
| 2823 return is_success; | 2823 return is_success; |
| 2824 } | 2824 } |
| 2825 | 2825 |
| 2826 LocalHttpTestServer* test_server() { | 2826 LocalHttpTestServer* test_server() { |
| 2827 return &test_server_; | 2827 return &test_server_; |
| 2828 } | 2828 } |
| 2829 | 2829 |
| 2830 void VerifyReferrerPolicyAfterRedirect(URLRequest::ReferrerPolicy policy, | |
| 2831 SpawnedTestServer::Type origin, | |
| 2832 SpawnedTestServer::Type destination, | |
| 2833 const std::string& referrer, | |
| 2834 const std::string& expected) { | |
| 2835 // Spin up the servers. | |
| 2836 SpawnedTestServer https_test_server( | |
| 2837 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
| 2838 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
| 2839 ASSERT_TRUE(https_test_server.Start()); | |
| 2840 ASSERT_TRUE(test_server_.Start()); | |
|
mmenke
2014/11/19 16:29:03
All the server starting and stopping, particularly
Mike West
2014/11/20 10:45:30
That seems reasonable. It still requires us to spi
mmenke
2014/11/20 16:23:45
Starting two servers per test is much less likely
| |
| 2841 | |
| 2842 // Create and execute the request. | |
| 2843 GURL destination_url = destination == SpawnedTestServer::TYPE_HTTP | |
| 2844 ? test_server_.GetURL(std::string()) | |
| 2845 : https_test_server.GetURL(std::string()); | |
| 2846 GURL origin_url = | |
| 2847 origin == SpawnedTestServer::TYPE_HTTP | |
| 2848 ? test_server_.GetURL("server-redirect?" + destination_url.spec()) | |
| 2849 : https_test_server.GetURL("server-redirect?" + | |
| 2850 destination_url.spec()); | |
| 2851 | |
| 2852 std::string original_referrer = referrer; | |
| 2853 ReplaceFirstSubstringAfterOffset(&original_referrer, 0, "[HTTP_ORIGIN]", | |
| 2854 test_server_.GetURL(std::string()).spec()); | |
| 2855 ReplaceFirstSubstringAfterOffset( | |
| 2856 &original_referrer, 0, "[HTTPS_ORIGIN]", | |
| 2857 https_test_server.GetURL(std::string()).spec()); | |
| 2858 | |
| 2859 std::string expected_referrer = expected; | |
| 2860 ReplaceFirstSubstringAfterOffset(&expected_referrer, 0, "[HTTP_ORIGIN]", | |
| 2861 test_server_.GetURL(std::string()).spec()); | |
| 2862 ReplaceFirstSubstringAfterOffset( | |
| 2863 &expected_referrer, 0, "[HTTPS_ORIGIN]", | |
| 2864 https_test_server.GetURL(std::string()).spec()); | |
| 2865 | |
| 2866 TestDelegate d; | |
| 2867 scoped_ptr<URLRequest> req( | |
| 2868 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d, NULL)); | |
| 2869 req->set_referrer_policy(policy); | |
| 2870 req->SetReferrer(original_referrer); | |
| 2871 req->Start(); | |
| 2872 base::RunLoop().Run(); | |
| 2873 | |
| 2874 EXPECT_EQ(1, d.response_started_count()); | |
| 2875 EXPECT_EQ(1, d.received_redirect_count()); | |
| 2876 EXPECT_EQ(destination_url, req->url()); | |
| 2877 EXPECT_EQ(expected_referrer, req->referrer()); | |
| 2878 | |
| 2879 ASSERT_TRUE(test_server_.Stop()); | |
| 2880 ASSERT_TRUE(https_test_server.Stop()); | |
| 2881 } | |
| 2882 | |
| 2830 protected: | 2883 protected: |
| 2831 LocalHttpTestServer test_server_; | 2884 LocalHttpTestServer test_server_; |
| 2832 }; | 2885 }; |
| 2833 | 2886 |
| 2834 // In this unit test, we're using the HTTPTestServer as a proxy server and | 2887 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 2835 // issuing a CONNECT request with the magic host name "www.redirect.com". | 2888 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 2836 // The HTTPTestServer will return a 302 response, which we should not | 2889 // The HTTPTestServer will return a 302 response, which we should not |
| 2837 // follow. | 2890 // follow. |
| 2838 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { | 2891 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { |
| 2839 ASSERT_TRUE(test_server_.Start()); | 2892 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3906 << " Parameter = \"" << test_file << "\""; | 3959 << " Parameter = \"" << test_file << "\""; |
| 3907 } else { | 3960 } else { |
| 3908 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 3961 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 3909 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) | 3962 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
| 3910 << " Parameter = \"" << test_file << "\""; | 3963 << " Parameter = \"" << test_file << "\""; |
| 3911 } | 3964 } |
| 3912 } | 3965 } |
| 3913 } | 3966 } |
| 3914 } | 3967 } |
| 3915 | 3968 |
| 3916 TEST_F(URLRequestTestHTTP, HTTPSToHTTPRedirectNoRefererTest) { | 3969 TEST_F(URLRequestTestHTTP, ReferrerPolicyClearRefererOnTransition) { |
|
mmenke
2014/11/19 16:29:04
It's unexciting, but for completeness, should test
| |
| 3917 ASSERT_TRUE(test_server_.Start()); | 3970 VerifyReferrerPolicyAfterRedirect( |
| 3971 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, | |
| 3972 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTPS, | |
| 3973 "https://www.referrer.com/path/to/file.html", | |
| 3974 "https://www.referrer.com/path/to/file.html"); | |
| 3918 | 3975 |
| 3919 SpawnedTestServer https_test_server( | 3976 VerifyReferrerPolicyAfterRedirect( |
| 3920 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | 3977 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 3921 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 3978 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTP, |
| 3922 ASSERT_TRUE(https_test_server.Start()); | 3979 "https://www.referrer.com/path/to/file.html", ""); |
| 3923 | 3980 |
| 3924 // An https server is sent a request with an https referer, | 3981 VerifyReferrerPolicyAfterRedirect( |
| 3925 // and responds with a redirect to an http url. The http | 3982 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 3926 // server should not be sent the referer. | 3983 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTPS, |
| 3927 GURL http_destination = test_server_.GetURL(std::string()); | 3984 "http://www.referrer.com/path/to/file.html", |
| 3928 TestDelegate d; | 3985 "http://www.referrer.com/path/to/file.html"); |
| 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 | 3986 |
| 3936 EXPECT_EQ(1, d.response_started_count()); | 3987 VerifyReferrerPolicyAfterRedirect( |
| 3937 EXPECT_EQ(1, d.received_redirect_count()); | 3988 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 3938 EXPECT_EQ(http_destination, req->url()); | 3989 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTP, |
| 3939 EXPECT_EQ(std::string(), req->referrer()); | 3990 "http://www.referrer.com/path/to/file.html", |
| 3991 "http://www.referrer.com/path/to/file.html"); | |
| 3992 } | |
| 3993 | |
| 3994 TEST_F(URLRequestTestHTTP, ReferrerPolicyNeverClearReferer) { | |
| 3995 VerifyReferrerPolicyAfterRedirect( | |
| 3996 URLRequest::NEVER_CLEAR_REFERRER, SpawnedTestServer::TYPE_HTTPS, | |
| 3997 SpawnedTestServer::TYPE_HTTPS, | |
| 3998 "https://www.referrer.com/path/to/file.html", | |
| 3999 "https://www.referrer.com/path/to/file.html"); | |
| 4000 | |
| 4001 VerifyReferrerPolicyAfterRedirect( | |
| 4002 URLRequest::NEVER_CLEAR_REFERRER, SpawnedTestServer::TYPE_HTTPS, | |
| 4003 SpawnedTestServer::TYPE_HTTP, | |
| 4004 "https://www.referrer.com/path/to/file.html", | |
| 4005 "https://www.referrer.com/path/to/file.html"); | |
| 4006 | |
| 4007 VerifyReferrerPolicyAfterRedirect( | |
| 4008 URLRequest::NEVER_CLEAR_REFERRER, SpawnedTestServer::TYPE_HTTP, | |
| 4009 SpawnedTestServer::TYPE_HTTPS, | |
| 4010 "http://www.referrer.com/path/to/file.html", | |
| 4011 "http://www.referrer.com/path/to/file.html"); | |
| 4012 | |
| 4013 VerifyReferrerPolicyAfterRedirect( | |
| 4014 URLRequest::NEVER_CLEAR_REFERRER, SpawnedTestServer::TYPE_HTTP, | |
| 4015 SpawnedTestServer::TYPE_HTTP, "http://www.referrer.com/path/to/file.html", | |
| 4016 "http://www.referrer.com/path/to/file.html"); | |
| 4017 } | |
| 4018 | |
| 4019 TEST_F(URLRequestTestHTTP, ReferrerPolicyReduceReferrerGranularity) { | |
|
mmenke
2014/11/19 16:29:03
We actually have 6 cases for all these tests, not
| |
| 4020 VerifyReferrerPolicyAfterRedirect( | |
| 4021 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4022 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTPS, | |
| 4023 "[HTTPS_ORIGIN]path/to/file.html", "[HTTPS_ORIGIN]path/to/file.html"); | |
| 4024 | |
| 4025 VerifyReferrerPolicyAfterRedirect( | |
| 4026 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4027 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTP, | |
| 4028 "[HTTPS_ORIGIN]path/to/file.html", ""); | |
| 4029 | |
| 4030 VerifyReferrerPolicyAfterRedirect( | |
| 4031 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4032 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTPS, | |
| 4033 "[HTTP_ORIGIN]path/to/file.html", "[HTTP_ORIGIN]"); | |
| 4034 | |
| 4035 VerifyReferrerPolicyAfterRedirect( | |
| 4036 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4037 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTP, | |
| 4038 "[HTTP_ORIGIN]path/to/file.html", "[HTTP_ORIGIN]path/to/file.html"); | |
| 4039 } | |
| 4040 | |
| 4041 TEST_F(URLRequestTestHTTP, ReferrerPolicyOriginOnly) { | |
| 4042 VerifyReferrerPolicyAfterRedirect( | |
| 4043 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4044 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTPS, | |
| 4045 "[HTTPS_ORIGIN]path/to/file.html", "[HTTPS_ORIGIN]path/to/file.html"); | |
|
mmenke
2014/11/19 16:29:03
Shouldn't we test HTTPS cross origin, too, where w
Mike West
2014/11/20 10:45:30
Added cross-origin HTTPS tests.
| |
| 4046 | |
| 4047 VerifyReferrerPolicyAfterRedirect( | |
| 4048 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4049 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::TYPE_HTTP, | |
| 4050 "[HTTPS_ORIGIN]path/to/file.html", "[HTTPS_ORIGIN]"); | |
|
mmenke
2014/11/19 16:29:04
I thought we should clear the referrer in this cas
Mike West
2014/11/20 10:45:30
No, we clear it for "REDUCED_WHATEVER_...", but "O
| |
| 4051 | |
| 4052 VerifyReferrerPolicyAfterRedirect( | |
| 4053 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4054 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTPS, | |
| 4055 "[HTTP_ORIGIN]path/to/file.html", "[HTTP_ORIGIN]"); | |
| 4056 | |
| 4057 VerifyReferrerPolicyAfterRedirect( | |
| 4058 URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN, | |
| 4059 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::TYPE_HTTP, | |
| 4060 "[HTTP_ORIGIN]path/to/file.html", "[HTTP_ORIGIN]path/to/file.html"); | |
| 3940 } | 4061 } |
| 3941 | 4062 |
| 3942 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 4063 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
| 3943 ASSERT_TRUE(test_server_.Start()); | 4064 ASSERT_TRUE(test_server_.Start()); |
| 3944 | 4065 |
| 3945 GURL destination_url = test_server_.GetURL(std::string()); | 4066 GURL destination_url = test_server_.GetURL(std::string()); |
| 3946 GURL original_url = | 4067 GURL original_url = |
| 3947 test_server_.GetURL("server-redirect?" + destination_url.spec()); | 4068 test_server_.GetURL("server-redirect?" + destination_url.spec()); |
| 3948 TestDelegate d; | 4069 TestDelegate d; |
| 3949 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 4070 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| (...skipping 4672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8622 | 8743 |
| 8623 EXPECT_FALSE(r->is_pending()); | 8744 EXPECT_FALSE(r->is_pending()); |
| 8624 EXPECT_EQ(1, d->response_started_count()); | 8745 EXPECT_EQ(1, d->response_started_count()); |
| 8625 EXPECT_FALSE(d->received_data_before_response()); | 8746 EXPECT_FALSE(d->received_data_before_response()); |
| 8626 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8747 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8627 } | 8748 } |
| 8628 } | 8749 } |
| 8629 #endif // !defined(DISABLE_FTP_SUPPORT) | 8750 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 8630 | 8751 |
| 8631 } // namespace net | 8752 } // namespace net |
| OLD | NEW |