#include "services/service_manager/service_process_launcher.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "services/service_manager/public/mojom/service.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace service_manager {
namespace {
const char kTestServiceName[] = …;
#if BUILDFLAG(IS_WIN)
const base::FilePath::CharType kServiceExtension[] =
FILE_PATH_LITERAL(".service.exe");
#else
const base::FilePath::CharType kServiceExtension[] = …);
#endif
void ProcessReadyCallbackAdapter(bool expect_process_id_valid,
base::OnceClosure callback,
base::ProcessId process_id) { … }
class ServiceProcessLauncherDelegateImpl
: public ServiceProcessLauncherDelegate { … };
TEST(ServiceProcessLauncherTest, DISABLED_StartJoin) { … }
#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_MAC)
TEST(ServiceProcessLauncherTest, FailToLaunchProcess) {
base::test::TaskEnvironment task_environment;
base::FilePath test_service_path(FILE_PATH_LITERAL("rockot@_rules.service"));
ServiceProcessLauncherDelegateImpl service_process_launcher_delegate;
std::optional<ServiceProcessLauncher> launcher(
std::in_place, &service_process_launcher_delegate, test_service_path);
base::RunLoop run_loop;
launcher->Start(Identity(), sandbox::mojom::Sandbox::kNoSandbox,
base::BindOnce(&ProcessReadyCallbackAdapter,
false ,
run_loop.QuitClosure()));
run_loop.Run();
launcher.reset();
task_environment.RunUntilIdle();
}
#endif
}
}