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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 size_t file_count = arraysize(files_to_verify); 71 size_t file_count = arraysize(files_to_verify);
72 for (size_t i = 0; i < file_count; i++) { 72 for (size_t i = 0; i < file_count; i++) {
73 const char* relative_path = files_to_verify[i]; 73 const char* relative_path = files_to_verify[i];
74 base::FilePath orig_file = src.Append(relative_path); 74 base::FilePath orig_file = src.Append(relative_path);
75 base::FilePath final_file = 75 base::FilePath final_file =
76 temp_dir.path().Append(app_name).Append(relative_path); 76 temp_dir.path().Append(app_name).Append(relative_path);
77 EXPECT_TRUE(base::ContentsEqual(orig_file, final_file)); 77 EXPECT_TRUE(base::ContentsEqual(orig_file, final_file));
78 } 78 }
79 } 79 }
80 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 80 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
81
82 TEST_F(FileSelectHelperTest, GetSanitizedFileName) {
83 // The empty path should be preserved.
84 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("")),
85 FileSelectHelper::GetSanitizedFileName(base::FilePath()));
86
87 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("ascii.txt")),
88 FileSelectHelper::GetSanitizedFileName(
89 base::FilePath(FILE_PATH_LITERAL("ascii.txt"))));
90 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("trailing-spaces-")),
91 FileSelectHelper::GetSanitizedFileName(
92 base::FilePath(FILE_PATH_LITERAL("trailing-spaces "))));
93 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("path-components-in-name")),
94 FileSelectHelper::GetSanitizedFileName(
95 base::FilePath(FILE_PATH_LITERAL("path/components/in/name"))));
96
97 #if defined(OS_WIN)
98 // Invalid UTF-16. However, note that on Windows, the invalid UTF-16 will pass
99 // through without error.
100 base::FilePath::CharType kBadName[] = {0xd801, 0xdc37, 0xdc17, 0};
101 #else
102 // Invalid UTF-8
103 base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0};
104 #endif
105 base::FilePath bad_filename(kBadName);
106 ASSERT_FALSE(bad_filename.empty());
107 // The only thing we are testing is that if the source filename was non-empty,
108 // the resulting filename is also not empty. Invalid encoded filenames can
109 // cause conversions to fail. Such failures shouldn't cause the resulting
110 // filename to disappear.
111 EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty());
112 }
OLDNEW
« 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