Chromium Code Reviews| Index: base/files/file_util_unittest.cc |
| diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc |
| index ac3a654fdd3d8b179ecc9710b8fd48a1b4ab7a36..09c91566264dc45bdfedbe24ddeffcd805e6889b 100644 |
| --- a/base/files/file_util_unittest.cc |
| +++ b/base/files/file_util_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include <vector> |
| #include "base/base_paths.h" |
| +#include "base/environment.h" |
| #include "base/files/file_enumerator.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| @@ -838,6 +839,45 @@ TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
| EXPECT_FALSE(PathExists(subdir_path)); |
| } |
| +TEST_F(FileUtilTest, ExecutableExistsInPath) { |
| + // Create two directories that we will put in our PATH |
| + const char kPath[] = "PATH"; |
| + const FilePath::CharType kDir1[] = FPL("dir1"); |
| + const FilePath::CharType kDir2[] = FPL("dir2"); |
| + |
| + FilePath dir1 = temp_dir_.path().Append(kDir1); |
| + FilePath dir2 = temp_dir_.path().Append(kDir2); |
| + ASSERT_TRUE(CreateDirectory(dir1)); |
| + ASSERT_TRUE(CreateDirectory(dir2)); |
| + |
| + std::unique_ptr<Environment> env(base::Environment::Create()); |
| + |
| + ASSERT_TRUE(env->SetVar(kPath, dir1.value() + ":" + dir2.value())); |
| + |
| + const FilePath::CharType kRegularFileName[] = FPL("regular_file"); |
| + const FilePath::CharType kExeFileName[] = FPL("exe"); |
| + const FilePath::CharType kDneFileName[] = FPL("does_not_exist"); |
| + |
| + const FilePath kExePath = dir1.Append(kExeFileName); |
| + const FilePath kRegularFilePath = dir2.Append(kRegularFileName); |
| + |
| + // Write file. |
|
Lei Zhang
2016/06/23 19:17:06
Maybe just TouchFile() instead?
Tom (Use chromium acct)
2016/06/23 21:55:12
TouchFile checks if a file exists first
https://cs
Lei Zhang
2016/06/23 22:21:46
I'm going to change my title to Offerer of Bad Adv
|
| + const std::string kData("hello"); |
| + ASSERT_EQ(static_cast<int>(kData.length()), |
| + WriteFile(kExePath, kData.data(), kData.length())); |
| + ASSERT_TRUE(PathExists(kExePath)); |
| + ASSERT_EQ(static_cast<int>(kData.length()), |
| + WriteFile(kRegularFilePath, kData.data(), kData.length())); |
| + ASSERT_TRUE(PathExists(kRegularFilePath)); |
| + |
| + ASSERT_TRUE(SetPosixFilePermissions(dir1.Append(kExeFileName), |
| + FILE_PERMISSION_EXECUTE_BY_USER)); |
| + |
| + EXPECT_TRUE(ExecutableExistsInPath(env.get(), kExeFileName)); |
| + EXPECT_FALSE(ExecutableExistsInPath(env.get(), kRegularFileName)); |
| + EXPECT_FALSE(ExecutableExistsInPath(env.get(), kDneFileName)); |
| +} |
| + |
| #endif // defined(OS_POSIX) |
| #if defined(OS_WIN) |