blob: 59e8f5b73b0c0e652d0ebc496bfe5fe493cdf3a1 [file] [log] [blame]
<html>
<head>
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test closing a database connection in IndexedDB.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function test()
{
shouldBeTrue("'webkitIndexedDB' in window");
shouldBeFalse("webkitIndexedDB == null");
request = evalAndLog("webkitIndexedDB.open('transaction-after-close')");
request.onsuccess = openSuccess;
request.onerror = unexpectedErrorCallback;
}
function openSuccess()
{
debug("openSuccess():");
window.db = evalAndLog("db = event.target.result");
request = evalAndLog("request = db.setVersion('version 1')");
request.onsuccess = inSetVersion;
request.onerror = unexpectedErrorCallback;
}
function inSetVersion()
{
deleteAllObjectStores(db);
event.target.result.oncomplete = runFirstRegularTransaction;
event.target.result.onabort = unexpectedAbortCallback;
store = evalAndLog("store = db.createObjectStore('store')");
request = evalAndLog("request = store.put('x', 'y')");
request.onsuccess = onPutSuccess;
request.onerror = unexpectedErrorCallback;
}
function onPutSuccess()
{
testPassed("Put success")
}
function runFirstRegularTransaction()
{
debug("running first transaction")
currentTransaction = evalAndLog("currentTransaction = db.transaction(['store'], webkitIDBTransaction.READ_WRITE)");
currentTransaction.onabort = unexpectedAbortCallback;
currentTransaction.oncomplete = firstTransactionComplete;
objectStore = currentTransaction.objectStore('store');
request = evalAndLog("objectStore.put('a', 'b')");
request.onerror = unexpectedErrorCallback;
}
function firstTransactionComplete()
{
evalAndLog("db.close()");
evalAndExpectException("db.transaction(['store'], webkitIDBTransaction.READ_WRITE)", "webkitIDBDatabaseException.NOT_ALLOWED_ERR");
debug("")
debug("verify that we can reopen the db after calling close")
request = evalAndLog("webkitIndexedDB.open('transaction-after-close')");
request.onsuccess = onSecondOpen
request.onerror = unexpectedErrorCallback;
}
function onSecondOpen() {
second_db = evalAndLog("second_db = event.target.result");
currentTransaction = evalAndLog("currentTransaction = second_db.transaction(['store'], webkitIDBTransaction.READ_WRITE)");
store = currentTransaction.objectStore('store');
request = evalAndLog("request = store.put('1', '2')");
request.onsuccess = onFinalPutSuccess;
request.onerror = unexpectedErrorCallback;
currentTransaction.oncomplete = done;
currentTransaction.onabort = unexpectedAbortCallback;
}
function onFinalPutSuccess() {
testPassed("final put success");
}
test();
</script>
</body>
</html>