OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // The wait should always return because either |ready_event| is signaled or | 199 // The wait should always return because either |ready_event| is signaled or |
200 // |browser_victim_| died unexpectedly or exited on error. | 200 // |browser_victim_| died unexpectedly or exited on error. |
201 DWORD result = | 201 DWORD result = |
202 ::WaitForMultipleObjects(arraysize(handles), handles, FALSE, INFINITE); | 202 ::WaitForMultipleObjects(arraysize(handles), handles, FALSE, INFINITE); |
203 ASSERT_EQ(WAIT_OBJECT_0, result); | 203 ASSERT_EQ(WAIT_OBJECT_0, result); |
204 } | 204 } |
205 | 205 |
206 base::CommandLine MakeCmdLine(const std::string& procname) override { | 206 base::CommandLine MakeCmdLine(const std::string& procname) override { |
207 base::CommandLine cmd_line = base::MultiProcessTest::MakeCmdLine(procname); | 207 base::CommandLine cmd_line = base::MultiProcessTest::MakeCmdLine(procname); |
208 | 208 |
209 cmd_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_.path()); | 209 cmd_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_.GetPath()); |
210 cmd_line.AppendSwitchNative(kReadyEventNameFlag, ready_event_name_); | 210 cmd_line.AppendSwitchNative(kReadyEventNameFlag, ready_event_name_); |
211 cmd_line.AppendSwitchNative(kContinueEventNameFlag, continue_event_name_); | 211 cmd_line.AppendSwitchNative(kContinueEventNameFlag, continue_event_name_); |
212 if (window_option_ == WITH_WINDOW) | 212 if (window_option_ == WITH_WINDOW) |
213 cmd_line.AppendSwitch(kCreateWindowFlag); | 213 cmd_line.AppendSwitch(kCreateWindowFlag); |
214 | 214 |
215 return cmd_line; | 215 return cmd_line; |
216 } | 216 } |
217 | 217 |
218 void PrepareTest(WindowOption window_option, bool allow_kill) { | 218 void PrepareTest(WindowOption window_option, bool allow_kill) { |
219 ASSERT_NO_FATAL_FAILURE(LaunchHungBrowserProcess(window_option)); | 219 ASSERT_NO_FATAL_FAILURE(LaunchHungBrowserProcess(window_option)); |
220 | 220 |
221 // The ready event has been signalled - the process singleton is held by | 221 // The ready event has been signalled - the process singleton is held by |
222 // the hung sub process. | 222 // the hung sub process. |
223 test_singleton_.reset(new ProcessSingleton( | 223 test_singleton_.reset(new ProcessSingleton( |
224 user_data_dir(), base::Bind(&NotificationCallback))); | 224 user_data_dir(), base::Bind(&NotificationCallback))); |
225 | 225 |
226 test_singleton_->OverrideShouldKillRemoteProcessCallbackForTesting( | 226 test_singleton_->OverrideShouldKillRemoteProcessCallbackForTesting( |
227 base::Bind(&ProcessSingletonTest::MockShouldKillRemoteProcess, | 227 base::Bind(&ProcessSingletonTest::MockShouldKillRemoteProcess, |
228 base::Unretained(this), allow_kill)); | 228 base::Unretained(this), allow_kill)); |
229 } | 229 } |
230 | 230 |
231 base::Process* browser_victim() { return &browser_victim_; } | 231 base::Process* browser_victim() { return &browser_victim_; } |
232 const base::FilePath& user_data_dir() const { return user_data_dir_.path(); } | 232 const base::FilePath& user_data_dir() const { |
| 233 return user_data_dir_.GetPath(); |
| 234 } |
233 ProcessSingleton* test_singleton() const { return test_singleton_.get(); } | 235 ProcessSingleton* test_singleton() const { return test_singleton_.get(); } |
234 bool should_kill_called() const { return should_kill_called_; } | 236 bool should_kill_called() const { return should_kill_called_; } |
235 | 237 |
236 private: | 238 private: |
237 bool MockShouldKillRemoteProcess(bool allow_kill) { | 239 bool MockShouldKillRemoteProcess(bool allow_kill) { |
238 should_kill_called_ = true; | 240 should_kill_called_ = true; |
239 return allow_kill; | 241 return allow_kill; |
240 } | 242 } |
241 | 243 |
242 base::string16 ready_event_name_; | 244 base::string16 ready_event_name_; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // visible window. | 318 // visible window. |
317 EXPECT_TRUE(should_kill_called()); | 319 EXPECT_TRUE(should_kill_called()); |
318 | 320 |
319 // Verify that the hung browser has been terminated with the | 321 // Verify that the hung browser has been terminated with the |
320 // RESULT_CODE_HUNG exit code. | 322 // RESULT_CODE_HUNG exit code. |
321 int exit_code = 0; | 323 int exit_code = 0; |
322 EXPECT_TRUE( | 324 EXPECT_TRUE( |
323 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 325 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |
324 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); | 326 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); |
325 } | 327 } |
OLD | NEW |