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

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

Issue 2961093002: Omnibox UI Experiments: Implement elide-after-host experiment. (Closed)
Patch Set: 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 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 ? WideToUTF16(idn_cases[i].unicode_output) 729 ? WideToUTF16(idn_cases[i].unicode_output)
730 : ASCIIToUTF16(idn_cases[i].input)); 730 : ASCIIToUTF16(idn_cases[i].input));
731 EXPECT_EQ(expected, output) << "input # " << i << ": \"" 731 EXPECT_EQ(expected, output) << "input # " << i << ": \""
732 << idn_cases[i].input << "\""; 732 << idn_cases[i].input << "\"";
733 } 733 }
734 } 734 }
735 735
736 TEST(UrlFormatterTest, FormatUrl) { 736 TEST(UrlFormatterTest, FormatUrl) {
737 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword; 737 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword;
738 const UrlTestData tests[] = { 738 const UrlTestData tests[] = {
739 {"Empty URL", "", default_format_type, net::UnescapeRule::NORMAL, L"", 739 {"Empty URL", "", default_format_type, net::UnescapeRule::NORMAL, L"", 0},
740 0},
741 740
742 {"Simple URL", "http://www.google.com/", default_format_type, 741 {"Simple URL", "http://www.google.com/", default_format_type,
743 net::UnescapeRule::NORMAL, L"http://www.google.com/", 7}, 742 net::UnescapeRule::NORMAL, L"http://www.google.com/", 7},
744 743
745 {"With a port number and a reference", 744 {"With a port number and a reference",
746 "http://www.google.com:8080/#\xE3\x82\xB0", default_format_type, 745 "http://www.google.com:8080/#\xE3\x82\xB0", default_format_type,
747 net::UnescapeRule::NORMAL, L"http://www.google.com:8080/#\x30B0", 7}, 746 net::UnescapeRule::NORMAL, L"http://www.google.com:8080/#\x30B0", 7},
748 747
749 // -------- IDN tests -------- 748 // -------- IDN tests --------
750 {"Japanese IDN with ja", "http://xn--l8jvb1ey91xtjb.jp", 749 {"Japanese IDN with ja", "http://xn--l8jvb1ey91xtjb.jp",
751 default_format_type, net::UnescapeRule::NORMAL, 750 default_format_type, net::UnescapeRule::NORMAL,
752 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, 751 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 default_format_type, net::UnescapeRule::NORMAL, 785 default_format_type, net::UnescapeRule::NORMAL,
787 L"mailto:foo@example.com", 7}, 786 L"mailto:foo@example.com", 7},
788 787
789 // -------- unescape flag tests -------- 788 // -------- unescape flag tests --------
790 {"Do not unescape", 789 {"Do not unescape",
791 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" 790 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
792 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" 791 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
793 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 792 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
794 default_format_type, net::UnescapeRule::NONE, 793 default_format_type, net::UnescapeRule::NONE,
795 // GURL parses %-encoded hostnames into Punycode. 794 // GURL parses %-encoded hostnames into Punycode.
796 L"http://\x30B0\x30FC\x30B0\x30EB.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB " 795 L"http://\x30B0\x30FC\x30B0\x30EB.jp/"
796 L"%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
797 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 797 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
798 7}, 798 7},
799 799
800 {"Unescape normally", 800 {"Unescape normally",
801 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" 801 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
802 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" 802 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
803 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 803 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB",
804 default_format_type, net::UnescapeRule::NORMAL, 804 default_format_type, net::UnescapeRule::NORMAL,
805 L"http://\x30B0\x30FC\x30B0\x30EB.jp/\x30B0\x30FC\x30B0\x30EB" 805 L"http://\x30B0\x30FC\x30B0\x30EB.jp/\x30B0\x30FC\x30B0\x30EB"
806 L"?q=\x30B0\x30FC\x30B0\x30EB", 806 L"?q=\x30B0\x30FC\x30B0\x30EB",
807 7}, 807 7},
808 808
809 {"Unescape normally with BiDi control character", 809 {"Unescape normally with BiDi control character",
810 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 810 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", default_format_type,
811 default_format_type, net::UnescapeRule::NORMAL, 811 net::UnescapeRule::NORMAL,
812 L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7}, 812 L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7},
813 813
814 {"Unescape normally including unescape spaces", 814 {"Unescape normally including unescape spaces",
815 "http://www.google.com/search?q=Hello%20World", 815 "http://www.google.com/search?q=Hello%20World", default_format_type,
816 default_format_type, net::UnescapeRule::SPACES, 816 net::UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World",
817 L"http://www.google.com/search?q=Hello World", 7}, 817 7},
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 with user name", "http://user@example.com/foo", 828 {"omit http with user name", "http://user@example.com/foo",
829 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0}, 829 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0},
830 830
831 {"omit http", "http://www.google.com/", kFormatUrlOmitHTTP, 831 {"omit http", "http://www.google.com/", kFormatUrlOmitHTTP,
832 net::UnescapeRule::NORMAL, L"www.google.com/", 0}, 832 net::UnescapeRule::NORMAL, L"www.google.com/", 0},
833 833
834 {"omit http with https", "https://www.google.com/", 834 {"omit http with https", "https://www.google.com/", kFormatUrlOmitHTTP,
835 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, 835 net::UnescapeRule::NORMAL, L"https://www.google.com/", 8},
836 L"https://www.google.com/", 8},
837 836
838 {"omit http starts with ftp.", "http://ftp.google.com/", 837 {"omit http starts with ftp.", "http://ftp.google.com/",
839 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/", 838 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/",
840 7}, 839 7},
841 840
842 // -------- omit trailing slash on bare hostname -------- 841 // -------- omit trailing slash on bare hostname --------
843 {"omit slash when it's the entire path", "http://www.google.com/", 842 {"omit slash when it's the entire path", "http://www.google.com/",
844 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, 843 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
845 L"http://www.google.com", 7}, 844 L"http://www.google.com", 7},
846 {"omit slash when there's a ref", "http://www.google.com/#ref", 845 {"omit slash when there's a ref", "http://www.google.com/#ref",
847 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, 846 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
848 L"http://www.google.com/#ref", 7}, 847 L"http://www.google.com/#ref", 7},
849 {"omit slash when there's a query", "http://www.google.com/?", 848 {"omit slash when there's a query", "http://www.google.com/?",
850 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, 849 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
851 L"http://www.google.com/?", 7}, 850 L"http://www.google.com/?", 7},
852 {"omit slash when it's not the entire path", "http://www.google.com/foo", 851 {"omit slash when it's not the entire path", "http://www.google.com/foo",
853 kFormatUrlOmitTrailingSlashOnBareHostname, 852 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
854 net::UnescapeRule::NORMAL, L"http://www.google.com/foo", 7}, 853 L"http://www.google.com/foo", 7},
855 {"omit slash for nonstandard URLs", "data:/", 854 {"omit slash for nonstandard URLs", "data:/",
856 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, 855 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
857 L"data:/", 5}, 856 L"data:/", 5},
858 {"omit slash for file URLs", "file:///", 857 {"omit slash for file URLs", "file:///",
859 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, 858 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL,
860 L"file:///", 7}, 859 L"file:///", 7},
861 860
862 // -------- view-source: -------- 861 // -------- view-source: --------
863 {"view-source", "view-source:http://xn--qcka1pmc.jp/", 862 {"view-source", "view-source:http://xn--qcka1pmc.jp/",
864 default_format_type, net::UnescapeRule::NORMAL, 863 default_format_type, net::UnescapeRule::NORMAL,
865 L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 19}, 864 L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 19},
866 865
867 {"view-source of view-source", 866 {"view-source of view-source",
868 "view-source:view-source:http://xn--qcka1pmc.jp/", 867 "view-source:view-source:http://xn--qcka1pmc.jp/", default_format_type,
869 default_format_type, net::UnescapeRule::NORMAL, 868 net::UnescapeRule::NORMAL,
870 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12}, 869 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
871 870
872 // view-source should omit http and trailing slash where non-view-source 871 // view-source should omit http and trailing slash where non-view-source
873 // would. 872 // would.
874 {"view-source omit http", "view-source:http://a.b/c", 873 {"view-source omit http", "view-source:http://a.b/c", kFormatUrlOmitAll,
875 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"view-source:a.b/c", 12}, 874 net::UnescapeRule::NORMAL, L"view-source:a.b/c", 12},
876 {"view-source omit http starts with ftp.", "view-source:http://ftp.b/c", 875 {"view-source omit http starts with ftp.", "view-source:http://ftp.b/c",
877 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, 876 kFormatUrlOmitAll, net::UnescapeRule::NORMAL,
878 L"view-source:http://ftp.b/c", 19}, 877 L"view-source:http://ftp.b/c", 19},
879 {"view-source omit slash when it's the entire path", 878 {"view-source omit slash when it's the entire path",
880 "view-source:http://a.b/", kFormatUrlOmitAll, 879 "view-source:http://a.b/", kFormatUrlOmitAll, net::UnescapeRule::NORMAL,
881 net::UnescapeRule::NORMAL, L"view-source:a.b", 12}, 880 L"view-source:a.b", 12},
881
882 // -------- ellipsize the path --------
883 {"ellipsize path but still strip trailing slashes", "http://google.com/",
884 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
885 net::UnescapeRule::NORMAL, L"google.com", 0},
886 {"ellipsize path in simple filename-only case", "http://google.com/foo",
887 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
888 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
889 {"ellipsize path in directory and file case", "http://google.com/ab/cd",
890 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
891 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
892 {"ellipsize path with query only", "http://google.com/?foo=bar",
893 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
894 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
895 {"ellipsize path with ref only", "http://google.com/#foobar",
896 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
897 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
898 {"ellipsize path with path and query only", "http://google.com/foo?a=b",
899 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
900 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
901 {"ellipsize path with path and ref only", "http://google.com/foo#c",
902 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
903 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
904 {"ellipsize path with query and ref only", "http://google.com/?a=b#c",
905 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
906 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
907 {"ellipsize path with path, query and ref", "http://google.com/foo?a=b#c",
908 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
909 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
910 {"ellipsize URL with repeated delimiters (sanity check)",
911 "http://google.com////???####",
912 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
913 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
882 }; 914 };
883 915
884 for (size_t i = 0; i < arraysize(tests); ++i) { 916 for (size_t i = 0; i < arraysize(tests); ++i) {
885 size_t prefix_len; 917 size_t prefix_len;
886 base::string16 formatted = FormatUrl( 918 base::string16 formatted = FormatUrl(
887 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules, 919 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules,
888 nullptr, &prefix_len, nullptr); 920 nullptr, &prefix_len, nullptr);
889 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; 921 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
890 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 922 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
891 } 923 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 CheckAdjustedOffsets("http://ftp.google.com/", kFormatUrlOmitHTTP, 1246 CheckAdjustedOffsets("http://ftp.google.com/", kFormatUrlOmitHTTP,
1215 net::UnescapeRule::NORMAL, 1247 net::UnescapeRule::NORMAL,
1216 omit_http_start_with_ftp_offsets); 1248 omit_http_start_with_ftp_offsets);
1217 1249
1218 const size_t omit_all_offsets[] = { 1250 const size_t omit_all_offsets[] = {
1219 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1251 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1220 0, 1, 2, 3, 4, 5, 6, 7 1252 0, 1, 2, 3, 4, 5, 6, 7
1221 }; 1253 };
1222 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, 1254 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll,
1223 net::UnescapeRule::NORMAL, omit_all_offsets); 1255 net::UnescapeRule::NORMAL, omit_all_offsets);
1256
1257 const size_t ellipsize_path_offsets[] = {
1258 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4,
1259 5, 6, 7, 8, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 9};
Peter Kasting 2017/06/28 20:54:35 Nit: Is this spacing git cl format's fault? It's
tommycli 2017/06/28 21:21:39 Yes, it's from git cl format. I didn't question it
1260 CheckAdjustedOffsets("http://foo.com/abcdefg",
1261 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1262 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1263 CheckAdjustedOffsets("http://foo.com/abc/def",
1264 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1265 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1266 CheckAdjustedOffsets("http://foo.com/abc?a=b",
1267 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1268 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1269 CheckAdjustedOffsets("http://foo.com/abc#def",
1270 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1271 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1272 CheckAdjustedOffsets("http://foo.com/a?a=b#f",
1273 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1274 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1275 CheckAdjustedOffsets("http://foo.com//??###",
1276 kFormatUrlOmitAll | kFormatUrlExperimentalEllipsizePath,
1277 net::UnescapeRule::NORMAL, ellipsize_path_offsets);
1224 } 1278 }
1225 1279
1226 } // namespace 1280 } // namespace
1227 1281
1228 } // namespace url_formatter 1282 } // 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