Move referrer stripping into GURL::GetAsReferrer().
This patch moves the code that removes username, password and ref parts
of the url from http referrers into GURL::GetAsReferrer().
BUG=340295
Review URL: https://codereview.chromium.org/185133005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258392 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc
index c2d86e9..738f2cc 100644
--- a/url/gurl_unittest.cc
+++ b/url/gurl_unittest.cc
@@ -287,6 +287,25 @@
}
}
+TEST(GURLTest, GetAsReferrer) {
+ struct TestCase {
+ const char* input;
+ const char* expected;
+ } cases[] = {
+ {"http://www.google.com", "http://www.google.com/"},
+ {"http://user:[email protected]:21/blah#baz", "http://www.google.com:21/blah"},
+ {"http://[email protected]", "http://www.google.com/"},
+ {"http://:[email protected]", "http://www.google.com/"},
+ {"http://:@www.google.com", "http://www.google.com/"},
+ {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"},
+ };
+ for (size_t i = 0; i < ARRAYSIZE(cases); i++) {
+ GURL url(cases[i].input);
+ GURL origin = url.GetAsReferrer();
+ EXPECT_EQ(cases[i].expected, origin.spec());
+ }
+}
+
TEST(GURLTest, GetWithEmptyPath) {
struct TestCase {
const char* input;