OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "components/browser_watcher/exit_code_watcher_win.h" | 5 #include "components/browser_watcher/exit_code_watcher_win.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/process/process.h" | 8 #include "base/process/process.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 return 1; | 31 return 1; |
32 } | 32 } |
33 | 33 |
34 class ScopedSleeperProcess { | 34 class ScopedSleeperProcess { |
35 public: | 35 public: |
36 ScopedSleeperProcess() : is_killed_(false) { | 36 ScopedSleeperProcess() : is_killed_(false) { |
37 } | 37 } |
38 | 38 |
39 ~ScopedSleeperProcess() { | 39 ~ScopedSleeperProcess() { |
40 if (process_.IsValid()) { | 40 if (process_.IsValid()) { |
41 process_.Terminate(-1); | 41 process_.Terminate(-1, false); |
42 int exit_code = 0; | 42 int exit_code = 0; |
43 EXPECT_TRUE(process_.WaitForExit(&exit_code)); | 43 EXPECT_TRUE(process_.WaitForExit(&exit_code)); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 void Launch() { | 47 void Launch() { |
48 ASSERT_FALSE(process_.IsValid()); | 48 ASSERT_FALSE(process_.IsValid()); |
49 | 49 |
50 base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine()); | 50 base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine()); |
51 base::LaunchOptions options; | 51 base::LaunchOptions options; |
52 options.start_hidden = true; | 52 options.start_hidden = true; |
53 process_ = base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options); | 53 process_ = base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options); |
54 ASSERT_TRUE(process_.IsValid()); | 54 ASSERT_TRUE(process_.IsValid()); |
55 } | 55 } |
56 | 56 |
57 void Kill(int exit_code, bool wait) { | 57 void Kill(int exit_code, bool wait) { |
58 ASSERT_TRUE(process_.IsValid()); | 58 ASSERT_TRUE(process_.IsValid()); |
59 ASSERT_FALSE(is_killed_); | 59 ASSERT_FALSE(is_killed_); |
60 process_.Terminate(exit_code); | 60 process_.Terminate(exit_code, false); |
61 int seen_exit_code = 0; | 61 int seen_exit_code = 0; |
62 EXPECT_TRUE(process_.WaitForExit(&seen_exit_code)); | 62 EXPECT_TRUE(process_.WaitForExit(&seen_exit_code)); |
63 EXPECT_EQ(exit_code, seen_exit_code); | 63 EXPECT_EQ(exit_code, seen_exit_code); |
64 is_killed_ = true; | 64 is_killed_ = true; |
65 } | 65 } |
66 | 66 |
67 const base::Process& process() const { return process_; } | 67 const base::Process& process() const { return process_; } |
68 | 68 |
69 private: | 69 private: |
70 base::Process process_; | 70 base::Process process_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Kill the sleeper, and make sure it's exited before we continue. | 161 // Kill the sleeper, and make sure it's exited before we continue. |
162 ASSERT_NO_FATAL_FAILURE(sleeper.Kill(kExitCode, true)); | 162 ASSERT_NO_FATAL_FAILURE(sleeper.Kill(kExitCode, true)); |
163 | 163 |
164 watcher.WaitForExit(); | 164 watcher.WaitForExit(); |
165 EXPECT_EQ(kExitCode, watcher.exit_code()); | 165 EXPECT_EQ(kExitCode, watcher.exit_code()); |
166 | 166 |
167 VerifyWroteExitCode(sleeper.process().Pid(), kExitCode); | 167 VerifyWroteExitCode(sleeper.process().Pid(), kExitCode); |
168 } | 168 } |
169 | 169 |
170 } // namespace browser_watcher | 170 } // namespace browser_watcher |
OLD | NEW |