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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/url_formatter/url_formatter.h" 5 #include "components/url_formatter/url_formatter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 omit_http_start_with_ftp_offsets); 1216 omit_http_start_with_ftp_offsets);
1217 1217
1218 const size_t omit_all_offsets[] = { 1218 const size_t omit_all_offsets[] = {
1219 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1219 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1220 0, 1, 2, 3, 4, 5, 6, 7 1220 0, 1, 2, 3, 4, 5, 6, 7
1221 }; 1221 };
1222 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, 1222 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll,
1223 net::UnescapeRule::NORMAL, omit_all_offsets); 1223 net::UnescapeRule::NORMAL, omit_all_offsets);
1224 } 1224 }
1225 1225
1226 TEST(UrlFormatterTest, StripSubdomains) {
1227 struct TestCase {
1228 std::string expected;
1229 std::string input_host;
1230 StripSubdomainTypes subdomains_to_strip;
1231 } cases[] = {
1232 // Test successful strippings of subdomains.
1233 {"google.com", "www.google.com", kStripWWW},
1234 {"google.com", "m.google.com", kStripM},
1235 {"google.com", "www.google.com", kStripWWW | kStripM},
1236 {"google.com", "m.google.com", kStripWWW | kStripM},
1237 {"google.com", "www.m.google.com", kStripWWW | kStripM},
1238 {"google.com", "m.www.google.com", kStripWWW | kStripM},
1239
1240 // Test partial strippings.
1241 {"m.google.com", "www.m.google.com", kStripWWW},
1242 {"www.google.com", "m.www.google.com", kStripM},
1243 {"en.wikipedia.org", "en.m.wikipedia.org", kStripWWW | kStripM},
1244 {"foo.google.com", "www.foo.google.com", kStripWWW | kStripM},
1245 {"foo.google.com", "foo.www.google.com", kStripWWW | kStripM},
1246
1247 // Leave subdomains alone if the flags specify it as such.
1248 {"www.google.com", "www.google.com", kStripM},
1249 {"m.google.com", "m.google.com", kStripWWW},
1250
1251 // 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.
1252 {"www.co.uk", "www.co.uk", kStripWWW},
1253 {"www.garden", "www.garden", kStripWWW},
1254
1255 // Leave eTLD+1s (registry and domain) alone.
1256 {"google.com", "google.com", kStripWWW},
1257 {"www.com", "www.com", kStripWWW | kStripM},
1258 {"m.com", "m.com", kStripWWW | kStripM},
1259 {"mail.google.com", "mail.google.com", kStripWWW | kStripM},
1260 };
1261
1262 for (TestCase& test_case : cases) {
1263 EXPECT_EQ(test_case.expected, url_formatter::StripSubdomains(
1264 GURL("http://" + test_case.input_host),
1265 test_case.subdomains_to_strip))
1266 << " input_host = " << test_case.input_host << std::endl
1267 << " subdomains_to_strip = " << test_case.subdomains_to_strip;
1268 }
1269 }
1270
1226 } // namespace 1271 } // namespace
1227 1272
1228 } // namespace url_formatter 1273 } // namespace url_formatter
OLDNEW
« 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