Commit 13cc94a3 authored by asanka's avatar asanka Committed by Commit bot

[net] Clang-format filename_util_unittest.cc

Upcoming changes to filename_util are unreviewable if they include
material code changes and formatting changes. This CL just includes
formatting changes and is the result of running:

  'clang-format -i --style=Chromium filename_util_unittest.cc'.

Depends on: https://codereview.chromium.org/869823003
Needed by : https://codereview.chromium.org/869233006

BUG=444102

Review URL: https://codereview.chromium.org/873843002

Cr-Commit-Position: refs/heads/master@{#314399}
parent 99aa853c
...@@ -123,40 +123,48 @@ static const base::FilePath::CharType* kSafePortableRelativePaths[] = { ...@@ -123,40 +123,48 @@ static const base::FilePath::CharType* kSafePortableRelativePaths[] = {
}; };
TEST(FilenameUtilTest, IsSafePortablePathComponent) { TEST(FilenameUtilTest, IsSafePortablePathComponent) {
for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) { for (size_t i = 0; i < arraysize(kSafePortableBasenames); ++i) {
EXPECT_TRUE(IsSafePortablePathComponent(base::FilePath( EXPECT_TRUE(
kSafePortableBasenames[i]))) << kSafePortableBasenames[i]; IsSafePortablePathComponent(base::FilePath(kSafePortableBasenames[i])))
<< kSafePortableBasenames[i];
} }
for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) { for (size_t i = 0; i < arraysize(kUnsafePortableBasenames); ++i) {
EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath( EXPECT_FALSE(IsSafePortablePathComponent(
kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; base::FilePath(kUnsafePortableBasenames[i])))
<< kUnsafePortableBasenames[i];
} }
for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) { for (size_t i = 0; i < arraysize(kSafePortableRelativePaths); ++i) {
EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath( EXPECT_FALSE(IsSafePortablePathComponent(
kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i]; base::FilePath(kSafePortableRelativePaths[i])))
<< kSafePortableRelativePaths[i];
} }
} }
TEST(FilenameUtilTest, IsSafePortableRelativePath) { TEST(FilenameUtilTest, IsSafePortableRelativePath) {
base::FilePath safe_dirname(FILE_PATH_LITERAL("a")); base::FilePath safe_dirname(FILE_PATH_LITERAL("a"));
for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) { for (size_t i = 0; i < arraysize(kSafePortableBasenames); ++i) {
EXPECT_TRUE(IsSafePortableRelativePath(base::FilePath( EXPECT_TRUE(
kSafePortableBasenames[i]))) << kSafePortableBasenames[i]; IsSafePortableRelativePath(base::FilePath(kSafePortableBasenames[i])))
EXPECT_TRUE(IsSafePortableRelativePath(safe_dirname.Append(base::FilePath( << kSafePortableBasenames[i];
kSafePortableBasenames[i])))) << kSafePortableBasenames[i]; EXPECT_TRUE(IsSafePortableRelativePath(
safe_dirname.Append(base::FilePath(kSafePortableBasenames[i]))))
<< kSafePortableBasenames[i];
} }
for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) { for (size_t i = 0; i < arraysize(kSafePortableRelativePaths); ++i) {
EXPECT_TRUE(IsSafePortableRelativePath(base::FilePath( EXPECT_TRUE(IsSafePortableRelativePath(
kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i]; base::FilePath(kSafePortableRelativePaths[i])))
EXPECT_TRUE(IsSafePortableRelativePath(safe_dirname.Append(base::FilePath( << kSafePortableRelativePaths[i];
kSafePortableRelativePaths[i])))) << kSafePortableRelativePaths[i]; EXPECT_TRUE(IsSafePortableRelativePath(
safe_dirname.Append(base::FilePath(kSafePortableRelativePaths[i]))))
<< kSafePortableRelativePaths[i];
} }
for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) { for (size_t i = 0; i < arraysize(kUnsafePortableBasenames); ++i) {
EXPECT_FALSE(IsSafePortableRelativePath(base::FilePath( EXPECT_FALSE(
kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; IsSafePortableRelativePath(base::FilePath(kUnsafePortableBasenames[i])))
<< kUnsafePortableBasenames[i];
if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) {
EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( EXPECT_FALSE(IsSafePortableRelativePath(
base::FilePath(kUnsafePortableBasenames[i])))) safe_dirname.Append(base::FilePath(kUnsafePortableBasenames[i]))))
<< kUnsafePortableBasenames[i]; << kUnsafePortableBasenames[i];
} }
} }
...@@ -174,8 +182,7 @@ TEST(FilenameUtilTest, FileURLConversion) { ...@@ -174,8 +182,7 @@ TEST(FilenameUtilTest, FileURLConversion) {
// issue 14153: To be tested with the OS default codepage other than 1252. // issue 14153: To be tested with the OS default codepage other than 1252.
{L"D:\\latin1\\caf\x00E9\x00DD.txt", {L"D:\\latin1\\caf\x00E9\x00DD.txt",
"file:///D:/latin1/caf%C3%A9%C3%9D.txt"}, "file:///D:/latin1/caf%C3%A9%C3%9D.txt"},
{L"D:\\otherlatin\\caf\x0119.txt", {L"D:\\otherlatin\\caf\x0119.txt", "file:///D:/otherlatin/caf%C4%99.txt"},
"file:///D:/otherlatin/caf%C4%99.txt"},
{L"D:\\greek\\\x03B1\x03B2\x03B3.txt", {L"D:\\greek\\\x03B1\x03B2\x03B3.txt",
"file:///D:/greek/%CE%B1%CE%B2%CE%B3.txt"}, "file:///D:/greek/%CE%B1%CE%B2%CE%B3.txt"},
{L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", {L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc",
...@@ -205,8 +212,8 @@ TEST(FilenameUtilTest, FileURLConversion) { ...@@ -205,8 +212,8 @@ TEST(FilenameUtilTest, FileURLConversion) {
base::FilePath output; base::FilePath output;
for (size_t i = 0; i < arraysize(round_trip_cases); i++) { for (size_t i = 0; i < arraysize(round_trip_cases); i++) {
// convert to the file URL // convert to the file URL
GURL file_url(FilePathToFileURL( GURL file_url(
WStringAsFilePath(round_trip_cases[i].file))); FilePathToFileURL(WStringAsFilePath(round_trip_cases[i].file)));
EXPECT_EQ(round_trip_cases[i].url, file_url.spec()); EXPECT_EQ(round_trip_cases[i].url, file_url.spec());
// Back to the filename. // Back to the filename.
...@@ -239,13 +246,13 @@ TEST(FilenameUtilTest, FileURLConversion) { ...@@ -239,13 +246,13 @@ TEST(FilenameUtilTest, FileURLConversion) {
{L"/foo/bar.txt", "file:////foo////bar.txt"}, {L"/foo/bar.txt", "file:////foo////bar.txt"},
{L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"},
{L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"}, {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"},
// We get these wrong because GURL turns back slashes into forward // We get these wrong because GURL turns back slashes into forward
// slashes. // slashes.
//{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
//{L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"}, // {L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"},
//{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
//{L"/foo%5Cbar.txt", "file:////foo\\bar.txt"}, // {L"/foo%5Cbar.txt", "file:////foo\\bar.txt"},
//{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, // {L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
#endif #endif
}; };
for (size_t i = 0; i < arraysize(url_cases); i++) { for (size_t i = 0; i < arraysize(url_cases); i++) {
...@@ -253,14 +260,13 @@ TEST(FilenameUtilTest, FileURLConversion) { ...@@ -253,14 +260,13 @@ TEST(FilenameUtilTest, FileURLConversion) {
EXPECT_EQ(url_cases[i].file, FilePathAsWString(output)); EXPECT_EQ(url_cases[i].file, FilePathAsWString(output));
} }
// Unfortunately, UTF8ToWide discards invalid UTF8 input. // Unfortunately, UTF8ToWide discards invalid UTF8 input.
#ifdef BUG_878908_IS_FIXED #ifdef BUG_878908_IS_FIXED
// Test that no conversion happens if the UTF-8 input is invalid, and that // Test that no conversion happens if the UTF-8 input is invalid, and that
// the input is preserved in UTF-8 // the input is preserved in UTF-8
const char invalid_utf8[] = "file:///d:/Blah/\xff.doc"; const char invalid_utf8[] = "file:///d:/Blah/\xff.doc";
const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc"; const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc";
EXPECT_TRUE(FileURLToFilePath( EXPECT_TRUE(FileURLToFilePath(GURL(std::string(invalid_utf8)), &output));
GURL(std::string(invalid_utf8)), &output));
EXPECT_EQ(std::wstring(invalid_wide), output); EXPECT_EQ(std::wstring(invalid_wide), output);
#endif #endif
...@@ -288,144 +294,88 @@ TEST(FilenameUtilTest, GenerateSafeFileName) { ...@@ -288,144 +294,88 @@ TEST(FilenameUtilTest, GenerateSafeFileName) {
const base::FilePath::CharType* expected_filename; const base::FilePath::CharType* expected_filename;
} safe_tests[] = { } safe_tests[] = {
#if defined(OS_WIN) #if defined(OS_WIN)
{ {"text/html",
"text/html",
FILE_PATH_LITERAL("C:\\foo\\bar.htm"), FILE_PATH_LITERAL("C:\\foo\\bar.htm"),
FILE_PATH_LITERAL("C:\\foo\\bar.htm") FILE_PATH_LITERAL("C:\\foo\\bar.htm")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\bar.html"), FILE_PATH_LITERAL("C:\\foo\\bar.html"),
FILE_PATH_LITERAL("C:\\foo\\bar.html") FILE_PATH_LITERAL("C:\\foo\\bar.html")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\bar"), FILE_PATH_LITERAL("C:\\foo\\bar"),
FILE_PATH_LITERAL("C:\\foo\\bar.htm") FILE_PATH_LITERAL("C:\\foo\\bar.htm")},
}, {"image/png",
{
"image/png",
FILE_PATH_LITERAL("C:\\bar.html"), FILE_PATH_LITERAL("C:\\bar.html"),
FILE_PATH_LITERAL("C:\\bar.html") FILE_PATH_LITERAL("C:\\bar.html")},
}, {"image/png",
{
"image/png",
FILE_PATH_LITERAL("C:\\bar"), FILE_PATH_LITERAL("C:\\bar"),
FILE_PATH_LITERAL("C:\\bar.png") FILE_PATH_LITERAL("C:\\bar.png")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\bar.exe"), FILE_PATH_LITERAL("C:\\foo\\bar.exe"),
FILE_PATH_LITERAL("C:\\foo\\bar.exe") FILE_PATH_LITERAL("C:\\foo\\bar.exe")},
}, {"image/gif",
{
"image/gif",
FILE_PATH_LITERAL("C:\\foo\\bar.exe"), FILE_PATH_LITERAL("C:\\foo\\bar.exe"),
FILE_PATH_LITERAL("C:\\foo\\bar.exe") FILE_PATH_LITERAL("C:\\foo\\bar.exe")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\google.com"), FILE_PATH_LITERAL("C:\\foo\\google.com"),
FILE_PATH_LITERAL("C:\\foo\\google.com") FILE_PATH_LITERAL("C:\\foo\\google.com")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\con.htm"), FILE_PATH_LITERAL("C:\\foo\\con.htm"),
FILE_PATH_LITERAL("C:\\foo\\_con.htm") FILE_PATH_LITERAL("C:\\foo\\_con.htm")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\con"), FILE_PATH_LITERAL("C:\\foo\\con"),
FILE_PATH_LITERAL("C:\\foo\\_con.htm") FILE_PATH_LITERAL("C:\\foo\\_con.htm")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\harmless.{not-really-this-may-be-a-guid}"), FILE_PATH_LITERAL("C:\\foo\\harmless.{not-really-this-may-be-a-guid}"),
FILE_PATH_LITERAL("C:\\foo\\harmless.download") FILE_PATH_LITERAL("C:\\foo\\harmless.download")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\harmless.local"), FILE_PATH_LITERAL("C:\\foo\\harmless.local"),
FILE_PATH_LITERAL("C:\\foo\\harmless.download") FILE_PATH_LITERAL("C:\\foo\\harmless.download")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\harmless.lnk"), FILE_PATH_LITERAL("C:\\foo\\harmless.lnk"),
FILE_PATH_LITERAL("C:\\foo\\harmless.download") FILE_PATH_LITERAL("C:\\foo\\harmless.download")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-"), FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-"),
FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-") FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-")},
},
// Allow extension synonyms. // Allow extension synonyms.
{ {"image/jpeg",
"image/jpeg",
FILE_PATH_LITERAL("C:\\foo\\bar.jpg"), FILE_PATH_LITERAL("C:\\foo\\bar.jpg"),
FILE_PATH_LITERAL("C:\\foo\\bar.jpg") FILE_PATH_LITERAL("C:\\foo\\bar.jpg")},
}, {"image/jpeg",
{
"image/jpeg",
FILE_PATH_LITERAL("C:\\foo\\bar.jpeg"), FILE_PATH_LITERAL("C:\\foo\\bar.jpeg"),
FILE_PATH_LITERAL("C:\\foo\\bar.jpeg") FILE_PATH_LITERAL("C:\\foo\\bar.jpeg")},
},
#else // !defined(OS_WIN) #else // !defined(OS_WIN)
{ {"text/html",
"text/html",
FILE_PATH_LITERAL("/foo/bar.htm"), FILE_PATH_LITERAL("/foo/bar.htm"),
FILE_PATH_LITERAL("/foo/bar.htm") FILE_PATH_LITERAL("/foo/bar.htm")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("/foo/bar.html"), FILE_PATH_LITERAL("/foo/bar.html"),
FILE_PATH_LITERAL("/foo/bar.html") FILE_PATH_LITERAL("/foo/bar.html")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("/foo/bar"), FILE_PATH_LITERAL("/foo/bar"),
FILE_PATH_LITERAL("/foo/bar.html") FILE_PATH_LITERAL("/foo/bar.html")},
}, {"image/png",
{
"image/png",
FILE_PATH_LITERAL("/bar.html"), FILE_PATH_LITERAL("/bar.html"),
FILE_PATH_LITERAL("/bar.html") FILE_PATH_LITERAL("/bar.html")},
}, {"image/png", FILE_PATH_LITERAL("/bar"), FILE_PATH_LITERAL("/bar.png")},
{ {"image/gif",
"image/png",
FILE_PATH_LITERAL("/bar"),
FILE_PATH_LITERAL("/bar.png")
},
{
"image/gif",
FILE_PATH_LITERAL("/foo/bar.exe"), FILE_PATH_LITERAL("/foo/bar.exe"),
FILE_PATH_LITERAL("/foo/bar.exe") FILE_PATH_LITERAL("/foo/bar.exe")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("/foo/google.com"), FILE_PATH_LITERAL("/foo/google.com"),
FILE_PATH_LITERAL("/foo/google.com") FILE_PATH_LITERAL("/foo/google.com")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("/foo/con.htm"), FILE_PATH_LITERAL("/foo/con.htm"),
FILE_PATH_LITERAL("/foo/con.htm") FILE_PATH_LITERAL("/foo/con.htm")},
}, {"text/html",
{
"text/html",
FILE_PATH_LITERAL("/foo/con"), FILE_PATH_LITERAL("/foo/con"),
FILE_PATH_LITERAL("/foo/con.html") FILE_PATH_LITERAL("/foo/con.html")},
},
// Allow extension synonyms. // Allow extension synonyms.
{ {"image/jpeg",
"image/jpeg",
FILE_PATH_LITERAL("/bar.jpg"), FILE_PATH_LITERAL("/bar.jpg"),
FILE_PATH_LITERAL("/bar.jpg") FILE_PATH_LITERAL("/bar.jpg")},
}, {"image/jpeg",
{
"image/jpeg",
FILE_PATH_LITERAL("/bar.jpeg"), FILE_PATH_LITERAL("/bar.jpeg"),
FILE_PATH_LITERAL("/bar.jpeg") FILE_PATH_LITERAL("/bar.jpeg")},
},
#endif // !defined(OS_WIN) #endif // !defined(OS_WIN)
}; };
...@@ -442,47 +392,39 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -442,47 +392,39 @@ TEST(FilenameUtilTest, GenerateFileName) {
// parameters and that Content-Disposition headers are properly // parameters and that Content-Disposition headers are properly
// handled including failovers when the header is malformed. // handled including failovers when the header is malformed.
const GenerateFilenameCase selection_tests[] = { const GenerateFilenameCase selection_tests[] = {
{ {__LINE__,
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=test.html", "attachment; filename=test.html",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"test.html\"", "attachment; filename=\"test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename= \"test.html\"", "attachment; filename= \"test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename = \"test.html\"", "attachment; filename = \"test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {// filename is whitespace. Should failover to URL host
{ // filename is whitespace. Should failover to URL host
__LINE__, __LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename= ", "attachment; filename= ",
...@@ -490,9 +432,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -490,9 +432,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"www.google.com" L"www.google.com"},
}, {// No filename.
{ // No filename.
__LINE__, __LINE__,
"http://www.google.com/path/test.html", "http://www.google.com/path/test.html",
"attachment", "attachment",
...@@ -500,9 +441,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -500,9 +441,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {// Ditto
{ // Ditto
__LINE__, __LINE__,
"http://www.google.com/path/test.html", "http://www.google.com/path/test.html",
"attachment;", "attachment;",
...@@ -510,9 +450,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -510,9 +450,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {// No C-D
{ // No C-D
__LINE__, __LINE__,
"http://www.google.com/", "http://www.google.com/",
"", "",
...@@ -520,19 +459,16 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -520,19 +459,16 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"www.google.com" L"www.google.com"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/test.html", "http://www.google.com/test.html",
"", "",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {// Now that we use src/url's ExtractFileName, this case falls back to
{ // Now that we use src/url's ExtractFileName, this case falls back to
// the hostname. If this behavior is not desirable, we'd better change // the hostname. If this behavior is not desirable, we'd better change
// ExtractFileName (in url_parse.cc). // ExtractFileName (in url_parse.cc).
__LINE__, __LINE__,
...@@ -542,49 +478,12 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -542,49 +478,12 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"www.google.com" L"www.google.com"},
}, {__LINE__, "http://www.google.com/path", "", "", "", "", L"", L"path"},
{ {__LINE__, "file:///", "", "", "", "", L"", L"download"},
__LINE__, {__LINE__, "file:///path/testfile", "", "", "", "", L"", L"testfile"},
"http://www.google.com/path", {__LINE__, "non-standard-scheme:", "", "", "", "", L"", L"download"},
"", {// C-D should override default
"",
"",
"",
L"",
L"path"
},
{
__LINE__,
"file:///",
"",
"",
"",
"",
L"",
L"download"
},
{
__LINE__,
"file:///path/testfile",
"",
"",
"",
"",
L"",
L"testfile"
},
{
__LINE__,
"non-standard-scheme:",
"",
"",
"",
"",
L"",
L"download"
},
{ // C-D should override default
__LINE__, __LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename =\"test.html\"", "attachment; filename =\"test.html\"",
...@@ -592,9 +491,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -592,9 +491,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"download", L"download",
L"test.html" L"test.html"},
}, {// But the URL shouldn't
{ // But the URL shouldn't
__LINE__, __LINE__,
"http://www.google.com/", "http://www.google.com/",
"", "",
...@@ -602,39 +500,32 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -602,39 +500,32 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"download", L"download",
L"download" L"download"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"../test.html\"", "attachment; filename=\"../test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"-test.html" L"-test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"..\\test.html\"", "attachment; filename=\"..\\test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"..\\\\test.html\"", "attachment; filename=\"..\\\\test.html\"",
"", "",
"", "",
"", "",
L"", L"",
L"-test.html" L"-test.html"},
}, {// Filename disappears after leading and trailing periods are removed.
{ // Filename disappears after leading and trailing periods are removed.
__LINE__, __LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"..\"", "attachment; filename=\"..\"",
...@@ -642,9 +533,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -642,9 +533,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"default", L"default",
L"default" L"default"},
}, {// C-D specified filename disappears. Failover to final filename.
{ // C-D specified filename disappears. Failover to final filename.
__LINE__, __LINE__,
"http://www.google.com/test.html", "http://www.google.com/test.html",
"attachment; filename=\"..\"", "attachment; filename=\"..\"",
...@@ -652,11 +542,9 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -652,11 +542,9 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"default", L"default",
L"default" L"default"},
},
// Below is a small subset of cases taken from HttpContentDisposition tests. // Below is a small subset of cases taken from HttpContentDisposition tests.
{ {__LINE__,
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"%EC%98%88%EC%88%A0%20" "attachment; filename=\"%EC%98%88%EC%88%A0%20"
"%EC%98%88%EC%88%A0.jpg\"", "%EC%98%88%EC%88%A0.jpg\"",
...@@ -664,30 +552,24 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -664,30 +552,24 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"\uc608\uc220 \uc608\uc220.jpg" L"\uc608\uc220 \uc608\uc220.jpg"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
"", "",
"", "",
"", "",
"", "",
L"download", L"download",
L"\uc608\uc220 \uc608\uc220.jpg" L"\uc608\uc220 \uc608\uc220.jpg"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment;", "attachment;",
"", "",
"", "",
"", "",
L"\uB2E4\uC6B4\uB85C\uB4DC", L"\uB2E4\uC6B4\uB85C\uB4DC",
L"\uB2E4\uC6B4\uB85C\uB4DC" L"\uB2E4\uC6B4\uB85C\uB4DC"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/", "http://www.google.com/",
"attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" "attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD="
"D13=2Epng?=\"", "D13=2Epng?=\"",
...@@ -695,39 +577,32 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -695,39 +577,32 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"download", L"download",
L"\u82b8\u88533.png" L"\u82b8\u88533.png"},
}, {__LINE__,
{
__LINE__,
"http://www.example.com/images?id=3", "http://www.example.com/images?id=3",
"attachment; filename=caf\xc3\xa9.png", "attachment; filename=caf\xc3\xa9.png",
"iso-8859-1", "iso-8859-1",
"", "",
"", "",
L"", L"",
L"caf\u00e9.png" L"caf\u00e9.png"},
}, {__LINE__,
{
__LINE__,
"http://www.example.com/images?id=3", "http://www.example.com/images?id=3",
"attachment; filename=caf\xe5.png", "attachment; filename=caf\xe5.png",
"windows-1253", "windows-1253",
"", "",
"", "",
L"", L"",
L"caf\u03b5.png" L"caf\u03b5.png"},
}, {__LINE__,
{
__LINE__,
"http://www.example.com/file?id=3", "http://www.example.com/file?id=3",
"attachment; name=\xcf\xc2\xd4\xd8.zip", "attachment; name=\xcf\xc2\xd4\xd8.zip",
"GBK", "GBK",
"", "",
"", "",
L"", L"",
L"\u4e0b\u8f7d.zip" L"\u4e0b\u8f7d.zip"},
}, {// Invalid C-D header. Extracts filename from url.
{ // Invalid C-D header. Extracts filename from url.
__LINE__, __LINE__,
"http://www.google.com/test.html", "http://www.google.com/test.html",
"attachment; filename==?iiso88591?Q?caf=EG?=", "attachment; filename==?iiso88591?Q?caf=EG?=",
...@@ -735,60 +610,35 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -735,60 +610,35 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"test.html" L"test.html"},
},
// about: and data: URLs // about: and data: URLs
{ {__LINE__, "about:chrome", "", "", "", "", L"", L"download"},
__LINE__, {__LINE__, "data:,looks/like/a.path", "", "", "", "", L"", L"download"},
"about:chrome", {__LINE__,
"",
"",
"",
"",
L"",
L"download"
},
{
__LINE__,
"data:,looks/like/a.path",
"",
"",
"",
"",
L"",
L"download"
},
{
__LINE__,
"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", "data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=",
"", "",
"", "",
"", "",
"", "",
L"", L"",
L"download" L"download"},
}, {__LINE__,
{
__LINE__,
"data:,looks/like/a.path", "data:,looks/like/a.path",
"", "",
"", "",
"", "",
"", "",
L"default_filename_is_given", L"default_filename_is_given",
L"default_filename_is_given" L"default_filename_is_given"},
}, {__LINE__,
{
__LINE__,
"data:,looks/like/a.path", "data:,looks/like/a.path",
"", "",
"", "",
"", "",
"", "",
L"\u65e5\u672c\u8a9e", // Japanese Kanji. L"\u65e5\u672c\u8a9e", // Japanese Kanji.
L"\u65e5\u672c\u8a9e" L"\u65e5\u672c\u8a9e"},
}, {// The filename encoding is specified by the referrer charset.
{ // The filename encoding is specified by the referrer charset.
__LINE__, __LINE__,
"http://example.com/V%FDvojov%E1%20psychologie.doc", "http://example.com/V%FDvojov%E1%20psychologie.doc",
"", "",
...@@ -796,9 +646,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -796,9 +646,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"", "",
L"", L"",
L"V\u00fdvojov\u00e1 psychologie.doc" L"V\u00fdvojov\u00e1 psychologie.doc"},
}, {// Suggested filename takes precedence over URL
{ // Suggested filename takes precedence over URL
__LINE__, __LINE__,
"http://www.google.com/test", "http://www.google.com/test",
"", "",
...@@ -806,9 +655,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -806,9 +655,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"suggested", "suggested",
"", "",
L"", L"",
L"suggested" L"suggested"},
}, {// The content-disposition has higher precedence over the suggested name.
{ // The content-disposition has higher precedence over the suggested name.
__LINE__, __LINE__,
"http://www.google.com/test", "http://www.google.com/test",
"attachment; filename=test.html", "attachment; filename=test.html",
...@@ -816,18 +664,15 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -816,18 +664,15 @@ TEST(FilenameUtilTest, GenerateFileName) {
"suggested", "suggested",
"", "",
L"", L"",
L"test.html" L"test.html"},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/test", "http://www.google.com/test",
"attachment; filename=test", "attachment; filename=test",
"utf-8", "utf-8",
"", "",
"image/png", "image/png",
L"", L"",
L"test" L"test"},
},
#if 0 #if 0
{ // The filename encoding doesn't match the referrer charset, the system { // The filename encoding doesn't match the referrer charset, the system
// charset, or UTF-8. // charset, or UTF-8.
...@@ -843,27 +688,23 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -843,27 +688,23 @@ TEST(FilenameUtilTest, GenerateFileName) {
}, },
#endif #endif
// Raw 8bit characters in C-D // Raw 8bit characters in C-D
{ {__LINE__,
__LINE__,
"http://www.example.com/images?id=3", "http://www.example.com/images?id=3",
"attachment; filename=caf\xc3\xa9.png", "attachment; filename=caf\xc3\xa9.png",
"iso-8859-1", "iso-8859-1",
"", "",
"image/png", "image/png",
L"", L"",
L"caf\u00e9.png" L"caf\u00e9.png"},
}, {__LINE__,
{
__LINE__,
"http://www.example.com/images?id=3", "http://www.example.com/images?id=3",
"attachment; filename=caf\xe5.png", "attachment; filename=caf\xe5.png",
"windows-1253", "windows-1253",
"", "",
"image/png", "image/png",
L"", L"",
L"caf\u03b5.png" L"caf\u03b5.png"},
}, {// No 'filename' keyword in the disposition, use the URL
{ // No 'filename' keyword in the disposition, use the URL
__LINE__, __LINE__,
"http://www.evil.com/my_download.txt", "http://www.evil.com/my_download.txt",
"a_file_name.txt", "a_file_name.txt",
...@@ -871,9 +712,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -871,9 +712,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"text/plain", "text/plain",
L"download", L"download",
L"my_download.txt" L"my_download.txt"},
}, {// Spaces in the disposition file name
{ // Spaces in the disposition file name
__LINE__, __LINE__,
"http://www.frontpagehacker.com/a_download.exe", "http://www.frontpagehacker.com/a_download.exe",
"filename=My Downloaded File.exe", "filename=My Downloaded File.exe",
...@@ -881,9 +721,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -881,9 +721,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"application/octet-stream", "application/octet-stream",
L"download", L"download",
L"My Downloaded File.exe" L"My Downloaded File.exe"},
}, {// % encoded
{ // % encoded
__LINE__, __LINE__,
"http://www.examples.com/", "http://www.examples.com/",
"attachment; " "attachment; "
...@@ -892,9 +731,8 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -892,9 +731,8 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"image/jpeg", "image/jpeg",
L"download", L"download",
L"\uc608\uc220 \uc608\uc220.jpg" L"\uc608\uc220 \uc608\uc220.jpg"},
}, {// name= parameter
{ // name= parameter
__LINE__, __LINE__,
"http://www.examples.com/q.cgi?id=abc", "http://www.examples.com/q.cgi?id=abc",
"attachment; name=abc de.pdf", "attachment; name=abc de.pdf",
...@@ -902,19 +740,17 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -902,19 +740,17 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"application/octet-stream", "application/octet-stream",
L"download", L"download",
L"abc de.pdf" L"abc de.pdf"},
}, {__LINE__,
{
__LINE__,
"http://www.example.com/path", "http://www.example.com/path",
"filename=\"=?EUC-JP?Q?=B7=DD=BD=D13=2Epng?=\"", "filename=\"=?EUC-JP?Q?=B7=DD=BD=D13=2Epng?=\"",
"", "",
"", "",
"image/png", "image/png",
L"download", L"download",
L"\x82b8\x8853" L"3.png" L"\x82b8\x8853"
}, L"3.png"},
{ // The following two have invalid CD headers and filenames come from the {// The following two have invalid CD headers and filenames come from the
// URL. // URL.
__LINE__, __LINE__,
"http://www.example.com/test%20123", "http://www.example.com/test%20123",
...@@ -923,19 +759,16 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -923,19 +759,16 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"image/jpeg", "image/jpeg",
L"download", L"download",
L"test 123" JPEG_EXT L"test 123" JPEG_EXT},
}, {__LINE__,
{
__LINE__,
"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
"malformed_disposition", "malformed_disposition",
"", "",
"", "",
"image/jpeg", "image/jpeg",
L"download", L"download",
L"\uc608\uc220 \uc608\uc220.jpg" L"\uc608\uc220 \uc608\uc220.jpg"},
}, {// Invalid C-D. No filename from URL. Falls back to 'download'.
{ // Invalid C-D. No filename from URL. Falls back to 'download'.
__LINE__, __LINE__,
"http://www.google.com/path1/path2/", "http://www.google.com/path1/path2/",
"attachment; filename==?iso88591?Q?caf=E3?", "attachment; filename==?iso88591?Q?caf=E3?",
...@@ -943,8 +776,7 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -943,8 +776,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
"", "",
"image/jpeg", "image/jpeg",
L"download", L"download",
L"download" JPEG_EXT L"download" JPEG_EXT},
},
}; };
// Tests filename generation. Once the correct filename is // Tests filename generation. Once the correct filename is
...@@ -1067,7 +899,7 @@ TEST(FilenameUtilTest, GenerateFileName) { ...@@ -1067,7 +899,7 @@ TEST(FilenameUtilTest, GenerateFileName) {
"text/plain", "text/plain",
L"download", L"download",
L"my-cat.jpg"}, L"my-cat.jpg"},
// Windows specific tests // Windows specific tests
#if defined(OS_WIN) #if defined(OS_WIN)
{__LINE__, {__LINE__,
"http://www.goodguy.com/evil.exe", "http://www.goodguy.com/evil.exe",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment