blob: 8995e6d13a83abdf229784a9d106485f73451a53 [file] [log] [blame]
<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 IndexedDB transaction basics.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function test()
{
shouldBeTrue("'webkitIndexedDB' in window");
shouldBeFalse("webkitIndexedDB == null");
result = evalAndLog("webkitIndexedDB.open('name')");
verifyResult(result);
result.onsuccess = openSuccess;
result.onerror = unexpectedErrorCallback;
}
function openSuccess()
{
debug("openSuccess():");
verifySuccessEvent(event);
window.db = evalAndLog("db = event.result");
result = evalAndLog("result = db.setVersion('version 1')");
result.onsuccess = cleanDatabase;
result.onerror = unexpectedErrorCallback;
}
function cleanDatabase()
{
verifySuccessEvent(event);
deleteAllObjectStores(db, checkMetadataEmpty);
commitAndContinue(testSetVersionAbort1);
}
function testSetVersionAbort1()
{
checkMetadataEmpty();
result = evalAndLog("result = startSetVersion('version fail')");
result.onsuccess = addRemoveIDBObjects;
}
function addRemoveIDBObjects()
{
debug("addRemoveIDBObjects():");
verifySuccessEvent(event);
var trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = testSetVersionAbort2;
trans.oncomplete = unexpectedCompleteCallback;
var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
evalAndLog("db.deleteObjectStore('storeFail')");
evalAndLog("store.deleteIndex('indexFail')");
trans.abort();
}
function testSetVersionAbort2()
{
checkMetadataEmpty();
result = evalAndLog("result = startSetVersion('version fail')");
result.onsuccess = addRemoveAddIDBObjects;
}
function addRemoveAddIDBObjects()
{
debug("addRemoveAddIDBObjects():");
verifySuccessEvent(event);
var trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = testSetVersionAbort3;
trans.oncomplete = unexpectedCompleteCallback;
var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
evalAndLog("db.deleteObjectStore('storeFail')");
evalAndLog("store.deleteIndex('indexFail')");
var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
trans.abort();
}
function testSetVersionAbort3()
{
checkMetadataEmpty();
result = evalAndLog("result = startSetVersion('version fail')");
result.onsuccess = addIDBObjects;
}
function addIDBObjects()
{
debug("addIDBObjects():");
verifySuccessEvent(event);
var trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = testSetVersionAbort4;
trans.oncomplete = unexpectedCompleteCallback;
var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
trans.abort();
}
function testSetVersionAbort4()
{
checkMetadataEmpty();
result = evalAndLog("result = startSetVersion('version fail')");
result.onsuccess = addIDBObjectsAndCommit;
}
function addIDBObjects()
{
debug("addIDBObjects():");
verifySuccessEvent(event);
var trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = unexpectedAbortCallback;
var store = evalAndLog("store = db.createObjectStore('storeFail', null)");
var index = evalAndLog("index = store.createIndex('indexFail', 'x', false)");
commitAndContinue(testSetVersionAbort5);
}
function commitAndContinue(continueFunction)
{
window.setTimeout(continueFunction, 0);
}
function testSetVersionAbort5()
{
checkMetadataExistingObjectStore();
result = evalAndLog("result = startSetVersion('version fail')");
result.onsuccess = removeIDBObjects;
}
function removeIDBObjects()
{
debug("removeIDBObjects():");
verifySuccessEvent(event);
var trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = testSetVersionAbort6;
trans.oncomplete = unexpectedCompleteCallback;
var store = evalAndLog("store = trans.objectStore('storeFail')");
evalAndLog("store.deleteIndex('indexFail')");
evalAndLog("db.deleteObjectStore('storeFail')");
trans.abort();
}
function testSetVersionAbort6()
{
checkMetadataExistingObjectStore();
setNewVersion();
}
function startSetVersion(versionName)
{
result = db.setVersion(versionName);
verifyResult(result);
result.onerror = unexpectedErrorCallback;
return result;
}
function checkMetadataEmpty()
{
shouldBe("window.db.objectStoreNames", "[]");
shouldBe("window.db.objectStoreNames.length", "0");
shouldBe("window.db.objectStoreNames.contains('storeFail')", "false");
}
function checkMetadataExistingObjectStore()
{
shouldBe("db.objectStoreNames", "['storeFail']");
shouldBe("db.objectStoreNames.length", "1");
shouldBe("db.objectStoreNames.contains('storeFail')", "true");
}
function setNewVersion()
{
result = evalAndLog("db.setVersion('new version')");
verifyResult(result);
result.onsuccess = setVersionSuccess;
result.onerror = unexpectedErrorCallback;
}
function setVersionSuccess()
{
debug("setVersionSuccess():");
verifySuccessEvent(event);
window.trans = evalAndLog("trans = event.result");
shouldBeTrue("trans !== null");
trans.onabort = unexpectedAbortCallback;
trans.oncomplete = completeCallback;
window.completeEventFired = false;
deleteAllObjectStores(db, createObjectStoreAndStartTransaction);
}
function createObjectStoreAndStartTransaction()
{
evalAndLog("db.createObjectStore('storeName', null)");
transaction = evalAndLog("db.transaction({mode: webkitIDBTransaction.READ_WRITE})");
transaction.onabort = abortCallback;
var store = evalAndLog("store = transaction.objectStore('storeName')");
shouldBeEqualToString("store.name", "storeName");
}
function completeCallback()
{
verifyCompleteEvent(event);
window.completeEventFired = true;
}
function abortCallback()
{
verifyAbortEvent(event);
checkForCompleteEvent();
}
function checkForCompleteEvent()
{
if (completeEventFired) {
testPassed("oncomplete event had fired");
done();
} else
setTimeout(checkForCompleteEvent, 1);
}
var successfullyParsed = true;
test();
</script>
</body>
</html>