blob: f7355bfeb0fc91c611b8d4d16b155346e31d389d [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/updater/updater_branding.h"
#include "chrome/updater/util.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/updater/mac/mac_util.h"
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_WIN)
#define EXECUTABLE_EXTENSION ".exe"
#else
#define EXECUTABLE_EXTENSION ""
#endif // BUILDFLAG(IS_WIN)
// Tests the updater process returns 0 when run with --test argument.
TEST(UpdaterTest, UpdaterExitCode) {
base::FilePath this_executable_path;
ASSERT_TRUE(base::PathService::Get(base::FILE_EXE, &this_executable_path));
const base::FilePath executableFolder = this_executable_path.DirName();
const base::FilePath updater =
#if BUILDFLAG(IS_MAC)
this_executable_path.DirName().Append(
updater::GetExecutableRelativePath());
#else
this_executable_path.DirName().Append(
FILE_PATH_LITERAL("updater_test" EXECUTABLE_EXTENSION));
#endif // BUILDFLAG(IS_MAC)
base::LaunchOptions options;
#if BUILDFLAG(IS_WIN)
options.start_hidden = true;
#endif // BUILDFLAG(IS_WIN)
base::CommandLine command_line(updater);
command_line.AppendSwitch("test");
auto process = base::LaunchProcess(command_line, options);
ASSERT_TRUE(process.IsValid());
int exit_code = -1;
EXPECT_TRUE(process.WaitForExitWithTimeout(base::Seconds(60), &exit_code));
EXPECT_EQ(0, exit_code);
}