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

        Test migration from sqlite to leveldb for IndexedDB
        backend.
        https://bugs.webkit.org/show_bug.cgi?id=61000

        * storage/indexeddb/migrate-basics-expected.txt: Added.
        * storage/indexeddb/migrate-basics.html: Added.
2011-06-08  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::open):
        (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-06-08  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:
        * src/AssertMatchingEnums.cpp:
        * src/WebIDBFactoryImpl.cpp:
        (WebKit::WebIDBFactory::setOverrideBackingStoreType):
        (WebKit::WebIDBFactory::setTemporaryDatabaseFolder):
        (WebKit::WebIDBFactoryImpl::open):
2011-06-08  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/77780@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@88358 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed Jun 8, 2011
1 parent cea1f69 commit 61c5b74e578b0527471bfb9843da06b6751a3fe7
@@ -1,3 +1,14 @@
2011-06-08 Greg Simon <gregsimon@chromium.org>

Reviewed by Dimitri Glazkov.

Test migration from sqlite to leveldb for IndexedDB
backend.
https://bugs.webkit.org/show_bug.cgi?id=61000

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

2011-06-08 James Simonsen <simonjam@chromium.org>

[Chromium] Unreviewed, skip two failing tests. Bugs filed.
@@ -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('MigrationPlainOldStore', {autoIncrement: false})
store = window.db.createObjectStore('MigrationStoreWithKeyPath', {keyPath: 'id', autoIncrement: true})
window.db.createObjectStore('MigrationStoreWithAutoIncrement', {autoIncrement: true})
trans = db.transaction([], webkitIDBTransaction.READ_WRITE)
index = store.createIndex('ExampleIndex','id', false)
sqliteTestAddRecords1():
store = trans.objectStore('MigrationPlainOldStore')
store = store.add({name: 'George'},1)
sqliteTestAddRecords2():
store = trans.objectStore('MigrationStoreWithKeyPath')
store.add({name: 'Thomas', id: 3})
sqliteTestAddRecords3():
store = trans.objectStore('MigrationStoreWithAutoIncrement')
store.add({name: 'Lincoln', number: '7012'}, 5)
leveldbOpenSuccess():
db = event.target.result
trans = db.transaction([], webkitIDBTransaction.READ_WRITE, 0)
leveldbCheckPlainOldStore():
store = trans.objectStore('MigrationPlainOldStore')
FAIL store = trans.objectStore('MigrationPlainOldStore') 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,199 @@
<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('MigrationPlainOldStore', {autoIncrement: false})");
window.store = evalAndLog("store = window.db.createObjectStore('MigrationStoreWithKeyPath', {keyPath: 'id', autoIncrement: true})");
evalAndLog("window.db.createObjectStore('MigrationStoreWithAutoIncrement', {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('MigrationPlainOldStore')");
request = evalAndLog("store = store.add({name: 'George'},1)");
request.onsuccess = sqliteTestAddRecords2;
request.onfailure = unexpectedErrorCallback;
}

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

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

function sqliteTestAddRecords3()
{
debug("sqliteTestAddRecords3():");
window.store = evalAndLog("store = trans.objectStore('MigrationStoreWithAutoIncrement')");
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('MigrationPlainOldStore')");
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('MigrationStoreWithKeyPath')");
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('MigrationStoreWithAutoIncrement')");
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;
if (window.layoutTestController)
layoutTestController.setOverrideIndexedDBBackingStore("default");
layoutTestController.clearAllDatabases();
done();
}

test();

var successfullyParsed = true;

</script>
</body>
</html>
@@ -1,3 +1,27 @@
2011-06-08 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::open):
(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-06-08 Dmitry Lomov <dslomov@google.com>

Reviewed by Adam Barth.
@@ -29,6 +29,7 @@
#if ENABLE(INDEXED_DATABASE)

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

namespace WebCore {

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

} // namespace WebCore
@@ -72,8 +72,7 @@ void IDBFactoryBackendImpl::removeIDBBackingStore(const String& uniqueIdentifier

void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir, int64_t maximumSize, BackingStoreType backingStoreType)
{
String fileIdentifier = securityOrigin->databaseIdentifier();
String uniqueIdentifier = fileIdentifier + "@" + name;
String uniqueIdentifier = securityOrigin->databaseIdentifier() + "@" + name + String::format("@%d", (int)backingStoreType);
IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
if (it != m_databaseBackendMap.end()) {
callbacks->onSuccess(it->second);
@@ -83,15 +82,30 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
// 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())
IDBBackingStoreMap::iterator it2 = m_backingStoreMap.find(uniqueIdentifier);
if (it2 != m_backingStoreMap.end() && (backingStoreType == it2->second->backingStoreType()))
backingStore = it2->second;
else {
if (backingStoreType == DefaultBackingStore)
backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
#if ENABLE(LEVELDB)
// Should we migrate this backing store?
bool hasSQLBackingStore = IDBSQLiteBackingStore::backingStoreExists(securityOrigin.get(), dataDir);
bool hasLevelDBBackingStore = IDBLevelDBBackingStore::backingStoreExists(securityOrigin.get(), dataDir);

if (hasSQLBackingStore && hasLevelDBBackingStore)
backingStoreType = LevelDBBackingStore;

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

if (backingStoreType == DefaultBackingStore || backingStoreType == SQLiteBackingStore)
backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, uniqueIdentifier, this);
#if ENABLE(LEVELDB)
else if (backingStoreType == LevelDBBackingStore)
backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, maximumSize, uniqueIdentifier, this);
#endif
if (!backingStore) {
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
@@ -104,6 +118,11 @@ void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> ca
m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
}

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

} // namespace WebCore

#endif // ENABLE(INDEXED_DATABASE)
@@ -59,6 +59,7 @@ class IDBFactoryBackendImpl : public IDBFactoryBackendInterface {

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

typedef HashMap<String, IDBDatabaseBackendImpl*> IDBDatabaseBackendMap;
IDBDatabaseBackendMap m_databaseBackendMap;
@@ -53,7 +53,8 @@ class IDBFactoryBackendInterface : public ThreadSafeRefCounted<IDBFactoryBackend

enum BackingStoreType {
DefaultBackingStore,
LevelDBBackingStore
LevelDBBackingStore,
SQLiteBackingStore
};

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

0 comments on commit 61c5b74

Please sign in to comment.