1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/test/ui/ui_test_suite.h"
9 #include "base/command_line.h"
10 #include "base/environment.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h"
14 #include "base/process/kill.h"
15 #include "base/process/launch.h"
16 #include "base/process/process_iterator.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/env_vars.h"
20 UITestSuite::UITestSuite(int argc
, char** argv
) : ChromeTestSuite(argc
, argv
) {
22 crash_service_
= NULL
;
26 void UITestSuite::Initialize() {
27 ChromeTestSuite::Initialize();
33 void UITestSuite::Shutdown() {
36 base::KillProcess(crash_service_
, 0, false);
39 ChromeTestSuite::Shutdown();
43 void UITestSuite::LoadCrashService() {
44 scoped_ptr
<base::Environment
> env(base::Environment::Create());
45 if (env
->HasVar(env_vars::kHeadless
))
48 if (base::GetProcessCount(L
"crash_service.exe", NULL
))
51 job_handle_
.Set(CreateJobObject(NULL
, NULL
));
52 if (!job_handle_
.IsValid()) {
53 LOG(ERROR
) << "Could not create JobObject.";
57 if (!base::SetJobObjectLimitFlags(job_handle_
.Get(),
58 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
)) {
59 LOG(ERROR
) << "Could not SetJobObjectLimitFlags.";
63 base::FilePath exe_dir
;
64 if (!PathService::Get(base::DIR_EXE
, &exe_dir
)) {
65 LOG(ERROR
) << "Failed to get path to DIR_EXE, "
66 << "not starting crash_service.exe!";
70 base::LaunchOptions launch_options
;
71 launch_options
.job_handle
= job_handle_
.Get();
72 base::FilePath crash_service
= exe_dir
.Append(L
"crash_service.exe");
73 base::win::ScopedHandle crash_service_handle
;
74 if (!base::LaunchProcess(crash_service
.value(), base::LaunchOptions(),
75 &crash_service_handle
)) {
76 LOG(ERROR
) << "Couldn't start crash_service.exe, so this ui_tests run "
77 << "won't tell you if any test crashes!";
80 crash_service_
= crash_service_handle
.Take();