| Index: net/base/filename_util_unittest.cc
|
| diff --git a/net/base/filename_util_unittest.cc b/net/base/filename_util_unittest.cc
|
| index 2b7e0ad8c6d503aa42ac6e1fd8cac7f47e12ce3d..216f37582741eb6bb4ff561a930386d7ab575cd1 100644
|
| --- a/net/base/filename_util_unittest.cc
|
| +++ b/net/base/filename_util_unittest.cc
|
| @@ -287,7 +287,7 @@ TEST(FilenameUtilTest, FileURLConversion) {
|
| #define TXT_EXT L".txt"
|
| #define TAR_EXT L".tar"
|
|
|
| -TEST(FilenameUtilTest, GenerateSafeFileName) {
|
| +TEST(FilenameUtilTest, EnsureSafePortableFileName) {
|
| const struct {
|
| const char* mime_type;
|
| const base::FilePath::CharType* filename;
|
| @@ -365,10 +365,10 @@ TEST(FilenameUtilTest, GenerateSafeFileName) {
|
| FILE_PATH_LITERAL("/foo/google.com")},
|
| {"text/html",
|
| FILE_PATH_LITERAL("/foo/con.htm"),
|
| - FILE_PATH_LITERAL("/foo/con.htm")},
|
| + FILE_PATH_LITERAL("/foo/_con.htm")},
|
| {"text/html",
|
| FILE_PATH_LITERAL("/foo/con"),
|
| - FILE_PATH_LITERAL("/foo/con.html")},
|
| + FILE_PATH_LITERAL("/foo/_con.html")},
|
| // Allow extension synonyms.
|
| {"image/jpeg",
|
| FILE_PATH_LITERAL("/bar.jpg"),
|
| @@ -381,7 +381,9 @@ TEST(FilenameUtilTest, GenerateSafeFileName) {
|
|
|
| for (size_t i = 0; i < arraysize(safe_tests); ++i) {
|
| base::FilePath file_path(safe_tests[i].filename);
|
| - GenerateSafeFileName(safe_tests[i].mime_type, false, &file_path);
|
| + EnsureSafePortableFileName(safe_tests[i].mime_type,
|
| + EXTENSION_OPTION_GENERATE_IF_MISSING,
|
| + &file_path);
|
| EXPECT_EQ(safe_tests[i].expected_filename, file_path.value())
|
| << "Iteration " << i;
|
| }
|
| @@ -391,7 +393,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| // Tests whether the correct filename is selected from the the given
|
| // parameters and that Content-Disposition headers are properly
|
| // handled including failovers when the header is malformed.
|
| - const GenerateFilenameCase selection_tests[] = {
|
| + static const GenerateFilenameCase kSelectionTests[] = {
|
| {__LINE__,
|
| "http://www.google.com/",
|
| "attachment; filename=test.html",
|
| @@ -453,13 +455,13 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| L"test.html"},
|
| {// No C-D
|
| __LINE__,
|
| - "http://www.google.com/",
|
| - "",
|
| + "http://example.com/V%FDvojov%E1%20psychologie.doc",
|
| "",
|
| + "utf-8",
|
| "",
|
| "",
|
| L"",
|
| - L"www.google.com"},
|
| + L"example.com"},
|
| {__LINE__,
|
| "http://www.google.com/test.html",
|
| "",
|
| @@ -508,15 +510,15 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "",
|
| "",
|
| L"",
|
| - L"-test.html"},
|
| + L"_._test.html"},
|
| {__LINE__,
|
| "http://www.google.com/",
|
| - "attachment; filename=\"..\\test.html\"",
|
| + "attachment; filename=\"..//test.html\"",
|
| "",
|
| "",
|
| "",
|
| L"",
|
| - L"test.html"},
|
| + L"_.__test.html"},
|
| {__LINE__,
|
| "http://www.google.com/",
|
| "attachment; filename=\"..\\\\test.html\"",
|
| @@ -524,20 +526,19 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "",
|
| "",
|
| L"",
|
| - L"-test.html"},
|
| - {// Filename disappears after leading and trailing periods are removed.
|
| - __LINE__,
|
| + L"_._test.html"},
|
| + {__LINE__,
|
| "http://www.google.com/",
|
| - "attachment; filename=\"..\"",
|
| + "attachment; filename=\"..\\\\\\\\test.html\"",
|
| "",
|
| "",
|
| "",
|
| - L"default",
|
| - L"default"},
|
| - {// C-D specified filename disappears. Failover to final filename.
|
| + L"",
|
| + L"_.__test.html"},
|
| + {// Content-Disposition specifies an empty filename.
|
| __LINE__,
|
| - "http://www.google.com/test.html",
|
| - "attachment; filename=\"..\"",
|
| + "http://www.google.com/",
|
| + "attachment; filename=",
|
| "",
|
| "",
|
| "",
|
| @@ -706,7 +707,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| L"caf\u03b5.png"},
|
| {// No 'filename' keyword in the disposition, use the URL
|
| __LINE__,
|
| - "http://www.evil.com/my_download.txt",
|
| + "http://www.example.com/my_download.txt",
|
| "a_file_name.txt",
|
| "",
|
| "",
|
| @@ -782,54 +783,61 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| // Tests filename generation. Once the correct filename is
|
| // selected, they should be passed through the validation steps and
|
| // a correct extension should be added if necessary.
|
| - const GenerateFilenameCase generation_tests[] = {
|
| - // Dotfiles. Ensures preceeding period(s) stripped.
|
| - {__LINE__,
|
| - "http://www.google.com/.test.html",
|
| + static const GenerateFilenameCase kGenerationTests[] = {
|
| + {// Dotfiles. Ensures preceeding period(s) escaped.
|
| + __LINE__,
|
| + "http://www.google.com/.test",
|
| "",
|
| "",
|
| "",
|
| "",
|
| L"",
|
| - L"test.html"},
|
| - {__LINE__, "http://www.google.com/.test", "", "", "", "", L"", L"test"},
|
| - {__LINE__, "http://www.google.com/..test", "", "", "", "", L"", L"test"},
|
| - {// Disposition has relative paths, remove directory separators
|
| + L"_test"},
|
| + {// Multiple dots. It's only necessary to escape the first one.
|
| __LINE__,
|
| - "http://www.evil.com/my_download.txt",
|
| + "http://www.google.com/..test",
|
| + "",
|
| + "",
|
| + "",
|
| + "",
|
| + L"",
|
| + L"_.test"},
|
| + {// Disposition has relative paths, escape path separators
|
| + __LINE__,
|
| + "http://www.example.com/my_download.txt",
|
| "filename=../../../../././../a_file_name.txt",
|
| "",
|
| "",
|
| - "text/plain",
|
| - L"download",
|
| - L"-..-..-..-.-.-..-a_file_name.txt"},
|
| + "",
|
| + L"",
|
| + L"_._.._.._.._._._.._a_file_name.txt"},
|
| {// Disposition has parent directories, remove directory separators
|
| __LINE__,
|
| - "http://www.evil.com/my_download.txt",
|
| + "http://www.example.com/my_download.txt",
|
| "filename=dir1/dir2/a_file_name.txt",
|
| "",
|
| "",
|
| - "text/plain",
|
| - L"download",
|
| - L"dir1-dir2-a_file_name.txt"},
|
| + "",
|
| + L"",
|
| + L"dir1_dir2_a_file_name.txt"},
|
| {// Disposition has relative paths, remove directory separators
|
| __LINE__,
|
| - "http://www.evil.com/my_download.txt",
|
| + "http://www.example.com/my_download.txt",
|
| "filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt",
|
| "",
|
| "",
|
| - "text/plain",
|
| - L"download",
|
| - L"-..-..-..-.-.-..-a_file_name.txt"},
|
| + "",
|
| + L"",
|
| + L"_._.._.._.._._._.._a_file_name.txt"},
|
| {// Disposition has parent directories, remove directory separators
|
| __LINE__,
|
| - "http://www.evil.com/my_download.txt",
|
| + "http://www.example.com/my_download.txt",
|
| "filename=dir1\\dir2\\a_file_name.txt",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| - L"dir1-dir2-a_file_name.txt"},
|
| + L"dir1_dir2_a_file_name.txt"},
|
| {// No useful information in disposition or URL, use default
|
| __LINE__,
|
| "http://www.truncated.com/path/",
|
| @@ -837,17 +845,27 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "",
|
| "",
|
| "text/plain",
|
| - L"download",
|
| - L"download" TXT_EXT},
|
| - {// Filename looks like HTML?
|
| + L"default",
|
| + L"default" TXT_EXT},
|
| + {// No useful information in disposition or URL, use default. Don't
|
| + // generate an extension since the default filename already has one.
|
| + __LINE__,
|
| + "http://www.truncated.com/path/",
|
| + "",
|
| + "",
|
| + "",
|
| + "text/plain",
|
| + L"default.ext",
|
| + L"default.ext"},
|
| + {// Filename looks like HTML.
|
| __LINE__,
|
| - "http://www.evil.com/get/malware/here",
|
| + "http://www.example.com/get/malware/here",
|
| "filename=\"<blink>Hello kitty</blink>\"",
|
| "",
|
| "",
|
| "text/plain",
|
| L"default",
|
| - L"-blink-Hello kitty--blink-"},
|
| + L"_blink_Hello kitty__blink_"},
|
| {// A normal avi should get .avi and not .avi.avi
|
| __LINE__,
|
| "https://blah.google.com/misc/2.avi",
|
| @@ -857,9 +875,10 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "video/x-msvideo",
|
| L"download",
|
| L"2.avi"},
|
| - {// Extension generation
|
| + {// No extensions should be generated if the filename was from a
|
| + // Content-Disposition header.
|
| __LINE__,
|
| - "http://www.example.com/my-cat",
|
| + "http://www.example.com/",
|
| "filename=my-cat",
|
| "",
|
| "",
|
| @@ -867,425 +886,216 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| L"download",
|
| L"my-cat"},
|
| {__LINE__,
|
| - "http://www.example.com/my-cat",
|
| + "http://www.example.com/",
|
| "filename=my-cat",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| L"my-cat"},
|
| - {__LINE__,
|
| - "http://www.example.com/my-cat",
|
| - "filename=my-cat",
|
| - "",
|
| - "",
|
| - "text/html",
|
| - L"download",
|
| - L"my-cat"},
|
| - {// Unknown MIME type
|
| + {// An extension should be generated for a URL derived filename.
|
| __LINE__,
|
| "http://www.example.com/my-cat",
|
| - "filename=my-cat",
|
| - "",
|
| "",
|
| - "dance/party",
|
| - L"download",
|
| - L"my-cat"},
|
| - {__LINE__,
|
| - "http://www.example.com/my-cat.jpg",
|
| - "filename=my-cat.jpg",
|
| "",
|
| "",
|
| "text/plain",
|
| - L"download",
|
| - L"my-cat.jpg"},
|
| -// Windows specific tests
|
| -#if defined(OS_WIN)
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.exe",
|
| - "filename=evil.exe",
|
| - "",
|
| - "",
|
| - "image/jpeg",
|
| - L"download",
|
| - L"evil.exe"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/ok.exe",
|
| - "filename=ok.exe",
|
| + L"",
|
| + L"my-cat" TXT_EXT},
|
| + {// Unknown MIME type. No extension generated.
|
| + __LINE__,
|
| + "http://www.example.com/my-cat",
|
| "",
|
| "",
|
| - "binary/octet-stream",
|
| - L"download",
|
| - L"ok.exe"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.dll",
|
| - "filename=evil.dll",
|
| - "",
|
| "",
|
| "dance/party",
|
| L"download",
|
| - L"evil.dll"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.exe",
|
| - "filename=evil",
|
| - "",
|
| + L"my-cat"},
|
| + {// Trailing spaces.
|
| + __LINE__,
|
| + "http://www.example.com/",
|
| + "filename=\"evil.exe \"",
|
| "",
|
| - "application/rss+xml",
|
| - L"download",
|
| - L"evil"},
|
| - // Test truncation of trailing dots and spaces
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.exe ",
|
| - "filename=evil.exe ",
|
| "",
|
| "",
|
| - "binary/octet-stream",
|
| L"download",
|
| - L"evil.exe"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.exe.",
|
| + L"evil.exe_"},
|
| + {// Trailing dots.
|
| + __LINE__,
|
| + "http://www.example.com/",
|
| "filename=evil.exe.",
|
| "",
|
| "",
|
| "binary/octet-stream",
|
| L"download",
|
| - L"evil.exe-"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.exe. . .",
|
| + L"evil.exe_"},
|
| + {// Multiple trailing dots and spaces.
|
| + __LINE__,
|
| + "http://www.example.com/",
|
| "filename=evil.exe. . .",
|
| "",
|
| "",
|
| "binary/octet-stream",
|
| L"download",
|
| - L"evil.exe-------"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/evil.",
|
| - "filename=evil.",
|
| - "",
|
| - "",
|
| - "binary/octet-stream",
|
| - L"download",
|
| - L"evil-"},
|
| + L"evil.exe. . _"},
|
| {__LINE__,
|
| - "http://www.goodguy.com/. . . . .",
|
| + "http://www.example.com/",
|
| "filename=. . . . .",
|
| "",
|
| "",
|
| "binary/octet-stream",
|
| L"download",
|
| - L"download"},
|
| + L"_ . . . _"},
|
| {__LINE__,
|
| - "http://www.badguy.com/attachment?name=meh.exe%C2%A0",
|
| - "attachment; filename=\"meh.exe\xC2\xA0\"",
|
| + "http://www.example.com/",
|
| + "filename=.",
|
| "",
|
| "",
|
| "binary/octet-stream",
|
| - L"",
|
| - L"meh.exe-"},
|
| -#endif // OS_WIN
|
| - {__LINE__,
|
| - "http://www.goodguy.com/utils.js",
|
| - "filename=utils.js",
|
| - "",
|
| - "",
|
| - "application/x-javascript",
|
| - L"download",
|
| - L"utils.js"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/contacts.js",
|
| - "filename=contacts.js",
|
| - "",
|
| - "",
|
| - "application/json",
|
| L"download",
|
| - L"contacts.js"},
|
| + L"_"},
|
| {__LINE__,
|
| - "http://www.goodguy.com/utils.js",
|
| - "filename=utils.js",
|
| - "",
|
| - "",
|
| - "text/javascript",
|
| - L"download",
|
| - L"utils.js"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/utils.js",
|
| - "filename=utils.js",
|
| - "",
|
| - "",
|
| - "text/javascript;version=2",
|
| - L"download",
|
| - L"utils.js"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/utils.js",
|
| - "filename=utils.js",
|
| - "",
|
| - "",
|
| - "application/ecmascript",
|
| - L"download",
|
| - L"utils.js"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/utils.js",
|
| - "filename=utils.js",
|
| - "",
|
| - "",
|
| - "application/ecmascript;version=4",
|
| - L"download",
|
| - L"utils.js"},
|
| - {__LINE__,
|
| - "http://www.goodguy.com/program.exe",
|
| - "filename=program.exe",
|
| - "",
|
| - "",
|
| - "application/foo-bar",
|
| - L"download",
|
| - L"program.exe"},
|
| - {__LINE__,
|
| - "http://www.evil.com/../foo.txt",
|
| - "filename=../foo.txt",
|
| - "",
|
| - "",
|
| - "text/plain",
|
| - L"download",
|
| - L"-foo.txt"},
|
| - {__LINE__,
|
| - "http://www.evil.com/..\\foo.txt",
|
| - "filename=..\\foo.txt",
|
| - "",
|
| - "",
|
| - "text/plain",
|
| - L"download",
|
| - L"-foo.txt"},
|
| - {__LINE__,
|
| - "http://www.evil.com/.hidden",
|
| - "filename=.hidden",
|
| + "http://www.example.com/",
|
| + "filename=..",
|
| "",
|
| "",
|
| - "text/plain",
|
| + "binary/octet-stream",
|
| L"download",
|
| - L"hidden"},
|
| + L"__"},
|
| {__LINE__,
|
| - "http://www.evil.com/trailing.",
|
| - "filename=trailing.",
|
| - "",
|
| + "http://www.example.com/",
|
| + "filename=\"meh.exe\xC2\xA0\"",
|
| "",
|
| - "dance/party",
|
| - L"download",
|
| -#if defined(OS_WIN)
|
| - L"trailing-"
|
| -#else
|
| - L"trailing"
|
| -#endif
|
| - },
|
| - {__LINE__,
|
| - "http://www.evil.com/trailing.",
|
| - "filename=trailing.",
|
| "",
|
| "",
|
| - "text/plain",
|
| - L"download",
|
| -#if defined(OS_WIN)
|
| - L"trailing-"
|
| + L"",
|
| +#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
| + // On Linux, \xA0 is allowed in the filename.
|
| + L"meh.exe\xA0"
|
| #else
|
| - L"trailing"
|
| + L"meh.exe_"
|
| #endif
|
| },
|
| - {__LINE__,
|
| - "http://www.evil.com/.",
|
| - "filename=.",
|
| - "",
|
| - "",
|
| - "dance/party",
|
| - L"download",
|
| - L"download"},
|
| - {__LINE__,
|
| - "http://www.evil.com/..",
|
| - "filename=..",
|
| + {// user.js should be left alone because the final extension matches the
|
| + // MIME type.
|
| + __LINE__,
|
| + "http://www.example.com/utils.user.js?foo",
|
| "",
|
| "",
|
| - "dance/party",
|
| - L"download",
|
| - L"download"},
|
| - {__LINE__,
|
| - "http://www.evil.com/...",
|
| - "filename=...",
|
| - "",
|
| "",
|
| - "dance/party",
|
| - L"download",
|
| - L"download"},
|
| + "application/javascript",
|
| + L"",
|
| + L"utils.user.js"},
|
| {// Note that this one doesn't have "filename=" on it.
|
| __LINE__,
|
| - "http://www.evil.com/",
|
| + "http://www.example.com/",
|
| "a_file_name.txt",
|
| "",
|
| "",
|
| "image/jpeg",
|
| - L"download",
|
| - L"download" JPEG_EXT},
|
| - {__LINE__,
|
| - "http://www.evil.com/",
|
| + L"default",
|
| + L"default" JPEG_EXT},
|
| + {// Content-Disposition specifies an empty filename.
|
| + __LINE__,
|
| + "http://www.example.com/",
|
| "filename=",
|
| "",
|
| "",
|
| "image/jpeg",
|
| - L"download",
|
| - L"download" JPEG_EXT},
|
| - {__LINE__,
|
| - "http://www.example.com/simple",
|
| - "filename=simple",
|
| - "",
|
| - "",
|
| - "application/octet-stream",
|
| - L"download",
|
| - L"simple"},
|
| + L"default",
|
| + L"default" JPEG_EXT},
|
| // Reserved words on Windows
|
| {__LINE__,
|
| - "http://www.goodguy.com/COM1",
|
| + "http://www.example.com/",
|
| "filename=COM1",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_COM1"
|
| -#else
|
| - L"COM1"
|
| -#endif
|
| - },
|
| + L"_COM1"},
|
| {__LINE__,
|
| - "http://www.goodguy.com/COM4.txt",
|
| + "http://www.example.com/",
|
| "filename=COM4.txt",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_COM4.txt"
|
| -#else
|
| - L"COM4.txt"
|
| -#endif
|
| - },
|
| + L"_COM4.txt"},
|
| {__LINE__,
|
| - "http://www.goodguy.com/lpt1.TXT",
|
| + "http://www.example.com/",
|
| "filename=lpt1.TXT",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_lpt1.TXT"
|
| -#else
|
| - L"lpt1.TXT"
|
| -#endif
|
| - },
|
| + L"_lpt1.TXT"},
|
| {__LINE__,
|
| - "http://www.goodguy.com/clock$.txt",
|
| + "http://www.example.com/",
|
| "filename=clock$.txt",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_clock$.txt"
|
| -#else
|
| - L"clock$.txt"
|
| -#endif
|
| - },
|
| + L"_clock$.txt"},
|
| {// Validation should also apply to sugested name
|
| __LINE__,
|
| - "http://www.goodguy.com/blah$.txt",
|
| - "filename=clock$.txt",
|
| + "http://www.example.com/",
|
| + "",
|
| "",
|
| "clock$.txt",
|
| "text/plain",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_clock$.txt"
|
| -#else
|
| - L"clock$.txt"
|
| -#endif
|
| - },
|
| - {__LINE__,
|
| - "http://www.goodguy.com/mycom1.foo",
|
| + L"_clock$.txt"},
|
| + {// Shouldn't match substrings.
|
| + __LINE__,
|
| + "http://www.example.com/",
|
| "filename=mycom1.foo",
|
| "",
|
| "",
|
| "text/plain",
|
| L"download",
|
| L"mycom1.foo"},
|
| - {__LINE__,
|
| - "http://www.badguy.com/Setup.exe.local",
|
| + {// Shell integrated extensions.
|
| + __LINE__,
|
| + "http://www.example.com/Setup.exe.local",
|
| "filename=Setup.exe.local",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"Setup.exe.download"
|
| -#else
|
| - L"Setup.exe.local"
|
| -#endif
|
| - },
|
| + L"Setup.exe.download"},
|
| {__LINE__,
|
| - "http://www.badguy.com/Setup.exe.local",
|
| + "http://www.example.com/Setup.exe.local",
|
| "filename=Setup.exe.local.local",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"Setup.exe.local.download"
|
| -#else
|
| - L"Setup.exe.local.local"
|
| -#endif
|
| - },
|
| + L"Setup.exe.local.download"},
|
| {__LINE__,
|
| - "http://www.badguy.com/Setup.exe.lnk",
|
| + "http://www.example.com/Setup.exe.lnk",
|
| "filename=Setup.exe.lnk",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"Setup.exe.download"
|
| -#else
|
| - L"Setup.exe.lnk"
|
| -#endif
|
| - },
|
| + L"Setup.exe.download"},
|
| {__LINE__,
|
| - "http://www.badguy.com/Desktop.ini",
|
| + "http://www.example.com/Desktop.ini",
|
| "filename=Desktop.ini",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_Desktop.ini"
|
| -#else
|
| - L"Desktop.ini"
|
| -#endif
|
| - },
|
| + L"_Desktop.ini"},
|
| {__LINE__,
|
| - "http://www.badguy.com/Thumbs.db",
|
| + "http://www.example.com/Thumbs.db",
|
| "filename=Thumbs.db",
|
| "",
|
| "",
|
| "application/foo-bar",
|
| L"download",
|
| -#if defined(OS_WIN)
|
| - L"_Thumbs.db"
|
| -#else
|
| - L"Thumbs.db"
|
| -#endif
|
| - },
|
| - {__LINE__,
|
| - "http://www.hotmail.com",
|
| - "filename=source.jpg",
|
| - "",
|
| - "",
|
| - "application/x-javascript",
|
| - L"download",
|
| - L"source.jpg"},
|
| + L"_Thumbs.db"},
|
| {// http://crbug.com/5772.
|
| __LINE__,
|
| "http://www.example.com/foo.tar.gz",
|
| @@ -1306,7 +1116,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| L"foo.tgz"},
|
| {// http://crbug.com/7337.
|
| __LINE__,
|
| - "http://maged.lordaeron.org/blank.reg",
|
| + "http://example.com/blank.reg",
|
| "",
|
| "",
|
| "",
|
| @@ -1332,12 +1142,12 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| {// http://crbug.com/20337
|
| __LINE__,
|
| "http://www.example.com/.download.txt",
|
| - "filename=.download.txt",
|
| + "filename=.foo.txt",
|
| "",
|
| "",
|
| "text/plain",
|
| - L"-download",
|
| - L"download.txt"},
|
| + L"download",
|
| + L"_foo.txt"},
|
| {// http://crbug.com/56855.
|
| __LINE__,
|
| "http://www.example.com/bar.sh",
|
| @@ -1356,6 +1166,51 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "text/plain",
|
| L"download",
|
| L"npdf" TXT_EXT},
|
| + {// The "extension" of the URL derived filename is going to be .tar.gz,
|
| + // whereas the extension mapped to application/gzip is .gz. Despite this
|
| + // the extension should be left as-is because the FinalExtension() of the
|
| + // filename matches .gz.
|
| + __LINE__,
|
| + "http://www.example.com/x.tar.gz?query",
|
| + "",
|
| + "",
|
| + "",
|
| + "application/gzip",
|
| + L"download",
|
| + L"x.tar.gz"},
|
| + {// A MIME type can map to multiple extensions. Any of these should be
|
| + // accepted as the extension and should be overwritten only if there is no
|
| + // match.
|
| + __LINE__,
|
| + "http://www.example.com/foo.htm?query",
|
| + "",
|
| + "",
|
| + "",
|
| + "text/html",
|
| + L"download",
|
| + L"foo.htm"},
|
| + {// A MIME type can map to multiple extensions. Any of these should be
|
| + // accepted as the extension and should be overwritten only if there is no
|
| + // match.
|
| + __LINE__,
|
| + "http://www.example.com/foo.html?query",
|
| + "",
|
| + "",
|
| + "",
|
| + "text/html",
|
| + L"download",
|
| + L"foo.html"},
|
| + {// A MIME type can map to multiple extensions. Any of these should be
|
| + // accepted as the extension and should be overwritten only if there is no
|
| + // match.
|
| + __LINE__,
|
| + "http://www.example.com/foo.bar?query",
|
| + "",
|
| + "",
|
| + "",
|
| + "text/html",
|
| + L"download",
|
| + L"foo" HTML_EXT},
|
| {// Shouldn't overwrite C-D specified extension.
|
| __LINE__,
|
| "http://www.example.com/npdf.php?fn=foobar.pdf",
|
| @@ -1374,6 +1229,24 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| "image/jpeg",
|
| L"download",
|
| L"image" JPEG_EXT},
|
| + {// Hostname derived filenames should have extensions appended.
|
| + __LINE__,
|
| + "http://www.example.com",
|
| + "",
|
| + "",
|
| + "",
|
| + "text/html",
|
| + L"",
|
| + L"www.example.com" HTML_EXT},
|
| + {// IDN
|
| + __LINE__,
|
| + "http://xn--fzc2c9eoa8e.example.com",
|
| + "",
|
| + "",
|
| + "",
|
| + "",
|
| + L"",
|
| + L"\u0dbd\u0d82\u0d9a\u0dcf\u0dc0.example.com"},
|
| {__LINE__,
|
| "http://www.example.com/image.aspx?id=blargh",
|
| "",
|
| @@ -1381,7 +1254,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| " .foo",
|
| "",
|
| L"download",
|
| - L"-.foo"},
|
| + L"_.foo"},
|
| #if defined(OS_CHROMEOS)
|
| {// http://crosbug.com/26028
|
| __LINE__,
|
| @@ -1395,14 +1268,14 @@ TEST(FilenameUtilTest, GenerateFileName) {
|
| #endif
|
| };
|
|
|
| - for (size_t i = 0; i < arraysize(selection_tests); ++i)
|
| - RunGenerateFileNameTestCase(&selection_tests[i]);
|
| + for (const auto& test_case : kSelectionTests)
|
| + RunGenerateFileNameTestCase(&test_case);
|
|
|
| - for (size_t i = 0; i < arraysize(generation_tests); ++i)
|
| - RunGenerateFileNameTestCase(&generation_tests[i]);
|
| + for (const auto& test_case : kGenerationTests)
|
| + RunGenerateFileNameTestCase(&test_case);
|
|
|
| - for (size_t i = 0; i < arraysize(generation_tests); ++i) {
|
| - GenerateFilenameCase test_case = generation_tests[i];
|
| + for (const auto& const_test_case : kGenerationTests) {
|
| + GenerateFilenameCase test_case = const_test_case;
|
| test_case.referrer_charset = "GBK";
|
| RunGenerateFileNameTestCase(&test_case);
|
| }
|
|
|