4 testRunner
.notifyDone();
9 function transactionErrorCallback(error
, expectedErrorCodeName
)
11 if (error
.code
== error
[expectedErrorCodeName
]) {
12 log("PASS: expected and got error code " + expectedErrorCodeName
);
13 if (++testsRun
== TOTAL_TESTS
)
16 log("FAIL: expected error code " + expectedErrorCodeName
+ " (" + error
[expectedErrorCodeName
] + "); got " + error
.code
);
21 function transactionSuccessCallback()
23 log("FAIL: a transaction has completed successfully.");
27 function testTransaction(db
, transactionCallback
, expectedErrorCodeName
)
29 db
.transaction(transactionCallback
,
31 transactionErrorCallback(error
, expectedErrorCodeName
);
32 }, transactionSuccessCallback
);
35 function testTransactionThrowsException(db
)
37 testTransaction(db
, function(tx
) { throw "Exception thrown in transaction callback."; }, "UNKNOWN_ERR");
40 function testTransactionFailureBecauseOfStatementFailure(db
)
44 tx
.executeSql("BAD STATEMENT", [], null, function(tx
, error
) { return true; });
48 function testInvalidStatement(db
)
50 testTransaction(db
, function(tx
) { tx
.executeSql("BAD STATEMENT"); }, "SYNTAX_ERR");
53 function testIncorrectNumberOfBindParameters(db
)
57 tx
.executeSql("CREATE TABLE IF NOT EXISTS BadBindNumberTest (Foo INT, Bar INT)");
58 tx
.executeSql("INSERT INTO BadBindNumberTest VALUES (?, ?)", [1]);
62 function testBindParameterOfWrongType(db
)
65 badString
.toString = function() { throw "Cannot call toString() on this object." };
67 testTransaction(db
, function(tx
) {
68 tx
.executeSql("CREATE TABLE IF NOT EXISTS BadBindTypeTest (Foo TEXT)");
69 tx
.executeSql("INSERT INTO BadBindTypeTest VALUES (?)", [badString
]);
73 function testConstraintFailure(db
)
77 tx
.executeSql("CREATE TABLE IF NOT EXISTS ConstraintTest (Foo INTEGER PRIMARY KEY)");
78 tx
.executeSql("INSERT INTO ConstraintTest VALUES (1)");
79 tx
.executeSql("INSERT INTO ConstraintTest VALUES (1)");
83 function testQuotaExceeded(db
)
87 tx
.executeSql("CREATE TABLE IF NOT EXISTS QuotaTest (Foo BLOB)");
88 tx
.executeSql("INSERT INTO QuotaTest VALUES (ZEROBLOB(10 * 1024 * 1024))");
92 function testVersionMismatch(db
)
94 // Use another DB handle to change the version. However, in order to make sure that the DB version is not
95 // changed before the transactions in the other tests have run, we need to do it in a transaction on 'db'.
96 db
.transaction(function(tx
) {
97 var db2
= openDatabaseWithSuffix("SQLErrorCodesTest", "1.0", "Tests the error codes.", 1);
98 db2
.changeVersion("1.0", "2.0", function(tx
) { },
100 log("FAIL: could not change the DB version.");
107 tx
.executeSql("THIS STATEMENT SHOULD NEVER GET EXECUTED");
113 if (window
.testRunner
)
114 testRunner
.clearAllDatabases();
116 var db
= openDatabaseWithSuffix("SQLErrorCodesTest", "1.0", "Tests the error codes.", 1);
117 testTransactionThrowsException(db
);
118 testTransactionFailureBecauseOfStatementFailure(db
);
119 testInvalidStatement(db
);
120 testIncorrectNumberOfBindParameters(db
);
121 testBindParameterOfWrongType(db
);
122 testConstraintFailure(db
);
123 testQuotaExceeded(db
);
124 testVersionMismatch(db
);