1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
// 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.
#include "content/browser/indexed_db/instance/mock_factory_client.h"
#include <memory>
#include <utility>
#include "base/task/sequenced_task_runner.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "testing/gtest/include/gtest/gtest.h"
using blink::IndexedDBDatabaseMetadata;
using blink::IndexedDBKey;
namespace content::indexed_db {
MockFactoryClient::MockFactoryClient()
: FactoryClient(mojo::NullAssociatedRemote()) {}
MockFactoryClient::MockFactoryClient(bool expect_connection)
: FactoryClient(mojo::NullAssociatedRemote()),
expect_connection_(expect_connection) {}
MockFactoryClient::~MockFactoryClient() {
EXPECT_EQ(expect_connection_, !!connection_);
}
void MockFactoryClient::OnError(const DatabaseError& error) {
error_called_ = true;
}
void MockFactoryClient::OnDeleteSuccess(int64_t old_version) {}
void MockFactoryClient::OnOpenSuccess(
std::unique_ptr<Connection> connection,
const IndexedDBDatabaseMetadata& metadata) {
if (!upgrade_called_) {
connection_ = std::move(connection);
}
if (call_on_db_success_) {
std::move(call_on_db_success_).Run();
}
}
void MockFactoryClient::OnUpgradeNeeded(
int64_t old_version,
std::unique_ptr<Connection> connection,
const IndexedDBDatabaseMetadata& metadata,
const IndexedDBDataLossInfo& data_loss_info) {
connection_ = std::move(connection);
upgrade_called_ = true;
if (call_on_upgrade_needed_) {
std::move(call_on_upgrade_needed_).Run();
}
}
void MockFactoryClient::CallOnUpgradeNeeded(base::OnceClosure closure) {
call_on_upgrade_needed_ = std::move(closure);
}
void MockFactoryClient::CallOnDBSuccess(base::OnceClosure closure) {
call_on_db_success_ = std::move(closure);
}
void MockFactoryClient::CallOnInfoSuccess(base::RepeatingClosure closure) {
call_on_info_success_ = std::move(closure);
}
ThunkFactoryClient::ThunkFactoryClient(FactoryClient& wrapped)
: MockFactoryClient(false), wrapped_(wrapped) {}
void ThunkFactoryClient::OnError(const DatabaseError& error) {
wrapped_->OnError(error);
}
void ThunkFactoryClient::OnBlocked(int64_t existing_version) {
wrapped_->OnBlocked(existing_version);
}
void ThunkFactoryClient::OnUpgradeNeeded(
int64_t old_version,
std::unique_ptr<Connection> connection,
const blink::IndexedDBDatabaseMetadata& metadata,
const IndexedDBDataLossInfo& data_loss_info) {
wrapped_->OnUpgradeNeeded(old_version, std::move(connection), metadata,
data_loss_info);
}
void ThunkFactoryClient::OnOpenSuccess(
std::unique_ptr<Connection> connection,
const blink::IndexedDBDatabaseMetadata& metadata) {
wrapped_->OnOpenSuccess(std::move(connection), metadata);
}
void ThunkFactoryClient::OnDeleteSuccess(int64_t old_version) {
wrapped_->OnDeleteSuccess(old_version);
}
} // namespace content::indexed_db
|