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 3ba5e361b4fef70c25f413819466d67e2f48365b..d395e08af7e65fde88a694d224426b6707c867fa 100644 |
| --- a/components/url_formatter/url_formatter_unittest.cc |
| +++ b/components/url_formatter/url_formatter_unittest.cc |
| @@ -934,6 +934,56 @@ TEST(UrlFormatterTest, FormatUrl) { |
| "https://ftp.google.com/", |
| kFormatUrlOmitHTTP | kFormatUrlExperimentalOmitHTTPS, |
| net::UnescapeRule::NORMAL, L"https://ftp.google.com/", 8}, |
| + |
| + // -------- omit trivial subdomains -------- |
| + {"omit trivial subdomains - trim www", "http://www.google.com/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://google.com/", 7}, |
| + {"omit trivial subdomains - trim m", "http://m.google.com/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://google.com/", 7}, |
| + {"omit trivial subdomains - trim m and www", "http://m.www.google.com/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://google.com/", 7}, |
| + {"omit trivial subdomains - trim m from middle", |
| + "http://en.m.wikipedia.org/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://en.wikipedia.org/", 7}, |
| + {"omit trivial subdomains but leave subdomains ending in www", |
|
Peter Kasting
2017/07/06 06:01:21
Nit: Maybe "don't do blind substring matches for w
tommycli
2017/07/06 16:25:46
Done.
|
| + "http://wwww.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://wwww.google.com/", 7}, |
| + {"omit trivial subdomains but leave subdomains ending in m", |
| + "http://foom.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://foom.google.com/", 7}, |
| + {"omit trivial subdomains and consume one trailing delimiter only", |
|
Peter Kasting
2017/07/06 06:01:21
Is it important that we test this? Such URLs aren
tommycli
2017/07/06 16:25:46
It's really to verify that the code doesn't crash.
Peter Kasting
2017/07/06 16:31:47
Oh, did it crash in some version of your code? Th
|
| + "http://www...m..foobar...google.com/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://...foobar...google.com/", 7}, |
| + |
| + {"omit trivial subdomains - sanity check for ordinary subdomains", |
| + "http://mail.yahoo.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://mail.yahoo.com/", 7}, |
| + {"omit trivial subdomains - sanity check for auth", |
| + "http://www:m@google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://www:m@google.com/", 13}, |
| + {"omit trivial subdomains - sanity check for path", |
| + "http://google.com/www.m.foobar", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://google.com/www.m.foobar", 7}, |
| + {"omit trivial subdomains - sanity check for IDN", |
| + "http://www.xn--cy2a840a.m.xn--cy2a840a.com", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL, |
| + L"http://\x89c6\x9891.\x89c6\x9891.com/", 7}, |
| + |
| + {"omit trivial subdomains but leave registry and domain alone - trivial", |
| + "http://google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://google.com/", 7}, |
| + {"omit trivial subdomains but leave registry and domain alone - www", |
| + "http://www.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://www.com/", 7}, |
| + {"omit trivial subdomains but leave registry and domain alone - co.uk", |
| + "http://m.co.uk/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, L"http://m.co.uk/", 7}, |
| }; |
| for (size_t i = 0; i < arraysize(tests); ++i) { |
| @@ -1313,6 +1363,23 @@ TEST(UrlFormatterTest, FormatUrlWithOffsets) { |
| CheckAdjustedOffsets("https://u:p@www.google.com/", |
| kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS, |
| net::UnescapeRule::NORMAL, omit_https_with_auth_offsets); |
| + |
| + const size_t strip_trivial_subdomains_offsets[] = { |
| + 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, |
| + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; |
| + CheckAdjustedOffsets( |
| + "http://www.google.com/foo/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, strip_trivial_subdomains_offsets); |
| + |
| + const size_t strip_trivial_subdomains_from_idn_offsets[] = { |
| + 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, |
| + kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| + kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, |
| + 13, 14, 15, 16, 17, 18, 19}; |
| + CheckAdjustedOffsets("http://www.xn--l8jvb1ey91xtjb.jp/foo/", |
| + kFormatUrlExperimentalOmitTrivialSubdomains, |
| + net::UnescapeRule::NORMAL, |
| + strip_trivial_subdomains_from_idn_offsets); |
| } |
| } // namespace |