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

Side by Side Diff: components/url_formatter/url_formatter_unittest.cc

Issue 2966233002: Omnibox UI Experiments: Strip trivial subdomains (Closed)
Patch Set: make cast explicit for windows Created 3 years, 5 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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 "https://user:password@example.com/foo", 927 "https://user:password@example.com/foo",
928 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS, 928 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS,
929 net::UnescapeRule::NORMAL, L"example.com/foo", 0}, 929 net::UnescapeRule::NORMAL, L"example.com/foo", 0},
930 {"omit https, but preserve user name and password", 930 {"omit https, but preserve user name and password",
931 "https://user:password@example.com/foo", kFormatUrlExperimentalOmitHTTPS, 931 "https://user:password@example.com/foo", kFormatUrlExperimentalOmitHTTPS,
932 net::UnescapeRule::NORMAL, L"user:password@example.com/foo", 14}, 932 net::UnescapeRule::NORMAL, L"user:password@example.com/foo", 14},
933 {"omit https should not affect hosts starting with ftp.", 933 {"omit https should not affect hosts starting with ftp.",
934 "https://ftp.google.com/", 934 "https://ftp.google.com/",
935 kFormatUrlOmitHTTP | kFormatUrlExperimentalOmitHTTPS, 935 kFormatUrlOmitHTTP | kFormatUrlExperimentalOmitHTTPS,
936 net::UnescapeRule::NORMAL, L"https://ftp.google.com/", 8}, 936 net::UnescapeRule::NORMAL, L"https://ftp.google.com/", 8},
937
938 // -------- omit trivial subdomains --------
939 {"omit trivial subdomains - trim www", "http://www.google.com/",
940 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
941 L"http://google.com/", 7},
942 {"omit trivial subdomains - trim m", "http://m.google.com/",
943 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
944 L"http://google.com/", 7},
945 {"omit trivial subdomains - trim m and www", "http://m.www.google.com/",
946 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
947 L"http://google.com/", 7},
948 {"omit trivial subdomains - trim m from middle",
949 "http://en.m.wikipedia.org/",
950 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
951 L"http://en.wikipedia.org/", 7},
952 {"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.
953 "http://wwww.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
954 net::UnescapeRule::NORMAL, L"http://wwww.google.com/", 7},
955 {"omit trivial subdomains but leave subdomains ending in m",
956 "http://foom.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
957 net::UnescapeRule::NORMAL, L"http://foom.google.com/", 7},
958 {"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
959 "http://www...m..foobar...google.com/",
960 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
961 L"http://...foobar...google.com/", 7},
962
963 {"omit trivial subdomains - sanity check for ordinary subdomains",
964 "http://mail.yahoo.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
965 net::UnescapeRule::NORMAL, L"http://mail.yahoo.com/", 7},
966 {"omit trivial subdomains - sanity check for auth",
967 "http://www:m@google.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
968 net::UnescapeRule::NORMAL, L"http://www:m@google.com/", 13},
969 {"omit trivial subdomains - sanity check for path",
970 "http://google.com/www.m.foobar",
971 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
972 L"http://google.com/www.m.foobar", 7},
973 {"omit trivial subdomains - sanity check for IDN",
974 "http://www.xn--cy2a840a.m.xn--cy2a840a.com",
975 kFormatUrlExperimentalOmitTrivialSubdomains, net::UnescapeRule::NORMAL,
976 L"http://\x89c6\x9891.\x89c6\x9891.com/", 7},
977
978 {"omit trivial subdomains but leave registry and domain alone - trivial",
979 "http://google.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
980 net::UnescapeRule::NORMAL, L"http://google.com/", 7},
981 {"omit trivial subdomains but leave registry and domain alone - www",
982 "http://www.com/", kFormatUrlExperimentalOmitTrivialSubdomains,
983 net::UnescapeRule::NORMAL, L"http://www.com/", 7},
984 {"omit trivial subdomains but leave registry and domain alone - co.uk",
985 "http://m.co.uk/", kFormatUrlExperimentalOmitTrivialSubdomains,
986 net::UnescapeRule::NORMAL, L"http://m.co.uk/", 7},
937 }; 987 };
938 988
939 for (size_t i = 0; i < arraysize(tests); ++i) { 989 for (size_t i = 0; i < arraysize(tests); ++i) {
940 size_t prefix_len; 990 size_t prefix_len;
941 base::string16 formatted = FormatUrl( 991 base::string16 formatted = FormatUrl(
942 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules, 992 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules,
943 nullptr, &prefix_len, nullptr); 993 nullptr, &prefix_len, nullptr);
944 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; 994 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
945 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 995 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
946 } 996 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 kFormatUrlExperimentalOmitHTTPS, 1356 kFormatUrlExperimentalOmitHTTPS,
1307 net::UnescapeRule::NORMAL, omit_https_offsets); 1357 net::UnescapeRule::NORMAL, omit_https_offsets);
1308 1358
1309 const size_t omit_https_with_auth_offsets[] = { 1359 const size_t omit_https_with_auth_offsets[] = {
1310 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1360 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0,
1311 kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 1361 kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5,
1312 6, 7, 8, 9, 10, 11, 12, 13, 14}; 1362 6, 7, 8, 9, 10, 11, 12, 13, 14};
1313 CheckAdjustedOffsets("https://u:p@www.google.com/", 1363 CheckAdjustedOffsets("https://u:p@www.google.com/",
1314 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS, 1364 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS,
1315 net::UnescapeRule::NORMAL, omit_https_with_auth_offsets); 1365 net::UnescapeRule::NORMAL, omit_https_with_auth_offsets);
1366
1367 const size_t strip_trivial_subdomains_offsets[] = {
1368 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8,
1369 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
1370 CheckAdjustedOffsets(
1371 "http://www.google.com/foo/", kFormatUrlExperimentalOmitTrivialSubdomains,
1372 net::UnescapeRule::NORMAL, strip_trivial_subdomains_offsets);
1373
1374 const size_t strip_trivial_subdomains_from_idn_offsets[] = {
1375 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos,
1376 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos,
1377 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12,
1378 13, 14, 15, 16, 17, 18, 19};
1379 CheckAdjustedOffsets("http://www.xn--l8jvb1ey91xtjb.jp/foo/",
1380 kFormatUrlExperimentalOmitTrivialSubdomains,
1381 net::UnescapeRule::NORMAL,
1382 strip_trivial_subdomains_from_idn_offsets);
1316 } 1383 }
1317 1384
1318 } // namespace 1385 } // namespace
1319 1386
1320 } // namespace url_formatter 1387 } // 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