| 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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 | 818 |
| 819 /* | 819 /* |
| 820 {"unescape=true with some special characters", | 820 {"unescape=true with some special characters", |
| 821 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", | 821 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", |
| 822 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, | 822 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, |
| 823 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25}, | 823 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25}, |
| 824 */ | 824 */ |
| 825 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...". | 825 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...". |
| 826 | 826 |
| 827 // -------- omit http: -------- | 827 // -------- omit http: -------- |
| 828 {"omit http", "http://www.google.com/", kFormatUrlOmitHTTP, |
| 829 net::UnescapeRule::NORMAL, L"www.google.com/", 0}, |
| 830 |
| 831 {"omit http on bare scheme", "http://", kFormatUrlOmitAll, |
| 832 net::UnescapeRule::NORMAL, L"", 0}, |
| 833 |
| 828 {"omit http with user name", "http://user@example.com/foo", | 834 {"omit http with user name", "http://user@example.com/foo", |
| 829 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0}, | 835 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0}, |
| 830 | 836 |
| 831 {"omit http", "http://www.google.com/", kFormatUrlOmitHTTP, | |
| 832 net::UnescapeRule::NORMAL, L"www.google.com/", 0}, | |
| 833 | |
| 834 {"omit http with https", "https://www.google.com/", kFormatUrlOmitHTTP, | 837 {"omit http with https", "https://www.google.com/", kFormatUrlOmitHTTP, |
| 835 net::UnescapeRule::NORMAL, L"https://www.google.com/", 8}, | 838 net::UnescapeRule::NORMAL, L"https://www.google.com/", 8}, |
| 836 | 839 |
| 837 {"omit http starts with ftp.", "http://ftp.google.com/", | 840 {"omit http starts with ftp.", "http://ftp.google.com/", |
| 838 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/", | 841 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/", |
| 839 7}, | 842 7}, |
| 840 | 843 |
| 841 // -------- omit trailing slash on bare hostname -------- | 844 // -------- omit trailing slash on bare hostname -------- |
| 842 {"omit slash when it's the entire path", "http://www.google.com/", | 845 {"omit slash when it's the entire path", "http://www.google.com/", |
| 843 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, | 846 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 909 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 907 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, | 910 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, |
| 908 {"elide after host with path, query and ref", | 911 {"elide after host with path, query and ref", |
| 909 "http://google.com/foo?a=b#c", | 912 "http://google.com/foo?a=b#c", |
| 910 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 913 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 911 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, | 914 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, |
| 912 {"elide after host with repeated delimiters (sanity check)", | 915 {"elide after host with repeated delimiters (sanity check)", |
| 913 "http://google.com////???####", | 916 "http://google.com////???####", |
| 914 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 917 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 915 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, | 918 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0}, |
| 919 |
| 920 // -------- omit https -------- |
| 921 {"omit https", "https://www.google.com/", kFormatUrlExperimentalOmitHTTPS, |
| 922 net::UnescapeRule::NORMAL, L"www.google.com/", 0}, |
| 923 {"omit https but do not omit http", "http://www.google.com/", |
| 924 kFormatUrlExperimentalOmitHTTPS, net::UnescapeRule::NORMAL, |
| 925 L"http://www.google.com/", 7}, |
| 926 {"omit https, username, and password", |
| 927 "https://user:password@example.com/foo", |
| 928 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS, |
| 929 net::UnescapeRule::NORMAL, L"example.com/foo", 0}, |
| 930 {"omit https, but preserve user name and password", |
| 931 "https://user:password@example.com/foo", kFormatUrlExperimentalOmitHTTPS, |
| 932 net::UnescapeRule::NORMAL, L"user:password@example.com/foo", 14}, |
| 933 {"omit https should not affect hosts starting with ftp.", |
| 934 "https://ftp.google.com/", |
| 935 kFormatUrlOmitHTTP | kFormatUrlExperimentalOmitHTTPS, |
| 936 net::UnescapeRule::NORMAL, L"https://ftp.google.com/", 8}, |
| 916 }; | 937 }; |
| 917 | 938 |
| 918 for (size_t i = 0; i < arraysize(tests); ++i) { | 939 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 919 size_t prefix_len; | 940 size_t prefix_len; |
| 920 base::string16 formatted = FormatUrl( | 941 base::string16 formatted = FormatUrl( |
| 921 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules, | 942 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules, |
| 922 nullptr, &prefix_len, nullptr); | 943 nullptr, &prefix_len, nullptr); |
| 923 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; | 944 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; |
| 924 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; | 945 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; |
| 925 } | 946 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 net::UnescapeRule::NORMAL, elide_after_host_offsets); | 1291 net::UnescapeRule::NORMAL, elide_after_host_offsets); |
| 1271 CheckAdjustedOffsets("http://foo.com/abc#def", | 1292 CheckAdjustedOffsets("http://foo.com/abc#def", |
| 1272 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 1293 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 1273 net::UnescapeRule::NORMAL, elide_after_host_offsets); | 1294 net::UnescapeRule::NORMAL, elide_after_host_offsets); |
| 1274 CheckAdjustedOffsets("http://foo.com/a?a=b#f", | 1295 CheckAdjustedOffsets("http://foo.com/a?a=b#f", |
| 1275 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 1296 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 1276 net::UnescapeRule::NORMAL, elide_after_host_offsets); | 1297 net::UnescapeRule::NORMAL, elide_after_host_offsets); |
| 1277 CheckAdjustedOffsets("http://foo.com//??###", | 1298 CheckAdjustedOffsets("http://foo.com//??###", |
| 1278 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, | 1299 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost, |
| 1279 net::UnescapeRule::NORMAL, elide_after_host_offsets); | 1300 net::UnescapeRule::NORMAL, elide_after_host_offsets); |
| 1301 |
| 1302 const size_t omit_https_offsets[] = { |
| 1303 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, |
| 1304 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; |
| 1305 CheckAdjustedOffsets("https://www.google.com/", |
| 1306 kFormatUrlExperimentalOmitHTTPS, |
| 1307 net::UnescapeRule::NORMAL, omit_https_offsets); |
| 1308 |
| 1309 const size_t omit_https_with_auth_offsets[] = { |
| 1310 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, |
| 1311 kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, |
| 1312 6, 7, 8, 9, 10, 11, 12, 13, 14}; |
| 1313 CheckAdjustedOffsets("https://u:p@www.google.com/", |
| 1314 kFormatUrlOmitAll | kFormatUrlExperimentalOmitHTTPS, |
| 1315 net::UnescapeRule::NORMAL, omit_https_with_auth_offsets); |
| 1280 } | 1316 } |
| 1281 | 1317 |
| 1282 } // namespace | 1318 } // namespace |
| 1283 | 1319 |
| 1284 } // namespace url_formatter | 1320 } // namespace url_formatter |
| OLD | NEW |