| 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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 - don't do blind substring matches for www", |
| 953 "http://wwww.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| 954 net::UnescapeRule::NORMAL, L"http://wwww.google.com/", 7}, |
| 955 {"omit trivial subdomains - don't do blind substring matches for m", |
| 956 "http://foom.google.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| 957 net::UnescapeRule::NORMAL, L"http://foom.google.com/", 7}, |
| 958 {"omit trivial subdomains - don't crash on multiple delimiters", |
| 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 Loading... |
| 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_1[] = { |
| 1368 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, kNpos, 7, |
| 1369 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; |
| 1370 CheckAdjustedOffsets("http://www.m.google.com/foo/", |
| 1371 kFormatUrlExperimentalOmitTrivialSubdomains, |
| 1372 net::UnescapeRule::NORMAL, |
| 1373 strip_trivial_subdomains_offsets_1); |
| 1374 |
| 1375 const size_t strip_trivial_subdomains_offsets_2[] = { |
| 1376 0, 1, 2, 3, 4, 5, 6, 7, kNpos, 7, 8, 9, |
| 1377 10, kNpos, kNpos, kNpos, 10, 11, 12, 13, 14, 15, 16, 17}; |
| 1378 CheckAdjustedOffsets( |
| 1379 "http://m.en.www.foo.com/", kFormatUrlExperimentalOmitTrivialSubdomains, |
| 1380 net::UnescapeRule::NORMAL, strip_trivial_subdomains_offsets_2); |
| 1381 |
| 1382 const size_t strip_trivial_subdomains_from_idn_offsets[] = { |
| 1383 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, |
| 1384 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1385 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, |
| 1386 13, 14, 15, 16, 17, 18, 19}; |
| 1387 CheckAdjustedOffsets("http://www.xn--l8jvb1ey91xtjb.jp/foo/", |
| 1388 kFormatUrlExperimentalOmitTrivialSubdomains, |
| 1389 net::UnescapeRule::NORMAL, |
| 1390 strip_trivial_subdomains_from_idn_offsets); |
| 1316 } | 1391 } |
| 1317 | 1392 |
| 1318 } // namespace | 1393 } // namespace |
| 1319 | 1394 |
| 1320 } // namespace url_formatter | 1395 } // namespace url_formatter |
| OLD | NEW |