chromium/chrome/updater/test/unit_test_util_unittest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/updater/test/unit_test_util.h"

#include <optional>
#include <string>
#include <vector>

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "chrome/updater/test/integration_tests_impl.h"
#include "chrome/updater/test/test_scope.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/re2/src/re2/re2.h"

#if BUILDFLAG(IS_WIN)
#include <windows.h>

#include "base/strings/string_number_conversions_win.h"
#include "chrome/updater/util/win_util.h"
#include "chrome/updater/win/test/test_executables.h"
#include "chrome/updater/win/test/test_strings.h"
#endif

namespace updater::test {
namespace {

std::string ToString(const std::string& s) {}

std::string ToString(const std::wstring& s) {}

}  // namespace

TEST(UnitTestUtil, ToString) {}

TEST(UnitTestUtil, Processes) {}

TEST(UnitTestUtil, GetTestName) {}

// Enable the test to print the effective values for the test timeouts when
// debugging timeout issues.
TEST(UnitTestUtil, DISABLED_PrintTestTimeouts) {}

TEST(UnitTestUtil, DeleteFileAndEmptyParentDirectories) {}

#if BUILDFLAG(IS_WIN)
TEST(UnitTestUtil, FindProcesses) {
  base::CommandLine command_line = GetTestProcessCommandLine(
      GetUpdaterScopeForTesting(), test::GetTestName());

  // Create a unique name for a shared event to be waited for in the test
  // process and signaled in this test.
  EventHolder event_holder(CreateWaitableEventForTest());

  command_line.AppendSwitchNative(kTestEventToWaitOn, event_holder.name);

  const base::Process process = base::LaunchProcess(command_line, {});
  ASSERT_TRUE(process.IsValid());

  EXPECT_TRUE(test::WaitFor([&] { return process.IsRunning(); }));
  EXPECT_EQ(test::FindProcesses(kTestProcessExecutableName).size(), 1U);

  event_holder.event.Signal();

  EXPECT_TRUE(test::WaitFor([&] { return !process.IsRunning(); }));
  EXPECT_TRUE(test::FindProcesses(kTestProcessExecutableName).empty());
}
#endif  // BUILDFLAG(IS_WIN)

}  // namespace updater::test