<html>
<head>
<script>

var TOTAL_STATEMENTS = 8;
var statements = 0;
var db = null;

function log(message)
{
    document.body.innerText += message + "\n";
}

function terminateTest()
{
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function executeStatement(expectedToPass, statement)
{
    db.transaction(function(tx) {
        tx.executeSql(statement, [],
            function(tx, data) {
                if (!expectedToPass) {
                    log("Statement " + statement + " was expected to fail, but passed.");
                    terminateTest();
                }
                if (++statements == TOTAL_STATEMENTS) {
                    log("Test passed.");
                    terminateTest();
                }
            }, function(tx, error) {
                if (expectedToPass) {
                    log("Statement " + statement + " was expected to pass, but failed.");
                    terminateTest();
                }
                if (++statements == TOTAL_STATEMENTS) {
                    log("Test passed.");
                    terminateTest();
                }
            });
    });
}

function runTest()
{
    if (window.layoutTestController) {
        layoutTestController.clearAllDatabases();
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }

    db = openDatabase("ExecuteSQLAcceptsOnlyOneStatementTest", "1.0", "", 1);
    db.transaction(function(tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
    }, function(error) {
        log("Test failed: " + error.message);
        terminateTest();
    }, function() {
        executeStatement(true, "INSERT INTO Test VALUES (1)");
        executeStatement(true, "INSERT INTO Test VALUES (2);");
        executeStatement(true, "   INSERT INTO Test VALUES (3)    ");
        executeStatement(true, "   INSERT INTO Test VALUES (4);   ");
        executeStatement(true, "INSERT INTO Test VALUES (5)   ;");
        executeStatement(false, "INSERT INTO Test VALUES (6); garbage");
        executeStatement(false, "INSERT INTO Test VALUES (7); INSERT INTO Test VALUES (8)");
        executeStatement(false, "  INSERT INTO Test VALUES (9);   INSERT INTO Test VALUES (10);   ");
    });
}

</script>
</head>
<body onload="runTest();">
This test tests that executeSql() fails when called with a string that has more than one valid statement in it.<br>
</body>
</body>
</html>