// 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.
module storage.mojom;
import "components/services/storage/public/mojom/buckets/bucket_locator.mojom";
import "mojo/public/mojom/base/byte_string.mojom";
import "mojo/public/mojom/base/file_path.mojom";
enum FailClass {
NOTHING,
LEVELDB_ITERATOR,
LEVELDB_DIRECT_TRANSACTION,
LEVELDB_TRANSACTION,
LEVELDB_DATABASE,
};
enum FailMethod {
NOTHING,
COMMIT,
COMMIT_DISK_FULL,
COMMIT_SYNC,
GET,
SEEK,
WRITE,
};
// A test-only interface for creating fake failures in IndexedDB methods.
interface MockFailureInjector {
// Causes indexeddb to fail in a given way on a given call.
FailOperation(FailClass failure_class, FailMethod failure_method,
int32 instance_num, int32 call_num);
};
// A test-only interface extending storage.mojom.IndexedDBControl.
interface IndexedDBControlTest {
// Gets the root data path for storage.
GetBaseDataPathForTesting() => (mojo_base.mojom.FilePath path);
// Gets the name of the local storage file for the given `bucket_locator`.
GetFilePathForTesting(storage.mojom.BucketLocator bucket_locator) =>
(mojo_base.mojom.FilePath path);
// Forgets the storage keys and sizes read from disk.
ResetCachesForTesting() => ();
// Does a direct write to a database with a given key/value pair.
WriteToIndexedDBForTesting(storage.mojom.BucketLocator bucket_locator,
mojo_base.mojom.ByteString key,
mojo_base.mojom.ByteString value) => ();
// Returns the path for a given key/database/blob.
GetPathForBlobForTesting(storage.mojom.BucketLocator bucket_locator,
int64 database_id, int64 blob_number) =>
(mojo_base.mojom.FilePath path);
// Compacts the backing store for a given `bucket_locator`.
CompactBackingStoreForTesting(storage.mojom.BucketLocator bucket_locator) =>
();
// Gets the total usage in bytes across all buckets.
GetUsageForTesting() => (int64 total_usage);
// Overrides an IndexedDB backing store with a mock that can inject failures
// at specific points. The receiver will be attached to the *next* backing
// store that's created after this is called.
//
// Note: in order for this not to be flaky, this should be called before
// using the IndexedDB system in any way to ensure that that the default
// class factory isn't used before the testing one is set.
BindMockFailureSingletonForTesting(
pending_receiver<MockFailureInjector> receiver);
// Return keys used in WriteToIndexedDBForTesting.
GetDatabaseKeysForTesting() =>
(string schema_version_key, string data_version_key);
// Forces disk files to be re-read and added to active set if changed.
ForceInitializeFromFilesForTesting() => ();
};