chromium/remoting/host/native_messaging/native_messaging_reader_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/native_messaging/native_messaging_reader.h"

#include <cstdint>
#include <memory>
#include <optional>
#include <utility>

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/build_config.h"
#include "remoting/host/setup/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace remoting {

class NativeMessagingReaderTest : public testing::Test {};

NativeMessagingReaderTest::NativeMessagingReaderTest() = default;

NativeMessagingReaderTest::~NativeMessagingReaderTest() = default;

void NativeMessagingReaderTest::SetUp() {}

void NativeMessagingReaderTest::RunAndWaitForOperationComplete() {}

void NativeMessagingReaderTest::OnMessage(base::Value message) {}

void NativeMessagingReaderTest::OnError() {}

void NativeMessagingReaderTest::WriteMessage(const std::string& message) {}

void NativeMessagingReaderTest::WriteData(const char* data, int length) {}

TEST_F(NativeMessagingReaderTest, ReaderDestroyedByClosingPipe) {}

#if BUILDFLAG(IS_WIN)
// This scenario is only a problem on Windows as closing the write pipe there
// does not trigger the parent process to close the read pipe.
// TODO(crbug.com/40221037) Disabled because it's flaky.
TEST_F(NativeMessagingReaderTest, DISABLED_ReaderDestroyedByOwner) {
  WriteMessage("{\"foo\": 42}");
  RunAndWaitForOperationComplete();
  ASSERT_FALSE(on_error_signaled_);

  // Destroy the reader while it is waiting for more data.
  reader_.reset();
  ASSERT_FALSE(on_error_signaled_);
}
#endif  // BUILDFLAG(IS_WIN)

TEST_F(NativeMessagingReaderTest, SingleGoodMessage) {}

TEST_F(NativeMessagingReaderTest, MultipleGoodMessages) {}

TEST_F(NativeMessagingReaderTest, InvalidLength) {}

TEST_F(NativeMessagingReaderTest, EmptyFile) {}

TEST_F(NativeMessagingReaderTest, ShortHeader) {}

TEST_F(NativeMessagingReaderTest, EmptyBody) {}

TEST_F(NativeMessagingReaderTest, ShortBody) {}

TEST_F(NativeMessagingReaderTest, InvalidJSON) {}

}  // namespace remoting