chromium/content/browser/indexed_db/indexed_db_backing_store_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/342213636): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "content/browser/indexed_db/indexed_db_backing_store.h"

#include <stddef.h>
#include <stdint.h>

#include <string>
#include <string_view>
#include <tuple>
#include <utility>

#include "base/barrier_closure.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/synchronization/waitable_event_watcher.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/uuid.h"
#include "components/services/storage/indexed_db/locks/partitioned_lock_manager.h"
#include "components/services/storage/indexed_db/scopes/varint_coding.h"
#include "components/services/storage/indexed_db/transactional_leveldb/leveldb_write_batch.h"
#include "components/services/storage/indexed_db/transactional_leveldb/transactional_leveldb_database.h"
#include "components/services/storage/privileged/mojom/indexed_db_control.mojom-test-utils.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "content/browser/indexed_db/indexed_db_bucket_context.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/browser/indexed_db/indexed_db_leveldb_operations.h"
#include "content/browser/indexed_db/indexed_db_value.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "net/base/features.h"
#include "net/base/schemeful_site.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "storage/browser/test/fake_blob.h"
#include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_quota_manager_proxy.h"
#include "storage/browser/test/mock_special_storage_policy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"

IndexedDBDatabaseMetadata;
IndexedDBIndexMetadata;
IndexedDBKey;
IndexedDBKeyPath;
IndexedDBKeyRange;
IndexedDBObjectStoreMetadata;
StorageKey;
Origin;

namespace content {

struct BlobWrite {};

class MockBlobStorageContext : public ::storage::mojom::BlobStorageContext {};

class FakeFileSystemAccessTransferToken
    : public ::blink::mojom::FileSystemAccessTransferToken {};

class MockFileSystemAccessContext
    : public ::storage::mojom::FileSystemAccessContext {};

class IndexedDBBackingStoreTest : public testing::Test {};

class IndexedDBBackingStoreTestForThirdPartyStoragePartitioning
    : public testing::WithParamInterface<bool>,
      public IndexedDBBackingStoreTest {};

INSTANTIATE_TEST_SUITE_P();

enum class ExternalObjectTestType {};

class IndexedDBBackingStoreTestWithExternalObjects
    : public testing::WithParamInterface<ExternalObjectTestType>,
      public IndexedDBBackingStoreTest {};

INSTANTIATE_TEST_SUITE_P();

class IndexedDBBackingStoreTestWithBlobs
    : public IndexedDBBackingStoreTestWithExternalObjects {};

BlobWriteCallback CreateBlobWriteCallback(
    bool* succeeded,
    base::OnceClosure on_done = base::OnceClosure()) {}

TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) {}

TEST_P(IndexedDBBackingStoreTestWithExternalObjects, PutGetConsistency) {}

// http://crbug.com/1131151
// Validate that recovery journal cleanup during a transaction does
// not delete blobs that were just written.
TEST_P(IndexedDBBackingStoreTestWithExternalObjects, BlobWriteCleanup) {}

TEST_P(IndexedDBBackingStoreTestWithExternalObjects, DeleteRange) {}

TEST_P(IndexedDBBackingStoreTestWithExternalObjects, DeleteRangeEmptyRange) {}

TEST_P(IndexedDBBackingStoreTestWithExternalObjects,
       BlobJournalInterleavedTransactions) {}

TEST_P(IndexedDBBackingStoreTestWithExternalObjects, ActiveBlobJournal) {}

// Make sure that using very high ( more than 32 bit ) values for
// database_id and object_store_id still work.
TEST_F(IndexedDBBackingStoreTest, HighIds) {}

// Make sure that other invalid ids do not crash.
TEST_F(IndexedDBBackingStoreTest, InvalidIds) {}

TEST_F(IndexedDBBackingStoreTest, CreateDatabase) {}

TEST_F(IndexedDBBackingStoreTest, GetDatabaseNames) {}

TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
       ReadCorruptionInfoForOpaqueStorageKey) {}

TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
       ReadCorruptionInfoForFirstPartyStorageKey) {}

TEST_P(IndexedDBBackingStoreTestForThirdPartyStoragePartitioning,
       ReadCorruptionInfoForThirdPartyStorageKey) {}

namespace {

// v3 Blob Data is encoded as a series of:
//   { is_file [bool], blob_number [int64_t as varInt],
//     type [string-with-length, may be empty],
//     (for Blobs only) size [int64_t as varInt]
//     (for Files only) fileName [string-with-length]
//   }
// There is no length field; just read until you run out of data.
std::string EncodeV3BlobInfos(
    const std::vector<IndexedDBExternalObject>& blob_info) {}

}  // namespace

TEST_F(IndexedDBBackingStoreTestWithBlobs, SchemaUpgradeV3ToV4) {}

TEST_F(IndexedDBBackingStoreTestWithBlobs, SchemaUpgradeV4ToV5) {}

// This tests that external objects are deleted when ClearObjectStore is called.
// See: http://crbug.com/488851
// TODO(enne): we could use more comprehensive testing for ClearObjectStore.
TEST_P(IndexedDBBackingStoreTestWithExternalObjects, ClearObjectStoreObjects) {}

}  // namespace content