Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(906)

Unified Diff: chrome/browser/file_select_helper_unittest.cc

Issue 1409003002: [SafeBrowsing] Block dangerous unchecked downloads based on a Finch trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}
« no previous file with comments | « chrome/browser/file_select_helper.cc ('k') | chrome/browser/safe_browsing/unverified_download_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698