Commit 3569c091 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

indexeddb: convert some browser tests to IndexedDBControl

IndexedDBContext access is going away, and so these tests need to use
public mojo interfaces instead of private indexeddb interfaces.

This converts some easier browser tests over to using the new interface.

Bug: 1015214
Change-Id: I68bb1cd46ff6ae13d8b113d37886a499e0d97276
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088337Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Auto-Submit: enne <enne@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747201}
parent d09dbab2
...@@ -9,12 +9,45 @@ import "mojo/public/mojom/base/values.mojom"; ...@@ -9,12 +9,45 @@ import "mojo/public/mojom/base/values.mojom";
import "mojo/public/mojom/base/time.mojom"; import "mojo/public/mojom/base/time.mojom";
import "url/mojom/origin.mojom"; import "url/mojom/origin.mojom";
enum V2SchemaCorruptionStatus {
CORRUPTION_UNKNOWN,
CORRUPTION_NO,
CORRUPTION_YES,
};
// A test-only interface extending storage.mojom.IndexedDBControl. // A test-only interface extending storage.mojom.IndexedDBControl.
interface IndexedDBControlTest { interface IndexedDBControlTest {
// Gets the root data path for storage.
GetBaseDataPathForTesting() => (mojo_base.mojom.FilePath path);
// Gets the file name of the local storage file for the given origin. // Gets the file name of the local storage file for the given origin.
GetFilePathForTesting(url.mojom.Origin origin) => GetFilePathForTesting(url.mojom.Origin origin) =>
(mojo_base.mojom.FilePath path); (mojo_base.mojom.FilePath path);
// Forgets the origins/sizes read from disk. // Forgets the origins/sizes read from disk.
ResetCachesForTesting() => (); ResetCachesForTesting() => ();
// Downgrades databases to V2.
ForceSchemaDowngradeForTesting(url.mojom.Origin origin) => (bool downgraded);
// Returns the corruption status for a given database.
HasV2SchemaCorruptionForTesting(url.mojom.Origin origin) =>
(V2SchemaCorruptionStatus status);
// Does a direct write to a database with a given key/value pair.
WriteToIndexedDBForTesting(url.mojom.Origin origin, string key,
string value) => ();
// Returns the number of blobs for a given origin.
GetBlobCountForTesting(url.mojom.Origin origin) => (int64 num_blobs);
// Returns the next blob id for a given origin.
GetNextBlobNumberForTesting(url.mojom.Origin origin, int64 database_id) =>
(int64 next_blob_number);
// Returns the path for a given origin/database/blob.
GetPathForBlobForTesting(url.mojom.Origin origin, int64 database_id,
int64 blob_number) =>
(mojo_base.mojom.FilePath path);
}; };
...@@ -25,12 +25,17 @@ ...@@ -25,12 +25,17 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "components/services/storage/indexed_db/leveldb/leveldb_factory.h" #include "components/services/storage/indexed_db/leveldb/leveldb_factory.h"
#include "components/services/storage/indexed_db/scopes/varint_coding.h"
#include "components/services/storage/indexed_db/transactional_leveldb/transactional_leveldb_database.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/indexed_db/indexed_db_class_factory.h" #include "content/browser/indexed_db/indexed_db_class_factory.h"
#include "content/browser/indexed_db/indexed_db_connection.h" #include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_database.h" #include "content/browser/indexed_db/indexed_db_database.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h" #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h" #include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_leveldb_operations.h" #include "content/browser/indexed_db/indexed_db_leveldb_operations.h"
#include "content/browser/indexed_db/indexed_db_origin_state.h"
#include "content/browser/indexed_db/indexed_db_origin_state_handle.h"
#include "content/browser/indexed_db/indexed_db_quota_client.h" #include "content/browser/indexed_db/indexed_db_quota_client.h"
#include "content/browser/indexed_db/indexed_db_tracing.h" #include "content/browser/indexed_db/indexed_db_tracing.h"
#include "content/browser/indexed_db/indexed_db_transaction.h" #include "content/browser/indexed_db/indexed_db_transaction.h"
...@@ -407,18 +412,6 @@ void IndexedDBContextImpl::BindTestInterface( ...@@ -407,18 +412,6 @@ void IndexedDBContextImpl::BindTestInterface(
test_receivers_.Add(this, std::move(receiver)); test_receivers_.Add(this, std::move(receiver));
} }
void IndexedDBContextImpl::GetFilePathForTesting(
const Origin& origin,
GetFilePathForTestingCallback callback) {
std::move(callback).Run(GetLevelDBPath(origin));
}
void IndexedDBContextImpl::ResetCachesForTesting(base::OnceClosure callback) {
origin_set_.reset();
origin_size_map_.clear();
std::move(callback).Run();
}
void IndexedDBContextImpl::AddObserver( void IndexedDBContextImpl::AddObserver(
mojo::PendingRemote<storage::mojom::IndexedDBObserver> observer) { mojo::PendingRemote<storage::mojom::IndexedDBObserver> observer) {
IDBTaskRunner()->PostTask( IDBTaskRunner()->PostTask(
...@@ -432,26 +425,147 @@ void IndexedDBContextImpl::AddObserver( ...@@ -432,26 +425,147 @@ void IndexedDBContextImpl::AddObserver(
base::Unretained(this), std::move(observer))); base::Unretained(this), std::move(observer)));
} }
void IndexedDBContextImpl::ForceCloseSync( void IndexedDBContextImpl::GetBaseDataPathForTesting(
GetBaseDataPathForTestingCallback callback) {
std::move(callback).Run(data_path());
}
void IndexedDBContextImpl::GetFilePathForTesting(
const Origin& origin, const Origin& origin,
storage::mojom::ForceCloseReason reason) { GetFilePathForTestingCallback callback) {
ForceClose(origin, reason, base::DoNothing()); std::move(callback).Run(GetLevelDBPath(origin));
}
void IndexedDBContextImpl::ResetCachesForTesting(base::OnceClosure callback) {
origin_set_.reset();
origin_size_map_.clear();
std::move(callback).Run();
} }
bool IndexedDBContextImpl::ForceSchemaDowngrade(const Origin& origin) { void IndexedDBContextImpl::ForceSchemaDowngradeForTesting(
const url::Origin& origin,
ForceSchemaDowngradeForTestingCallback callback) {
DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence()); DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence());
if (is_incognito() || !HasOrigin(origin)) if (is_incognito() || !HasOrigin(origin)) {
return false; std::move(callback).Run(false);
return;
}
if (indexeddb_factory_.get()) { if (indexeddb_factory_.get()) {
indexeddb_factory_->ForceSchemaDowngrade(origin); indexeddb_factory_->ForceSchemaDowngrade(origin);
return true; std::move(callback).Run(true);
return;
} }
ForceCloseSync( ForceCloseSync(
origin, origin,
storage::mojom::ForceCloseReason::FORCE_SCHEMA_DOWNGRADE_INTERNALS_PAGE); storage::mojom::ForceCloseReason::FORCE_SCHEMA_DOWNGRADE_INTERNALS_PAGE);
return false; std::move(callback).Run(false);
}
void IndexedDBContextImpl::HasV2SchemaCorruptionForTesting(
const url::Origin& origin,
HasV2SchemaCorruptionForTestingCallback callback) {
DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence());
if (is_incognito() || !HasOrigin(origin)) {
std::move(callback).Run(
storage::mojom::V2SchemaCorruptionStatus::CORRUPTION_UNKNOWN);
}
if (indexeddb_factory_.get()) {
std::move(callback).Run(
static_cast<storage::mojom::V2SchemaCorruptionStatus>(
indexeddb_factory_->HasV2SchemaCorruption(origin)));
return;
}
return std::move(callback).Run(
storage::mojom::V2SchemaCorruptionStatus::CORRUPTION_UNKNOWN);
}
void IndexedDBContextImpl::WriteToIndexedDBForTesting(
const url::Origin& origin,
const std::string& key,
const std::string& value,
base::OnceClosure callback) {
IndexedDBOriginStateHandle handle;
leveldb::Status s;
std::tie(handle, s, std::ignore, std::ignore, std::ignore) =
GetIDBFactory()->GetOrOpenOriginFactory(origin, data_path(),
/*create_if_missing=*/true);
CHECK(s.ok()) << s.ToString();
CHECK(handle.IsHeld());
TransactionalLevelDBDatabase* db =
handle.origin_state()->backing_store()->db();
std::string value_copy = value;
s = db->Put(key, &value_copy);
CHECK(s.ok()) << s.ToString();
handle.Release();
GetIDBFactory()->ForceClose(origin, true);
std::move(callback).Run();
}
void IndexedDBContextImpl::GetBlobCountForTesting(
const Origin& origin,
GetBlobCountForTestingCallback callback) {
std::move(callback).Run(GetOriginBlobFileCount(origin));
}
void IndexedDBContextImpl::GetNextBlobNumberForTesting(
const Origin& origin,
int64_t database_id,
GetNextBlobNumberForTestingCallback callback) {
IndexedDBOriginStateHandle handle;
leveldb::Status s;
std::tie(handle, s, std::ignore, std::ignore, std::ignore) =
GetIDBFactory()->GetOrOpenOriginFactory(origin, data_path(),
/*create_if_missing=*/true);
CHECK(s.ok()) << s.ToString();
CHECK(handle.IsHeld());
TransactionalLevelDBDatabase* db =
handle.origin_state()->backing_store()->db();
const std::string key_gen_key = DatabaseMetaDataKey::Encode(
database_id, DatabaseMetaDataKey::BLOB_KEY_GENERATOR_CURRENT_NUMBER);
std::string data;
bool found = false;
bool ok = db->Get(key_gen_key, &data, &found).ok();
CHECK(found);
CHECK(ok);
base::StringPiece slice(data);
int64_t number;
CHECK(DecodeVarInt(&slice, &number));
CHECK(DatabaseMetaDataKey::IsValidBlobNumber(number));
std::move(callback).Run(number);
}
void IndexedDBContextImpl::GetPathForBlobForTesting(
const url::Origin& origin,
int64_t database_id,
int64_t blob_number,
GetPathForBlobForTestingCallback callback) {
IndexedDBOriginStateHandle handle;
leveldb::Status s;
std::tie(handle, s, std::ignore, std::ignore, std::ignore) =
GetIDBFactory()->GetOrOpenOriginFactory(origin, data_path(),
/*create_if_missing=*/true);
CHECK(s.ok()) << s.ToString();
CHECK(handle.IsHeld());
IndexedDBBackingStore* backing_store = handle.origin_state()->backing_store();
base::FilePath path =
backing_store->GetBlobFileName(database_id, blob_number);
std::move(callback).Run(path);
}
void IndexedDBContextImpl::ForceCloseSync(
const Origin& origin,
storage::mojom::ForceCloseReason reason) {
ForceClose(origin, reason, base::DoNothing());
} }
IndexedDBFactoryImpl* IndexedDBContextImpl::GetIDBFactory() { IndexedDBFactoryImpl* IndexedDBContextImpl::GetIDBFactory() {
...@@ -522,18 +636,6 @@ base::Time IndexedDBContextImpl::GetOriginLastModified(const Origin& origin) { ...@@ -522,18 +636,6 @@ base::Time IndexedDBContextImpl::GetOriginLastModified(const Origin& origin) {
return file_info.last_modified; return file_info.last_modified;
} }
V2SchemaCorruptionStatus IndexedDBContextImpl::HasV2SchemaCorruption(
const Origin& origin) {
DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence());
if (is_incognito() || !HasOrigin(origin))
return V2SchemaCorruptionStatus::kUnknown;
if (indexeddb_factory_.get())
return indexeddb_factory_->HasV2SchemaCorruption(origin);
return V2SchemaCorruptionStatus::kUnknown;
}
size_t IndexedDBContextImpl::GetConnectionCountSync(const Origin& origin) { size_t IndexedDBContextImpl::GetConnectionCountSync(const Origin& origin) {
DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence()); DCHECK(IDBTaskRunner()->RunsTasksInCurrentSequence());
if (!HasOrigin(origin)) if (!HasOrigin(origin))
......
...@@ -88,13 +88,36 @@ class CONTENT_EXPORT IndexedDBContextImpl ...@@ -88,13 +88,36 @@ class CONTENT_EXPORT IndexedDBContextImpl
void BindTestInterface( void BindTestInterface(
mojo::PendingReceiver<storage::mojom::IndexedDBControlTest> receiver) mojo::PendingReceiver<storage::mojom::IndexedDBControlTest> receiver)
override; override;
void AddObserver(
mojo::PendingRemote<storage::mojom::IndexedDBObserver> observer) override;
// mojom::IndexedDBControlTest implementation: // mojom::IndexedDBControlTest implementation:
void GetBaseDataPathForTesting(
GetBaseDataPathForTestingCallback callback) override;
void GetFilePathForTesting(const url::Origin& origin, void GetFilePathForTesting(const url::Origin& origin,
GetFilePathForTestingCallback callback) override; GetFilePathForTestingCallback callback) override;
void ResetCachesForTesting(base::OnceClosure callback) override; void ResetCachesForTesting(base::OnceClosure callback) override;
void AddObserver( void ForceSchemaDowngradeForTesting(
mojo::PendingRemote<storage::mojom::IndexedDBObserver> observer) override; const url::Origin& origin,
ForceSchemaDowngradeForTestingCallback callback) override;
void HasV2SchemaCorruptionForTesting(
const url::Origin& origin,
HasV2SchemaCorruptionForTestingCallback callback) override;
void WriteToIndexedDBForTesting(const url::Origin& origin,
const std::string& key,
const std::string& value,
base::OnceClosure callback) override;
void GetBlobCountForTesting(const url::Origin& origin,
GetBlobCountForTestingCallback callback) override;
void GetNextBlobNumberForTesting(
const url::Origin& origin,
int64_t database_id,
GetNextBlobNumberForTestingCallback callback) override;
void GetPathForBlobForTesting(
const url::Origin& origin,
int64_t database_id,
int64_t blob_number,
GetPathForBlobForTestingCallback callback) override;
// TODO(enne): fix internal indexeddb callers to use ForceClose async instead. // TODO(enne): fix internal indexeddb callers to use ForceClose async instead.
void ForceCloseSync(const url::Origin& origin, void ForceCloseSync(const url::Origin& origin,
...@@ -135,8 +158,6 @@ class CONTENT_EXPORT IndexedDBContextImpl ...@@ -135,8 +158,6 @@ class CONTENT_EXPORT IndexedDBContextImpl
// Used by IndexedDBInternalsUI to populate internals page. // Used by IndexedDBInternalsUI to populate internals page.
base::ListValue* GetAllOriginsDetails(); base::ListValue* GetAllOriginsDetails();
bool ForceSchemaDowngrade(const url::Origin& origin);
V2SchemaCorruptionStatus HasV2SchemaCorruption(const url::Origin& origin);
// GetStoragePaths returns all paths owned by this database, in arbitrary // GetStoragePaths returns all paths owned by this database, in arbitrary
// order. // order.
std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const; std::vector<base::FilePath> GetStoragePaths(const url::Origin& origin) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment