Remove URL fragment from referrer HTTP header (to comply with rfc2616) when opening link using "Open Link in New Tab" option.
Change URLRequest::set_referrer to URLRequest::SetReferrer which sanitizes referrer by removing URL fragment, user name and password.
Remove URLRequest::GetSanitizedReferrer as URLRequest::referrer is now sanitized during set.
BUG=168213
TEST=net_unittests, browser_tests
Review URL: https://chromiumcodereview.appspot.com/12569007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193482 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 1e2e7e6..ed80b71 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2291,7 +2291,7 @@
TestDelegate d;
URLRequest req(
test_server.GetURL("echoheader?Referer"), &d, &default_context_);
- req.set_referrer("http://foo.com/");
+ req.SetReferrer("http://foo.com/");
HttpRequestHeaders headers;
headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
@@ -3323,7 +3323,7 @@
TestDelegate d;
URLRequest req(https_test_server.GetURL(
"server-redirect?" + http_destination.spec()), &d, &default_context_);
- req.set_referrer("https://www.referrer.com/");
+ req.SetReferrer("https://www.referrer.com/");
req.Start();
MessageLoop::current()->Run();
@@ -3897,13 +3897,40 @@
TestDelegate d;
URLRequest req(
test_server_.GetURL("echoheader?Referer"), &d, &default_context_);
- req.set_referrer("http://user:[email protected]/");
+ req.SetReferrer("http://user:[email protected]/");
req.Start();
MessageLoop::current()->Run();
EXPECT_EQ(std::string("http://foo.com/"), d.data_received());
}
+TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) {
+ ASSERT_TRUE(test_server_.Start());
+
+ TestDelegate d;
+ URLRequest req(
+ test_server_.GetURL("echoheader?Referer"), &d, &default_context_);
+ req.SetReferrer("http://foo.com/test#fragment");
+ req.Start();
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(std::string("http://foo.com/test"), d.data_received());
+}
+
+TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) {
+ ASSERT_TRUE(test_server_.Start());
+
+ TestDelegate d;
+ URLRequest req(
+ test_server_.GetURL("echoheader?Referer"), &d, &default_context_);
+ req.SetReferrer("http://foo.com/test#fragment");
+ req.SetReferrer("");
+ req.Start();
+ MessageLoop::current()->Run();
+
+ EXPECT_EQ(std::string("None"), d.data_received());
+}
+
TEST_F(URLRequestTestHTTP, CancelRedirect) {
ASSERT_TRUE(test_server_.Start());