#ifdef UNSAFE_BUFFERS_BUILD
#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 = …;
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 net_log {
class FakeNetLogExporter : public network::mojom::NetLogExporter { … };
class FakeNetworkContext : public network::TestNetworkContext { … };
bool SetPathToGivenAndReturnTrue(const base::FilePath& path_to_return,
base::FilePath* path) { … }
[[nodiscard]] ::testing::AssertionResult VerifyState(
base::Value::Dict state,
const std::string& expected_state_string) { … }
[[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) { … }
class TestStateObserver : public NetExportFileWriter::StateObserver { … };
class TestFilePathCallback { … };
class NetExportFileWriterTest : public ::testing::Test { … };
TEST_F(NetExportFileWriterTest, InitFail) { … }
TEST_F(NetExportFileWriterTest, InitWithoutExistingLog) { … }
TEST_F(NetExportFileWriterTest, InitWithExistingLog) { … }
TEST_F(NetExportFileWriterTest, StartAndStopWithAllCaptureModes) { … }
TEST_F(NetExportFileWriterTest, StartClearsFile) { … }
TEST_F(NetExportFileWriterTest, AddEvent) { … }
TEST_F(NetExportFileWriterTest, AddEventCustomPath) { … }
TEST_F(NetExportFileWriterTest, StopWithPolledData) { … }
TEST_F(NetExportFileWriterTest, StartWithNetworkContextActive) { … }
TEST_F(NetExportFileWriterTest, ReceiveStartWhileInitializing) { … }
TEST_F(NetExportFileWriterTest, ReceiveStartWhileStoppingLog) { … }
TEST_F(NetExportFileWriterTest, HandleCrash) { … }
}