7 document
.getElementById("console").innerHTML
+= message
+ "<br>";
13 if (window
.testRunner
)
14 testRunner
.notifyDone();
17 var txCallbackCount
= 0;
18 var NUMBER_OF_TRANSACTIONS
= 10;
21 function runTransaction(expectedToFail
, statementErrorCallback
)
23 database
.transaction(function(tx
) {
24 tx
.executeSql("CREATE TABLE IF NOT EXISTS TestTable (RandomData TEXT)");
25 tx
.executeSql("INSERT INTO TestTable VALUES (?)", ['test']);
26 tx
.executeSql("THIS STATEMENT WILL FAIL", [],
28 log("FAIL - this statement should have failed");
30 }, statementErrorCallback
);
31 tx
.executeSql("INSERT INTO TestTable VALUES (?)", ['test1'],
34 log("FAIL - This statement should not have been executed");
37 log("FAIL - This statement should not have been executed");
41 log("PASS - the transaction error callback was invoked.");
43 log("FAIL - the transaction error callback should not have been invoked.");
44 if (++txCallbackCount
== NUMBER_OF_TRANSACTIONS
)
48 log("FAIL - the transaction success callback should not have been invoked.");
50 log("PASS - the transaction success callback was invoked.");
51 if (++txCallbackCount
== NUMBER_OF_TRANSACTIONS
)
58 if (window
.testRunner
) {
59 testRunner
.clearAllDatabases();
60 testRunner
.dumpAsText();
61 testRunner
.waitUntilDone();
64 database
= openDatabase("StatementErrorCallbackTest", "1.0", "statement error callback test", 1024);
66 runTransaction(true, function(error
) { return true; });
67 runTransaction(true, function(error
) { throw "Exception in statement error callback"; return false; });
68 runTransaction(true, function(error
) { return "some string"; });
69 runTransaction(true, function(error
) { return 1234; });
70 runTransaction(true, function(error
) { return {a
: 2, b
: "abc"}; });
71 runTransaction(true, function(error
) { return "false"; });
72 runTransaction(false, function(error
) {});
73 runTransaction(false, function(error
) { return false; });
74 runTransaction(false, function(error
) { return 0; });
75 runTransaction(false, function(error
) { return null; });
81 <body onload=
"runTest()">
82 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.