chromium/remoting/host/setup/me2me_native_messaging_host_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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

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) {}

// TODO (weitaosu): crbug.com/323306. Re-enable these tests.
// Test all valid request-types.
TEST_F(Me2MeNativeMessagingHostTest, All) {}

// Verify that response ID matches request ID.
TEST_F(Me2MeNativeMessagingHostTest, Id) {}

// Verify non-Dictionary requests are rejected.
TEST_F(Me2MeNativeMessagingHostTest, WrongFormat) {}

// Verify requests with no type are rejected.
TEST_F(Me2MeNativeMessagingHostTest, MissingType) {}

// Verify rejection if type is unrecognized.
TEST_F(Me2MeNativeMessagingHostTest, InvalidType) {}

// Verify rejection if getPinHash request has no hostId.
TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoHostId) {}

// Verify rejection if getPinHash request has no pin.
TEST_F(Me2MeNativeMessagingHostTest, GetPinHashNoPin) {}

// Verify rejection if updateDaemonConfig request has invalid config.
TEST_F(Me2MeNativeMessagingHostTest, UpdateDaemonConfigInvalidConfig) {}

// Verify rejection if startDaemon request has invalid config.
TEST_F(Me2MeNativeMessagingHostTest, StartDaemonInvalidConfig) {}

// Verify rejection if startDaemon request has no "consent" parameter.
TEST_F(Me2MeNativeMessagingHostTest, StartDaemonNoConsent) {}

// Verify rejection if getCredentialsFromAuthCode has no auth code.
TEST_F(Me2MeNativeMessagingHostTest, GetCredentialsFromAuthCodeNoAuthCode) {}

}  // namespace remoting