<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 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([], 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([], 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([], 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"); | |
} | |
var successfullyParsed = true; | |
test(); | |
</script> | |
</body> | |
</html> |