| Index: chrome/browser/file_select_helper_unittest.cc
|
| diff --git a/chrome/browser/file_select_helper_unittest.cc b/chrome/browser/file_select_helper_unittest.cc
|
| index c7c128e3b4ac392060d07aba87ae0454acb3a88d..823ccc0843fbe68f77622b28b52193552a93a227 100644
|
| --- a/chrome/browser/file_select_helper_unittest.cc
|
| +++ b/chrome/browser/file_select_helper_unittest.cc
|
| @@ -78,3 +78,35 @@ TEST_F(FileSelectHelperTest, ZipPackage) {
|
| }
|
| }
|
| #endif // defined(OS_MACOSX) && !defined(OS_IOS)
|
| +
|
| +TEST_F(FileSelectHelperTest, GetSanitizedFileName) {
|
| + // The empty path should be preserved.
|
| + EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("")),
|
| + FileSelectHelper::GetSanitizedFileName(base::FilePath()));
|
| +
|
| + EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("ascii.txt")),
|
| + FileSelectHelper::GetSanitizedFileName(
|
| + base::FilePath(FILE_PATH_LITERAL("ascii.txt"))));
|
| + EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("trailing-spaces-")),
|
| + FileSelectHelper::GetSanitizedFileName(
|
| + base::FilePath(FILE_PATH_LITERAL("trailing-spaces "))));
|
| + EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("path-components-in-name")),
|
| + FileSelectHelper::GetSanitizedFileName(
|
| + base::FilePath(FILE_PATH_LITERAL("path/components/in/name"))));
|
| +
|
| +#if defined(OS_WIN)
|
| + // Invalid UTF-16. However, note that on Windows, the invalid UTF-16 will pass
|
| + // through without error.
|
| + base::FilePath::CharType kBadName[] = {0xd801, 0xdc37, 0xdc17, 0};
|
| +#else
|
| + // Invalid UTF-8
|
| + base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0};
|
| +#endif
|
| + base::FilePath bad_filename(kBadName);
|
| + ASSERT_FALSE(bad_filename.empty());
|
| + // The only thing we are testing is that if the source filename was non-empty,
|
| + // the resulting filename is also not empty. Invalid encoded filenames can
|
| + // cause conversions to fail. Such failures shouldn't cause the resulting
|
| + // filename to disappear.
|
| + EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty());
|
| +}
|
|
|