#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "remoting/host/setup/me2me_native_messaging_host.h"
#include <stddef.h>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/stringize_macros.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "net/base/file_stream.h"
#include "net/base/network_interfaces.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/base/mock_oauth_client.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/native_messaging/log_message_handler.h"
#include "remoting/host/native_messaging/native_messaging_pipe.h"
#include "remoting/host/native_messaging/pipe_messaging_channel.h"
#include "remoting/host/pin_hash.h"
#include "remoting/host/setup/test_util.h"
#include "remoting/protocol/pairing_registry.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
MockPairingRegistryDelegate;
PairingRegistry;
SynchronousPairingRegistry;
Optional;
void VerifyHelloResponse(const base::Value::Dict& response) { … }
void VerifyGetHostNameResponse(const base::Value::Dict& response) { … }
void VerifyGetPinHashResponse(const base::Value::Dict& response) { … }
void VerifyGenerateKeyPairResponse(const base::Value::Dict& response) { … }
void VerifyGetDaemonConfigResponse(const base::Value::Dict& response) { … }
void VerifyGetUsageStatsConsentResponse(const base::Value::Dict& response) { … }
void VerifyStopDaemonResponse(const base::Value::Dict& response) { … }
void VerifyGetDaemonStateResponse(const base::Value::Dict& response) { … }
void VerifyUpdateDaemonConfigResponse(const base::Value::Dict& response) { … }
void VerifyStartDaemonResponse(const base::Value::Dict& response) { … }
void VerifyGetCredentialsFromAuthCodeResponse(
const base::Value::Dict& response) { … }
}
namespace remoting {
class MockDaemonControllerDelegate : public DaemonController::Delegate { … };
MockDaemonControllerDelegate::MockDaemonControllerDelegate() = default;
MockDaemonControllerDelegate::~MockDaemonControllerDelegate() = default;
DaemonController::State MockDaemonControllerDelegate::GetState() { … }
std::optional<base::Value::Dict> MockDaemonControllerDelegate::GetConfig() { … }
void MockDaemonControllerDelegate::CheckPermission(
bool it2me,
DaemonController::BoolCallback callback) { … }
void MockDaemonControllerDelegate::SetConfigAndStart(
base::Value::Dict config,
bool consent,
DaemonController::CompletionCallback done) { … }
void MockDaemonControllerDelegate::UpdateConfig(
base::Value::Dict config,
DaemonController::CompletionCallback done) { … }
void MockDaemonControllerDelegate::Stop(
DaemonController::CompletionCallback done) { … }
DaemonController::UsageStatsConsent
MockDaemonControllerDelegate::GetUsageStatsConsent() { … }
class Me2MeNativeMessagingHostTest : public testing::Test { … };
Me2MeNativeMessagingHostTest::Me2MeNativeMessagingHostTest() = default;
Me2MeNativeMessagingHostTest::~Me2MeNativeMessagingHostTest() = default;
void Me2MeNativeMessagingHostTest::SetUp() { … }
void Me2MeNativeMessagingHostTest::StartHost() { … }
void Me2MeNativeMessagingHostTest::StopHost() { … }
void Me2MeNativeMessagingHostTest::ExitTest() { … }
void Me2MeNativeMessagingHostTest::TearDown() { … }
std::optional<base::Value::Dict>
Me2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() { … }
void Me2MeNativeMessagingHostTest::WriteMessageToInputPipe(
const base::ValueView& message) { … }
void Me2MeNativeMessagingHostTest::TestBadRequest(const base::Value& message) { … }
TEST_F(Me2MeNativeMessagingHostTest, All) { … }
TEST_F(Me2MeNativeMessagingHostTest, Id) { … }
TEST_F(Me2MeNativeMessagingHostTest, WrongFormat) { … }
TEST_F(Me2MeNativeMessagingHostTest, MissingType) { … }
TEST_F(Me2MeNativeMessagingHostTest, InvalidType) { … }
TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoHostId) { … }
TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoPin) { … }
TEST_F(Me2MeNativeMessagingHostTest, UpdateDaemonConfigInvalidConfig) { … }
TEST_F(Me2MeNativeMessagingHostTest, StartDaemonInvalidConfig) { … }
TEST_F(Me2MeNativeMessagingHostTest, StartDaemonNoConsent) { … }
TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) { … }
}