#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/log/file_net_log_observer.h"
#include <string>
#include <vector>
#include "base/files/file.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/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/gmock_expected_support.h"
#include "base/threading/thread.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "base/values.h"
#include "build/build_config.h"
#include "net/base/test_completion_callback.h"
#include "net/log/net_log.h"
#include "net/log/net_log_entry.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_source_type.h"
#include "net/log/net_log_util.h"
#include "net/log/net_log_values.h"
#include "net/test/test_with_task_environment.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
const int kTotalNumFiles = …;
const int kLargeFileSize = …;
const size_t kDummyEventSize = …;
void AddEntries(FileNetLogObserver* logger,
int num_entries,
size_t entry_size) { … }
struct ParsedNetLog { … };
base::expected<void, std::string> ParsedNetLog::InitFromFileContents(
const std::string& input) { … }
const base::Value::Dict* ParsedNetLog::GetEvent(size_t i) const { … }
base::expected<std::unique_ptr<ParsedNetLog>, std::string> ReadNetLogFromDisk(
const base::FilePath& log_path) { … }
void VerifyEventsInLog(const ParsedNetLog* log,
size_t num_events_emitted,
size_t num_events_saved) { … }
void ExpectDictionaryContainsProperty(const base::Value::Dict& dict,
const std::string& key,
const std::string& value) { … }
class FileNetLogObserverTest : public ::testing::TestWithParam<bool>,
public WithTaskEnvironment { … };
class FileNetLogObserverBoundedTest : public ::testing::Test,
public WithTaskEnvironment { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(FileNetLogObserverTest, ObserverDestroyedWithoutStopObserving) { … }
TEST_P(FileNetLogObserverTest,
ObserverDestroyedWithoutStopObservingPreExisting) { … }
TEST_P(FileNetLogObserverTest, StopObservingNullClosure) { … }
TEST_P(FileNetLogObserverTest, InitLogWithInvalidPath) { … }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithNoEvents) { … }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { … }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEventPreExisting) { … }
TEST_P(FileNetLogObserverTest,
GeneratesValidJSONWithNoEventsCreateBoundedFile) { … }
TEST_P(FileNetLogObserverTest,
GeneratesValidJSONWithOneEventCreateBoundedFile) { … }
TEST_P(FileNetLogObserverTest, BoundedFileFillsFile) { … }
TEST_P(FileNetLogObserverTest, BoundedFileTruncatesEventsAfterLimit) { … }
TEST_P(FileNetLogObserverTest, PreExistingFileBroken) { … }
TEST_P(FileNetLogObserverTest, CustomConstants) { … }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) { … }
TEST_P(FileNetLogObserverTest, LogModeRecorded) { … }
TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) { … }
TEST_F(FileNetLogObserverBoundedTest, EqualToOneFile) { … }
TEST_F(FileNetLogObserverBoundedTest, OneEventOverOneFile) { … }
TEST_F(FileNetLogObserverBoundedTest, EqualToTwoFiles) { … }
TEST_F(FileNetLogObserverBoundedTest, FillAllFilesNoOverwriting) { … }
TEST_F(FileNetLogObserverBoundedTest, DropOldEventsFromWriteQueue) { … }
TEST_F(FileNetLogObserverBoundedTest, OverwriteAllFiles) { … }
TEST_F(FileNetLogObserverBoundedTest, PartiallyOverwriteFiles) { … }
TEST_F(FileNetLogObserverBoundedTest, SomeFilesFailToOpen) { … }
TEST_F(FileNetLogObserverBoundedTest, InprogressDirectoryBlocked) { … }
TEST_F(FileNetLogObserverBoundedTest, BlockEventsFile0) { … }
TEST_F(FileNetLogObserverBoundedTest, PreExistingUsesSpecifiedDir) { … }
TEST_F(FileNetLogObserverBoundedTest, LargeWriteQueueSize) { … }
void AddEntriesViaNetLog(NetLog* net_log, int num_entries) { … }
TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreadsWithStopObserving) { … }
TEST_P(FileNetLogObserverTest,
AddEventsFromMultipleThreadsWithoutStopObserving) { … }
}
}