Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 1238 // 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.
| |
| 1239 {"m.google.com", "www.m.google.com", kStripWWW | kStripM}, | |
| 1240 {"www.google.com", "m.www.google.com", kStripWWW | kStripM}, | |
| 1241 | |
|
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.
| |
| 1242 // Leave eTLD+1s alone. | |
| 1243 {"google.com", "google.com", kStripWWW}, | |
| 1244 {"www.com", "www.com", kStripWWW | kStripM}, | |
| 1245 {"m.com", "m.com", kStripWWW | kStripM}, | |
| 1246 {"mail.google.com", "mail.google.com", kStripWWW | kStripM}, | |
| 1247 }; | |
| 1248 | |
| 1249 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.
| |
| 1250 EXPECT_EQ(cases[i].expected, url_formatter::StripSubdomains( | |
| 1251 GURL("http://" + cases[i].input_host), | |
| 1252 cases[i].subdomains_to_strip)) | |
| 1253 << " input_host = " << cases[i].input_host << std::endl | |
| 1254 << " subdomains_to_strip = " << cases[i].subdomains_to_strip; | |
| 1255 } | |
| 1256 } | |
| 1257 | |
| 1226 } // namespace | 1258 } // namespace |
| 1227 | 1259 |
| 1228 } // namespace url_formatter | 1260 } // namespace url_formatter |
| OLD | NEW |