Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / websql / sql-error-codes.js
blob8e30ac2fc279ac897afaafc2301b5a4edf35aee2
1 function finishTest()
3 if (window.testRunner)
4 testRunner.notifyDone();
7 var TOTAL_TESTS = 8;
8 var testsRun = 0;
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)
14 finishTest();
15 } else {
16 log("FAIL: expected error code " + expectedErrorCodeName + " (" + error[expectedErrorCodeName] + "); got " + error.code);
17 finishTest();
21 function transactionSuccessCallback()
23 log("FAIL: a transaction has completed successfully.");
24 finishTest();
27 function testTransaction(db, transactionCallback, expectedErrorCodeName)
29 db.transaction(transactionCallback,
30 function(error) {
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)
42 testTransaction(db,
43 function(tx) {
44 tx.executeSql("BAD STATEMENT", [], null, function(tx, error) { return true; });
45 }, "UNKNOWN_ERR");
48 function testInvalidStatement(db)
50 testTransaction(db, function(tx) { tx.executeSql("BAD STATEMENT"); }, "SYNTAX_ERR");
53 function testIncorrectNumberOfBindParameters(db)
55 testTransaction(db,
56 function(tx) {
57 tx.executeSql("CREATE TABLE IF NOT EXISTS BadBindNumberTest (Foo INT, Bar INT)");
58 tx.executeSql("INSERT INTO BadBindNumberTest VALUES (?, ?)", [1]);
59 }, "SYNTAX_ERR");
62 function testBindParameterOfWrongType(db)
64 var badString = { };
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]);
70 }, "UNKNOWN_ERR");
73 function testConstraintFailure(db)
75 testTransaction(db,
76 function(tx) {
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)");
80 }, "CONSTRAINT_ERR");
83 function testQuotaExceeded(db)
85 testTransaction(db,
86 function(tx) {
87 tx.executeSql("CREATE TABLE IF NOT EXISTS QuotaTest (Foo BLOB)");
88 tx.executeSql("INSERT INTO QuotaTest VALUES (ZEROBLOB(10 * 1024 * 1024))");
89 }, "QUOTA_ERR");
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) { },
99 function(error) {
100 log("FAIL: could not change the DB version.");
101 finishTest();
102 }, function() { });
105 testTransaction(db,
106 function(tx) {
107 tx.executeSql("THIS STATEMENT SHOULD NEVER GET EXECUTED");
108 }, "VERSION_ERR");
111 function runTest()
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);