chromium/components/net_log/net_export_file_writer_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 "components/net_log/net_export_file_writer.h"

#include <stdint.h>

#include <memory>
#include <optional>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/base/network_change_notifier.h"
#include "net/base/test_completion_callback.h"
#include "net/log/net_log_capture_mode.h"
#include "net/log/net_log_event_type.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/network_context.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/test/fake_test_cert_verifier_params_factory.h"
#include "services/network/test/test_network_context.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char kChannelString[] =;
const size_t kMaxLogSizeBytes =;  // 100MiB

// Keep this in sync with kLogRelativePath defined in net_export_file_writer.cc.
base::FilePath::CharType kLogRelativePath[] =);

const char kCaptureModeDefaultString[] =;
const char kCaptureModeIncludeSensitiveString[] =;
const char kCaptureModeIncludeEverythingString[] =;

const char kStateUninitializedString[] =;
const char kStateInitializingString[] =;
const char kStateNotLoggingString[] =;
const char kStateStartingLogString[] =;
const char kStateLoggingString[] =;
const char kStateStoppingLogString[] =;
}  // namespace

namespace net_log {

class FakeNetLogExporter : public network::mojom::NetLogExporter {};

class FakeNetworkContext : public network::TestNetworkContext {};

// Sets |path| to |path_to_return| and always returns true. This function is
// used to override NetExportFileWriter's usual getter for the default log base
// directory.
bool SetPathToGivenAndReturnTrue(const base::FilePath& path_to_return,
                                 base::FilePath* path) {}

// Checks the "state" string of a NetExportFileWriter state.
[[nodiscard]] ::testing::AssertionResult VerifyState(
    base::Value::Dict state,
    const std::string& expected_state_string) {}

// Checks all fields of a NetExportFileWriter state except possibly the
// "captureMode" string; that field is only checked if
// |expected_log_capture_mode_known| is true.
[[nodiscard]] ::testing::AssertionResult VerifyState(
    base::Value::Dict state,
    const std::string& expected_state_string,
    bool expected_log_exists,
    bool expected_log_capture_mode_known,
    const std::string& expected_log_capture_mode_string) {}

[[nodiscard]] ::testing::AssertionResult ReadCompleteLogFile(
    const base::FilePath& log_path,
    std::unique_ptr<base::Value::Dict>* root) {}

// An implementation of NetExportFileWriter::StateObserver that allows waiting
// until it's notified of a new state.
class TestStateObserver : public NetExportFileWriter::StateObserver {};

// A class that wraps around TestClosure. Provides the ability to wait on a
// file path callback and retrieve the result.
class TestFilePathCallback {};

class NetExportFileWriterTest : public ::testing::Test {};

TEST_F(NetExportFileWriterTest, InitFail) {}

TEST_F(NetExportFileWriterTest, InitWithoutExistingLog) {}

TEST_F(NetExportFileWriterTest, InitWithExistingLog) {}

TEST_F(NetExportFileWriterTest, StartAndStopWithAllCaptureModes) {}

// Verify the file sizes after two consecutive starts/stops are the same (even
// if some junk data is added in between).
TEST_F(NetExportFileWriterTest, StartClearsFile) {}

// Adds an event to the log file, then checks that the file is larger than
// the file created without that event.
TEST_F(NetExportFileWriterTest, AddEvent) {}

// Using a custom path to make sure logging can still occur when the path has
// changed.
TEST_F(NetExportFileWriterTest, AddEventCustomPath) {}

TEST_F(NetExportFileWriterTest, StopWithPolledData) {}

// Test with requests in flight. This is done by going through a sequence of a
// redirect --- at which point the log is started --- and then a fetch of
// destination that's blocked on an event in EmbeddedTestServer.
TEST_F(NetExportFileWriterTest, StartWithNetworkContextActive) {}

TEST_F(NetExportFileWriterTest, ReceiveStartWhileInitializing) {}

TEST_F(NetExportFileWriterTest, ReceiveStartWhileStoppingLog) {}

TEST_F(NetExportFileWriterTest, HandleCrash) {}

}  // namespace net_log