summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/statement-error-callback.html
blob: 060a881e81c91c174e28cd7e9eab7491a6fd9c38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<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 = 7;
var database;

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 runTransactionExpectedToFail(statementErrorCallback)
{
    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(tx, data) {
                log("FAIL - this statement should have failed");
                finishTest();
            }, statementErrorCallback);
        tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test1'],
            function(error) { log("FAIL - This statement should not have been executed"); },
            function() { log("FAIL - This statement should not have been executed"); });
    }, transactionErrorFunction, transactionSuccessFunction);
}

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

    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(tx, data) {
                log("FAIL - this statement should have failed");
                finishTest();
            }, function(tx, error) { return false; });
        tx.executeSql("INSERT INTO StatementErrorCallbackTest (randomData) VALUES (?)", ['test1'],
            function(tx, data) { },
            function(tx, error) { log("FAIL - This statement should not have caused an error"); });
    }, function(error) { log("FAIL - The transaction error callback should not have been invoked"); },
    function() { });

    runTransactionExpectedToFail(function(error) { return true; });
    runTransactionExpectedToFail(function(error) { throw "Exception in statement error callback"; return false; });
    runTransactionExpectedToFail(function(error) {});
    runTransactionExpectedToFail(function(error) { return null; });
    runTransactionExpectedToFail(function(error) { return "some string"; });
    runTransactionExpectedToFail(function(error) { return 1234; });
    runTransactionExpectedToFail(function(error) { return {a: 2, b: "abc"}; });
}

</script>
</head>

<body onload="runTest()">
This test confirms that a transaction is immediately rolled back if and only if a statement's error callback throws an exception, returns true, or doesn't return any value.
<pre id="console">
</pre>
</body>

</html>