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

Unified Diff: components/url_formatter/url_formatter_unittest.cc

Issue 2939423003: URL Formatter: Add StripSubdomain method that preserves eTLD + 1. (Closed)
Patch Set: fix 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
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..746f21e1c138db46cf76d3b6a0d2f3eae37b1b43 100644
--- a/components/url_formatter/url_formatter_unittest.cc
+++ b/components/url_formatter/url_formatter_unittest.cc
@@ -1223,6 +1223,38 @@ 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},
+
+ // Only strip one least-significant subdomain.
Peter Kasting 2017/06/17 02:46:55 Yeah, this seems not-what-we-want to me.
tommycli 2017/06/19 23:03:08 Done.
+ {"m.google.com", "www.m.google.com", kStripWWW | kStripM},
+ {"www.google.com", "m.www.google.com", kStripWWW | kStripM},
+
Peter Kasting 2017/06/17 02:46:55 There are no tests for "strip www from m.foo.com"
tommycli 2017/06/19 23:03:08 Done.
+ // Leave eTLD+1s 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},
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
Peter Kasting 2017/06/17 02:46:55 Nit: Use range-based for instead
tommycli 2017/06/19 23:03:08 Done.
+ EXPECT_EQ(cases[i].expected, url_formatter::StripSubdomains(
+ GURL("http://" + cases[i].input_host),
+ cases[i].subdomains_to_strip))
+ << " input_host = " << cases[i].input_host << std::endl
+ << " subdomains_to_strip = " << cases[i].subdomains_to_strip;
+ }
+}
+
} // namespace
} // namespace url_formatter
« components/url_formatter/url_formatter.cc ('K') | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698