• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<script>
4
5function log(message)
6{
7    document.getElementById("console").innerHTML += message + "<br>";
8}
9
10function finishTest()
11{
12    log("Test Complete");
13    if (window.layoutTestController)
14        layoutTestController.notifyDone();
15}
16
17var txCallbackCount = 0;
18var NUMBER_OF_TRANSACTIONS = 10;
19var database;
20
21function runTransaction(expectedToFail, statementErrorCallback)
22{
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", [],
27            function(tx, data) {
28                log("FAIL - this statement should have failed");
29                finishTest();
30            }, statementErrorCallback);
31        tx.executeSql("INSERT INTO TestTable VALUES (?)", ['test1'],
32            function(error) {
33                if (expectedToFail)
34                    log("FAIL - This statement should not have been executed");
35            }, function() {
36                if (expectedToFail)
37                    log("FAIL - This statement should not have been executed");
38            });
39    }, function(error) {
40        if (expectedToFail)
41            log("PASS - the transaction error callback was invoked.");
42        else
43            log("FAIL - the transaction error callback should not have been invoked.");
44        if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
45            finishTest();
46    }, function() {
47        if (expectedToFail)
48            log("FAIL - the transaction success callback should not have been invoked.");
49        else
50            log("PASS - the transaction success callback was invoked.");
51        if (++txCallbackCount == NUMBER_OF_TRANSACTIONS)
52            finishTest();
53    });
54}
55
56function runTest()
57{
58    if (window.layoutTestController) {
59        layoutTestController.clearAllDatabases();
60        layoutTestController.dumpAsText();
61        layoutTestController.waitUntilDone();
62    }
63
64    database = openDatabase("StatementErrorCallbackTest", "1.0", "statement error callback test", 1024);
65
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; });
76}
77
78</script>
79</head>
80
81<body onload="runTest()">
82This 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.
83<pre id="console">
84</pre>
85</body>
86
87</html>
88