| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/test/ui/ui_test_suite.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 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" | |
| 19 #include "chrome/test/base/chrome_unit_test_suite.h" | |
| 20 | |
| 21 UITestSuite::UITestSuite(int argc, char** argv) : ChromeTestSuite(argc, argv) { | |
| 22 #if defined(OS_WIN) | |
| 23 crash_service_ = NULL; | |
| 24 #endif | |
| 25 } | |
| 26 | |
| 27 void UITestSuite::Initialize() { | |
| 28 ChromeTestSuite::Initialize(); | |
| 29 ChromeUnitTestSuite::InitializeProviders(); | |
| 30 ChromeUnitTestSuite::InitializeResourceBundle(); | |
| 31 #if defined(OS_WIN) | |
| 32 LoadCrashService(); | |
| 33 #endif | |
| 34 } | |
| 35 | |
| 36 void UITestSuite::Shutdown() { | |
| 37 #if defined(OS_WIN) | |
| 38 if (crash_service_) | |
| 39 base::KillProcess(crash_service_, 0, false); | |
| 40 job_handle_.Close(); | |
| 41 #endif | |
| 42 ChromeTestSuite::Shutdown(); | |
| 43 } | |
| 44 | |
| 45 #if defined(OS_WIN) | |
| 46 void UITestSuite::LoadCrashService() { | |
| 47 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 48 if (env->HasVar(env_vars::kHeadless)) | |
| 49 return; | |
| 50 | |
| 51 if (base::GetProcessCount(L"crash_service.exe", NULL)) | |
| 52 return; | |
| 53 | |
| 54 job_handle_.Set(CreateJobObject(NULL, NULL)); | |
| 55 if (!job_handle_.IsValid()) { | |
| 56 LOG(ERROR) << "Could not create JobObject."; | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 if (!base::SetJobObjectLimitFlags(job_handle_.Get(), | |
| 61 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE)) { | |
| 62 LOG(ERROR) << "Could not SetJobObjectLimitFlags."; | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 base::FilePath exe_dir; | |
| 67 if (!PathService::Get(base::DIR_EXE, &exe_dir)) { | |
| 68 LOG(ERROR) << "Failed to get path to DIR_EXE, " | |
| 69 << "not starting crash_service.exe!"; | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 base::LaunchOptions launch_options; | |
| 74 launch_options.job_handle = job_handle_.Get(); | |
| 75 base::FilePath crash_service = exe_dir.Append(L"crash_service.exe"); | |
| 76 base::win::ScopedHandle crash_service_handle; | |
| 77 if (!base::LaunchProcess(crash_service.value(), base::LaunchOptions(), | |
| 78 &crash_service_handle)) { | |
| 79 LOG(ERROR) << "Couldn't start crash_service.exe, so this ui_tests run " | |
| 80 << "won't tell you if any test crashes!"; | |
| 81 return; | |
| 82 } | |
| 83 crash_service_ = crash_service_handle.Take(); | |
| 84 } | |
| 85 #endif | |
| OLD | NEW |