7 document
.getElementById("console").innerHTML
+= message
+ "<br>";
10 // signal to testRunner when this reaches zero.
12 // we first retrieve and store the number of rows already in our test database.
13 // our goal is to keep the number unchanged through the tests.
14 var initialRowCount
= 0;
16 var successCallbackCalled
;
23 log("All Tests are complete.");
25 if (window
.testRunner
)
26 testRunner
.notifyDone();
29 function successCallback()
31 successCallbackCalled
= true;
34 function verifySuccess(msg
)
36 database
.transaction(function(tx
)
38 tx
.executeSql("SELECT count(*) AS count FROM ErrorCallbackTest", [], function(tx
, rs
)
40 log(msg
+ " : " + (rs
.rows
.item(0).count
== initialRowCount
&& !successCallbackCalled
? "SUCCESS" : "FAILURE"));
46 function failMidWay(errorCallback
)
48 successCallbackCalled
= false;
49 database
.transaction(function(tx
)
51 tx
.executeSql("INSERT INTO ErrorCallbackTest(someValue) VALUES(?);", [ 1 ]);
52 tx
.executeSql("MUTTER SOMETHING ILLEGIBLE");
53 }, errorCallback
, successCallback
);
56 function statementCallbackThrowsException(errorCallback
)
58 successCallbackCalled
= false;
59 database
.transaction(function(tx
)
61 tx
.executeSql("INSERT INTO ErrorCallbackTest(someValue) VALUES(?);", [ 1 ], function()
70 if (window
.testRunner
) {
71 testRunner
.clearAllDatabases();
72 testRunner
.dumpAsText();
73 testRunner
.waitUntilDone();
76 database
= openDatabase("ErrorCallbackDatabase", "1.0", "Test for error callback", 1);
77 database
.transaction(function(tx
)
79 tx
.executeSql("CREATE TABLE IF NOT EXISTS ErrorCallbackTest (someValue)", []);
80 tx
.executeSql("SELECT count(*) AS count FROM ErrorCallbackTest", [], function(tx
, rs
)
82 initialRowCount
= rs
.rows
.item(0).count
;
86 failMidWay(function() { return true; });
87 verifySuccess("Testing transaction failing mid-way and error callback returning true");
88 failMidWay(function() { return false; });
89 verifySuccess("Testing transaction failing mid-way and error callback return false");
90 statementCallbackThrowsException(function() { return true; });
91 verifySuccess("Testing statement callback throwing exception and error callback returning true");
92 statementCallbackThrowsException(function() { return false; });
93 verifySuccess("Testing statement callback throwing exception and error callback returning false");
99 <body onload=
"runTest()">
100 This test confirms that
<code>SQLTransactionErrorCallback
</code> is invoked correctly and regardless of its output, the transaction is always rolled back on failure.