Index: net/base/net_util_unittest.cc |
=================================================================== |
--- net/base/net_util_unittest.cc (revision 85826) |
+++ net/base/net_util_unittest.cc (working copy) |
@@ -386,6 +386,7 @@ |
const char* url; |
const char* content_disp_header; |
const char* referrer_charset; |
+ const char* suggested_filename; |
const wchar_t* default_filename; |
const wchar_t* expected_filename; |
}; |
@@ -1048,46 +1049,55 @@ |
{"http://www.google.com/", |
"Content-disposition: attachment; filename=test.html", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename=\"test.html\"", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename= \"test.html\"", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename = \"test.html\"", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename= ", |
"", |
+ "", |
L"", |
L"www.google.com"}, |
{"http://www.google.com/path/test.html", |
"Content-disposition: attachment", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/path/test.html", |
"Content-disposition: attachment;", |
"", |
+ "", |
L"", |
L"test.html"}, |
{"http://www.google.com/", |
"", |
"", |
+ "", |
L"", |
L"www.google.com"}, |
{"http://www.google.com/test.html", |
"", |
"", |
+ "", |
L"", |
L"test.html"}, |
// Now that we use googleurl's ExtractFileName, this case falls back |
@@ -1096,51 +1106,61 @@ |
{"http://www.google.com/path/", |
"", |
"", |
+ "", |
L"", |
L"www.google.com"}, |
{"http://www.google.com/path", |
"", |
"", |
+ "", |
L"", |
L"path"}, |
{"file:///", |
"", |
"", |
+ "", |
L"", |
L"download"}, |
{"non-standard-scheme:", |
"", |
"", |
+ "", |
L"", |
L"download"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename =\"test.html\"", |
"", |
+ "", |
L"download", |
L"test.html"}, |
{"http://www.google.com/", |
"", |
"", |
+ "", |
L"download", |
L"download"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename=\"../test.html\"", |
"", |
+ "", |
L"", |
L"_test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename=\"..\\test.html\"", |
"", |
+ "", |
L"", |
L"_test.html"}, |
{"http://www.google.com/", |
"Content-disposition: attachment; filename=\"..\"", |
"", |
+ "", |
L"download", |
L"download"}, |
{"http://www.google.com/test.html", |
"Content-disposition: attachment; filename=\"..\"", |
"", |
+ "", |
L"download", |
L"test.html"}, |
// Below is a small subset of cases taken from GetFileNameFromCD test above. |
@@ -1148,93 +1168,123 @@ |
"Content-Disposition: attachment; filename=\"%EC%98%88%EC%88%A0%20" |
"%EC%98%88%EC%88%A0.jpg\"", |
"", |
+ "", |
L"", |
L"\uc608\uc220 \uc608\uc220.jpg"}, |
{"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
"", |
"", |
+ "", |
L"download", |
L"\uc608\uc220 \uc608\uc220.jpg"}, |
{"http://www.google.com/", |
"Content-disposition: attachment;", |
"", |
+ "", |
L"\uB2E4\uC6B4\uB85C\uB4DC", |
L"\uB2E4\uC6B4\uB85C\uB4DC"}, |
{"http://www.google.com/", |
"Content-Disposition: attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
"D13=2Epng?=\"", |
"", |
+ "", |
L"download", |
L"\u82b8\u88533.png"}, |
{"http://www.example.com/images?id=3", |
"Content-Disposition: attachment; filename=caf\xc3\xa9.png", |
"iso-8859-1", |
+ "", |
L"", |
L"caf\u00e9.png"}, |
{"http://www.example.com/images?id=3", |
"Content-Disposition: attachment; filename=caf\xe5.png", |
"windows-1253", |
+ "", |
L"", |
L"caf\u03b5.png"}, |
{"http://www.example.com/file?id=3", |
"Content-Disposition: attachment; name=\xcf\xc2\xd4\xd8.zip", |
"GBK", |
+ "", |
L"", |
L"\u4e0b\u8f7d.zip"}, |
// Invalid C-D header. Extracts filename from url. |
{"http://www.google.com/test.html", |
"Content-Disposition: attachment; filename==?iiso88591?Q?caf=EG?=", |
"", |
+ "", |
L"", |
L"test.html"}, |
// about: and data: URLs |
{"about:chrome", |
"", |
"", |
+ "", |
L"", |
L"download"}, |
{"data:,looks/like/a.path", |
"", |
"", |
+ "", |
L"", |
L"download"}, |
{"data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", |
"", |
"", |
+ "", |
L"", |
L"download"}, |
{"data:,looks/like/a.path", |
"", |
"", |
+ "", |
L"default_filename_is_given", |
L"default_filename_is_given"}, |
{"data:,looks/like/a.path", |
"", |
"", |
+ "", |
L"\u65e5\u672c\u8a9e", // Japanese Kanji. |
L"\u65e5\u672c\u8a9e"}, |
// Dotfiles. Ensures preceeding period(s) stripped. |
{"http://www.google.com/.test.html", |
- "", |
- "", |
- L"", |
- L"test.html"}, |
+ "", |
+ "", |
+ "", |
+ L"", |
+ L"test.html"}, |
{"http://www.google.com/.test", |
- "", |
- "", |
- L"", |
- L"test"}, |
+ "", |
+ "", |
+ "", |
+ L"", |
+ L"test"}, |
{"http://www.google.com/..test", |
- "", |
- "", |
- L"", |
- L"test"}, |
+ "", |
+ "", |
+ "", |
+ L"", |
+ L"test"}, |
// The filename encoding is specified by the referrer charset. |
{"http://example.com/V%FDvojov%E1%20psychologie.doc", |
"", |
"iso-8859-1", |
+ "", |
L"", |
L"V\u00fdvojov\u00e1 psychologie.doc"}, |
+ {"http://www.google.com/test", |
+ "", |
+ "", |
+ "suggested", |
+ L"", |
+ L"suggested"}, |
+ // The content-disposition has higher precedence over the suggested name. |
+ {"http://www.google.com/test", |
+ "Content-disposition: attachment; filename=test.html", |
+ "", |
+ "suggested", |
+ L"", |
+ L"test.html"}, |
// The filename encoding doesn't match the referrer charset, the |
// system charset, or UTF-8. |
// TODO(jshin): we need to handle this case. |
@@ -1242,6 +1292,7 @@ |
{"http://example.com/V%FDvojov%E1%20psychologie.doc", |
"", |
"utf-8", |
+ "", |
L"", |
L"V\u00fdvojov\u00e1 psychologie.doc", |
}, |
@@ -1251,7 +1302,8 @@ |
std::wstring default_name = test_cases[i].default_filename; |
string16 filename = GetSuggestedFilename( |
GURL(test_cases[i].url), test_cases[i].content_disp_header, |
- test_cases[i].referrer_charset, WideToUTF16(default_name)); |
+ test_cases[i].referrer_charset, test_cases[i].suggested_filename, |
+ WideToUTF16(default_name)); |
EXPECT_EQ(std::wstring(test_cases[i].expected_filename), |
UTF16ToWide(filename)) |
<< "Iteration " << i << ": " << test_cases[i].url; |