summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/statement-error-callback.html
blob: 6db836d1618b9932456851ac9f8e07a76cc15fad (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
<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 = 10;
var database;

function runTransaction(expectedToFail, statementErrorCallback)
{
    database.transaction(function(tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS TestTable (RandomData TEXT)");
        tx.executeSql("INSERT INTO TestTable VALUES (?)", ['test']);
        tx.executeSql("THIS STATEMENT WILL FAIL", [],
            function(tx, data) {
                log("FAIL - this statement should have failed");
                finishTest();
            }, statementErrorCallback);
        tx.executeSql("INSERT INTO TestTable VALUES (?)", ['test1'],
            function(error) {
                if (expectedToFail)
                    log("FAIL - This statement should not have been executed");
            }, function() {
                if (expectedToFail)
                    log("FAIL - This statement should not have been executed");
            });
    }, function(error) {
        if (expectedToFail)
            log("PASS - the transaction error callback was invoked.");
        else
            log("FAIL - the transaction error callback should not have been invoked.");
        if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
            finishTest();
    }, function() {
        if (expectedToFail)
            log("FAIL - the transaction success callback should not have been invoked.");
        else
            log("PASS - the transaction success callback was invoked.");
        if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
            finishTest();
    });
}

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

    database = openDatabase("StatementErrorCallbackTest", "1.0", "statement error callback test", 1024);

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

</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>