#include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h"
#include <memory>
#include <tuple>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/registry.h"
#endif
namespace extensions {
namespace {
void WriteTestNativeHostManifest(const base::FilePath& target_dir,
const std::string& host_name,
const base::FilePath& host_path,
bool user_level,
bool supports_native_initiated_connections) { … }
}
const char ScopedTestNativeMessagingHost::kHostName[] = …;
const char ScopedTestNativeMessagingHost::kBinaryMissingHostName[] = …;
const char ScopedTestNativeMessagingHost::
kSupportsNativeInitiatedConnectionsHostName[] = …;
const char ScopedTestNativeMessagingHost::kExtensionId[] = …;
#if BUILDFLAG(IS_WIN)
const char ScopedTestNativeMessagingHost::kHostExeName[] =
"com.google.chrome.test.exe.echo";
#endif
ScopedTestNativeMessagingHost::ScopedTestNativeMessagingHost() { … }
void ScopedTestNativeMessagingHost::RegisterTestHost(bool user_level) { … }
#if BUILDFLAG(IS_WIN)
void ScopedTestNativeMessagingHost::RegisterTestExeHost(
std::string_view filename,
bool user_level) {
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath binary_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_EXE, &binary_dir));
HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
ASSERT_NO_FATAL_FAILURE(registry_override_.OverrideRegistry(root_key));
base::FilePath host_path = binary_dir.AppendASCII(filename);
ASSERT_NO_FATAL_FAILURE(WriteTestNativeHostManifest(
temp_dir_.GetPath(), kHostExeName, host_path, user_level, false));
}
#endif
ScopedTestNativeMessagingHost::~ScopedTestNativeMessagingHost() { … }
}