summaryrefslogtreecommitdiffstats
path: root/url
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 10:06:50 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 10:06:50 +0000
commite9185c8ddd5dae24fccdfc4012feeee6dfcc6e9d (patch)
tree0327cbb1225ae75a8ec08d2f2d1ec9083068166a /url
parent780461764d6aa6305c95bdeedd02e8c8d48ce94b (diff)
downloadchromium_src-e9185c8ddd5dae24fccdfc4012feeee6dfcc6e9d.zip
chromium_src-e9185c8ddd5dae24fccdfc4012feeee6dfcc6e9d.tar.gz
chromium_src-e9185c8ddd5dae24fccdfc4012feeee6dfcc6e9d.tar.bz2
More tests for GURL's is_valid() and authority parser
BUG=none Review URL: https://codereview.chromium.org/238973006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'url')
-rw-r--r--url/gurl_unittest.cc51
1 files changed, 50 insertions, 1 deletions
diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc
index 738f2cc..a560887 100644
--- a/url/gurl_unittest.cc
+++ b/url/gurl_unittest.cc
@@ -85,6 +85,14 @@ TEST(GURLTest, Components) {
EXPECT_EQ("/foo;bar", url.path());
EXPECT_EQ("q=a", url.query());
EXPECT_EQ("ref", url.ref());
+
+ // Test parsing userinfo with special characters.
+ GURL url_special_pass("http://user:%40!$&'()*+,;=:@google.com:12345");
+ EXPECT_TRUE(url_special_pass.is_valid());
+ // GURL canonicalizes some delimiters.
+ EXPECT_EQ("%40!$&%27()*+,%3B%3D%3A", url_special_pass.password());
+ EXPECT_EQ("google.com", url_special_pass.host());
+ EXPECT_EQ("12345", url_special_pass.port());
}
TEST(GURLTest, Empty) {
@@ -208,8 +216,49 @@ TEST(GURLTest, CopyFileSystem) {
EXPECT_EQ("", inner->ref());
}
+TEST(GURLTest, IsValid) {
+ const char* valid_cases[] = {
+ "http://google.com",
+ "unknown://google.com",
+ "http://user:pass@google.com",
+ "http://google.com:12345",
+ "http://google.com/path",
+ "http://google.com//path",
+ "http://google.com?k=v#fragment",
+ "http://user:pass@google.com:12345/path?k=v#fragment",
+ "http:/path",
+ "http:path",
+ "://google.com",
+ };
+ for (size_t i = 0; i < ARRAYSIZE(valid_cases); i++) {
+ EXPECT_TRUE(GURL(valid_cases[i]).is_valid())
+ << "Case: " << valid_cases[i];
+ }
+
+ const char* invalid_cases[] = {
+ "http://?k=v",
+ "http:://google.com",
+ "http//google.com",
+ "http://google.com:12three45",
+ "path",
+ };
+ for (size_t i = 0; i < ARRAYSIZE(invalid_cases); i++) {
+ EXPECT_FALSE(GURL(invalid_cases[i]).is_valid())
+ << "Case: " << invalid_cases[i];
+ }
+}
+
+TEST(GURLTest, ExtraSlashesBeforeAuthority) {
+ // According to RFC3986, the hier-part for URI with an authority must use only
+ // two slashes, GURL intentionally just ignores slashes more than 2 and parses
+ // the following part as an authority.
+ GURL url("http:///host");
+ EXPECT_EQ("host", url.host());
+ EXPECT_EQ("/", url.path());
+}
+
// Given an invalid URL, we should still get most of the components.
-TEST(GURLTest, Invalid) {
+TEST(GURLTest, ComponentGettersWorkEvenForInvalidURL) {
GURL url("http:google.com:foo");
EXPECT_FALSE(url.is_valid());
EXPECT_EQ("http://google.com:foo/", url.possibly_invalid_spec());