Chromium Code Reviews| 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..2ca540d22e531c57dd2c28af63e3b02fe1769f19 100644 |
| --- a/components/url_formatter/url_formatter_unittest.cc |
| +++ b/components/url_formatter/url_formatter_unittest.cc |
| @@ -1223,6 +1223,51 @@ 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}, |
| + |
| + // Sanity check that we respect other registries. |
|
Peter Kasting
2017/06/19 23:42:32
Are these tests just extensions of the block below
tommycli
2017/06/19 23:48:51
Done.
|
| + {"www.co.uk", "www.co.uk", kStripWWW}, |
| + {"www.garden", "www.garden", 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}, |
| + }; |
| + |
| + 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 |