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
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<html>
<head>
<script>
function log(message)
{
document.getElementById("console").innerHTML += message + "<br>";
}
// signal to layoutTestController when this reaches zero.
var testCount = 4;
// we first retrieve and store the number of rows already in our test database.
// our goal is to keep the number unchanged through the tests.
var initialRowCount = 0;
var database;
var successCallbackCalled;
function finishTest()
{
if (--testCount)
return;
log("All Tests are complete.");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
function successCallback()
{
successCallbackCalled = true;
}
function verifySuccess(msg)
{
database.transaction(function(tx)
{
tx.executeSql("SELECT count(*) AS count FROM ErrorCallbackTest", [], function(tx, rs)
{
log(msg + " : " + (rs.rows.item(0).count == initialRowCount && !successCallbackCalled ? "SUCCESS" : "FAILURE"));
finishTest();
});
});
}
function failMidWay(errorCallback)
{
successCallbackCalled = false;
database.transaction(function(tx)
{
tx.executeSql("INSERT INTO ErrorCallbackTest(someValue) VALUES(?);", [ 1 ]);
tx.executeSql("MUTTER SOMETHING ILLEGIBLE");
}, errorCallback, successCallback);
}
function statementCallbackThrowsException(errorCallback)
{
successCallbackCalled = false;
database.transaction(function(tx)
{
tx.executeSql("INSERT INTO ErrorCallbackTest(someValue) VALUES(?);", [ 1 ], function()
{
throw {};
});
});
}
function runTest()
{
if (window.layoutTestController) {
layoutTestController.clearAllDatabases();
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
database = openDatabase("ErrorCallbackDatabase", "1.0", "Test for error callback", 1);
database.transaction(function(tx)
{
tx.executeSql("CREATE TABLE IF NOT EXISTS ErrorCallbackTest (someValue)", []);
tx.executeSql("SELECT count(*) AS count FROM ErrorCallbackTest", [], function(tx, rs)
{
initialRowCount = rs.rows.item(0).count;
});
});
failMidWay(function() { return true; });
verifySuccess("Testing transaction failing mid-way and error callback returning true");
failMidWay(function() { return false; });
verifySuccess("Testing transaction failing mid-way and error callback return false");
statementCallbackThrowsException(function() { return true; });
verifySuccess("Testing statement callback throwing exception and error callback returning true");
statementCallbackThrowsException(function() { return false; });
verifySuccess("Testing statement callback throwing exception and error callback returning false");
}
</script>
</head>
<body onload="runTest()">
This test confirms that <code>SQLTransactionErrorCallback</code> is invoked correctly and regardless of its output, the transaction is always rolled back on failure.
<pre id="console">
</pre>
</body>
</html>
|