OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 struct RFC1738Case { | 347 struct RFC1738Case { |
348 const char* host; | 348 const char* host; |
349 bool expected_output; | 349 bool expected_output; |
350 }; | 350 }; |
351 | 351 |
352 struct SuggestedFilenameCase { | 352 struct SuggestedFilenameCase { |
353 const char* url; | 353 const char* url; |
354 const char* content_disp_header; | 354 const char* content_disp_header; |
355 const char* referrer_charset; | 355 const char* referrer_charset; |
356 const wchar_t* default_filename; | 356 const char* default_filename; |
357 const wchar_t* expected_filename; | 357 const wchar_t* expected_filename; |
358 }; | 358 }; |
359 | 359 |
360 struct UrlTestData { | 360 struct UrlTestData { |
361 const char* description; | 361 const char* description; |
362 const char* input; | 362 const char* input; |
363 const std::wstring languages; | 363 const std::wstring languages; |
364 bool omit; | 364 bool omit; |
365 UnescapeRule::Type escape_rules; | 365 UnescapeRule::Type escape_rules; |
366 const std::wstring output; | 366 const std::wstring output; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 "", L""}, | 763 "", L""}, |
764 {"Content-Disposition: attachment; filename=%EC%98%88%EC%88%A", "", L""}, | 764 {"Content-Disposition: attachment; filename=%EC%98%88%EC%88%A", "", L""}, |
765 // %-escaped non-UTF-8 encoding is an "error" | 765 // %-escaped non-UTF-8 encoding is an "error" |
766 {"Content-Disposition: attachment; filename=%B7%DD%BD%D1.png", "", L""}, | 766 {"Content-Disposition: attachment; filename=%B7%DD%BD%D1.png", "", L""}, |
767 // Two RFC 2047 encoded words in a row without a space is an error. | 767 // Two RFC 2047 encoded words in a row without a space is an error. |
768 {"Content-Disposition: attachment; filename==?windows-1252?Q?caf=E3?=" | 768 {"Content-Disposition: attachment; filename==?windows-1252?Q?caf=E3?=" |
769 "=?iso-8859-7?b?4eIucG5nCg==?=", "", L""}, | 769 "=?iso-8859-7?b?4eIucG5nCg==?=", "", L""}, |
770 }; | 770 }; |
771 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 771 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
772 EXPECT_EQ(tests[i].expected, | 772 EXPECT_EQ(tests[i].expected, |
773 net::GetFileNameFromCD(tests[i].header_field, | 773 UTF8ToWide(net::GetFileNameFromCD(tests[i].header_field, |
774 tests[i].referrer_charset)); | 774 tests[i].referrer_charset))); |
775 } | 775 } |
776 } | 776 } |
777 | 777 |
778 TEST(NetUtilTest, IDNToUnicodeFast) { | 778 TEST(NetUtilTest, IDNToUnicodeFast) { |
779 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) { | 779 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) { |
780 for (size_t j = 0; j < arraysize(kLanguages); j++) { | 780 for (size_t j = 0; j < arraysize(kLanguages); j++) { |
781 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow | 781 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow |
782 if (j == 3 || j == 17 || j == 18) | 782 if (j == 3 || j == 17 || j == 18) |
783 continue; | 783 continue; |
784 std::wstring output; | 784 std::wstring output; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 EXPECT_EQ(L"", net::StripWWW(L"www.")); | 846 EXPECT_EQ(L"", net::StripWWW(L"www.")); |
847 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah")); | 847 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah")); |
848 EXPECT_EQ(L"blah", net::StripWWW(L"blah")); | 848 EXPECT_EQ(L"blah", net::StripWWW(L"blah")); |
849 } | 849 } |
850 | 850 |
851 TEST(NetUtilTest, GetSuggestedFilename) { | 851 TEST(NetUtilTest, GetSuggestedFilename) { |
852 const SuggestedFilenameCase test_cases[] = { | 852 const SuggestedFilenameCase test_cases[] = { |
853 {"http://www.google.com/", | 853 {"http://www.google.com/", |
854 "Content-disposition: attachment; filename=test.html", | 854 "Content-disposition: attachment; filename=test.html", |
855 "", | 855 "", |
856 L"", | 856 "", |
857 L"test.html"}, | 857 L"test.html"}, |
858 {"http://www.google.com/", | 858 {"http://www.google.com/", |
859 "Content-disposition: attachment; filename=\"test.html\"", | 859 "Content-disposition: attachment; filename=\"test.html\"", |
860 "", | 860 "", |
861 L"", | 861 "", |
862 L"test.html"}, | 862 L"test.html"}, |
863 {"http://www.google.com/path/test.html", | 863 {"http://www.google.com/path/test.html", |
864 "Content-disposition: attachment", | 864 "Content-disposition: attachment", |
865 "", | 865 "", |
866 L"", | 866 "", |
867 L"test.html"}, | 867 L"test.html"}, |
868 {"http://www.google.com/path/test.html", | 868 {"http://www.google.com/path/test.html", |
869 "Content-disposition: attachment;", | 869 "Content-disposition: attachment;", |
870 "", | 870 "", |
871 L"", | 871 "", |
872 L"test.html"}, | 872 L"test.html"}, |
873 {"http://www.google.com/", | 873 {"http://www.google.com/", |
874 "", | 874 "", |
875 "", | 875 "", |
876 L"", | 876 "", |
877 L"www.google.com"}, | 877 L"www.google.com"}, |
878 {"http://www.google.com/test.html", | 878 {"http://www.google.com/test.html", |
879 "", | 879 "", |
880 "", | 880 "", |
881 L"", | 881 "", |
882 L"test.html"}, | 882 L"test.html"}, |
883 // Now that we use googleurl's ExtractFileName, this case falls back | 883 // Now that we use googleurl's ExtractFileName, this case falls back |
884 // to the hostname. If this behavior is not desirable, we'd better | 884 // to the hostname. If this behavior is not desirable, we'd better |
885 // change ExtractFileName (in url_parse). | 885 // change ExtractFileName (in url_parse). |
886 {"http://www.google.com/path/", | 886 {"http://www.google.com/path/", |
887 "", | 887 "", |
888 "", | 888 "", |
889 L"", | 889 "", |
890 L"www.google.com"}, | 890 L"www.google.com"}, |
891 {"http://www.google.com/path", | 891 {"http://www.google.com/path", |
892 "", | 892 "", |
893 "", | 893 "", |
894 L"", | 894 "", |
895 L"path"}, | 895 L"path"}, |
896 {"file:///", | 896 {"file:///", |
897 "", | 897 "", |
898 "", | 898 "", |
899 L"", | 899 "", |
900 L"download"}, | 900 L"download"}, |
901 {"non-standard-scheme:", | 901 {"non-standard-scheme:", |
902 "", | 902 "", |
903 "", | 903 "", |
904 L"", | 904 "", |
905 L"download"}, | 905 L"download"}, |
906 {"http://www.google.com/", | 906 {"http://www.google.com/", |
907 "Content-disposition: attachment; filename =\"test.html\"", | 907 "Content-disposition: attachment; filename =\"test.html\"", |
908 "", | 908 "", |
909 L"download", | 909 "download", |
910 L"test.html"}, | 910 L"test.html"}, |
911 {"http://www.google.com/", | 911 {"http://www.google.com/", |
912 "", | 912 "", |
913 "", | 913 "", |
914 L"download", | 914 "download", |
915 L"download"}, | 915 L"download"}, |
916 {"http://www.google.com/", | 916 {"http://www.google.com/", |
917 "Content-disposition: attachment; filename=\"../test.html\"", | 917 "Content-disposition: attachment; filename=\"../test.html\"", |
918 "", | 918 "", |
919 L"", | 919 "", |
920 L"test.html"}, | 920 L"test.html"}, |
921 {"http://www.google.com/", | 921 {"http://www.google.com/", |
922 "Content-disposition: attachment; filename=\"..\"", | 922 "Content-disposition: attachment; filename=\"..\"", |
923 "", | 923 "", |
924 L"download", | 924 "download", |
925 L"download"}, | 925 L"download"}, |
926 {"http://www.google.com/test.html", | 926 {"http://www.google.com/test.html", |
927 "Content-disposition: attachment; filename=\"..\"", | 927 "Content-disposition: attachment; filename=\"..\"", |
928 "", | 928 "", |
929 L"download", | 929 "download", |
930 L"test.html"}, | 930 L"test.html"}, |
931 // Below is a small subset of cases taken from GetFileNameFromCD test above. | 931 // Below is a small subset of cases taken from GetFileNameFromCD test above. |
932 {"http://www.google.com/", | 932 {"http://www.google.com/", |
933 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" | 933 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" |
934 "%EC%98%88%EC%88%A0.jpg\"", | 934 "%EC%98%88%EC%88%A0.jpg\"", |
935 "", | 935 "", |
936 L"", | 936 "", |
937 L"\uc608\uc220 \uc608\uc220.jpg"}, | 937 L"\uc608\uc220 \uc608\uc220.jpg"}, |
938 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", | 938 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
939 "", | 939 "", |
940 "", | 940 "", |
941 L"download", | 941 "download", |
942 L"\uc608\uc220 \uc608\uc220.jpg"}, | 942 L"\uc608\uc220 \uc608\uc220.jpg"}, |
943 {"http://www.google.com/", | 943 {"http://www.google.com/", |
944 "Content-disposition: attachment;", | 944 "Content-disposition: attachment;", |
945 "", | 945 "", |
946 L"\uB2E4\uC6B4\uB85C\uB4DC", | 946 "\xEB\x8B\xA4\xEC\x9A\xB4\xEB\xA1\x9C\xEB\x93\x9C", |
947 L"\uB2E4\uC6B4\uB85C\uB4DC"}, | 947 L"\uB2E4\uC6B4\uB85C\uB4DC"}, |
948 {"http://www.google.com/", | 948 {"http://www.google.com/", |
949 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" | 949 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
950 "D13=2Epng?=\"", | 950 "D13=2Epng?=\"", |
951 "", | 951 "", |
952 L"download", | 952 "download", |
953 L"\u82b8\u88533.png"}, | 953 L"\u82b8\u88533.png"}, |
954 {"http://www.example.com/images?id=3", | 954 {"http://www.example.com/images?id=3", |
955 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", | 955 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", |
956 "iso-8859-1", | 956 "iso-8859-1", |
957 L"", | 957 "", |
958 L"caf\u00e9.png"}, | 958 L"caf\u00e9.png"}, |
959 {"http://www.example.com/images?id=3", | 959 {"http://www.example.com/images?id=3", |
960 "Content-Disposition: attachment; filename=caf\xe5.png", | 960 "Content-Disposition: attachment; filename=caf\xe5.png", |
961 "windows-1253", | 961 "windows-1253", |
962 L"", | 962 "", |
963 L"caf\u03b5.png"}, | 963 L"caf\u03b5.png"}, |
964 {"http://www.example.com/file?id=3", | 964 {"http://www.example.com/file?id=3", |
965 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", | 965 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", |
966 "GBK", | 966 "GBK", |
967 L"", | 967 "", |
968 L"\u4e0b\u8f7d.zip"}, | 968 L"\u4e0b\u8f7d.zip"}, |
969 // Invalid C-D header. Extracts filename from url. | 969 // Invalid C-D header. Extracts filename from url. |
970 {"http://www.google.com/test.html", | 970 {"http://www.google.com/test.html", |
971 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", | 971 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", |
972 "", | 972 "", |
973 L"", | 973 "", |
974 L"test.html"}, | 974 L"test.html"}, |
975 // about: and data: URLs | 975 // about: and data: URLs |
976 {"about:chrome", | 976 {"about:chrome", |
977 "", | 977 "", |
978 "", | 978 "", |
979 L"", | 979 "", |
980 L"download"}, | 980 L"download"}, |
981 {"data:,looks/like/a.path", | 981 {"data:,looks/like/a.path", |
982 "", | 982 "", |
983 "", | 983 "", |
984 L"", | 984 "", |
985 L"download"}, | 985 L"download"}, |
986 {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", | 986 {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", |
987 "", | 987 "", |
988 "", | 988 "", |
989 L"", | 989 "", |
990 L"download"}, | 990 L"download"}, |
991 }; | 991 }; |
992 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 992 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
993 std::wstring filename = net::GetSuggestedFilename( | 993 FilePath filename = net::GetSuggestedFilename( |
994 GURL(test_cases[i].url), test_cases[i].content_disp_header, | 994 GURL(test_cases[i].url), test_cases[i].content_disp_header, |
995 test_cases[i].referrer_charset, test_cases[i].default_filename); | 995 test_cases[i].referrer_charset, test_cases[i].default_filename); |
996 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename); | 996 #if defined(OS_WIN) |
| 997 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename.value()) |
| 998 #else |
| 999 EXPECT_EQ(WideToUTF8(test_cases[i].expected_filename), filename.value()) |
| 1000 #endif |
| 1001 << "Iteration " << i << ": " << test_cases[i].url; |
997 } | 1002 } |
998 } | 1003 } |
999 | 1004 |
1000 // This is currently a windows specific function. | 1005 // This is currently a windows specific function. |
1001 #if defined(OS_WIN) | 1006 #if defined(OS_WIN) |
1002 namespace { | 1007 namespace { |
1003 | 1008 |
1004 struct GetDirectoryListingEntryCase { | 1009 struct GetDirectoryListingEntryCase { |
1005 const wchar_t* name; | 1010 const wchar_t* name; |
1006 const char* raw_bytes; | 1011 const char* raw_bytes; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 net::SetExplicitlyAllowedPorts(invalid[i]); | 1439 net::SetExplicitlyAllowedPorts(invalid[i]); |
1435 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); | 1440 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); |
1436 } | 1441 } |
1437 | 1442 |
1438 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { | 1443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { |
1439 net::SetExplicitlyAllowedPorts(valid[i]); | 1444 net::SetExplicitlyAllowedPorts(valid[i]); |
1440 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); | 1445 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); |
1441 } | 1446 } |
1442 } | 1447 } |
1443 | 1448 |
OLD | NEW |