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

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: 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 unified diff | Download patch
« no previous file with comments | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Leave eTLD+1s (registry and domain) alone.
1252 {"google.com", "google.com", kStripWWW},
1253 {"www.com", "www.com", kStripWWW | kStripM},
1254 {"m.com", "m.com", kStripWWW | kStripM},
1255 {"mail.google.com", "mail.google.com", kStripWWW | kStripM},
1256 {"www.co.uk", "www.co.uk", kStripWWW},
1257 {"www.garden", "www.garden", kStripWWW},
1258 };
1259
1260 for (TestCase& test_case : cases) {
1261 EXPECT_EQ(test_case.expected, url_formatter::StripSubdomains(
1262 GURL("http://" + test_case.input_host),
1263 test_case.subdomains_to_strip))
1264 << " input_host = " << test_case.input_host << std::endl
1265 << " subdomains_to_strip = " << test_case.subdomains_to_strip;
1266 }
1267 }
1268
1226 } // namespace 1269 } // namespace
1227 1270
1228 } // namespace url_formatter 1271 } // namespace url_formatter
OLDNEW
« 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