Html程序  |  69行  |  2.81 KB

<html>
<head>
<script>

function log(message)
{
    document.getElementById("console").innerHTML += message + "<br>";
}

function finishTest()
{
    log("Test Complete");
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

var txCallbackCount = 0;
var NUMBER_OF_TRANSACTIONS = 2;

function transactionErrorFunction(error)
{
    log("PASS - the transaction error callback was invoked.");
    if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
        finishTest();
}

function transactionSuccessFunction(message)
{
    log("FAIL - the transaction success callback should not be invoked.");
    if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
        finishTest();
}

function runTest()
{
    if (window.layoutTestController) {
        layoutTestController.clearAllDatabases();
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }
    
    var database = openDatabase("bug-28872", "1.0", "statement error callback test", 1024);
    
    database.transaction(function(tx) {
            tx.executeSql("CREATE TABLE IF NOT EXISTS StatementErrorCallbackTest (randomData)");
            tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test']);
            tx.executeSql("THIS STATEMENT WILL FAIL", [], function(message) { log("FAIL - this statement should have failed"); finishTest(); }, function(error) { return true; });
            tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test1'], function(message) { log("FAIL - This statement should not have been executed"); }, function(message) { log("FAIL - This statement should not have been executed"); });
        }, transactionErrorFunction, transactionSuccessFunction);

    database.transaction(function(tx) {        
        tx.executeSql("CREATE TABLE IF NOT EXISTS StatementErrorCallbackTest (randomData)");
            tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test']);
            tx.executeSql("THIS STATEMENT WILL FAIL", [], function(message) { log("FAIL - this statement should have failed"); finishTest(); }, function(error) { throw "Exception in Statement error callback"; return false; });
            tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test1'], function(message) { log("FAIL - This statement should not have been executed"); }, function(message) { log("FAIL - This statement should not have been executed"); });
        }, transactionErrorFunction, transactionSuccessFunction);
}

</script>
</head>

<body onload="runTest()">
This test confirms that if the statement error callback returns true or throws an exception we do not execute any further statements in that transaction and instead execute the transaction error callback immediately.
<pre id="console">
</pre>
</body>

</html>