This source file includes following definitions.
- m_document
- executionContext
- create
- commit
- abort
- close
- create
- onVersionChange
- onForcedClose
- onAbort
- onComplete
- TEST_F
- TEST_F
#include "config.h"
#include "modules/indexeddb/IDBTransaction.h"
#include "core/dom/DOMError.h"
#include "core/dom/Document.h"
#include "modules/indexeddb/IDBDatabase.h"
#include "modules/indexeddb/IDBDatabaseCallbacks.h"
#include "modules/indexeddb/IDBPendingTransactionMonitor.h"
#include "platform/SharedBuffer.h"
#include "public/platform/WebIDBDatabase.h"
#include <gtest/gtest.h>
using namespace WebCore;
using blink::WebIDBDatabase;
namespace {
class IDBTransactionTest : public testing::Test {
public:
IDBTransactionTest()
: m_scope(V8ExecutionScope::create(v8::Isolate::GetCurrent()))
, m_document(Document::create())
{
}
ExecutionContext* executionContext()
{
return m_document.get();
}
private:
OwnPtr<V8ExecutionScope> m_scope;
RefPtr<Document> m_document;
};
class FakeWebIDBDatabase FINAL : public blink::WebIDBDatabase {
public:
static PassOwnPtr<FakeWebIDBDatabase> create() { return adoptPtr(new FakeWebIDBDatabase()); }
virtual void commit(long long transactionId) OVERRIDE { }
virtual void abort(long long transactionId) OVERRIDE { }
virtual void close() OVERRIDE { }
private:
FakeWebIDBDatabase() { }
};
class FakeIDBDatabaseCallbacks FINAL : public IDBDatabaseCallbacks {
public:
static PassRefPtr<FakeIDBDatabaseCallbacks> create() { return adoptRef(new FakeIDBDatabaseCallbacks()); }
virtual void onVersionChange(int64_t oldVersion, int64_t newVersion) OVERRIDE { }
virtual void onForcedClose() OVERRIDE { }
virtual void onAbort(int64_t transactionId, PassRefPtrWillBeRawPtr<DOMError> error) OVERRIDE { }
virtual void onComplete(int64_t transactionId) OVERRIDE { }
private:
FakeIDBDatabaseCallbacks() { }
};
TEST_F(IDBTransactionTest, EnsureLifetime)
{
OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create();
RefPtr<FakeIDBDatabaseCallbacks> connection = FakeIDBDatabaseCallbacks::create();
RefPtr<IDBDatabase> db = IDBDatabase::create(executionContext(), backend.release(), connection);
const int64_t transactionId = 1234;
const Vector<String> transactionScope;
RefPtr<IDBTransaction> transaction = IDBTransaction::create(executionContext(), transactionId, transactionScope, blink::WebIDBDatabase::TransactionReadOnly, db.get());
EXPECT_EQ(3, transaction->refCount());
RefPtr<IDBRequest> request = IDBRequest::create(executionContext(), IDBAny::createUndefined(), transaction.get());
IDBPendingTransactionMonitor::deactivateNewTransactions();
EXPECT_EQ(3, transaction->refCount());
executionContext()->stopActiveDOMObjects();
transaction->onAbort(DOMError::create(AbortError, "Aborted"));
EXPECT_EQ(1, transaction->refCount());
}
TEST_F(IDBTransactionTest, TransactionFinish)
{
OwnPtr<FakeWebIDBDatabase> backend = FakeWebIDBDatabase::create();
RefPtr<FakeIDBDatabaseCallbacks> connection = FakeIDBDatabaseCallbacks::create();
RefPtr<IDBDatabase> db = IDBDatabase::create(executionContext(), backend.release(), connection);
const int64_t transactionId = 1234;
const Vector<String> transactionScope;
RefPtr<IDBTransaction> transaction = IDBTransaction::create(executionContext(), transactionId, transactionScope, blink::WebIDBDatabase::TransactionReadOnly, db.get());
EXPECT_EQ(3, transaction->refCount());
IDBPendingTransactionMonitor::deactivateNewTransactions();
EXPECT_EQ(2, transaction->refCount());
IDBTransaction* transactionPtr = transaction.get();
transaction.clear();
EXPECT_EQ(1, transactionPtr->refCount());
executionContext()->stopActiveDOMObjects();
db->onAbort(transactionId, DOMError::create(AbortError, "Aborted"));
EXPECT_EQ(1, db->refCount());
}
}