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

Unified Diff: components/url_formatter/url_formatter_unittest.cc

Issue 2939423003: URL Formatter: Add StripSubdomain method that preserves eTLD + 1. (Closed)
Patch Set: Return std::string instead of base::StringPiece (which makes no sense) Created 3 years, 6 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 | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_formatter/url_formatter_unittest.cc
diff --git a/components/url_formatter/url_formatter_unittest.cc b/components/url_formatter/url_formatter_unittest.cc
index 544f55080a4c6eb940f53e55082d9db2e0346762..e768677700d3f93ad061894e71083dd4a22e951f 100644
--- a/components/url_formatter/url_formatter_unittest.cc
+++ b/components/url_formatter/url_formatter_unittest.cc
@@ -1223,6 +1223,49 @@ TEST(UrlFormatterTest, FormatUrlWithOffsets) {
net::UnescapeRule::NORMAL, omit_all_offsets);
}
+TEST(UrlFormatterTest, StripSubdomains) {
+ struct TestCase {
+ std::string expected;
+ std::string input_host;
+ StripSubdomainTypes subdomains_to_strip;
+ } cases[] = {
+ // Test successful strippings of subdomains.
+ {"google.com", "www.google.com", kStripWWW},
+ {"google.com", "m.google.com", kStripM},
+ {"google.com", "www.google.com", kStripWWW | kStripM},
+ {"google.com", "m.google.com", kStripWWW | kStripM},
+ {"google.com", "www.m.google.com", kStripWWW | kStripM},
+ {"google.com", "m.www.google.com", kStripWWW | kStripM},
+
+ // Test partial strippings.
+ {"m.google.com", "www.m.google.com", kStripWWW},
+ {"www.google.com", "m.www.google.com", kStripM},
+ {"en.wikipedia.org", "en.m.wikipedia.org", kStripWWW | kStripM},
+ {"foo.google.com", "www.foo.google.com", kStripWWW | kStripM},
+ {"foo.google.com", "foo.www.google.com", kStripWWW | kStripM},
+
+ // Leave subdomains alone if the flags specify it as such.
+ {"www.google.com", "www.google.com", kStripM},
+ {"m.google.com", "m.google.com", kStripWWW},
+
+ // Leave eTLD+1s (registry and domain) alone.
+ {"google.com", "google.com", kStripWWW},
+ {"www.com", "www.com", kStripWWW | kStripM},
+ {"m.com", "m.com", kStripWWW | kStripM},
+ {"mail.google.com", "mail.google.com", kStripWWW | kStripM},
+ {"www.co.uk", "www.co.uk", kStripWWW},
+ {"www.garden", "www.garden", kStripWWW},
+ };
+
+ for (TestCase& test_case : cases) {
+ EXPECT_EQ(test_case.expected, url_formatter::StripSubdomains(
+ GURL("http://" + test_case.input_host),
+ test_case.subdomains_to_strip))
+ << " input_host = " << test_case.input_host << std::endl
+ << " subdomains_to_strip = " << test_case.subdomains_to_strip;
+ }
+}
+
} // namespace
} // namespace url_formatter
« no previous file with comments | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698