| 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 // The following test expectations assume that the tests run with the locale |
| 98 // set to en-us. Chrome unit_tests are initialized to use en-us. |
| 99 #if defined(OS_WIN) |
| 100 // Invalid UTF-16 |
| 101 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("download")), |
| 102 FileSelectHelper::GetSanitizedFileName( |
| 103 base::FilePath(FILE_PATH_LITERAL("\ud801\udc37\udc17")))); |
| 104 #else |
| 105 // Invalid UTF-8 |
| 106 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("download")), |
| 107 FileSelectHelper::GetSanitizedFileName( |
| 108 base::FilePath(FILE_PATH_LITERAL("\xe3\x81\x81\x81\x82")))); |
| 109 #endif |
| 110 } |
| OLD | NEW |