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

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

Issue 640713002: Generated FIlename different from Content Disposition string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittests Created 6 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
« no previous file with comments | « net/base/filename_util_internal.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/filename_util.h" 5 #include "net/base/filename_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 { // The content-disposition has higher precedence over the suggested name. 803 { // The content-disposition has higher precedence over the suggested name.
804 __LINE__, 804 __LINE__,
805 "http://www.google.com/test", 805 "http://www.google.com/test",
806 "attachment; filename=test.html", 806 "attachment; filename=test.html",
807 "", 807 "",
808 "suggested", 808 "suggested",
809 "", 809 "",
810 L"", 810 L"",
811 L"test.html" 811 L"test.html"
812 }, 812 },
813 {
814 __LINE__,
815 "http://www.google.com/test",
816 "attachment; filename=test",
817 "utf-8",
818 "",
819 "image/png",
820 L"",
821 L"test"
822 },
813 #if 0 823 #if 0
814 { // The filename encoding doesn't match the referrer charset, the system 824 { // The filename encoding doesn't match the referrer charset, the system
815 // charset, or UTF-8. 825 // charset, or UTF-8.
816 // TODO(jshin): we need to handle this case. 826 // TODO(jshin): we need to handle this case.
817 __LINE__, 827 __LINE__,
818 "http://example.com/V%FDvojov%E1%20psychologie.doc", 828 "http://example.com/V%FDvojov%E1%20psychologie.doc",
819 "", 829 "",
820 "utf-8", 830 "utf-8",
821 "", 831 "",
822 "", 832 "",
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 L"download" TXT_EXT 1025 L"download" TXT_EXT
1016 }, 1026 },
1017 { // Filename looks like HTML? 1027 { // Filename looks like HTML?
1018 __LINE__, 1028 __LINE__,
1019 "http://www.evil.com/get/malware/here", 1029 "http://www.evil.com/get/malware/here",
1020 "filename=\"<blink>Hello kitty</blink>\"", 1030 "filename=\"<blink>Hello kitty</blink>\"",
1021 "", 1031 "",
1022 "", 1032 "",
1023 "text/plain", 1033 "text/plain",
1024 L"default", 1034 L"default",
1025 L"-blink-Hello kitty--blink-" TXT_EXT 1035 L"-blink-Hello kitty--blink-"
1026 }, 1036 },
1027 { // A normal avi should get .avi and not .avi.avi 1037 { // A normal avi should get .avi and not .avi.avi
1028 __LINE__, 1038 __LINE__,
1029 "https://blah.google.com/misc/2.avi", 1039 "https://blah.google.com/misc/2.avi",
1030 "", 1040 "",
1031 "", 1041 "",
1032 "", 1042 "",
1033 "video/x-msvideo", 1043 "video/x-msvideo",
1034 L"download", 1044 L"download",
1035 L"2.avi" 1045 L"2.avi"
1036 }, 1046 },
1037 { // Extension generation 1047 { // Extension generation
1038 __LINE__, 1048 __LINE__,
1039 "http://www.example.com/my-cat", 1049 "http://www.example.com/my-cat",
1040 "filename=my-cat", 1050 "filename=my-cat",
1041 "", 1051 "",
1042 "", 1052 "",
1043 "image/jpeg", 1053 "image/jpeg",
1044 L"download", 1054 L"download",
1045 L"my-cat" JPEG_EXT 1055 L"my-cat"
1046 }, 1056 },
1047 { 1057 {
1048 __LINE__, 1058 __LINE__,
1049 "http://www.example.com/my-cat", 1059 "http://www.example.com/my-cat",
1050 "filename=my-cat", 1060 "filename=my-cat",
1051 "", 1061 "",
1052 "", 1062 "",
1053 "text/plain", 1063 "text/plain",
1054 L"download", 1064 L"download",
1055 L"my-cat.txt" 1065 L"my-cat"
1056 }, 1066 },
1057 { 1067 {
1058 __LINE__, 1068 __LINE__,
1059 "http://www.example.com/my-cat", 1069 "http://www.example.com/my-cat",
1060 "filename=my-cat", 1070 "filename=my-cat",
1061 "", 1071 "",
1062 "", 1072 "",
1063 "text/html", 1073 "text/html",
1064 L"download", 1074 L"download",
1065 L"my-cat" HTML_EXT 1075 L"my-cat"
1066 }, 1076 },
1067 { // Unknown MIME type 1077 { // Unknown MIME type
1068 __LINE__, 1078 __LINE__,
1069 "http://www.example.com/my-cat", 1079 "http://www.example.com/my-cat",
1070 "filename=my-cat", 1080 "filename=my-cat",
1071 "", 1081 "",
1072 "", 1082 "",
1073 "dance/party", 1083 "dance/party",
1074 L"download", 1084 L"download",
1075 L"my-cat" 1085 L"my-cat"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 L"-foo.txt" 1289 L"-foo.txt"
1280 }, 1290 },
1281 { 1291 {
1282 __LINE__, 1292 __LINE__,
1283 "http://www.evil.com/.hidden", 1293 "http://www.evil.com/.hidden",
1284 "filename=.hidden", 1294 "filename=.hidden",
1285 "", 1295 "",
1286 "", 1296 "",
1287 "text/plain", 1297 "text/plain",
1288 L"download", 1298 L"download",
1289 L"hidden" TXT_EXT 1299 L"hidden"
1290 }, 1300 },
1291 { 1301 {
1292 __LINE__, 1302 __LINE__,
1293 "http://www.evil.com/trailing.", 1303 "http://www.evil.com/trailing.",
1294 "filename=trailing.", 1304 "filename=trailing.",
1295 "", 1305 "",
1296 "", 1306 "",
1297 "dance/party", 1307 "dance/party",
1298 L"download", 1308 L"download",
1299 #if defined(OS_WIN) 1309 #if defined(OS_WIN)
1300 L"trailing-" 1310 L"trailing-"
1301 #else 1311 #else
1302 L"trailing" 1312 L"trailing"
1303 #endif 1313 #endif
1304 }, 1314 },
1305 { 1315 {
1306 __LINE__, 1316 __LINE__,
1307 "http://www.evil.com/trailing.", 1317 "http://www.evil.com/trailing.",
1308 "filename=trailing.", 1318 "filename=trailing.",
1309 "", 1319 "",
1310 "", 1320 "",
1311 "text/plain", 1321 "text/plain",
1312 L"download", 1322 L"download",
1313 #if defined(OS_WIN) 1323 #if defined(OS_WIN)
1314 L"trailing-" TXT_EXT 1324 L"trailing-"
1315 #else 1325 #else
1316 L"trailing" TXT_EXT 1326 L"trailing"
1317 #endif 1327 #endif
1318 }, 1328 },
1319 { 1329 {
1320 __LINE__, 1330 __LINE__,
1321 "http://www.evil.com/.", 1331 "http://www.evil.com/.",
1322 "filename=.", 1332 "filename=.",
1323 "", 1333 "",
1324 "", 1334 "",
1325 "dance/party", 1335 "dance/party",
1326 L"download", 1336 L"download",
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 RunGenerateFileNameTestCase(&generation_tests[i]); 1668 RunGenerateFileNameTestCase(&generation_tests[i]);
1659 1669
1660 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generation_tests); ++i) { 1670 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generation_tests); ++i) {
1661 GenerateFilenameCase test_case = generation_tests[i]; 1671 GenerateFilenameCase test_case = generation_tests[i];
1662 test_case.referrer_charset = "GBK"; 1672 test_case.referrer_charset = "GBK";
1663 RunGenerateFileNameTestCase(&test_case); 1673 RunGenerateFileNameTestCase(&test_case);
1664 } 1674 }
1665 } 1675 }
1666 1676
1667 } // namespace net 1677 } // namespace net
OLDNEW
« no previous file with comments | « net/base/filename_util_internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698