Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1322)

Unified Diff: url/origin_unittest.cc

Issue 2287483002: Provide the equivalent of GURL::DomainIs for url::Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/origin.cc ('k') | url/url_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/origin_unittest.cc
diff --git a/url/origin_unittest.cc b/url/origin_unittest.cc
index 74ffd3038db974d9d944c0bdd93e9525f2735dd1..416e0e35ee56b5a23159c6731dc01fb46f2664ec 100644
--- a/url/origin_unittest.cc
+++ b/url/origin_unittest.cc
@@ -252,4 +252,61 @@ TEST(OriginTest, UnsafelyCreateUniqueViaEmbeddedNulls) {
}
}
+TEST(OriginTest, DomainIs) {
+ const struct {
+ const char* url;
+ const char* lower_ascii_domain;
+ bool expected_domain_is;
+ } kTestCases[] = {
+ {"http://google.com/foo", "google.com", true},
+ {"http://www.google.com:99/foo", "google.com", true},
+ {"http://www.google.com.cn/foo", "google.com", false},
+ {"http://www.google.comm", "google.com", false},
+ {"http://www.iamnotgoogle.com/foo", "google.com", false},
+ {"http://www.google.com/foo", "Google.com", false},
+
+ // If the host ends with a dot, it matches domains with or without a dot.
+ {"http://www.google.com./foo", "google.com", true},
+ {"http://www.google.com./foo", "google.com.", true},
+ {"http://www.google.com./foo", ".com", true},
+ {"http://www.google.com./foo", ".com.", true},
+
+ // But, if the host doesn't end with a dot and the input domain does, then
+ // it's considered to not match.
+ {"http://google.com/foo", "google.com.", false},
+
+ // If the host ends with two dots, it doesn't match.
+ {"http://www.google.com../foo", "google.com", false},
+
+ // Filesystem scheme.
+ {"filesystem:http://www.google.com:99/foo/", "google.com", true},
+ {"filesystem:http://www.iamnotgoogle.com/foo/", "google.com", false},
+
+ // File scheme.
+ {"file:///home/user/text.txt", "", false},
+ {"file:///home/user/text.txt", "txt", false},
+ };
+
+ for (const auto& test_case : kTestCases) {
+ SCOPED_TRACE(testing::Message() << "(url, domain): (" << test_case.url
+ << ", " << test_case.lower_ascii_domain
+ << ")");
+ GURL url(test_case.url);
+ ASSERT_TRUE(url.is_valid());
+ url::Origin origin(url);
+
+ EXPECT_EQ(test_case.expected_domain_is,
+ origin.DomainIs(test_case.lower_ascii_domain));
+ }
+
+ // If the URL is invalid, DomainIs returns false.
+ GURL invalid_url("google.com");
+ ASSERT_FALSE(invalid_url.is_valid());
+ EXPECT_FALSE(url::Origin(invalid_url).DomainIs("google.com"));
+
+ // Unique origins.
+ EXPECT_FALSE(url::Origin().DomainIs(""));
+ EXPECT_FALSE(url::Origin().DomainIs("com"));
+}
+
} // namespace url
« no previous file with comments | « url/origin.cc ('k') | url/url_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698