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

Unified Diff: url/url_util_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/url_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/url_util_unittest.cc
diff --git a/url/url_util_unittest.cc b/url/url_util_unittest.cc
index f0032c24582f170fff1d05c3646c7699c05ba3d3..af5d550005d2909affd4a1327b8f560840a95409 100644
--- a/url/url_util_unittest.cc
+++ b/url/url_util_unittest.cc
@@ -374,4 +374,47 @@ TEST(URLUtilTest, TestNoRefComponent) {
EXPECT_FALSE(resolved_parsed.ref.is_valid());
}
+TEST(URLUtilTest, TestDomainIs) {
+ const struct {
+ const char* canonicalized_host;
+ const char* lower_ascii_domain;
+ bool expected_domain_is;
+ } kTestCases[] = {
+ {"google.com", "google.com", true},
+ {"www.google.com", "google.com", true}, // Subdomain is ignored.
+ {"www.google.com.cn", "google.com", false}, // Different TLD.
+ {"www.google.comm", "google.com", false},
+ {"www.iamnotgoogle.com", "google.com", false}, // Different hostname.
+ {"www.google.com", "Google.com", false}, // The input is not lower-cased.
+
+ // If the host ends with a dot, it matches domains with or without a dot.
+ {"www.google.com.", "google.com", true},
+ {"www.google.com.", "google.com.", true},
+ {"www.google.com.", ".com", true},
+ {"www.google.com.", ".com.", true},
+
+ // But, if the host doesn't end with a dot and the input domain does, then
+ // it's considered to not match.
+ {"www.google.com", "google.com.", false},
+
+ // If the host ends with two dots, it doesn't match.
+ {"www.google.com..", "google.com", false},
+
+ // Empty parameters.
+ {"www.google.com", "", false},
+ {"", "www.google.com", false},
+ {"", "", false},
+ };
+
+ for (const auto& test_case : kTestCases) {
+ SCOPED_TRACE(testing::Message() << "(host, domain): ("
+ << test_case.canonicalized_host << ", "
+ << test_case.lower_ascii_domain << ")");
+
+ EXPECT_EQ(
+ test_case.expected_domain_is,
+ DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain));
+ }
+}
+
} // namespace url
« no previous file with comments | « url/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698