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

Unified Diff: base/files/file_util_unittest.cc

Issue 2086103002: Add base::ExecutableExistsInPath (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't leak base::Environment Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_util_posix.cc ('k') | chrome/browser/printing/printer_manager_dialog_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
+ 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)
« no previous file with comments | « base/files/file_util_posix.cc ('k') | chrome/browser/printing/printer_manager_dialog_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698