Chromium Code Reviews| Index: net/base/net_util_unittest.cc |
| =================================================================== |
| --- net/base/net_util_unittest.cc (revision 85116) |
| +++ 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,31 +1049,37 @@ |
| {"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/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 |
| @@ -1081,51 +1088,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. |
| @@ -1133,93 +1150,116 @@ |
| "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"}, |
|
asanka
2011/05/13 13:32:24
Could you also add a test to check that C-D has hi
jianli
2011/05/17 00:10:44
Done.
|
| // The filename encoding doesn't match the referrer charset, the |
| // system charset, or UTF-8. |
| // TODO(jshin): we need to handle this case. |
| @@ -1227,6 +1267,7 @@ |
| {"http://example.com/V%FDvojov%E1%20psychologie.doc", |
| "", |
| "utf-8", |
| + "", |
| L"", |
| L"V\u00fdvojov\u00e1 psychologie.doc", |
| }, |
| @@ -1236,7 +1277,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; |