| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |