chromium/components/reporting/storage/storage_queue_unittest.cc

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

#include "components/reporting/storage/storage_queue.h"

#include <atomic>
#include <cstdint>
#include <initializer_list>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/task_environment.h"
#include "base/threading/sequence_bound.h"
#include "base/types/expected.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/reporting/compression/compression_module.h"
#include "components/reporting/compression/decompression.h"
#include "components/reporting/encryption/test_encryption_module.h"
#include "components/reporting/proto/synced/record.pb.h"
#include "components/reporting/resources/resource_manager.h"
#include "components/reporting/storage/storage_configuration.h"
#include "components/reporting/util/file.h"
#include "components/reporting/util/status.h"
#include "components/reporting/util/status_macros.h"
#include "components/reporting/util/statusor.h"
#include "components/reporting/util/test_support_callbacks.h"
#include "crypto/sha2.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
AllOf;
AnyOf;
AtMost;
Between;
DoAll;
Eq;
Invoke;
Ne;
NotNull;
Property;
Return;
Sequence;
StrEq;
WithArg;
WithoutArgs;

namespace reporting {
namespace {

// Test uploader counter - for generation of unique ids.
std::atomic<int64_t> next_uploader_id{};

constexpr size_t kCompressionThreshold =;
const CompressionInformation::CompressionAlgorithm kCompressionType =;

// Metadata file name prefix.
const base::FilePath::CharType METADATA_NAME[] =);

// Forbidden file/folder names
const base::FilePath::StringType kInvalidFilePrefix =);
#if BUILDFLAG(IS_WIN)
const base::FilePath::StringPieceType kInvalidDirectoryPath =
    FILE_PATH_LITERAL("o:\\some\\inaccessible\\dir");
#else
const base::FilePath::StringPieceType kInvalidDirectoryPath =);
#endif

// Ensure files as specified by the parameters are deleted. Take the same
// parameters as base::FileEnumerator().
template <typename... FileEnumeratorParams>
void EnsureDeletingFiles(FileEnumeratorParams... file_enum_params) {}

class StorageQueueTest
    : public ::testing::TestWithParam<
          testing::tuple<size_t /*file_size*/, std::string /*dm_token*/>> {};

constexpr std::array<const char*, 3> kData =;
constexpr std::array<const char*, 3> kMoreData =;

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueAndReopen) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueReopenAndWriteMore) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueAndUpload) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueAndUploadWithFailures) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueReopenWriteMoreAndUpload) {}

TEST_P(StorageQueueTest,
       WriteIntoNewStorageQueueReopenWithMissingMetadataWriteMoreAndUpload) {}

TEST_P(
    StorageQueueTest,
    WriteIntoNewStorageQueueReopenWithMissingLastMetadataWriteMoreAndUpload) {}

TEST_P(StorageQueueTest,
       WriteIntoNewStorageQueueReopenWithMissingDataWriteMoreAndUpload) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueAndFlush) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueReopenWriteMoreAndFlush) {}

TEST_P(StorageQueueTest, ValidateVariousRecordSizes) {}

TEST_P(StorageQueueTest, WriteAndRepeatedlyUploadWithConfirmations) {}

TEST_P(StorageQueueTest, WriteAndUploadWithBadConfirmation) {}

TEST_P(StorageQueueTest, WriteAndRepeatedlyUploadWithConfirmationsAndReopen) {}

TEST_P(StorageQueueTest,
       WriteAndRepeatedlyUploadWithConfirmationsAndReopenWithFailures) {}

TEST_P(StorageQueueTest, WriteAndRepeatedlyImmediateUpload) {}

TEST_P(StorageQueueTest, WriteAndRepeatedlyImmediateUploadWithConfirmations) {}

TEST_P(StorageQueueTest, WriteAndImmediateUploadWithFailure) {}

TEST_P(StorageQueueTest, WriteAndImmediateUploadWithoutConfirmation) {}

TEST_P(StorageQueueTest, WriteEncryptFailure) {}

TEST_P(StorageQueueTest, ForceConfirm) {}

TEST_P(StorageQueueTest, WriteInvalidRecord) {}

TEST_P(StorageQueueTest, WriteRecordWithNoData) {}

TEST_P(StorageQueueTest, WriteRecordWithWriteMetadataFailures) {}

TEST_P(StorageQueueTest, WriteRecordWithWriteBlockFailures) {}

TEST_P(StorageQueueTest, WriteRecordWithInvalidFilePrefix) {}

TEST_P(StorageQueueTest, CreateStorageQueueInvalidOptionsPath) {}

TEST_P(StorageQueueTest, WriteRecordMetadataWithInsufficientDiskSpaceFailure) {}

TEST_P(StorageQueueTest, WrappedRecordWithInsufficientMemoryWithRetry) {}

TEST_P(StorageQueueTest, WrappedRecordWithInsufficientMemoryWithFailure) {}

TEST_P(StorageQueueTest, EncryptedRecordWithInsufficientMemoryWithRetry) {}

TEST_P(StorageQueueTest, EncryptedRecordWithInsufficientMemoryWithFailure) {}

TEST_P(StorageQueueTest, WriteRecordWithReservedSpace) {}

TEST_P(StorageQueueTest, UploadWithInsufficientMemory) {}

TEST_P(StorageQueueTest, WriteIntoNewStorageQueueReopenWithCorruptData) {}

TEST_P(StorageQueueTest, WriteWithUnencryptedCopy) {}

TEST_P(StorageQueueTest, WriteWithNoDestination) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace
}  // namespace reporting