OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 size_t input_offset; | 375 size_t input_offset; |
376 size_t output_offset; | 376 size_t output_offset; |
377 }; | 377 }; |
378 | 378 |
379 struct CompliantHostCase { | 379 struct CompliantHostCase { |
380 const char* host; | 380 const char* host; |
381 const char* desired_tld; | 381 const char* desired_tld; |
382 bool expected_output; | 382 bool expected_output; |
383 }; | 383 }; |
384 | 384 |
385 struct SuggestedFilenameCase { | 385 struct GenerateFilenameCase { |
386 const char* url; | 386 const char* url; |
387 const char* content_disp_header; | 387 const char* content_disp_header; |
388 const char* referrer_charset; | 388 const char* referrer_charset; |
389 const char* suggested_filename; | 389 const char* suggested_filename; |
| 390 const char* mime_type; |
390 const wchar_t* default_filename; | 391 const wchar_t* default_filename; |
391 const wchar_t* expected_filename; | 392 const wchar_t* expected_filename; |
392 }; | 393 }; |
393 | 394 |
394 struct UrlTestData { | 395 struct UrlTestData { |
395 const char* description; | 396 const char* description; |
396 const char* input; | 397 const char* input; |
397 const char* languages; | 398 const char* languages; |
398 FormatUrlTypes format_types; | 399 FormatUrlTypes format_types; |
399 UnescapeRule::Type escape_rules; | 400 UnescapeRule::Type escape_rules; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 std::string DumpIPNumber(const IPAddressNumber& v) { | 501 std::string DumpIPNumber(const IPAddressNumber& v) { |
501 std::string out; | 502 std::string out; |
502 for (size_t i = 0; i < v.size(); ++i) { | 503 for (size_t i = 0; i < v.size(); ++i) { |
503 if (i != 0) | 504 if (i != 0) |
504 out.append(","); | 505 out.append(","); |
505 out.append(base::IntToString(static_cast<int>(v[i]))); | 506 out.append(base::IntToString(static_cast<int>(v[i]))); |
506 } | 507 } |
507 return out; | 508 return out; |
508 } | 509 } |
509 | 510 |
| 511 void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case, |
| 512 size_t iteration, |
| 513 const char* suite) { |
| 514 #if defined(OS_WIN) |
| 515 string16 default_filename(test_case->default_filename); |
| 516 #else |
| 517 string16 default_filename(WideToUTF16(test_case->default_filename)); |
| 518 #endif |
| 519 FilePath file_path = GenerateFileName( |
| 520 GURL(test_case->url), test_case->content_disp_header, |
| 521 test_case->referrer_charset, test_case->suggested_filename, |
| 522 test_case->mime_type, default_filename); |
| 523 EXPECT_EQ(test_case->expected_filename, |
| 524 file_util::FilePathAsWString(file_path)) |
| 525 << "Iteration " << iteration << " of " << suite << ": " << test_case->url; |
| 526 } |
| 527 |
510 } // anonymous namespace | 528 } // anonymous namespace |
511 | 529 |
512 TEST(NetUtilTest, FileURLConversion) { | 530 TEST(NetUtilTest, FileURLConversion) { |
513 // a list of test file names and the corresponding URLs | 531 // a list of test file names and the corresponding URLs |
514 const FileCase round_trip_cases[] = { | 532 const FileCase round_trip_cases[] = { |
515 #if defined(OS_WIN) | 533 #if defined(OS_WIN) |
516 {L"C:\\foo\\bar.txt", "file:///C:/foo/bar.txt"}, | 534 {L"C:\\foo\\bar.txt", "file:///C:/foo/bar.txt"}, |
517 {L"\\\\some computer\\foo\\bar.txt", | 535 {L"\\\\some computer\\foo\\bar.txt", |
518 "file://some%20computer/foo/bar.txt"}, // UNC | 536 "file://some%20computer/foo/bar.txt"}, // UNC |
519 {L"D:\\Name;with%some symbols*#", | 537 {L"D:\\Name;with%some symbols*#", |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 } | 1058 } |
1041 } | 1059 } |
1042 | 1060 |
1043 TEST(NetUtilTest, StripWWW) { | 1061 TEST(NetUtilTest, StripWWW) { |
1044 EXPECT_EQ(string16(), StripWWW(string16())); | 1062 EXPECT_EQ(string16(), StripWWW(string16())); |
1045 EXPECT_EQ(string16(), StripWWW(ASCIIToUTF16("www."))); | 1063 EXPECT_EQ(string16(), StripWWW(ASCIIToUTF16("www."))); |
1046 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah"))); | 1064 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah"))); |
1047 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah"))); | 1065 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah"))); |
1048 } | 1066 } |
1049 | 1067 |
1050 TEST(NetUtilTest, GetSuggestedFilename) { | 1068 #if defined(OS_WIN) |
1051 const SuggestedFilenameCase test_cases[] = { | 1069 #define JPEG_EXT L".jpg" |
1052 {"http://www.google.com/", | 1070 #define HTML_EXT L".htm" |
1053 "Content-disposition: attachment; filename=test.html", | 1071 #define TXT_EXT L".txt" |
1054 "", | 1072 #define TAR_EXT L".tar" |
1055 "", | 1073 #elif defined(OS_MACOSX) |
1056 L"", | 1074 #define JPEG_EXT L".jpeg" |
1057 L"test.html"}, | 1075 #define HTML_EXT L".html" |
1058 {"http://www.google.com/", | 1076 #define TXT_EXT L".txt" |
1059 "Content-disposition: attachment; filename=\"test.html\"", | 1077 #define TAR_EXT L".tar" |
1060 "", | 1078 #else |
1061 "", | 1079 #define JPEG_EXT L".jpg" |
1062 L"", | 1080 #define HTML_EXT L".html" |
1063 L"test.html"}, | 1081 #define TXT_EXT L".txt" |
1064 {"http://www.google.com/", | 1082 #define TAR_EXT L".tar" |
1065 "Content-disposition: attachment; filename= \"test.html\"", | |
1066 "", | |
1067 "", | |
1068 L"", | |
1069 L"test.html"}, | |
1070 {"http://www.google.com/", | |
1071 "Content-disposition: attachment; filename = \"test.html\"", | |
1072 "", | |
1073 "", | |
1074 L"", | |
1075 L"test.html"}, | |
1076 {"http://www.google.com/", | |
1077 "Content-disposition: attachment; filename= ", | |
1078 "", | |
1079 "", | |
1080 L"", | |
1081 L"www.google.com"}, | |
1082 {"http://www.google.com/path/test.html", | |
1083 "Content-disposition: attachment", | |
1084 "", | |
1085 "", | |
1086 L"", | |
1087 L"test.html"}, | |
1088 {"http://www.google.com/path/test.html", | |
1089 "Content-disposition: attachment;", | |
1090 "", | |
1091 "", | |
1092 L"", | |
1093 L"test.html"}, | |
1094 {"http://www.google.com/", | |
1095 "", | |
1096 "", | |
1097 "", | |
1098 L"", | |
1099 L"www.google.com"}, | |
1100 {"http://www.google.com/test.html", | |
1101 "", | |
1102 "", | |
1103 "", | |
1104 L"", | |
1105 L"test.html"}, | |
1106 // Now that we use googleurl's ExtractFileName, this case falls back | |
1107 // to the hostname. If this behavior is not desirable, we'd better | |
1108 // change ExtractFileName (in url_parse). | |
1109 {"http://www.google.com/path/", | |
1110 "", | |
1111 "", | |
1112 "", | |
1113 L"", | |
1114 L"www.google.com"}, | |
1115 {"http://www.google.com/path", | |
1116 "", | |
1117 "", | |
1118 "", | |
1119 L"", | |
1120 L"path"}, | |
1121 {"file:///", | |
1122 "", | |
1123 "", | |
1124 "", | |
1125 L"", | |
1126 L"download"}, | |
1127 {"non-standard-scheme:", | |
1128 "", | |
1129 "", | |
1130 "", | |
1131 L"", | |
1132 L"download"}, | |
1133 {"http://www.google.com/", | |
1134 "Content-disposition: attachment; filename =\"test.html\"", | |
1135 "", | |
1136 "", | |
1137 L"download", | |
1138 L"test.html"}, | |
1139 {"http://www.google.com/", | |
1140 "", | |
1141 "", | |
1142 "", | |
1143 L"download", | |
1144 L"download"}, | |
1145 {"http://www.google.com/", | |
1146 "Content-disposition: attachment; filename=\"../test.html\"", | |
1147 "", | |
1148 "", | |
1149 L"", | |
1150 L"_test.html"}, | |
1151 {"http://www.google.com/", | |
1152 "Content-disposition: attachment; filename=\"..\\test.html\"", | |
1153 "", | |
1154 "", | |
1155 L"", | |
1156 L"_test.html"}, | |
1157 {"http://www.google.com/", | |
1158 "Content-disposition: attachment; filename=\"..\"", | |
1159 "", | |
1160 "", | |
1161 L"download", | |
1162 L"download"}, | |
1163 {"http://www.google.com/test.html", | |
1164 "Content-disposition: attachment; filename=\"..\"", | |
1165 "", | |
1166 "", | |
1167 L"download", | |
1168 L"test.html"}, | |
1169 // Below is a small subset of cases taken from GetFileNameFromCD test above. | |
1170 {"http://www.google.com/", | |
1171 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" | |
1172 "%EC%98%88%EC%88%A0.jpg\"", | |
1173 "", | |
1174 "", | |
1175 L"", | |
1176 L"\uc608\uc220 \uc608\uc220.jpg"}, | |
1177 {"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", | |
1178 "", | |
1179 "", | |
1180 "", | |
1181 L"download", | |
1182 L"\uc608\uc220 \uc608\uc220.jpg"}, | |
1183 {"http://www.google.com/", | |
1184 "Content-disposition: attachment;", | |
1185 "", | |
1186 "", | |
1187 L"\uB2E4\uC6B4\uB85C\uB4DC", | |
1188 L"\uB2E4\uC6B4\uB85C\uB4DC"}, | |
1189 {"http://www.google.com/", | |
1190 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" | |
1191 "D13=2Epng?=\"", | |
1192 "", | |
1193 "", | |
1194 L"download", | |
1195 L"\u82b8\u88533.png"}, | |
1196 {"http://www.example.com/images?id=3", | |
1197 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", | |
1198 "iso-8859-1", | |
1199 "", | |
1200 L"", | |
1201 L"caf\u00e9.png"}, | |
1202 {"http://www.example.com/images?id=3", | |
1203 "Content-Disposition: attachment; filename=caf\xe5.png", | |
1204 "windows-1253", | |
1205 "", | |
1206 L"", | |
1207 L"caf\u03b5.png"}, | |
1208 {"http://www.example.com/file?id=3", | |
1209 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", | |
1210 "GBK", | |
1211 "", | |
1212 L"", | |
1213 L"\u4e0b\u8f7d.zip"}, | |
1214 // Invalid C-D header. Extracts filename from url. | |
1215 {"http://www.google.com/test.html", | |
1216 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", | |
1217 "", | |
1218 "", | |
1219 L"", | |
1220 L"test.html"}, | |
1221 // about: and data: URLs | |
1222 {"about:chrome", | |
1223 "", | |
1224 "", | |
1225 "", | |
1226 L"", | |
1227 L"download"}, | |
1228 {"data:,looks/like/a.path", | |
1229 "", | |
1230 "", | |
1231 "", | |
1232 L"", | |
1233 L"download"}, | |
1234 {"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", | |
1235 "", | |
1236 "", | |
1237 "", | |
1238 L"", | |
1239 L"download"}, | |
1240 {"data:,looks/like/a.path", | |
1241 "", | |
1242 "", | |
1243 "", | |
1244 L"default_filename_is_given", | |
1245 L"default_filename_is_given"}, | |
1246 {"data:,looks/like/a.path", | |
1247 "", | |
1248 "", | |
1249 "", | |
1250 L"\u65e5\u672c\u8a9e", // Japanese Kanji. | |
1251 L"\u65e5\u672c\u8a9e"}, | |
1252 // Dotfiles. Ensures preceeding period(s) stripped. | |
1253 {"http://www.google.com/.test.html", | |
1254 "", | |
1255 "", | |
1256 "", | |
1257 L"", | |
1258 L"test.html"}, | |
1259 {"http://www.google.com/.test", | |
1260 "", | |
1261 "", | |
1262 "", | |
1263 L"", | |
1264 L"test"}, | |
1265 {"http://www.google.com/..test", | |
1266 "", | |
1267 "", | |
1268 "", | |
1269 L"", | |
1270 L"test"}, | |
1271 // The filename encoding is specified by the referrer charset. | |
1272 {"http://example.com/V%FDvojov%E1%20psychologie.doc", | |
1273 "", | |
1274 "iso-8859-1", | |
1275 "", | |
1276 L"", | |
1277 L"V\u00fdvojov\u00e1 psychologie.doc"}, | |
1278 {"http://www.google.com/test", | |
1279 "", | |
1280 "", | |
1281 "suggested", | |
1282 L"", | |
1283 L"suggested"}, | |
1284 // The content-disposition has higher precedence over the suggested name. | |
1285 {"http://www.google.com/test", | |
1286 "Content-disposition: attachment; filename=test.html", | |
1287 "", | |
1288 "suggested", | |
1289 L"", | |
1290 L"test.html"}, | |
1291 // The filename encoding doesn't match the referrer charset, the | |
1292 // system charset, or UTF-8. | |
1293 // TODO(jshin): we need to handle this case. | |
1294 #if 0 | |
1295 {"http://example.com/V%FDvojov%E1%20psychologie.doc", | |
1296 "", | |
1297 "utf-8", | |
1298 "", | |
1299 L"", | |
1300 L"V\u00fdvojov\u00e1 psychologie.doc", | |
1301 }, | |
1302 #endif | 1083 #endif |
| 1084 |
| 1085 TEST(NetUtilTest, GenerateSafeFileName) { |
| 1086 const struct { |
| 1087 const char* mime_type; |
| 1088 const FilePath::CharType* filename; |
| 1089 const FilePath::CharType* expected_filename; |
| 1090 } safe_tests[] = { |
| 1091 #if defined(OS_WIN) |
| 1092 { |
| 1093 "text/html", |
| 1094 FILE_PATH_LITERAL("C:\\foo\\bar.htm"), |
| 1095 FILE_PATH_LITERAL("C:\\foo\\bar.htm") |
| 1096 }, |
| 1097 { |
| 1098 "text/html", |
| 1099 FILE_PATH_LITERAL("C:\\foo\\bar.html"), |
| 1100 FILE_PATH_LITERAL("C:\\foo\\bar.html") |
| 1101 }, |
| 1102 { |
| 1103 "text/html", |
| 1104 FILE_PATH_LITERAL("C:\\foo\\bar"), |
| 1105 FILE_PATH_LITERAL("C:\\foo\\bar.htm") |
| 1106 }, |
| 1107 { |
| 1108 "image/png", |
| 1109 FILE_PATH_LITERAL("C:\\bar.html"), |
| 1110 FILE_PATH_LITERAL("C:\\bar.html") |
| 1111 }, |
| 1112 { |
| 1113 "image/png", |
| 1114 FILE_PATH_LITERAL("C:\\bar"), |
| 1115 FILE_PATH_LITERAL("C:\\bar.png") |
| 1116 }, |
| 1117 { |
| 1118 "text/html", |
| 1119 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), |
| 1120 FILE_PATH_LITERAL("C:\\foo\\bar.exe") |
| 1121 }, |
| 1122 { |
| 1123 "image/gif", |
| 1124 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), |
| 1125 FILE_PATH_LITERAL("C:\\foo\\bar.exe") |
| 1126 }, |
| 1127 { |
| 1128 "text/html", |
| 1129 FILE_PATH_LITERAL("C:\\foo\\google.com"), |
| 1130 FILE_PATH_LITERAL("C:\\foo\\google.com") |
| 1131 }, |
| 1132 { |
| 1133 "text/html", |
| 1134 FILE_PATH_LITERAL("C:\\foo\\con.htm"), |
| 1135 FILE_PATH_LITERAL("C:\\foo\\_con.htm") |
| 1136 }, |
| 1137 { |
| 1138 "text/html", |
| 1139 FILE_PATH_LITERAL("C:\\foo\\con"), |
| 1140 FILE_PATH_LITERAL("C:\\foo\\_con.htm") |
| 1141 }, |
| 1142 { |
| 1143 "text/html", |
| 1144 FILE_PATH_LITERAL("C:\\foo\\harmless.{not-really-this-may-be-a-guid}"), |
| 1145 FILE_PATH_LITERAL("C:\\foo\\harmless.download") |
| 1146 }, |
| 1147 { |
| 1148 "text/html", |
| 1149 FILE_PATH_LITERAL("C:\\foo\\harmless.local"), |
| 1150 FILE_PATH_LITERAL("C:\\foo\\harmless.download") |
| 1151 }, |
| 1152 { |
| 1153 "text/html", |
| 1154 FILE_PATH_LITERAL("C:\\foo\\harmless.lnk"), |
| 1155 FILE_PATH_LITERAL("C:\\foo\\harmless.download") |
| 1156 }, |
| 1157 { |
| 1158 "text/html", |
| 1159 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-"), |
| 1160 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-") |
| 1161 }, |
| 1162 #else // !defined(OS_WIN) |
| 1163 { |
| 1164 "text/html", |
| 1165 FILE_PATH_LITERAL("/foo/bar.htm"), |
| 1166 FILE_PATH_LITERAL("/foo/bar.htm") |
| 1167 }, |
| 1168 { |
| 1169 "text/html", |
| 1170 FILE_PATH_LITERAL("/foo/bar.html"), |
| 1171 FILE_PATH_LITERAL("/foo/bar.html") |
| 1172 }, |
| 1173 { |
| 1174 "text/html", |
| 1175 FILE_PATH_LITERAL("/foo/bar"), |
| 1176 FILE_PATH_LITERAL("/foo/bar.html") |
| 1177 }, |
| 1178 { |
| 1179 "image/png", |
| 1180 FILE_PATH_LITERAL("/bar.html"), |
| 1181 FILE_PATH_LITERAL("/bar.html") |
| 1182 }, |
| 1183 { |
| 1184 "image/png", |
| 1185 FILE_PATH_LITERAL("/bar"), |
| 1186 FILE_PATH_LITERAL("/bar.png") |
| 1187 }, |
| 1188 { |
| 1189 "image/gif", |
| 1190 FILE_PATH_LITERAL("/foo/bar.exe"), |
| 1191 FILE_PATH_LITERAL("/foo/bar.exe") |
| 1192 }, |
| 1193 { |
| 1194 "text/html", |
| 1195 FILE_PATH_LITERAL("/foo/google.com"), |
| 1196 FILE_PATH_LITERAL("/foo/google.com") |
| 1197 }, |
| 1198 { |
| 1199 "text/html", |
| 1200 FILE_PATH_LITERAL("/foo/con.htm"), |
| 1201 FILE_PATH_LITERAL("/foo/con.htm") |
| 1202 }, |
| 1203 { |
| 1204 "text/html", |
| 1205 FILE_PATH_LITERAL("/foo/con"), |
| 1206 FILE_PATH_LITERAL("/foo/con.html") |
| 1207 }, |
| 1208 #endif // !defined(OS_WIN) |
1303 }; | 1209 }; |
1304 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 1210 |
1305 std::wstring default_name = test_cases[i].default_filename; | 1211 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(safe_tests); ++i) { |
1306 string16 filename = GetSuggestedFilename( | 1212 FilePath file_path(safe_tests[i].filename); |
1307 GURL(test_cases[i].url), test_cases[i].content_disp_header, | 1213 GenerateSafeFileName(safe_tests[i].mime_type, &file_path); |
1308 test_cases[i].referrer_charset, test_cases[i].suggested_filename, | 1214 EXPECT_EQ(safe_tests[i].expected_filename, file_path.value()) |
1309 WideToUTF16(default_name)); | 1215 << "Iteration " << i; |
1310 EXPECT_EQ(std::wstring(test_cases[i].expected_filename), | |
1311 UTF16ToWide(filename)) | |
1312 << "Iteration " << i << ": " << test_cases[i].url; | |
1313 } | 1216 } |
1314 } | 1217 } |
1315 | 1218 |
| 1219 TEST(NetUtilTest, GenerateFileName) { |
| 1220 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 1221 // This test doesn't run when the locale is not UTF-8 because some of the |
| 1222 // string conversions fail. This is OK (we have the default value) but they |
| 1223 // don't match our expectations. |
| 1224 std::string locale = setlocale(LC_CTYPE, NULL); |
| 1225 StringToLowerASCII(&locale); |
| 1226 EXPECT_NE(std::string::npos, locale.find("utf-8")) |
| 1227 << "Your locale (" << locale << ") must be set to UTF-8 " |
| 1228 << "for this test to pass!"; |
| 1229 #endif |
| 1230 |
| 1231 // Tests whether the correct filename is selected from the the given |
| 1232 // parameters and that Content-Disposition headers are properly |
| 1233 // handled including failovers when the header is malformed. |
| 1234 const GenerateFilenameCase selection_tests[] = { |
| 1235 { |
| 1236 "http://www.google.com/", |
| 1237 "Content-disposition: attachment; filename=test.html", |
| 1238 "", |
| 1239 "", |
| 1240 "", |
| 1241 L"", |
| 1242 L"test.html" |
| 1243 }, |
| 1244 { |
| 1245 "http://www.google.com/", |
| 1246 "Content-disposition: attachment; filename=\"test.html\"", |
| 1247 "", |
| 1248 "", |
| 1249 "", |
| 1250 L"", |
| 1251 L"test.html" |
| 1252 }, |
| 1253 { |
| 1254 "http://www.google.com/", |
| 1255 "Content-disposition: attachment; filename= \"test.html\"", |
| 1256 "", |
| 1257 "", |
| 1258 "", |
| 1259 L"", |
| 1260 L"test.html" |
| 1261 }, |
| 1262 { |
| 1263 "http://www.google.com/", |
| 1264 "Content-disposition: attachment; filename = \"test.html\"", |
| 1265 "", |
| 1266 "", |
| 1267 "", |
| 1268 L"", |
| 1269 L"test.html" |
| 1270 }, |
| 1271 { // filename is whitespace. Should failover to URL host |
| 1272 "http://www.google.com/", |
| 1273 "Content-disposition: attachment; filename= ", |
| 1274 "", |
| 1275 "", |
| 1276 "", |
| 1277 L"", |
| 1278 L"www.google.com" |
| 1279 }, |
| 1280 { // No filename. |
| 1281 "http://www.google.com/path/test.html", |
| 1282 "Content-disposition: attachment", |
| 1283 "", |
| 1284 "", |
| 1285 "", |
| 1286 L"", |
| 1287 L"test.html" |
| 1288 }, |
| 1289 { // Ditto |
| 1290 "http://www.google.com/path/test.html", |
| 1291 "Content-disposition: attachment;", |
| 1292 "", |
| 1293 "", |
| 1294 "", |
| 1295 L"", |
| 1296 L"test.html" |
| 1297 }, |
| 1298 { // No C-D |
| 1299 "http://www.google.com/", |
| 1300 "", |
| 1301 "", |
| 1302 "", |
| 1303 "", |
| 1304 L"", |
| 1305 L"www.google.com" |
| 1306 }, |
| 1307 { |
| 1308 "http://www.google.com/test.html", |
| 1309 "", |
| 1310 "", |
| 1311 "", |
| 1312 "", |
| 1313 L"", |
| 1314 L"test.html" |
| 1315 }, |
| 1316 { // Now that we use googleurl's ExtractFileName, this case falls back to |
| 1317 // the hostname. If this behavior is not desirable, we'd better change |
| 1318 // ExtractFileName (in url_parse). |
| 1319 "http://www.google.com/path/", |
| 1320 "", |
| 1321 "", |
| 1322 "", |
| 1323 "", |
| 1324 L"", |
| 1325 L"www.google.com" |
| 1326 }, |
| 1327 { |
| 1328 "http://www.google.com/path", |
| 1329 "", |
| 1330 "", |
| 1331 "", |
| 1332 "", |
| 1333 L"", |
| 1334 L"path" |
| 1335 }, |
| 1336 { |
| 1337 "file:///", |
| 1338 "", |
| 1339 "", |
| 1340 "", |
| 1341 "", |
| 1342 L"", |
| 1343 L"download" |
| 1344 }, |
| 1345 { |
| 1346 "file:///path/testfile", |
| 1347 "", |
| 1348 "", |
| 1349 "", |
| 1350 "", |
| 1351 L"", |
| 1352 L"testfile" |
| 1353 }, |
| 1354 { |
| 1355 "non-standard-scheme:", |
| 1356 "", |
| 1357 "", |
| 1358 "", |
| 1359 "", |
| 1360 L"", |
| 1361 L"download" |
| 1362 }, |
| 1363 { // C-D should override default |
| 1364 "http://www.google.com/", |
| 1365 "Content-disposition: attachment; filename =\"test.html\"", |
| 1366 "", |
| 1367 "", |
| 1368 "", |
| 1369 L"download", |
| 1370 L"test.html" |
| 1371 }, |
| 1372 { // But the URL shouldn't |
| 1373 "http://www.google.com/", |
| 1374 "", |
| 1375 "", |
| 1376 "", |
| 1377 "", |
| 1378 L"download", |
| 1379 L"download" |
| 1380 }, |
| 1381 { |
| 1382 "http://www.google.com/", |
| 1383 "Content-disposition: attachment; filename=\"../test.html\"", |
| 1384 "", |
| 1385 "", |
| 1386 "", |
| 1387 L"", |
| 1388 L"_test.html" |
| 1389 }, |
| 1390 { |
| 1391 "http://www.google.com/", |
| 1392 "Content-disposition: attachment; filename=\"..\\test.html\"", |
| 1393 "", |
| 1394 "", |
| 1395 "", |
| 1396 L"", |
| 1397 L"_test.html" |
| 1398 }, |
| 1399 { // Filename disappears after leading and trailing periods are removed. |
| 1400 "http://www.google.com/", |
| 1401 "Content-disposition: attachment; filename=\"..\"", |
| 1402 "", |
| 1403 "", |
| 1404 "", |
| 1405 L"default", |
| 1406 L"default" |
| 1407 }, |
| 1408 { // C-D specified filename disappears. Should use last component of URL |
| 1409 // instead. |
| 1410 "http://www.google.com/test.html", |
| 1411 "Content-disposition: attachment; filename=\"..\"", |
| 1412 "", |
| 1413 "", |
| 1414 "", |
| 1415 L"download", |
| 1416 L"test.html" |
| 1417 }, |
| 1418 // Below is a small subset of cases taken from GetFileNameFromCD test above. |
| 1419 { |
| 1420 "http://www.google.com/", |
| 1421 "Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" |
| 1422 "%EC%98%88%EC%88%A0.jpg\"", |
| 1423 "", |
| 1424 "", |
| 1425 "", |
| 1426 L"", |
| 1427 L"\uc608\uc220 \uc608\uc220.jpg" |
| 1428 }, |
| 1429 { |
| 1430 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
| 1431 "", |
| 1432 "", |
| 1433 "", |
| 1434 "", |
| 1435 L"download", |
| 1436 L"\uc608\uc220 \uc608\uc220.jpg" |
| 1437 }, |
| 1438 { |
| 1439 "http://www.google.com/", |
| 1440 "Content-disposition: attachment;", |
| 1441 "", |
| 1442 "", |
| 1443 "", |
| 1444 L"\uB2E4\uC6B4\uB85C\uB4DC", |
| 1445 L"\uB2E4\uC6B4\uB85C\uB4DC" |
| 1446 }, |
| 1447 { |
| 1448 "http://www.google.com/", |
| 1449 "Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
| 1450 "D13=2Epng?=\"", |
| 1451 "", |
| 1452 "", |
| 1453 "", |
| 1454 L"download", |
| 1455 L"\u82b8\u88533.png" |
| 1456 }, |
| 1457 { |
| 1458 "http://www.example.com/images?id=3", |
| 1459 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", |
| 1460 "iso-8859-1", |
| 1461 "", |
| 1462 "", |
| 1463 L"", |
| 1464 L"caf\u00e9.png" |
| 1465 }, |
| 1466 { |
| 1467 "http://www.example.com/images?id=3", |
| 1468 "Content-Disposition: attachment; filename=caf\xe5.png", |
| 1469 "windows-1253", |
| 1470 "", |
| 1471 "", |
| 1472 L"", |
| 1473 L"caf\u03b5.png" |
| 1474 }, |
| 1475 { |
| 1476 "http://www.example.com/file?id=3", |
| 1477 "Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", |
| 1478 "GBK", |
| 1479 "", |
| 1480 "", |
| 1481 L"", |
| 1482 L"\u4e0b\u8f7d.zip" |
| 1483 }, |
| 1484 { // Invalid C-D header. Extracts filename from url. |
| 1485 "http://www.google.com/test.html", |
| 1486 "Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", |
| 1487 "", |
| 1488 "", |
| 1489 "", |
| 1490 L"", |
| 1491 L"test.html" |
| 1492 }, |
| 1493 // about: and data: URLs |
| 1494 { |
| 1495 "about:chrome", |
| 1496 "", |
| 1497 "", |
| 1498 "", |
| 1499 "", |
| 1500 L"", |
| 1501 L"download" |
| 1502 }, |
| 1503 { |
| 1504 "data:,looks/like/a.path", |
| 1505 "", |
| 1506 "", |
| 1507 "", |
| 1508 "", |
| 1509 L"", |
| 1510 L"download" |
| 1511 }, |
| 1512 { |
| 1513 "data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", |
| 1514 "", |
| 1515 "", |
| 1516 "", |
| 1517 "", |
| 1518 L"", |
| 1519 L"download" |
| 1520 }, |
| 1521 { |
| 1522 "data:,looks/like/a.path", |
| 1523 "", |
| 1524 "", |
| 1525 "", |
| 1526 "", |
| 1527 L"default_filename_is_given", |
| 1528 L"default_filename_is_given" |
| 1529 }, |
| 1530 { |
| 1531 "data:,looks/like/a.path", |
| 1532 "", |
| 1533 "", |
| 1534 "", |
| 1535 "", |
| 1536 L"\u65e5\u672c\u8a9e", // Japanese Kanji. |
| 1537 L"\u65e5\u672c\u8a9e" |
| 1538 }, |
| 1539 { // The filename encoding is specified by the referrer charset. |
| 1540 "http://example.com/V%FDvojov%E1%20psychologie.doc", |
| 1541 "", |
| 1542 "iso-8859-1", |
| 1543 "", |
| 1544 "", |
| 1545 L"", |
| 1546 L"V\u00fdvojov\u00e1 psychologie.doc" |
| 1547 }, |
| 1548 { // Suggested filename takes precedence over URL |
| 1549 "http://www.google.com/test", |
| 1550 "", |
| 1551 "", |
| 1552 "suggested", |
| 1553 "", |
| 1554 L"", |
| 1555 L"suggested" |
| 1556 }, |
| 1557 { // The content-disposition has higher precedence over the suggested name. |
| 1558 "http://www.google.com/test", |
| 1559 "Content-disposition: attachment; filename=test.html", |
| 1560 "", |
| 1561 "suggested", |
| 1562 "", |
| 1563 L"", |
| 1564 L"test.html" |
| 1565 }, |
| 1566 #if 0 |
| 1567 { // The filename encoding doesn't match the referrer charset, the system |
| 1568 // charset, or UTF-8. |
| 1569 // TODO(jshin): we need to handle this case. |
| 1570 "http://example.com/V%FDvojov%E1%20psychologie.doc", |
| 1571 "", |
| 1572 "utf-8", |
| 1573 "", |
| 1574 "", |
| 1575 L"", |
| 1576 L"V\u00fdvojov\u00e1 psychologie.doc", |
| 1577 }, |
| 1578 #endif |
| 1579 // Raw 8bit characters in C-D |
| 1580 { |
| 1581 "http://www.example.com/images?id=3", |
| 1582 "Content-Disposition: attachment; filename=caf\xc3\xa9.png", |
| 1583 "iso-8859-1", |
| 1584 "", |
| 1585 "image/png", |
| 1586 L"", |
| 1587 L"caf\u00e9.png" |
| 1588 }, |
| 1589 { |
| 1590 "http://www.example.com/images?id=3", |
| 1591 "Content-Disposition: attachment; filename=caf\xe5.png", |
| 1592 "windows-1253", |
| 1593 "", |
| 1594 "image/png", |
| 1595 L"", |
| 1596 L"caf\u03b5.png" |
| 1597 }, |
| 1598 { // No 'filename' keyword in the disposition, use the URL |
| 1599 "http://www.evil.com/my_download.txt", |
| 1600 "Content-Dispostion: a_file_name.txt", |
| 1601 "", |
| 1602 "", |
| 1603 "text/plain", |
| 1604 L"download", |
| 1605 L"my_download.txt" |
| 1606 }, |
| 1607 { // Spaces in the disposition file name |
| 1608 "http://www.frontpagehacker.com/a_download.exe", |
| 1609 "Content-Dispostion: filename=My Downloaded File.exe", |
| 1610 "", |
| 1611 "", |
| 1612 "application/octet-stream", |
| 1613 L"download", |
| 1614 L"My Downloaded File.exe" |
| 1615 }, |
| 1616 { // % encoded |
| 1617 "http://www.examples.com/", |
| 1618 "Content-Dispostion: attachment; " |
| 1619 "filename=\"%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg\"", |
| 1620 "", |
| 1621 "", |
| 1622 "image/jpeg", |
| 1623 L"download", |
| 1624 L"\uc608\uc220 \uc608\uc220.jpg" |
| 1625 }, |
| 1626 { // name= parameter |
| 1627 "http://www.examples.com/q.cgi?id=abc", |
| 1628 "Content-Dispostion: attachment; name=abc de.pdf", |
| 1629 "", |
| 1630 "", |
| 1631 "application/octet-stream", |
| 1632 L"download", |
| 1633 L"abc de.pdf" |
| 1634 }, |
| 1635 { |
| 1636 "http://www.example.com/path", |
| 1637 "Content-Dispostion: filename=\"=?EUC-JP?Q?=B7=DD=BD=D13=2Epng?=\"", |
| 1638 "", |
| 1639 "", |
| 1640 "image/png", |
| 1641 L"download", |
| 1642 L"\x82b8\x8853" L"3.png" |
| 1643 }, |
| 1644 { // The following two have invalid CD headers and filenames come from the |
| 1645 // URL. |
| 1646 "http://www.example.com/test%20123", |
| 1647 "Content-Dispostion: attachment; filename==?iiso88591?Q?caf=EG?=", |
| 1648 "", |
| 1649 "", |
| 1650 "image/jpeg", |
| 1651 L"download", |
| 1652 L"test 123" JPEG_EXT |
| 1653 }, |
| 1654 { |
| 1655 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
| 1656 "Content-Dispostion: malformed_disposition", |
| 1657 "", |
| 1658 "", |
| 1659 "image/jpeg", |
| 1660 L"download", |
| 1661 L"\uc608\uc220 \uc608\uc220.jpg" |
| 1662 }, |
| 1663 { // Invalid C-D. No filename from URL. Falls back to 'download'. |
| 1664 "http://www.google.com/path1/path2/", |
| 1665 "Content-Dispostion: attachment; filename==?iso88591?Q?caf=E3?", |
| 1666 "", |
| 1667 "", |
| 1668 "image/jpeg", |
| 1669 L"download", |
| 1670 L"download" JPEG_EXT |
| 1671 }, |
| 1672 }; |
| 1673 |
| 1674 // Tests filename generation. Once the correct filename is |
| 1675 // selected, they should be passed through the validation steps and |
| 1676 // a correct extension should be added if necessary. |
| 1677 const GenerateFilenameCase generation_tests[] = { |
| 1678 // Dotfiles. Ensures preceeding period(s) stripped. |
| 1679 { |
| 1680 "http://www.google.com/.test.html", |
| 1681 "", |
| 1682 "", |
| 1683 "", |
| 1684 "", |
| 1685 L"", |
| 1686 L"test.html" |
| 1687 }, |
| 1688 { |
| 1689 "http://www.google.com/.test", |
| 1690 "", |
| 1691 "", |
| 1692 "", |
| 1693 "", |
| 1694 L"", |
| 1695 L"test" |
| 1696 }, |
| 1697 { |
| 1698 "http://www.google.com/..test", |
| 1699 "", |
| 1700 "", |
| 1701 "", |
| 1702 "", |
| 1703 L"", |
| 1704 L"test" |
| 1705 }, |
| 1706 { // Disposition has relative paths, remove directory separators |
| 1707 "http://www.evil.com/my_download.txt", |
| 1708 "Content-Dispostion: filename=../../../../././../a_file_name.txt", |
| 1709 "", |
| 1710 "", |
| 1711 "text/plain", |
| 1712 L"download", |
| 1713 L"_.._.._.._._._.._a_file_name.txt" |
| 1714 }, |
| 1715 { // Disposition has parent directories, remove directory separators |
| 1716 "http://www.evil.com/my_download.txt", |
| 1717 "Content-Dispostion: filename=dir1/dir2/a_file_name.txt", |
| 1718 "", |
| 1719 "", |
| 1720 "text/plain", |
| 1721 L"download", |
| 1722 L"dir1_dir2_a_file_name.txt" |
| 1723 }, |
| 1724 { // Disposition has relative paths, remove directory separators |
| 1725 "http://www.evil.com/my_download.txt", |
| 1726 "Content-Dispostion: filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt", |
| 1727 "", |
| 1728 "", |
| 1729 "text/plain", |
| 1730 L"download", |
| 1731 L"_.._.._.._._._.._a_file_name.txt" |
| 1732 }, |
| 1733 { // Disposition has parent directories, remove directory separators |
| 1734 "http://www.evil.com/my_download.txt", |
| 1735 "Content-Dispostion: filename=dir1\\dir2\\a_file_name.txt", |
| 1736 "", |
| 1737 "", |
| 1738 "text/plain", |
| 1739 L"download", |
| 1740 L"dir1_dir2_a_file_name.txt" |
| 1741 }, |
| 1742 { // No useful information in disposition or URL, use default |
| 1743 "http://www.truncated.com/path/", |
| 1744 "", |
| 1745 "", |
| 1746 "", |
| 1747 "text/plain", |
| 1748 L"download", |
| 1749 L"download" TXT_EXT |
| 1750 }, |
| 1751 { // Filename looks like HTML? |
| 1752 "http://www.evil.com/get/malware/here", |
| 1753 "Content-Disposition: filename=\"<blink>Hello kitty</blink>\"", |
| 1754 "", |
| 1755 "", |
| 1756 "text/plain", |
| 1757 L"default", |
| 1758 L"-blink-Hello kitty-_blink-" TXT_EXT |
| 1759 }, |
| 1760 { // A normal avi should get .avi and not .avi.avi |
| 1761 "https://blah.google.com/misc/2.avi", |
| 1762 "", |
| 1763 "", |
| 1764 "", |
| 1765 "video/x-msvideo", |
| 1766 L"download", |
| 1767 L"2.avi" |
| 1768 }, |
| 1769 { // Extension generation |
| 1770 "http://www.example.com/my-cat", |
| 1771 "Content-Disposition: filename=my-cat", |
| 1772 "", |
| 1773 "", |
| 1774 "image/jpeg", |
| 1775 L"download", |
| 1776 L"my-cat" JPEG_EXT |
| 1777 }, |
| 1778 { |
| 1779 "http://www.example.com/my-cat", |
| 1780 "Content-Dispostion: filename=my-cat", |
| 1781 "", |
| 1782 "", |
| 1783 "text/plain", |
| 1784 L"download", |
| 1785 L"my-cat.txt" |
| 1786 }, |
| 1787 { |
| 1788 "http://www.example.com/my-cat", |
| 1789 "Content-Dispostion: filename=my-cat", |
| 1790 "", |
| 1791 "", |
| 1792 "text/html", |
| 1793 L"download", |
| 1794 L"my-cat" HTML_EXT |
| 1795 }, |
| 1796 { // Unknown MIME type |
| 1797 "http://www.example.com/my-cat", |
| 1798 "Content-Dispostion: filename=my-cat", |
| 1799 "", |
| 1800 "", |
| 1801 "dance/party", |
| 1802 L"download", |
| 1803 L"my-cat" |
| 1804 }, |
| 1805 { |
| 1806 "http://www.example.com/my-cat.jpg", |
| 1807 "Content-Dispostion: filename=my-cat.jpg", |
| 1808 "", |
| 1809 "", |
| 1810 "text/plain", |
| 1811 L"download", |
| 1812 L"my-cat.jpg" |
| 1813 }, |
| 1814 // Windows specific tests |
| 1815 #if defined(OS_WIN) |
| 1816 { |
| 1817 "http://www.goodguy.com/evil.exe", |
| 1818 "Content-Dispostion: filename=evil.exe", |
| 1819 "", |
| 1820 "", |
| 1821 "image/jpeg", |
| 1822 L"download", |
| 1823 L"evil.exe" |
| 1824 }, |
| 1825 { |
| 1826 "http://www.goodguy.com/ok.exe", |
| 1827 "Content-Dispostion: filename=ok.exe", |
| 1828 "", |
| 1829 "", |
| 1830 "binary/octet-stream", |
| 1831 L"download", |
| 1832 L"ok.exe" |
| 1833 }, |
| 1834 { |
| 1835 "http://www.goodguy.com/evil.dll", |
| 1836 "Content-Dispostion: filename=evil.dll", |
| 1837 "", |
| 1838 "", |
| 1839 "dance/party", |
| 1840 L"download", |
| 1841 L"evil.dll" |
| 1842 }, |
| 1843 { |
| 1844 "http://www.goodguy.com/evil.exe", |
| 1845 "Content-Dispostion: filename=evil", |
| 1846 "", |
| 1847 "", |
| 1848 "application/rss+xml", |
| 1849 L"download", |
| 1850 L"evil" |
| 1851 }, |
| 1852 // Test truncation of trailing dots and spaces |
| 1853 { |
| 1854 "http://www.goodguy.com/evil.exe ", |
| 1855 "Content-Dispostion: filename=evil.exe ", |
| 1856 "", |
| 1857 "", |
| 1858 "binary/octet-stream", |
| 1859 L"download", |
| 1860 L"evil.exe" |
| 1861 }, |
| 1862 { |
| 1863 "http://www.goodguy.com/evil.exe.", |
| 1864 "Content-Dispostion: filename=evil.exe.", |
| 1865 "", |
| 1866 "", |
| 1867 "binary/octet-stream", |
| 1868 L"download", |
| 1869 L"evil.exe" |
| 1870 }, |
| 1871 { |
| 1872 "http://www.goodguy.com/evil.exe. . .", |
| 1873 "Content-Dispostion: filename=evil.exe. . .", |
| 1874 "", |
| 1875 "", |
| 1876 "binary/octet-stream", |
| 1877 L"download", |
| 1878 L"evil.exe" |
| 1879 }, |
| 1880 { |
| 1881 "http://www.goodguy.com/evil.", |
| 1882 "Content-Dispostion: filename=evil.", |
| 1883 "", |
| 1884 "", |
| 1885 "binary/octet-stream", |
| 1886 L"download", |
| 1887 L"evil" |
| 1888 }, |
| 1889 { |
| 1890 "http://www.goodguy.com/. . . . .", |
| 1891 "Content-Dispostion: filename=. . . . .", |
| 1892 "", |
| 1893 "", |
| 1894 "binary/octet-stream", |
| 1895 L"download", |
| 1896 L"download" |
| 1897 }, |
| 1898 #endif // OS_WIN |
| 1899 { |
| 1900 "http://www.goodguy.com/utils.js", |
| 1901 "Content-Dispostion: filename=utils.js", |
| 1902 "", |
| 1903 "", |
| 1904 "application/x-javascript", |
| 1905 L"download", |
| 1906 L"utils.js" |
| 1907 }, |
| 1908 { |
| 1909 "http://www.goodguy.com/contacts.js", |
| 1910 "Content-Dispostion: filename=contacts.js", |
| 1911 "", |
| 1912 "", |
| 1913 "application/json", |
| 1914 L"download", |
| 1915 L"contacts.js" |
| 1916 }, |
| 1917 { |
| 1918 "http://www.goodguy.com/utils.js", |
| 1919 "Content-Dispostion: filename=utils.js", |
| 1920 "", |
| 1921 "", |
| 1922 "text/javascript", |
| 1923 L"download", |
| 1924 L"utils.js" |
| 1925 }, |
| 1926 { |
| 1927 "http://www.goodguy.com/utils.js", |
| 1928 "Content-Dispostion: filename=utils.js", |
| 1929 "", |
| 1930 "", |
| 1931 "text/javascript;version=2", |
| 1932 L"download", |
| 1933 L"utils.js" |
| 1934 }, |
| 1935 { |
| 1936 "http://www.goodguy.com/utils.js", |
| 1937 "Content-Dispostion: filename=utils.js", |
| 1938 "", |
| 1939 "", |
| 1940 "application/ecmascript", |
| 1941 L"download", |
| 1942 L"utils.js" |
| 1943 }, |
| 1944 { |
| 1945 "http://www.goodguy.com/utils.js", |
| 1946 "Content-Dispostion: filename=utils.js", |
| 1947 "", |
| 1948 "", |
| 1949 "application/ecmascript;version=4", |
| 1950 L"download", |
| 1951 L"utils.js" |
| 1952 }, |
| 1953 { |
| 1954 "http://www.goodguy.com/program.exe", |
| 1955 "Content-Dispostion: filename=program.exe", |
| 1956 "", |
| 1957 "", |
| 1958 "application/foo-bar", |
| 1959 L"download", |
| 1960 L"program.exe" |
| 1961 }, |
| 1962 { |
| 1963 "http://www.evil.com/../foo.txt", |
| 1964 "Content-Dispostion: filename=../foo.txt", |
| 1965 "", |
| 1966 "", |
| 1967 "text/plain", |
| 1968 L"download", |
| 1969 L"_foo.txt" |
| 1970 }, |
| 1971 { |
| 1972 "http://www.evil.com/..\\foo.txt", |
| 1973 "Content-Dispostion: filename=..\\foo.txt", |
| 1974 "", |
| 1975 "", |
| 1976 "text/plain", |
| 1977 L"download", |
| 1978 L"_foo.txt" |
| 1979 }, |
| 1980 { |
| 1981 "http://www.evil.com/.hidden", |
| 1982 "Content-Dispostion: filename=.hidden", |
| 1983 "", |
| 1984 "", |
| 1985 "text/plain", |
| 1986 L"download", |
| 1987 L"hidden" TXT_EXT |
| 1988 }, |
| 1989 { |
| 1990 "http://www.evil.com/trailing.", |
| 1991 "Content-Disposition: filename=trailing.", |
| 1992 "", |
| 1993 "", |
| 1994 "dance/party", |
| 1995 L"download", |
| 1996 L"trailing" |
| 1997 }, |
| 1998 { |
| 1999 "http://www.evil.com/trailing.", |
| 2000 "Content-Disposition: filename=trailing.", |
| 2001 "", |
| 2002 "", |
| 2003 "text/plain", |
| 2004 L"download", |
| 2005 L"trailing" TXT_EXT |
| 2006 }, |
| 2007 { |
| 2008 "http://www.evil.com/.", |
| 2009 "Content-Dispostion: filename=.", |
| 2010 "", |
| 2011 "", |
| 2012 "dance/party", |
| 2013 L"download", |
| 2014 L"download" |
| 2015 }, |
| 2016 { |
| 2017 "http://www.evil.com/..", |
| 2018 "Content-Dispostion: filename=..", |
| 2019 "", |
| 2020 "", |
| 2021 "dance/party", |
| 2022 L"download", |
| 2023 L"download" |
| 2024 }, |
| 2025 { |
| 2026 "http://www.evil.com/...", |
| 2027 "Content-Dispostion: filename=...", |
| 2028 "", |
| 2029 "", |
| 2030 "dance/party", |
| 2031 L"download", |
| 2032 L"download" |
| 2033 }, |
| 2034 { // Note that this one doesn't have "filename=" on it. |
| 2035 "http://www.evil.com/", |
| 2036 "Content-Dispostion: a_file_name.txt", |
| 2037 "", |
| 2038 "", |
| 2039 "image/jpeg", |
| 2040 L"download", |
| 2041 L"download" JPEG_EXT |
| 2042 }, |
| 2043 { |
| 2044 "http://www.evil.com/", |
| 2045 "Content-Dispostion: filename=", |
| 2046 "", |
| 2047 "", |
| 2048 "image/jpeg", |
| 2049 L"download", |
| 2050 L"download" JPEG_EXT |
| 2051 }, |
| 2052 { |
| 2053 "http://www.example.com/simple", |
| 2054 "Content-Dispostion: filename=simple", |
| 2055 "", |
| 2056 "", |
| 2057 "application/octet-stream", |
| 2058 L"download", |
| 2059 L"simple" |
| 2060 }, |
| 2061 // Reserved words on Windows |
| 2062 { |
| 2063 "http://www.goodguy.com/COM1", |
| 2064 "Content-Dispostion: filename=COM1", |
| 2065 "", |
| 2066 "", |
| 2067 "application/foo-bar", |
| 2068 L"download", |
| 2069 #if defined(OS_WIN) |
| 2070 L"_COM1" |
| 2071 #else |
| 2072 L"COM1" |
| 2073 #endif |
| 2074 }, |
| 2075 { |
| 2076 "http://www.goodguy.com/COM4.txt", |
| 2077 "Content-Dispostion: filename=COM4.txt", |
| 2078 "", |
| 2079 "", |
| 2080 "text/plain", |
| 2081 L"download", |
| 2082 #if defined(OS_WIN) |
| 2083 L"_COM4.txt" |
| 2084 #else |
| 2085 L"COM4.txt" |
| 2086 #endif |
| 2087 }, |
| 2088 { |
| 2089 "http://www.goodguy.com/lpt1.TXT", |
| 2090 "Content-Dispostion: filename=lpt1.TXT", |
| 2091 "", |
| 2092 "", |
| 2093 "text/plain", |
| 2094 L"download", |
| 2095 #if defined(OS_WIN) |
| 2096 L"_lpt1.TXT" |
| 2097 #else |
| 2098 L"lpt1.TXT" |
| 2099 #endif |
| 2100 }, |
| 2101 { |
| 2102 "http://www.goodguy.com/clock$.txt", |
| 2103 "Content-Dispostion: filename=clock$.txt", |
| 2104 "", |
| 2105 "", |
| 2106 "text/plain", |
| 2107 L"download", |
| 2108 #if defined(OS_WIN) |
| 2109 L"_clock$.txt" |
| 2110 #else |
| 2111 L"clock$.txt" |
| 2112 #endif |
| 2113 }, |
| 2114 { // Validation should also apply to sugested name |
| 2115 "http://www.goodguy.com/blah$.txt", |
| 2116 "Content-Dispostion: filename=clock$.txt", |
| 2117 "", |
| 2118 "clock$.txt", |
| 2119 "text/plain", |
| 2120 L"download", |
| 2121 #if defined(OS_WIN) |
| 2122 L"_clock$.txt" |
| 2123 #else |
| 2124 L"clock$.txt" |
| 2125 #endif |
| 2126 }, |
| 2127 { |
| 2128 "http://www.goodguy.com/mycom1.foo", |
| 2129 "Content-Dispostion: filename=mycom1.foo", |
| 2130 "", |
| 2131 "", |
| 2132 "text/plain", |
| 2133 L"download", |
| 2134 L"mycom1.foo" |
| 2135 }, |
| 2136 { |
| 2137 "http://www.badguy.com/Setup.exe.local", |
| 2138 "Content-Dispostion: filename=Setup.exe.local", |
| 2139 "", |
| 2140 "", |
| 2141 "application/foo-bar", |
| 2142 L"download", |
| 2143 #if defined(OS_WIN) |
| 2144 L"Setup.exe.download" |
| 2145 #else |
| 2146 L"Setup.exe.local" |
| 2147 #endif |
| 2148 }, |
| 2149 { |
| 2150 "http://www.badguy.com/Setup.exe.local", |
| 2151 "filename=Setup.exe.local.local", |
| 2152 "", |
| 2153 "", |
| 2154 "application/foo-bar", |
| 2155 L"download", |
| 2156 #if defined(OS_WIN) |
| 2157 L"Setup.exe.local.download" |
| 2158 #else |
| 2159 L"Setup.exe.local.local" |
| 2160 #endif |
| 2161 }, |
| 2162 { |
| 2163 "http://www.badguy.com/Setup.exe.lnk", |
| 2164 "Content-Dispostion: filename=Setup.exe.lnk", |
| 2165 "", |
| 2166 "", |
| 2167 "application/foo-bar", |
| 2168 L"download", |
| 2169 #if defined(OS_WIN) |
| 2170 L"Setup.exe.download" |
| 2171 #else |
| 2172 L"Setup.exe.lnk" |
| 2173 #endif |
| 2174 }, |
| 2175 { |
| 2176 "http://www.badguy.com/Desktop.ini", |
| 2177 "Content-Dispostion: filename=Desktop.ini", |
| 2178 "", |
| 2179 "", |
| 2180 "application/foo-bar", |
| 2181 L"download", |
| 2182 #if defined(OS_WIN) |
| 2183 L"_Desktop.ini" |
| 2184 #else |
| 2185 L"Desktop.ini" |
| 2186 #endif |
| 2187 }, |
| 2188 { |
| 2189 "http://www.badguy.com/Thumbs.db", |
| 2190 "Content-Dispostion: filename=Thumbs.db", |
| 2191 "", |
| 2192 "", |
| 2193 "application/foo-bar", |
| 2194 L"download", |
| 2195 #if defined(OS_WIN) |
| 2196 L"_Thumbs.db" |
| 2197 #else |
| 2198 L"Thumbs.db" |
| 2199 #endif |
| 2200 }, |
| 2201 { |
| 2202 "http://www.hotmail.com", |
| 2203 "Content-Dispostion: filename=source.jpg", |
| 2204 "", |
| 2205 "", |
| 2206 "application/x-javascript", |
| 2207 L"download", |
| 2208 L"source.jpg" |
| 2209 }, |
| 2210 { // http://crbug.com/5772. |
| 2211 "http://www.example.com/foo.tar.gz", |
| 2212 "Content-Dispostion: ", |
| 2213 "", |
| 2214 "", |
| 2215 "application/x-tar", |
| 2216 L"download", |
| 2217 L"foo.tar.gz" |
| 2218 }, |
| 2219 { // http://crbug.com/52250. |
| 2220 "http://www.example.com/foo.tgz", |
| 2221 "Content-Dispostion: ", |
| 2222 "", |
| 2223 "", |
| 2224 "application/x-tar", |
| 2225 L"download", |
| 2226 L"foo.tgz" |
| 2227 }, |
| 2228 { // http://crbug.com/7337. |
| 2229 "http://maged.lordaeron.org/blank.reg", |
| 2230 "Content-Dispostion: ", |
| 2231 "", |
| 2232 "", |
| 2233 "text/x-registry", |
| 2234 L"download", |
| 2235 L"blank.reg" |
| 2236 }, |
| 2237 { |
| 2238 "http://www.example.com/bar.tar", |
| 2239 "Content-Dispostion: ", |
| 2240 "", |
| 2241 "", |
| 2242 "application/x-tar", |
| 2243 L"download", |
| 2244 L"bar.tar" |
| 2245 }, |
| 2246 { |
| 2247 "http://www.example.com/bar.bogus", |
| 2248 "", |
| 2249 "", |
| 2250 "", |
| 2251 "application/x-tar", |
| 2252 L"download", |
| 2253 L"bar.bogus" |
| 2254 }, |
| 2255 { // http://crbug.com/20337 |
| 2256 "http://www.example.com/.download.txt", |
| 2257 "Content-Dispostion: filename=.download.txt", |
| 2258 "", |
| 2259 "", |
| 2260 "text/plain", |
| 2261 L"download", |
| 2262 L"download.txt" |
| 2263 }, |
| 2264 { // http://crbug.com/56855. |
| 2265 "http://www.example.com/bar.sh", |
| 2266 "", |
| 2267 "", |
| 2268 "", |
| 2269 "application/x-sh", |
| 2270 L"download", |
| 2271 L"bar.sh" |
| 2272 }, |
| 2273 }; |
| 2274 |
| 2275 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(selection_tests); ++i) |
| 2276 RunGenerateFileNameTestCase(&selection_tests[i], i, "selection"); |
| 2277 |
| 2278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generation_tests); ++i) |
| 2279 RunGenerateFileNameTestCase(&generation_tests[i], i, "generation"); |
| 2280 |
| 2281 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generation_tests); ++i) { |
| 2282 GenerateFilenameCase test_case = generation_tests[i]; |
| 2283 test_case.referrer_charset = "GBK"; |
| 2284 RunGenerateFileNameTestCase(&test_case, i, "generation (referrer=GBK)"); |
| 2285 } |
| 2286 } |
| 2287 |
1316 // This is currently a windows specific function. | 2288 // This is currently a windows specific function. |
1317 #if defined(OS_WIN) | 2289 #if defined(OS_WIN) |
1318 namespace { | 2290 namespace { |
1319 | 2291 |
1320 struct GetDirectoryListingEntryCase { | 2292 struct GetDirectoryListingEntryCase { |
1321 const wchar_t* name; | 2293 const wchar_t* name; |
1322 const char* raw_bytes; | 2294 const char* raw_bytes; |
1323 bool is_dir; | 2295 bool is_dir; |
1324 int64 filesize; | 2296 int64 filesize; |
1325 base::Time time; | 2297 base::Time time; |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 if (it->address[i] != 0) { | 3321 if (it->address[i] != 0) { |
2350 all_zeroes = false; | 3322 all_zeroes = false; |
2351 break; | 3323 break; |
2352 } | 3324 } |
2353 } | 3325 } |
2354 EXPECT_FALSE(all_zeroes); | 3326 EXPECT_FALSE(all_zeroes); |
2355 } | 3327 } |
2356 } | 3328 } |
2357 | 3329 |
2358 } // namespace net | 3330 } // namespace net |
OLD | NEW |