Skip to content
Permalink
Browse files
2011-05-24 Greg Simon <gregsimon@chromium.org>
        Reviewed by Dimitri Glazkov.

        Control Indexeddb backends from LayoutTestController
        https://bugs.webkit.org/show_bug.cgi?id=61000

        LayoutTest for migration between SQLite and LevelDB
        in IndxededDB.

        * storage/indexeddb/migrate-basics-expected.txt: Added.
        * storage/indexeddb/migrate-basics.html: Added.
2011-05-24  Greg Simon  <gregsimon@chromium.org>

        Reviewed by Dimitri Glazkov.

        Control Indexeddb backends from LayoutTestController
        https://bugs.webkit.org/show_bug.cgi?id=61000

        Test: storage/indexeddb/migrate-basics.html

        * storage/IDBBackingStore.h:
        * storage/IDBFactoryBackendImpl.cpp:
        (WebCore::IDBFactoryBackendImpl::IDBFactoryBackendImpl):
        (WebCore::IDBFactoryBackendImpl::open):
        (WebCore::IDBFactoryBackendImpl::setEnableMigration):
        (WebCore::IDBFactoryBackendImpl::migrate):
        * storage/IDBFactoryBackendImpl.h:
        * storage/IDBFactoryBackendInterface.h:
        * storage/IDBLevelDBBackingStore.cpp:
        (WebCore::IDBLevelDBBackingStore::backingStoreExists):
        * storage/IDBLevelDBBackingStore.h:
        (WebCore::IDBLevelDBBackingStore::backingStoreType):
        * storage/IDBSQLiteBackingStore.cpp:
        (WebCore::IDBSQLiteBackingStore::backingStoreExists):
        * storage/IDBSQLiteBackingStore.h:
        (WebCore::IDBSQLiteBackingStore::backingStoreType):
2011-05-24  Greg Simon  <gregsimon@chromium.org>

        Reviewed by Dimitri Glazkov.

        Control Indexeddb backends from LayoutTestController
        https://bugs.webkit.org/show_bug.cgi?id=61000

        * public/WebIDBFactory.h:
        (WebKit::WebIDBFactory::setEnableMigration):
        * src/AssertMatchingEnums.cpp:
        * src/IDBFactoryBackendProxy.cpp:
        (WebKit::IDBFactoryBackendProxy::setEnableMigration):
        * src/IDBFactoryBackendProxy.h:
        * src/WebIDBFactoryImpl.cpp:
        (WebKit::WebIDBFactory::setOverrideBackingStoreType):
        (WebKit::WebIDBFactory::setTemporaryDatabaseFolder):
        (WebKit::WebIDBFactoryImpl::WebIDBFactoryImpl):
        (WebKit::WebIDBFactoryImpl::open):
        (WebKit::WebIDBFactoryImpl::setEnableMigration):
        * src/WebIDBFactoryImpl.h:
2011-05-24  Greg Simon  <gregsimon@chromium.org>

        Reviewed by Dimitri Glazkov.

        Control Indexeddb backends from LayoutTestController
        https://bugs.webkit.org/show_bug.cgi?id=61000

        * DumpRenderTree/chromium/LayoutTestController.cpp:
        (LayoutTestController::LayoutTestController):
        (LayoutTestController::setOverrideIndexedDBBackingStore):
        (LayoutTestController::clearAllDatabases):
        * DumpRenderTree/chromium/LayoutTestController.h:

Canonical link: https://commits.webkit.org/76809@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87257 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed May 25, 2011
1 parent 99080dc commit 1f6aa1c7043596fc20859575c4312abc42b6eeb3
@@ -1,3 +1,16 @@
2011-05-24 Greg Simon <gregsimon@chromium.org>

Reviewed by Dimitri Glazkov.

Control Indexeddb backends from LayoutTestController
https://bugs.webkit.org/show_bug.cgi?id=61000

LayoutTest for migration between SQLite and LevelDB
in IndxededDB.

* storage/indexeddb/migrate-basics-expected.txt: Added.
* storage/indexeddb/migrate-basics.html: Added.

2011-05-24 Fumitoshi Ukai <ukai@chromium.org>

Unreviewed.
@@ -0,0 +1,36 @@
Test migration from SQLite to LevelDB.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


webkitIndexedDB.open('MigrationDatabase')
sqliteCreateSuccess():
db = event.target.result
db.setVersion('new version')
sqliteSetVersionSuccess():
window.db.createObjectStore('PlainOldStore', {autoIncrement: false})
store = window.db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true})
window.db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true})
trans = db.transaction([], webkitIDBTransaction.READ_WRITE)
index = store.createIndex('ExampleIndex','id', false)
sqliteTestAddRecords1():
store = trans.objectStore('PlainOldStore')
store = store.add({name: 'George'},1)
sqliteTestAddRecords2():
store = trans.objectStore('StoreWithKeyPath')
store.add({name: 'Thomas', id: 3})
sqliteTestAddRecords3():
store = trans.objectStore('StoreWithAutoIncrement')
store.add({name: 'Lincoln', number: '7012'}, 5)
leveldbOpenSuccess():
db = event.target.result
trans = db.transaction([], webkitIDBTransaction.READ_WRITE, 0)
leveldbCheckPlainOldStore():
store = trans.objectStore('PlainOldStore')
FAIL store = trans.objectStore('PlainOldStore') threw exception Error: NOT_FOUND_ERR: DOM IDBDatabase Exception 3
request = store.openCursor(keyRange)
FAIL request = store.openCursor(keyRange) threw exception TypeError: Cannot call method 'openCursor' of undefined
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,197 @@
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>

description("Test migration from SQLite to LevelDB.");

if (window.layoutTestController)
layoutTestController.waitUntilDone();

function test()
{
if (window.layoutTestController)
layoutTestController.setOverrideIndexedDBBackingStore("sqlite");

request = evalAndLog("webkitIndexedDB.open('MigrationDatabase')");
request.onsuccess = sqliteOpenSuccess;
request.onerror = unexpectedErrorCallback;
}

function sqliteOpenSuccess()
{
debug("sqliteCreateSuccess():");
window.db = evalAndLog("db = event.target.result");

request = evalAndLog("db.setVersion('new version')");
request.onsuccess = sqliteSetVersionSuccess;
request.onerror = unexpectedErrorCallback;
}

function sqliteSetVersionSuccess()
{
debug("sqliteSetVersionSuccess():");
evalAndLog("window.db.createObjectStore('PlainOldStore', {autoIncrement: false})");
window.store = evalAndLog("store = window.db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true})");
evalAndLog("window.db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true})");

window.trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
window.index = evalAndLog("index = store.createIndex('ExampleIndex','id', false)");


sqliteTestAddRecords1();
}

function sqliteTestAddRecords1()
{
debug("sqliteTestAddRecords1():");
window.store = evalAndLog("store = trans.objectStore('PlainOldStore')");
request = evalAndLog("store = store.add({name: 'George'},1)");
request.onsuccess = sqliteTestAddRecords2;
request.onfailure = unexpectedErrorCallback;
}

function sqliteTestAddRecords2()
{
debug("sqliteTestAddRecords2():");
window.store = evalAndLog("store = trans.objectStore('StoreWithKeyPath')");

request = evalAndLog("store.add({name: 'Thomas', id: 3})");
request.onsuccess = sqliteTestAddRecords3;
request.onfailure = unexpectedErrorCallback;
}

function sqliteTestAddRecords3()
{
debug("sqliteTestAddRecords3():");
window.store = evalAndLog("store = trans.objectStore('StoreWithAutoIncrement')");
request = evalAndLog("store.add({name: 'Lincoln', number: '7012'}, 5)");
request.onsuccess = sqliteCloseDatabase;
request.onfailure = unexpectedErrorCallback;
}


function sqliteCloseDatabase()
{
window.db.close();
window.db = null;
window.trans = null;
leveldbOpen();
}

function leveldbOpen()
{
if (window.layoutTestController)
layoutTestController.setOverrideIndexedDBBackingStore("leveldb");

// This next line will trigger the migration.
request = webkitIndexedDB.open('MigrationDatabase');
request.onsuccess = leveldbOpenSuccess;
request.onerror = unexpectedErrorCallback;
}

function leveldbOpenSuccess()
{
debug("leveldbOpenSuccess():");
window.db = evalAndLog("db = event.target.result");
window.trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE, 0)");
leveldbCheckPlainOldStore();
}

function leveldbCheckPlainOldStore()
{
debug("leveldbCheckPlainOldStore():");
window.store = evalAndLog("store = trans.objectStore('PlainOldStore')");
window.keyRange = webkitIDBKeyRange.lowerBound(0);
request = evalAndLog("request = store.openCursor(keyRange)");
if (!request) {
testMigrationEnd();
return;
}
request.onsuccess = leveldbCheckPlainOldStoreCursorNext;
request.onerror = unexpectedErrorCallback;
}

function leveldbCheckPlainOldStoreCursorNext()
{
debug("leveldbCheckPlainOldStoreCursorNext():");
window.cursor = event.target.result;
if (!window.cursor) {
leveldbCheckStoreWithKeyPath();
return;
}

shouldBeTrue("cursor.value.name == 'George'");
cursor.continue();
}

function leveldbCheckStoreWithKeyPath()
{
debug("leveldbCheckStoreWithKeyPath():");
window.store = evalAndLog("store = trans.objectStore('StoreWithKeyPath')");
var keyRange = webkitIDBKeyRange.lowerBound(0);
request = store.openCursor(keyRange);
request.onsuccess = leveldbCheckStoreWithKeyPathCursorNext;
request.onerror = unexpectedErrorCallback;
}

function leveldbCheckStoreWithKeyPathCursorNext()
{
debug("leveldbCheckStoreWithKeyPathCursorNext():");
window.cursor = event.target.result;
if (!window.cursor) {
leveldbCheckStoreWithAutoIncrement();
return;
}

shouldBeTrue("cursor.value.name == 'Thomas'");
shouldBeTrue("cursor.value.id == '3'");
cursor.continue();
}

function leveldbCheckStoreWithAutoIncrement()
{
debug("leveldbCheckStoreWithAutoIncrement():");
window.store = evalAndLog("store = trans.objectStore('StoreWithAutoIncrement')");
var keyRange = webkitIDBKeyRange.lowerBound(0);
request = store.openCursor(keyRange);
request.onsuccess = leveldbCheckStoreWithAutoIncrementCursorNext;
request.onerror = unexpectedErrorCallback;
}
function leveldbCheckStoreWithAutoIncrementCursorNext()
{
debug("leveldbCheckStoreWithAutoIncrementCursorNext():");
window.cursor = event.target.result;
if (!window.cursor) {
testMigrationEnd();
return;
}

shouldBeTrue("cursor.value.name == 'Lincoln'");
shouldBeTrue("cursor.value.number == '7012'");
cursor.continue();
}

function testMigrationEnd()
{
window.db.close();
window.db = null;
layoutTestController.clearAllDatabases();
layoutTestController.setOverrideIndexedDBBackingStore("default");
done();
}

test();

var successfullyParsed = true;

</script>
</body>
</html>
@@ -1,3 +1,29 @@
2011-05-24 Greg Simon <gregsimon@chromium.org>

Reviewed by Dimitri Glazkov.

Control Indexeddb backends from LayoutTestController
https://bugs.webkit.org/show_bug.cgi?id=61000

Test: storage/indexeddb/migrate-basics.html

* storage/IDBBackingStore.h:
* storage/IDBFactoryBackendImpl.cpp:
(WebCore::IDBFactoryBackendImpl::IDBFactoryBackendImpl):
(WebCore::IDBFactoryBackendImpl::open):
(WebCore::IDBFactoryBackendImpl::setEnableMigration):
(WebCore::IDBFactoryBackendImpl::migrate):
* storage/IDBFactoryBackendImpl.h:
* storage/IDBFactoryBackendInterface.h:
* storage/IDBLevelDBBackingStore.cpp:
(WebCore::IDBLevelDBBackingStore::backingStoreExists):
* storage/IDBLevelDBBackingStore.h:
(WebCore::IDBLevelDBBackingStore::backingStoreType):
* storage/IDBSQLiteBackingStore.cpp:
(WebCore::IDBSQLiteBackingStore::backingStoreExists):
* storage/IDBSQLiteBackingStore.h:
(WebCore::IDBSQLiteBackingStore::backingStoreType):

2011-05-24 Leo Yang <leo.yang@torchmobile.com.cn>

Reviewed by Ryosuke Niwa.
@@ -29,6 +29,8 @@
#if ENABLE(INDEXED_DATABASE)

#include "IDBCursor.h"
#include "IDBFactoryBackendImpl.h"
#include "IDBFactoryBackendInterface.h"
#include "SQLiteDatabase.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
@@ -37,7 +39,6 @@

namespace WebCore {

class IDBFactoryBackendImpl;
class IDBKey;
class IDBKeyRange;
class SecurityOrigin;
@@ -106,6 +107,7 @@ class IDBBackingStore : public RefCounted<IDBBackingStore> {
virtual void rollback() = 0;
};
virtual PassRefPtr<Transaction> createTransaction() = 0;
virtual IDBFactoryBackendInterface::BackingStoreType backingStoreType() = 0;
};

} // namespace WebCore
@@ -45,6 +45,7 @@ namespace WebCore {

IDBFactoryBackendImpl::IDBFactoryBackendImpl()
: m_transactionCoordinator(IDBTransactionCoordinator::create())
, m_migrateEnabled(false)
{
}

@@ -76,18 +77,39 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
String uniqueIdentifier = fileIdentifier + "@" + name;
IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
if (it != m_databaseBackendMap.end()) {
callbacks->onSuccess(it->second);
return;
// Also check that backing store types match: this is important for migration.
if ((backingStoreType == DefaultBackingStore) || (backingStoreType == it->second->backingStore()->backingStoreType())) {
callbacks->onSuccess(it->second);
return;
}
}

// FIXME: Everything from now on should be done on another thread.

RefPtr<IDBBackingStore> backingStore;
IDBBackingStoreMap::iterator it2 = m_backingStoreMap.find(fileIdentifier);
if (it2 != m_backingStoreMap.end())
if (it2 != m_backingStoreMap.end() && (backingStoreType == it2->second->backingStoreType()))
backingStore = it2->second;
else {
if (backingStoreType == DefaultBackingStore)
#if ENABLE(LEVELDB)
if (m_migrateEnabled) {
bool hasSQLBackend = IDBSQLiteBackingStore::backingStoreExists(securityOrigin.get(), dataDir);
bool hasLevelDbBackend = IDBLevelDBBackingStore::backingStoreExists(securityOrigin.get(), dataDir);

if (hasSQLBackend && hasLevelDbBackend)
backingStoreType = LevelDBBackingStore;

// Migration: if the database exists and is SQLite we want to migrate it to LevelDB.
if (hasSQLBackend && !hasLevelDbBackend) {
if (migrate(name, securityOrigin.get(), dataDir, maximumSize))
backingStoreType = LevelDBBackingStore;
else
backingStoreType = DefaultBackingStore;
}
}
#endif

if (backingStoreType == DefaultBackingStore || backingStoreType == SQLiteBackingStore)
backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
#if ENABLE(LEVELDB)
else if (backingStoreType == LevelDBBackingStore)
@@ -104,6 +126,17 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
}

void IDBFactoryBackendImpl::setEnableMigration(bool enabled)
{
m_migrateEnabled = enabled;
}

bool IDBFactoryBackendImpl::migrate(const String& name, SecurityOrigin* securityOrigin, const String& dataDir, int64_t maximumSize)
{
// FIXME: Implement migration.
return false;
}

} // namespace WebCore

#endif // ENABLE(INDEXED_DATABASE)
@@ -56,9 +56,11 @@ class IDBFactoryBackendImpl : public IDBFactoryBackendInterface {
void removeIDBBackingStore(const String& uniqueIdentifier);

virtual void open(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir, int64_t maximumSize, BackingStoreType);
virtual void setEnableMigration(bool);

private:
IDBFactoryBackendImpl();
bool migrate(const String& name, SecurityOrigin*, const String& dataDir, int64_t maximumSize);

typedef HashMap<String, IDBDatabaseBackendImpl*> IDBDatabaseBackendMap;
IDBDatabaseBackendMap m_databaseBackendMap;
@@ -68,6 +70,8 @@ class IDBFactoryBackendImpl : public IDBFactoryBackendInterface {

RefPtr<IDBTransactionCoordinator> m_transactionCoordinator;

bool m_migrateEnabled;

// Only one instance of the factory should exist at any given time.
static IDBFactoryBackendImpl* idbFactoryBackendImpl;
};

0 comments on commit 1f6aa1c

Please sign in to comment.