blob: 8ce6d07d7517dba86aa10c33867fa7e881fd56f9 [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("Verify that a transaction with an error aborts unless preventDefault() is called.");
if (window.layoutTestController)
layoutTestController.waitUntilDone();
function test()
{
request = evalAndLog("webkitIndexedDB.open('error-causes-abort-by-default')");
request.onsuccess = setVersion;
request.onerror = unexpectedErrorCallback;
}
function setVersion()
{
db = evalAndLog("db = event.target.result");
request = evalAndLog("db.setVersion('new version')");
request.onsuccess = deleteExisting;
request.onerror = unexpectedErrorCallback;
}
function deleteExisting()
{
debug("setVersionSuccess():");
window.trans = evalAndLog("trans = event.target.result");
shouldBeTrue("trans !== null");
trans.onabort = unexpectedAbortCallback;
evalAndLog("trans.oncomplete = addData");
deleteAllObjectStores(db);
evalAndLog("db.createObjectStore('storeName', null)");
}
function addData()
{
trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
evalAndLog("trans.onabort = unexpectedAbortCallback");
evalAndLog("trans.oncomplete = transactionCompleted");
store = evalAndLog("store = trans.objectStore('storeName')");
request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
request.onsuccess = addMore;
request.onerror = unexpectedErrorCallback;
}
function addMore()
{
request = evalAndLog("event.target.source.add({x: 'value', y: 'zzz'}, 'key')");
request.onsuccess = unexpectedSuccessCallback;
request.addEventListener("error", preventTheDefault);
}
function preventTheDefault()
{
evalAndLog("event.preventDefault()");
}
function transactionCompleted()
{
testPassed("Transaction completed");
debug("");
debug("");
trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
evalAndLog("trans.onabort = transactionAborted1");
evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
store = evalAndLog("store = trans.objectStore('storeName')");
request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
request.onsuccess = unexpectedSuccessCallback;
request.onerror = allowDefault;
}
function allowDefault()
{
debug("Doing nothing to prevent the default action...");
}
function transactionAborted1()
{
testPassed("Transaction aborted");
debug("");
debug("");
trans = evalAndLog("trans = db.transaction([], webkitIDBTransaction.READ_WRITE)");
evalAndLog("trans.onabort = transactionAborted2");
evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
store = evalAndLog("store = trans.objectStore('storeName')");
request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
request.onsuccess = unexpectedSuccessCallback;
debug("Omitting an onerror handler");
}
function transactionAborted2()
{
testPassed("Transaction aborted");
done();
}
test();
var successfullyParsed = true;
</script>
</body>
</html>