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

Side by Side Diff: base/process/process_util_unittest.cc

Issue 885423003: Add the ability to change directories before execing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 RAW_CHECK(getpid() == ctid); 1016 RAW_CHECK(getpid() == ctid);
1017 _exit(kSuccess); 1017 _exit(kSuccess);
1018 } 1018 }
1019 1019
1020 ASSERT_NE(-1, pid); 1020 ASSERT_NE(-1, pid);
1021 int status = 42; 1021 int status = 42;
1022 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); 1022 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
1023 ASSERT_TRUE(WIFEXITED(status)); 1023 ASSERT_TRUE(WIFEXITED(status));
1024 EXPECT_EQ(kSuccess, WEXITSTATUS(status)); 1024 EXPECT_EQ(kSuccess, WEXITSTATUS(status));
1025 } 1025 }
1026
1027 MULTIPROCESS_TEST_MAIN(CheckCwdProcess) {
1028 base::FilePath expected;
1029 CHECK(base::GetTempDir(&expected));
1030 base::FilePath actual;
1031 CHECK(base::GetCurrentDirectory(&actual));
1032 CHECK(actual == expected);
1033 return kSuccess;
1034 }
1035
1036 TEST_F(ProcessUtilTest, CurrentDirectory) {
1037 // TODO(rickyz): Add support for passing arguments to multiprocess children,
1038 // then create a special directory for this test.
1039 base::FilePath tmp_dir;
1040 ASSERT_TRUE(base::GetTempDir(&tmp_dir));
1041
1042 base::LaunchOptions options;
1043 options.current_directory = tmp_dir;
1044
1045 base::Process process(SpawnChildWithOptions("CheckCwdProcess", options));
1046 ASSERT_TRUE(process.IsValid());
1047
1048 int exit_code = 42;
1049 EXPECT_TRUE(process.WaitForExit(&exit_code));
1050 EXPECT_EQ(kSuccess, exit_code);
1051 }
1052
1053 TEST_F(ProcessUtilTest, InvalidCurrentDirectory) {
1054 base::LaunchOptions options;
1055 options.current_directory = base::FilePath("/dev/null");
1056
1057 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options));
1058 ASSERT_TRUE(process.IsValid());
1059
1060 int exit_code = kSuccess;
1061 EXPECT_TRUE(process.WaitForExit(&exit_code));
1062 EXPECT_NE(kSuccess, exit_code);
1063 }
1026 #endif 1064 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698