| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ASSERT_FALSE(dest.empty()); | 56 ASSERT_FALSE(dest.empty()); |
| 57 ASSERT_TRUE(base::PathExists(dest)); | 57 ASSERT_TRUE(base::PathExists(dest)); |
| 58 | 58 |
| 59 base::ScopedTempDir temp_dir; | 59 base::ScopedTempDir temp_dir; |
| 60 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 60 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 61 | 61 |
| 62 // Unzip the package into a temporary directory. | 62 // Unzip the package into a temporary directory. |
| 63 base::CommandLine cl(base::FilePath("/usr/bin/unzip")); | 63 base::CommandLine cl(base::FilePath("/usr/bin/unzip")); |
| 64 cl.AppendArg(dest.value().c_str()); | 64 cl.AppendArg(dest.value().c_str()); |
| 65 cl.AppendArg("-d"); | 65 cl.AppendArg("-d"); |
| 66 cl.AppendArg(temp_dir.path().value().c_str()); | 66 cl.AppendArg(temp_dir.GetPath().value().c_str()); |
| 67 std::string output; | 67 std::string output; |
| 68 EXPECT_TRUE(base::GetAppOutput(cl, &output)); | 68 EXPECT_TRUE(base::GetAppOutput(cl, &output)); |
| 69 | 69 |
| 70 // Verify that several key files haven't changed. | 70 // Verify that several key files haven't changed. |
| 71 const char* files_to_verify[] = {"Contents/Info.plist", | 71 const char* files_to_verify[] = {"Contents/Info.plist", |
| 72 "Contents/MacOS/Calculator", | 72 "Contents/MacOS/Calculator", |
| 73 "Contents/_CodeSignature/CodeResources"}; | 73 "Contents/_CodeSignature/CodeResources"}; |
| 74 size_t file_count = arraysize(files_to_verify); | 74 size_t file_count = arraysize(files_to_verify); |
| 75 for (size_t i = 0; i < file_count; i++) { | 75 for (size_t i = 0; i < file_count; i++) { |
| 76 const char* relative_path = files_to_verify[i]; | 76 const char* relative_path = files_to_verify[i]; |
| 77 base::FilePath orig_file = src.Append(relative_path); | 77 base::FilePath orig_file = src.Append(relative_path); |
| 78 base::FilePath final_file = | 78 base::FilePath final_file = |
| 79 temp_dir.path().Append(app_name).Append(relative_path); | 79 temp_dir.GetPath().Append(app_name).Append(relative_path); |
| 80 EXPECT_TRUE(base::ContentsEqual(orig_file, final_file)); | 80 EXPECT_TRUE(base::ContentsEqual(orig_file, final_file)); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 #endif // defined(OS_MACOSX) | 83 #endif // defined(OS_MACOSX) |
| 84 | 84 |
| 85 TEST_F(FileSelectHelperTest, GetSanitizedFileName) { | 85 TEST_F(FileSelectHelperTest, GetSanitizedFileName) { |
| 86 // The empty path should be preserved. | 86 // The empty path should be preserved. |
| 87 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("")), | 87 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("")), |
| 88 FileSelectHelper::GetSanitizedFileName(base::FilePath())); | 88 FileSelectHelper::GetSanitizedFileName(base::FilePath())); |
| 89 | 89 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0}; | 106 base::FilePath::CharType kBadName[] = {0xe3, 0x81, 0x81, 0x81, 0x82, 0}; |
| 107 #endif | 107 #endif |
| 108 base::FilePath bad_filename(kBadName); | 108 base::FilePath bad_filename(kBadName); |
| 109 ASSERT_FALSE(bad_filename.empty()); | 109 ASSERT_FALSE(bad_filename.empty()); |
| 110 // The only thing we are testing is that if the source filename was non-empty, | 110 // The only thing we are testing is that if the source filename was non-empty, |
| 111 // the resulting filename is also not empty. Invalid encoded filenames can | 111 // the resulting filename is also not empty. Invalid encoded filenames can |
| 112 // cause conversions to fail. Such failures shouldn't cause the resulting | 112 // cause conversions to fail. Such failures shouldn't cause the resulting |
| 113 // filename to disappear. | 113 // filename to disappear. |
| 114 EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty()); | 114 EXPECT_FALSE(FileSelectHelper::GetSanitizedFileName(bad_filename).empty()); |
| 115 } | 115 } |
| OLD | NEW |