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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 343014: Enable localization of default downloaded filename.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.cc ('k') | webkit/glue/weburlloader_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/sys_string_conversions.h"
8 #include "base/time.h" 9 #include "base/time.h"
9 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 #if defined(OS_WIN) 15 #if defined(OS_WIN)
15 #include <ws2tcpip.h> 16 #include <ws2tcpip.h>
16 #else 17 #else
17 #include <netdb.h> 18 #include <netdb.h>
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 347
347 struct RFC1738Case { 348 struct RFC1738Case {
348 const char* host; 349 const char* host;
349 bool expected_output; 350 bool expected_output;
350 }; 351 };
351 352
352 struct SuggestedFilenameCase { 353 struct SuggestedFilenameCase {
353 const char* url; 354 const char* url;
354 const char* content_disp_header; 355 const char* content_disp_header;
355 const char* referrer_charset; 356 const char* referrer_charset;
356 const char* default_filename; 357 const wchar_t* default_filename;
357 const wchar_t* expected_filename; 358 const wchar_t* expected_filename;
358 }; 359 };
359 360
360 struct UrlTestData { 361 struct UrlTestData {
361 const char* description; 362 const char* description;
362 const char* input; 363 const char* input;
363 const std::wstring languages; 364 const std::wstring languages;
364 bool omit; 365 bool omit;
365 UnescapeRule::Type escape_rules; 366 UnescapeRule::Type escape_rules;
366 const std::wstring output; 367 const std::wstring output;
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 EXPECT_EQ(L"", net::StripWWW(L"www.")); 847 EXPECT_EQ(L"", net::StripWWW(L"www."));
847 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah")); 848 EXPECT_EQ(L"blah", net::StripWWW(L"www.blah"));
848 EXPECT_EQ(L"blah", net::StripWWW(L"blah")); 849 EXPECT_EQ(L"blah", net::StripWWW(L"blah"));
849 } 850 }
850 851
851 TEST(NetUtilTest, GetSuggestedFilename) { 852 TEST(NetUtilTest, GetSuggestedFilename) {
852 const SuggestedFilenameCase test_cases[] = { 853 const SuggestedFilenameCase test_cases[] = {
853 {"http://www.google.com/", 854 {"http://www.google.com/",
854 "Content-disposition: attachment; filename=test.html", 855 "Content-disposition: attachment; filename=test.html",
855 "", 856 "",
856 "", 857 L"",
857 L"test.html"}, 858 L"test.html"},
858 {"http://www.google.com/", 859 {"http://www.google.com/",
859 "Content-disposition: attachment; filename=\"test.html\"", 860 "Content-disposition: attachment; filename=\"test.html\"",
860 "", 861 "",
861 "", 862 L"",
862 L"test.html"}, 863 L"test.html"},
863 {"http://www.google.com/path/test.html", 864 {"http://www.google.com/path/test.html",
864 "Content-disposition: attachment", 865 "Content-disposition: attachment",
865 "", 866 "",
866 "", 867 L"",
867 L"test.html"}, 868 L"test.html"},
868 {"http://www.google.com/path/test.html", 869 {"http://www.google.com/path/test.html",
869 "Content-disposition: attachment;", 870 "Content-disposition: attachment;",
870 "", 871 "",
871 "", 872 L"",
872 L"test.html"}, 873 L"test.html"},
873 {"http://www.google.com/", 874 {"http://www.google.com/",
874 "", 875 "",
875 "", 876 "",
876 "", 877 L"",
877 L"www.google.com"}, 878 L"www.google.com"},
878 {"http://www.google.com/test.html", 879 {"http://www.google.com/test.html",
879 "", 880 "",
880 "", 881 "",
881 "", 882 L"",
882 L"test.html"}, 883 L"test.html"},
883 // Now that we use googleurl's ExtractFileName, this case falls back 884 // Now that we use googleurl's ExtractFileName, this case falls back
884 // to the hostname. If this behavior is not desirable, we'd better 885 // to the hostname. If this behavior is not desirable, we'd better
885 // change ExtractFileName (in url_parse). 886 // change ExtractFileName (in url_parse).
886 {"http://www.google.com/path/", 887 {"http://www.google.com/path/",
887 "", 888 "",
888 "", 889 "",
889 "", 890 L"",
890 L"www.google.com"}, 891 L"www.google.com"},
891 {"http://www.google.com/path", 892 {"http://www.google.com/path",
892 "", 893 "",
893 "", 894 "",
894 "", 895 L"",
895 L"path"}, 896 L"path"},
896 {"file:///", 897 {"file:///",
897 "", 898 "",
898 "", 899 "",
899 "", 900 L"",
900 L"download"}, 901 L"download"},
901 {"non-standard-scheme:", 902 {"non-standard-scheme:",
902 "", 903 "",
903 "", 904 "",
904 "", 905 L"",
905 L"download"}, 906 L"download"},
906 {"http://www.google.com/", 907 {"http://www.google.com/",
907 "Content-disposition: attachment; filename =\"test.html\"", 908 "Content-disposition: attachment; filename =\"test.html\"",
908 "", 909 "",
909 "download", 910 L"download",
910 L"test.html"}, 911 L"test.html"},
911 {"http://www.google.com/", 912 {"http://www.google.com/",
912 "", 913 "",
913 "", 914 "",
914 "download", 915 L"download",
915 L"download"}, 916 L"download"},
916 {"http://www.google.com/", 917 {"http://www.google.com/",
917 "Content-disposition: attachment; filename=\"../test.html\"", 918 "Content-disposition: attachment; filename=\"../test.html\"",
918 "", 919 "",
919 "", 920 L"",
920 L"test.html"}, 921 L"test.html"},
921 {"http://www.google.com/", 922 {"http://www.google.com/",
922 "Content-disposition: attachment; filename=\"..\"", 923 "Content-disposition: attachment; filename=\"..\"",
923 "", 924 "",
924 "download", 925 L"download",
925 L"download"}, 926 L"download"},
926 {"http://www.google.com/test.html", 927 {"http://www.google.com/test.html",
927 "Content-disposition: attachment; filename=\"..\"", 928 "Content-disposition: attachment; filename=\"..\"",
928 "", 929 "",
929 "download", 930 L"download",
930 L"test.html"}, 931 L"test.html"},
931 // Below is a small subset of cases taken from GetFileNameFromCD test above. 932 // Below is a small subset of cases taken from GetFileNameFromCD test above.
932 {"http://www.google.com/", 933 {"http://www.google.com/",
933 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" 934 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20"
934 "%EC%98%88%EC%88%A0.jpg\"", 935 "%EC%98%88%EC%88%A0.jpg\"",
935 "", 936 "",
936 "", 937 L"",
937 L"\uc608\uc220 \uc608\uc220.jpg"}, 938 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", 939 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
939 "", 940 "",
940 "", 941 "",
941 "download", 942 L"download",
942 L"\uc608\uc220 \uc608\uc220.jpg"}, 943 L"\uc608\uc220 \uc608\uc220.jpg"},
943 {"http://www.google.com/", 944 {"http://www.google.com/",
944 "Content-disposition: attachment;", 945 "Content-disposition: attachment;",
945 "", 946 "",
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 L"\uB2E4\uC6B4\uB85C\uB4DC"},
948 {"http://www.google.com/", 949 {"http://www.google.com/",
949 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" 950 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD="
950 "D13=2Epng?=\"", 951 "D13=2Epng?=\"",
951 "", 952 "",
952 "download", 953 L"download",
953 L"\u82b8\u88533.png"}, 954 L"\u82b8\u88533.png"},
954 {"http://www.example.com/images?id=3", 955 {"http://www.example.com/images?id=3",
955 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", 956 "Content-Disposition: attachment; filename=caf\xc3\xa9.png",
956 "iso-8859-1", 957 "iso-8859-1",
957 "", 958 L"",
958 L"caf\u00e9.png"}, 959 L"caf\u00e9.png"},
959 {"http://www.example.com/images?id=3", 960 {"http://www.example.com/images?id=3",
960 "Content-Disposition: attachment; filename=caf\xe5.png", 961 "Content-Disposition: attachment; filename=caf\xe5.png",
961 "windows-1253", 962 "windows-1253",
962 "", 963 L"",
963 L"caf\u03b5.png"}, 964 L"caf\u03b5.png"},
964 {"http://www.example.com/file?id=3", 965 {"http://www.example.com/file?id=3",
965 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", 966 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip",
966 "GBK", 967 "GBK",
967 "", 968 L"",
968 L"\u4e0b\u8f7d.zip"}, 969 L"\u4e0b\u8f7d.zip"},
969 // Invalid C-D header. Extracts filename from url. 970 // Invalid C-D header. Extracts filename from url.
970 {"http://www.google.com/test.html", 971 {"http://www.google.com/test.html",
971 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", 972 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=",
972 "", 973 "",
973 "", 974 L"",
974 L"test.html"}, 975 L"test.html"},
975 // about: and data: URLs 976 // about: and data: URLs
976 {"about:chrome", 977 {"about:chrome",
977 "", 978 "",
978 "", 979 "",
979 "", 980 L"",
980 L"download"}, 981 L"download"},
981 {"data:,looks/like/a.path", 982 {"data:,looks/like/a.path",
982 "", 983 "",
983 "", 984 "",
984 "", 985 L"",
985 L"download"}, 986 L"download"},
986 {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", 987 {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=",
987 "", 988 "",
988 "", 989 "",
990 L"",
991 L"download"},
992 {"data:,looks/like/a.path",
989 "", 993 "",
990 L"download"}, 994 "",
995 L"default_filename_is_given",
996 L"default_filename_is_given"},
997 {"data:,looks/like/a.path",
998 "",
999 "",
1000 L"\u65e5\u672c\u8a9e", // Japanese Kanji.
1001 L"\u65e5\u672c\u8a9e"},
991 }; 1002 };
992 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 1003 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
1004 #if defined(OS_WIN)
1005 FilePath default_name(test_cases[i].default_filename);
1006 #else
1007 FilePath default_name(
1008 base::SysWideToNativeMB(test_cases[i].default_filename));
1009 #endif
993 FilePath filename = net::GetSuggestedFilename( 1010 FilePath filename = net::GetSuggestedFilename(
994 GURL(test_cases[i].url), test_cases[i].content_disp_header, 1011 GURL(test_cases[i].url), test_cases[i].content_disp_header,
995 test_cases[i].referrer_charset, test_cases[i].default_filename); 1012 test_cases[i].referrer_charset, default_name);
996 #if defined(OS_WIN) 1013 #if defined(OS_WIN)
997 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename.value()) 1014 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename.value())
998 #else 1015 #else
999 EXPECT_EQ(WideToUTF8(test_cases[i].expected_filename), filename.value()) 1016 EXPECT_EQ(base::SysWideToNativeMB(test_cases[i].expected_filename),
1017 filename.value())
1000 #endif 1018 #endif
1001 << "Iteration " << i << ": " << test_cases[i].url; 1019 << "Iteration " << i << ": " << test_cases[i].url;
1002 } 1020 }
1003 } 1021 }
1004 1022
1005 // This is currently a windows specific function. 1023 // This is currently a windows specific function.
1006 #if defined(OS_WIN) 1024 #if defined(OS_WIN)
1007 namespace { 1025 namespace {
1008 1026
1009 struct GetDirectoryListingEntryCase { 1027 struct GetDirectoryListingEntryCase {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 net::SetExplicitlyAllowedPorts(invalid[i]); 1457 net::SetExplicitlyAllowedPorts(invalid[i]);
1440 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); 1458 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size()));
1441 } 1459 }
1442 1460
1443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { 1461 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) {
1444 net::SetExplicitlyAllowedPorts(valid[i]); 1462 net::SetExplicitlyAllowedPorts(valid[i]);
1445 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); 1463 EXPECT_EQ(i, net::explicitly_allowed_ports.size());
1446 } 1464 }
1447 } 1465 }
1448 1466
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | webkit/glue/weburlloader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698