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

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

Issue 2961093002: Omnibox UI Experiments: Implement elide-after-host experiment. (Closed)
Patch Set: address pkasting comments 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
« no previous file with comments | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // -------- elide after host --------
883 {"elide after host but still strip trailing slashes",
884 "http://google.com/",
885 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
886 net::UnescapeRule::NORMAL, L"google.com", 0},
887 {"elide after host in simple filename-only case", "http://google.com/foo",
888 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
889 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
890 {"elide after host in directory and file case", "http://google.com/ab/cd",
891 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
892 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
893 {"elide after host with query only", "http://google.com/?foo=bar",
894 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
895 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
896 {"elide after host with ref only", "http://google.com/#foobar",
897 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
898 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
899 {"elide after host with path and query only", "http://google.com/foo?a=b",
900 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
901 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
902 {"elide after host with path and ref only", "http://google.com/foo#c",
903 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
904 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
905 {"elide after host with query and ref only", "http://google.com/?a=b#c",
906 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
907 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
908 {"elide after host with path, query and ref",
909 "http://google.com/foo?a=b#c",
910 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
911 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
912 {"elide after host with repeated delimiters (sanity check)",
913 "http://google.com////???####",
914 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
915 net::UnescapeRule::NORMAL, L"google.com/\x2026\x0000", 0},
882 }; 916 };
883 917
884 for (size_t i = 0; i < arraysize(tests); ++i) { 918 for (size_t i = 0; i < arraysize(tests); ++i) {
885 size_t prefix_len; 919 size_t prefix_len;
886 base::string16 formatted = FormatUrl( 920 base::string16 formatted = FormatUrl(
887 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules, 921 GURL(tests[i].input), tests[i].format_types, tests[i].escape_rules,
888 nullptr, &prefix_len, nullptr); 922 nullptr, &prefix_len, nullptr);
889 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; 923 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description;
890 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 924 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
891 } 925 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 CheckAdjustedOffsets("http://ftp.google.com/", kFormatUrlOmitHTTP, 1248 CheckAdjustedOffsets("http://ftp.google.com/", kFormatUrlOmitHTTP,
1215 net::UnescapeRule::NORMAL, 1249 net::UnescapeRule::NORMAL,
1216 omit_http_start_with_ftp_offsets); 1250 omit_http_start_with_ftp_offsets);
1217 1251
1218 const size_t omit_all_offsets[] = { 1252 const size_t omit_all_offsets[] = {
1219 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1253 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1220 0, 1, 2, 3, 4, 5, 6, 7 1254 0, 1, 2, 3, 4, 5, 6, 7
1221 }; 1255 };
1222 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll, 1256 CheckAdjustedOffsets("http://user@foo.com/", kFormatUrlOmitAll,
1223 net::UnescapeRule::NORMAL, omit_all_offsets); 1257 net::UnescapeRule::NORMAL, omit_all_offsets);
1258
1259 const size_t elide_after_host_offsets[] = {
1260 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4,
1261 5, 6, 7, 8, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 9};
1262 CheckAdjustedOffsets("http://foo.com/abcdefg",
1263 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1264 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1265 CheckAdjustedOffsets("http://foo.com/abc/def",
1266 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1267 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1268 CheckAdjustedOffsets("http://foo.com/abc?a=b",
1269 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1270 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1271 CheckAdjustedOffsets("http://foo.com/abc#def",
1272 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1273 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1274 CheckAdjustedOffsets("http://foo.com/a?a=b#f",
1275 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1276 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1277 CheckAdjustedOffsets("http://foo.com//??###",
1278 kFormatUrlOmitAll | kFormatUrlExperimentalElideAfterHost,
1279 net::UnescapeRule::NORMAL, elide_after_host_offsets);
1224 } 1280 }
1225 1281
1226 } // namespace 1282 } // namespace
1227 1283
1228 } // namespace url_formatter 1284 } // namespace url_formatter
OLDNEW
« no previous file with comments | « components/url_formatter/url_formatter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698