Index: content/browser/loader/resource_dispatcher_host_unittest.cc |
diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc |
index 08e5f4d17e040b7706ada50493dc550197b71656..2a1f12cd82322a9c92ec8c4b60ae6bda6c2461ec 100644 |
--- a/content/browser/loader/resource_dispatcher_host_unittest.cc |
+++ b/content/browser/loader/resource_dispatcher_host_unittest.cc |
@@ -2935,4 +2935,96 @@ TEST_F(ResourceDispatcherHostTest, DownloadToFile) { |
filter_->child_id(), response_head.download_file_path)); |
} |
+namespace { |
+ |
+void MatchSanitizedReferrer( |
+ const std::string& original_referrer_url, |
+ blink::WebReferrerPolicy referrer_policy, |
+ const std::string& request_url, |
+ const std::string& expected_sanitized_referrer_url) { |
+ Referrer sanitized_referrer = SanitizeReferrerForRequest( |
+ GURL(request_url), |
+ Referrer(GURL(original_referrer_url), referrer_policy)); |
+ EXPECT_EQ(GURL(expected_sanitized_referrer_url), sanitized_referrer.url); |
+ EXPECT_EQ(referrer_policy, sanitized_referrer.policy); |
+} |
+ |
+} |
+ |
+TEST(SanitizeReferrerForRequestTest, HttpReferrerHttpRequest) { |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyAlways, |
+ "http://bar.example.com", |
+ "http://foo.example.com/path"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyDefault, |
+ "http://bar.example.com", |
+ "http://foo.example.com/path"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyOrigin, |
+ "http://bar.example.com", |
+ "http://foo.example.com"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyNever, |
+ "http://bar.example.com", |
+ ""); |
+} |
+ |
+TEST(SanitizeReferrerForRequestTest, HttpReferrerHttpsRequest) { |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyAlways, |
+ "https://bar.example.com", |
+ "http://foo.example.com/path"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyDefault, |
+ "https://bar.example.com", |
+ "http://foo.example.com/path"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyOrigin, |
+ "https://bar.example.com", |
+ "http://foo.example.com"); |
+ MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyNever, |
+ "https://bar.example.com", |
+ ""); |
+} |
+ |
+TEST(SanitizeReferrerForRequestTest, HttpsReferrerHttpRequest) { |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyAlways, |
+ "http://bar.example.com", |
+ "https://foo.example.com/path"); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyDefault, |
+ "http://bar.example.com", |
+ ""); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyOrigin, |
+ "http://bar.example.com", |
+ "https://foo.example.com"); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyNever, |
+ "http://bar.example.com", |
+ ""); |
+} |
+ |
+TEST(SanitizeReferrerForRequestTest, HttpsReferrerHttpsRequest) { |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyAlways, |
+ "https://bar.example.com", |
+ "https://foo.example.com/path"); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyDefault, |
+ "https://bar.example.com", |
+ "https://foo.example.com/path"); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyOrigin, |
+ "https://bar.example.com", |
+ "https://foo.example.com"); |
+ MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag", |
+ blink::WebReferrerPolicyNever, |
+ "https://bar.example.com", |
+ ""); |
+} |
+ |
} // namespace content |